@fluid-experimental/tree 2.21.0 → 2.23.0-323641

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.
@@ -15,8 +15,8 @@ function getIds(range) {
15
15
  let last = ids.last;
16
16
  const overrides = ids;
17
17
  if (overrides.overrides !== undefined) {
18
- first ?? (first = overrides.overrides[0][0]);
19
- last ?? (last = overrides.overrides[overrides.overrides.length - 1][0]);
18
+ first ??= overrides.overrides[0][0];
19
+ last ??= overrides.overrides[overrides.overrides.length - 1][0];
20
20
  }
21
21
  (0, internal_1.assert)(first !== undefined && last !== undefined, 0x656 /* malformed IdCreationRange */);
22
22
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"IdRange.js","sourceRoot":"","sources":["../../src/id-compressor/IdRange.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAI7D,SAAgB,MAAM,CACrB,KAAsB;IAEtB,MAAM,EAAE,GAAG,EAAE,GAAG,KAAK,CAAC;IACtB,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACvB,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,IAAI,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC;IACtB,IAAI,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;IAEpB,MAAM,SAAS,GAAG,GAA4C,CAAC;IAC/D,IAAI,SAAS,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;QACvC,KAAK,KAAL,KAAK,GAAK,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAC;QACpC,IAAI,KAAJ,IAAI,GAAK,SAAS,CAAC,SAAS,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAC;IACjE,CAAC;IAED,IAAA,iBAAM,EAAC,KAAK,KAAK,SAAS,IAAI,IAAI,KAAK,SAAS,EAAE,KAAK,CAAC,+BAA+B,CAAC,CAAC;IAEzF,OAAO;QACN,KAAK;QACL,IAAI;QACJ,SAAS,EAAE,SAAS,CAAC,SAAS;KAC9B,CAAC;AACH,CAAC;AAxBD,wBAwBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from '@fluidframework/core-utils/internal';\n\nimport type { IdCreationRange, UnackedLocalId } from './persisted-types/index.js';\n\nexport function getIds(\n\trange: IdCreationRange\n): { first: UnackedLocalId; last: UnackedLocalId; overrides?: IdCreationRange.Overrides } | undefined {\n\tconst { ids } = range;\n\tif (ids === undefined) {\n\t\treturn undefined;\n\t}\n\n\tlet first = ids.first;\n\tlet last = ids.last;\n\n\tconst overrides = ids as Partial<IdCreationRange.HasOverrides>;\n\tif (overrides.overrides !== undefined) {\n\t\tfirst ??= overrides.overrides[0][0];\n\t\tlast ??= overrides.overrides[overrides.overrides.length - 1][0];\n\t}\n\n\tassert(first !== undefined && last !== undefined, 0x656 /* malformed IdCreationRange */);\n\n\treturn {\n\t\tfirst,\n\t\tlast,\n\t\toverrides: overrides.overrides,\n\t};\n}\n"]}
1
+ {"version":3,"file":"IdRange.js","sourceRoot":"","sources":["../../src/id-compressor/IdRange.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAI7D,SAAgB,MAAM,CACrB,KAAsB;IAEtB,MAAM,EAAE,GAAG,EAAE,GAAG,KAAK,CAAC;IACtB,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACvB,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,IAAI,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC;IACtB,IAAI,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;IAEpB,MAAM,SAAS,GAAG,GAA4C,CAAC;IAC/D,IAAI,SAAS,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;QACvC,KAAK,KAAK,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACpC,IAAI,KAAK,SAAS,CAAC,SAAS,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACjE,CAAC;IAED,IAAA,iBAAM,EAAC,KAAK,KAAK,SAAS,IAAI,IAAI,KAAK,SAAS,EAAE,KAAK,CAAC,+BAA+B,CAAC,CAAC;IAEzF,OAAO;QACN,KAAK;QACL,IAAI;QACJ,SAAS,EAAE,SAAS,CAAC,SAAS;KAC9B,CAAC;AACH,CAAC;AAxBD,wBAwBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from '@fluidframework/core-utils/internal';\n\nimport type { IdCreationRange, UnackedLocalId } from './persisted-types/index.js';\n\nexport function getIds(\n\trange: IdCreationRange\n): { first: UnackedLocalId; last: UnackedLocalId; overrides?: IdCreationRange.Overrides } | undefined {\n\tconst { ids } = range;\n\tif (ids === undefined) {\n\t\treturn undefined;\n\t}\n\n\tlet first = ids.first;\n\tlet last = ids.last;\n\n\tconst overrides = ids as Partial<IdCreationRange.HasOverrides>;\n\tif (overrides.overrides !== undefined) {\n\t\tfirst ??= overrides.overrides[0][0];\n\t\tlast ??= overrides.overrides[overrides.overrides.length - 1][0];\n\t}\n\n\tassert(first !== undefined && last !== undefined, 0x656 /* malformed IdCreationRange */);\n\n\treturn {\n\t\tfirst,\n\t\tlast,\n\t\toverrides: overrides.overrides,\n\t};\n}\n"]}
package/lib/TreeView.js CHANGED
@@ -145,7 +145,7 @@ export class TreeView {
145
145
  if (trait.length === 0) {
146
146
  return foundIndex;
147
147
  }
148
- this.traitIndicesCache ?? (this.traitIndicesCache = new Map());
148
+ this.traitIndicesCache ??= new Map();
149
149
  for (let i = 0; i < trait.length; i++) {
150
150
  const nodeInTrait = trait[i];
151
151
  const index = i;
@@ -1 +1 @@
1
- {"version":3,"file":"TreeView.js","sourceRoot":"","sources":["../src/TreeView.ts"],"names":[],"m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AAG,KAAK,CAAe,CAAC;AACrC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from '@fluidframework/core-utils/internal';\n\nimport { copyPropertyIfDefined, fail } from './Common.js';\nimport { Delta, Forest, isParentedForestNode } from './Forest.js';\nimport { NodeId, TraitLabel } from './Identifiers.js';\nimport { NodeData, Side } from './persisted-types/index.js';\n\n/**\n * Specifies the location of a trait (a labeled sequence of nodes) within the tree.\n * @alpha\n */\nexport interface TraitLocation {\n\treadonly parent: NodeId;\n\treadonly label: TraitLabel;\n}\n\n/**\n * An immutable view of a distributed tree node.\n * @alpha\n */\nexport interface TreeViewNode extends NodeData<NodeId> {\n\t/** The IDs of the children under this node */\n\treadonly traits: ReadonlyMap<TraitLabel, readonly NodeId[]>;\n\t/** The parent and trait under which this node resides. Undefined iff this is the root node of the tree (i.e. {@link initialTree}). */\n\treadonly parentage?: TraitLocation;\n}\n\n/**\n * Index of a place within a trait.\n * 0 = before all nodes,\n * 1 = after first node,\n * etc.\n * @alpha\n */\nexport type PlaceIndex = number & { readonly PlaceIndex: unique symbol };\n\n/**\n * Index of a node within a trait.\n * 0 = first node,\n * 1 = second node,\n * etc.\n * @alpha\n */\nexport type TraitNodeIndex = number & { readonly TraitNodeIndex: unique symbol };\n\n/**\n * A place within a particular `TreeView` that is anchored relative to a specific node in the tree, or relative to the outside of the trait.\n * Valid iff 'trait' is valid and, if provided, sibling is in the Location specified by 'trait'.\n * @alpha\n */\nexport interface TreeViewPlace {\n\treadonly sibling?: NodeId;\n\treadonly side: Side;\n\treadonly trait: TraitLocation;\n}\n\n/**\n * Specifies the range of nodes from `start` to `end` within a trait within a particular `TreeView`.\n * Valid iff start and end are valid and are within the same trait.\n * @alpha\n */\nexport interface TreeViewRange {\n\treadonly start: TreeViewPlace;\n\treadonly end: TreeViewPlace;\n}\n\n/**\n * Contains some redundant information. Use only in computations between edits. Do not store.\n * @internal\n */\nexport interface NodeInTrait {\n\treadonly trait: TraitLocation;\n\treadonly index: TraitNodeIndex;\n}\n\n/**\n * A view of a distributed tree.\n * @alpha\n */\nexport abstract class TreeView {\n\tpublic readonly root: NodeId;\n\tprotected readonly forest: Forest;\n\tprivate readonly rootNode: TreeViewNode;\n\n\t/**\n\t * A cache of node's index within their parent trait.\n\t * Used to avoid redundant linear scans of traits.\n\t * Not shared across views; initialized to empty each time a TreeView is created.\n\t */\n\tprivate traitIndicesCache?: Map<NodeId, TraitNodeIndex>;\n\n\tprotected constructor(root: NodeId, forest: Forest) {\n\t\tthis.root = root;\n\t\tthis.forest = forest;\n\t\tthis.rootNode = this.getViewNode(root);\n\t}\n\n\t/** @returns the number of nodes in this view */\n\tpublic get size(): number {\n\t\treturn this.forest.size;\n\t}\n\n\t/** @returns true iff a node with the given id exists in this view */\n\tpublic hasNode(id: NodeId): boolean {\n\t\treturn this.forest.has(id);\n\t}\n\n\t/**\n\t * @returns the index just after place (which specifies a location between items).\n\t * Performance note: this is O(siblings in trait).\n\t */\n\tpublic findIndexWithinTrait(place: TreeViewPlace): PlaceIndex {\n\t\tif (place.sibling === undefined) {\n\t\t\treturn this.getIndexOfSide(place.side, place.trait);\n\t\t}\n\t\treturn getIndex(place.side, this.getIndexInTrait(place.sibling));\n\t}\n\n\t/** @returns the node associated with the given id in this view. Fails if the node does not exist in this view. */\n\tpublic getViewNode(id: NodeId): TreeViewNode {\n\t\treturn this.tryGetViewNode(id) ?? fail('NodeId not found');\n\t}\n\n\t/** @returns the node associated with the given id in this view, or undefined if the node does not exist in this view */\n\tpublic tryGetViewNode(id: NodeId): TreeViewNode | undefined {\n\t\tconst forestNode = this.forest.tryGet(id);\n\t\tif (forestNode !== undefined && isParentedForestNode(forestNode)) {\n\t\t\tconst viewNode: TreeViewNode = {\n\t\t\t\tdefinition: forestNode.definition,\n\t\t\t\tidentifier: forestNode.identifier,\n\t\t\t\ttraits: forestNode.traits,\n\t\t\t\tparentage: {\n\t\t\t\t\tlabel: forestNode.traitParent,\n\t\t\t\t\tparent: forestNode.parentId,\n\t\t\t\t},\n\t\t\t};\n\t\t\tcopyPropertyIfDefined(forestNode, viewNode, 'payload');\n\t\t\treturn viewNode;\n\t\t}\n\n\t\treturn forestNode;\n\t}\n\n\t/**\n\t * @returns the label of the trait under which a node with the given id resides. Fails if the node does not exist in this view or if\n\t * it is the root node.\n\t */\n\tpublic getTraitLabel(id: NodeId): TraitLabel {\n\t\treturn this.forest.getParent(id).traitParent;\n\t}\n\n\t/**\n\t * @returns the label of the trait under which a node with the given id resides, or undefined if the node is not present in this\n\t * view or if it is the root node\n\t */\n\tpublic tryGetTraitLabel(id: NodeId): TraitLabel | undefined {\n\t\treturn this.forest.tryGetParent(id)?.traitParent;\n\t}\n\n\t/**\n\t * @returns the parent of the node with the given id. Fails if the node does not exist in this view or if it is the root node.\n\t */\n\tpublic getParentViewNode(id: NodeId): TreeViewNode {\n\t\tconst parentInfo = this.forest.getParent(id);\n\t\treturn this.getViewNode(parentInfo.parentId);\n\t}\n\n\t/**\n\t * @returns the parent of the node with the given id. Returns undefined if the node does not exist in this view or if it is the root\n\t * node.\n\t */\n\tpublic tryGetParentViewNode(id: NodeId): TreeViewNode | undefined {\n\t\tconst parentInfo = this.forest.tryGetParent(id);\n\t\tif (parentInfo === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn this.getViewNode(parentInfo.parentId);\n\t}\n\n\t/**\n\t * @returns the trait location of the node with the given id. Fails if the node does not exist in this view or of it is the root\n\t * node\n\t */\n\tpublic getTraitLocation(id: NodeId): TraitLocation {\n\t\tconst parentData = this.forest.getParent(id);\n\t\treturn {\n\t\t\tparent: parentData.parentId,\n\t\t\tlabel: parentData.traitParent,\n\t\t};\n\t}\n\n\t/**\n\t * @returns the trait location of the node with the given id, or undefined if the node does not exist in this view or if it is the root\n\t * node\n\t */\n\tpublic tryGetTraitLocation(id: NodeId): TraitLocation | undefined {\n\t\tconst parentData = this.forest.tryGetParent(id);\n\t\tif (parentData === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn {\n\t\t\tparent: parentData.parentId,\n\t\t\tlabel: parentData.traitParent,\n\t\t};\n\t}\n\n\t/**\n\t * @returns the index within the trait under which the node with the given id resides. The node must exist in this view and must have a\n\t * parent.\n\t * Performance note: this is O(siblings in trait).\n\t */\n\tpublic getIndexInTrait(id: NodeId): TraitNodeIndex {\n\t\tconst index = this.tryGetIndexInTrait(id);\n\t\treturn index ?? fail('ID does not exist in the forest.');\n\t}\n\n\t/**\n\t * @returns the index within the trait under which the node with the given id resides, or undefined if the node does not exist in this\n\t * view or does not have a parent.\n\t * Performance note: this is O(siblings in trait).\n\t */\n\tpublic tryGetIndexInTrait(id: NodeId): TraitNodeIndex | undefined {\n\t\tconst cachedIndex = this.traitIndicesCache?.get(id);\n\t\tif (cachedIndex !== undefined) {\n\t\t\treturn cachedIndex;\n\t\t}\n\n\t\tconst parentData = this.forest.tryGetParent(id);\n\t\tif (parentData === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst parent = this.forest.tryGet(parentData.parentId);\n\t\tif (parent === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst trait = parent.traits.get(parentData.traitParent) ?? fail('inconsistent forest: trait parent not found');\n\t\tlet foundIndex: TraitNodeIndex | undefined;\n\t\tif (trait.length === 0) {\n\t\t\treturn foundIndex;\n\t\t}\n\n\t\tthis.traitIndicesCache ??= new Map();\n\t\tfor (let i = 0; i < trait.length; i++) {\n\t\t\tconst nodeInTrait = trait[i];\n\t\t\tconst index = i as TraitNodeIndex;\n\t\t\tthis.traitIndicesCache.set(nodeInTrait, index);\n\t\t\tif (nodeInTrait === id) {\n\t\t\t\tfoundIndex = index;\n\t\t\t}\n\t\t}\n\n\t\treturn foundIndex;\n\t}\n\n\t/**\n\t * @returns the trait at the given location. If no such trait exists, returns an empty trait.\n\t */\n\tpublic getTrait(traitLocation: TraitLocation): readonly NodeId[] {\n\t\treturn this.getViewNode(traitLocation.parent).traits.get(traitLocation.label) ?? [];\n\t}\n\n\t/** Asserts that the view's internal state is consistent. Useful for testing/validation. */\n\tpublic assertConsistent(): void {\n\t\tthis.forest.assertConsistent();\n\t}\n\n\tpublic [Symbol.iterator](): IterableIterator<TreeViewNode> {\n\t\treturn this.iterateNodeDescendants(this.rootNode);\n\t}\n\n\t/** @returns true iff the given view is equal to this view */\n\tpublic abstract equals(view: TreeView): boolean;\n\n\t/**\n\t * @returns true iff the given view's forest of nodes is equivalent to this view's forest of nodes\n\t * @param strict - if true, the views' forests must be the same object, otherwise they must merely be equivalent\n\t */\n\tpublic hasEqualForest(view: TreeView, strict = false): boolean {\n\t\tif (this.root === view.root) {\n\t\t\t// TODO:#49100:Perf: make this faster and/or remove use by PrefetchingCheckout.\n\t\t\treturn strict ? this.forest === view.forest : this.forest.equals(view.forest);\n\t\t}\n\n\t\treturn false;\n\t}\n\n\tprivate *iterateNodeDescendants(node: TreeViewNode): IterableIterator<TreeViewNode> {\n\t\tyield node;\n\t\tfor (const label of [...node.traits.keys()].sort()) {\n\t\t\tconst trait = node.traits.get(label);\n\t\t\tfor (const childId of trait ?? fail('Expected trait with label')) {\n\t\t\t\tconst child = this.getViewNode(childId);\n\t\t\t\tyield* this.iterateNodeDescendants(child);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate getIndexOfSide(side: Side, traitLocation: TraitLocation): PlaceIndex {\n\t\treturn side === Side.After ? (0 as PlaceIndex) : (this.getTrait(traitLocation).length as PlaceIndex);\n\t}\n\n\t/**\n\t * Calculate the difference between two `TreeView`s\n\t * @param view - the other view to compare to this one\n\t * @returns A {@link Delta} which nodes must be changed, added, and removed to get from `this` to `view`.\n\t * The views must share a root.\n\t */\n\tpublic delta(view: TreeView): Delta<NodeId> {\n\t\tassert(this.root === view.root, 0x63d /* Delta can only be calculated between views that share a root */);\n\t\treturn this.forest.delta(view.forest);\n\t}\n}\n\nfunction getIndex(side: Side, index: TraitNodeIndex): PlaceIndex {\n\treturn (side +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S,QAAQ,CAAC,IAAU,EAAE,KAAqB;IAClD,OAAO,CAAC,IAAI,GAAG,KAAK,CAAe,CAAC;AACrC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from '@fluidframework/core-utils/internal';\n\nimport { copyPropertyIfDefined, fail } from './Common.js';\nimport { Delta, Forest, isParentedForestNode } from './Forest.js';\nimport { NodeId, TraitLabel } from './Identifiers.js';\nimport { NodeData, Side } from './persisted-types/index.js';\n\n/**\n * Specifies the location of a trait (a labeled sequence of nodes) within the tree.\n * @alpha\n */\nexport interface TraitLocation {\n\treadonly parent: NodeId;\n\treadonly label: TraitLabel;\n}\n\n/**\n * An immutable view of a distributed tree node.\n * @alpha\n */\nexport interface TreeViewNode extends NodeData<NodeId> {\n\t/** The IDs of the children under this node */\n\treadonly traits: ReadonlyMap<TraitLabel, readonly NodeId[]>;\n\t/** The parent and trait under which this node resides. Undefined iff this is the root node of the tree (i.e. {@link initialTree}). */\n\treadonly parentage?: TraitLocation;\n}\n\n/**\n * Index of a place within a trait.\n * 0 = before all nodes,\n * 1 = after first node,\n * etc.\n * @alpha\n */\nexport type PlaceIndex = number & { readonly PlaceIndex: unique symbol };\n\n/**\n * Index of a node within a trait.\n * 0 = first node,\n * 1 = second node,\n * etc.\n * @alpha\n */\nexport type TraitNodeIndex = number & { readonly TraitNodeIndex: unique symbol };\n\n/**\n * A place within a particular `TreeView` that is anchored relative to a specific node in the tree, or relative to the outside of the trait.\n * Valid iff 'trait' is valid and, if provided, sibling is in the Location specified by 'trait'.\n * @alpha\n */\nexport interface TreeViewPlace {\n\treadonly sibling?: NodeId;\n\treadonly side: Side;\n\treadonly trait: TraitLocation;\n}\n\n/**\n * Specifies the range of nodes from `start` to `end` within a trait within a particular `TreeView`.\n * Valid iff start and end are valid and are within the same trait.\n * @alpha\n */\nexport interface TreeViewRange {\n\treadonly start: TreeViewPlace;\n\treadonly end: TreeViewPlace;\n}\n\n/**\n * Contains some redundant information. Use only in computations between edits. Do not store.\n * @internal\n */\nexport interface NodeInTrait {\n\treadonly trait: TraitLocation;\n\treadonly index: TraitNodeIndex;\n}\n\n/**\n * A view of a distributed tree.\n * @alpha\n */\nexport abstract class TreeView {\n\tpublic readonly root: NodeId;\n\tprotected readonly forest: Forest;\n\tprivate readonly rootNode: TreeViewNode;\n\n\t/**\n\t * A cache of node's index within their parent trait.\n\t * Used to avoid redundant linear scans of traits.\n\t * Not shared across views; initialized to empty each time a TreeView is created.\n\t */\n\tprivate traitIndicesCache?: Map<NodeId, TraitNodeIndex>;\n\n\tprotected constructor(root: NodeId, forest: Forest) {\n\t\tthis.root = root;\n\t\tthis.forest = forest;\n\t\tthis.rootNode = this.getViewNode(root);\n\t}\n\n\t/** @returns the number of nodes in this view */\n\tpublic get size(): number {\n\t\treturn this.forest.size;\n\t}\n\n\t/** @returns true iff a node with the given id exists in this view */\n\tpublic hasNode(id: NodeId): boolean {\n\t\treturn this.forest.has(id);\n\t}\n\n\t/**\n\t * @returns the index just after place (which specifies a location between items).\n\t * Performance note: this is O(siblings in trait).\n\t */\n\tpublic findIndexWithinTrait(place: TreeViewPlace): PlaceIndex {\n\t\tif (place.sibling === undefined) {\n\t\t\treturn this.getIndexOfSide(place.side, place.trait);\n\t\t}\n\t\treturn getIndex(place.side, this.getIndexInTrait(place.sibling));\n\t}\n\n\t/** @returns the node associated with the given id in this view. Fails if the node does not exist in this view. */\n\tpublic getViewNode(id: NodeId): TreeViewNode {\n\t\treturn this.tryGetViewNode(id) ?? fail('NodeId not found');\n\t}\n\n\t/** @returns the node associated with the given id in this view, or undefined if the node does not exist in this view */\n\tpublic tryGetViewNode(id: NodeId): TreeViewNode | undefined {\n\t\tconst forestNode = this.forest.tryGet(id);\n\t\tif (forestNode !== undefined && isParentedForestNode(forestNode)) {\n\t\t\tconst viewNode: TreeViewNode = {\n\t\t\t\tdefinition: forestNode.definition,\n\t\t\t\tidentifier: forestNode.identifier,\n\t\t\t\ttraits: forestNode.traits,\n\t\t\t\tparentage: {\n\t\t\t\t\tlabel: forestNode.traitParent,\n\t\t\t\t\tparent: forestNode.parentId,\n\t\t\t\t},\n\t\t\t};\n\t\t\tcopyPropertyIfDefined(forestNode, viewNode, 'payload');\n\t\t\treturn viewNode;\n\t\t}\n\n\t\treturn forestNode;\n\t}\n\n\t/**\n\t * @returns the label of the trait under which a node with the given id resides. Fails if the node does not exist in this view or if\n\t * it is the root node.\n\t */\n\tpublic getTraitLabel(id: NodeId): TraitLabel {\n\t\treturn this.forest.getParent(id).traitParent;\n\t}\n\n\t/**\n\t * @returns the label of the trait under which a node with the given id resides, or undefined if the node is not present in this\n\t * view or if it is the root node\n\t */\n\tpublic tryGetTraitLabel(id: NodeId): TraitLabel | undefined {\n\t\treturn this.forest.tryGetParent(id)?.traitParent;\n\t}\n\n\t/**\n\t * @returns the parent of the node with the given id. Fails if the node does not exist in this view or if it is the root node.\n\t */\n\tpublic getParentViewNode(id: NodeId): TreeViewNode {\n\t\tconst parentInfo = this.forest.getParent(id);\n\t\treturn this.getViewNode(parentInfo.parentId);\n\t}\n\n\t/**\n\t * @returns the parent of the node with the given id. Returns undefined if the node does not exist in this view or if it is the root\n\t * node.\n\t */\n\tpublic tryGetParentViewNode(id: NodeId): TreeViewNode | undefined {\n\t\tconst parentInfo = this.forest.tryGetParent(id);\n\t\tif (parentInfo === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn this.getViewNode(parentInfo.parentId);\n\t}\n\n\t/**\n\t * @returns the trait location of the node with the given id. Fails if the node does not exist in this view or of it is the root\n\t * node\n\t */\n\tpublic getTraitLocation(id: NodeId): TraitLocation {\n\t\tconst parentData = this.forest.getParent(id);\n\t\treturn {\n\t\t\tparent: parentData.parentId,\n\t\t\tlabel: parentData.traitParent,\n\t\t};\n\t}\n\n\t/**\n\t * @returns the trait location of the node with the given id, or undefined if the node does not exist in this view or if it is the root\n\t * node\n\t */\n\tpublic tryGetTraitLocation(id: NodeId): TraitLocation | undefined {\n\t\tconst parentData = this.forest.tryGetParent(id);\n\t\tif (parentData === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn {\n\t\t\tparent: parentData.parentId,\n\t\t\tlabel: parentData.traitParent,\n\t\t};\n\t}\n\n\t/**\n\t * @returns the index within the trait under which the node with the given id resides. The node must exist in this view and must have a\n\t * parent.\n\t * Performance note: this is O(siblings in trait).\n\t */\n\tpublic getIndexInTrait(id: NodeId): TraitNodeIndex {\n\t\tconst index = this.tryGetIndexInTrait(id);\n\t\treturn index ?? fail('ID does not exist in the forest.');\n\t}\n\n\t/**\n\t * @returns the index within the trait under which the node with the given id resides, or undefined if the node does not exist in this\n\t * view or does not have a parent.\n\t * Performance note: this is O(siblings in trait).\n\t */\n\tpublic tryGetIndexInTrait(id: NodeId): TraitNodeIndex | undefined {\n\t\tconst cachedIndex = this.traitIndicesCache?.get(id);\n\t\tif (cachedIndex !== undefined) {\n\t\t\treturn cachedIndex;\n\t\t}\n\n\t\tconst parentData = this.forest.tryGetParent(id);\n\t\tif (parentData === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst parent = this.forest.tryGet(parentData.parentId);\n\t\tif (parent === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst trait = parent.traits.get(parentData.traitParent) ?? fail('inconsistent forest: trait parent not found');\n\t\tlet foundIndex: TraitNodeIndex | undefined;\n\t\tif (trait.length === 0) {\n\t\t\treturn foundIndex;\n\t\t}\n\n\t\tthis.traitIndicesCache ??= new Map();\n\t\tfor (let i = 0; i < trait.length; i++) {\n\t\t\tconst nodeInTrait = trait[i];\n\t\t\tconst index = i as TraitNodeIndex;\n\t\t\tthis.traitIndicesCache.set(nodeInTrait, index);\n\t\t\tif (nodeInTrait === id) {\n\t\t\t\tfoundIndex = index;\n\t\t\t}\n\t\t}\n\n\t\treturn foundIndex;\n\t}\n\n\t/**\n\t * @returns the trait at the given location. If no such trait exists, returns an empty trait.\n\t */\n\tpublic getTrait(traitLocation: TraitLocation): readonly NodeId[] {\n\t\treturn this.getViewNode(traitLocation.parent).traits.get(traitLocation.label) ?? [];\n\t}\n\n\t/** Asserts that the view's internal state is consistent. Useful for testing/validation. */\n\tpublic assertConsistent(): void {\n\t\tthis.forest.assertConsistent();\n\t}\n\n\tpublic [Symbol.iterator](): IterableIterator<TreeViewNode> {\n\t\treturn this.iterateNodeDescendants(this.rootNode);\n\t}\n\n\t/** @returns true iff the given view is equal to this view */\n\tpublic abstract equals(view: TreeView): boolean;\n\n\t/**\n\t * @returns true iff the given view's forest of nodes is equivalent to this view's forest of nodes\n\t * @param strict - if true, the views' forests must be the same object, otherwise they must merely be equivalent\n\t */\n\tpublic hasEqualForest(view: TreeView, strict = false): boolean {\n\t\tif (this.root === view.root) {\n\t\t\t// TODO:#49100:Perf: make this faster and/or remove use by PrefetchingCheckout.\n\t\t\treturn strict ? this.forest === view.forest : this.forest.equals(view.forest);\n\t\t}\n\n\t\treturn false;\n\t}\n\n\tprivate *iterateNodeDescendants(node: TreeViewNode): IterableIterator<TreeViewNode> {\n\t\tyield node;\n\t\tfor (const label of [...node.traits.keys()].sort()) {\n\t\t\tconst trait = node.traits.get(label);\n\t\t\tfor (const childId of trait ?? fail('Expected trait with label')) {\n\t\t\t\tconst child = this.getViewNode(childId);\n\t\t\t\tyield* this.iterateNodeDescendants(child);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate getIndexOfSide(side: Side, traitLocation: TraitLocation): PlaceIndex {\n\t\treturn side === Side.After ? (0 as PlaceIndex) : (this.getTrait(traitLocation).length as PlaceIndex);\n\t}\n\n\t/**\n\t * Calculate the difference between two `TreeView`s\n\t * @param view - the other view to compare to this one\n\t * @returns A {@link Delta} which nodes must be changed, added, and removed to get from `this` to `view`.\n\t * The views must share a root.\n\t */\n\tpublic delta(view: TreeView): Delta<NodeId> {\n\t\tassert(this.root === view.root, 0x63d /* Delta can only be calculated between views that share a root */);\n\t\treturn this.forest.delta(view.forest);\n\t}\n}\n\nfunction getIndex(side: Side, index: TraitNodeIndex): PlaceIndex {\n\treturn (side + index) as PlaceIndex;\n}\n"]}
@@ -507,7 +507,7 @@ export class IdCompressor {
507
507
  (normalizedLastFinalizedLocal - overriddenLocal) -
508
508
  1);
509
509
  }
