@fluid-experimental/tree 0.59.2001 → 0.59.3000

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 (258) hide show
  1. package/.eslintrc.js +2 -0
  2. package/.vscode/SharedTree.code-workspace +15 -0
  3. package/.vscode/settings.json +6 -0
  4. package/dist/ChangeCompression.js +9 -9
  5. package/dist/ChangeCompression.js.map +1 -1
  6. package/dist/ChangeTypes.d.ts +1 -6
  7. package/dist/ChangeTypes.d.ts.map +1 -1
  8. package/dist/ChangeTypes.js +5 -5
  9. package/dist/ChangeTypes.js.map +1 -1
  10. package/dist/Checkout.js +14 -14
  11. package/dist/Checkout.js.map +1 -1
  12. package/dist/Common.d.ts +21 -3
  13. package/dist/Common.d.ts.map +1 -1
  14. package/dist/Common.js +29 -4
  15. package/dist/Common.js.map +1 -1
  16. package/dist/EditLog.js +26 -25
  17. package/dist/EditLog.js.map +1 -1
  18. package/dist/EditUtilities.js +17 -17
  19. package/dist/EditUtilities.js.map +1 -1
  20. package/dist/Forest.js +31 -31
  21. package/dist/Forest.js.map +1 -1
  22. package/dist/HistoryEditFactory.js +9 -9
  23. package/dist/HistoryEditFactory.js.map +1 -1
  24. package/dist/IdConversion.js +9 -9
  25. package/dist/IdConversion.js.map +1 -1
  26. package/dist/Identifiers.d.ts +4 -0
  27. package/dist/Identifiers.d.ts.map +1 -1
  28. package/dist/Identifiers.js.map +1 -1
  29. package/dist/LogViewer.d.ts +1 -5
  30. package/dist/LogViewer.d.ts.map +1 -1
  31. package/dist/LogViewer.js +11 -19
  32. package/dist/LogViewer.js.map +1 -1
  33. package/dist/MergeHealth.js +2 -2
  34. package/dist/MergeHealth.js.map +1 -1
  35. package/dist/NodeIdUtilities.js +2 -2
  36. package/dist/NodeIdUtilities.js.map +1 -1
  37. package/dist/PayloadUtilities.js +1 -1
  38. package/dist/PayloadUtilities.js.map +1 -1
  39. package/dist/RevisionValueCache.d.ts +13 -10
  40. package/dist/RevisionValueCache.d.ts.map +1 -1
  41. package/dist/RevisionValueCache.js +14 -11
  42. package/dist/RevisionValueCache.js.map +1 -1
  43. package/dist/RevisionView.js +4 -4
  44. package/dist/RevisionView.js.map +1 -1
  45. package/dist/SerializationUtilities.js +4 -4
  46. package/dist/SerializationUtilities.js.map +1 -1
  47. package/dist/SharedTree.d.ts +93 -31
  48. package/dist/SharedTree.d.ts.map +1 -1
  49. package/dist/SharedTree.js +160 -131
  50. package/dist/SharedTree.js.map +1 -1
  51. package/dist/SharedTreeEncoder.d.ts +3 -3
  52. package/dist/SharedTreeEncoder.d.ts.map +1 -1
  53. package/dist/SharedTreeEncoder.js +36 -36
  54. package/dist/SharedTreeEncoder.js.map +1 -1
  55. package/dist/StringInterner.js +1 -1
  56. package/dist/StringInterner.js.map +1 -1
  57. package/dist/Summary.js +1 -1
  58. package/dist/Summary.js.map +1 -1
  59. package/dist/SummaryBackCompatibility.js +8 -8
  60. package/dist/SummaryBackCompatibility.js.map +1 -1
  61. package/dist/Transaction.js +1 -1
  62. package/dist/Transaction.js.map +1 -1
  63. package/dist/TransactionInternal.js +17 -17
  64. package/dist/TransactionInternal.js.map +1 -1
  65. package/dist/TreeCompressor.d.ts.map +1 -1
  66. package/dist/TreeCompressor.js +6 -8
  67. package/dist/TreeCompressor.js.map +1 -1
  68. package/dist/TreeNodeHandle.js +4 -4
  69. package/dist/TreeNodeHandle.js.map +1 -1
  70. package/dist/TreeView.js +7 -7
  71. package/dist/TreeView.js.map +1 -1
  72. package/dist/TreeViewUtilities.js +2 -2
  73. package/dist/TreeViewUtilities.js.map +1 -1
  74. package/dist/UndoRedoHandler.js +1 -1
  75. package/dist/UndoRedoHandler.js.map +1 -1
  76. package/dist/UuidUtilities.d.ts +30 -0
  77. package/dist/UuidUtilities.d.ts.map +1 -0
  78. package/dist/UuidUtilities.js +106 -0
  79. package/dist/UuidUtilities.js.map +1 -0
  80. package/dist/id-compressor/AppendOnlySortedMap.d.ts +52 -28
  81. package/dist/id-compressor/AppendOnlySortedMap.d.ts.map +1 -1
  82. package/dist/id-compressor/AppendOnlySortedMap.js +167 -90
  83. package/dist/id-compressor/AppendOnlySortedMap.js.map +1 -1
  84. package/dist/id-compressor/IdCompressor.d.ts +43 -42
  85. package/dist/id-compressor/IdCompressor.d.ts.map +1 -1
  86. package/dist/id-compressor/IdCompressor.js +179 -177
  87. package/dist/id-compressor/IdCompressor.js.map +1 -1
  88. package/dist/id-compressor/IdRange.js +1 -1
  89. package/dist/id-compressor/IdRange.js.map +1 -1
  90. package/dist/id-compressor/NumericUuid.d.ts +6 -14
  91. package/dist/id-compressor/NumericUuid.d.ts.map +1 -1
  92. package/dist/id-compressor/NumericUuid.js +15 -76
  93. package/dist/id-compressor/NumericUuid.js.map +1 -1
  94. package/dist/id-compressor/SessionIdNormalizer.d.ts +122 -0
  95. package/dist/id-compressor/SessionIdNormalizer.d.ts.map +1 -0
  96. package/dist/id-compressor/SessionIdNormalizer.js +418 -0
  97. package/dist/id-compressor/SessionIdNormalizer.js.map +1 -0
  98. package/dist/id-compressor/persisted-types/0.0.1.d.ts +6 -13
  99. package/dist/id-compressor/persisted-types/0.0.1.d.ts.map +1 -1
  100. package/dist/id-compressor/persisted-types/0.0.1.js.map +1 -1
  101. package/dist/index.d.ts +2 -2
  102. package/dist/index.d.ts.map +1 -1
  103. package/dist/index.js.map +1 -1
  104. package/dist/persisted-types/0.1.1.d.ts +1 -6
  105. package/dist/persisted-types/0.1.1.d.ts.map +1 -1
  106. package/dist/persisted-types/0.1.1.js +3 -3
  107. package/dist/persisted-types/0.1.1.js.map +1 -1
  108. package/lib/ChangeTypes.d.ts +1 -6
  109. package/lib/ChangeTypes.d.ts.map +1 -1
  110. package/lib/Checkout.js.map +1 -1
  111. package/lib/Common.d.ts +21 -3
  112. package/lib/Common.d.ts.map +1 -1
  113. package/lib/Common.js +25 -3
  114. package/lib/Common.js.map +1 -1
  115. package/lib/EditLog.js +2 -1
  116. package/lib/EditLog.js.map +1 -1
  117. package/lib/EditUtilities.js.map +1 -1
  118. package/lib/Forest.js.map +1 -1
  119. package/lib/HistoryEditFactory.js.map +1 -1
  120. package/lib/Identifiers.d.ts +4 -0
  121. package/lib/Identifiers.d.ts.map +1 -1
  122. package/lib/Identifiers.js.map +1 -1
  123. package/lib/LogViewer.d.ts +1 -5
  124. package/lib/LogViewer.d.ts.map +1 -1
  125. package/lib/LogViewer.js +5 -13
  126. package/lib/LogViewer.js.map +1 -1
  127. package/lib/MergeHealth.js.map +1 -1
  128. package/lib/NodeIdUtilities.js.map +1 -1
  129. package/lib/RevisionValueCache.d.ts +13 -10
  130. package/lib/RevisionValueCache.d.ts.map +1 -1
  131. package/lib/RevisionValueCache.js +10 -7
  132. package/lib/RevisionValueCache.js.map +1 -1
  133. package/lib/RevisionView.js.map +1 -1
  134. package/lib/SharedTree.d.ts +93 -31
  135. package/lib/SharedTree.d.ts.map +1 -1
  136. package/lib/SharedTree.js +107 -78
  137. package/lib/SharedTree.js.map +1 -1
  138. package/lib/SharedTreeEncoder.d.ts +3 -3
  139. package/lib/SharedTreeEncoder.d.ts.map +1 -1
  140. package/lib/SharedTreeEncoder.js +4 -4
  141. package/lib/SharedTreeEncoder.js.map +1 -1
  142. package/lib/StringInterner.js.map +1 -1
  143. package/lib/Summary.js.map +1 -1
  144. package/lib/TreeCompressor.d.ts.map +1 -1
  145. package/lib/TreeCompressor.js +1 -3
  146. package/lib/TreeCompressor.js.map +1 -1
  147. package/lib/TreeNodeHandle.js.map +1 -1
  148. package/lib/TreeView.js.map +1 -1
  149. package/lib/TreeViewUtilities.js.map +1 -1
  150. package/lib/UuidUtilities.d.ts +30 -0
  151. package/lib/UuidUtilities.d.ts.map +1 -0
  152. package/lib/UuidUtilities.js +98 -0
  153. package/lib/UuidUtilities.js.map +1 -0
  154. package/lib/id-compressor/AppendOnlySortedMap.d.ts +52 -28
  155. package/lib/id-compressor/AppendOnlySortedMap.d.ts.map +1 -1
  156. package/lib/id-compressor/AppendOnlySortedMap.js +165 -88
  157. package/lib/id-compressor/AppendOnlySortedMap.js.map +1 -1
  158. package/lib/id-compressor/IdCompressor.d.ts +43 -42
  159. package/lib/id-compressor/IdCompressor.d.ts.map +1 -1
  160. package/lib/id-compressor/IdCompressor.js +97 -95
  161. package/lib/id-compressor/IdCompressor.js.map +1 -1
  162. package/lib/id-compressor/NumericUuid.d.ts +6 -14
  163. package/lib/id-compressor/NumericUuid.d.ts.map +1 -1
  164. package/lib/id-compressor/NumericUuid.js +11 -70
  165. package/lib/id-compressor/NumericUuid.js.map +1 -1
  166. package/lib/id-compressor/SessionIdNormalizer.d.ts +122 -0
  167. package/lib/id-compressor/SessionIdNormalizer.d.ts.map +1 -0
  168. package/lib/id-compressor/SessionIdNormalizer.js +414 -0
  169. package/lib/id-compressor/SessionIdNormalizer.js.map +1 -0
  170. package/lib/id-compressor/persisted-types/0.0.1.d.ts +6 -13
  171. package/lib/id-compressor/persisted-types/0.0.1.d.ts.map +1 -1
  172. package/lib/id-compressor/persisted-types/0.0.1.js.map +1 -1
  173. package/lib/index.d.ts +2 -2
  174. package/lib/index.d.ts.map +1 -1
  175. package/lib/index.js.map +1 -1
  176. package/lib/persisted-types/0.1.1.d.ts +1 -6
  177. package/lib/persisted-types/0.1.1.d.ts.map +1 -1
  178. package/lib/persisted-types/0.1.1.js.map +1 -1
  179. package/lib/test/AppendOnlySortedMap.perf.tests.d.ts +6 -0
  180. package/lib/test/AppendOnlySortedMap.perf.tests.d.ts.map +1 -0
  181. package/lib/test/AppendOnlySortedMap.perf.tests.js +49 -0
  182. package/lib/test/AppendOnlySortedMap.perf.tests.js.map +1 -0
  183. package/lib/test/AppendOnlySortedMap.tests.js +56 -14
  184. package/lib/test/AppendOnlySortedMap.tests.js.map +1 -1
  185. package/lib/test/Checkout.tests.js +2 -2
  186. package/lib/test/Checkout.tests.js.map +1 -1
  187. package/lib/test/Forest.tests.js.map +1 -1
  188. package/lib/test/IdCompressor.perf.tests.js +8 -2
  189. package/lib/test/IdCompressor.perf.tests.js.map +1 -1
  190. package/lib/test/IdCompressor.tests.js +75 -24
  191. package/lib/test/IdCompressor.tests.js.map +1 -1
  192. package/lib/test/LogViewer.tests.js +3 -5
  193. package/lib/test/LogViewer.tests.js.map +1 -1
  194. package/lib/test/NumericUuid.perf.tests.js +4 -4
  195. package/lib/test/NumericUuid.perf.tests.js.map +1 -1
  196. package/lib/test/NumericUuid.tests.js +5 -4
  197. package/lib/test/NumericUuid.tests.js.map +1 -1
  198. package/lib/test/RevisionValueCache.tests.js.map +1 -1
  199. package/lib/test/RevisionView.tests.js.map +1 -1
  200. package/lib/test/SessionIdNormalizer.tests.d.ts +6 -0
  201. package/lib/test/SessionIdNormalizer.tests.d.ts.map +1 -0
  202. package/lib/test/SessionIdNormalizer.tests.js +299 -0
  203. package/lib/test/SessionIdNormalizer.tests.js.map +1 -0
  204. package/lib/test/Summary.tests.js +1 -1
  205. package/lib/test/Summary.tests.js.map +1 -1
  206. package/lib/test/TreeCompression.tests.js +1 -1
  207. package/lib/test/TreeCompression.tests.js.map +1 -1
  208. package/lib/test/Virtualization.tests.js +1 -1
  209. package/lib/test/Virtualization.tests.js.map +1 -1
  210. package/lib/test/fuzz/Generators.d.ts +3 -14
  211. package/lib/test/fuzz/Generators.d.ts.map +1 -1
  212. package/lib/test/fuzz/Generators.js +60 -151
  213. package/lib/test/fuzz/Generators.js.map +1 -1
  214. package/lib/test/fuzz/SharedTreeFuzzTests.d.ts +10 -7
  215. package/lib/test/fuzz/SharedTreeFuzzTests.d.ts.map +1 -1
  216. package/lib/test/fuzz/SharedTreeFuzzTests.js +94 -104
  217. package/lib/test/fuzz/SharedTreeFuzzTests.js.map +1 -1
  218. package/lib/test/fuzz/Types.d.ts +2 -9
  219. package/lib/test/fuzz/Types.d.ts.map +1 -1
  220. package/lib/test/fuzz/Types.js +1 -1
  221. package/lib/test/fuzz/Types.js.map +1 -1
  222. package/lib/test/utilities/IdCompressorTestUtilities.d.ts +57 -11
  223. package/lib/test/utilities/IdCompressorTestUtilities.d.ts.map +1 -1
  224. package/lib/test/utilities/IdCompressorTestUtilities.js +112 -98
  225. package/lib/test/utilities/IdCompressorTestUtilities.js.map +1 -1
  226. package/lib/test/utilities/PendingLocalStateTests.d.ts.map +1 -1
  227. package/lib/test/utilities/PendingLocalStateTests.js +2 -1
  228. package/lib/test/utilities/PendingLocalStateTests.js.map +1 -1
  229. package/lib/test/utilities/SharedTreeTests.d.ts.map +1 -1
  230. package/lib/test/utilities/SharedTreeTests.js +30 -1
  231. package/lib/test/utilities/SharedTreeTests.js.map +1 -1
  232. package/lib/test/utilities/SharedTreeVersioningTests.d.ts.map +1 -1
  233. package/lib/test/utilities/SharedTreeVersioningTests.js +20 -0
  234. package/lib/test/utilities/SharedTreeVersioningTests.js.map +1 -1
  235. package/lib/test/utilities/SummaryLoadPerfTests.d.ts.map +1 -1
  236. package/lib/test/utilities/SummaryLoadPerfTests.js +6 -3
  237. package/lib/test/utilities/SummaryLoadPerfTests.js.map +1 -1
  238. package/lib/test/utilities/TestNode.js.map +1 -1
  239. package/lib/test/utilities/TestUtilities.d.ts +9 -1
  240. package/lib/test/utilities/TestUtilities.d.ts.map +1 -1
  241. package/lib/test/utilities/TestUtilities.js +27 -13
  242. package/lib/test/utilities/TestUtilities.js.map +1 -1
  243. package/package.json +19 -17
  244. package/src/Common.ts +42 -4
  245. package/src/EditLog.ts +1 -1
  246. package/src/Identifiers.ts +5 -0
  247. package/src/LogViewer.ts +4 -20
  248. package/src/RevisionValueCache.ts +11 -8
  249. package/src/SharedTree.ts +222 -75
  250. package/src/SharedTreeEncoder.ts +17 -11
  251. package/src/TreeCompressor.ts +2 -4
  252. package/src/UuidUtilities.ts +123 -0
  253. package/src/id-compressor/AppendOnlySortedMap.ts +183 -94
  254. package/src/id-compressor/IdCompressor.ts +144 -132
  255. package/src/id-compressor/NumericUuid.ts +11 -80
  256. package/src/id-compressor/SessionIdNormalizer.ts +497 -0
  257. package/src/id-compressor/persisted-types/0.0.1.ts +12 -15
  258. package/src/index.ts +5 -0
