@fluid-experimental/tree 2.63.0-358419 → 2.63.0-359461
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditUtilities.js","sourceRoot":"","sources":["../src/EditUtilities.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAAoE;AACpE,+BAAoC;AAEpC,qDAAiH;AACjH,2CAAmE;AAGnE,+DAAwD;AACxD,uDAAqE;AACrE,2EAA0E;AAE1E,iEAAoF;AACpF,yDAeoC;AAEpC;;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,IAAA,SAAM,GAAY,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,CAAC;QACtC,OAAO,IAAI,CAAC;IACb,CAAC;IAED,MAAM,aAAa,GAAG,OAAO,CAAC,IAAI,CAAS,CAAC;IAC5C,kIAAkI;IAClI,MAAM,UAAU,GAAI,IAAwB,KAAK,aAAa,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IAC/F,aAA+B,CAAC,MAAM,GAAG,EAAE,CAAC;IAC7C,MAAM,YAAY,GAGZ,CAAC,EAAE,aAAa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B,oBAAoB,CAAC,KAAkB;IACtD,MAAM,KAAK,GAAgB,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC;IAChD,IAAA,iCAAqB,EAAC,KAAK,EAAE,KAAK,EAAE,kBAAkB,CAAC,CAAC;IACxD,IAAA,iCAAqB,EAAC,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,EAAE,QAAQ,CAAC,UAAU,IAAI,aAAa,CAAC,cAAc,EAAE;KACjE,CAAC;IACF,IAAA,iCAAqB,EAAC,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 { compareArrays } from '@fluidframework/core-utils/internal';\nimport { v4 as uuidv4 } from 'uuid';\n\nimport { BuildNode, BuildTreeNode, Change, HasVariadicTraits, StablePlace, StableRange } from './ChangeTypes.js';\nimport { Mutable, copyPropertyIfDefined, fail } from './Common.js';\nimport { Definition, DetachedSequenceId, EditId, NodeId, StableNodeId, TraitLabel } from './Identifiers.js';\nimport { NodeIdContext, NodeIdConverter } from './NodeIdUtilities.js';\nimport { comparePayloads } from './PayloadUtilities.js';\nimport { TransactionView, iterateChildren } from './RevisionView.js';\nimport { getChangeNode_0_0_2FromView } from './SerializationUtilities.js';\nimport { TraitLocation, TreeView } from './TreeView.js';\nimport { placeFromStablePlace, rangeFromStableRange } from './TreeViewUtilities.js';\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/index.js';\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 = (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| {\n\t\t\t\tnodeVisitor?: (node: TIn) => void;\n\t\t\t\tplaceholderVisitor?: (placeholder: TPlaceholder) => void;\n\t\t },\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| {\n\t\t\t\tnodeVisitor?: (node: TIn) => void;\n\t\t\t\tplaceholderVisitor?: (placeholder: TPlaceholder) => void;\n\t\t },\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 * @internal\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 * @internal\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 * @alpha\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 * @alpha\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| {\n\t\t\tresult: RangeValidationResultKind.Valid;\n\t\t\tstart: StablePlaceInternal;\n\t\t\tend: StablePlaceInternal;\n\t }\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: {\n\t\t\t\tkind: RangeValidationResultKind.BadPlace,\n\t\t\t\tplace: start,\n\t\t\t\tplaceFailure: validatedStart.result,\n\t\t\t},\n\t\t};\n\t}\n\n\tconst validatedEnd = validateStablePlace(view, end);\n\tif (validatedEnd.result !== PlaceValidationResult.Valid) {\n\t\treturn {\n\t\t\tresult: {\n\t\t\t\tkind: RangeValidationResultKind.BadPlace,\n\t\t\t\tplace: end,\n\t\t\t\tplaceFailure: validatedEnd.result,\n\t\t\t},\n\t\t};\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 * @alpha\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 * @alpha\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 * @alpha\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');\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AAK,EAAE,KAAK,EAAE,kBAAkB,CAAC,CAAC;IACxD,IAAA,iCAAqB,EAAC,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,EAAE,QAAQ,CAAC,UAAU,IAAI,aAAa,CAAC,cAAc,EAAE;KACjE,CAAC;IACF,IAAA,iCAAqB,EAAC,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 { compareArrays } from '@fluidframework/core-utils/internal';\nimport { v4 as uuidv4 } from 'uuid';\n\nimport { BuildNode, BuildTreeNode, Change, HasVariadicTraits, StablePlace, StableRange } from './ChangeTypes.js';\nimport { Mutable, copyPropertyIfDefined, fail } from './Common.js';\nimport { Definition, DetachedSequenceId, EditId, NodeId, StableNodeId, TraitLabel } from './Identifiers.js';\nimport { NodeIdContext, NodeIdConverter } from './NodeIdUtilities.js';\nimport { comparePayloads } from './PayloadUtilities.js';\nimport { TransactionView, iterateChildren } from './RevisionView.js';\nimport { getChangeNode_0_0_2FromView } from './SerializationUtilities.js';\nimport { TraitLocation, TreeView } from './TreeView.js';\nimport { placeFromStablePlace, rangeFromStableRange } from './TreeViewUtilities.js';\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/index.js';\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;\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 = (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| {\n\t\t\t\tnodeVisitor?: (node: TIn) => void;\n\t\t\t\tplaceholderVisitor?: (placeholder: TPlaceholder) => void;\n\t\t },\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| {\n\t\t\t\tnodeVisitor?: (node: TIn) => void;\n\t\t\t\tplaceholderVisitor?: (placeholder: TPlaceholder) => void;\n\t\t },\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;\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 * @internal\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 * @internal\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 * @alpha\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 * @alpha\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| {\n\t\t\tresult: RangeValidationResultKind.Valid;\n\t\t\tstart: StablePlaceInternal;\n\t\t\tend: StablePlaceInternal;\n\t }\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: {\n\t\t\t\tkind: RangeValidationResultKind.BadPlace,\n\t\t\t\tplace: start,\n\t\t\t\tplaceFailure: validatedStart.result,\n\t\t\t},\n\t\t};\n\t}\n\n\tconst validatedEnd = validateStablePlace(view, end);\n\tif (validatedEnd.result !== PlaceValidationResult.Valid) {\n\t\treturn {\n\t\t\tresult: {\n\t\t\t\tkind: RangeValidationResultKind.BadPlace,\n\t\t\t\tplace: end,\n\t\t\t\tplaceFailure: validatedEnd.result,\n\t\t\t},\n\t\t};\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 * @alpha\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 * @alpha\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 * @alpha\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/RevisionView.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RevisionView.js","sourceRoot":"","sources":["../src/RevisionView.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,2CAA+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AAED,SAAS,kBAAkB,CAAS,QAA2C;IAC9E,OAAO,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;AAChC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { HasVariadicTraits } from './ChangeTypes.js';\nimport { Mutable, MutableMap, copyPropertyIfDefined, fail } from './Common.js';\nimport { Forest } from './Forest.js';\nimport { NodeId, StableNodeId, TraitLabel } from './Identifiers.js';\nimport { NodeIdConverter } from './NodeIdUtilities.js';\nimport { TreeView, TreeViewNode, TreeViewPlace, TreeViewRange } from './TreeView.js';\nimport { Payload, TreeNode, TreeNodeSequence } from './persisted-types/index.js';\n\n/**\n * An immutable view of a distributed tree.\n * @alpha\n */\nexport class RevisionView extends TreeView {\n\t/**\n\t * Constructs a {@link RevisionView} using the supplied tree.\n\t * @param root - the root of the tree to use as the contents of the {@link RevisionView}\n\t * @param expensiveValidation - whether or not to perform additional validation, e.g. to catch errors when testing\n\t */\n\tpublic static fromTree<T extends TreeNode<T, NodeId>>(root: T, expensiveValidation?: boolean): RevisionView;\n\t/**\n\t * Constructs a {@link RevisionView} using the supplied tree.\n\t * @param root - the root of the tree to use as the contents of the `RevisionView`\n\t * @param idConverter - the {@link NodeIdConverter} that will recompress the IDs the in the tree\n\t * @param expensiveValidation - whether or not to perform additional validation, e.g. to catch errors when testing\n\t */\n\tpublic static fromTree<T extends TreeNode<T, StableNodeId>>(\n\t\troot: T,\n\t\tidConverter: NodeIdConverter,\n\t\texpensiveValidation?: boolean\n\t): RevisionView;\n\n\tpublic static fromTree<T extends TreeNode<T, NodeId> | TreeNode<T, StableNodeId>>(\n\t\troot: T,\n\t\tidConverterOrExpensiveValidation?: NodeIdConverter | boolean,\n\t\texpensiveValidation = false\n\t): RevisionView {\n\t\tif (typeof idConverterOrExpensiveValidation === 'object') {\n\t\t\tconst rootId = idConverterOrExpensiveValidation.convertToNodeId(root.identifier as StableNodeId);\n\n\t\t\tconst treeViewNodes = convertTreeNodesToViewNodes(root, (node) => {\n\t\t\t\tconst identifier = idConverterOrExpensiveValidation.convertToNodeId(node.identifier as StableNodeId);\n\t\t\t\tconst viewNode = {\n\t\t\t\t\tdefinition: node.definition,\n\t\t\t\t\tidentifier,\n\t\t\t\t};\n\t\t\t\tcopyPropertyIfDefined(node, viewNode, 'payload');\n\t\t\t\treturn viewNode;\n\t\t\t});\n\n\t\t\treturn new RevisionView(rootId, Forest.create(expensiveValidation).add(treeViewNodes));\n\t\t} else {\n\t\t\treturn new RevisionView(\n\t\t\t\troot.identifier as NodeId,\n\t\t\t\tForest.create(expensiveValidation).add(\n\t\t\t\t\tconvertTreeNodesToViewNodes(root, (node) => {\n\t\t\t\t\t\tconst viewNode = {\n\t\t\t\t\t\t\tdefinition: node.definition,\n\t\t\t\t\t\t\tidentifier: node.identifier as NodeId,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tcopyPropertyIfDefined(node, viewNode, 'payload');\n\t\t\t\t\t\treturn viewNode;\n\t\t\t\t\t})\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\t}\n\n\t/** Begin a transaction by generating a mutable `TransactionView` from this view */\n\tpublic openForTransaction(): TransactionView {\n\t\treturn new TransactionView(this.root, this.forest);\n\t}\n\n\tpublic equals(view: TreeView): boolean {\n\t\tif (!(view instanceof RevisionView)) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn this.hasEqualForest(view);\n\t}\n}\n\n/**\n * An view of a distributed tree that is part of an ongoing transaction between `RevisionView`s.\n * @alpha\n */\nexport class TransactionView extends TreeView {\n\t/** Conclude a transaction by generating an immutable `RevisionView` from this view */\n\tpublic close(): RevisionView {\n\t\treturn new RevisionView(this.root, this.forest);\n\t}\n\n\t/** Inserts all nodes in a NodeSequence into the view */\n\tpublic addNodes(sequence: Iterable<TreeViewNode>): TransactionView {\n\t\treturn new TransactionView(this.root, this.forest.add(sequence));\n\t}\n\n\t/** Remove all nodes with the given ids from the view */\n\tpublic deleteNodes(nodes: Iterable<NodeId>): TransactionView {\n\t\treturn new TransactionView(this.root, this.forest.delete(nodes, true));\n\t}\n\n\t/**\n\t * Parents a set of detached nodes at a specified place.\n\t * @param nodesToAttach - the nodes to parent in the specified place. The nodes must already be present in the view.\n\t * @param place - the location to insert the nodes.\n\t */\n\tpublic attachRange(nodesToAttach: readonly NodeId[], place: TreeViewPlace): TransactionView {\n\t\tconst { parent, label } = place.trait;\n\t\tconst index = this.findIndexWithinTrait(place);\n\t\treturn new TransactionView(this.root, this.forest.attachRangeOfChildren(parent, label, index, nodesToAttach));\n\t}\n\n\t/**\n\t * Detaches a range of nodes from their parent. The detached nodes remain in the view.\n\t * @param rangeToDetach - the range of nodes to detach\n\t */\n\tpublic detachRange(rangeToDetach: TreeViewRange): {\n\t\tview: TransactionView;\n\t\tdetached: readonly NodeId[];\n\t} {\n\t\tconst { start, end } = rangeToDetach;\n\t\tconst { trait: traitLocation } = start;\n\t\tconst { parent, label } = traitLocation;\n\t\tconst startIndex = this.findIndexWithinTrait(start);\n\t\tconst endIndex = this.findIndexWithinTrait(end);\n\t\tconst { forest, detached } = this.forest.detachRangeOfChildren(parent, label, startIndex, endIndex);\n\t\treturn { view: new TransactionView(this.root, forest), detached };\n\t}\n\n\t/**\n\t * Sets or overwrites a node's value. The node must exist in this view.\n\t * @param nodeId - the id of the node\n\t * @param value - the new value\n\t */\n\tpublic setNodeValue(nodeId: NodeId, value: Payload): TransactionView {\n\t\treturn new TransactionView(this.root, this.forest.setValue(nodeId, value));\n\t}\n\n\tpublic equals(view: TreeView): boolean {\n\t\tif (!(view instanceof TransactionView)) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn this.hasEqualForest(view);\n\t}\n}\n\n/**\n * Transform an input tree into a list of {@link TreeViewNode}s.\n * @param tree - the input tree\n * @param convert - a conversion function that will run on each node in the input tree to produce the output nodes.\n * Returning undefined means that conversion for the given node was impossible, at which time the entire tree conversion will be aborted\n * and return undefined.\n */\nexport function convertTreeNodesToViewNodes<\n\tTIn extends HasVariadicTraits<TIn>,\n\tTOut extends TreeViewNode = TreeViewNode,\n>(root: TIn, convert: (node: TIn) => Omit<TOut, 'traits'>): TOut[];\n\n/**\n * Transform an input tree into a list of {@link TreeViewNode}s.\n * @param tree - the input tree\n * @param convert - a conversion function that will run on each node in the input tree to produce the output nodes.\n */\nexport function convertTreeNodesToViewNodes<\n\tTIn extends HasVariadicTraits<TIn>,\n\tTOut extends TreeViewNode = TreeViewNode,\n>(root: TIn, convert: (node: TIn) => Omit<TOut, 'traits'> | undefined): TOut[] | undefined;\n\n/**\n * Transform an input tree into a list of {@link TreeViewNode}s.\n * @param tree - the input tree\n * @param convert - a conversion function that will run on each node in the input tree to produce the output nodes.\n * Returning undefined means that conversion for the given node was impossible, at which time the entire tree conversion will be aborted\n * and return undefined.\n */\nexport function convertTreeNodesToViewNodes<\n\tTIn extends HasVariadicTraits<TIn>,\n\tTOut extends TreeViewNode = TreeViewNode,\n>(root: TIn, convert: (node: TIn) => Omit<TOut, 'traits'> | undefined): TOut[] | undefined {\n\tconst convertedRoot = convert(root) as Mutable<TOut>;\n\tif (convertedRoot === undefined || root.traits === undefined) {\n\t\treturn undefined;\n\t}\n\t// `convertedRoot` might be the same as `root`, in which case stash the children of `root` before wiping them from `convertedRoot`\n\tconst rootTraits = (root as unknown as TOut) === convertedRoot ? { traits: root.traits } : root;\n\tconvertedRoot.traits = new Map();\n\tconst pendingNodes: {\n\t\tchildIterator: Iterator<[TraitLabel, TIn]>;\n\t\tnewNode: Mutable<TOut>;\n\t}[] = [{ childIterator: iterateChildren(rootTraits)[Symbol.iterator](), newNode: convertedRoot }];\n\tconst resultNodes: TOut[] = [];\n\n\twhile (pendingNodes.length > 0) {\n\t\tconst { childIterator, newNode } = pendingNodes[pendingNodes.length - 1] ?? fail('Undefined node');\n\t\tconst { value, done } = childIterator.next();\n\t\tif (done === true) {\n\t\t\tresultNodes.push(\n\t\t\t\tpendingNodes.pop()?.newNode ?? fail('covertTreeNodesToViewNodes incorrectly coordinated parentage')\n\t\t\t);\n\t\t} else {\n\t\t\tconst [traitLabel, child] = value as [TraitLabel, TIn];\n\t\t\tconst convertedChild = convert(child) as TOut;\n\t\t\tif (convertedChild === undefined) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tif (child.traits !== undefined) {\n\t\t\t\tconst childTraits = (child as unknown as TOut) === convertedChild ? { traits: child.traits } : child;\n\t\t\t\t(convertedChild as Mutable<TOut>).traits = new Map();\n\t\t\t\tpendingNodes.push({\n\t\t\t\t\tchildIterator: iterateChildren(childTraits)[Symbol.iterator](),\n\t\t\t\t\tnewNode: convertedChild,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst newTraits = newNode.traits as MutableMap<TOut['traits']>;\n\t\t\tlet newTrait = newTraits.get(traitLabel);\n\t\t\tif (newTrait === undefined) {\n\t\t\t\tnewTrait = [];\n\t\t\t\tnewTraits.set(traitLabel, newTrait);\n\t\t\t}\n\t\t\t(newTrait as NodeId[]).push(convertedChild.identifier);\n\t\t}\n\t}\n\n\treturn resultNodes;\n}\n\n/**\n * Returns an iterable of the supplied node's traits in a stable order.\n */\nexport function* iterateChildren<T>(hasTraits: HasVariadicTraits<T>): Iterable<[TraitLabel, T]> {\n\tif (hasTraits.traits !== undefined) {\n\t\tfor (const [label, trait] of Object.entries(hasTraits.traits).sort()) {\n\t\t\tif (trait !== undefined) {\n\t\t\t\tif (isTreeNodeSequence(trait)) {\n\t\t\t\t\tfor (const child of trait) {\n\t\t\t\t\t\tyield [label as TraitLabel, child];\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tyield [label as TraitLabel, trait];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction isTreeNodeSequence<TChild>(sequence: TreeNodeSequence<TChild> | TChild): sequence is TreeNodeSequence<TChild> {\n\treturn Array.isArray(sequence);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"RevisionView.js","sourceRoot":"","sources":["../src/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,CAAC;QACF,CAAC;IACF,CAAC;AACF,CAAC;AAdD,0CAcC;AAED,SAAS,kBAAkB,CAAS,QAA2C;IAC9E,OAAO,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;AAChC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { HasVariadicTraits } from './ChangeTypes.js';\nimport { Mutable, MutableMap, copyPropertyIfDefined, fail } from './Common.js';\nimport { Forest } from './Forest.js';\nimport { NodeId, StableNodeId, TraitLabel } from './Identifiers.js';\nimport { NodeIdConverter } from './NodeIdUtilities.js';\nimport { TreeView, TreeViewNode, TreeViewPlace, TreeViewRange } from './TreeView.js';\nimport { Payload, TreeNode, TreeNodeSequence } from './persisted-types/index.js';\n\n/**\n * An immutable view of a distributed tree.\n * @alpha\n */\nexport class RevisionView extends TreeView {\n\t/**\n\t * Constructs a {@link RevisionView} using the supplied tree.\n\t * @param root - the root of the tree to use as the contents of the {@link RevisionView}\n\t * @param expensiveValidation - whether or not to perform additional validation, e.g. to catch errors when testing\n\t */\n\tpublic static fromTree<T extends TreeNode<T, NodeId>>(root: T, expensiveValidation?: boolean): RevisionView;\n\t/**\n\t * Constructs a {@link RevisionView} using the supplied tree.\n\t * @param root - the root of the tree to use as the contents of the `RevisionView`\n\t * @param idConverter - the {@link NodeIdConverter} that will recompress the IDs the in the tree\n\t * @param expensiveValidation - whether or not to perform additional validation, e.g. to catch errors when testing\n\t */\n\tpublic static fromTree<T extends TreeNode<T, StableNodeId>>(\n\t\troot: T,\n\t\tidConverter: NodeIdConverter,\n\t\texpensiveValidation?: boolean\n\t): RevisionView;\n\n\tpublic static fromTree<T extends TreeNode<T, NodeId> | TreeNode<T, StableNodeId>>(\n\t\troot: T,\n\t\tidConverterOrExpensiveValidation?: NodeIdConverter | boolean,\n\t\texpensiveValidation = false\n\t): RevisionView {\n\t\tif (typeof idConverterOrExpensiveValidation === 'object') {\n\t\t\tconst rootId = idConverterOrExpensiveValidation.convertToNodeId(root.identifier as StableNodeId);\n\n\t\t\tconst treeViewNodes = convertTreeNodesToViewNodes(root, (node) => {\n\t\t\t\tconst identifier = idConverterOrExpensiveValidation.convertToNodeId(node.identifier as StableNodeId);\n\t\t\t\tconst viewNode = {\n\t\t\t\t\tdefinition: node.definition,\n\t\t\t\t\tidentifier,\n\t\t\t\t};\n\t\t\t\tcopyPropertyIfDefined(node, viewNode, 'payload');\n\t\t\t\treturn viewNode;\n\t\t\t});\n\n\t\t\treturn new RevisionView(rootId, Forest.create(expensiveValidation).add(treeViewNodes));\n\t\t} else {\n\t\t\treturn new RevisionView(\n\t\t\t\troot.identifier as NodeId,\n\t\t\t\tForest.create(expensiveValidation).add(\n\t\t\t\t\tconvertTreeNodesToViewNodes(root, (node) => {\n\t\t\t\t\t\tconst viewNode = {\n\t\t\t\t\t\t\tdefinition: node.definition,\n\t\t\t\t\t\t\tidentifier: node.identifier as NodeId,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tcopyPropertyIfDefined(node, viewNode, 'payload');\n\t\t\t\t\t\treturn viewNode;\n\t\t\t\t\t})\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\t}\n\n\t/** Begin a transaction by generating a mutable `TransactionView` from this view */\n\tpublic openForTransaction(): TransactionView {\n\t\treturn new TransactionView(this.root, this.forest);\n\t}\n\n\tpublic equals(view: TreeView): boolean {\n\t\tif (!(view instanceof RevisionView)) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn this.hasEqualForest(view);\n\t}\n}\n\n/**\n * An view of a distributed tree that is part of an ongoing transaction between `RevisionView`s.\n * @alpha\n */\nexport class TransactionView extends TreeView {\n\t/** Conclude a transaction by generating an immutable `RevisionView` from this view */\n\tpublic close(): RevisionView {\n\t\treturn new RevisionView(this.root, this.forest);\n\t}\n\n\t/** Inserts all nodes in a NodeSequence into the view */\n\tpublic addNodes(sequence: Iterable<TreeViewNode>): TransactionView {\n\t\treturn new TransactionView(this.root, this.forest.add(sequence));\n\t}\n\n\t/** Remove all nodes with the given ids from the view */\n\tpublic deleteNodes(nodes: Iterable<NodeId>): TransactionView {\n\t\treturn new TransactionView(this.root, this.forest.delete(nodes, true));\n\t}\n\n\t/**\n\t * Parents a set of detached nodes at a specified place.\n\t * @param nodesToAttach - the nodes to parent in the specified place. The nodes must already be present in the view.\n\t * @param place - the location to insert the nodes.\n\t */\n\tpublic attachRange(nodesToAttach: readonly NodeId[], place: TreeViewPlace): TransactionView {\n\t\tconst { parent, label } = place.trait;\n\t\tconst index = this.findIndexWithinTrait(place);\n\t\treturn new TransactionView(this.root, this.forest.attachRangeOfChildren(parent, label, index, nodesToAttach));\n\t}\n\n\t/**\n\t * Detaches a range of nodes from their parent. The detached nodes remain in the view.\n\t * @param rangeToDetach - the range of nodes to detach\n\t */\n\tpublic detachRange(rangeToDetach: TreeViewRange): {\n\t\tview: TransactionView;\n\t\tdetached: readonly NodeId[];\n\t} {\n\t\tconst { start, end } = rangeToDetach;\n\t\tconst { trait: traitLocation } = start;\n\t\tconst { parent, label } = traitLocation;\n\t\tconst startIndex = this.findIndexWithinTrait(start);\n\t\tconst endIndex = this.findIndexWithinTrait(end);\n\t\tconst { forest, detached } = this.forest.detachRangeOfChildren(parent, label, startIndex, endIndex);\n\t\treturn { view: new TransactionView(this.root, forest), detached };\n\t}\n\n\t/**\n\t * Sets or overwrites a node's value. The node must exist in this view.\n\t * @param nodeId - the id of the node\n\t * @param value - the new value\n\t */\n\tpublic setNodeValue(nodeId: NodeId, value: Payload): TransactionView {\n\t\treturn new TransactionView(this.root, this.forest.setValue(nodeId, value));\n\t}\n\n\tpublic equals(view: TreeView): boolean {\n\t\tif (!(view instanceof TransactionView)) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn this.hasEqualForest(view);\n\t}\n}\n\n/**\n * Transform an input tree into a list of {@link TreeViewNode}s.\n * @param tree - the input tree\n * @param convert - a conversion function that will run on each node in the input tree to produce the output nodes.\n * Returning undefined means that conversion for the given node was impossible, at which time the entire tree conversion will be aborted\n * and return undefined.\n */\nexport function convertTreeNodesToViewNodes<\n\tTIn extends HasVariadicTraits<TIn>,\n\tTOut extends TreeViewNode = TreeViewNode,\n>(root: TIn, convert: (node: TIn) => Omit<TOut, 'traits'>): TOut[];\n\n/**\n * Transform an input tree into a list of {@link TreeViewNode}s.\n * @param tree - the input tree\n * @param convert - a conversion function that will run on each node in the input tree to produce the output nodes.\n */\nexport function convertTreeNodesToViewNodes<\n\tTIn extends HasVariadicTraits<TIn>,\n\tTOut extends TreeViewNode = TreeViewNode,\n>(root: TIn, convert: (node: TIn) => Omit<TOut, 'traits'> | undefined): TOut[] | undefined;\n\n/**\n * Transform an input tree into a list of {@link TreeViewNode}s.\n * @param tree - the input tree\n * @param convert - a conversion function that will run on each node in the input tree to produce the output nodes.\n * Returning undefined means that conversion for the given node was impossible, at which time the entire tree conversion will be aborted\n * and return undefined.\n */\nexport function convertTreeNodesToViewNodes<\n\tTIn extends HasVariadicTraits<TIn>,\n\tTOut extends TreeViewNode = TreeViewNode,\n>(root: TIn, convert: (node: TIn) => Omit<TOut, 'traits'> | undefined): TOut[] | undefined {\n\tconst convertedRoot = convert(root) as Mutable<TOut>;\n\tif (convertedRoot === undefined || root.traits === undefined) {\n\t\treturn undefined;\n\t}\n\t// `convertedRoot` might be the same as `root`, in which case stash the children of `root` before wiping them from `convertedRoot`\n\tconst rootTraits = (root as unknown as TOut) === convertedRoot ? { traits: root.traits } : root;\n\tconvertedRoot.traits = new Map();\n\tconst pendingNodes: {\n\t\tchildIterator: Iterator<[TraitLabel, TIn]>;\n\t\tnewNode: Mutable<TOut>;\n\t}[] = [{ childIterator: iterateChildren(rootTraits)[Symbol.iterator](), newNode: convertedRoot }];\n\tconst resultNodes: TOut[] = [];\n\n\twhile (pendingNodes.length > 0) {\n\t\tconst { childIterator, newNode } = pendingNodes[pendingNodes.length - 1] ?? fail('Undefined node');\n\t\tconst { value, done } = childIterator.next();\n\t\tif (done === true) {\n\t\t\tresultNodes.push(\n\t\t\t\tpendingNodes.pop()?.newNode ?? fail('covertTreeNodesToViewNodes incorrectly coordinated parentage')\n\t\t\t);\n\t\t} else {\n\t\t\tconst [traitLabel, child] = value;\n\t\t\tconst convertedChild = convert(child) as TOut;\n\t\t\tif (convertedChild === undefined) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tif (child.traits !== undefined) {\n\t\t\t\tconst childTraits = (child as unknown as TOut) === convertedChild ? { traits: child.traits } : child;\n\t\t\t\t(convertedChild as Mutable<TOut>).traits = new Map();\n\t\t\t\tpendingNodes.push({\n\t\t\t\t\tchildIterator: iterateChildren(childTraits)[Symbol.iterator](),\n\t\t\t\t\tnewNode: convertedChild,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst newTraits = newNode.traits as MutableMap<TOut['traits']>;\n\t\t\tlet newTrait = newTraits.get(traitLabel);\n\t\t\tif (newTrait === undefined) {\n\t\t\t\tnewTrait = [];\n\t\t\t\tnewTraits.set(traitLabel, newTrait);\n\t\t\t}\n\t\t\t(newTrait as NodeId[]).push(convertedChild.identifier);\n\t\t}\n\t}\n\n\treturn resultNodes;\n}\n\n/**\n * Returns an iterable of the supplied node's traits in a stable order.\n */\nexport function* iterateChildren<T>(hasTraits: HasVariadicTraits<T>): Iterable<[TraitLabel, T]> {\n\tif (hasTraits.traits !== undefined) {\n\t\tfor (const [label, trait] of Object.entries(hasTraits.traits).sort()) {\n\t\t\tif (trait !== undefined) {\n\t\t\t\tif (isTreeNodeSequence(trait)) {\n\t\t\t\t\tfor (const child of trait) {\n\t\t\t\t\t\tyield [label as TraitLabel, child];\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tyield [label as TraitLabel, trait];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction isTreeNodeSequence<TChild>(sequence: TreeNodeSequence<TChild> | TChild): sequence is TreeNodeSequence<TChild> {\n\treturn Array.isArray(sequence);\n}\n"]}
|
package/lib/EditUtil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B,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC;AACpE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAkB;IACtD,MAAM,KAAK,GAAgB,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC;IAChD,qBAAqB,CAAC,KAAK,EAAE,KAAK,EAAE,kBAAkB,CAAC,CAAC;IACxD,qBAAqB,CAAC,KAAK,EAAE,KAAK,EAAE,gBAAgB,CAAC,CAAC;IACtD,OAAO,KAAK,CAAC;AACd,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,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;AAED,6EAA6E;AAC7E,MAAM,UAAU,oBAAoB,CACnC,QAAuB,EACvB,aAA4B;IAE5B,MAAM,MAAM,GAAG;QACd,UAAU,EAAE,QAAQ,CAAC,UAAwB;QAC7C,UAAU,EAAE,QAAQ,CAAC,UAAU,IAAI,aAAa,CAAC,cAAc,EAAE;KACjE,CAAC;IACF,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;IACnD,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { compareArrays } from '@fluidframework/core-utils/internal';\nimport { v4 as uuidv4 } from 'uuid';\n\nimport { BuildNode, BuildTreeNode, Change, HasVariadicTraits, StablePlace, StableRange } from './ChangeTypes.js';\nimport { Mutable, copyPropertyIfDefined, fail } from './Common.js';\nimport { Definition, DetachedSequenceId, EditId, NodeId, StableNodeId, TraitLabel } from './Identifiers.js';\nimport { NodeIdContext, NodeIdConverter } from './NodeIdUtilities.js';\nimport { comparePayloads } from './PayloadUtilities.js';\nimport { TransactionView, iterateChildren } from './RevisionView.js';\nimport { getChangeNode_0_0_2FromView } from './SerializationUtilities.js';\nimport { TraitLocation, TreeView } from './TreeView.js';\nimport { placeFromStablePlace, rangeFromStableRange } from './TreeViewUtilities.js';\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/index.js';\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 = (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| {\n\t\t\t\tnodeVisitor?: (node: TIn) => void;\n\t\t\t\tplaceholderVisitor?: (placeholder: TPlaceholder) => void;\n\t\t },\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| {\n\t\t\t\tnodeVisitor?: (node: TIn) => void;\n\t\t\t\tplaceholderVisitor?: (placeholder: TPlaceholder) => void;\n\t\t },\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 * @internal\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 * @internal\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 * @alpha\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 * @alpha\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| {\n\t\t\tresult: RangeValidationResultKind.Valid;\n\t\t\tstart: StablePlaceInternal;\n\t\t\tend: StablePlaceInternal;\n\t }\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: {\n\t\t\t\tkind: RangeValidationResultKind.BadPlace,\n\t\t\t\tplace: start,\n\t\t\t\tplaceFailure: validatedStart.result,\n\t\t\t},\n\t\t};\n\t}\n\n\tconst validatedEnd = validateStablePlace(view, end);\n\tif (validatedEnd.result !== PlaceValidationResult.Valid) {\n\t\treturn {\n\t\t\tresult: {\n\t\t\t\tkind: RangeValidationResultKind.BadPlace,\n\t\t\t\tplace: end,\n\t\t\t\tplaceFailure: validatedEnd.result,\n\t\t\t},\n\t\t};\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 * @alpha\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 * @alpha\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 * @alpha\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,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AACpE,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,EAA4B,MAAM,EAAkC,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACjH,OAAO,EAAW,qBAAqB,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAGnE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAmB,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAE,2BAA2B,EAAE,MAAM,6BAA6B,CAAC;AAE1E,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACpF,OAAO,EAEN,cAAc,EAQd,mBAAmB,GAKnB,MAAM,4BAA4B,CAAC;AAEpC;;GAEG;AAEH;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,OAAe,EAAE,OAAe;IAC5D,8GAA8G;IAC9G,2GAA2G;IAC3G,OAAO,OAAO,KAAK,OAAO,CAAC;AAC5B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,OAAO,CAAQ,OAAyB;IACvD,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,CAAC;AACrC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,SAAS;IACxB,OAAO,MAAM,EAAY,CAAC;AAC3B,CAAC;AAiCD;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAK/B,IAAwB,EACxB,OAAsC,EACtC,aAAkE;IAElE,IAAI,WAAW,CAAC,IAAI,EAAE,aAAa,CAAC,EAAE,CAAC;QACtC,OAAO,IAAI,CAAC;IACb,CAAC;IAED,MA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WAAW,CAAC,oBAAoB,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC;AACpE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAkB;IACtD,MAAM,KAAK,GAAgB,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC;IAChD,qBAAqB,CAAC,KAAK,EAAE,KAAK,EAAE,kBAAkB,CAAC,CAAC;IACxD,qBAAqB,CAAC,KAAK,EAAE,KAAK,EAAE,gBAAgB,CAAC,CAAC;IACtD,OAAO,KAAK,CAAC;AACd,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,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;AAED,6EAA6E;AAC7E,MAAM,UAAU,oBAAoB,CACnC,QAAuB,EACvB,aAA4B;IAE5B,MAAM,MAAM,GAAG;QACd,UAAU,EAAE,QAAQ,CAAC,UAAwB;QAC7C,UAAU,EAAE,QAAQ,CAAC,UAAU,IAAI,aAAa,CAAC,cAAc,EAAE;KACjE,CAAC;IACF,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;IACnD,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { compareArrays } from '@fluidframework/core-utils/internal';\nimport { v4 as uuidv4 } from 'uuid';\n\nimport { BuildNode, BuildTreeNode, Change, HasVariadicTraits, StablePlace, StableRange } from './ChangeTypes.js';\nimport { Mutable, copyPropertyIfDefined, fail } from './Common.js';\nimport { Definition, DetachedSequenceId, EditId, NodeId, StableNodeId, TraitLabel } from './Identifiers.js';\nimport { NodeIdContext, NodeIdConverter } from './NodeIdUtilities.js';\nimport { comparePayloads } from './PayloadUtilities.js';\nimport { TransactionView, iterateChildren } from './RevisionView.js';\nimport { getChangeNode_0_0_2FromView } from './SerializationUtilities.js';\nimport { TraitLocation, TreeView } from './TreeView.js';\nimport { placeFromStablePlace, rangeFromStableRange } from './TreeViewUtilities.js';\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/index.js';\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;\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 = (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| {\n\t\t\t\tnodeVisitor?: (node: TIn) => void;\n\t\t\t\tplaceholderVisitor?: (placeholder: TPlaceholder) => void;\n\t\t },\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| {\n\t\t\t\tnodeVisitor?: (node: TIn) => void;\n\t\t\t\tplaceholderVisitor?: (placeholder: TPlaceholder) => void;\n\t\t },\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;\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 * @internal\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 * @internal\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 * @alpha\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 * @alpha\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| {\n\t\t\tresult: RangeValidationResultKind.Valid;\n\t\t\tstart: StablePlaceInternal;\n\t\t\tend: StablePlaceInternal;\n\t }\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: {\n\t\t\t\tkind: RangeValidationResultKind.BadPlace,\n\t\t\t\tplace: start,\n\t\t\t\tplaceFailure: validatedStart.result,\n\t\t\t},\n\t\t};\n\t}\n\n\tconst validatedEnd = validateStablePlace(view, end);\n\tif (validatedEnd.result !== PlaceValidationResult.Valid) {\n\t\treturn {\n\t\t\tresult: {\n\t\t\t\tkind: RangeValidationResultKind.BadPlace,\n\t\t\t\tplace: end,\n\t\t\t\tplaceFailure: validatedEnd.result,\n\t\t\t},\n\t\t};\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 * @alpha\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 * @alpha\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 * @alpha\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, 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M,KAAK,IAAI,KAAK,EAAE,CAAC;wBAC3B,MAAM,CAAC,KAAmB,EAAE,KAAK,CAAC,CAAC;oBACpC,CAAC;gBACF,CAAC;qBAAM,CAAC;oBACP,MAAM,CAAC,KAAmB,EAAE,KAAK,CAAC,CAAC;gBACpC,CAAC;YACF,CAAC;QACF,CAAC;IACF,CAAC;AACF,CAAC;AAED,SAAS,kBAAkB,CAAS,QAA2C;IAC9E,OAAO,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;AAChC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { HasVariadicTraits } from './ChangeTypes.js';\nimport { Mutable, MutableMap, copyPropertyIfDefined, fail } from './Common.js';\nimport { Forest } from './Forest.js';\nimport { NodeId, StableNodeId, TraitLabel } from './Identifiers.js';\nimport { NodeIdConverter } from './NodeIdUtilities.js';\nimport { TreeView, TreeViewNode, TreeViewPlace, TreeViewRange } from './TreeView.js';\nimport { Payload, TreeNode, TreeNodeSequence } from './persisted-types/index.js';\n\n/**\n * An immutable view of a distributed tree.\n * @alpha\n */\nexport class RevisionView extends TreeView {\n\t/**\n\t * Constructs a {@link RevisionView} using the supplied tree.\n\t * @param root - the root of the tree to use as the contents of the {@link RevisionView}\n\t * @param expensiveValidation - whether or not to perform additional validation, e.g. to catch errors when testing\n\t */\n\tpublic static fromTree<T extends TreeNode<T, NodeId>>(root: T, expensiveValidation?: boolean): RevisionView;\n\t/**\n\t * Constructs a {@link RevisionView} using the supplied tree.\n\t * @param root - the root of the tree to use as the contents of the `RevisionView`\n\t * @param idConverter - the {@link NodeIdConverter} that will recompress the IDs the in the tree\n\t * @param expensiveValidation - whether or not to perform additional validation, e.g. to catch errors when testing\n\t */\n\tpublic static fromTree<T extends TreeNode<T, StableNodeId>>(\n\t\troot: T,\n\t\tidConverter: NodeIdConverter,\n\t\texpensiveValidation?: boolean\n\t): RevisionView;\n\n\tpublic static fromTree<T extends TreeNode<T, NodeId> | TreeNode<T, StableNodeId>>(\n\t\troot: T,\n\t\tidConverterOrExpensiveValidation?: NodeIdConverter | boolean,\n\t\texpensiveValidation = false\n\t): RevisionView {\n\t\tif (typeof idConverterOrExpensiveValidation === 'object') {\n\t\t\tconst rootId = idConverterOrExpensiveValidation.convertToNodeId(root.identifier as StableNodeId);\n\n\t\t\tconst treeViewNodes = convertTreeNodesToViewNodes(root, (node) => {\n\t\t\t\tconst identifier = idConverterOrExpensiveValidation.convertToNodeId(node.identifier as StableNodeId);\n\t\t\t\tconst viewNode = {\n\t\t\t\t\tdefinition: node.definition,\n\t\t\t\t\tidentifier,\n\t\t\t\t};\n\t\t\t\tcopyPropertyIfDefined(node, viewNode, 'payload');\n\t\t\t\treturn viewNode;\n\t\t\t});\n\n\t\t\treturn new RevisionView(rootId, Forest.create(expensiveValidation).add(treeViewNodes));\n\t\t} else {\n\t\t\treturn new RevisionView(\n\t\t\t\troot.identifier as NodeId,\n\t\t\t\tForest.create(expensiveValidation).add(\n\t\t\t\t\tconvertTreeNodesToViewNodes(root, (node) => {\n\t\t\t\t\t\tconst viewNode = {\n\t\t\t\t\t\t\tdefinition: node.definition,\n\t\t\t\t\t\t\tidentifier: node.identifier as NodeId,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tcopyPropertyIfDefined(node, viewNode, 'payload');\n\t\t\t\t\t\treturn viewNode;\n\t\t\t\t\t})\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\t}\n\n\t/** Begin a transaction by generating a mutable `TransactionView` from this view */\n\tpublic openForTransaction(): TransactionView {\n\t\treturn new TransactionView(this.root, this.forest);\n\t}\n\n\tpublic equals(view: TreeView): boolean {\n\t\tif (!(view instanceof RevisionView)) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn this.hasEqualForest(view);\n\t}\n}\n\n/**\n * An view of a distributed tree that is part of an ongoing transaction between `RevisionView`s.\n * @alpha\n */\nexport class TransactionView extends TreeView {\n\t/** Conclude a transaction by generating an immutable `RevisionView` from this view */\n\tpublic close(): RevisionView {\n\t\treturn new RevisionView(this.root, this.forest);\n\t}\n\n\t/** Inserts all nodes in a NodeSequence into the view */\n\tpublic addNodes(sequence: Iterable<TreeViewNode>): TransactionView {\n\t\treturn new TransactionView(this.root, this.forest.add(sequence));\n\t}\n\n\t/** Remove all nodes with the given ids from the view */\n\tpublic deleteNodes(nodes: Iterable<NodeId>): TransactionView {\n\t\treturn new TransactionView(this.root, this.forest.delete(nodes, true));\n\t}\n\n\t/**\n\t * Parents a set of detached nodes at a specified place.\n\t * @param nodesToAttach - the nodes to parent in the specified place. The nodes must already be present in the view.\n\t * @param place - the location to insert the nodes.\n\t */\n\tpublic attachRange(nodesToAttach: readonly NodeId[], place: TreeViewPlace): TransactionView {\n\t\tconst { parent, label } = place.trait;\n\t\tconst index = this.findIndexWithinTrait(place);\n\t\treturn new TransactionView(this.root, this.forest.attachRangeOfChildren(parent, label, index, nodesToAttach));\n\t}\n\n\t/**\n\t * Detaches a range of nodes from their parent. The detached nodes remain in the view.\n\t * @param rangeToDetach - the range of nodes to detach\n\t */\n\tpublic detachRange(rangeToDetach: TreeViewRange): {\n\t\tview: TransactionView;\n\t\tdetached: readonly NodeId[];\n\t} {\n\t\tconst { start, end } = rangeToDetach;\n\t\tconst { trait: traitLocation } = start;\n\t\tconst { parent, label } = traitLocation;\n\t\tconst startIndex = this.findIndexWithinTrait(start);\n\t\tconst endIndex = this.findIndexWithinTrait(end);\n\t\tconst { forest, detached } = this.forest.detachRangeOfChildren(parent, label, startIndex, endIndex);\n\t\treturn { view: new TransactionView(this.root, forest), detached };\n\t}\n\n\t/**\n\t * Sets or overwrites a node's value. The node must exist in this view.\n\t * @param nodeId - the id of the node\n\t * @param value - the new value\n\t */\n\tpublic setNodeValue(nodeId: NodeId, value: Payload): TransactionView {\n\t\treturn new TransactionView(this.root, this.forest.setValue(nodeId, value));\n\t}\n\n\tpublic equals(view: TreeView): boolean {\n\t\tif (!(view instanceof TransactionView)) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn this.hasEqualForest(view);\n\t}\n}\n\n/**\n * Transform an input tree into a list of {@link TreeViewNode}s.\n * @param tree - the input tree\n * @param convert - a conversion function that will run on each node in the input tree to produce the output nodes.\n * Returning undefined means that conversion for the given node was impossible, at which time the entire tree conversion will be aborted\n * and return undefined.\n */\nexport function convertTreeNodesToViewNodes<\n\tTIn extends HasVariadicTraits<TIn>,\n\tTOut extends TreeViewNode = TreeViewNode,\n>(root: TIn, convert: (node: TIn) => Omit<TOut, 'traits'>): TOut[];\n\n/**\n * Transform an input tree into a list of {@link TreeViewNode}s.\n * @param tree - the input tree\n * @param convert - a conversion function that will run on each node in the input tree to produce the output nodes.\n */\nexport function convertTreeNodesToViewNodes<\n\tTIn extends HasVariadicTraits<TIn>,\n\tTOut extends TreeViewNode = TreeViewNode,\n>(root: TIn, convert: (node: TIn) => Omit<TOut, 'traits'> | undefined): TOut[] | undefined;\n\n/**\n * Transform an input tree into a list of {@link TreeViewNode}s.\n * @param tree - the input tree\n * @param convert - a conversion function that will run on each node in the input tree to produce the output nodes.\n * Returning undefined means that conversion for the given node was impossible, at which time the entire tree conversion will be aborted\n * and return undefined.\n */\nexport function convertTreeNodesToViewNodes<\n\tTIn extends HasVariadicTraits<TIn>,\n\tTOut extends TreeViewNode = TreeViewNode,\n>(root: TIn, convert: (node: TIn) => Omit<TOut, 'traits'> | undefined): TOut[] | undefined {\n\tconst convertedRoot = convert(root) as Mutable<TOut>;\n\tif (convertedRoot === undefined || root.traits === undefined) {\n\t\treturn undefined;\n\t}\n\t// `convertedRoot` might be the same as `root`, in which case stash the children of `root` before wiping them from `convertedRoot`\n\tconst rootTraits = (root as unknown as TOut) === convertedRoot ? { traits: root.traits } : root;\n\tconvertedRoot.traits = new Map();\n\tconst pendingNodes: {\n\t\tchildIterator: Iterator<[TraitLabel, TIn]>;\n\t\tnewNode: Mutable<TOut>;\n\t}[] = [{ childIterator: iterateChildren(rootTraits)[Symbol.iterator](), newNode: convertedRoot }];\n\tconst resultNodes: TOut[] = [];\n\n\twhile (pendingNodes.length > 0) {\n\t\tconst { childIterator, newNode } = pendingNodes[pendingNodes.length - 1] ?? fail('Undefined node');\n\t\tconst { value, done } = childIterator.next();\n\t\tif (done === true) {\n\t\t\tresultNodes.push(\n\t\t\t\tpendingNodes.pop()?.newNode ?? fail('covertTreeNodesToViewNodes incorrectly coordinated parentage')\n\t\t\t);\n\t\t} else {\n\t\t\tconst [traitLabel, child] = value as [TraitLabel, TIn];\n\t\t\tconst convertedChild = convert(child) as TOut;\n\t\t\tif (convertedChild === undefined) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tif (child.traits !== undefined) {\n\t\t\t\tconst childTraits = (child as unknown as TOut) === convertedChild ? { traits: child.traits } : child;\n\t\t\t\t(convertedChild as Mutable<TOut>).traits = new Map();\n\t\t\t\tpendingNodes.push({\n\t\t\t\t\tchildIterator: iterateChildren(childTraits)[Symbol.iterator](),\n\t\t\t\t\tnewNode: convertedChild,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst newTraits = newNode.traits as MutableMap<TOut['traits']>;\n\t\t\tlet newTrait = newTraits.get(traitLabel);\n\t\t\tif (newTrait === undefined) {\n\t\t\t\tnewTrait = [];\n\t\t\t\tnewTraits.set(traitLabel, newTrait);\n\t\t\t}\n\t\t\t(newTrait as NodeId[]).push(convertedChild.identifier);\n\t\t}\n\t}\n\n\treturn resultNodes;\n}\n\n/**\n * Returns an iterable of the supplied node's traits in a stable order.\n */\nexport function* iterateChildren<T>(hasTraits: HasVariadicTraits<T>): Iterable<[TraitLabel, T]> {\n\tif (hasTraits.traits !== undefined) {\n\t\tfor (const [label, trait] of Object.entries(hasTraits.traits).sort()) {\n\t\t\tif (trait !== undefined) {\n\t\t\t\tif (isTreeNodeSequence(trait)) {\n\t\t\t\t\tfor (const child of trait) {\n\t\t\t\t\t\tyield [label as TraitLabel, child];\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tyield [label as TraitLabel, trait];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction isTreeNodeSequence<TChild>(sequence: TreeNodeSequence<TChild> | TChild): sequence is TreeNodeSequence<TChild> {\n\treturn Array.isArray(sequence);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"RevisionView.js","sourceRoot":"","sources":["../src/RevisionView.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAuB,qBAAqB,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGrC,OAAO,EAAE,QAAQ,EAA8C,MAAM,eAAe,CAAC;AAGrF;;;GAGG;AACH,MAAM,OAAO,YAAa,SAAQ,QAAQ;IAmBlC,MAAM,CAAC,QAAQ,CACrB,IAAO,EACP,gCAA4D,EAC5D,mBAAmB,GAAG,KAAK;QAE3B,IAAI,OAAO,gCAAgC,KAAK,QAAQ,EAAE,CAAC;YAC1D,MAAM,MAAM,GAAG,gCAAgC,CAAC,eAAe,CAAC,IAAI,CAAC,UAA0B,CAAC,CAAC;YAEjG,MAAM,aAAa,GAAG,2BAA2B,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE;gBAChE,MAAM,UAAU,GAAG,gCAAgC,CAAC,eAAe,CAAC,IAAI,CAAC,UAA0B,CAAC,CAAC;gBACrG,MAAM,QAAQ,GAAG;oBAChB,UAAU,EAAE,IAAI,CAAC,UAAU;oBAC3B,UAAU;iBACV,CAAC;gBACF,qBAAqB,CAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;gBACjD,OAAO,QAAQ,CAAC;YACjB,CAAC,CAAC,CAAC;YAEH,OAAO,IAAI,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC;QACxF,CAAC;aAAM,CAAC;YACP,OAAO,IAAI,YA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I,KAAK,KAAK,SAAS,EAAE,CAAC;gBACzB,IAAI,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC;oBAC/B,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,CAAC;wBAC3B,MAAM,CAAC,KAAmB,EAAE,KAAK,CAAC,CAAC;oBACpC,CAAC;gBACF,CAAC;qBAAM,CAAC;oBACP,MAAM,CAAC,KAAmB,EAAE,KAAK,CAAC,CAAC;gBACpC,CAAC;YACF,CAAC;QACF,CAAC;IACF,CAAC;AACF,CAAC;AAED,SAAS,kBAAkB,CAAS,QAA2C;IAC9E,OAAO,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;AAChC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { HasVariadicTraits } from './ChangeTypes.js';\nimport { Mutable, MutableMap, copyPropertyIfDefined, fail } from './Common.js';\nimport { Forest } from './Forest.js';\nimport { NodeId, StableNodeId, TraitLabel } from './Identifiers.js';\nimport { NodeIdConverter } from './NodeIdUtilities.js';\nimport { TreeView, TreeViewNode, TreeViewPlace, TreeViewRange } from './TreeView.js';\nimport { Payload, TreeNode, TreeNodeSequence } from './persisted-types/index.js';\n\n/**\n * An immutable view of a distributed tree.\n * @alpha\n */\nexport class RevisionView extends TreeView {\n\t/**\n\t * Constructs a {@link RevisionView} using the supplied tree.\n\t * @param root - the root of the tree to use as the contents of the {@link RevisionView}\n\t * @param expensiveValidation - whether or not to perform additional validation, e.g. to catch errors when testing\n\t */\n\tpublic static fromTree<T extends TreeNode<T, NodeId>>(root: T, expensiveValidation?: boolean): RevisionView;\n\t/**\n\t * Constructs a {@link RevisionView} using the supplied tree.\n\t * @param root - the root of the tree to use as the contents of the `RevisionView`\n\t * @param idConverter - the {@link NodeIdConverter} that will recompress the IDs the in the tree\n\t * @param expensiveValidation - whether or not to perform additional validation, e.g. to catch errors when testing\n\t */\n\tpublic static fromTree<T extends TreeNode<T, StableNodeId>>(\n\t\troot: T,\n\t\tidConverter: NodeIdConverter,\n\t\texpensiveValidation?: boolean\n\t): RevisionView;\n\n\tpublic static fromTree<T extends TreeNode<T, NodeId> | TreeNode<T, StableNodeId>>(\n\t\troot: T,\n\t\tidConverterOrExpensiveValidation?: NodeIdConverter | boolean,\n\t\texpensiveValidation = false\n\t): RevisionView {\n\t\tif (typeof idConverterOrExpensiveValidation === 'object') {\n\t\t\tconst rootId = idConverterOrExpensiveValidation.convertToNodeId(root.identifier as StableNodeId);\n\n\t\t\tconst treeViewNodes = convertTreeNodesToViewNodes(root, (node) => {\n\t\t\t\tconst identifier = idConverterOrExpensiveValidation.convertToNodeId(node.identifier as StableNodeId);\n\t\t\t\tconst viewNode = {\n\t\t\t\t\tdefinition: node.definition,\n\t\t\t\t\tidentifier,\n\t\t\t\t};\n\t\t\t\tcopyPropertyIfDefined(node, viewNode, 'payload');\n\t\t\t\treturn viewNode;\n\t\t\t});\n\n\t\t\treturn new RevisionView(rootId, Forest.create(expensiveValidation).add(treeViewNodes));\n\t\t} else {\n\t\t\treturn new RevisionView(\n\t\t\t\troot.identifier as NodeId,\n\t\t\t\tForest.create(expensiveValidation).add(\n\t\t\t\t\tconvertTreeNodesToViewNodes(root, (node) => {\n\t\t\t\t\t\tconst viewNode = {\n\t\t\t\t\t\t\tdefinition: node.definition,\n\t\t\t\t\t\t\tidentifier: node.identifier as NodeId,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tcopyPropertyIfDefined(node, viewNode, 'payload');\n\t\t\t\t\t\treturn viewNode;\n\t\t\t\t\t})\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\t}\n\n\t/** Begin a transaction by generating a mutable `TransactionView` from this view */\n\tpublic openForTransaction(): TransactionView {\n\t\treturn new TransactionView(this.root, this.forest);\n\t}\n\n\tpublic equals(view: TreeView): boolean {\n\t\tif (!(view instanceof RevisionView)) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn this.hasEqualForest(view);\n\t}\n}\n\n/**\n * An view of a distributed tree that is part of an ongoing transaction between `RevisionView`s.\n * @alpha\n */\nexport class TransactionView extends TreeView {\n\t/** Conclude a transaction by generating an immutable `RevisionView` from this view */\n\tpublic close(): RevisionView {\n\t\treturn new RevisionView(this.root, this.forest);\n\t}\n\n\t/** Inserts all nodes in a NodeSequence into the view */\n\tpublic addNodes(sequence: Iterable<TreeViewNode>): TransactionView {\n\t\treturn new TransactionView(this.root, this.forest.add(sequence));\n\t}\n\n\t/** Remove all nodes with the given ids from the view */\n\tpublic deleteNodes(nodes: Iterable<NodeId>): TransactionView {\n\t\treturn new TransactionView(this.root, this.forest.delete(nodes, true));\n\t}\n\n\t/**\n\t * Parents a set of detached nodes at a specified place.\n\t * @param nodesToAttach - the nodes to parent in the specified place. The nodes must already be present in the view.\n\t * @param place - the location to insert the nodes.\n\t */\n\tpublic attachRange(nodesToAttach: readonly NodeId[], place: TreeViewPlace): TransactionView {\n\t\tconst { parent, label } = place.trait;\n\t\tconst index = this.findIndexWithinTrait(place);\n\t\treturn new TransactionView(this.root, this.forest.attachRangeOfChildren(parent, label, index, nodesToAttach));\n\t}\n\n\t/**\n\t * Detaches a range of nodes from their parent. The detached nodes remain in the view.\n\t * @param rangeToDetach - the range of nodes to detach\n\t */\n\tpublic detachRange(rangeToDetach: TreeViewRange): {\n\t\tview: TransactionView;\n\t\tdetached: readonly NodeId[];\n\t} {\n\t\tconst { start, end } = rangeToDetach;\n\t\tconst { trait: traitLocation } = start;\n\t\tconst { parent, label } = traitLocation;\n\t\tconst startIndex = this.findIndexWithinTrait(start);\n\t\tconst endIndex = this.findIndexWithinTrait(end);\n\t\tconst { forest, detached } = this.forest.detachRangeOfChildren(parent, label, startIndex, endIndex);\n\t\treturn { view: new TransactionView(this.root, forest), detached };\n\t}\n\n\t/**\n\t * Sets or overwrites a node's value. The node must exist in this view.\n\t * @param nodeId - the id of the node\n\t * @param value - the new value\n\t */\n\tpublic setNodeValue(nodeId: NodeId, value: Payload): TransactionView {\n\t\treturn new TransactionView(this.root, this.forest.setValue(nodeId, value));\n\t}\n\n\tpublic equals(view: TreeView): boolean {\n\t\tif (!(view instanceof TransactionView)) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn this.hasEqualForest(view);\n\t}\n}\n\n/**\n * Transform an input tree into a list of {@link TreeViewNode}s.\n * @param tree - the input tree\n * @param convert - a conversion function that will run on each node in the input tree to produce the output nodes.\n * Returning undefined means that conversion for the given node was impossible, at which time the entire tree conversion will be aborted\n * and return undefined.\n */\nexport function convertTreeNodesToViewNodes<\n\tTIn extends HasVariadicTraits<TIn>,\n\tTOut extends TreeViewNode = TreeViewNode,\n>(root: TIn, convert: (node: TIn) => Omit<TOut, 'traits'>): TOut[];\n\n/**\n * Transform an input tree into a list of {@link TreeViewNode}s.\n * @param tree - the input tree\n * @param convert - a conversion function that will run on each node in the input tree to produce the output nodes.\n */\nexport function convertTreeNodesToViewNodes<\n\tTIn extends HasVariadicTraits<TIn>,\n\tTOut extends TreeViewNode = TreeViewNode,\n>(root: TIn, convert: (node: TIn) => Omit<TOut, 'traits'> | undefined): TOut[] | undefined;\n\n/**\n * Transform an input tree into a list of {@link TreeViewNode}s.\n * @param tree - the input tree\n * @param convert - a conversion function that will run on each node in the input tree to produce the output nodes.\n * Returning undefined means that conversion for the given node was impossible, at which time the entire tree conversion will be aborted\n * and return undefined.\n */\nexport function convertTreeNodesToViewNodes<\n\tTIn extends HasVariadicTraits<TIn>,\n\tTOut extends TreeViewNode = TreeViewNode,\n>(root: TIn, convert: (node: TIn) => Omit<TOut, 'traits'> | undefined): TOut[] | undefined {\n\tconst convertedRoot = convert(root) as Mutable<TOut>;\n\tif (convertedRoot === undefined || root.traits === undefined) {\n\t\treturn undefined;\n\t}\n\t// `convertedRoot` might be the same as `root`, in which case stash the children of `root` before wiping them from `convertedRoot`\n\tconst rootTraits = (root as unknown as TOut) === convertedRoot ? { traits: root.traits } : root;\n\tconvertedRoot.traits = new Map();\n\tconst pendingNodes: {\n\t\tchildIterator: Iterator<[TraitLabel, TIn]>;\n\t\tnewNode: Mutable<TOut>;\n\t}[] = [{ childIterator: iterateChildren(rootTraits)[Symbol.iterator](), newNode: convertedRoot }];\n\tconst resultNodes: TOut[] = [];\n\n\twhile (pendingNodes.length > 0) {\n\t\tconst { childIterator, newNode } = pendingNodes[pendingNodes.length - 1] ?? fail('Undefined node');\n\t\tconst { value, done } = childIterator.next();\n\t\tif (done === true) {\n\t\t\tresultNodes.push(\n\t\t\t\tpendingNodes.pop()?.newNode ?? fail('covertTreeNodesToViewNodes incorrectly coordinated parentage')\n\t\t\t);\n\t\t} else {\n\t\t\tconst [traitLabel, child] = value;\n\t\t\tconst convertedChild = convert(child) as TOut;\n\t\t\tif (convertedChild === undefined) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tif (child.traits !== undefined) {\n\t\t\t\tconst childTraits = (child as unknown as TOut) === convertedChild ? { traits: child.traits } : child;\n\t\t\t\t(convertedChild as Mutable<TOut>).traits = new Map();\n\t\t\t\tpendingNodes.push({\n\t\t\t\t\tchildIterator: iterateChildren(childTraits)[Symbol.iterator](),\n\t\t\t\t\tnewNode: convertedChild,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst newTraits = newNode.traits as MutableMap<TOut['traits']>;\n\t\t\tlet newTrait = newTraits.get(traitLabel);\n\t\t\tif (newTrait === undefined) {\n\t\t\t\tnewTrait = [];\n\t\t\t\tnewTraits.set(traitLabel, newTrait);\n\t\t\t}\n\t\t\t(newTrait as NodeId[]).push(convertedChild.identifier);\n\t\t}\n\t}\n\n\treturn resultNodes;\n}\n\n/**\n * Returns an iterable of the supplied node's traits in a stable order.\n */\nexport function* iterateChildren<T>(hasTraits: HasVariadicTraits<T>): Iterable<[TraitLabel, T]> {\n\tif (hasTraits.traits !== undefined) {\n\t\tfor (const [label, trait] of Object.entries(hasTraits.traits).sort()) {\n\t\t\tif (trait !== undefined) {\n\t\t\t\tif (isTreeNodeSequence(trait)) {\n\t\t\t\t\tfor (const child of trait) {\n\t\t\t\t\t\tyield [label as TraitLabel, child];\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tyield [label as TraitLabel, trait];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction isTreeNodeSequence<TChild>(sequence: TreeNodeSequence<TChild> | TChild): sequence is TreeNodeSequence<TChild> {\n\treturn Array.isArray(sequence);\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluid-experimental/tree",
|
|
3
|
-
"version": "2.63.0-
|
|
3
|
+
"version": "2.63.0-359461",
|
|
4
4
|
"description": "Distributed tree",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -27,18 +27,18 @@
|
|
|
27
27
|
"main": "lib/index.js",
|
|
28
28
|
"types": "lib/index.d.ts",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@fluid-internal/client-utils": "2.63.0-
|
|
31
|
-
"@fluidframework/container-definitions": "2.63.0-
|
|
32
|
-
"@fluidframework/core-interfaces": "2.63.0-
|
|
33
|
-
"@fluidframework/core-utils": "2.63.0-
|
|
34
|
-
"@fluidframework/datastore-definitions": "2.63.0-
|
|
35
|
-
"@fluidframework/driver-definitions": "2.63.0-
|
|
36
|
-
"@fluidframework/id-compressor": "2.63.0-
|
|
37
|
-
"@fluidframework/runtime-definitions": "2.63.0-
|
|
38
|
-
"@fluidframework/runtime-utils": "2.63.0-
|
|
39
|
-
"@fluidframework/shared-object-base": "2.63.0-
|
|
40
|
-
"@fluidframework/telemetry-utils": "2.63.0-
|
|
41
|
-
"@fluidframework/tree": "2.63.0-
|
|
30
|
+
"@fluid-internal/client-utils": "2.63.0-359461",
|
|
31
|
+
"@fluidframework/container-definitions": "2.63.0-359461",
|
|
32
|
+
"@fluidframework/core-interfaces": "2.63.0-359461",
|
|
33
|
+
"@fluidframework/core-utils": "2.63.0-359461",
|
|
34
|
+
"@fluidframework/datastore-definitions": "2.63.0-359461",
|
|
35
|
+
"@fluidframework/driver-definitions": "2.63.0-359461",
|
|
36
|
+
"@fluidframework/id-compressor": "2.63.0-359461",
|
|
37
|
+
"@fluidframework/runtime-definitions": "2.63.0-359461",
|
|
38
|
+
"@fluidframework/runtime-utils": "2.63.0-359461",
|
|
39
|
+
"@fluidframework/shared-object-base": "2.63.0-359461",
|
|
40
|
+
"@fluidframework/telemetry-utils": "2.63.0-359461",
|
|
41
|
+
"@fluidframework/tree": "2.63.0-359461",
|
|
42
42
|
"@tylerbu/sorted-btree-es6": "^1.8.0",
|
|
43
43
|
"buffer": "^6.0.3",
|
|
44
44
|
"denque": "^1.5.1",
|
|
@@ -48,20 +48,20 @@
|
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@arethetypeswrong/cli": "^0.17.1",
|
|
50
50
|
"@biomejs/biome": "~1.9.3",
|
|
51
|
-
"@fluid-internal/mocha-test-setup": "2.63.0-
|
|
52
|
-
"@fluid-private/stochastic-test-utils": "2.63.0-
|
|
53
|
-
"@fluid-private/test-drivers": "2.63.0-
|
|
51
|
+
"@fluid-internal/mocha-test-setup": "2.63.0-359461",
|
|
52
|
+
"@fluid-private/stochastic-test-utils": "2.63.0-359461",
|
|
53
|
+
"@fluid-private/test-drivers": "2.63.0-359461",
|
|
54
54
|
"@fluid-tools/benchmark": "^0.51.0",
|
|
55
55
|
"@fluidframework/build-common": "^2.0.3",
|
|
56
56
|
"@fluidframework/build-tools": "^0.58.3",
|
|
57
|
-
"@fluidframework/container-definitions": "2.63.0-
|
|
58
|
-
"@fluidframework/container-loader": "2.63.0-
|
|
59
|
-
"@fluidframework/container-runtime": "2.63.0-
|
|
57
|
+
"@fluidframework/container-definitions": "2.63.0-359461",
|
|
58
|
+
"@fluidframework/container-loader": "2.63.0-359461",
|
|
59
|
+
"@fluidframework/container-runtime": "2.63.0-359461",
|
|
60
60
|
"@fluidframework/eslint-config-fluid": "^6.0.0",
|
|
61
|
-
"@fluidframework/runtime-utils": "2.63.0-
|
|
62
|
-
"@fluidframework/test-runtime-utils": "2.63.0-
|
|
63
|
-
"@fluidframework/test-utils": "2.63.0-
|
|
64
|
-
"@fluidframework/undo-redo": "2.63.0-
|
|
61
|
+
"@fluidframework/runtime-utils": "2.63.0-359461",
|
|
62
|
+
"@fluidframework/test-runtime-utils": "2.63.0-359461",
|
|
63
|
+
"@fluidframework/test-utils": "2.63.0-359461",
|
|
64
|
+
"@fluidframework/undo-redo": "2.63.0-359461",
|
|
65
65
|
"@microsoft/api-extractor": "7.52.11",
|
|
66
66
|
"@types/chai": "^4.0.0",
|
|
67
67
|
"@types/lru-cache": "^5.1.0",
|
package/src/EditUtilities.ts
CHANGED
|
@@ -126,7 +126,7 @@ export function convertTreeNodes<
|
|
|
126
126
|
if (done === true) {
|
|
127
127
|
pendingNodes.pop();
|
|
128
128
|
} else {
|
|
129
|
-
const [traitLabel, child] = value
|
|
129
|
+
const [traitLabel, child] = value;
|
|
130
130
|
let convertedChild: TOut | TPlaceholder;
|
|
131
131
|
if (!isKnownType(child, isPlaceholder)) {
|
|
132
132
|
convertedChild = convert(child) as TOut;
|
|
@@ -203,7 +203,7 @@ export function walkTree<TIn extends HasVariadicTraits<TIn | TPlaceholder>, TPla
|
|
|
203
203
|
if (done === true) {
|
|
204
204
|
childIterators.pop();
|
|
205
205
|
} else {
|
|
206
|
-
const [_, child] = value
|
|
206
|
+
const [_, child] = value;
|
|
207
207
|
if (isKnownType(child, isPlaceholder)) {
|
|
208
208
|
placeholderVisitor?.(child);
|
|
209
209
|
} else {
|
package/src/RevisionView.ts
CHANGED
|
@@ -204,7 +204,7 @@ export function convertTreeNodesToViewNodes<
|
|
|
204
204
|
pendingNodes.pop()?.newNode ?? fail('covertTreeNodesToViewNodes incorrectly coordinated parentage')
|
|
205
205
|
);
|
|
206
206
|
} else {
|
|
207
|
-
const [traitLabel, child] = value
|
|
207
|
+
const [traitLabel, child] = value;
|
|
208
208
|
const convertedChild = convert(child) as TOut;
|
|
209
209
|
if (convertedChild === undefined) {
|
|
210
210
|
return undefined;
|