510
- cluster.overrides ?? (cluster.overrides = new Map());
510
+ cluster.overrides ??= new Map();
511
511
  const inversionKey = IdCompressor.createInversionKey(override);
512
512
  const existingIds = this.getExistingIdsForNewOverride(inversionKey, true);
513
513
  let overrideForCluster;
@@ -833,7 +833,7 @@ export class IdCompressor {
833
833
  return undefined;
834
834
  }
835
835
  const { clusterBase: closestBaseFinalId, cluster: closestCluster } = compressionMapping;
836
- numericUuid ?? (numericUuid = numericUuidFromStableId(inversionKey));
836
+ numericUuid ??= numericUuidFromStableId(inversionKey);
837
837
  const uuidOffset = getPositiveDelta(numericUuid, closestCluster.baseUuid, closestCluster.count - 1);
838
838
  if (uuidOffset !== undefined) {
839
839
  let targetFinalId = (closestBaseFinalId + uuidOffset);
@@ -1140,7 +1140,7 @@ export class IdCompressor {
1140
1140
  if (session.attributionId !== sessionId) {
1141
1141
  // As an optimization, don't include the attributionId if it is its default (the sessionId)
1142
1142
  // Get the index into the array for the given attribution ID. If it doesn't exist, push it onto the array and update the map.
1143
- sessionData.push(getOrCreate(attributionIdToAttributionIndex, session.attributionId, (id) => (serializedAttributionIds ?? (serializedAttributionIds = [])).push(id) - 1));
1143
+ sessionData.push(getOrCreate(attributionIdToAttributionIndex, session.attributionId, (id) => (serializedAttributionIds ??= []).push(id) - 1));
1144
1144
  }
1145
1145
  sessionIdToSessionIndex.set(sessionId, serializedSessions.length);
1146
1146
  serializedSessions.push(sessionData);