@@ -36,7 +36,7 @@ exports.newEdit = newEdit;
36
36
  * Generates a new edit object from the supplied changes.
37
37
  */
38
38
  function newEditId() {
39
- return uuid_1.v4();
39
+ return (0, uuid_1.v4)();
40
40
  }
41
41
  exports.newEditId = newEditId;
42
42
  /**
@@ -56,9 +56,9 @@ function convertTreeNodes(root, convert, isPlaceholder) {
56
56
  // `convertedRoot` might be the same as `root`, in which case stash the children of `root` before wiping them from `convertedRoot`
57
57
  const rootTraits = root === convertedRoot ? { traits: root.traits } : root;
58
58
  convertedRoot.traits = {};
59
- const pendingNodes = [{ childIterator: RevisionView_1.iterateChildren(rootTraits)[Symbol.iterator](), newNode: convertedRoot }];
59
+ const pendingNodes = [{ childIterator: (0, RevisionView_1.iterateChildren)(rootTraits)[Symbol.iterator](), newNode: convertedRoot }];
60
60
  while (pendingNodes.length > 0) {
61
- const { childIterator, newNode } = (_a = pendingNodes[pendingNodes.length - 1]) !== null && _a !== void 0 ? _a : Common_1.fail('Undefined node');
61
+ const { childIterator, newNode } = (_a = pendingNodes[pendingNodes.length - 1]) !== null && _a !== void 0 ? _a : (0, Common_1.fail)('Undefined node');
62
62
  const { value, done } = childIterator.next();
63
63
  if (done === true) {
64
64
  pendingNodes.pop();
@@ -71,7 +71,7 @@ function convertTreeNodes(root, convert, isPlaceholder) {
71
71
  if (child.traits !== undefined) {
72
72
  const childTraits = child === convertedChild ? { traits: child.traits } : child;
73
73
  pendingNodes.push({
74
- childIterator: RevisionView_1.iterateChildren(childTraits)[Symbol.iterator](),
74
+ childIterator: (0, RevisionView_1.iterateChildren)(childTraits)[Symbol.iterator](),
75
75
  newNode: convertedChild,
76
76
  });
77
77
  }
@@ -101,9 +101,9 @@ function walkTree(tree, visitors, isPlaceholder) {
101
101
  return;
102
102
  }
103
103
  nodeVisitor === null || nodeVisitor === void 0 ? void 0 : nodeVisitor(tree);
104
- const childIterators = [RevisionView_1.iterateChildren(tree)[Symbol.iterator]()];
104
+ const childIterators = [(0, RevisionView_1.iterateChildren)(tree)[Symbol.iterator]()];
105
105
  while (childIterators.length > 0) {
106
- const childIterator = (_a = childIterators[childIterators.length - 1]) !== null && _a !== void 0 ? _a : Common_1.fail('Undefined node');
106
+ const childIterator = (_a = childIterators[childIterators.length - 1]) !== null && _a !== void 0 ? _a : (0, Common_1.fail)('Undefined node');
107
107
  const { value, done } = childIterator.next();
108
108
  if (done === true) {
109
109
  childIterators.pop();
@@ -115,7 +115,7 @@ function walkTree(tree, visitors, isPlaceholder) {
115
115
  }
116
116
  else {
117
117
  nodeVisitor === null || nodeVisitor === void 0 ? void 0 : nodeVisitor(child);
118
- childIterators.push(RevisionView_1.iterateChildren(child)[Symbol.iterator]());
118
+ childIterators.push((0, RevisionView_1.iterateChildren)(child)[Symbol.iterator]());
119
119
  }
120
120
  }
121
121
  }
@@ -148,7 +148,7 @@ function deepCompareNodes(a, b, comparator = compareNodes) {
148
148
  if (childrenA.length !== childrenB.length) {
149
149
  return false;
150
150
  }
151
- const traitsEqual = Common_1.compareArrays(childrenA, childrenB, (childA, childB) => {
151
+ const traitsEqual = (0, Common_1.compareArrays)(childrenA, childrenB, (childA, childB) => {
152
152
  if (typeof childA === 'number' || typeof childB === 'number') {
153
153
  // Check if children are DetachedSequenceIds
154
154
  return childA === childB;
@@ -177,7 +177,7 @@ function compareNodes(a, b) {
177
177
  if (a.definition !== b.definition) {
178
178
  return false;
179
179
  }
180
- if (!PayloadUtilities_1.comparePayloads(a.payload, b.payload)) {
180
+ if (!(0, PayloadUtilities_1.comparePayloads)(a.payload, b.payload)) {
181
181
  return false;
182
182
  }
183
183
  return true;
@@ -187,8 +187,8 @@ exports.compareNodes = compareNodes;
187
187
  * Compare two views such that semantically equivalent node IDs are considered equal.
188
188
  */
189
189
  function areRevisionViewsSemanticallyEqual(treeViewA, idConverterA, treeViewB, idConverterB) {
190
- const treeA = SerializationUtilities_1.getChangeNode_0_0_2FromView(treeViewA, idConverterA);
191
- const treeB = SerializationUtilities_1.getChangeNode_0_0_2FromView(treeViewB, idConverterB);
190
+ const treeA = (0, SerializationUtilities_1.getChangeNode_0_0_2FromView)(treeViewA, idConverterA);
191
+ const treeB = (0, SerializationUtilities_1.getChangeNode_0_0_2FromView)(treeViewB, idConverterB);
192
192
  if (!deepCompareNodes(treeA, treeB)) {
193
193
  return false;
194
194
  }
@@ -294,7 +294,7 @@ function validateStableRange(view, range) {
294
294
  if (!compareTraits(startTraitLocation, endTraitLocation)) {
295
295
  return { result: RangeValidationResultKind.PlacesInDifferentTraits };
296
296
  }
297
- const { start: startPlace, end: endPlace } = TreeViewUtilities_1.rangeFromStableRange(view, {
297
+ const { start: startPlace, end: endPlace } = (0, TreeViewUtilities_1.rangeFromStableRange)(view, {
298
298
  start: validatedStart,
299
299
  end: validatedEnd,
300
300
  });
@@ -331,7 +331,7 @@ function compareTraits(traitA, traitB) {
331
331
  * @param placeToInsert - the location to insert the nodes.
332
332
  */
333
333
  function insertIntoTrait(view, nodesToInsert, placeToInsert) {
334
- return view.attachRange(nodesToInsert, TreeViewUtilities_1.placeFromStablePlace(view, placeToInsert));
334
+ return view.attachRange(nodesToInsert, (0, TreeViewUtilities_1.placeFromStablePlace)(view, placeToInsert));
335
335
  }
336
336
  exports.insertIntoTrait = insertIntoTrait;
337
337
  /**
@@ -339,7 +339,7 @@ exports.insertIntoTrait = insertIntoTrait;
339
339
  * @param rangeToDetach - the range of nodes to detach
340
340
  */
341
341
  function detachRange(view, rangeToDetach) {
342
- return view.detachRange(TreeViewUtilities_1.rangeFromStableRange(view, rangeToDetach));
342
+ return view.detachRange((0, TreeViewUtilities_1.rangeFromStableRange)(view, rangeToDetach));
343
343
  }
344
344
  exports.detachRange = detachRange;
345
345
  /**
@@ -347,8 +347,8 @@ exports.detachRange = detachRange;
347
347
  */
348
348
  function deepCloneStablePlace(place) {
349
349
  const clone = { side: place.side };
350
- Common_1.copyPropertyIfDefined(place, clone, 'referenceSibling');
351
- Common_1.copyPropertyIfDefined(place, clone, 'referenceTrait');
350
+ (0, Common_1.copyPropertyIfDefined)(place, clone, 'referenceSibling');
351
+ (0, Common_1.copyPropertyIfDefined)(place, clone, 'referenceTrait');
352
352
  return clone;
353
353
  }
354
354
  exports.deepCloneStablePlace = deepCloneStablePlace;
@@ -366,7 +366,7 @@ function internalizeBuildNode(nodeData, nodeIdContext) {
366
366
  definition: nodeData.definition,
367
367
  identifier: (_a = nodeData.identifier) !== null && _a !== void 0 ? _a : nodeIdContext.generateNodeId(),
368
368
  };
369
- Common_1.copyPropertyIfDefined(nodeData, output, 'payload');
369
+ (0, Common_1.copyPropertyIfDefined)(nodeData, output, 'payload');
370
370
  return output;
371
371
  }
372
372
  exports.internalizeBuildNode = internalizeBuildNode;
@@ -1 +1 @@
1
- {"version":3,"file":"EditUtilities.js","sourceRoot":"","sources":["../src/EditUtilities.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+BAAoC;AACpC,qCAA+E;AAG/E,uDAe2B;AAE3B,+CAA8G;AAC9G,2DAAiF;AACjF,iDAAkE;AAClE,qEAAuE;AACvE,yDAAqD;AAErD;;GAEG;AAEH;;GAEG;AACH,SAAgB,YAAY,CAAC,OAAe,EAAE,OAAe;IAC5D,8GAA8G;IAC9G,2GAA2G;IAC3G,OAAO,OAAO,KAAK,OAAO,CAAC;AAC5B,CAAC;AAJD,oCAIC;AAED;;GAEG;AACH,SAAgB,OAAO,CAAQ,OAAyB;IACvD,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,CAAC;AACrC,CAAC;AAFD,0BAEC;AAED;;GAEG;AACH,SAAgB,SAAS;IACxB,OAAO,SAAM,EAAY,CAAC;AAC3B,CAAC;AAFD,8BAEC;AAiCD;;;;;;;GAOG;AACH,SAAgB,gBAAgB,CAK/B,IAAwB,EACxB,OAAsC,EACtC,aAAkE;;IAElE,IAAI,WAAW,CAAC,IAAI,EAAE,aAAa,CAAC,EAAE;QACrC,OAAO,IAAI,CAAC;KACZ;IAED,MAAM,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AAK,EAAE,KAAK,EAAE,kBAAkB,CAAC,CAAC;IACxD,8BAAqB,CAAC,KAAK,EAAE,KAAK,EAAE,gBAAgB,CAAC,CAAC;IACtD,OAAO,KAAK,CAAC;AACd,CAAC;AALD,oDAKC;AAED;;GAEG;AACH,SAAgB,oBAAoB,CAAC,KAAkB;IACtD,OAAO,EAAE,KAAK,EAAE,oBAAoB,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,oBAAoB,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;AAC3F,CAAC;AAFD,oDAEC;AAED,6EAA6E;AAC7E,SAAgB,oBAAoB,CACnC,QAAuB,EACvB,aAA4B;;IAE5B,MAAM,MAAM,GAAG;QACd,UAAU,EAAE,QAAQ,CAAC,UAAwB;QAC7C,UAAU,QAAE,QAAQ,CAAC,UAAU,mCAAI,aAAa,CAAC,cAAc,EAAE;KACjE,CAAC;IACF,8BAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;IACnD,OAAO,MAAM,CAAC;AACf,CAAC;AAVD,oDAUC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { v4 as uuidv4 } from 'uuid';\nimport { compareArrays, copyPropertyIfDefined, fail, Mutable } from './Common';\nimport { Definition, DetachedSequenceId, EditId, NodeId, StableNodeId, TraitLabel } from './Identifiers';\nimport { NodeIdContext, NodeIdConverter } from './NodeIdUtilities';\nimport {\n\tBuildNodeInternal,\n\tChangeInternal,\n\tChangeNode,\n\tChangeNode_0_0_2,\n\tEdit,\n\tHasTraits,\n\tNodeData,\n\tSide,\n\tStablePlaceInternal,\n\tStableRangeInternal,\n\tTraitLocationInternal,\n\tTraitMap,\n\tTreeNode,\n\tTreeNodeSequence,\n} from './persisted-types';\nimport { TraitLocation, TreeView } from './TreeView';\nimport { BuildNode, BuildTreeNode, Change, HasVariadicTraits, StablePlace, StableRange } from './ChangeTypes';\nimport { placeFromStablePlace, rangeFromStableRange } from './TreeViewUtilities';\nimport { iterateChildren, TransactionView } from './RevisionView';\nimport { getChangeNode_0_0_2FromView } from './SerializationUtilities';\nimport { comparePayloads } from './PayloadUtilities';\n\n/**\n * Functions for constructing and comparing Edits.\n */\n\n/**\n * Returns true if the provided Edits have equivalent properties.\n */\nexport function compareEdits(editIdA: EditId, editIdB: EditId): boolean {\n\t// TODO #45414: We should also be deep comparing the list of changes in the edit. This is not straightforward.\n\t// We can use our edit validation code when we write it since it will need to do deep walks of the changes.\n\treturn editIdA === editIdB;\n}\n\n/**\n * Generates a new edit object from the supplied changes.\n */\nexport function newEdit<TEdit>(changes: readonly TEdit[]): Edit<TEdit> {\n\treturn { id: newEditId(), changes };\n}\n\n/**\n * Generates a new edit object from the supplied changes.\n */\nexport function newEditId(): EditId {\n\treturn uuidv4() as EditId;\n}\n\n/**\n * A node type that does not require its children to be specified\n */\nexport type NoTraits<TChild extends HasVariadicTraits<unknown>> = Omit<TChild, keyof HasVariadicTraits<TChild>>;\n\n/**\n * Transform an input tree into an isomorphic output tree\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 tree.\n */\nexport function convertTreeNodes<TIn extends HasVariadicTraits<TIn>, TOut extends HasTraits<TOut>>(\n\troot: TIn,\n\tconvert: (node: TIn) => NoTraits<TOut>\n): TOut;\n\n/**\n * Transform an input tree into an isomorphic output tree\n * @param tree - the input tree\n * @param convert - a conversion function that will run on each (non-placeholder) node in the input tree to produce the output tree.\n * @param isPlaceholder - a predicate which determines if a node is a placeholder\n */\nexport function convertTreeNodes<\n\tTIn extends HasVariadicTraits<TIn | TPlaceholder>,\n\tTOut extends HasTraits<TOut | TPlaceholder>,\n\tTPlaceholder\n>(\n\troot: TIn | TPlaceholder,\n\tconvert: (node: TIn) => NoTraits<TOut>,\n\tisPlaceholder: (node: TIn | TPlaceholder) => node is TPlaceholder\n): TOut | TPlaceholder;\n\n/**\n * Transform an input tree into an isomorphic output tree\n * @param tree - the input tree\n * @param convert - a conversion function that will run on each (non-placeholder) node in the input tree to produce the output tree.\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 * @param isPlaceholder - a predicate which determines if the given node is of type TPlaceholder\n */\nexport function convertTreeNodes<\n\tTIn extends HasVariadicTraits<TIn | TPlaceholder>,\n\tTOut extends HasTraits<TOut | TPlaceholder>,\n\tTPlaceholder\n>(\n\troot: TIn | TPlaceholder,\n\tconvert: (node: TIn) => NoTraits<TOut>,\n\tisPlaceholder?: (node: TIn | TPlaceholder) => node is TPlaceholder\n): TOut | TPlaceholder {\n\tif (isKnownType(root, isPlaceholder)) {\n\t\treturn root;\n\t}\n\n\tconst convertedRoot = convert(root) as TOut;\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\t(convertedRoot as Mutable<TOut>).traits = {};\n\tconst pendingNodes: {\n\t\tchildIterator: Iterator<[TraitLabel, TIn | TPlaceholder]>;\n\t\tnewNode: Mutable<TOut>;\n\t}[] = [{ childIterator: iterateChildren(rootTraits)[Symbol.iterator](), newNode: convertedRoot }];\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\tpendingNodes.pop();\n\t\t} else {\n\t\t\tconst [traitLabel, child] = value as [TraitLabel, TIn | TPlaceholder];\n\t\t\tlet convertedChild: TOut | TPlaceholder;\n\t\t\tif (!isKnownType(child, isPlaceholder)) {\n\t\t\t\tconvertedChild = convert(child) as TOut;\n\t\t\t\tif (child.traits !== undefined) {\n\t\t\t\t\tconst childTraits =\n\t\t\t\t\t\t(child as unknown as TOut) === convertedChild ? { traits: child.traits } : child;\n\t\t\t\t\tpendingNodes.push({\n\t\t\t\t\t\tchildIterator: iterateChildren(childTraits)[Symbol.iterator](),\n\t\t\t\t\t\tnewNode: convertedChild,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\t(convertedChild as Mutable<TOut>).traits = {};\n\t\t\t} else {\n\t\t\t\tconvertedChild = child;\n\t\t\t}\n\t\t\tconst newTraits = newNode.traits as Mutable<TraitMap<TOut | TPlaceholder>>;\n\t\t\tlet newTrait = newTraits[traitLabel];\n\t\t\tif (newTrait === undefined) {\n\t\t\t\tnewTrait = [];\n\t\t\t\tnewTraits[traitLabel] = newTrait;\n\t\t\t}\n\t\t\t(newTrait as (TOut | TPlaceholder)[]).push(convertedChild);\n\t\t}\n\t}\n\n\treturn convertedRoot;\n}\n\n/**\n * Visits an input tree in a depth-first pre-order traversal.\n * @param tree - the input tree\n * @param visitor - callback invoked for each node in the tree.\n */\nexport function walkTree<TIn extends HasVariadicTraits<TIn>>(tree: TIn, visitor: (node: TIn) => void): void;\n\n/**\n * Visits an input tree containing placeholders in a depth-first pre-order traversal.\n * @param tree - the input tree\n * @param visitor - callback invoked for each node in the tree. Must return true if the given node is a TPlaceholder.\n */\nexport function walkTree<TIn extends HasVariadicTraits<TIn | TPlaceholder>, TPlaceholder = never>(\n\ttree: TIn | TPlaceholder,\n\tvisitors:\n\t\t| ((node: TIn) => void)\n\t\t| { nodeVisitor?: (node: TIn) => void; placeholderVisitor?: (placeholder: TPlaceholder) => void },\n\tisPlaceholder: (node: TIn | TPlaceholder) => node is TPlaceholder\n): void;\n\nexport function walkTree<TIn extends HasVariadicTraits<TIn | TPlaceholder>, TPlaceholder = never>(\n\ttree: TIn | TPlaceholder,\n\tvisitors:\n\t\t| ((node: TIn) => void)\n\t\t| { nodeVisitor?: (node: TIn) => void; placeholderVisitor?: (placeholder: TPlaceholder) => void },\n\tisPlaceholder?: (node: TIn | TPlaceholder) => node is TPlaceholder\n): void {\n\tconst nodeVisitor = typeof visitors === 'function' ? visitors : visitors.nodeVisitor;\n\tconst placeholderVisitor = typeof visitors === 'object' ? visitors.placeholderVisitor : undefined;\n\tif (isKnownType(tree, isPlaceholder)) {\n\t\tplaceholderVisitor?.(tree);\n\t\treturn;\n\t}\n\tnodeVisitor?.(tree);\n\n\tconst childIterators: Iterator<[TraitLabel, TIn | TPlaceholder]>[] = [iterateChildren(tree)[Symbol.iterator]()];\n\n\twhile (childIterators.length > 0) {\n\t\tconst childIterator = childIterators[childIterators.length - 1] ?? fail('Undefined node');\n\t\tconst { value, done } = childIterator.next();\n\t\tif (done === true) {\n\t\t\tchildIterators.pop();\n\t\t} else {\n\t\t\tconst [_, child] = value as [TraitLabel, TIn | TPlaceholder];\n\t\t\tif (isKnownType(child, isPlaceholder)) {\n\t\t\t\tplaceholderVisitor?.(child);\n\t\t\t} else {\n\t\t\t\tnodeVisitor?.(child);\n\t\t\t\tchildIterators.push(iterateChildren(child)[Symbol.iterator]());\n\t\t\t}\n\t\t}\n\t}\n}\n\n// Useful for collapsing type checks in `convertTreeNodes` into a single line\nfunction isKnownType<T, Type extends T>(value: T, isType?: (value: T) => value is Type): value is Type {\n\treturn isType?.(value) ?? false;\n}\n\n/**\n * Check if two trees are equivalent, meaning they have the same descendants with the same properties.\n *\n * See {@link comparePayloads} for payload comparison semantics.\n */\nexport function deepCompareNodes(\n\ta: ChangeNode | ChangeNode_0_0_2,\n\tb: ChangeNode | ChangeNode_0_0_2,\n\tcomparator: (\n\t\ta: NodeData<NodeId> | NodeData<StableNodeId>,\n\t\tb: NodeData<NodeId> | NodeData<StableNodeId>\n\t) => boolean = compareNodes\n): boolean {\n\tif (a === b) {\n\t\treturn true;\n\t}\n\n\tif (!comparator(a, b)) {\n\t\treturn false;\n\t}\n\n\tconst traitsA = Object.entries(a.traits);\n\tconst traitsB = Object.entries(b.traits);\n\n\tif (traitsA.length !== traitsB.length) {\n\t\treturn false;\n\t}\n\n\tfor (const [traitLabel, childrenA] of traitsA) {\n\t\tconst childrenB = b.traits[traitLabel];\n\n\t\tif (childrenA.length !== childrenB.length) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst traitsEqual = compareArrays<ChangeNode | ChangeNode_0_0_2>(childrenA, childrenB, (childA, childB) => {\n\t\t\tif (typeof childA === 'number' || typeof childB === 'number') {\n\t\t\t\t// Check if children are DetachedSequenceIds\n\t\t\t\treturn childA === childB;\n\t\t\t}\n\n\t\t\treturn deepCompareNodes(childA, childB);\n\t\t});\n\n\t\tif (!traitsEqual) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\treturn true;\n}\n\n/*\n * Returns true if two nodes have equivalent data and payloads, otherwise false.\n * Does not compare children\n * @param nodes - two or more nodes to compare\n */\nexport function compareNodes(\n\ta: NodeData<NodeId> | NodeData<StableNodeId>,\n\tb: NodeData<NodeId> | NodeData<StableNodeId>\n): boolean {\n\tif (a === b) {\n\t\treturn true;\n\t}\n\n\tif (a.identifier !== b.identifier) {\n\t\treturn false;\n\t}\n\n\tif (a.definition !== b.definition) {\n\t\treturn false;\n\t}\n\n\tif (!comparePayloads(a.payload, b.payload)) {\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n\n/**\n * Compare two views such that semantically equivalent node IDs are considered equal.\n */\nexport function areRevisionViewsSemanticallyEqual(\n\ttreeViewA: TreeView,\n\tidConverterA: NodeIdConverter,\n\ttreeViewB: TreeView,\n\tidConverterB: NodeIdConverter\n): boolean {\n\tconst treeA = getChangeNode_0_0_2FromView(treeViewA, idConverterA);\n\tconst treeB = getChangeNode_0_0_2FromView(treeViewB, idConverterB);\n\tif (!deepCompareNodes(treeA, treeB)) {\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n\n/**\n * Create a sequence of changes that resets the contents of `trait`.\n * @public\n */\nexport function setTrait(trait: TraitLocation, nodes: BuildNode | TreeNodeSequence<BuildNode>): Change[] {\n\tconst id = 0 as DetachedSequenceId;\n\tconst traitContents = StableRange.all(trait);\n\treturn [Change.detach(traitContents), Change.build(nodes, id), Change.insert(id, traitContents.start)];\n}\n\n/**\n * Create a sequence of changes that resets the contents of `trait`.\n * @internal\n */\nexport function setTraitInternal(\n\ttrait: TraitLocationInternal,\n\tnodes: TreeNodeSequence<BuildNodeInternal>\n): ChangeInternal[] {\n\tconst id = 0 as DetachedSequenceId;\n\tconst traitContents = StableRangeInternal.all(trait);\n\treturn [\n\t\tChangeInternal.detach(traitContents),\n\t\tChangeInternal.build(nodes, id),\n\t\tChangeInternal.insert(id, traitContents.start),\n\t];\n}\n\n/**\n * Check the validity of the given `StablePlace`\n * @param view - the `TreeView` within which to validate the given place\n * @param place - the `StablePlace` to check\n */\nexport function validateStablePlace(\n\tview: TreeView,\n\tplace: StablePlaceInternal\n):\n\t| {\n\t\t\tresult: PlaceValidationResult.Valid;\n\t\t\tside: Side;\n\t\t\treferenceSibling: NodeId;\n\t\t\treferenceTrait?: never;\n\t }\n\t| {\n\t\t\tresult: PlaceValidationResult.Valid;\n\t\t\tside: Side;\n\t\t\treferenceSibling?: never;\n\t\t\treferenceTrait: TraitLocation;\n\t }\n\t| { result: Exclude<PlaceValidationResult, PlaceValidationResult.Valid> } {\n\t/* A StablePlace is valid if the following conditions are met:\n\t * 1. A sibling or trait is defined.\n\t * 2. If a sibling is defined, both it and its parent exist in the `TreeView`.\n\t * 3. If a trait is defined, its parent node exists in the `TreeView`.\n\t * 4. If a sibling and a trait location are both specified, the sibling needs to actually be in that trait.\n\t */\n\tconst { referenceSibling, referenceTrait } = place;\n\n\t// A well-formed `StablePlace` specifies exactly one of `referenceSibling` and `referenceTrait`.\n\tif (\n\t\t(referenceSibling === undefined && referenceTrait === undefined) ||\n\t\t(referenceSibling !== undefined && referenceTrait !== undefined)\n\t) {\n\t\treturn { result: PlaceValidationResult.Malformed };\n\t}\n\n\tif (referenceSibling !== undefined) {\n\t\tif (!view.hasNode(referenceSibling)) {\n\t\t\treturn { result: PlaceValidationResult.MissingSibling };\n\t\t}\n\n\t\t// Detached nodes and the root are invalid anchors.\n\t\tif (view.tryGetTraitLabel(referenceSibling) === undefined) {\n\t\t\treturn { result: PlaceValidationResult.SiblingIsRootOrDetached };\n\t\t}\n\n\t\treturn { result: PlaceValidationResult.Valid, side: place.side, referenceSibling };\n\t}\n\n\tif (referenceTrait === undefined) {\n\t\treturn { result: PlaceValidationResult.MissingParent };\n\t}\n\n\tif (!view.hasNode(referenceTrait.parent)) {\n\t\treturn { result: PlaceValidationResult.MissingParent };\n\t}\n\n\treturn { result: PlaceValidationResult.Valid, side: place.side, referenceTrait };\n}\n\n/**\n * The result of validating a place.\n */\nexport enum PlaceValidationResult {\n\tValid = 'Valid',\n\tMalformed = 'Malformed',\n\tSiblingIsRootOrDetached = 'SiblingIsRootOrDetached',\n\tMissingSibling = 'MissingSibling',\n\tMissingParent = 'MissingParent',\n}\n\n/**\n * The result of validating a bad place.\n */\nexport type BadPlaceValidationResult = Exclude<PlaceValidationResult, PlaceValidationResult.Valid>;\n\n/**\n * Check the validity of the given `StableRange`\n * @param view - the `TreeView` within which to validate the given range\n * @param range - the `StableRange` to check\n */\nexport function validateStableRange(\n\tview: TreeView,\n\trange: StableRangeInternal\n):\n\t| { result: RangeValidationResultKind.Valid; start: StablePlaceInternal; end: StablePlaceInternal }\n\t| { result: Exclude<RangeValidationResult, RangeValidationResultKind.Valid> } {\n\t/* A StableRange is valid if the following conditions are met:\n\t * 1. Its start and end places are valid.\n\t * 2. Its start and end places are within the same trait.\n\t * 3. Its start place is before its end place.\n\t */\n\tconst { start, end } = range;\n\n\tconst validatedStart = validateStablePlace(view, start);\n\tif (validatedStart.result !== PlaceValidationResult.Valid) {\n\t\treturn {\n\t\t\tresult: { kind: RangeValidationResultKind.BadPlace, place: start, placeFailure: validatedStart.result },\n\t\t};\n\t}\n\n\tconst validatedEnd = validateStablePlace(view, end);\n\tif (validatedEnd.result !== PlaceValidationResult.Valid) {\n\t\treturn { result: { kind: RangeValidationResultKind.BadPlace, place: end, placeFailure: validatedEnd.result } };\n\t}\n\n\tconst startTraitLocation = validatedStart.referenceTrait || view.getTraitLocation(validatedStart.referenceSibling);\n\tconst endTraitLocation = validatedEnd.referenceTrait || view.getTraitLocation(validatedEnd.referenceSibling);\n\tif (!compareTraits(startTraitLocation, endTraitLocation)) {\n\t\treturn { result: RangeValidationResultKind.PlacesInDifferentTraits };\n\t}\n\n\tconst { start: startPlace, end: endPlace } = rangeFromStableRange(view, {\n\t\tstart: validatedStart,\n\t\tend: validatedEnd,\n\t});\n\tconst startIndex = view.findIndexWithinTrait(startPlace);\n\tconst endIndex = view.findIndexWithinTrait(endPlace);\n\n\tif (startIndex > endIndex) {\n\t\treturn { result: RangeValidationResultKind.Inverted };\n\t}\n\n\treturn { result: RangeValidationResultKind.Valid, start: validatedStart, end: validatedEnd };\n}\n\n/**\n * The kinds of result of validating a range.\n */\nexport enum RangeValidationResultKind {\n\tValid = 'Valid',\n\tBadPlace = 'BadPlace',\n\tPlacesInDifferentTraits = 'PlacesInDifferentTraits',\n\tInverted = 'Inverted',\n}\n\n/**\n * The result of validating a range.\n */\nexport type RangeValidationResult =\n\t| RangeValidationResultKind.Valid\n\t| RangeValidationResultKind.PlacesInDifferentTraits\n\t| RangeValidationResultKind.Inverted\n\t| {\n\t\t\tkind: RangeValidationResultKind.BadPlace;\n\t\t\tplace: StablePlaceInternal;\n\t\t\tplaceFailure: BadPlaceValidationResult;\n\t };\n\n/**\n * The result of validating a bad range.\n */\nexport type BadRangeValidationResult = Exclude<RangeValidationResult, RangeValidationResultKind.Valid>;\n\n/**\n * Check if two TraitLocations are equal.\n */\nfunction compareTraits(traitA: TraitLocation, traitB: TraitLocation): boolean {\n\tif (traitA.label !== traitB.label || traitA.parent !== traitB.parent) {\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n\n/**\n * Parents a set of nodes in a specified location within a trait.\n * @param nodesToInsert - the nodes to parent in the specified place. The nodes must already be present in the TreeView.\n * @param placeToInsert - the location to insert the nodes.\n */\nexport function insertIntoTrait(\n\tview: TransactionView,\n\tnodesToInsert: readonly NodeId[],\n\tplaceToInsert: StablePlace\n): TransactionView {\n\treturn view.attachRange(nodesToInsert, placeFromStablePlace(view, placeToInsert));\n}\n\n/**\n * Detaches a range of nodes from their parent. The detached nodes remain in the TreeView.\n * @param rangeToDetach - the range of nodes to detach\n */\nexport function detachRange(\n\tview: TransactionView,\n\trangeToDetach: StableRange\n): { view: TransactionView; detached: readonly NodeId[] } {\n\treturn view.detachRange(rangeFromStableRange(view, rangeToDetach));\n}\n\n/**\n * Deeply clone the given StablePlace\n */\nexport function deepCloneStablePlace(place: StablePlace): StablePlace {\n\tconst clone: StablePlace = { side: place.side };\n\tcopyPropertyIfDefined(place, clone, 'referenceSibling');\n\tcopyPropertyIfDefined(place, clone, 'referenceTrait');\n\treturn clone;\n}\n\n/**\n * Deeply clone the given StableRange\n */\nexport function deepCloneStableRange(range: StableRange): StableRange {\n\treturn { start: deepCloneStablePlace(range.start), end: deepCloneStablePlace(range.end) };\n}\n\n/** Convert a node used in a Build change into its internal representation */\nexport function internalizeBuildNode(\n\tnodeData: BuildTreeNode,\n\tnodeIdContext: NodeIdContext\n): Omit<TreeNode<BuildNodeInternal, NodeId>, 'traits'> {\n\tconst output = {\n\t\tdefinition: nodeData.definition as Definition,\n\t\tidentifier: nodeData.identifier ?? nodeIdContext.generateNodeId(),\n\t};\n\tcopyPropertyIfDefined(nodeData, output, 'payload');\n\treturn output;\n}\n"]}
1
+ {"version":3,"file":"EditUtilities.js","sourceRoot":"","sources":["../src/EditUtilities.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+BAAoC;AACpC,qCAA+E;AAG/E,uDAe2B;AAE3B,+CAA8G;AAC9G,2DAAiF;AACjF,iDAAkE;AAClE,qEAAuE;AACvE,yDAAqD;AAErD;;GAEG;AAEH;;GAEG;AACH,SAAgB,YAAY,CAAC,OAAe,EAAE,OAAe;IAC5D,8GAA8G;IAC9G,2GAA2G;IAC3G,OAAO,OAAO,KAAK,OAAO,CAAC;AAC5B,CAAC;AAJD,oCAIC;AAED;;GAEG;AACH,SAAgB,OAAO,CAAQ,OAAyB;IACvD,OAAO,EAA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n * Licensed under the MIT License.\n */\n\nimport { v4 as uuidv4 } from 'uuid';\nimport { compareArrays, copyPropertyIfDefined, fail, Mutable } from './Common';\nimport { Definition, DetachedSequenceId, EditId, NodeId, StableNodeId, TraitLabel } from './Identifiers';\nimport { NodeIdContext, NodeIdConverter } from './NodeIdUtilities';\nimport {\n\tBuildNodeInternal,\n\tChangeInternal,\n\tChangeNode,\n\tChangeNode_0_0_2,\n\tEdit,\n\tHasTraits,\n\tNodeData,\n\tSide,\n\tStablePlaceInternal,\n\tStableRangeInternal,\n\tTraitLocationInternal,\n\tTraitMap,\n\tTreeNode,\n\tTreeNodeSequence,\n} from './persisted-types';\nimport { TraitLocation, TreeView } from './TreeView';\nimport { BuildNode, BuildTreeNode, Change, HasVariadicTraits, StablePlace, StableRange } from './ChangeTypes';\nimport { placeFromStablePlace, rangeFromStableRange } from './TreeViewUtilities';\nimport { iterateChildren, TransactionView } from './RevisionView';\nimport { getChangeNode_0_0_2FromView } from './SerializationUtilities';\nimport { comparePayloads } from './PayloadUtilities';\n\n/**\n * Functions for constructing and comparing Edits.\n */\n\n/**\n * Returns true if the provided Edits have equivalent properties.\n */\nexport function compareEdits(editIdA: EditId, editIdB: EditId): boolean {\n\t// TODO #45414: We should also be deep comparing the list of changes in the edit. This is not straightforward.\n\t// We can use our edit validation code when we write it since it will need to do deep walks of the changes.\n\treturn editIdA === editIdB;\n}\n\n/**\n * Generates a new edit object from the supplied changes.\n */\nexport function newEdit<TEdit>(changes: readonly TEdit[]): Edit<TEdit> {\n\treturn { id: newEditId(), changes };\n}\n\n/**\n * Generates a new edit object from the supplied changes.\n */\nexport function newEditId(): EditId {\n\treturn uuidv4() as EditId;\n}\n\n/**\n * A node type that does not require its children to be specified\n */\nexport type NoTraits<TChild extends HasVariadicTraits<unknown>> = Omit<TChild, keyof HasVariadicTraits<TChild>>;\n\n/**\n * Transform an input tree into an isomorphic output tree\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 tree.\n */\nexport function convertTreeNodes<TIn extends HasVariadicTraits<TIn>, TOut extends HasTraits<TOut>>(\n\troot: TIn,\n\tconvert: (node: TIn) => NoTraits<TOut>\n): TOut;\n\n/**\n * Transform an input tree into an isomorphic output tree\n * @param tree - the input tree\n * @param convert - a conversion function that will run on each (non-placeholder) node in the input tree to produce the output tree.\n * @param isPlaceholder - a predicate which determines if a node is a placeholder\n */\nexport function convertTreeNodes<\n\tTIn extends HasVariadicTraits<TIn | TPlaceholder>,\n\tTOut extends HasTraits<TOut | TPlaceholder>,\n\tTPlaceholder\n>(\n\troot: TIn | TPlaceholder,\n\tconvert: (node: TIn) => NoTraits<TOut>,\n\tisPlaceholder: (node: TIn | TPlaceholder) => node is TPlaceholder\n): TOut | TPlaceholder;\n\n/**\n * Transform an input tree into an isomorphic output tree\n * @param tree - the input tree\n * @param convert - a conversion function that will run on each (non-placeholder) node in the input tree to produce the output tree.\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 * @param isPlaceholder - a predicate which determines if the given node is of type TPlaceholder\n */\nexport function convertTreeNodes<\n\tTIn extends HasVariadicTraits<TIn | TPlaceholder>,\n\tTOut extends HasTraits<TOut | TPlaceholder>,\n\tTPlaceholder\n>(\n\troot: TIn | TPlaceholder,\n\tconvert: (node: TIn) => NoTraits<TOut>,\n\tisPlaceholder?: (node: TIn | TPlaceholder) => node is TPlaceholder\n): TOut | TPlaceholder {\n\tif (isKnownType(root, isPlaceholder)) {\n\t\treturn root;\n\t}\n\n\tconst convertedRoot = convert(root) as TOut;\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\t(convertedRoot as Mutable<TOut>).traits = {};\n\tconst pendingNodes: {\n\t\tchildIterator: Iterator<[TraitLabel, TIn | TPlaceholder]>;\n\t\tnewNode: Mutable<TOut>;\n\t}[] = [{ childIterator: iterateChildren(rootTraits)[Symbol.iterator](), newNode: convertedRoot }];\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\tpendingNodes.pop();\n\t\t} else {\n\t\t\tconst [traitLabel, child] = value as [TraitLabel, TIn | TPlaceholder];\n\t\t\tlet convertedChild: TOut | TPlaceholder;\n\t\t\tif (!isKnownType(child, isPlaceholder)) {\n\t\t\t\tconvertedChild = convert(child) as TOut;\n\t\t\t\tif (child.traits !== undefined) {\n\t\t\t\t\tconst childTraits =\n\t\t\t\t\t\t(child as unknown as TOut) === convertedChild ? { traits: child.traits } : child;\n\t\t\t\t\tpendingNodes.push({\n\t\t\t\t\t\tchildIterator: iterateChildren(childTraits)[Symbol.iterator](),\n\t\t\t\t\t\tnewNode: convertedChild,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\t(convertedChild as Mutable<TOut>).traits = {};\n\t\t\t} else {\n\t\t\t\tconvertedChild = child;\n\t\t\t}\n\t\t\tconst newTraits = newNode.traits as Mutable<TraitMap<TOut | TPlaceholder>>;\n\t\t\tlet newTrait = newTraits[traitLabel];\n\t\t\tif (newTrait === undefined) {\n\t\t\t\tnewTrait = [];\n\t\t\t\tnewTraits[traitLabel] = newTrait;\n\t\t\t}\n\t\t\t(newTrait as (TOut | TPlaceholder)[]).push(convertedChild);\n\t\t}\n\t}\n\n\treturn convertedRoot;\n}\n\n/**\n * Visits an input tree in a depth-first pre-order traversal.\n * @param tree - the input tree\n * @param visitor - callback invoked for each node in the tree.\n */\nexport function walkTree<TIn extends HasVariadicTraits<TIn>>(tree: TIn, visitor: (node: TIn) => void): void;\n\n/**\n * Visits an input tree containing placeholders in a depth-first pre-order traversal.\n * @param tree - the input tree\n * @param visitor - callback invoked for each node in the tree. Must return true if the given node is a TPlaceholder.\n */\nexport function walkTree<TIn extends HasVariadicTraits<TIn | TPlaceholder>, TPlaceholder = never>(\n\ttree: TIn | TPlaceholder,\n\tvisitors:\n\t\t| ((node: TIn) => void)\n\t\t| { nodeVisitor?: (node: TIn) => void; placeholderVisitor?: (placeholder: TPlaceholder) => void },\n\tisPlaceholder: (node: TIn | TPlaceholder) => node is TPlaceholder\n): void;\n\nexport function walkTree<TIn extends HasVariadicTraits<TIn | TPlaceholder>, TPlaceholder = never>(\n\ttree: TIn | TPlaceholder,\n\tvisitors:\n\t\t| ((node: TIn) => void)\n\t\t| { nodeVisitor?: (node: TIn) => void; placeholderVisitor?: (placeholder: TPlaceholder) => void },\n\tisPlaceholder?: (node: TIn | TPlaceholder) => node is TPlaceholder\n): void {\n\tconst nodeVisitor = typeof visitors === 'function' ? visitors : visitors.nodeVisitor;\n\tconst placeholderVisitor = typeof visitors === 'object' ? visitors.placeholderVisitor : undefined;\n\tif (isKnownType(tree, isPlaceholder)) {\n\t\tplaceholderVisitor?.(tree);\n\t\treturn;\n\t}\n\tnodeVisitor?.(tree);\n\n\tconst childIterators: Iterator<[TraitLabel, TIn | TPlaceholder]>[] = [iterateChildren(tree)[Symbol.iterator]()];\n\n\twhile (childIterators.length > 0) {\n\t\tconst childIterator = childIterators[childIterators.length - 1] ?? fail('Undefined node');\n\t\tconst { value, done } = childIterator.next();\n\t\tif (done === true) {\n\t\t\tchildIterators.pop();\n\t\t} else {\n\t\t\tconst [_, child] = value as [TraitLabel, TIn | TPlaceholder];\n\t\t\tif (isKnownType(child, isPlaceholder)) {\n\t\t\t\tplaceholderVisitor?.(child);\n\t\t\t} else {\n\t\t\t\tnodeVisitor?.(child);\n\t\t\t\tchildIterators.push(iterateChildren(child)[Symbol.iterator]());\n\t\t\t}\n\t\t}\n\t}\n}\n\n// Useful for collapsing type checks in `convertTreeNodes` into a single line\nfunction isKnownType<T, Type extends T>(value: T, isType?: (value: T) => value is Type): value is Type {\n\treturn isType?.(value) ?? false;\n}\n\n/**\n * Check if two trees are equivalent, meaning they have the same descendants with the same properties.\n *\n * See {@link comparePayloads} for payload comparison semantics.\n */\nexport function deepCompareNodes(\n\ta: ChangeNode | ChangeNode_0_0_2,\n\tb: ChangeNode | ChangeNode_0_0_2,\n\tcomparator: (\n\t\ta: NodeData<NodeId> | NodeData<StableNodeId>,\n\t\tb: NodeData<NodeId> | NodeData<StableNodeId>\n\t) => boolean = compareNodes\n): boolean {\n\tif (a === b) {\n\t\treturn true;\n\t}\n\n\tif (!comparator(a, b)) {\n\t\treturn false;\n\t}\n\n\tconst traitsA = Object.entries(a.traits);\n\tconst traitsB = Object.entries(b.traits);\n\n\tif (traitsA.length !== traitsB.length) {\n\t\treturn false;\n\t}\n\n\tfor (const [traitLabel, childrenA] of traitsA) {\n\t\tconst childrenB = b.traits[traitLabel];\n\n\t\tif (childrenA.length !== childrenB.length) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst traitsEqual = compareArrays<ChangeNode | ChangeNode_0_0_2>(childrenA, childrenB, (childA, childB) => {\n\t\t\tif (typeof childA === 'number' || typeof childB === 'number') {\n\t\t\t\t// Check if children are DetachedSequenceIds\n\t\t\t\treturn childA === childB;\n\t\t\t}\n\n\t\t\treturn deepCompareNodes(childA, childB);\n\t\t});\n\n\t\tif (!traitsEqual) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\treturn true;\n}\n\n/*\n * Returns true if two nodes have equivalent data and payloads, otherwise false.\n * Does not compare children\n * @param nodes - two or more nodes to compare\n */\nexport function compareNodes(\n\ta: NodeData<NodeId> | NodeData<StableNodeId>,\n\tb: NodeData<NodeId> | NodeData<StableNodeId>\n): boolean {\n\tif (a === b) {\n\t\treturn true;\n\t}\n\n\tif (a.identifier !== b.identifier) {\n\t\treturn false;\n\t}\n\n\tif (a.definition !== b.definition) {\n\t\treturn false;\n\t}\n\n\tif (!comparePayloads(a.payload, b.payload)) {\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n\n/**\n * Compare two views such that semantically equivalent node IDs are considered equal.\n */\nexport function areRevisionViewsSemanticallyEqual(\n\ttreeViewA: TreeView,\n\tidConverterA: NodeIdConverter,\n\ttreeViewB: TreeView,\n\tidConverterB: NodeIdConverter\n): boolean {\n\tconst treeA = getChangeNode_0_0_2FromView(treeViewA, idConverterA);\n\tconst treeB = getChangeNode_0_0_2FromView(treeViewB, idConverterB);\n\tif (!deepCompareNodes(treeA, treeB)) {\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n\n/**\n * Create a sequence of changes that resets the contents of `trait`.\n * @public\n */\nexport function setTrait(trait: TraitLocation, nodes: BuildNode | TreeNodeSequence<BuildNode>): Change[] {\n\tconst id = 0 as DetachedSequenceId;\n\tconst traitContents = StableRange.all(trait);\n\treturn [Change.detach(traitContents), Change.build(nodes, id), Change.insert(id, traitContents.start)];\n}\n\n/**\n * Create a sequence of changes that resets the contents of `trait`.\n * @internal\n */\nexport function setTraitInternal(\n\ttrait: TraitLocationInternal,\n\tnodes: TreeNodeSequence<BuildNodeInternal>\n): ChangeInternal[] {\n\tconst id = 0 as DetachedSequenceId;\n\tconst traitContents = StableRangeInternal.all(trait);\n\treturn [\n\t\tChangeInternal.detach(traitContents),\n\t\tChangeInternal.build(nodes, id),\n\t\tChangeInternal.insert(id, traitContents.start),\n\t];\n}\n\n/**\n * Check the validity of the given `StablePlace`\n * @param view - the `TreeView` within which to validate the given place\n * @param place - the `StablePlace` to check\n */\nexport function validateStablePlace(\n\tview: TreeView,\n\tplace: StablePlaceInternal\n):\n\t| {\n\t\t\tresult: PlaceValidationResult.Valid;\n\t\t\tside: Side;\n\t\t\treferenceSibling: NodeId;\n\t\t\treferenceTrait?: never;\n\t }\n\t| {\n\t\t\tresult: PlaceValidationResult.Valid;\n\t\t\tside: Side;\n\t\t\treferenceSibling?: never;\n\t\t\treferenceTrait: TraitLocation;\n\t }\n\t| { result: Exclude<PlaceValidationResult, PlaceValidationResult.Valid> } {\n\t/* A StablePlace is valid if the following conditions are met:\n\t * 1. A sibling or trait is defined.\n\t * 2. If a sibling is defined, both it and its parent exist in the `TreeView`.\n\t * 3. If a trait is defined, its parent node exists in the `TreeView`.\n\t * 4. If a sibling and a trait location are both specified, the sibling needs to actually be in that trait.\n\t */\n\tconst { referenceSibling, referenceTrait } = place;\n\n\t// A well-formed `StablePlace` specifies exactly one of `referenceSibling` and `referenceTrait`.\n\tif (\n\t\t(referenceSibling === undefined && referenceTrait === undefined) ||\n\t\t(referenceSibling !== undefined && referenceTrait !== undefined)\n\t) {\n\t\treturn { result: PlaceValidationResult.Malformed };\n\t}\n\n\tif (referenceSibling !== undefined) {\n\t\tif (!view.hasNode(referenceSibling)) {\n\t\t\treturn { result: PlaceValidationResult.MissingSibling };\n\t\t}\n\n\t\t// Detached nodes and the root are invalid anchors.\n\t\tif (view.tryGetTraitLabel(referenceSibling) === undefined) {\n\t\t\treturn { result: PlaceValidationResult.SiblingIsRootOrDetached };\n\t\t}\n\n\t\treturn { result: PlaceValidationResult.Valid, side: place.side, referenceSibling };\n\t}\n\n\tif (referenceTrait === undefined) {\n\t\treturn { result: PlaceValidationResult.MissingParent };\n\t}\n\n\tif (!view.hasNode(referenceTrait.parent)) {\n\t\treturn { result: PlaceValidationResult.MissingParent };\n\t}\n\n\treturn { result: PlaceValidationResult.Valid, side: place.side, referenceTrait };\n}\n\n/**\n * The result of validating a place.\n */\nexport enum PlaceValidationResult {\n\tValid = 'Valid',\n\tMalformed = 'Malformed',\n\tSiblingIsRootOrDetached = 'SiblingIsRootOrDetached',\n\tMissingSibling = 'MissingSibling',\n\tMissingParent = 'MissingParent',\n}\n\n/**\n * The result of validating a bad place.\n */\nexport type BadPlaceValidationResult = Exclude<PlaceValidationResult, PlaceValidationResult.Valid>;\n\n/**\n * Check the validity of the given `StableRange`\n * @param view - the `TreeView` within which to validate the given range\n * @param range - the `StableRange` to check\n */\nexport function validateStableRange(\n\tview: TreeView,\n\trange: StableRangeInternal\n):\n\t| { result: RangeValidationResultKind.Valid; start: StablePlaceInternal; end: StablePlaceInternal }\n\t| { result: Exclude<RangeValidationResult, RangeValidationResultKind.Valid> } {\n\t/* A StableRange is valid if the following conditions are met:\n\t * 1. Its start and end places are valid.\n\t * 2. Its start and end places are within the same trait.\n\t * 3. Its start place is before its end place.\n\t */\n\tconst { start, end } = range;\n\n\tconst validatedStart = validateStablePlace(view, start);\n\tif (validatedStart.result !== PlaceValidationResult.Valid) {\n\t\treturn {\n\t\t\tresult: { kind: RangeValidationResultKind.BadPlace, place: start, placeFailure: validatedStart.result },\n\t\t};\n\t}\n\n\tconst validatedEnd = validateStablePlace(view, end);\n\tif (validatedEnd.result !== PlaceValidationResult.Valid) {\n\t\treturn { result: { kind: RangeValidationResultKind.BadPlace, place: end, placeFailure: validatedEnd.result } };\n\t}\n\n\tconst startTraitLocation = validatedStart.referenceTrait || view.getTraitLocation(validatedStart.referenceSibling);\n\tconst endTraitLocation = validatedEnd.referenceTrait || view.getTraitLocation(validatedEnd.referenceSibling);\n\tif (!compareTraits(startTraitLocation, endTraitLocation)) {\n\t\treturn { result: RangeValidationResultKind.PlacesInDifferentTraits };\n\t}\n\n\tconst { start: startPlace, end: endPlace } = rangeFromStableRange(view, {\n\t\tstart: validatedStart,\n\t\tend: validatedEnd,\n\t});\n\tconst startIndex = view.findIndexWithinTrait(startPlace);\n\tconst endIndex = view.findIndexWithinTrait(endPlace);\n\n\tif (startIndex > endIndex) {\n\t\treturn { result: RangeValidationResultKind.Inverted };\n\t}\n\n\treturn { result: RangeValidationResultKind.Valid, start: validatedStart, end: validatedEnd };\n}\n\n/**\n * The kinds of result of validating a range.\n */\nexport enum RangeValidationResultKind {\n\tValid = 'Valid',\n\tBadPlace = 'BadPlace',\n\tPlacesInDifferentTraits = 'PlacesInDifferentTraits',\n\tInverted = 'Inverted',\n}\n\n/**\n * The result of validating a range.\n */\nexport type RangeValidationResult =\n\t| RangeValidationResultKind.Valid\n\t| RangeValidationResultKind.PlacesInDifferentTraits\n\t| RangeValidationResultKind.Inverted\n\t| {\n\t\t\tkind: RangeValidationResultKind.BadPlace;\n\t\t\tplace: StablePlaceInternal;\n\t\t\tplaceFailure: BadPlaceValidationResult;\n\t };\n\n/**\n * The result of validating a bad range.\n */\nexport type BadRangeValidationResult = Exclude<RangeValidationResult, RangeValidationResultKind.Valid>;\n\n/**\n * Check if two TraitLocations are equal.\n */\nfunction compareTraits(traitA: TraitLocation, traitB: TraitLocation): boolean {\n\tif (traitA.label !== traitB.label || traitA.parent !== traitB.parent) {\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n\n/**\n * Parents a set of nodes in a specified location within a trait.\n * @param nodesToInsert - the nodes to parent in the specified place. The nodes must already be present in the TreeView.\n * @param placeToInsert - the location to insert the nodes.\n */\nexport function insertIntoTrait(\n\tview: TransactionView,\n\tnodesToInsert: readonly NodeId[],\n\tplaceToInsert: StablePlace\n): TransactionView {\n\treturn view.attachRange(nodesToInsert, placeFromStablePlace(view, placeToInsert));\n}\n\n/**\n * Detaches a range of nodes from their parent. The detached nodes remain in the TreeView.\n * @param rangeToDetach - the range of nodes to detach\n */\nexport function detachRange(\n\tview: TransactionView,\n\trangeToDetach: StableRange\n): { view: TransactionView; detached: readonly NodeId[] } {\n\treturn view.detachRange(rangeFromStableRange(view, rangeToDetach));\n}\n\n/**\n * Deeply clone the given StablePlace\n */\nexport function deepCloneStablePlace(place: StablePlace): StablePlace {\n\tconst clone: StablePlace = { side: place.side };\n\tcopyPropertyIfDefined(place, clone, 'referenceSibling');\n\tcopyPropertyIfDefined(place, clone, 'referenceTrait');\n\treturn clone;\n}\n\n/**\n * Deeply clone the given StableRange\n */\nexport function deepCloneStableRange(range: StableRange): StableRange {\n\treturn { start: deepCloneStablePlace(range.start), end: deepCloneStablePlace(range.end) };\n}\n\n/** Convert a node used in a Build change into its internal representation */\nexport function internalizeBuildNode(\n\tnodeData: BuildTreeNode,\n\tnodeIdContext: NodeIdContext\n): Omit<TreeNode<BuildNodeInternal, NodeId>, 'traits'> {\n\tconst output = {\n\t\tdefinition: nodeData.definition as Definition,\n\t\tidentifier: nodeData.identifier ?? nodeIdContext.generateNodeId(),\n\t};\n\tcopyPropertyIfDefined(nodeData, output, 'payload');\n\treturn output;\n}\n"]}
package/dist/Forest.js CHANGED
@@ -20,7 +20,7 @@ function isParentedForestNode(node) {
20
20
  const parentedNode = node;
21
21
  const hasParent = parentedNode.parentId !== undefined;
22
22
  const hasTraitParent = parentedNode.traitParent !== undefined;
23
- Common_1.assert(hasParent === hasTraitParent, 'node must have either both parent and traitParent set or neither');
23
+ (0, Common_1.assert)(hasParent === hasTraitParent, 'node must have either both parent and traitParent set or neither');
24
24
  return hasParent;
25
25
  }
26
26
  exports.isParentedForestNode = isParentedForestNode;
@@ -72,12 +72,12 @@ class Forest {
72
72
  for (const node of newNodes) {
73
73
  const { identifier } = node;
74
74
  for (const [traitLabel, trait] of node.traits) {
75
- Common_1.assert(trait.length > 0, 'any trait arrays present in a node must be non-empty');
75
+ (0, Common_1.assert)(trait.length > 0, 'any trait arrays present in a node must be non-empty');
76
76
  for (const childId of trait) {
77
77
  const child = mutableNodes.get(childId);
78
78
  if (child !== undefined) {
79
79
  // A child already exists in the forest, and its parent is now being added
80
- Common_1.assert(!isParentedForestNode(child), 'can not give a child multiple parents');
80
+ (0, Common_1.assert)(!isParentedForestNode(child), 'can not give a child multiple parents');
81
81
  const parentedChild = {
82
82
  definition: child.definition,
83
83
  identifier: child.identifier,
@@ -85,7 +85,7 @@ class Forest {
85
85
  parentId: identifier,
86
86
  traitParent: traitLabel,
87
87
  };
88
- Common_1.copyPropertyIfDefined(child, parentedChild, 'payload');
88
+ (0, Common_1.copyPropertyIfDefined)(child, parentedChild, 'payload');
89
89
  // Overwrite the existing child with its parented version
90
90
  mutableNodes.set(childId, parentedChild);
91
91
  }
@@ -99,11 +99,11 @@ class Forest {
99
99
  // Now add each node to the forest and apply any parentage information that was recorded above
100
100
  for (const node of newNodes) {
101
101
  const parentData = childToParent.get(node.identifier);
102
- Common_1.assert(!mutableNodes.has(node.identifier), 'can not add node with already existing id');
102
+ (0, Common_1.assert)(!mutableNodes.has(node.identifier), 'can not add node with already existing id');
103
103
  if (parentData !== undefined) {
104
104
  // This is a child whom we haven't added yet, but whose parent we already added above. Supply the recorded parentage info.
105
105
  const child = Object.assign({ definition: node.definition, identifier: node.identifier, traits: node.traits }, parentData);
106
- Common_1.copyPropertyIfDefined(node, child, 'payload');
106
+ (0, Common_1.copyPropertyIfDefined)(node, child, 'payload');
107
107
  mutableNodes.set(node.identifier, child);
108
108
  }
109
109
  else {
@@ -125,13 +125,13 @@ class Forest {
125
125
  */
126
126
  attachRangeOfChildren(parentId, label, index, childIds) {
127
127
  var _a;
128
- Common_1.assert(index >= 0, 'invalid attach index');
128
+ (0, Common_1.assert)(index >= 0, 'invalid attach index');
129
129
  const parentNode = this.nodes.get(parentId);
130
- Common_1.assert(parentNode, 'can not insert children under node that does not exist');
130
+ (0, Common_1.assert)(parentNode, 'can not insert children under node that does not exist');
131
131
  const mutableNodes = this.nodes.clone();
132
132
  const traits = new Map(parentNode.traits);
133
133
  const trait = (_a = traits.get(label)) !== null && _a !== void 0 ? _a : [];
134
- Common_1.assert(index <= trait.length, 'invalid attach index');
134
+ (0, Common_1.assert)(index <= trait.length, 'invalid attach index');
135
135
  // If there is nothing to insert, return early.
136
136
  // This is good for performance, but also avoids an edge case where an empty trait could be created (which is an error).
137
137
  if (childIds.length === 0) {
@@ -142,7 +142,7 @@ class Forest {
142
142
  mutableNodes.set(parentId, Object.assign(Object.assign({}, parentNode), { traits }));
143
143
  for (const childId of childIds) {
144
144
  mutableNodes.editRange(childId, childId, true, (_, n) => {
145
- Common_1.assert(!isParentedForestNode(n), 'can not attach node that already has a parent');
145
+ (0, Common_1.assert)(!isParentedForestNode(n), 'can not attach node that already has a parent');
146
146
  const breakVal = {
147
147
  value: Object.assign(Object.assign({}, n), { parentId, traitParent: label }),
148
148
  };
@@ -164,16 +164,16 @@ class Forest {
164
164
  */
165
165
  detachRangeOfChildren(parentId, label, startIndex, endIndex) {
166
166
  var _a;
167
- Common_1.assert(startIndex >= 0 && endIndex >= startIndex, 'invalid detach index range');
167
+ (0, Common_1.assert)(startIndex >= 0 && endIndex >= startIndex, 'invalid detach index range');
168
168
  const parentNode = this.nodes.get(parentId);
169
- Common_1.assert(parentNode, 'can not detach children under node that does not exist');
169
+ (0, Common_1.assert)(parentNode, 'can not detach children under node that does not exist');
170
170
  if (startIndex === endIndex) {
171
171
  return { forest: this, detached: [] };
172
172
  }
173
173
  const mutableNodes = this.nodes.clone();
174
174
  const traits = new Map(parentNode.traits);
175
175
  const trait = (_a = traits.get(label)) !== null && _a !== void 0 ? _a : [];
176
- Common_1.assert(endIndex <= trait.length, 'invalid detach index range');
176
+ (0, Common_1.assert)(endIndex <= trait.length, 'invalid detach index range');
177
177
  const detached = trait.slice(startIndex, endIndex);
178
178
  const newChildren = [...trait.slice(0, startIndex), ...trait.slice(endIndex)];
179
179
  const deleteTrait = newChildren.length === 0;
@@ -193,7 +193,7 @@ class Forest {
193
193
  traits: n.traits,
194
194
  },
195
195
  };
196
- Common_1.copyPropertyIfDefined(n, breakVal.value, 'payload');
196
+ (0, Common_1.copyPropertyIfDefined)(n, breakVal.value, 'payload');
197
197
  return breakVal;
198
198
  });
199
199
  }
@@ -213,7 +213,7 @@ class Forest {
213
213
  // eslint-disable-next-line @rushstack/no-new-null
214
214
  setValue(nodeId, value) {
215
215
  const node = this.nodes.get(nodeId);
216
- Common_1.assert(node, 'can not replace payload for node that does not exist');
216
+ (0, Common_1.assert)(node, 'can not replace payload for node that does not exist');
217
217
  const mutableNodes = this.nodes.clone();
218
218
  const newNode = Object.assign({}, node);
219
219
  if (value !== null) {
@@ -239,7 +239,7 @@ class Forest {
239
239
  */
240
240
  get(id) {
241
241
  var _a;
242
- return (_a = this.nodes.get(id)) !== null && _a !== void 0 ? _a : Common_1.fail('NodeId not found');
242
+ return (_a = this.nodes.get(id)) !== null && _a !== void 0 ? _a : (0, Common_1.fail)('NodeId not found');
243
243
  }
244
244
  /**
245
245
  * @returns the node associated with `id`, or undefined if there is none
@@ -264,8 +264,8 @@ class Forest {
264
264
  }
265
265
  deleteRecursive(mutableNodes, id, deleteChildren) {
266
266
  var _a;
267
- const node = (_a = mutableNodes.get(id)) !== null && _a !== void 0 ? _a : Common_1.fail('node to delete must exist');
268
- Common_1.assert(!isParentedForestNode(node), 'deleted nodes must be unparented');
267
+ const node = (_a = mutableNodes.get(id)) !== null && _a !== void 0 ? _a : (0, Common_1.fail)('node to delete must exist');
268
+ (0, Common_1.assert)(!isParentedForestNode(node), 'deleted nodes must be unparented');
269
269
  mutableNodes.delete(id);
270
270
  for (const trait of node.traits.values()) {
271
271
  for (const childId of trait) {
@@ -277,7 +277,7 @@ class Forest {
277
277
  traits: n.traits,
278
278
  },
279
279
  };
280
- Common_1.copyPropertyIfDefined(n, breakVal.value, 'payload');
280
+ (0, Common_1.copyPropertyIfDefined)(n, breakVal.value, 'payload');
281
281
  return breakVal;
282
282
  });
283
283
  if (deleteChildren) {
@@ -297,18 +297,18 @@ class Forest {
297
297
  if (isParentedForestNode(node)) {
298
298
  const parent = this.get(node.parentId);
299
299
  const trait = parent.traits.get(node.traitParent);
300
- Common_1.assert(trait !== undefined);
301
- Common_1.assert(trait.indexOf(node.identifier) >= 0, 'node is parented incorrectly');
300
+ (0, Common_1.assert)(trait !== undefined);
301
+ (0, Common_1.assert)(trait.indexOf(node.identifier) >= 0, 'node is parented incorrectly');
302
302
  }
303
303
  for (const trait of node.traits.values()) {
304
- Common_1.assert(trait.length > 0, 'trait is present but empty');
304
+ (0, Common_1.assert)(trait.length > 0, 'trait is present but empty');
305
305
  for (const childId of trait) {
306
306
  const child = this.nodes.get(childId);
307
- Common_1.assert(child, 'child in trait is not in forest');
308
- Common_1.assert(isParentedForestNode(child), 'child is not parented');
309
- Common_1.assert(child.parentId === node.identifier, 'child parent pointer is incorrect');
310
- Common_1.assert(!checkedChildren.has(childId), 'the item tree tree must not contain cycles or multi-parented nodes');
311
- Common_1.assert(((_a = child.parentId) !== null && _a !== void 0 ? _a : Common_1.fail('each node must have associated metadata')) === nodeId, 'cached parent is incorrect');
307
+ (0, Common_1.assert)(child, 'child in trait is not in forest');
308
+ (0, Common_1.assert)(isParentedForestNode(child), 'child is not parented');
309
+ (0, Common_1.assert)(child.parentId === node.identifier, 'child parent pointer is incorrect');
310
+ (0, Common_1.assert)(!checkedChildren.has(childId), 'the item tree tree must not contain cycles or multi-parented nodes');
311
+ (0, Common_1.assert)(((_a = child.parentId) !== null && _a !== void 0 ? _a : (0, Common_1.fail)('each node must have associated metadata')) === nodeId, 'cached parent is incorrect');
312
312
  checkedChildren.add(childId);
313
313
  }
314
314
  }
@@ -320,9 +320,9 @@ class Forest {
320
320
  getParent(id) {
321
321
  const child = this.nodes.get(id);
322
322
  if (child === undefined) {
323
- Common_1.fail('NodeId not found');
323
+ (0, Common_1.fail)('NodeId not found');
324
324
  }
325
- Common_1.assert(isParentedForestNode(child), 'Node is not parented');
325
+ (0, Common_1.assert)(isParentedForestNode(child), 'Node is not parented');
326
326
  return { parentId: child.parentId, traitParent: child.traitParent };
327
327
  }
328
328
  /**
@@ -351,7 +351,7 @@ class Forest {
351
351
  if (forest.size !== this.size) {
352
352
  return false;
353
353
  }
354
- return Common_1.compareBtrees(this.nodes, forest.nodes, compareForestNodes);
354
+ return (0, Common_1.compareBtrees)(this.nodes, forest.nodes, compareForestNodes);
355
355
  }
356
356
  /**
357
357
  * Calculate the difference between two forests.
@@ -394,7 +394,7 @@ function compareForestNodes(nodeA, nodeB) {
394
394
  if (nodeA.definition !== nodeB.definition) {
395
395
  return false;
396
396
  }
397
- if (!PayloadUtilities_1.comparePayloads(nodeA.payload, nodeB.payload)) {
397
+ if (!(0, PayloadUtilities_1.comparePayloads)(nodeA.payload, nodeB.payload)) {
398
398
  return false;
399
399
  }
400
400
  if (nodeA.traits.size !== nodeB.traits.size) {
@@ -1 +1 @@
1
- {"version":3,"file":"Forest.js","sourceRoot":"","sources":["../src/Forest.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,gEAAiC;AACj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,KAAK,CAAC,MAAM,CAAC,IAAI,KAAK,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE;QAC5C,OAAO,KAAK,CAAC;KACb;IAED,KAAK,MAAM,MAAM,IAAI,KAAK,CAAC,MAAM,EAAE;QAClC,MAAM,CAAC,WAAW,EAAE,aAAa,CAAC,GAAG,MAAM,CAAC;QAC5C,MAAM,aAAa,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QACpD,IAAI,CAAC,aAAa,EAAE;YACnB,OAAO,KAAK,CAAC;SACb;QAED,IAAI,aAAa,CAAC,MAAM,KAAK,aAAa,CAAC,MAAM,EAAE;YAClD,OAAO,KAAK,CAAC;SACb;QAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAC9C,IAAI,aAAa,CAAC,CAAC,CAAC,KAAK,aAAa,CAAC,CAAC,CAAC,EAAE;gBAC1C,OAAO,KAAK,CAAC;aACb;SACD;KACD;IAED,OAAO,IAAI,CAAC;AACb,CAAC;AAxCD,gDAwCC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport BTree from 'sorted-btree';\nimport { fail, assert, copyPropertyIfDefined, compareBtrees, compareFiniteNumbers } from './Common';\nimport { NodeId, TraitLabel } from './Identifiers';\nimport { comparePayloads } from './PayloadUtilities';\nimport { NodeData, Payload } from './persisted-types';\n\n/**\n * A node that can be contained within a Forest\n *\n * @public\n */\nexport interface ForestNode extends NodeData<NodeId> {\n\treadonly traits: ReadonlyMap<TraitLabel, readonly NodeId[]>;\n}\n\n/**\n * A node within a Forest that has a parent (and is therefore not the root node)\n *\n * @public\n */\nexport interface ParentedForestNode extends ForestNode, ParentData {}\n\n/**\n * Check whether or not the given node in a forest is parented\n *\n * @public\n */\nexport function isParentedForestNode(node: ForestNode): node is ParentedForestNode {\n\tconst parentedNode = node as ForestNode & Partial<ParentedForestNode>;\n\tconst hasParent = parentedNode.parentId !== undefined;\n\tconst hasTraitParent = parentedNode.traitParent !== undefined;\n\tassert(hasParent === hasTraitParent, 'node must have either both parent and traitParent set or neither');\n\treturn hasParent;\n}\n\n/**\n * Information about a ForestNode's parent\n *\n * @public\n */\nexport interface ParentData {\n\treadonly parentId: NodeId;\n\treadonly traitParent: TraitLabel;\n}\n\n/**\n * Differences from one forest to another.\n */\nexport interface Delta<NodeId> {\n\t/**\n\t * Nodes whose content changed.\n\t */\n\treadonly changed: readonly NodeId[];\n\t/**\n\t * Nodes that were added.\n\t */\n\treadonly added: readonly NodeId[];\n\t/**\n\t * Nodes that were removed.\n\t */\n\treadonly removed: readonly NodeId[];\n}\n\ninterface ForestState {\n\tnodes: BTree<NodeId, ForestNode>;\n\texpensiveValidation: boolean;\n}\n\n/**\n * An immutable forest of ForestNode.\n * Enforces single parenting, and allows querying the parent.\n *\n * @public\n */\nexport class Forest {\n\t/**\n\t * Contains the nodes in the forest.\n\t * Used as an immutable data-structure: must not be modified.\n\t */\n\tprivate readonly nodes: BTree<NodeId, ForestNode>;\n\n\t/**\n\t * If true, consistency checks will be applied after forest operations.\n\t */\n\tprivate readonly expensiveValidation: boolean;\n\n\t/**\n\t * Caller must ensure provided BTrees are not modified.\n\t * Will not modify the BTrees.\n\t */\n\tprivate constructor(data: ForestState);\n\n\t/**\n\t * Construct a new forest without reusing nodes from a previous one.\n\t */\n\tprivate constructor(expensiveValidation: boolean);\n\n\tprivate constructor(data?: ForestState | boolean) {\n\t\tif (typeof data === 'object') {\n\t\t\tthis.nodes = data.nodes;\n\t\t\tthis.expensiveValidation = data.expensiveValidation;\n\t\t} else {\n\t\t\tthis.nodes = new BTree<NodeId, ForestNode>(undefined, compareFiniteNumbers);\n\t\t\tthis.expensiveValidation = data ?? false;\n\t\t}\n\t\tif (this.expensiveValidation) {\n\t\t\tthis.assertConsistent();\n\t\t}\n\t}\n\n\t/**\n\t * Creates a new Forest.\n\t */\n\tpublic static create(expensiveValidation = false): Forest {\n\t\treturn new Forest(expensiveValidation);\n\t}\n\n\t/**\n\t * Returns the number of nodes in the forest.\n\t */\n\tpublic get size(): number {\n\t\treturn this.nodes.size;\n\t}\n\n\t/**\n\t * Adds the supplied nodes to the forest. The nodes' IDs must be unique in the forest.\n\t * @param nodes - the sequence of nodes to add to the forest. If any of them have children which exist in the forest already, those\n\t * children will be parented. Any trait arrays present in a node must be non-empty. The nodes may be provided in any order.\n\t */\n\tpublic add(nodes: Iterable<ForestNode>): Forest {\n\t\tconst newNodes = [...nodes];\n\t\tconst mutableNodes = this.nodes.clone();\n\n\t\t// This method iterates through the supplied nodes in two passes, first looking only at children and second actually adding the\n\t\t// nodes. This allows nodes to be passed in any order, e.g. a parent followed by a child or a child followed by a parent.\n\n\t\tconst childToParent = new Map<NodeId, ParentData>(); // Temporarily records the parentage of children that don't exist yet\n\n\t\t// First, inspect the children of each node. If the child is already in the forest, update its parentage. If it is not in the\n\t\t// forest, it may be about to be added in the second loop below so record its parentage temporarily for when that happens.\n\t\tfor (const node of newNodes) {\n\t\t\tconst { identifier } = node;\n\t\t\tfor (const [traitLabel, trait] of node.traits) {\n\t\t\t\tassert(trait.length > 0, 'any trait arrays present in a node must be non-empty');\n\t\t\t\tfor (const childId of trait) {\n\t\t\t\t\tconst child = mutableNodes.get(childId);\n\t\t\t\t\tif (child !== undefined) {\n\t\t\t\t\t\t// A child already exists in the forest, and its parent is now being added\n\t\t\t\t\t\tassert(!isParentedForestNode(child), 'can not give a child multiple parents');\n\t\t\t\t\t\tconst parentedChild = {\n\t\t\t\t\t\t\tdefinition: child.definition,\n\t\t\t\t\t\t\tidentifier: child.identifier,\n\t\t\t\t\t\t\ttraits: child.traits,\n\t\t\t\t\t\t\tparentId: identifier,\n\t\t\t\t\t\t\ttraitParent: traitLabel,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tcopyPropertyIfDefined(child, parentedChild, 'payload');\n\t\t\t\t\t\t// Overwrite the existing child with its parented version\n\t\t\t\t\t\tmutableNodes.set(childId, parentedChild);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// The child hasn't been added yet, so record its parentage to use when it is added below\n\t\t\t\t\t\tchildToParent.set(childId, { parentId: identifier, traitParent: traitLabel });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Now add each node to the forest and apply any parentage information that was recorded above\n\t\tfor (const node of newNodes) {\n\t\t\tconst parentData = childToParent.get(node.identifier);\n\t\t\tassert(!mutableNodes.has(node.identifier), 'can not add node with already existing id');\n\t\t\tif (parentData !== undefined) {\n\t\t\t\t// This is a child whom we haven't added yet, but whose parent we already added above. Supply the recorded parentage info.\n\t\t\t\tconst child = {\n\t\t\t\t\tdefinition: node.definition,\n\t\t\t\t\tidentifier: node.identifier,\n\t\t\t\t\ttraits: node.traits,\n\t\t\t\t\t...parentData,\n\t\t\t\t};\n\t\t\t\tcopyPropertyIfDefined(node, child, 'payload');\n\t\t\t\tmutableNodes.set(node.identifier, child);\n\t\t\t} else {\n\t\t\t\t// This is a node that has no parent. Add it with no parentage information.\n\t\t\t\tmutableNodes.set(node.identifier, node);\n\t\t\t}\n\t\t}\n\n\t\treturn new Forest({\n\t\t\tnodes: mutableNodes,\n\t\t\texpensiveValidation: this.expensiveValidation,\n\t\t});\n\t}\n\n\t/**\n\t * Parents a set of nodes already in the forest at a specified location within a trait.\n\t * @param parentId - the id of the parent under which to insert the new nodes\n\t * @param label - the label of the trait under which to insert the new nodes\n\t * @param index - the index in the trait after which to insert the new nodes\n\t * @param childIds - the ids of the nodes to insert\n\t */\n\tpublic attachRangeOfChildren(\n\t\tparentId: NodeId,\n\t\tlabel: TraitLabel,\n\t\tindex: number,\n\t\tchildIds: readonly NodeId[]\n\t): Forest {\n\t\tassert(index >= 0, 'invalid attach index');\n\t\tconst parentNode = this.nodes.get(parentId);\n\t\tassert(parentNode, 'can not insert children under node that does not exist');\n\t\tconst mutableNodes = this.nodes.clone();\n\t\tconst traits = new Map(parentNode.traits);\n\t\tconst trait = traits.get(label) ?? [];\n\t\tassert(index <= trait.length, 'invalid attach index');\n\n\t\t// If there is nothing to insert, return early.\n\t\t// This is good for performance, but also avoids an edge case where an empty trait could be created (which is an error).\n\t\tif (childIds.length === 0) {\n\t\t\treturn this;\n\t\t}\n\t\tconst newChildren = [...trait.slice(0, index), ...childIds, ...trait.slice(index)];\n\t\ttraits.set(label, newChildren);\n\t\tmutableNodes.set(parentId, { ...parentNode, traits });\n\n\t\tfor (const childId of childIds) {\n\t\t\tmutableNodes.editRange(childId, childId, true, (_, n) => {\n\t\t\t\tassert(!isParentedForestNode(n), 'can not attach node that already has a parent');\n\t\t\t\tconst breakVal: { value: ParentedForestNode } = {\n\t\t\t\t\tvalue: {\n\t\t\t\t\t\t...n,\n\t\t\t\t\t\tparentId,\n\t\t\t\t\t\ttraitParent: label,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t\treturn breakVal;\n\t\t\t});\n\t\t}\n\n\t\treturn new Forest({\n\t\t\tnodes: mutableNodes,\n\t\t\texpensiveValidation: this.expensiveValidation,\n\t\t});\n\t}\n\n\t/**\n\t * Detaches a range of nodes from their parent. The detached nodes remain in the `Forest`.\n\t * @param parentId - the id of the parent from which to detach the nodes\n\t * @param label - the label of the trait from which to detach the nodes\n\t * @param startIndex - the index of the first node in the range to detach\n\t * @param endIndex - the index after the last node in the range to detach\n\t * @returns a new `Forest` with the nodes detached, and a list of the ids of the nodes that were detached\n\t */\n\tpublic detachRangeOfChildren(\n\t\tparentId: NodeId,\n\t\tlabel: TraitLabel,\n\t\tstartIndex: number,\n\t\tendIndex: number\n\t): { forest: Forest; detached: readonly NodeId[] } {\n\t\tassert(startIndex >= 0 && endIndex >= startIndex, 'invalid detach index range');\n\t\tconst parentNode = this.nodes.get(parentId);\n\t\tassert(parentNode, 'can not detach children under node that does not exist');\n\t\tif (startIndex === endIndex) {\n\t\t\treturn { forest: this, detached: [] };\n\t\t}\n\n\t\tconst mutableNodes = this.nodes.clone();\n\t\tconst traits = new Map(parentNode.traits);\n\t\tconst trait = traits.get(label) ?? [];\n\t\tassert(endIndex <= trait.length, 'invalid detach index range');\n\t\tconst detached: NodeId[] = trait.slice(startIndex, endIndex);\n\t\tconst newChildren = [...trait.slice(0, startIndex), ...trait.slice(endIndex)];\n\t\tconst deleteTrait = newChildren.length === 0;\n\t\tif (deleteTrait) {\n\t\t\ttraits.delete(label);\n\t\t} else {\n\t\t\ttraits.set(label, newChildren);\n\t\t}\n\n\t\tmutableNodes.set(parentId, { ...parentNode, traits });\n\t\tfor (const childId of detached) {\n\t\t\tmutableNodes.editRange(childId, childId, true, (_, n) => {\n\t\t\t\tconst breakVal: { value: ForestNode } = {\n\t\t\t\t\tvalue: {\n\t\t\t\t\t\tdefinition: n.definition,\n\t\t\t\t\t\tidentifier: n.identifier,\n\t\t\t\t\t\ttraits: n.traits,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t\tcopyPropertyIfDefined(n, breakVal.value, 'payload');\n\t\t\t\treturn breakVal;\n\t\t\t});\n\t\t}\n\n\t\treturn {\n\t\t\tforest: new Forest({\n\t\t\t\tnodes: mutableNodes,\n\t\t\t\texpensiveValidation: this.expensiveValidation,\n\t\t\t}),\n\t\t\tdetached,\n\t\t};\n\t}\n\n\t/**\n\t * Replaces a node's value. The node must exist in this `Forest`.\n\t * @param nodeId - the id of the node\n\t * @param value - the new value\n\t */\n\t// eslint-disable-next-line @rushstack/no-new-null\n\tpublic setValue(nodeId: NodeId, value: Payload | null): Forest {\n\t\tconst node = this.nodes.get(nodeId);\n\t\tassert(node, 'can not replace payload for node that does not exist');\n\t\tconst mutableNodes = this.nodes.clone();\n\t\tconst newNode = { ...node };\n\t\tif (value !== null) {\n\t\t\tnewNode.payload = value;\n\t\t} else {\n\t\t\tdelete newNode.payload;\n\t\t}\n\t\tmutableNodes.set(nodeId, newNode);\n\t\treturn new Forest({\n\t\t\tnodes: mutableNodes,\n\t\t\texpensiveValidation: this.expensiveValidation,\n\t\t});\n\t}\n\n\t/**\n\t * @returns true if the node associated with `id` exists in this forest, otherwise false\n\t */\n\tpublic has(id: NodeId): boolean {\n\t\treturn this.nodes.has(id);\n\t}\n\n\t/**\n\t * @returns the node associated with `id`. Should not be used if there is no node with the provided id.\n\t */\n\tpublic get(id: NodeId): ForestNode {\n\t\treturn this.nodes.get(id) ?? fail('NodeId not found');\n\t}\n\n\t/**\n\t * @returns the node associated with `id`, or undefined if there is none\n\t */\n\tpublic tryGet(id: NodeId): ForestNode | undefined {\n\t\treturn this.nodes.get(id);\n\t}\n\n\t/**\n\t * Deletes every node in ids (each of which must be unparented)\n\t * @param ids - The IDs of the nodes to delete.\n\t * @param deleteChildren - If true, recursively deletes descendants. Otherwise, leaves children unparented.\n\t */\n\tpublic delete(ids: Iterable<NodeId>, deleteChildren: boolean): Forest {\n\t\tconst mutableNodes = this.nodes.clone();\n\t\tfor (const id of ids) {\n\t\t\tthis.deleteRecursive(mutableNodes, id, deleteChildren);\n\t\t}\n\n\t\treturn new Forest({\n\t\t\tnodes: mutableNodes,\n\t\t\texpensiveValidation: this.expensiveValidation,\n\t\t});\n\t}\n\n\tprivate deleteRecursive(mutableNodes: BTree<NodeId, ForestNode>, id: NodeId, deleteChildren: boolean): void {\n\t\tconst node = mutableNodes.get(id) ?? fail('node to delete must exist');\n\t\tassert(!isParentedForestNode(node), 'deleted nodes must be unparented');\n\t\tmutableNodes.delete(id);\n\t\tfor (const trait of node.traits.values()) {\n\t\t\tfor (const childId of trait) {\n\t\t\t\tmutableNodes.editRange(childId, childId, true, (_, n) => {\n\t\t\t\t\tconst breakVal: { value: ForestNode } = {\n\t\t\t\t\t\tvalue: {\n\t\t\t\t\t\t\tdefinition: n.definition,\n\t\t\t\t\t\t\tidentifier: n.identifier,\n\t\t\t\t\t\t\ttraits: n.traits,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t\tcopyPropertyIfDefined(n, breakVal.value, 'payload');\n\t\t\t\t\treturn breakVal;\n\t\t\t\t});\n\n\t\t\t\tif (deleteChildren) {\n\t\t\t\t\tthis.deleteRecursive(mutableNodes, childId, deleteChildren);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Checks that the metadata is correct, and the items form a forest.\n\t * This is an expensive O(map size) operation.\n\t */\n\tpublic assertConsistent(): void {\n\t\tconst checkedChildren = new Set<NodeId>([]);\n\t\tfor (const [nodeId, node] of this.nodes.entries(undefined, [])) {\n\t\t\tif (isParentedForestNode(node)) {\n\t\t\t\tconst parent = this.get(node.parentId);\n\t\t\t\tconst trait = parent.traits.get(node.traitParent);\n\t\t\t\tassert(trait !== undefined);\n\t\t\t\tassert(trait.indexOf(node.identifier) >= 0, 'node is parented incorrectly');\n\t\t\t}\n\n\t\t\tfor (const trait of node.traits.values()) {\n\t\t\t\tassert(trait.length > 0, 'trait is present but empty');\n\t\t\t\tfor (const childId of trait) {\n\t\t\t\t\tconst child = this.nodes.get(childId);\n\t\t\t\t\tassert(child, 'child in trait is not in forest');\n\t\t\t\t\tassert(isParentedForestNode(child), 'child is not parented');\n\t\t\t\t\tassert(child.parentId === node.identifier, 'child parent pointer is incorrect');\n\t\t\t\t\tassert(\n\t\t\t\t\t\t!checkedChildren.has(childId),\n\t\t\t\t\t\t'the item tree tree must not contain cycles or multi-parented nodes'\n\t\t\t\t\t);\n\t\t\t\t\tassert(\n\t\t\t\t\t\t(child.parentId ?? fail('each node must have associated metadata')) === nodeId,\n\t\t\t\t\t\t'cached parent is incorrect'\n\t\t\t\t\t);\n\t\t\t\t\tcheckedChildren.add(childId);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * @returns the parent of `id`. Should not be used if there is no node with id or if id refers to the root node.\n\t */\n\tpublic getParent(id: NodeId): ParentData {\n\t\tconst child = this.nodes.get(id);\n\t\tif (child === undefined) {\n\t\t\tfail('NodeId not found');\n\t\t}\n\n\t\tassert(isParentedForestNode(child), 'Node is not parented');\n\t\treturn { parentId: child.parentId, traitParent: child.traitParent };\n\t}\n\n\t/**\n\t * @returns undefined iff root, otherwise the parent of `id`.\n\t */\n\tpublic tryGetParent(id: NodeId): ParentData | undefined {\n\t\tconst child = this.nodes.get(id);\n\t\tif (child === undefined || !isParentedForestNode(child)) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn {\n\t\t\tparentId: child.parentId,\n\t\t\ttraitParent: child.traitParent,\n\t\t};\n\t}\n\n\t/**\n\t * Compares two forests for equality.\n\t * @param forest - the other forest to compare to this one\n\t * @param comparator - a function which returns true if two objects of type ForestNode are equivalent, false otherwise\n\t * @returns true iff the forests are equal.\n\t */\n\tpublic equals(forest: Forest): boolean {\n\t\tif (this === forest || this.nodes === forest.nodes) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif (forest.size !== this.size) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn compareBtrees(this.nodes, forest.nodes, compareForestNodes);\n\t}\n\n\t/**\n\t * Calculate the difference between two forests.\n\t * @param forest - the other forest to compare to this one\n\t * @param comparator - a function which returns true if two objects of type ForestNode are equivalent, false otherwise\n\t * @returns A {@link Delta} listing which nodes must be changed, added, and removed to get from `this` to `forest`.\n\t */\n\tpublic delta(forest: Forest): Delta<NodeId> {\n\t\tconst changed: NodeId[] = [];\n\t\tconst removed: NodeId[] = [];\n\t\tconst added: NodeId[] = [];\n\t\tthis.nodes.diffAgainst(\n\t\t\tforest.nodes,\n\t\t\t(id) => {\n\t\t\t\tremoved.push(id);\n\t\t\t},\n\t\t\t(id) => {\n\t\t\t\tadded.push(id);\n\t\t\t},\n\t\t\t(id, nodeThis, nodeOther) => {\n\t\t\t\tif (!compareForestNodes(nodeThis, nodeOther)) {\n\t\t\t\t\tchanged.push(id);\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t\treturn {\n\t\t\tchanged,\n\t\t\tadded,\n\t\t\tremoved,\n\t\t};\n\t}\n}\n\n/**\n * @returns true iff two `ForestNodes` are equivalent.\n * May return false for nodes they contain equivalent payloads encoded differently.\n */\nexport function compareForestNodes(nodeA: ForestNode, nodeB: ForestNode): boolean {\n\tif (nodeA === nodeB) {\n\t\treturn true;\n\t}\n\n\tif (nodeA.identifier !== nodeB.identifier) {\n\t\treturn false;\n\t}\n\n\tif (nodeA.definition !== nodeB.definition) {\n\t\treturn false;\n\t}\n\n\tif (!comparePayloads(nodeA.payload, nodeB.payload)) {\n\t\treturn false;\n\t}\n\n\tif (nodeA.traits.size !== nodeB.traits.size) {\n\t\treturn false;\n\t}\n\n\tfor (const traitA of nodeA.traits) {\n\t\tconst [traitLabelA, nodeSequenceA] = traitA;\n\t\tconst nodeSequenceB = nodeB.traits.get(traitLabelA);\n\t\tif (!nodeSequenceB) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (nodeSequenceA.length !== nodeSequenceB.length) {\n\t\t\treturn false;\n\t\t}\n\n\t\tfor (let i = 0; i < nodeSequenceA.length; i++) {\n\t\t\tif (nodeSequenceA[i] !== nodeSequenceB[i]) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn true;\n}\n"]}
1
+ {"version":3,"file":"Forest.js","sourceRoot":"","sources":["../src/Forest.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,gEAAiC;AACjC,qCAAoG;AAEpG,yDAAqD;AAmBrD;;;;GAIG;AACH,SAAgB,oBAAoB,CAAC,IAAgB;IACpD,MAAM,YAAY,GAAG,IAAgD,CAAC;IACtE,MAAM,SAAS,GAAG,YAAY,CAAC,QAAQ,KAAK,SAAS,CAAC;IACtD,MAAM,cAAc,GAAG,YAAY,CAAC,WAAW,KAAK,SAAS,CAAC;IAC9D,IAAA,eAAM,EAAC,SAAS,KAAK,cAAc,EAAE,kEAAkE,CAAC,CAAC;IACzG,OAAO,SAAS,CAAC;AAClB,CAAC;AAND,oDAMC;AAmCD;;;;;GAKG;AACH,MAAa,MAAM;IAuBlB,YAAoB,IAA4B;QAC/C,IAAI,OAA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AM,CAAC;QAC5C,MAAM,aAAa,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QACpD,IAAI,CAAC,aAAa,EAAE;YACnB,OAAO,KAAK,CAAC;SACb;QAED,IAAI,aAAa,CAAC,MAAM,KAAK,aAAa,CAAC,MAAM,EAAE;YAClD,OAAO,KAAK,CAAC;SACb;QAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAC9C,IAAI,aAAa,CAAC,CAAC,CAAC,KAAK,aAAa,CAAC,CAAC,CAAC,EAAE;gBAC1C,OAAO,KAAK,CAAC;aACb;SACD;KACD;IAED,OAAO,IAAI,CAAC;AACb,CAAC;AAxCD,gDAwCC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport BTree from 'sorted-btree';\nimport { fail, assert, copyPropertyIfDefined, compareBtrees, compareFiniteNumbers } from './Common';\nimport { NodeId, TraitLabel } from './Identifiers';\nimport { comparePayloads } from './PayloadUtilities';\nimport { NodeData, Payload } from './persisted-types';\n\n/**\n * A node that can be contained within a Forest\n *\n * @public\n */\nexport interface ForestNode extends NodeData<NodeId> {\n\treadonly traits: ReadonlyMap<TraitLabel, readonly NodeId[]>;\n}\n\n/**\n * A node within a Forest that has a parent (and is therefore not the root node)\n *\n * @public\n */\nexport interface ParentedForestNode extends ForestNode, ParentData {}\n\n/**\n * Check whether or not the given node in a forest is parented\n *\n * @public\n */\nexport function isParentedForestNode(node: ForestNode): node is ParentedForestNode {\n\tconst parentedNode = node as ForestNode & Partial<ParentedForestNode>;\n\tconst hasParent = parentedNode.parentId !== undefined;\n\tconst hasTraitParent = parentedNode.traitParent !== undefined;\n\tassert(hasParent === hasTraitParent, 'node must have either both parent and traitParent set or neither');\n\treturn hasParent;\n}\n\n/**\n * Information about a ForestNode's parent\n *\n * @public\n */\nexport interface ParentData {\n\treadonly parentId: NodeId;\n\treadonly traitParent: TraitLabel;\n}\n\n/**\n * Differences from one forest to another.\n */\nexport interface Delta<NodeId> {\n\t/**\n\t * Nodes whose content changed.\n\t */\n\treadonly changed: readonly NodeId[];\n\t/**\n\t * Nodes that were added.\n\t */\n\treadonly added: readonly NodeId[];\n\t/**\n\t * Nodes that were removed.\n\t */\n\treadonly removed: readonly NodeId[];\n}\n\ninterface ForestState {\n\tnodes: BTree<NodeId, ForestNode>;\n\texpensiveValidation: boolean;\n}\n\n/**\n * An immutable forest of ForestNode.\n * Enforces single parenting, and allows querying the parent.\n *\n * @public\n */\nexport class Forest {\n\t/**\n\t * Contains the nodes in the forest.\n\t * Used as an immutable data-structure: must not be modified.\n\t */\n\tprivate readonly nodes: BTree<NodeId, ForestNode>;\n\n\t/**\n\t * If true, consistency checks will be applied after forest operations.\n\t */\n\tprivate readonly expensiveValidation: boolean;\n\n\t/**\n\t * Caller must ensure provided BTrees are not modified.\n\t * Will not modify the BTrees.\n\t */\n\tprivate constructor(data: ForestState);\n\n\t/**\n\t * Construct a new forest without reusing nodes from a previous one.\n\t */\n\tprivate constructor(expensiveValidation: boolean);\n\n\tprivate constructor(data?: ForestState | boolean) {\n\t\tif (typeof data === 'object') {\n\t\t\tthis.nodes = data.nodes;\n\t\t\tthis.expensiveValidation = data.expensiveValidation;\n\t\t} else {\n\t\t\tthis.nodes = new BTree<NodeId, ForestNode>(undefined, compareFiniteNumbers);\n\t\t\tthis.expensiveValidation = data ?? false;\n\t\t}\n\t\tif (this.expensiveValidation) {\n\t\t\tthis.assertConsistent();\n\t\t}\n\t}\n\n\t/**\n\t * Creates a new Forest.\n\t */\n\tpublic static create(expensiveValidation = false): Forest {\n\t\treturn new Forest(expensiveValidation);\n\t}\n\n\t/**\n\t * Returns the number of nodes in the forest.\n\t */\n\tpublic get size(): number {\n\t\treturn this.nodes.size;\n\t}\n\n\t/**\n\t * Adds the supplied nodes to the forest. The nodes' IDs must be unique in the forest.\n\t * @param nodes - the sequence of nodes to add to the forest. If any of them have children which exist in the forest already, those\n\t * children will be parented. Any trait arrays present in a node must be non-empty. The nodes may be provided in any order.\n\t */\n\tpublic add(nodes: Iterable<ForestNode>): Forest {\n\t\tconst newNodes = [...nodes];\n\t\tconst mutableNodes = this.nodes.clone();\n\n\t\t// This method iterates through the supplied nodes in two passes, first looking only at children and second actually adding the\n\t\t// nodes. This allows nodes to be passed in any order, e.g. a parent followed by a child or a child followed by a parent.\n\n\t\tconst childToParent = new Map<NodeId, ParentData>(); // Temporarily records the parentage of children that don't exist yet\n\n\t\t// First, inspect the children of each node. If the child is already in the forest, update its parentage. If it is not in the\n\t\t// forest, it may be about to be added in the second loop below so record its parentage temporarily for when that happens.\n\t\tfor (const node of newNodes) {\n\t\t\tconst { identifier } = node;\n\t\t\tfor (const [traitLabel, trait] of node.traits) {\n\t\t\t\tassert(trait.length > 0, 'any trait arrays present in a node must be non-empty');\n\t\t\t\tfor (const childId of trait) {\n\t\t\t\t\tconst child = mutableNodes.get(childId);\n\t\t\t\t\tif (child !== undefined) {\n\t\t\t\t\t\t// A child already exists in the forest, and its parent is now being added\n\t\t\t\t\t\tassert(!isParentedForestNode(child), 'can not give a child multiple parents');\n\t\t\t\t\t\tconst parentedChild = {\n\t\t\t\t\t\t\tdefinition: child.definition,\n\t\t\t\t\t\t\tidentifier: child.identifier,\n\t\t\t\t\t\t\ttraits: child.traits,\n\t\t\t\t\t\t\tparentId: identifier,\n\t\t\t\t\t\t\ttraitParent: traitLabel,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tcopyPropertyIfDefined(child, parentedChild, 'payload');\n\t\t\t\t\t\t// Overwrite the existing child with its parented version\n\t\t\t\t\t\tmutableNodes.set(childId, parentedChild);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// The child hasn't been added yet, so record its parentage to use when it is added below\n\t\t\t\t\t\tchildToParent.set(childId, { parentId: identifier, traitParent: traitLabel });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Now add each node to the forest and apply any parentage information that was recorded above\n\t\tfor (const node of newNodes) {\n\t\t\tconst parentData = childToParent.get(node.identifier);\n\t\t\tassert(!mutableNodes.has(node.identifier), 'can not add node with already existing id');\n\t\t\tif (parentData !== undefined) {\n\t\t\t\t// This is a child whom we haven't added yet, but whose parent we already added above. Supply the recorded parentage info.\n\t\t\t\tconst child = {\n\t\t\t\t\tdefinition: node.definition,\n\t\t\t\t\tidentifier: node.identifier,\n\t\t\t\t\ttraits: node.traits,\n\t\t\t\t\t...parentData,\n\t\t\t\t};\n\t\t\t\tcopyPropertyIfDefined(node, child, 'payload');\n\t\t\t\tmutableNodes.set(node.identifier, child);\n\t\t\t} else {\n\t\t\t\t// This is a node that has no parent. Add it with no parentage information.\n\t\t\t\tmutableNodes.set(node.identifier, node);\n\t\t\t}\n\t\t}\n\n\t\treturn new Forest({\n\t\t\tnodes: mutableNodes,\n\t\t\texpensiveValidation: this.expensiveValidation,\n\t\t});\n\t}\n\n\t/**\n\t * Parents a set of nodes already in the forest at a specified location within a trait.\n\t * @param parentId - the id of the parent under which to insert the new nodes\n\t * @param label - the label of the trait under which to insert the new nodes\n\t * @param index - the index in the trait after which to insert the new nodes\n\t * @param childIds - the ids of the nodes to insert\n\t */\n\tpublic attachRangeOfChildren(\n\t\tparentId: NodeId,\n\t\tlabel: TraitLabel,\n\t\tindex: number,\n\t\tchildIds: readonly NodeId[]\n\t): Forest {\n\t\tassert(index >= 0, 'invalid attach index');\n\t\tconst parentNode = this.nodes.get(parentId);\n\t\tassert(parentNode, 'can not insert children under node that does not exist');\n\t\tconst mutableNodes = this.nodes.clone();\n\t\tconst traits = new Map(parentNode.traits);\n\t\tconst trait = traits.get(label) ?? [];\n\t\tassert(index <= trait.length, 'invalid attach index');\n\n\t\t// If there is nothing to insert, return early.\n\t\t// This is good for performance, but also avoids an edge case where an empty trait could be created (which is an error).\n\t\tif (childIds.length === 0) {\n\t\t\treturn this;\n\t\t}\n\t\tconst newChildren = [...trait.slice(0, index), ...childIds, ...trait.slice(index)];\n\t\ttraits.set(label, newChildren);\n\t\tmutableNodes.set(parentId, { ...parentNode, traits });\n\n\t\tfor (const childId of childIds) {\n\t\t\tmutableNodes.editRange(childId, childId, true, (_, n) => {\n\t\t\t\tassert(!isParentedForestNode(n), 'can not attach node that already has a parent');\n\t\t\t\tconst breakVal: { value: ParentedForestNode } = {\n\t\t\t\t\tvalue: {\n\t\t\t\t\t\t...n,\n\t\t\t\t\t\tparentId,\n\t\t\t\t\t\ttraitParent: label,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t\treturn breakVal;\n\t\t\t});\n\t\t}\n\n\t\treturn new Forest({\n\t\t\tnodes: mutableNodes,\n\t\t\texpensiveValidation: this.expensiveValidation,\n\t\t});\n\t}\n\n\t/**\n\t * Detaches a range of nodes from their parent. The detached nodes remain in the `Forest`.\n\t * @param parentId - the id of the parent from which to detach the nodes\n\t * @param label - the label of the trait from which to detach the nodes\n\t * @param startIndex - the index of the first node in the range to detach\n\t * @param endIndex - the index after the last node in the range to detach\n\t * @returns a new `Forest` with the nodes detached, and a list of the ids of the nodes that were detached\n\t */\n\tpublic detachRangeOfChildren(\n\t\tparentId: NodeId,\n\t\tlabel: TraitLabel,\n\t\tstartIndex: number,\n\t\tendIndex: number\n\t): { forest: Forest; detached: readonly NodeId[] } {\n\t\tassert(startIndex >= 0 && endIndex >= startIndex, 'invalid detach index range');\n\t\tconst parentNode = this.nodes.get(parentId);\n\t\tassert(parentNode, 'can not detach children under node that does not exist');\n\t\tif (startIndex === endIndex) {\n\t\t\treturn { forest: this, detached: [] };\n\t\t}\n\n\t\tconst mutableNodes = this.nodes.clone();\n\t\tconst traits = new Map(parentNode.traits);\n\t\tconst trait = traits.get(label) ?? [];\n\t\tassert(endIndex <= trait.length, 'invalid detach index range');\n\t\tconst detached: NodeId[] = trait.slice(startIndex, endIndex);\n\t\tconst newChildren = [...trait.slice(0, startIndex), ...trait.slice(endIndex)];\n\t\tconst deleteTrait = newChildren.length === 0;\n\t\tif (deleteTrait) {\n\t\t\ttraits.delete(label);\n\t\t} else {\n\t\t\ttraits.set(label, newChildren);\n\t\t}\n\n\t\tmutableNodes.set(parentId, { ...parentNode, traits });\n\t\tfor (const childId of detached) {\n\t\t\tmutableNodes.editRange(childId, childId, true, (_, n) => {\n\t\t\t\tconst breakVal: { value: ForestNode } = {\n\t\t\t\t\tvalue: {\n\t\t\t\t\t\tdefinition: n.definition,\n\t\t\t\t\t\tidentifier: n.identifier,\n\t\t\t\t\t\ttraits: n.traits,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t\tcopyPropertyIfDefined(n, breakVal.value, 'payload');\n\t\t\t\treturn breakVal;\n\t\t\t});\n\t\t}\n\n\t\treturn {\n\t\t\tforest: new Forest({\n\t\t\t\tnodes: mutableNodes,\n\t\t\t\texpensiveValidation: this.expensiveValidation,\n\t\t\t}),\n\t\t\tdetached,\n\t\t};\n\t}\n\n\t/**\n\t * Replaces a node's value. The node must exist in this `Forest`.\n\t * @param nodeId - the id of the node\n\t * @param value - the new value\n\t */\n\t// eslint-disable-next-line @rushstack/no-new-null\n\tpublic setValue(nodeId: NodeId, value: Payload | null): Forest {\n\t\tconst node = this.nodes.get(nodeId);\n\t\tassert(node, 'can not replace payload for node that does not exist');\n\t\tconst mutableNodes = this.nodes.clone();\n\t\tconst newNode = { ...node };\n\t\tif (value !== null) {\n\t\t\tnewNode.payload = value;\n\t\t} else {\n\t\t\tdelete newNode.payload;\n\t\t}\n\t\tmutableNodes.set(nodeId, newNode);\n\t\treturn new Forest({\n\t\t\tnodes: mutableNodes,\n\t\t\texpensiveValidation: this.expensiveValidation,\n\t\t});\n\t}\n\n\t/**\n\t * @returns true if the node associated with `id` exists in this forest, otherwise false\n\t */\n\tpublic has(id: NodeId): boolean {\n\t\treturn this.nodes.has(id);\n\t}\n\n\t/**\n\t * @returns the node associated with `id`. Should not be used if there is no node with the provided id.\n\t */\n\tpublic get(id: NodeId): ForestNode {\n\t\treturn this.nodes.get(id) ?? fail('NodeId not found');\n\t}\n\n\t/**\n\t * @returns the node associated with `id`, or undefined if there is none\n\t */\n\tpublic tryGet(id: NodeId): ForestNode | undefined {\n\t\treturn this.nodes.get(id);\n\t}\n\n\t/**\n\t * Deletes every node in ids (each of which must be unparented)\n\t * @param ids - The IDs of the nodes to delete.\n\t * @param deleteChildren - If true, recursively deletes descendants. Otherwise, leaves children unparented.\n\t */\n\tpublic delete(ids: Iterable<NodeId>, deleteChildren: boolean): Forest {\n\t\tconst mutableNodes = this.nodes.clone();\n\t\tfor (const id of ids) {\n\t\t\tthis.deleteRecursive(mutableNodes, id, deleteChildren);\n\t\t}\n\n\t\treturn new Forest({\n\t\t\tnodes: mutableNodes,\n\t\t\texpensiveValidation: this.expensiveValidation,\n\t\t});\n\t}\n\n\tprivate deleteRecursive(mutableNodes: BTree<NodeId, ForestNode>, id: NodeId, deleteChildren: boolean): void {\n\t\tconst node = mutableNodes.get(id) ?? fail('node to delete must exist');\n\t\tassert(!isParentedForestNode(node), 'deleted nodes must be unparented');\n\t\tmutableNodes.delete(id);\n\t\tfor (const trait of node.traits.values()) {\n\t\t\tfor (const childId of trait) {\n\t\t\t\tmutableNodes.editRange(childId, childId, true, (_, n) => {\n\t\t\t\t\tconst breakVal: { value: ForestNode } = {\n\t\t\t\t\t\tvalue: {\n\t\t\t\t\t\t\tdefinition: n.definition,\n\t\t\t\t\t\t\tidentifier: n.identifier,\n\t\t\t\t\t\t\ttraits: n.traits,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t\tcopyPropertyIfDefined(n, breakVal.value, 'payload');\n\t\t\t\t\treturn breakVal;\n\t\t\t\t});\n\n\t\t\t\tif (deleteChildren) {\n\t\t\t\t\tthis.deleteRecursive(mutableNodes, childId, deleteChildren);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Checks that the metadata is correct, and the items form a forest.\n\t * This is an expensive O(map size) operation.\n\t */\n\tpublic assertConsistent(): void {\n\t\tconst checkedChildren = new Set<NodeId>([]);\n\t\tfor (const [nodeId, node] of this.nodes.entries(undefined, [])) {\n\t\t\tif (isParentedForestNode(node)) {\n\t\t\t\tconst parent = this.get(node.parentId);\n\t\t\t\tconst trait = parent.traits.get(node.traitParent);\n\t\t\t\tassert(trait !== undefined);\n\t\t\t\tassert(trait.indexOf(node.identifier) >= 0, 'node is parented incorrectly');\n\t\t\t}\n\n\t\t\tfor (const trait of node.traits.values()) {\n\t\t\t\tassert(trait.length > 0, 'trait is present but empty');\n\t\t\t\tfor (const childId of trait) {\n\t\t\t\t\tconst child = this.nodes.get(childId);\n\t\t\t\t\tassert(child, 'child in trait is not in forest');\n\t\t\t\t\tassert(isParentedForestNode(child), 'child is not parented');\n\t\t\t\t\tassert(child.parentId === node.identifier, 'child parent pointer is incorrect');\n\t\t\t\t\tassert(\n\t\t\t\t\t\t!checkedChildren.has(childId),\n\t\t\t\t\t\t'the item tree tree must not contain cycles or multi-parented nodes'\n\t\t\t\t\t);\n\t\t\t\t\tassert(\n\t\t\t\t\t\t(child.parentId ?? fail('each node must have associated metadata')) === nodeId,\n\t\t\t\t\t\t'cached parent is incorrect'\n\t\t\t\t\t);\n\t\t\t\t\tcheckedChildren.add(childId);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * @returns the parent of `id`. Should not be used if there is no node with id or if id refers to the root node.\n\t */\n\tpublic getParent(id: NodeId): ParentData {\n\t\tconst child = this.nodes.get(id);\n\t\tif (child === undefined) {\n\t\t\tfail('NodeId not found');\n\t\t}\n\n\t\tassert(isParentedForestNode(child), 'Node is not parented');\n\t\treturn { parentId: child.parentId, traitParent: child.traitParent };\n\t}\n\n\t/**\n\t * @returns undefined iff root, otherwise the parent of `id`.\n\t */\n\tpublic tryGetParent(id: NodeId): ParentData | undefined {\n\t\tconst child = this.nodes.get(id);\n\t\tif (child === undefined || !isParentedForestNode(child)) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn {\n\t\t\tparentId: child.parentId,\n\t\t\ttraitParent: child.traitParent,\n\t\t};\n\t}\n\n\t/**\n\t * Compares two forests for equality.\n\t * @param forest - the other forest to compare to this one\n\t * @param comparator - a function which returns true if two objects of type ForestNode are equivalent, false otherwise\n\t * @returns true iff the forests are equal.\n\t */\n\tpublic equals(forest: Forest): boolean {\n\t\tif (this === forest || this.nodes === forest.nodes) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif (forest.size !== this.size) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn compareBtrees(this.nodes, forest.nodes, compareForestNodes);\n\t}\n\n\t/**\n\t * Calculate the difference between two forests.\n\t * @param forest - the other forest to compare to this one\n\t * @param comparator - a function which returns true if two objects of type ForestNode are equivalent, false otherwise\n\t * @returns A {@link Delta} listing which nodes must be changed, added, and removed to get from `this` to `forest`.\n\t */\n\tpublic delta(forest: Forest): Delta<NodeId> {\n\t\tconst changed: NodeId[] = [];\n\t\tconst removed: NodeId[] = [];\n\t\tconst added: NodeId[] = [];\n\t\tthis.nodes.diffAgainst(\n\t\t\tforest.nodes,\n\t\t\t(id) => {\n\t\t\t\tremoved.push(id);\n\t\t\t},\n\t\t\t(id) => {\n\t\t\t\tadded.push(id);\n\t\t\t},\n\t\t\t(id, nodeThis, nodeOther) => {\n\t\t\t\tif (!compareForestNodes(nodeThis, nodeOther)) {\n\t\t\t\t\tchanged.push(id);\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t\treturn {\n\t\t\tchanged,\n\t\t\tadded,\n\t\t\tremoved,\n\t\t};\n\t}\n}\n\n/**\n * @returns true iff two `ForestNodes` are equivalent.\n * May return false for nodes they contain equivalent payloads encoded differently.\n */\nexport function compareForestNodes(nodeA: ForestNode, nodeB: ForestNode): boolean {\n\tif (nodeA === nodeB) {\n\t\treturn true;\n\t}\n\n\tif (nodeA.identifier !== nodeB.identifier) {\n\t\treturn false;\n\t}\n\n\tif (nodeA.definition !== nodeB.definition) {\n\t\treturn false;\n\t}\n\n\tif (!comparePayloads(nodeA.payload, nodeB.payload)) {\n\t\treturn false;\n\t}\n\n\tif (nodeA.traits.size !== nodeB.traits.size) {\n\t\treturn false;\n\t}\n\n\tfor (const traitA of nodeA.traits) {\n\t\tconst [traitLabelA, nodeSequenceA] = traitA;\n\t\tconst nodeSequenceB = nodeB.traits.get(traitLabelA);\n\t\tif (!nodeSequenceB) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (nodeSequenceA.length !== nodeSequenceB.length) {\n\t\t\treturn false;\n\t\t}\n\n\t\tfor (let i = 0; i < nodeSequenceA.length; i++) {\n\t\t\tif (nodeSequenceA[i] !== nodeSequenceB[i]) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn true;\n}\n"]}