@fluidframework/sequence 2.0.0-internal.4.1.2 → 2.0.0-internal.4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"intervalCollection.js","sourceRoot":"","sources":["../src/intervalCollection.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;AAEH,+BAA+B;AAE/B,+DAAyE;AAEzE,qEAA6D;AAC7D,2DAqBoC;AAEpC,qEAA+D;AAC/D,+BAAkC;AASlC,iDAAiG;AAEjG,MAAM,qBAAqB,GAAG,YAAY,CAAC;AAE3C,IAAY,YAiBX;AAjBD,WAAY,YAAY;IACvB,mDAAY,CAAA;IACZ,+CAAU,CAAA;IAEV;;;;;OAKG;IACH,iEAAmB,CAAA;IAEnB;;;OAGG;IACH,yDAAe,CAAA;AAChB,CAAC,EAjBW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAiBvB;AAqDD;;;GAGG;AACH,SAAS,kBAAkB,CAC1B,QAAsC,EACtC,KAAc;IAEd,OAAO;QACN,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;QAClB,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;QAChB,cAAc,EAAE,QAAQ,CAAC,CAAC,CAAC;QAC3B,YAAY,EAAE,QAAQ,CAAC,CAAC,CAAC;QACzB,UAAU,kCAAO,QAAQ,CAAC,CAAC,CAAC,KAAE,CAAC,mCAAsB,CAAC,EAAE,CAAC,KAAK,CAAC,GAAE;KACjE,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,SAAS,gBAAgB,CAAC,QAA6B;IACtD,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,cAAc,EAAE,YAAY,EAAE,UAAU,EAAE,GAAG,QAAQ,CAAC;IAE1E,OAAO;QACN,KAAK;QACL,GAAG;QACH,cAAc;QACd,YAAY;wCAGP,UAAU,KAAE,CAAC,mCAAsB,CAAC,EAAE,SAAS;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,eAAe,EAAE;YAC1B,MAAM,IAAI,8BAAY,CAAC,+BAA+B,CAAC,CAAC;SACxD;QAED,OAAO,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;IAC/C,CAAC;CACD;AAv5BD,gDAu5BC;AAgBD;;;;;GAKG;AACH,SAAgB,2BAA2B,CAC1C,iBAAyC;;IAEzC,MAAM,EAAE,QAAQ,EAAE,CAAC,mCAAsB,CAAC,EAAE,mBAAmB,EAAE,GAChE,MAAA,iBAAiB,CAAC,UAAU,mCAAI,EAAE,CAAC;IACpC,OAAO,QAAQ,IAAI,CAAA,mBAAmB,aAAnB,mBAAmB,uBAAnB,mBAAmB,CAAE,MAAM,MAAK,CAAC;QACnD,CAAC,CAAC,EAAE,KAAK,EAAE,mBAAmB,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE;QAC7C,CAAC,CAAC,SAAS,CAAC;AACd,CAAC;AARD,kEAQC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable no-bitwise */\n\nimport { assert, TypedEventEmitter } from \"@fluidframework/common-utils\";\nimport { IEvent } from \"@fluidframework/common-definitions\";\nimport { UsageError } from \"@fluidframework/container-utils\";\nimport {\n\taddProperties,\n\tClient,\n\tcompareReferencePositions,\n\tConflictAction,\n\tcreateMap,\n\tICombiningOp,\n\tISegment,\n\tMergeTreeDeltaType,\n\tminReferencePosition,\n\tPropertiesManager,\n\tPropertySet,\n\tRedBlackTree,\n\tLocalReferencePosition,\n\tReferenceType,\n\trefTypeIncludesFlag,\n\treservedRangeLabelsKey,\n\tUnassignedSequenceNumber,\n\tmaxReferencePosition,\n\tcreateDetachedLocalReferencePosition,\n\tDetachedReferencePosition,\n} from \"@fluidframework/merge-tree\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport { LoggingError } from \"@fluidframework/telemetry-utils\";\nimport { v4 as uuid } from \"uuid\";\nimport {\n\tIMapMessageLocalMetadata,\n\tIValueFactory,\n\tIValueOpEmitter,\n\tIValueOperation,\n\tIValueType,\n\tIValueTypeOperationValue,\n} from \"./defaultMapInterfaces\";\nimport { IInterval, IntervalConflictResolver, IntervalTree, IntervalNode } from \"./intervalTree\";\n\nconst reservedIntervalIdKey = \"intervalId\";\n\nexport enum IntervalType {\n\tSimple = 0x0,\n\tNest = 0x1,\n\n\t/**\n\t * SlideOnRemove indicates that the ends of the interval will slide if the segment\n\t * they reference is removed and acked.\n\t * See `packages\\dds\\merge-tree\\REFERENCEPOSITIONS.md` for details\n\t * SlideOnRemove is the default interval behavior and does not need to be specified.\n\t */\n\tSlideOnRemove = 0x2, // SlideOnRemove is default behavior - all intervals are SlideOnRemove\n\n\t/**\n\t * A temporary interval, used internally\n\t * @internal\n\t */\n\tTransient = 0x4,\n}\n\n/**\n * Serialized object representation of an interval.\n * This representation is used for ops that create or change intervals.\n * @internal\n */\nexport interface ISerializedInterval {\n\t/**\n\t * Sequence number at which `start` and `end` should be interpreted\n\t *\n\t * @remarks - It's unclear that this is necessary to store here.\n\t * This should just be the refSeq on the op that modified the interval, which should be available via other means.\n\t * At the time of writing, it's not plumbed through to the reconnect/rebase code, however, which does need it.\n\t */\n\tsequenceNumber: number;\n\t/** Start position of the interval */\n\tstart: number;\n\t/** End position of the interval */\n\tend: number;\n\t/** Interval type to create */\n\tintervalType: IntervalType;\n\t/** Any properties the interval has */\n\tproperties?: PropertySet;\n}\n\n/**\n * Represents a change that should be applied to an existing interval.\n * Changes can modify any of start/end/properties, with `undefined` signifying no change should be made.\n * @internal\n */\nexport type SerializedIntervalDelta = Omit<ISerializedInterval, \"start\" | \"end\" | \"properties\"> &\n\tPartial<Pick<ISerializedInterval, \"start\" | \"end\" | \"properties\">>;\n\n/**\n * A size optimization to avoid redundantly storing keys when serializing intervals\n * as JSON for summaries.\n *\n * Intervals are of the format:\n *\n * [start, end, sequenceNumber, intervalType, properties]\n */\nexport type CompressedSerializedInterval = [number, number, number, IntervalType, PropertySet];\n\n/**\n * @internal\n */\nexport interface ISerializedIntervalCollectionV2 {\n\tlabel: string;\n\tversion: 2;\n\tintervals: CompressedSerializedInterval[];\n}\n\n/**\n * Decompress an interval after loading a summary from JSON. The exact format\n * of this compression is unspecified and subject to change\n */\nfunction decompressInterval(\n\tinterval: CompressedSerializedInterval,\n\tlabel?: string,\n): ISerializedInterval {\n\treturn {\n\t\tstart: interval[0],\n\t\tend: interval[1],\n\t\tsequenceNumber: interval[2],\n\t\tintervalType: interval[3],\n\t\tproperties: { ...interval[4], [reservedRangeLabelsKey]: [label] },\n\t};\n}\n\n/**\n * Compress an interval prior to serialization as JSON. The exact format of this\n * compression is unspecified and subject to change\n */\nfunction compressInterval(interval: ISerializedInterval): CompressedSerializedInterval {\n\tconst { start, end, sequenceNumber, intervalType, properties } = interval;\n\n\treturn [\n\t\tstart,\n\t\tend,\n\t\tsequenceNumber,\n\t\tintervalType,\n\t\t// remove the `referenceRangeLabels` property as it is already stored\n\t\t// in the `label` field of the summary\n\t\t{ ...properties, [reservedRangeLabelsKey]: undefined },\n\t];\n}\n\nexport interface ISerializableInterval extends IInterval {\n\t/** Serializable bag of properties associated with the interval. */\n\tproperties: PropertySet;\n\t/** @internal */\n\tpropertyManager: PropertiesManager;\n\t/** @internal */\n\tserialize(): ISerializedInterval;\n\t/** @internal */\n\taddProperties(\n\t\tprops: PropertySet,\n\t\tcollaborating?: boolean,\n\t\tseq?: number,\n\t): PropertySet | undefined;\n\t/**\n\t * Gets the id associated with this interval.\n\t * When the interval is used as part of an interval collection, this id can be used to modify or remove the\n\t * interval.\n\t * @remarks - This signature includes `undefined` strictly for backwards-compatibility reasons, as older versions\n\t * of Fluid didn't always write interval ids.\n\t */\n\tgetIntervalId(): string | undefined;\n}\n\nexport interface IIntervalHelpers<TInterval extends ISerializableInterval> {\n\tcompareEnds(a: TInterval, b: TInterval): number;\n\t/**\n\t *\n\t * @param label - label of the interval collection this interval is being added to. This parameter is\n\t * irrelevant for transient intervals.\n\t * @param start - numerical start position of the interval\n\t * @param end - numberical end position of the interval\n\t * @param client - client creating the interval\n\t * @param intervalType - Type of interval to create. Default is SlideOnRemove\n\t * @param op - If this create came from a remote client, op that created it. Default is undefined (i.e. local)\n\t * @param fromSnapshot - If this create came from loading a snapshot. Default is false.\n\t */\n\tcreate(\n\t\tlabel: string,\n\t\tstart: number | undefined,\n\t\tend: number | undefined,\n\t\tclient: Client | undefined,\n\t\tintervalType: IntervalType,\n\t\top?: ISequencedDocumentMessage,\n\t\tfromSnapshot?: boolean,\n\t): TInterval;\n}\n\n/**\n * Serializable interval whose endpoints are plain-old numbers.\n */\nexport class Interval implements ISerializableInterval {\n\t/**\n\t * {@inheritDoc ISerializableInterval.properties}\n\t */\n\tpublic properties: PropertySet;\n\t/** @internal */\n\tpublic auxProps: PropertySet[] | undefined;\n\t/**\n\t * {@inheritDoc ISerializableInterval.propertyManager}\n\t * @deprecated - This API was never intended to be public and will be marked internal in a future release.\n\t */\n\tpublic propertyManager: PropertiesManager;\n\tconstructor(public start: number, public end: number, props?: PropertySet) {\n\t\tthis.propertyManager = new PropertiesManager();\n\t\tthis.properties = {};\n\n\t\tif (props) {\n\t\t\tthis.addProperties(props);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc ISerializableInterval.getIntervalId}\n\t */\n\tpublic getIntervalId(): string {\n\t\tconst id = this.properties?.[reservedIntervalIdKey];\n\t\tassert(id !== undefined, 0x5e1 /* interval ID should not be undefined */);\n\t\treturn `${id}`;\n\t}\n\n\t/**\n\t * @returns an array containing any auxiliary property sets added with `addPropertySet`.\n\t */\n\tpublic getAdditionalPropertySets(): PropertySet[] {\n\t\treturn this.auxProps ?? [];\n\t}\n\n\t/**\n\t * Adds an auxiliary set of properties to this interval.\n\t * These properties can be recovered using `getAdditionalPropertySets`\n\t * @param props - set of properties to add\n\t * @remarks - This gets called as part of the default conflict resolver for `IntervalCollection<Interval>`\n\t * (i.e. non-sequence-based interval collections). However, the additional properties don't get serialized.\n\t * This functionality seems half-baked.\n\t */\n\tpublic addPropertySet(props: PropertySet) {\n\t\tif (this.auxProps === undefined) {\n\t\t\tthis.auxProps = [];\n\t\t}\n\t\tthis.auxProps.push(props);\n\t}\n\n\t/**\n\t * {@inheritDoc ISerializableInterval.serialize}\n\t * @internal\n\t */\n\tpublic serialize(): ISerializedInterval {\n\t\tconst serializedInterval: ISerializedInterval = {\n\t\t\tend: this.end,\n\t\t\tintervalType: 0,\n\t\t\tsequenceNumber: 0,\n\t\t\tstart: this.start,\n\t\t};\n\t\tif (this.properties) {\n\t\t\tserializedInterval.properties = this.properties;\n\t\t}\n\t\treturn serializedInterval;\n\t}\n\n\t/**\n\t * {@inheritDoc IInterval.clone}\n\t */\n\tpublic clone() {\n\t\treturn new Interval(this.start, this.end, this.properties);\n\t}\n\n\t/**\n\t * {@inheritDoc IInterval.compare}\n\t */\n\tpublic compare(b: Interval) {\n\t\tconst startResult = this.compareStart(b);\n\t\tif (startResult === 0) {\n\t\t\tconst endResult = this.compareEnd(b);\n\t\t\tif (endResult === 0) {\n\t\t\t\tconst thisId = this.getIntervalId();\n\t\t\t\tif (thisId) {\n\t\t\t\t\tconst bId = b.getIntervalId();\n\t\t\t\t\tif (bId) {\n\t\t\t\t\t\treturn thisId > bId ? 1 : thisId < bId ? -1 : 0;\n\t\t\t\t\t}\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t\treturn 0;\n\t\t\t} else {\n\t\t\t\treturn endResult;\n\t\t\t}\n\t\t} else {\n\t\t\treturn startResult;\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc IInterval.compareStart}\n\t */\n\tpublic compareStart(b: Interval) {\n\t\treturn this.start - b.start;\n\t}\n\n\t/**\n\t * {@inheritDoc IInterval.compareEnd}\n\t */\n\tpublic compareEnd(b: Interval) {\n\t\treturn this.end - b.end;\n\t}\n\n\t/**\n\t * {@inheritDoc IInterval.overlaps}\n\t */\n\tpublic overlaps(b: Interval) {\n\t\tconst result = this.start <= b.end && this.end >= b.start;\n\t\treturn result;\n\t}\n\n\t/**\n\t * {@inheritDoc IInterval.union}\n\t * @deprecated - This API was never intended to be public and will be marked internal in a future release.\n\t */\n\tpublic union(b: Interval) {\n\t\treturn new Interval(\n\t\t\tMath.min(this.start, b.start),\n\t\t\tMath.max(this.end, b.end),\n\t\t\tthis.properties,\n\t\t);\n\t}\n\n\tpublic getProperties() {\n\t\treturn this.properties;\n\t}\n\n\t/**\n\t * {@inheritDoc ISerializableInterval.addProperties}\n\t * @deprecated - This API was never intended to be public and will be marked internal in a future release.\n\t */\n\tpublic addProperties(\n\t\tnewProps: PropertySet,\n\t\tcollaborating: boolean = false,\n\t\tseq?: number,\n\t\top?: ICombiningOp,\n\t): PropertySet | undefined {\n\t\tif (newProps) {\n\t\t\tthis.initializeProperties();\n\t\t\treturn this.propertyManager.addProperties(\n\t\t\t\tthis.properties,\n\t\t\t\tnewProps,\n\t\t\t\top,\n\t\t\t\tseq,\n\t\t\t\tcollaborating,\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc IInterval.modify}\n\t * @deprecated - This API was never intended to be public and will be marked internal in a future release.\n\t */\n\tpublic modify(label: string, start: number, end: number, op?: ISequencedDocumentMessage) {\n\t\tconst startPos = start ?? this.start;\n\t\tconst endPos = end ?? this.end;\n\t\tif (this.start === startPos && this.end === endPos) {\n\t\t\t// Return undefined to indicate that no change is necessary.\n\t\t\treturn;\n\t\t}\n\t\tconst newInterval = new Interval(startPos, endPos);\n\t\tif (this.properties) {\n\t\t\tnewInterval.initializeProperties();\n\t\t\tthis.propertyManager.copyTo(\n\t\t\t\tthis.properties,\n\t\t\t\tnewInterval.properties,\n\t\t\t\tnewInterval.propertyManager,\n\t\t\t);\n\t\t}\n\t\treturn newInterval;\n\t}\n\n\tprivate initializeProperties(): void {\n\t\tif (!this.propertyManager) {\n\t\t\tthis.propertyManager = new PropertiesManager();\n\t\t}\n\t\tif (!this.properties) {\n\t\t\tthis.properties = createMap<any>();\n\t\t}\n\t}\n}\n\n/**\n * Interval impelmentation whose ends are associated with positions in a mutatable sequence.\n * As such, when content is inserted into the middle of the interval, the interval expands to\n * include that content.\n *\n * @remarks - The endpoint's position should be treated exclusively to get reasonable behavior--i.e.\n * an interval referring to \"hello\" in \"hello world\" should have a start position of 0 and an end\n * position of 5.\n *\n * To see why, consider what happens if \"llo wor\" is removed from the string to make \"held\".\n * The interval's startpoint remains on the \"h\" (it isn't altered), but the interval's endpoint\n * slides forward to the next unremoved position, which is the \"l\" in \"held\".\n * Users would generally expect the interval to now refer to \"he\" (as it is the subset of content\n * remaining after the removal), hence the \"l\" should be excluded.\n * If the interval endpoint was treated inclusively, the interval would now refer to \"hel\", which\n * is undesirable.\n *\n * Since the end of an interval is treated exclusively but cannot be greater than or equal to the\n * length of the associated sequence, application models which leverage interval collections should\n * consider inserting a marker at the end of the sequence to represent the end of the content.\n */\nexport class SequenceInterval implements ISerializableInterval {\n\t/**\n\t * {@inheritDoc ISerializableInterval.properties}\n\t */\n\tpublic properties: PropertySet;\n\t/**\n\t * {@inheritDoc ISerializableInterval.propertyManager}\n\t * @deprecated - This API was never intended to be public and will be marked internal in a future release.\n\t */\n\tpublic propertyManager: PropertiesManager;\n\n\tconstructor(\n\t\tprivate readonly client: Client,\n\t\t/**\n\t\t * Start endpoint of this interval.\n\t\t * @remarks - This endpoint can be resolved into a character position using the SharedString it's a part of.\n\t\t */\n\t\tpublic start: LocalReferencePosition,\n\t\t/**\n\t\t * End endpoint of this interval.\n\t\t * @remarks - This endpoint can be resolved into a character position using the SharedString it's a part of.\n\t\t */\n\t\tpublic end: LocalReferencePosition,\n\t\tpublic intervalType: IntervalType,\n\t\tprops?: PropertySet,\n\t) {\n\t\tthis.propertyManager = new PropertiesManager();\n\t\tthis.properties = {};\n\n\t\tif (props) {\n\t\t\tthis.addProperties(props);\n\t\t}\n\t}\n\n\tprivate callbacks?: Record<\"beforePositionChange\" | \"afterPositionChange\", () => void>;\n\n\t/**\n\t * Subscribes to position change events on this interval if there are no current listeners.\n\t * @internal\n\t */\n\tpublic addPositionChangeListeners(\n\t\tbeforePositionChange: () => void,\n\t\tafterPositionChange: () => void,\n\t): void {\n\t\tif (this.callbacks === undefined) {\n\t\t\tthis.callbacks = {\n\t\t\t\tbeforePositionChange,\n\t\t\t\tafterPositionChange,\n\t\t\t};\n\n\t\t\tconst startCbs = (this.start.callbacks ??= {});\n\t\t\tconst endCbs = (this.end.callbacks ??= {});\n\t\t\tstartCbs.beforeSlide = endCbs.beforeSlide = beforePositionChange;\n\t\t\tstartCbs.afterSlide = endCbs.afterSlide = afterPositionChange;\n\t\t}\n\t}\n\n\t/**\n\t * Removes the currently subscribed position change listeners.\n\t * @internal\n\t */\n\tpublic removePositionChangeListeners(): void {\n\t\tif (this.callbacks) {\n\t\t\tthis.callbacks = undefined;\n\t\t\tthis.start.callbacks = undefined;\n\t\t\tthis.end.callbacks = undefined;\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc ISerializableInterval.serialize}\n\t * @internal\n\t */\n\tpublic serialize(): ISerializedInterval {\n\t\tconst startPosition = this.client.localReferencePositionToPosition(this.start);\n\t\tconst endPosition = this.client.localReferencePositionToPosition(this.end);\n\t\tconst serializedInterval: ISerializedInterval = {\n\t\t\tend: endPosition,\n\t\t\tintervalType: this.intervalType,\n\t\t\tsequenceNumber: this.client.getCurrentSeq(),\n\t\t\tstart: startPosition,\n\t\t};\n\n\t\tif (this.properties) {\n\t\t\tserializedInterval.properties = this.properties;\n\t\t}\n\n\t\treturn serializedInterval;\n\t}\n\n\t/**\n\t * {@inheritDoc IInterval.clone}\n\t */\n\tpublic clone() {\n\t\treturn new SequenceInterval(\n\t\t\tthis.client,\n\t\t\tthis.start,\n\t\t\tthis.end,\n\t\t\tthis.intervalType,\n\t\t\tthis.properties,\n\t\t);\n\t}\n\n\t/**\n\t * {@inheritDoc IInterval.compare}\n\t */\n\tpublic compare(b: SequenceInterval) {\n\t\tconst startResult = this.compareStart(b);\n\t\tif (startResult === 0) {\n\t\t\tconst endResult = this.compareEnd(b);\n\t\t\tif (endResult === 0) {\n\t\t\t\tconst thisId = this.getIntervalId();\n\t\t\t\tif (thisId) {\n\t\t\t\t\tconst bId = b.getIntervalId();\n\t\t\t\t\tif (bId) {\n\t\t\t\t\t\treturn thisId > bId ? 1 : thisId < bId ? -1 : 0;\n\t\t\t\t\t}\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t\treturn 0;\n\t\t\t} else {\n\t\t\t\treturn endResult;\n\t\t\t}\n\t\t} else {\n\t\t\treturn startResult;\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc IInterval.compareStart}\n\t */\n\tpublic compareStart(b: SequenceInterval) {\n\t\treturn compareReferencePositions(this.start, b.start);\n\t}\n\n\t/**\n\t * {@inheritDoc IInterval.compareEnd}\n\t */\n\tpublic compareEnd(b: SequenceInterval) {\n\t\treturn compareReferencePositions(this.end, b.end);\n\t}\n\n\t/**\n\t * {@inheritDoc IInterval.overlaps}\n\t */\n\tpublic overlaps(b: SequenceInterval) {\n\t\tconst result =\n\t\t\tcompareReferencePositions(this.start, b.end) <= 0 &&\n\t\t\tcompareReferencePositions(this.end, b.start) >= 0;\n\t\treturn result;\n\t}\n\n\t/**\n\t * {@inheritDoc ISerializableInterval.getIntervalId}\n\t */\n\tpublic getIntervalId(): string {\n\t\tconst id = this.properties?.[reservedIntervalIdKey];\n\t\tassert(id !== undefined, 0x5e2 /* interval ID should not be undefined */);\n\t\treturn `${id}`;\n\t}\n\n\t/**\n\t * {@inheritDoc IInterval.union}\n\t * @deprecated - This API was never intended to be public and will be marked internal in a future release.\n\t */\n\tpublic union(b: SequenceInterval) {\n\t\treturn new SequenceInterval(\n\t\t\tthis.client,\n\t\t\tminReferencePosition(this.start, b.start),\n\t\t\tmaxReferencePosition(this.end, b.end),\n\t\t\tthis.intervalType,\n\t\t);\n\t}\n\n\t/**\n\t * {@inheritDoc ISerializableInterval.addProperties}\n\t * @deprecated - This API was never intended to be public and will be marked internal in a future release.\n\t */\n\tpublic addProperties(\n\t\tnewProps: PropertySet,\n\t\tcollab: boolean = false,\n\t\tseq?: number,\n\t\top?: ICombiningOp,\n\t): PropertySet | undefined {\n\t\tthis.initializeProperties();\n\t\treturn this.propertyManager.addProperties(this.properties, newProps, op, seq, collab);\n\t}\n\n\t/**\n\t * @returns whether this interval overlaps two numerical positions.\n\t */\n\tpublic overlapsPos(bstart: number, bend: number) {\n\t\tconst startPos = this.client.localReferencePositionToPosition(this.start);\n\t\tconst endPos = this.client.localReferencePositionToPosition(this.end);\n\t\treturn endPos > bstart && startPos < bend;\n\t}\n\n\t/**\n\t * {@inheritDoc IInterval.modify}\n\t * @deprecated - This API was never intended to be public and will be marked internal in a future release.\n\t */\n\tpublic modify(\n\t\tlabel: string,\n\t\tstart: number,\n\t\tend: number,\n\t\top?: ISequencedDocumentMessage,\n\t\tlocalSeq?: number,\n\t) {\n\t\tconst getRefType = (baseType: ReferenceType): ReferenceType => {\n\t\t\tlet refType = baseType;\n\t\t\tif (op === undefined) {\n\t\t\t\trefType &= ~ReferenceType.SlideOnRemove;\n\t\t\t\trefType |= ReferenceType.StayOnRemove;\n\t\t\t}\n\t\t\treturn refType;\n\t\t};\n\n\t\tlet startRef = this.start;\n\t\tif (start !== undefined) {\n\t\t\tstartRef = createPositionReference(\n\t\t\t\tthis.client,\n\t\t\t\tstart,\n\t\t\t\tgetRefType(this.start.refType),\n\t\t\t\top,\n\t\t\t\tundefined,\n\t\t\t\tlocalSeq,\n\t\t\t);\n\t\t\tif (this.start.properties) {\n\t\t\t\tstartRef.addProperties(this.start.properties);\n\t\t\t}\n\t\t}\n\n\t\tlet endRef = this.end;\n\t\tif (end !== undefined) {\n\t\t\tendRef = createPositionReference(\n\t\t\t\tthis.client,\n\t\t\t\tend,\n\t\t\t\tgetRefType(this.end.refType),\n\t\t\t\top,\n\t\t\t\tundefined,\n\t\t\t\tlocalSeq,\n\t\t\t);\n\t\t\tif (this.end.properties) {\n\t\t\t\tendRef.addProperties(this.end.properties);\n\t\t\t}\n\t\t}\n\n\t\tconst newInterval = new SequenceInterval(this.client, startRef, endRef, this.intervalType);\n\t\tif (this.properties) {\n\t\t\tnewInterval.initializeProperties();\n\t\t\tthis.propertyManager.copyTo(\n\t\t\t\tthis.properties,\n\t\t\t\tnewInterval.properties,\n\t\t\t\tnewInterval.propertyManager,\n\t\t\t);\n\t\t}\n\t\treturn newInterval;\n\t}\n\n\tprivate initializeProperties(): void {\n\t\tif (!this.propertyManager) {\n\t\t\tthis.propertyManager = new PropertiesManager();\n\t\t}\n\t\tif (!this.properties) {\n\t\t\tthis.properties = createMap<any>();\n\t\t}\n\t}\n}\n\nfunction createPositionReferenceFromSegoff(\n\tclient: Client,\n\tsegoff: { segment: ISegment | undefined; offset: number | undefined },\n\trefType: ReferenceType,\n\top?: ISequencedDocumentMessage,\n\tlocalSeq?: number,\n\tfromSnapshot?: boolean,\n): LocalReferencePosition {\n\tif (segoff.segment) {\n\t\tconst ref = client.createLocalReferencePosition(\n\t\t\tsegoff.segment,\n\t\t\tsegoff.offset,\n\t\t\trefType,\n\t\t\tundefined,\n\t\t);\n\t\treturn ref;\n\t}\n\n\t// Creating references on detached segments is allowed for:\n\t// - Transient segments\n\t// - References coming from a remote client (location may have been concurrently removed)\n\t// - References being rebased to a new sequence number\n\t// (segment they originally referred to may have been removed with no suitable replacement)\n\tif (\n\t\t!op &&\n\t\t!localSeq &&\n\t\t!fromSnapshot &&\n\t\t!refTypeIncludesFlag(refType, ReferenceType.Transient)\n\t) {\n\t\tthrow new UsageError(\"Non-transient references need segment\");\n\t}\n\n\treturn createDetachedLocalReferencePosition(refType);\n}\n\nfunction createPositionReference(\n\tclient: Client,\n\tpos: number,\n\trefType: ReferenceType,\n\top?: ISequencedDocumentMessage,\n\tfromSnapshot?: boolean,\n\tlocalSeq?: number,\n): LocalReferencePosition {\n\tlet segoff;\n\tif (op) {\n\t\tassert(\n\t\t\t(refType & ReferenceType.SlideOnRemove) !== 0,\n\t\t\t0x2f5 /* op create references must be SlideOnRemove */,\n\t\t);\n\t\tsegoff = client.getContainingSegment(pos, {\n\t\t\treferenceSequenceNumber: op.referenceSequenceNumber,\n\t\t\tclientId: op.clientId,\n\t\t});\n\t\tsegoff = client.getSlideToSegment(segoff);\n\t} else {\n\t\tassert(\n\t\t\t(refType & ReferenceType.SlideOnRemove) === 0 || !!fromSnapshot,\n\t\t\t0x2f6 /* SlideOnRemove references must be op created */,\n\t\t);\n\t\tsegoff = client.getContainingSegment(pos, undefined, localSeq);\n\t}\n\treturn createPositionReferenceFromSegoff(client, segoff, refType, op, localSeq, fromSnapshot);\n}\n\nexport function createSequenceInterval(\n\tlabel: string,\n\tstart: number,\n\tend: number,\n\tclient: Client,\n\tintervalType: IntervalType,\n\top?: ISequencedDocumentMessage,\n\tfromSnapshot?: boolean,\n): SequenceInterval {\n\tlet beginRefType = ReferenceType.RangeBegin;\n\tlet endRefType = ReferenceType.RangeEnd;\n\tif (intervalType === IntervalType.Transient) {\n\t\tbeginRefType = ReferenceType.Transient;\n\t\tendRefType = ReferenceType.Transient;\n\t} else {\n\t\tif (intervalType === IntervalType.Nest) {\n\t\t\tbeginRefType = ReferenceType.NestBegin;\n\t\t\tendRefType = ReferenceType.NestEnd;\n\t\t}\n\t\t// All non-transient interval references must eventually be SlideOnRemove\n\t\t// To ensure eventual consistency, they must start as StayOnRemove when\n\t\t// pending (created locally and creation op is not acked)\n\t\tif (op || fromSnapshot) {\n\t\t\tbeginRefType |= ReferenceType.SlideOnRemove;\n\t\t\tendRefType |= ReferenceType.SlideOnRemove;\n\t\t} else {\n\t\t\tbeginRefType |= ReferenceType.StayOnRemove;\n\t\t\tendRefType |= ReferenceType.StayOnRemove;\n\t\t}\n\t}\n\n\tconst startLref = createPositionReference(client, start, beginRefType, op, fromSnapshot);\n\tconst endLref = createPositionReference(client, end, endRefType, op, fromSnapshot);\n\tconst rangeProp = {\n\t\t[reservedRangeLabelsKey]: [label],\n\t};\n\tstartLref.addProperties(rangeProp);\n\tendLref.addProperties(rangeProp);\n\n\tconst ival = new SequenceInterval(client, startLref, endLref, intervalType, rangeProp);\n\treturn ival;\n}\n\nexport function defaultIntervalConflictResolver(a: Interval, b: Interval) {\n\ta.addPropertySet(b.properties);\n\treturn a;\n}\n\nexport function createIntervalIndex(conflict?: IntervalConflictResolver<Interval>) {\n\tconst helpers: IIntervalHelpers<Interval> = {\n\t\tcompareEnds: compareIntervalEnds,\n\t\tcreate: createInterval,\n\t};\n\tconst lc = new LocalIntervalCollection<Interval>(undefined as any as Client, \"\", helpers);\n\tif (conflict) {\n\t\tlc.addConflictResolver(conflict);\n\t} else {\n\t\tlc.addConflictResolver(defaultIntervalConflictResolver);\n\t}\n\treturn lc;\n}\n\nexport class LocalIntervalCollection<TInterval extends ISerializableInterval> {\n\tprivate readonly intervalTree = new IntervalTree<TInterval>();\n\tprivate readonly endIntervalTree: RedBlackTree<TInterval, TInterval>;\n\tprivate readonly intervalIdMap: Map<string, TInterval> = new Map();\n\tprivate conflictResolver: IntervalConflictResolver<TInterval> | undefined;\n\tprivate endConflictResolver: ConflictAction<TInterval, TInterval> | undefined;\n\n\tprivate static readonly legacyIdPrefix = \"legacy\";\n\n\tconstructor(\n\t\tprivate readonly client: Client,\n\t\tprivate readonly label: string,\n\t\tprivate readonly helpers: IIntervalHelpers<TInterval>,\n\t\t/** Callback invoked each time one of the endpoints of an interval slides. */\n\t\tprivate readonly onPositionChange?: (\n\t\t\tinterval: TInterval,\n\t\t\tpreviousInterval: TInterval,\n\t\t) => void,\n\t) {\n\t\t// eslint-disable-next-line @typescript-eslint/unbound-method\n\t\tthis.endIntervalTree = new RedBlackTree<TInterval, TInterval>(helpers.compareEnds);\n\t}\n\n\tpublic addConflictResolver(conflictResolver: IntervalConflictResolver<TInterval>) {\n\t\tthis.conflictResolver = conflictResolver;\n\t\tthis.endConflictResolver = (key: TInterval, currentKey: TInterval) => {\n\t\t\tconst ival = conflictResolver(key, currentKey);\n\t\t\treturn {\n\t\t\t\tdata: ival,\n\t\t\t\tkey: ival,\n\t\t\t};\n\t\t};\n\t}\n\n\tpublic map(fn: (interval: TInterval) => void) {\n\t\tthis.intervalTree.map(fn);\n\t}\n\n\tpublic createLegacyId(start: number, end: number): string {\n\t\t// Create a non-unique ID based on start and end to be used on intervals that come from legacy clients\n\t\t// without ID's.\n\t\treturn `${LocalIntervalCollection.legacyIdPrefix}${start}-${end}`;\n\t}\n\n\t/**\n\t * Validates that a serialized interval has the ID property. Creates an ID\n\t * if one does not already exist\n\t *\n\t * @param serializedInterval - The interval to be checked\n\t * @returns The interval's existing or newly created id\n\t */\n\tpublic ensureSerializedId(serializedInterval: ISerializedInterval): string {\n\t\tlet id: string | undefined = serializedInterval.properties?.[reservedIntervalIdKey];\n\t\tif (id === undefined) {\n\t\t\t// An interval came over the wire without an ID, so create a non-unique one based on start/end.\n\t\t\t// This will allow all clients to refer to this interval consistently.\n\t\t\tid = this.createLegacyId(serializedInterval.start, serializedInterval.end);\n\t\t\tconst newProps = {\n\t\t\t\t[reservedIntervalIdKey]: id,\n\t\t\t};\n\t\t\tserializedInterval.properties = addProperties(serializedInterval.properties, newProps);\n\t\t}\n\t\t// Make the ID immutable for safety's sake.\n\t\tObject.defineProperty(serializedInterval.properties, reservedIntervalIdKey, {\n\t\t\tconfigurable: false,\n\t\t\tenumerable: true,\n\t\t\twritable: false,\n\t\t});\n\n\t\treturn id;\n\t}\n\n\tpublic mapUntil(fn: (interval: TInterval) => boolean) {\n\t\tthis.intervalTree.mapUntil(fn);\n\t}\n\n\tpublic gatherIterationResults(\n\t\tresults: TInterval[],\n\t\titeratesForward: boolean,\n\t\tstart?: number,\n\t\tend?: number,\n\t) {\n\t\tif (this.intervalTree.intervals.isEmpty()) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (start === undefined && end === undefined) {\n\t\t\t// No start/end provided. Gather the whole tree in the specified order.\n\t\t\tif (iteratesForward) {\n\t\t\t\tthis.intervalTree.map((interval: TInterval) => {\n\t\t\t\t\tresults.push(interval);\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tthis.intervalTree.mapBackward((interval: TInterval) => {\n\t\t\t\t\tresults.push(interval);\n\t\t\t\t});\n\t\t\t}\n\t\t} else {\n\t\t\tconst transientInterval: TInterval = this.helpers.create(\n\t\t\t\t\"transient\",\n\t\t\t\tstart,\n\t\t\t\tend,\n\t\t\t\tthis.client,\n\t\t\t\tIntervalType.Transient,\n\t\t\t);\n\n\t\t\tif (start === undefined) {\n\t\t\t\t// Only end position provided. Since the tree is not sorted by end position,\n\t\t\t\t// walk the whole tree in the specified order, gathering intervals that match the end.\n\t\t\t\tif (iteratesForward) {\n\t\t\t\t\tthis.intervalTree.map((interval: TInterval) => {\n\t\t\t\t\t\tif (transientInterval.compareEnd(interval) === 0) {\n\t\t\t\t\t\t\tresults.push(interval);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tthis.intervalTree.mapBackward((interval: TInterval) => {\n\t\t\t\t\t\tif (transientInterval.compareEnd(interval) === 0) {\n\t\t\t\t\t\t\tresults.push(interval);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Start and (possibly) end provided. Walk the subtrees that may contain\n\t\t\t\t// this start position.\n\t\t\t\tconst compareFn =\n\t\t\t\t\tend === undefined\n\t\t\t\t\t\t? (node: IntervalNode<TInterval>) => {\n\t\t\t\t\t\t\t\treturn transientInterval.compareStart(node.key);\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: (node: IntervalNode<TInterval>) => {\n\t\t\t\t\t\t\t\treturn transientInterval.compare(node.key);\n\t\t\t\t\t\t };\n\t\t\t\tconst continueLeftFn = (cmpResult: number) => cmpResult <= 0;\n\t\t\t\tconst continueRightFn = (cmpResult: number) => cmpResult >= 0;\n\t\t\t\tconst actionFn = (node: IntervalNode<TInterval>) => {\n\t\t\t\t\tresults.push(node.key);\n\t\t\t\t};\n\n\t\t\t\tif (iteratesForward) {\n\t\t\t\t\tthis.intervalTree.intervals.walkExactMatchesForward(\n\t\t\t\t\t\tcompareFn,\n\t\t\t\t\t\tactionFn,\n\t\t\t\t\t\tcontinueLeftFn,\n\t\t\t\t\t\tcontinueRightFn,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tthis.intervalTree.intervals.walkExactMatchesBackward(\n\t\t\t\t\t\tcompareFn,\n\t\t\t\t\t\tactionFn,\n\t\t\t\t\t\tcontinueLeftFn,\n\t\t\t\t\t\tcontinueRightFn,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * @returns an array of all intervals contained in this collection that overlap the range\n\t * `[startPosition, endPosition)`.\n\t */\n\tpublic findOverlappingIntervals(startPosition: number, endPosition: number) {\n\t\tif (endPosition < startPosition || this.intervalTree.intervals.isEmpty()) {\n\t\t\treturn [];\n\t\t}\n\t\tconst transientInterval = this.helpers.create(\n\t\t\t\"transient\",\n\t\t\tstartPosition,\n\t\t\tendPosition,\n\t\t\tthis.client,\n\t\t\tIntervalType.Transient,\n\t\t);\n\n\t\tconst overlappingIntervalNodes = this.intervalTree.match(transientInterval);\n\t\treturn overlappingIntervalNodes.map((node) => node.key);\n\t}\n\n\tpublic previousInterval(pos: number) {\n\t\tconst transientInterval = this.helpers.create(\n\t\t\t\"transient\",\n\t\t\tpos,\n\t\t\tpos,\n\t\t\tthis.client,\n\t\t\tIntervalType.Transient,\n\t\t);\n\t\tconst rbNode = this.endIntervalTree.floor(transientInterval);\n\t\tif (rbNode) {\n\t\t\treturn rbNode.data;\n\t\t}\n\t}\n\n\tpublic nextInterval(pos: number) {\n\t\tconst transientInterval = this.helpers.create(\n\t\t\t\"transient\",\n\t\t\tpos,\n\t\t\tpos,\n\t\t\tthis.client,\n\t\t\tIntervalType.Transient,\n\t\t);\n\t\tconst rbNode = this.endIntervalTree.ceil(transientInterval);\n\t\tif (rbNode) {\n\t\t\treturn rbNode.data;\n\t\t}\n\t}\n\n\tpublic removeInterval(startPosition: number, endPosition: number) {\n\t\tconst transientInterval = this.helpers.create(\n\t\t\t\"transient\",\n\t\t\tstartPosition,\n\t\t\tendPosition,\n\t\t\tthis.client,\n\t\t\tIntervalType.Transient,\n\t\t);\n\t\tthis.intervalTree.remove(transientInterval);\n\t\tthis.endIntervalTree.remove(transientInterval);\n\t\treturn transientInterval;\n\t}\n\n\tprivate removeIntervalFromIndex(interval: TInterval) {\n\t\tthis.intervalTree.removeExisting(interval);\n\t\tthis.endIntervalTree.remove(interval);\n\n\t\tconst id = interval.getIntervalId();\n\n\t\tassert(id !== undefined, 0x311 /* expected id to exist on interval */);\n\n\t\tthis.intervalIdMap.delete(id);\n\t}\n\n\tpublic removeExistingInterval(interval: TInterval) {\n\t\tthis.removeIntervalFromIndex(interval);\n\t\tthis.removeIntervalListeners(interval);\n\t}\n\n\tpublic createInterval(\n\t\tstart: number,\n\t\tend: number,\n\t\tintervalType: IntervalType,\n\t\top?: ISequencedDocumentMessage,\n\t): TInterval {\n\t\treturn this.helpers.create(this.label, start, end, this.client, intervalType, op);\n\t}\n\n\tpublic addInterval(\n\t\tstart: number,\n\t\tend: number,\n\t\tintervalType: IntervalType,\n\t\tprops?: PropertySet,\n\t\top?: ISequencedDocumentMessage,\n\t) {\n\t\tconst interval: TInterval = this.createInterval(start, end, intervalType, op);\n\t\tif (interval) {\n\t\t\tif (!interval.properties) {\n\t\t\t\tinterval.properties = createMap<any>();\n\t\t\t}\n\n\t\t\tif (props) {\n\t\t\t\tinterval.addProperties(props);\n\t\t\t}\n\t\t\tinterval.properties[reservedIntervalIdKey] ??= uuid();\n\t\t\tthis.add(interval);\n\t\t}\n\t\treturn interval;\n\t}\n\n\tprivate linkEndpointsToInterval(interval: TInterval): void {\n\t\tif (interval instanceof SequenceInterval) {\n\t\t\tinterval.start.addProperties({ interval });\n\t\t\tinterval.end.addProperties({ interval });\n\t\t}\n\t}\n\n\tprivate addIntervalToIndex(interval: TInterval) {\n\t\tconst id = interval.getIntervalId();\n\t\tassert(\n\t\t\tid !== undefined,\n\t\t\t0x2c0 /* \"ID must be created before adding interval to collection\" */,\n\t\t);\n\t\t// Make the ID immutable.\n\t\tObject.defineProperty(interval.properties, reservedIntervalIdKey, {\n\t\t\tconfigurable: false,\n\t\t\tenumerable: true,\n\t\t\twritable: false,\n\t\t});\n\t\tthis.intervalTree.put(interval, this.conflictResolver);\n\t\tthis.endIntervalTree.put(interval, interval, this.endConflictResolver);\n\t\tthis.intervalIdMap.set(id, interval);\n\t}\n\n\tpublic add(interval: TInterval): void {\n\t\tthis.linkEndpointsToInterval(interval);\n\t\tthis.addIntervalToIndex(interval);\n\t\tthis.addIntervalListeners(interval);\n\t}\n\n\tpublic getIntervalById(id: string) {\n\t\treturn this.intervalIdMap.get(id);\n\t}\n\n\tpublic changeInterval(\n\t\tinterval: TInterval,\n\t\tstart: number | undefined,\n\t\tend: number | undefined,\n\t\top?: ISequencedDocumentMessage,\n\t\tlocalSeq?: number,\n\t) {\n\t\tconst newInterval = interval.modify(this.label, start, end, op, localSeq) as\n\t\t\t| TInterval\n\t\t\t| undefined;\n\t\tif (newInterval) {\n\t\t\tthis.removeExistingInterval(interval);\n\t\t\tthis.add(newInterval);\n\t\t}\n\t\treturn newInterval;\n\t}\n\n\tpublic serialize(): ISerializedIntervalCollectionV2 {\n\t\tconst intervals = this.intervalTree.intervals.keys();\n\t\treturn {\n\t\t\tlabel: this.label,\n\t\t\tintervals: intervals.map((interval) => compressInterval(interval.serialize())),\n\t\t\tversion: 2,\n\t\t};\n\t}\n\n\tprivate addIntervalListeners(interval: TInterval) {\n\t\tconst cloneRef = (ref: LocalReferencePosition) => {\n\t\t\tconst segment = ref.getSegment();\n\t\t\tif (segment === undefined) {\n\t\t\t\t// Cloning is unnecessary: refs which have slid off the string entirely\n\t\t\t\t// never get slid back on. Creation code for refs doesn't accept undefined segment\n\t\t\t\t// either, so this must be special-cased.\n\t\t\t\treturn ref;\n\t\t\t}\n\n\t\t\treturn this.client.createLocalReferencePosition(\n\t\t\t\tsegment,\n\t\t\t\tref.getOffset(),\n\t\t\t\tReferenceType.Transient,\n\t\t\t\tref.properties,\n\t\t\t);\n\t\t};\n\t\tif (interval instanceof SequenceInterval) {\n\t\t\tlet previousInterval: (TInterval & SequenceInterval) | undefined;\n\t\t\tlet pendingChanges = 0;\n\t\t\tinterval.addPositionChangeListeners(\n\t\t\t\t() => {\n\t\t\t\t\tpendingChanges++;\n\t\t\t\t\t// Note: both start and end can change and invoke beforeSlide on each endpoint before afterSlide.\n\t\t\t\t\tif (!previousInterval) {\n\t\t\t\t\t\tpreviousInterval = interval.clone() as TInterval & SequenceInterval;\n\t\t\t\t\t\tpreviousInterval.start = cloneRef(previousInterval.start);\n\t\t\t\t\t\tpreviousInterval.end = cloneRef(previousInterval.end);\n\t\t\t\t\t\tthis.removeIntervalFromIndex(interval);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tassert(\n\t\t\t\t\t\tpreviousInterval !== undefined,\n\t\t\t\t\t\t0x3fa /* Invalid interleaving of before/after slide */,\n\t\t\t\t\t);\n\t\t\t\t\tpendingChanges--;\n\t\t\t\t\tif (pendingChanges === 0) {\n\t\t\t\t\t\tthis.addIntervalToIndex(interval);\n\t\t\t\t\t\tthis.onPositionChange?.(interval, previousInterval);\n\t\t\t\t\t\tpreviousInterval = undefined;\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate removeIntervalListeners(interval: TInterval) {\n\t\tif (interval instanceof SequenceInterval) {\n\t\t\tinterval.removePositionChangeListeners();\n\t\t}\n\t}\n}\n\nexport const compareSequenceIntervalEnds = (a: SequenceInterval, b: SequenceInterval): number =>\n\tcompareReferencePositions(a.end, b.end);\n\nclass SequenceIntervalCollectionFactory\n\timplements IValueFactory<IntervalCollection<SequenceInterval>>\n{\n\tpublic load(\n\t\temitter: IValueOpEmitter,\n\t\traw: ISerializedInterval[] | ISerializedIntervalCollectionV2 = [],\n\t): IntervalCollection<SequenceInterval> {\n\t\tconst helpers: IIntervalHelpers<SequenceInterval> = {\n\t\t\tcompareEnds: compareSequenceIntervalEnds,\n\t\t\tcreate: createSequenceInterval,\n\t\t};\n\t\treturn new IntervalCollection<SequenceInterval>(helpers, true, emitter, raw);\n\t}\n\n\tpublic store(\n\t\tvalue: IntervalCollection<SequenceInterval>,\n\t): ISerializedInterval[] | ISerializedIntervalCollectionV2 {\n\t\treturn value.serializeInternal();\n\t}\n}\n\nexport class SequenceIntervalCollectionValueType\n\timplements IValueType<IntervalCollection<SequenceInterval>>\n{\n\tpublic static Name = \"sharedStringIntervalCollection\";\n\n\tpublic get name(): string {\n\t\treturn SequenceIntervalCollectionValueType.Name;\n\t}\n\n\tpublic get factory(): IValueFactory<IntervalCollection<SequenceInterval>> {\n\t\treturn SequenceIntervalCollectionValueType._factory;\n\t}\n\n\tpublic get ops(): Map<string, IValueOperation<IntervalCollection<SequenceInterval>>> {\n\t\treturn SequenceIntervalCollectionValueType._ops;\n\t}\n\n\tprivate static readonly _factory: IValueFactory<IntervalCollection<SequenceInterval>> =\n\t\tnew SequenceIntervalCollectionFactory();\n\n\tprivate static readonly _ops = makeOpsMap<SequenceInterval>();\n}\n\nconst compareIntervalEnds = (a: Interval, b: Interval) => a.end - b.end;\n\nfunction createInterval(label: string, start: number, end: number, client: Client): Interval {\n\tconst rangeProp: PropertySet = {};\n\n\tif (label && label.length > 0) {\n\t\trangeProp[reservedRangeLabelsKey] = [label];\n\t}\n\n\treturn new Interval(start, end, rangeProp);\n}\n\nclass IntervalCollectionFactory implements IValueFactory<IntervalCollection<Interval>> {\n\tpublic load(\n\t\temitter: IValueOpEmitter,\n\t\traw: ISerializedInterval[] | ISerializedIntervalCollectionV2 = [],\n\t): IntervalCollection<Interval> {\n\t\tconst helpers: IIntervalHelpers<Interval> = {\n\t\t\tcompareEnds: compareIntervalEnds,\n\t\t\tcreate: createInterval,\n\t\t};\n\t\tconst collection = new IntervalCollection<Interval>(helpers, false, emitter, raw);\n\t\tcollection.attachGraph(undefined as any as Client, \"\");\n\t\treturn collection;\n\t}\n\n\tpublic store(value: IntervalCollection<Interval>): ISerializedIntervalCollectionV2 {\n\t\treturn value.serializeInternal();\n\t}\n}\n\nexport class IntervalCollectionValueType implements IValueType<IntervalCollection<Interval>> {\n\tpublic static Name = \"sharedIntervalCollection\";\n\n\tpublic get name(): string {\n\t\treturn IntervalCollectionValueType.Name;\n\t}\n\n\tpublic get factory(): IValueFactory<IntervalCollection<Interval>> {\n\t\treturn IntervalCollectionValueType._factory;\n\t}\n\n\tpublic get ops(): Map<string, IValueOperation<IntervalCollection<Interval>>> {\n\t\treturn IntervalCollectionValueType._ops;\n\t}\n\n\tprivate static readonly _factory: IValueFactory<IntervalCollection<Interval>> =\n\t\tnew IntervalCollectionFactory();\n\tprivate static readonly _ops = makeOpsMap<Interval>();\n}\n\nexport function makeOpsMap<T extends ISerializableInterval>(): Map<\n\tstring,\n\tIValueOperation<IntervalCollection<T>>\n> {\n\tconst rebase = (\n\t\tcollection: IntervalCollection<T>,\n\t\top: IValueTypeOperationValue,\n\t\tlocalOpMetadata: IMapMessageLocalMetadata,\n\t) => {\n\t\tconst { localSeq } = localOpMetadata;\n\t\tconst rebasedValue = collection.rebaseLocalInterval(op.opName, op.value, localSeq);\n\t\tconst rebasedOp = { ...op, value: rebasedValue };\n\t\treturn { rebasedOp, rebasedLocalOpMetadata: localOpMetadata };\n\t};\n\n\treturn new Map<string, IValueOperation<IntervalCollection<T>>>([\n\t\t[\n\t\t\t\"add\",\n\t\t\t{\n\t\t\t\tprocess: (collection, params, local, op, localOpMetadata) => {\n\t\t\t\t\t// if params is undefined, the interval was deleted during\n\t\t\t\t\t// rebasing\n\t\t\t\t\tif (!params) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tassert(op !== undefined, 0x3fb /* op should exist here */);\n\t\t\t\t\tcollection.ackAdd(params, local, op, localOpMetadata);\n\t\t\t\t},\n\t\t\t\trebase,\n\t\t\t},\n\t\t],\n\t\t[\n\t\t\t\"delete\",\n\t\t\t{\n\t\t\t\tprocess: (collection, params, local, op) => {\n\t\t\t\t\tassert(op !== undefined, 0x3fc /* op should exist here */);\n\t\t\t\t\tcollection.ackDelete(params, local, op);\n\t\t\t\t},\n\t\t\t\trebase: (collection, op, localOpMetadata) => {\n\t\t\t\t\t// Deletion of intervals is based on id, so requires no rebasing.\n\t\t\t\t\treturn { rebasedOp: op, rebasedLocalOpMetadata: localOpMetadata };\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t\t[\n\t\t\t\"change\",\n\t\t\t{\n\t\t\t\tprocess: (collection, params, local, op, localOpMetadata) => {\n\t\t\t\t\t// if params is undefined, the interval was deleted during\n\t\t\t\t\t// rebasing\n\t\t\t\t\tif (!params) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tassert(op !== undefined, 0x3fd /* op should exist here */);\n\t\t\t\t\tcollection.ackChange(params, local, op, localOpMetadata);\n\t\t\t\t},\n\t\t\t\trebase,\n\t\t\t},\n\t\t],\n\t]);\n}\n\nexport type DeserializeCallback = (properties: PropertySet) => void;\n\nexport class IntervalCollectionIterator<TInterval extends ISerializableInterval>\n\timplements Iterator<TInterval>\n{\n\tprivate readonly results: TInterval[];\n\tprivate index: number;\n\n\tconstructor(\n\t\tcollection: IntervalCollection<TInterval>,\n\t\titeratesForward: boolean = true,\n\t\tstart?: number,\n\t\tend?: number,\n\t) {\n\t\tthis.results = [];\n\t\tthis.index = 0;\n\n\t\tcollection.gatherIterationResults(this.results, iteratesForward, start, end);\n\t}\n\n\tpublic next(): IteratorResult<TInterval> {\n\t\tif (this.index < this.results.length) {\n\t\t\treturn {\n\t\t\t\tvalue: this.results[this.index++],\n\t\t\t\tdone: false,\n\t\t\t};\n\t\t}\n\n\t\treturn {\n\t\t\tvalue: undefined,\n\t\t\tdone: true,\n\t\t};\n\t}\n}\n\n/**\n * Change events emitted by `IntervalCollection`s\n */\nexport interface IIntervalCollectionEvent<TInterval extends ISerializableInterval> extends IEvent {\n\t/**\n\t * This event is invoked whenever the endpoints of an interval may have changed.\n\t * This can happen on:\n\t * - local endpoint modification\n\t * - ack of a remote endpoint modification\n\t * - position change due to segment sliding (slides due to mergeTree segment deletion will always appear local)\n\t * The `interval` argument reflects the new values.\n\t * `previousInterval` contains transient `ReferencePosition`s at the same location as the interval's original\n\t * endpoints. These references should be used for position information only.\n\t * `local` reflects whether the change originated locally.\n\t * `op` is defined if and only if the server has acked this change.\n\t */\n\t(\n\t\tevent: \"changeInterval\",\n\t\tlistener: (\n\t\t\tinterval: TInterval,\n\t\t\tpreviousInterval: TInterval,\n\t\t\tlocal: boolean,\n\t\t\top: ISequencedDocumentMessage | undefined,\n\t\t) => void,\n\t);\n\t/**\n\t * This event is invoked whenever an interval is added or removed from the collection.\n\t * `local` reflects whether the change originated locally.\n\t * `op` is defined if and only if the server has acked this change.\n\t */\n\t(\n\t\tevent: \"addInterval\" | \"deleteInterval\",\n\t\tlistener: (\n\t\t\tinterval: TInterval,\n\t\t\tlocal: boolean,\n\t\t\top: ISequencedDocumentMessage | undefined,\n\t\t) => void,\n\t);\n\t/**\n\t * This event is invoked whenever an interval's properties have changed.\n\t * `interval` reflects the state of the updated properties.\n\t * `propertyDeltas` is a map-like whose keys contain all values that were changed, and whose\n\t * values contain all previous values of the property set.\n\t * This object can be used directly in a call to `changeProperties` to revert the property change if desired.\n\t * `local` reflects whether the change originated locally.\n\t * `op` is defined if and only if the server has acked this change.\n\t */\n\t(\n\t\tevent: \"propertyChanged\",\n\t\tlistener: (\n\t\t\tinterval: TInterval,\n\t\t\tpropertyDeltas: PropertySet,\n\t\t\tlocal: boolean,\n\t\t\top: ISequencedDocumentMessage | undefined,\n\t\t) => void,\n\t);\n}\n\n/**\n * Collection of intervals that supports addition, modification, removal, and efficient spatial querying.\n * This class is not a DDS in its own right, but emits events on mutating operations such that it's possible to\n * integrate into a DDS.\n * This aligns with its usage in `SharedSegmentSequence`, which allows associating intervals to positions in the\n * sequence DDS which are broadcast to all other clients in an eventually consistent fashion.\n */\nexport class IntervalCollection<TInterval extends ISerializableInterval> extends TypedEventEmitter<\n\tIIntervalCollectionEvent<TInterval>\n> {\n\tprivate savedSerializedIntervals?: ISerializedInterval[];\n\tprivate localCollection: LocalIntervalCollection<TInterval> | undefined;\n\tprivate onDeserialize: DeserializeCallback | undefined;\n\tprivate client: Client | undefined;\n\tprivate readonly localSeqToSerializedInterval = new Map<\n\t\tnumber,\n\t\tISerializedInterval | SerializedIntervalDelta\n\t>();\n\tprivate readonly localSeqToRebasedInterval = new Map<\n\t\tnumber,\n\t\tISerializedInterval | SerializedIntervalDelta\n\t>();\n\tprivate readonly pendingChangesStart: Map<string, ISerializedInterval[]> = new Map<\n\t\tstring,\n\t\tISerializedInterval[]\n\t>();\n\tprivate readonly pendingChangesEnd: Map<string, ISerializedInterval[]> = new Map<\n\t\tstring,\n\t\tISerializedInterval[]\n\t>();\n\n\tpublic get attached(): boolean {\n\t\treturn !!this.localCollection;\n\t}\n\n\t/** @internal */\n\tconstructor(\n\t\tprivate readonly helpers: IIntervalHelpers<TInterval>,\n\t\tprivate readonly requiresClient: boolean,\n\t\tprivate readonly emitter: IValueOpEmitter,\n\t\tserializedIntervals: ISerializedInterval[] | ISerializedIntervalCollectionV2,\n\t) {\n\t\tsuper();\n\n\t\tthis.savedSerializedIntervals = Array.isArray(serializedIntervals)\n\t\t\t? serializedIntervals\n\t\t\t: serializedIntervals.intervals.map((i) =>\n\t\t\t\t\tdecompressInterval(i, serializedIntervals.label),\n\t\t\t );\n\t}\n\n\tprivate rebasePositionWithSegmentSlide(\n\t\tpos: number,\n\t\tseqNumberFrom: number,\n\t\tlocalSeq: number,\n\t): number | undefined {\n\t\tif (!this.client) {\n\t\t\tthrow new LoggingError(\"mergeTree client must exist\");\n\t\t}\n\t\tconst { clientId } = this.client.getCollabWindow();\n\t\tconst { segment, offset } = this.client.getContainingSegment(\n\t\t\tpos,\n\t\t\t{\n\t\t\t\treferenceSequenceNumber: seqNumberFrom,\n\t\t\t\tclientId: this.client.getLongClientId(clientId),\n\t\t\t},\n\t\t\tlocalSeq,\n\t\t);\n\n\t\t// if segment is undefined, it slid off the string\n\t\tassert(segment !== undefined, 0x54e /* No segment found */);\n\n\t\tconst segoff = this.client.getSlideToSegment({ segment, offset }) ?? segment;\n\n\t\t// case happens when rebasing op, but concurrently entire string has been deleted\n\t\tif (segoff.segment === undefined || segoff.offset === undefined) {\n\t\t\treturn DetachedReferencePosition;\n\t\t}\n\n\t\tassert(\n\t\t\toffset !== undefined && 0 <= offset && offset < segment.cachedLength,\n\t\t\t0x54f /* Invalid offset */,\n\t\t);\n\t\treturn this.client.findReconnectionPosition(segoff.segment, localSeq) + segoff.offset;\n\t}\n\n\tprivate computeRebasedPositions(\n\t\tlocalSeq: number,\n\t): ISerializedInterval | SerializedIntervalDelta {\n\t\tassert(\n\t\t\tthis.client !== undefined,\n\t\t\t0x550 /* Client should be defined when computing rebased position */,\n\t\t);\n\t\tconst original = this.localSeqToSerializedInterval.get(localSeq);\n\t\tassert(\n\t\t\toriginal !== undefined,\n\t\t\t0x551 /* Failed to store pending serialized interval info for this localSeq. */,\n\t\t);\n\t\tconst rebased = { ...original };\n\t\tconst { start, end, sequenceNumber } = original;\n\t\tif (start !== undefined) {\n\t\t\trebased.start = this.rebasePositionWithSegmentSlide(start, sequenceNumber, localSeq);\n\t\t}\n\t\tif (end !== undefined) {\n\t\t\trebased.end = this.rebasePositionWithSegmentSlide(end, sequenceNumber, localSeq);\n\t\t}\n\t\treturn rebased;\n\t}\n\n\t/** @internal */\n\tpublic attachGraph(client: Client, label: string) {\n\t\tif (this.attached) {\n\t\t\tthrow new LoggingError(\"Only supports one Sequence attach\");\n\t\t}\n\n\t\tif (client === undefined && this.requiresClient) {\n\t\t\tthrow new LoggingError(\"Client required for this collection\");\n\t\t}\n\n\t\t// Instantiate the local interval collection based on the saved intervals\n\t\tthis.client = client;\n\t\tif (client) {\n\t\t\tclient.on(\"normalize\", () => {\n\t\t\t\tfor (const localSeq of this.localSeqToSerializedInterval.keys()) {\n\t\t\t\t\tthis.localSeqToRebasedInterval.set(\n\t\t\t\t\t\tlocalSeq,\n\t\t\t\t\t\tthis.computeRebasedPositions(localSeq),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\n\t\tthis.localCollection = new LocalIntervalCollection<TInterval>(\n\t\t\tclient,\n\t\t\tlabel,\n\t\t\tthis.helpers,\n\t\t\t(interval, previousInterval) => this.emitChange(interval, previousInterval, true),\n\t\t);\n\t\tif (this.savedSerializedIntervals) {\n\t\t\tfor (const serializedInterval of this.savedSerializedIntervals) {\n\t\t\t\tthis.localCollection.ensureSerializedId(serializedInterval);\n\t\t\t\tconst { start, end, intervalType, properties } = serializedInterval;\n\t\t\t\tconst interval = this.helpers.create(\n\t\t\t\t\tlabel,\n\t\t\t\t\tstart,\n\t\t\t\t\tend,\n\t\t\t\t\tclient,\n\t\t\t\t\tintervalType,\n\t\t\t\t\tundefined,\n\t\t\t\t\ttrue,\n\t\t\t\t);\n\t\t\t\tif (properties) {\n\t\t\t\t\tinterval.addProperties(properties);\n\t\t\t\t}\n\t\t\t\tthis.localCollection.add(interval);\n\t\t\t}\n\t\t}\n\t\tthis.savedSerializedIntervals = undefined;\n\t}\n\n\t/**\n\t * Gets the next local sequence number, modifying this client's collab window in doing so.\n\t */\n\tprivate getNextLocalSeq(): number {\n\t\tif (this.client) {\n\t\t\treturn ++this.client.getCollabWindow().localSeq;\n\t\t}\n\n\t\treturn 0;\n\t}\n\n\tprivate emitChange(\n\t\tinterval: TInterval,\n\t\tpreviousInterval: TInterval,\n\t\tlocal: boolean,\n\t\top?: ISequencedDocumentMessage,\n\t): void {\n\t\t// Temporarily make references transient so that positional queries work (non-transient refs\n\t\t// on resolve to DetachedPosition on any segments that don't contain them). The original refType\n\t\t// is restored as single-endpoint changes re-use previous references.\n\t\tlet startRefType: ReferenceType;\n\t\tlet endRefType: ReferenceType;\n\t\tif (previousInterval instanceof SequenceInterval) {\n\t\t\tstartRefType = previousInterval.start.refType;\n\t\t\tendRefType = previousInterval.end.refType;\n\t\t\tpreviousInterval.start.refType = ReferenceType.Transient;\n\t\t\tpreviousInterval.end.refType = ReferenceType.Transient;\n\t\t\tthis.emit(\"changeInterval\", interval, previousInterval, local, op);\n\t\t\tpreviousInterval.start.refType = startRefType;\n\t\t\tpreviousInterval.end.refType = endRefType;\n\t\t} else {\n\t\t\tthis.emit(\"changeInterval\", interval, previousInterval, local, op);\n\t\t}\n\t}\n\n\t/**\n\t * @returns the interval in this collection that has the provided `id`.\n\t * If no interval in the collection has this `id`, returns `undefined`.\n\t */\n\tpublic getIntervalById(id: string) {\n\t\tif (!this.localCollection) {\n\t\t\tthrow new LoggingError(\"attach must be called before accessing intervals\");\n\t\t}\n\t\treturn this.localCollection.getIntervalById(id);\n\t}\n\n\t/**\n\t * Creates a new interval and add it to the collection.\n\t * @param start - interval start position (inclusive)\n\t * @param end - interval end position (exclusive)\n\t * @param intervalType - type of the interval. All intervals are SlideOnRemove. Intervals may not be Transient.\n\t * @param props - properties of the interval\n\t * @returns - the created interval\n\t * @remarks - See documentation on {@link SequenceInterval} for comments on interval endpoint semantics: there are subtleties\n\t * with how the current half-open behavior is represented.\n\t */\n\tpublic add(\n\t\tstart: number,\n\t\tend: number,\n\t\tintervalType: IntervalType,\n\t\tprops?: PropertySet,\n\t): TInterval {\n\t\tif (!this.localCollection) {\n\t\t\tthrow new LoggingError(\"attach must be called prior to adding intervals\");\n\t\t}\n\t\tif (intervalType & IntervalType.Transient) {\n\t\t\tthrow new LoggingError(\"Can not add transient intervals\");\n\t\t}\n\n\t\tconst interval: TInterval = this.localCollection.addInterval(\n\t\t\tstart,\n\t\t\tend,\n\t\t\tintervalType,\n\t\t\tprops,\n\t\t);\n\n\t\tif (interval) {\n\t\t\tconst serializedInterval = {\n\t\t\t\tend,\n\t\t\t\tintervalType,\n\t\t\t\tproperties: interval.properties,\n\t\t\t\tsequenceNumber: this.client?.getCurrentSeq() ?? 0,\n\t\t\t\tstart,\n\t\t\t};\n\t\t\tconst localSeq = this.getNextLocalSeq();\n\t\t\tthis.localSeqToSerializedInterval.set(localSeq, serializedInterval);\n\t\t\t// Local ops get submitted to the server. Remote ops have the deserializer run.\n\t\t\tthis.emitter.emit(\"add\", undefined, serializedInterval, { localSeq });\n\t\t}\n\n\t\tthis.emit(\"addInterval\", interval, true, undefined);\n\n\t\treturn interval;\n\t}\n\n\tprivate deleteExistingInterval(\n\t\tinterval: TInterval,\n\t\tlocal: boolean,\n\t\top?: ISequencedDocumentMessage,\n\t) {\n\t\tif (!this.localCollection) {\n\t\t\tthrow new LoggingError(\"Attach must be called before accessing intervals\");\n\t\t}\n\t\t// The given interval is known to exist in the collection.\n\t\tthis.localCollection.removeExistingInterval(interval);\n\n\t\tif (interval) {\n\t\t\t// Local ops get submitted to the server. Remote ops have the deserializer run.\n\t\t\tif (local) {\n\t\t\t\tthis.emitter.emit(\"delete\", undefined, interval.serialize(), {\n\t\t\t\t\tlocalSeq: this.getNextLocalSeq(),\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tif (this.onDeserialize) {\n\t\t\t\t\tthis.onDeserialize(interval);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthis.emit(\"deleteInterval\", interval, local, op);\n\t}\n\n\t/**\n\t * Removes an interval from the collection.\n\t * @param id - Id of the interval to remove\n\t * @returns the removed interval\n\t */\n\tpublic removeIntervalById(id: string) {\n\t\tif (!this.localCollection) {\n\t\t\tthrow new LoggingError(\"Attach must be called before accessing intervals\");\n\t\t}\n\t\tconst interval = this.localCollection.getIntervalById(id);\n\t\tif (interval) {\n\t\t\tthis.deleteExistingInterval(interval, true, undefined);\n\t\t}\n\t\treturn interval;\n\t}\n\n\t/**\n\t * Changes the properties on an existing interval.\n\t * @param id - Id of the interval whose properties should be changed\n\t * @param props - Property set to apply to the interval. Shallow merging is used between any existing properties\n\t * and `prop`, i.e. the interval will end up with a property object equivalent to `{ ...oldProps, ...props }`.\n\t */\n\tpublic changeProperties(id: string, props: PropertySet) {\n\t\tif (!this.attached) {\n\t\t\tthrow new LoggingError(\"Attach must be called before accessing intervals\");\n\t\t}\n\t\tif (typeof id !== \"string\") {\n\t\t\tthrow new LoggingError(\"Change API requires an ID that is a string\");\n\t\t}\n\t\tif (!props) {\n\t\t\tthrow new LoggingError(\"changeProperties should be called with a property set\");\n\t\t}\n\n\t\tconst interval = this.getIntervalById(id);\n\t\tif (interval) {\n\t\t\t// Pass Unassigned as the sequence number to indicate that this is a local op that is waiting for an ack.\n\t\t\tconst deltaProps = interval.addProperties(props, true, UnassignedSequenceNumber);\n\t\t\tconst serializedInterval: ISerializedInterval = interval.serialize();\n\n\t\t\t// Emit a change op that will only change properties. Add the ID to\n\t\t\t// the property bag provided by the caller.\n\t\t\tserializedInterval.start = undefined as any;\n\t\t\tserializedInterval.end = undefined as any;\n\n\t\t\tserializedInterval.properties = props;\n\t\t\tserializedInterval.properties[reservedIntervalIdKey] = interval.getIntervalId();\n\t\t\tconst localSeq = this.getNextLocalSeq();\n\t\t\tthis.localSeqToSerializedInterval.set(localSeq, serializedInterval);\n\t\t\tthis.emitter.emit(\"change\", undefined, serializedInterval, { localSeq });\n\t\t\tthis.emit(\"propertyChanged\", interval, deltaProps, true, undefined);\n\t\t}\n\t}\n\n\t/**\n\t * Changes the endpoints of an existing interval.\n\t * @param id - Id of the interval to change\n\t * @param start - New start value, if defined. `undefined` signifies this endpoint should be left unchanged.\n\t * @param end - New end value, if defined. `undefined` signifies this endpoint should be left unchanged.\n\t * @returns the interval that was changed, if it existed in the collection.\n\t */\n\tpublic change(id: string, start?: number, end?: number): TInterval | undefined {\n\t\tif (!this.localCollection) {\n\t\t\tthrow new LoggingError(\"Attach must be called before accessing intervals\");\n\t\t}\n\n\t\t// Force id to be a string.\n\t\tif (typeof id !== \"string\") {\n\t\t\tthrow new LoggingError(\"Change API requires an ID that is a string\");\n\t\t}\n\n\t\tconst interval = this.getIntervalById(id);\n\t\tif (interval) {\n\t\t\tconst newInterval = this.localCollection.changeInterval(interval, start, end);\n\t\t\tif (!newInterval) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tconst serializedInterval: SerializedIntervalDelta = interval.serialize();\n\t\t\tserializedInterval.start = start;\n\t\t\tserializedInterval.end = end;\n\t\t\t// Emit a property bag containing only the ID, as we don't intend for this op to change any properties.\n\t\t\tserializedInterval.properties = {\n\t\t\t\t[reservedIntervalIdKey]: interval.getIntervalId(),\n\t\t\t};\n\t\t\tconst localSeq = this.getNextLocalSeq();\n\t\t\tthis.localSeqToSerializedInterval.set(localSeq, serializedInterval);\n\t\t\tthis.emitter.emit(\"change\", undefined, serializedInterval, { localSeq });\n\t\t\tthis.addPendingChange(id, serializedInterval);\n\t\t\tthis.emitChange(newInterval, interval, true);\n\t\t\treturn newInterval;\n\t\t}\n\t\t// No interval to change\n\t\treturn undefined;\n\t}\n\n\tprivate addPendingChange(id: string, serializedInterval: SerializedIntervalDelta) {\n\t\tif (serializedInterval.start !== undefined) {\n\t\t\tthis.addPendingChangeHelper(id, this.pendingChangesStart, serializedInterval);\n\t\t}\n\t\tif (serializedInterval.end !== undefined) {\n\t\t\tthis.addPendingChangeHelper(id, this.pendingChangesEnd, serializedInterval);\n\t\t}\n\t}\n\n\tprivate addPendingChangeHelper(\n\t\tid: string,\n\t\tpendingChanges: Map<string, SerializedIntervalDelta[]>,\n\t\tserializedInterval: SerializedIntervalDelta,\n\t) {\n\t\tlet entries: SerializedIntervalDelta[] | undefined = pendingChanges.get(id);\n\t\tif (!entries) {\n\t\t\tentries = [];\n\t\t\tpendingChanges.set(id, entries);\n\t\t}\n\t\tentries.push(serializedInterval);\n\t}\n\n\tprivate removePendingChange(serializedInterval: SerializedIntervalDelta) {\n\t\t// Change ops always have an ID.\n\t\tconst id: string = serializedInterval.properties?.[reservedIntervalIdKey];\n\t\tif (serializedInterval.start !== undefined) {\n\t\t\tthis.removePendingChangeHelper(id, this.pendingChangesStart, serializedInterval);\n\t\t}\n\t\tif (serializedInterval.end !== undefined) {\n\t\t\tthis.removePendingChangeHelper(id, this.pendingChangesEnd, serializedInterval);\n\t\t}\n\t}\n\n\tprivate removePendingChangeHelper(\n\t\tid: string,\n\t\tpendingChanges: Map<string, SerializedIntervalDelta[]>,\n\t\tserializedInterval: SerializedIntervalDelta,\n\t) {\n\t\tconst entries = pendingChanges.get(id);\n\t\tif (entries) {\n\t\t\tconst pendingChange = entries.shift();\n\t\t\tif (entries.length === 0) {\n\t\t\t\tpendingChanges.delete(id);\n\t\t\t}\n\t\t\tif (\n\t\t\t\tpendingChange?.start !== serializedInterval.start ||\n\t\t\t\tpendingChange?.end !== serializedInterval.end\n\t\t\t) {\n\t\t\t\tthrow new LoggingError(\"Mismatch in pending changes\");\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate hasPendingChangeStart(id: string) {\n\t\tconst entries = this.pendingChangesStart.get(id);\n\t\treturn entries && entries.length !== 0;\n\t}\n\n\tprivate hasPendingChangeEnd(id: string) {\n\t\tconst entries = this.pendingChangesEnd.get(id);\n\t\treturn entries && entries.length !== 0;\n\t}\n\n\t/** @internal */\n\tpublic ackChange(\n\t\tserializedInterval: ISerializedInterval,\n\t\tlocal: boolean,\n\t\top: ISequencedDocumentMessage,\n\t\tlocalOpMetadata: IMapMessageLocalMetadata | undefined,\n\t) {\n\t\tif (!this.localCollection) {\n\t\t\tthrow new LoggingError(\"Attach must be called before accessing intervals\");\n\t\t}\n\n\t\tif (local) {\n\t\t\tassert(\n\t\t\t\tlocalOpMetadata !== undefined,\n\t\t\t\t0x552 /* op metadata should be defined for local op */,\n\t\t\t);\n\t\t\tthis.localSeqToSerializedInterval.delete(localOpMetadata?.localSeq);\n\t\t\t// This is an ack from the server. Remove the pending change.\n\t\t\tthis.removePendingChange(serializedInterval);\n\t\t}\n\n\t\t// Note that the ID is in the property bag only to allow us to find the interval.\n\t\t// This API cannot change the ID, and writing to the ID property will result in an exception. So we\n\t\t// strip it out of the properties here.\n\t\tconst { [reservedIntervalIdKey]: id, ...newProps } = serializedInterval.properties ?? {};\n\t\tassert(id !== undefined, 0x3fe /* id must exist on the interval */);\n\t\tconst interval: TInterval | undefined = this.getIntervalById(id);\n\t\tif (!interval) {\n\t\t\t// The interval has been removed locally; no-op.\n\t\t\treturn;\n\t\t}\n\n\t\tif (local) {\n\t\t\t// Let the propertyManager prune its pending change-properties set.\n\t\t\tinterval.propertyManager?.ackPendingProperties({\n\t\t\t\ttype: MergeTreeDeltaType.ANNOTATE,\n\t\t\t\tprops: serializedInterval.properties ?? {},\n\t\t\t});\n\n\t\t\tthis.ackInterval(interval, op);\n\t\t} else {\n\t\t\t// If there are pending changes with this ID, don't apply the remote start/end change, as the local ack\n\t\t\t// should be the winning change.\n\t\t\tlet start: number | undefined;\n\t\t\tlet end: number | undefined;\n\t\t\t// Track pending start/end independently of one another.\n\t\t\tif (!this.hasPendingChangeStart(id)) {\n\t\t\t\tstart = serializedInterval.start;\n\t\t\t}\n\t\t\tif (!this.hasPendingChangeEnd(id)) {\n\t\t\t\tend = serializedInterval.end;\n\t\t\t}\n\n\t\t\tlet newInterval = interval;\n\t\t\tif (start !== undefined || end !== undefined) {\n\t\t\t\t// If changeInterval gives us a new interval, work with that one. Otherwise keep working with\n\t\t\t\t// the one we originally found in the tree.\n\t\t\t\tnewInterval =\n\t\t\t\t\tthis.localCollection.changeInterval(interval, start, end, op) ?? interval;\n\t\t\t}\n\t\t\tconst deltaProps = newInterval.addProperties(newProps, true, op.sequenceNumber);\n\t\t\tif (this.onDeserialize) {\n\t\t\t\tthis.onDeserialize(newInterval);\n\t\t\t}\n\n\t\t\tif (newInterval !== interval) {\n\t\t\t\tthis.emitChange(newInterval, interval, local, op);\n\t\t\t}\n\n\t\t\tconst changedProperties = Object.keys(newProps).length > 0;\n\t\t\tif (changedProperties) {\n\t\t\t\tthis.emit(\"propertyChanged\", interval, deltaProps, local, op);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * @deprecated - This functionality was useful when adding two intervals at the same start/end positions resulted\n\t * in a conflict. This is no longer the case (as of PR#6407), as interval collections support multiple intervals\n\t * at the same location and gives each interval a unique id.\n\t *\n\t * As such, the conflict resolver is never invoked and unnecessary. This API will be removed in an upcoming release.\n\t */\n\tpublic addConflictResolver(conflictResolver: IntervalConflictResolver<TInterval>): void {\n\t\tif (!this.localCollection) {\n\t\t\tthrow new LoggingError(\"attachSequence must be called\");\n\t\t}\n\t\tthis.localCollection.addConflictResolver(conflictResolver);\n\t}\n\n\tpublic attachDeserializer(onDeserialize: DeserializeCallback): void {\n\t\t// If no deserializer is specified can skip all processing work\n\t\tif (!onDeserialize) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Start by storing the callbacks so that any subsequent modifications make use of them\n\t\tthis.onDeserialize = onDeserialize;\n\n\t\t// Trigger the async prepare work across all values in the collection\n\t\tthis.localCollection?.map((interval) => {\n\t\t\tonDeserialize(interval);\n\t\t});\n\t}\n\n\t/**\n\t * Returns new interval after rebasing. If undefined, the interval was\n\t * deleted as a result of rebasing. This can occur if the interval applies\n\t * to a range that no longer exists, and the interval was unable to slide.\n\t *\n\t * @internal\n\t */\n\tpublic rebaseLocalInterval(\n\t\topName: string,\n\t\tserializedInterval: SerializedIntervalDelta,\n\t\tlocalSeq: number,\n\t): SerializedIntervalDelta | undefined {\n\t\tif (!this.client) {\n\t\t\t// If there's no associated mergeTree client, the originally submitted op is still correct.\n\t\t\treturn serializedInterval;\n\t\t}\n\t\tif (!this.attached) {\n\t\t\tthrow new LoggingError(\"attachSequence must be called\");\n\t\t}\n\n\t\tconst { intervalType, properties } = serializedInterval;\n\n\t\tconst { start: startRebased, end: endRebased } =\n\t\t\tthis.localSeqToRebasedInterval.get(localSeq) ?? this.computeRebasedPositions(localSeq);\n\n\t\tconst intervalId = properties?.[reservedIntervalIdKey];\n\t\tconst localInterval = this.localCollection?.getIntervalById(intervalId);\n\n\t\tconst rebased: SerializedIntervalDelta = {\n\t\t\tstart: startRebased,\n\t\t\tend: endRebased,\n\t\t\tintervalType,\n\t\t\tsequenceNumber: this.client?.getCurrentSeq() ?? 0,\n\t\t\tproperties,\n\t\t};\n\n\t\tif (\n\t\t\topName === \"change\" &&\n\t\t\t(this.hasPendingChangeStart(intervalId) || this.hasPendingChangeEnd(intervalId))\n\t\t) {\n\t\t\tthis.removePendingChange(serializedInterval);\n\t\t\tthis.addPendingChange(intervalId, rebased);\n\t\t}\n\n\t\t// if the interval slid off the string, rebase the op to be a noop and delete the interval.\n\t\tif (\n\t\t\tstartRebased === DetachedReferencePosition ||\n\t\t\tendRebased === DetachedReferencePosition\n\t\t) {\n\t\t\tif (localInterval) {\n\t\t\t\tthis.localCollection?.removeExistingInterval(localInterval);\n\t\t\t}\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif (localInterval !== undefined) {\n\t\t\t// we know we must be using `SequenceInterval` because `this.client` exists\n\t\t\tassert(\n\t\t\t\tlocalInterval instanceof SequenceInterval,\n\t\t\t\t0x3a0 /* localInterval must be `SequenceInterval` when used with client */,\n\t\t\t);\n\t\t\t// The rebased op may place this interval's endpoints on different segments. Calling `changeInterval` here\n\t\t\t// updates the local client's state to be consistent with the emitted op.\n\t\t\tthis.localCollection?.changeInterval(\n\t\t\t\tlocalInterval,\n\t\t\t\tstartRebased,\n\t\t\t\tendRebased,\n\t\t\t\tundefined,\n\t\t\t\tlocalSeq,\n\t\t\t);\n\t\t}\n\n\t\treturn rebased;\n\t}\n\n\tprivate getSlideToSegment(lref: LocalReferencePosition) {\n\t\tif (!this.client) {\n\t\t\tthrow new LoggingError(\"client does not exist\");\n\t\t}\n\t\tconst segoff = { segment: lref.getSegment(), offset: lref.getOffset() };\n\t\tif (segoff.segment?.localRefs?.has(lref) !== true) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst newSegoff = this.client.getSlideToSegment(segoff);\n\t\tconst value: { segment: ISegment | undefined; offset: number | undefined } | undefined =\n\t\t\tsegoff.segment === newSegoff.segment && segoff.offset === newSegoff.offset\n\t\t\t\t? undefined\n\t\t\t\t: newSegoff;\n\t\treturn value;\n\t}\n\n\tprivate setSlideOnRemove(lref: LocalReferencePosition) {\n\t\tlet refType = lref.refType;\n\t\trefType = refType & ~ReferenceType.StayOnRemove;\n\t\trefType = refType | ReferenceType.SlideOnRemove;\n\t\tlref.refType = refType;\n\t}\n\n\tprivate ackInterval(interval: TInterval, op: ISequencedDocumentMessage) {\n\t\t// Only SequenceIntervals need potential sliding\n\t\tif (!(interval instanceof SequenceInterval)) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (\n\t\t\t!refTypeIncludesFlag(interval.start, ReferenceType.StayOnRemove) &&\n\t\t\t!refTypeIncludesFlag(interval.end, ReferenceType.StayOnRemove)\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst newStart = this.getSlideToSegment(interval.start);\n\t\tconst newEnd = this.getSlideToSegment(interval.end);\n\n\t\tconst id = interval.properties[reservedIntervalIdKey];\n\t\tconst hasPendingStartChange = this.hasPendingChangeStart(id);\n\t\tconst hasPendingEndChange = this.hasPendingChangeEnd(id);\n\n\t\tif (!hasPendingStartChange) {\n\t\t\tthis.setSlideOnRemove(interval.start);\n\t\t}\n\n\t\tif (!hasPendingEndChange) {\n\t\t\tthis.setSlideOnRemove(interval.end);\n\t\t}\n\n\t\tconst needsStartUpdate = newStart !== undefined && !hasPendingStartChange;\n\t\tconst needsEndUpdate = newEnd !== undefined && !hasPendingEndChange;\n\n\t\tif (needsStartUpdate || needsEndUpdate) {\n\t\t\tif (!this.localCollection) {\n\t\t\t\tthrow new LoggingError(\"Attach must be called before accessing intervals\");\n\t\t\t}\n\n\t\t\t// `interval`'s endpoints will get modified in-place, so clone it prior to doing so for event emission.\n\t\t\tconst oldInterval = interval.clone() as TInterval & SequenceInterval;\n\n\t\t\t// In this case, where we change the start or end of an interval,\n\t\t\t// it is necessary to remove and re-add the interval listeners.\n\t\t\t// This ensures that the correct listeners are added to the LocalReferencePosition.\n\t\t\tthis.localCollection.removeExistingInterval(interval);\n\t\t\tif (!this.client) {\n\t\t\t\tthrow new LoggingError(\"client does not exist\");\n\t\t\t}\n\n\t\t\tif (needsStartUpdate) {\n\t\t\t\tconst props = interval.start.properties;\n\t\t\t\tinterval.start = createPositionReferenceFromSegoff(\n\t\t\t\t\tthis.client,\n\t\t\t\t\tnewStart,\n\t\t\t\t\tinterval.start.refType,\n\t\t\t\t\top,\n\t\t\t\t);\n\t\t\t\tif (props) {\n\t\t\t\t\tinterval.start.addProperties(props);\n\t\t\t\t}\n\t\t\t\tconst oldSeg = oldInterval.start.getSegment();\n\t\t\t\t// remove and rebuild start interval as transient for event\n\t\t\t\tthis.client.removeLocalReferencePosition(oldInterval.start);\n\t\t\t\toldInterval.start.refType = ReferenceType.Transient;\n\t\t\t\toldSeg?.localRefs?.addLocalRef(oldInterval.start, oldInterval.start.getOffset());\n\t\t\t}\n\t\t\tif (needsEndUpdate) {\n\t\t\t\tconst props = interval.end.properties;\n\t\t\t\tinterval.end = createPositionReferenceFromSegoff(\n\t\t\t\t\tthis.client,\n\t\t\t\t\tnewEnd,\n\t\t\t\t\tinterval.end.refType,\n\t\t\t\t\top,\n\t\t\t\t);\n\t\t\t\tif (props) {\n\t\t\t\t\tinterval.end.addProperties(props);\n\t\t\t\t}\n\t\t\t\t// remove and rebuild end interval as transient for event\n\t\t\t\tconst oldSeg = oldInterval.end.getSegment();\n\t\t\t\tthis.client.removeLocalReferencePosition(oldInterval.end);\n\t\t\t\toldInterval.end.refType = ReferenceType.Transient;\n\t\t\t\toldSeg?.localRefs?.addLocalRef(oldInterval.end, oldInterval.end.getOffset());\n\t\t\t}\n\t\t\tthis.localCollection.add(interval);\n\t\t\tthis.emitChange(interval, oldInterval as TInterval, true, op);\n\t\t}\n\t}\n\n\t/** @internal */\n\tpublic ackAdd(\n\t\tserializedInterval: ISerializedInterval,\n\t\tlocal: boolean,\n\t\top: ISequencedDocumentMessage,\n\t\tlocalOpMetadata: IMapMessageLocalMetadata | undefined,\n\t) {\n\t\tif (local) {\n\t\t\tassert(\n\t\t\t\tlocalOpMetadata !== undefined,\n\t\t\t\t0x553 /* op metadata should be defined for local op */,\n\t\t\t);\n\t\t\tthis.localSeqToSerializedInterval.delete(localOpMetadata.localSeq);\n\t\t\tconst id: string = serializedInterval.properties?.[reservedIntervalIdKey];\n\t\t\tconst localInterval = this.getIntervalById(id);\n\t\t\tif (localInterval) {\n\t\t\t\tthis.ackInterval(localInterval, op);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (!this.localCollection) {\n\t\t\tthrow new LoggingError(\"attachSequence must be called\");\n\t\t}\n\n\t\tthis.localCollection.ensureSerializedId(serializedInterval);\n\n\t\tconst interval: TInterval = this.localCollection.addInterval(\n\t\t\tserializedInterval.start,\n\t\t\tserializedInterval.end,\n\t\t\tserializedInterval.intervalType,\n\t\t\tserializedInterval.properties,\n\t\t\top,\n\t\t);\n\n\t\tif (interval) {\n\t\t\tif (this.onDeserialize) {\n\t\t\t\tthis.onDeserialize(interval);\n\t\t\t}\n\t\t}\n\n\t\tthis.emit(\"addInterval\", interval, local, op);\n\n\t\treturn interval;\n\t}\n\n\t/** @internal */\n\tpublic ackDelete(\n\t\tserializedInterval: ISerializedInterval,\n\t\tlocal: boolean,\n\t\top: ISequencedDocumentMessage,\n\t): void {\n\t\tif (local) {\n\t\t\t// Local ops were applied when the message was created and there's no \"pending delete\"\n\t\t\t// state to bookkeep: remote operation application takes into account possibility of\n\t\t\t// locally deleted interval whenever a lookup happens.\n\t\t\treturn;\n\t\t}\n\n\t\tif (!this.localCollection) {\n\t\t\tthrow new LoggingError(\"attach must be called prior to deleting intervals\");\n\t\t}\n\n\t\tconst id = this.localCollection.ensureSerializedId(serializedInterval);\n\t\tconst interval = this.localCollection.getIntervalById(id);\n\t\tif (interval) {\n\t\t\tthis.deleteExistingInterval(interval, local, op);\n\t\t}\n\t}\n\n\t/**\n\t * @internal\n\t */\n\tpublic serializeInternal(): ISerializedIntervalCollectionV2 {\n\t\tif (!this.localCollection) {\n\t\t\tthrow new LoggingError(\"attachSequence must be called\");\n\t\t}\n\n\t\treturn this.localCollection.serialize();\n\t}\n\n\t/**\n\t * @returns an iterator over all intervals in this collection.\n\t */\n\tpublic [Symbol.iterator](): IntervalCollectionIterator<TInterval> {\n\t\tconst iterator = new IntervalCollectionIterator<TInterval>(this);\n\t\treturn iterator;\n\t}\n\n\t/**\n\t * @returns a forward iterator over all intervals in this collection with start point equal to `startPosition`.\n\t */\n\tpublic CreateForwardIteratorWithStartPosition(\n\t\tstartPosition: number,\n\t): IntervalCollectionIterator<TInterval> {\n\t\tconst iterator = new IntervalCollectionIterator<TInterval>(this, true, startPosition);\n\t\treturn iterator;\n\t}\n\n\t/**\n\t * @returns a backward iterator over all intervals in this collection with start point equal to `startPosition`.\n\t */\n\tpublic CreateBackwardIteratorWithStartPosition(\n\t\tstartPosition: number,\n\t): IntervalCollectionIterator<TInterval> {\n\t\tconst iterator = new IntervalCollectionIterator<TInterval>(this, false, startPosition);\n\t\treturn iterator;\n\t}\n\n\t/**\n\t * @returns a forward iterator over all intervals in this collection with end point equal to `endPosition`.\n\t */\n\tpublic CreateForwardIteratorWithEndPosition(\n\t\tendPosition: number,\n\t): IntervalCollectionIterator<TInterval> {\n\t\tconst iterator = new IntervalCollectionIterator<TInterval>(\n\t\t\tthis,\n\t\t\ttrue,\n\t\t\tundefined,\n\t\t\tendPosition,\n\t\t);\n\t\treturn iterator;\n\t}\n\n\t/**\n\t * @returns a backward iterator over all intervals in this collection with end point equal to `endPosition`.\n\t */\n\tpublic CreateBackwardIteratorWithEndPosition(\n\t\tendPosition: number,\n\t): IntervalCollectionIterator<TInterval> {\n\t\tconst iterator = new IntervalCollectionIterator<TInterval>(\n\t\t\tthis,\n\t\t\tfalse,\n\t\t\tundefined,\n\t\t\tendPosition,\n\t\t);\n\t\treturn iterator;\n\t}\n\n\t/**\n\t * Gathers iteration results that optionally match a start/end criteria into the provided array.\n\t * @param results - Array to gather the results into. In lieu of a return value, this array will be populated with\n\t * intervals matching the query upon edit.\n\t * @param iteratesForward - whether or not iteration should be in the forward direction\n\t * @param start - If provided, only match intervals whose start point is equal to `start`.\n\t * @param end - If provided, only match intervals whose end point is equal to `end`.\n\t */\n\tpublic gatherIterationResults(\n\t\tresults: TInterval[],\n\t\titeratesForward: boolean,\n\t\tstart?: number,\n\t\tend?: number,\n\t) {\n\t\tif (!this.localCollection) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.localCollection.gatherIterationResults(results, iteratesForward, start, end);\n\t}\n\n\t/**\n\t * @returns an array of all intervals in this collection that overlap with the interval\n\t * `[startPosition, endPosition]`.\n\t */\n\tpublic findOverlappingIntervals(startPosition: number, endPosition: number): TInterval[] {\n\t\tif (!this.localCollection) {\n\t\t\tthrow new LoggingError(\"attachSequence must be called\");\n\t\t}\n\n\t\treturn this.localCollection.findOverlappingIntervals(startPosition, endPosition);\n\t}\n\n\t/**\n\t * Applies a function to each interval in this collection.\n\t */\n\tpublic map(fn: (interval: TInterval) => void) {\n\t\tif (!this.localCollection) {\n\t\t\tthrow new LoggingError(\"attachSequence must be called\");\n\t\t}\n\n\t\tthis.localCollection.map(fn);\n\t}\n\n\tpublic previousInterval(pos: number): TInterval | undefined {\n\t\tif (!this.localCollection) {\n\t\t\tthrow new LoggingError(\"attachSequence must be called\");\n\t\t}\n\n\t\treturn this.localCollection.previousInterval(pos);\n\t}\n\n\tpublic nextInterval(pos: number): TInterval | undefined {\n\t\tif (!this.localCollection) {\n\t\t\tthrow new LoggingError(\"attachSequence must be called\");\n\t\t}\n\n\t\treturn this.localCollection.nextInterval(pos);\n\t}\n}\n\n/**\n * Information that identifies an interval within a `Sequence`.\n */\nexport interface IntervalLocator {\n\t/**\n\t * Label for the collection the interval is a part of\n\t */\n\tlabel: string;\n\t/**\n\t * Interval within that collection\n\t */\n\tinterval: SequenceInterval;\n}\n\n/**\n * Returns an object that can be used to find the interval a given LocalReferencePosition belongs to.\n * @returns undefined if the reference position is not the endpoint of any interval (e.g. it was created\n * on the merge tree directly by app code), otherwise an {@link IntervalLocator} for the interval this\n * endpoint is a part of.\n */\nexport function intervalLocatorFromEndpoint(\n\tpotentialEndpoint: LocalReferencePosition,\n): IntervalLocator | undefined {\n\tconst { interval, [reservedRangeLabelsKey]: collectionNameArray } =\n\t\tpotentialEndpoint.properties ?? {};\n\treturn interval && collectionNameArray?.length === 1\n\t\t? { label: collectionNameArray[0], interval }\n\t\t: undefined;\n}\n"]}
1
+ {"version":3,"file":"intervalCollection.js","sourceRoot":"","sources":["../src/intervalCollection.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;AAEH,+BAA+B;AAE/B,+DAAyE;AAEzE,qEAA6D;AAC7D,2DAoBoC;AAEpC,qEAA+D;AAC/D,+BAAkC;AASlC,iDAAiG;AAEjG,MAAM,qBAAqB,GAAG,YAAY,CAAC;AAE3C,IAAY,YAiBX;AAjBD,WAAY,YAAY;IACvB,mDAAY,CAAA;IACZ,+CAAU,CAAA;IAEV;;;;;OAKG;IACH,iEAAmB,CAAA;IAEnB;;;OAGG;IACH,yDAAe,CAAA;AAChB,CAAC,EAjBW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAiBvB;AAqDD;;;GAGG;AACH,SAAS,kBAAkB,CAC1B,QAAsC,EACtC,KAAc;IAEd,OAAO;QACN,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;QAClB,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;QAChB,cAAc,EAAE,QAAQ,CAAC,CAAC,CAAC;QAC3B,YAAY,EAAE,QAAQ,CAAC,CAAC,CAAC;QACzB,UAAU,kCAAO,QAAQ,CAAC,CAAC,CAAC,KAAE,CAAC,mCAAsB,CAAC,EAAE,CAAC,KAAK,CAAC,GAAE;KACjE,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,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eAAe,CAAC,eAAe,EAAE;YAC5D,EAAE,CAAC,QAAQ,CAAC,CAAC;SACb;IACF,CAAC;IAEM,gBAAgB,CAAC,GAAW;QAClC,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;YAC1B,MAAM,IAAI,8BAAY,CAAC,+BAA+B,CAAC,CAAC;SACxD;QAED,OAAO,IAAI,CAAC,eAAe,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACpE,CAAC;IAEM,YAAY,CAAC,GAAW;QAC9B,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;YAC1B,MAAM,IAAI,8BAAY,CAAC,+BAA+B,CAAC,CAAC;SACxD;QAED,OAAO,IAAI,CAAC,eAAe,CAAC,gBAAgB,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;IAChE,CAAC;CACD;AAh6BD,gDAg6BC;AAgBD;;;;;GAKG;AACH,SAAgB,2BAA2B,CAC1C,iBAAyC;;IAEzC,MAAM,EAAE,QAAQ,EAAE,CAAC,mCAAsB,CAAC,EAAE,mBAAmB,EAAE,GAChE,MAAA,iBAAiB,CAAC,UAAU,mCAAI,EAAE,CAAC;IACpC,OAAO,QAAQ,IAAI,CAAA,mBAAmB,aAAnB,mBAAmB,uBAAnB,mBAAmB,CAAE,MAAM,MAAK,CAAC;QACnD,CAAC,CAAC,EAAE,KAAK,EAAE,mBAAmB,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE;QAC7C,CAAC,CAAC,SAAS,CAAC;AACd,CAAC;AARD,kEAQC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable no-bitwise */\n\nimport { assert, TypedEventEmitter } from \"@fluidframework/common-utils\";\nimport { IEvent } from \"@fluidframework/common-definitions\";\nimport { UsageError } from \"@fluidframework/container-utils\";\nimport {\n\taddProperties,\n\tClient,\n\tcompareReferencePositions,\n\tcreateMap,\n\tICombiningOp,\n\tISegment,\n\tMergeTreeDeltaType,\n\tminReferencePosition,\n\tPropertiesManager,\n\tPropertySet,\n\tRedBlackTree,\n\tLocalReferencePosition,\n\tReferenceType,\n\trefTypeIncludesFlag,\n\treservedRangeLabelsKey,\n\tUnassignedSequenceNumber,\n\tmaxReferencePosition,\n\tcreateDetachedLocalReferencePosition,\n\tDetachedReferencePosition,\n} from \"@fluidframework/merge-tree\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport { LoggingError } from \"@fluidframework/telemetry-utils\";\nimport { v4 as uuid } from \"uuid\";\nimport {\n\tIMapMessageLocalMetadata,\n\tIValueFactory,\n\tIValueOpEmitter,\n\tIValueOperation,\n\tIValueType,\n\tIValueTypeOperationValue,\n} from \"./defaultMapInterfaces\";\nimport { IInterval, IntervalConflictResolver, IntervalTree, IntervalNode } from \"./intervalTree\";\n\nconst reservedIntervalIdKey = \"intervalId\";\n\nexport enum IntervalType {\n\tSimple = 0x0,\n\tNest = 0x1,\n\n\t/**\n\t * SlideOnRemove indicates that the ends of the interval will slide if the segment\n\t * they reference is removed and acked.\n\t * See `packages\\dds\\merge-tree\\REFERENCEPOSITIONS.md` for details\n\t * SlideOnRemove is the default interval behavior and does not need to be specified.\n\t */\n\tSlideOnRemove = 0x2, // SlideOnRemove is default behavior - all intervals are SlideOnRemove\n\n\t/**\n\t * A temporary interval, used internally\n\t * @internal\n\t */\n\tTransient = 0x4,\n}\n\n/**\n * Serialized object representation of an interval.\n * This representation is used for ops that create or change intervals.\n * @internal\n */\nexport interface ISerializedInterval {\n\t/**\n\t * Sequence number at which `start` and `end` should be interpreted\n\t *\n\t * @remarks - It's unclear that this is necessary to store here.\n\t * This should just be the refSeq on the op that modified the interval, which should be available via other means.\n\t * At the time of writing, it's not plumbed through to the reconnect/rebase code, however, which does need it.\n\t */\n\tsequenceNumber: number;\n\t/** Start position of the interval */\n\tstart: number;\n\t/** End position of the interval */\n\tend: number;\n\t/** Interval type to create */\n\tintervalType: IntervalType;\n\t/** Any properties the interval has */\n\tproperties?: PropertySet;\n}\n\n/**\n * Represents a change that should be applied to an existing interval.\n * Changes can modify any of start/end/properties, with `undefined` signifying no change should be made.\n * @internal\n */\nexport type SerializedIntervalDelta = Omit<ISerializedInterval, \"start\" | \"end\" | \"properties\"> &\n\tPartial<Pick<ISerializedInterval, \"start\" | \"end\" | \"properties\">>;\n\n/**\n * A size optimization to avoid redundantly storing keys when serializing intervals\n * as JSON for summaries.\n *\n * Intervals are of the format:\n *\n * [start, end, sequenceNumber, intervalType, properties]\n */\nexport type CompressedSerializedInterval = [number, number, number, IntervalType, PropertySet];\n\n/**\n * @internal\n */\nexport interface ISerializedIntervalCollectionV2 {\n\tlabel: string;\n\tversion: 2;\n\tintervals: CompressedSerializedInterval[];\n}\n\n/**\n * Decompress an interval after loading a summary from JSON. The exact format\n * of this compression is unspecified and subject to change\n */\nfunction decompressInterval(\n\tinterval: CompressedSerializedInterval,\n\tlabel?: string,\n): ISerializedInterval {\n\treturn {\n\t\tstart: interval[0],\n\t\tend: interval[1],\n\t\tsequenceNumber: interval[2],\n\t\tintervalType: interval[3],\n\t\tproperties: { ...interval[4], [reservedRangeLabelsKey]: [label] },\n\t};\n}\n\n/**\n * Compress an interval prior to serialization as JSON. The exact format of this\n * compression is unspecified and subject to change\n */\nfunction compressInterval(interval: ISerializedInterval): CompressedSerializedInterval {\n\tconst { start, end, sequenceNumber, intervalType, properties } = interval;\n\n\treturn [\n\t\tstart,\n\t\tend,\n\t\tsequenceNumber,\n\t\tintervalType,\n\t\t// remove the `referenceRangeLabels` property as it is already stored\n\t\t// in the `label` field of the summary\n\t\t{ ...properties, [reservedRangeLabelsKey]: undefined },\n\t];\n}\n\nexport interface ISerializableInterval extends IInterval {\n\t/** Serializable bag of properties associated with the interval. */\n\tproperties: PropertySet;\n\t/** @internal */\n\tpropertyManager: PropertiesManager;\n\t/** @internal */\n\tserialize(): ISerializedInterval;\n\t/** @internal */\n\taddProperties(\n\t\tprops: PropertySet,\n\t\tcollaborating?: boolean,\n\t\tseq?: number,\n\t): PropertySet | undefined;\n\t/**\n\t * Gets the id associated with this interval.\n\t * When the interval is used as part of an interval collection, this id can be used to modify or remove the\n\t * interval.\n\t * @remarks - This signature includes `undefined` strictly for backwards-compatibility reasons, as older versions\n\t * of Fluid didn't always write interval ids.\n\t */\n\tgetIntervalId(): string | undefined;\n}\n\nexport interface IIntervalHelpers<TInterval extends ISerializableInterval> {\n\tcompareEnds(a: TInterval, b: TInterval): number;\n\t/**\n\t *\n\t * @param label - label of the interval collection this interval is being added to. This parameter is\n\t * irrelevant for transient intervals.\n\t * @param start - numerical start position of the interval\n\t * @param end - numberical end position of the interval\n\t * @param client - client creating the interval\n\t * @param intervalType - Type of interval to create. Default is SlideOnRemove\n\t * @param op - If this create came from a remote client, op that created it. Default is undefined (i.e. local)\n\t * @param fromSnapshot - If this create came from loading a snapshot. Default is false.\n\t */\n\tcreate(\n\t\tlabel: string,\n\t\tstart: number | undefined,\n\t\tend: number | undefined,\n\t\tclient: Client | undefined,\n\t\tintervalType: IntervalType,\n\t\top?: ISequencedDocumentMessage,\n\t\tfromSnapshot?: boolean,\n\t): TInterval;\n}\n\n/**\n * Serializable interval whose endpoints are plain-old numbers.\n */\nexport class Interval implements ISerializableInterval {\n\t/**\n\t * {@inheritDoc ISerializableInterval.properties}\n\t */\n\tpublic properties: PropertySet;\n\t/** @internal */\n\tpublic auxProps: PropertySet[] | undefined;\n\t/**\n\t * {@inheritDoc ISerializableInterval.propertyManager}\n\t * @deprecated - This API was never intended to be public and will be marked internal in a future release.\n\t */\n\tpublic propertyManager: PropertiesManager;\n\tconstructor(public start: number, public end: number, props?: PropertySet) {\n\t\tthis.propertyManager = new PropertiesManager();\n\t\tthis.properties = {};\n\n\t\tif (props) {\n\t\t\tthis.addProperties(props);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc ISerializableInterval.getIntervalId}\n\t */\n\tpublic getIntervalId(): string {\n\t\tconst id = this.properties?.[reservedIntervalIdKey];\n\t\tassert(id !== undefined, 0x5e1 /* interval ID should not be undefined */);\n\t\treturn `${id}`;\n\t}\n\n\t/**\n\t * @returns an array containing any auxiliary property sets added with `addPropertySet`.\n\t */\n\tpublic getAdditionalPropertySets(): PropertySet[] {\n\t\treturn this.auxProps ?? [];\n\t}\n\n\t/**\n\t * Adds an auxiliary set of properties to this interval.\n\t * These properties can be recovered using `getAdditionalPropertySets`\n\t * @param props - set of properties to add\n\t * @remarks - This gets called as part of the default conflict resolver for `IntervalCollection<Interval>`\n\t * (i.e. non-sequence-based interval collections). However, the additional properties don't get serialized.\n\t * This functionality seems half-baked.\n\t */\n\tpublic addPropertySet(props: PropertySet) {\n\t\tif (this.auxProps === undefined) {\n\t\t\tthis.auxProps = [];\n\t\t}\n\t\tthis.auxProps.push(props);\n\t}\n\n\t/**\n\t * {@inheritDoc ISerializableInterval.serialize}\n\t * @internal\n\t */\n\tpublic serialize(): ISerializedInterval {\n\t\tconst serializedInterval: ISerializedInterval = {\n\t\t\tend: this.end,\n\t\t\tintervalType: 0,\n\t\t\tsequenceNumber: 0,\n\t\t\tstart: this.start,\n\t\t};\n\t\tif (this.properties) {\n\t\t\tserializedInterval.properties = this.properties;\n\t\t}\n\t\treturn serializedInterval;\n\t}\n\n\t/**\n\t * {@inheritDoc IInterval.clone}\n\t */\n\tpublic clone() {\n\t\treturn new Interval(this.start, this.end, this.properties);\n\t}\n\n\t/**\n\t * {@inheritDoc IInterval.compare}\n\t */\n\tpublic compare(b: Interval) {\n\t\tconst startResult = this.compareStart(b);\n\t\tif (startResult === 0) {\n\t\t\tconst endResult = this.compareEnd(b);\n\t\t\tif (endResult === 0) {\n\t\t\t\tconst thisId = this.getIntervalId();\n\t\t\t\tif (thisId) {\n\t\t\t\t\tconst bId = b.getIntervalId();\n\t\t\t\t\tif (bId) {\n\t\t\t\t\t\treturn thisId > bId ? 1 : thisId < bId ? -1 : 0;\n\t\t\t\t\t}\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t\treturn 0;\n\t\t\t} else {\n\t\t\t\treturn endResult;\n\t\t\t}\n\t\t} else {\n\t\t\treturn startResult;\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc IInterval.compareStart}\n\t */\n\tpublic compareStart(b: Interval) {\n\t\treturn this.start - b.start;\n\t}\n\n\t/**\n\t * {@inheritDoc IInterval.compareEnd}\n\t */\n\tpublic compareEnd(b: Interval) {\n\t\treturn this.end - b.end;\n\t}\n\n\t/**\n\t * {@inheritDoc IInterval.overlaps}\n\t */\n\tpublic overlaps(b: Interval) {\n\t\tconst result = this.start <= b.end && this.end >= b.start;\n\t\treturn result;\n\t}\n\n\t/**\n\t * {@inheritDoc IInterval.union}\n\t * @deprecated - This API was never intended to be public and will be marked internal in a future release.\n\t */\n\tpublic union(b: Interval) {\n\t\treturn new Interval(\n\t\t\tMath.min(this.start, b.start),\n\t\t\tMath.max(this.end, b.end),\n\t\t\tthis.properties,\n\t\t);\n\t}\n\n\tpublic getProperties() {\n\t\treturn this.properties;\n\t}\n\n\t/**\n\t * {@inheritDoc ISerializableInterval.addProperties}\n\t * @deprecated - This API was never intended to be public and will be marked internal in a future release.\n\t */\n\tpublic addProperties(\n\t\tnewProps: PropertySet,\n\t\tcollaborating: boolean = false,\n\t\tseq?: number,\n\t\top?: ICombiningOp,\n\t): PropertySet | undefined {\n\t\tif (newProps) {\n\t\t\tthis.initializeProperties();\n\t\t\treturn this.propertyManager.addProperties(\n\t\t\t\tthis.properties,\n\t\t\t\tnewProps,\n\t\t\t\top,\n\t\t\t\tseq,\n\t\t\t\tcollaborating,\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc IInterval.modify}\n\t * @deprecated - This API was never intended to be public and will be marked internal in a future release.\n\t */\n\tpublic modify(label: string, start: number, end: number, op?: ISequencedDocumentMessage) {\n\t\tconst startPos = start ?? this.start;\n\t\tconst endPos = end ?? this.end;\n\t\tif (this.start === startPos && this.end === endPos) {\n\t\t\t// Return undefined to indicate that no change is necessary.\n\t\t\treturn;\n\t\t}\n\t\tconst newInterval = new Interval(startPos, endPos);\n\t\tif (this.properties) {\n\t\t\tnewInterval.initializeProperties();\n\t\t\tthis.propertyManager.copyTo(\n\t\t\t\tthis.properties,\n\t\t\t\tnewInterval.properties,\n\t\t\t\tnewInterval.propertyManager,\n\t\t\t);\n\t\t}\n\t\treturn newInterval;\n\t}\n\n\tprivate initializeProperties(): void {\n\t\tif (!this.propertyManager) {\n\t\t\tthis.propertyManager = new PropertiesManager();\n\t\t}\n\t\tif (!this.properties) {\n\t\t\tthis.properties = createMap<any>();\n\t\t}\n\t}\n}\n\n/**\n * Interval impelmentation whose ends are associated with positions in a mutatable sequence.\n * As such, when content is inserted into the middle of the interval, the interval expands to\n * include that content.\n *\n * @remarks - The endpoint's position should be treated exclusively to get reasonable behavior--i.e.\n * an interval referring to \"hello\" in \"hello world\" should have a start position of 0 and an end\n * position of 5.\n *\n * To see why, consider what happens if \"llo wor\" is removed from the string to make \"held\".\n * The interval's startpoint remains on the \"h\" (it isn't altered), but the interval's endpoint\n * slides forward to the next unremoved position, which is the \"l\" in \"held\".\n * Users would generally expect the interval to now refer to \"he\" (as it is the subset of content\n * remaining after the removal), hence the \"l\" should be excluded.\n * If the interval endpoint was treated inclusively, the interval would now refer to \"hel\", which\n * is undesirable.\n *\n * Since the end of an interval is treated exclusively but cannot be greater than or equal to the\n * length of the associated sequence, application models which leverage interval collections should\n * consider inserting a marker at the end of the sequence to represent the end of the content.\n */\nexport class SequenceInterval implements ISerializableInterval {\n\t/**\n\t * {@inheritDoc ISerializableInterval.properties}\n\t */\n\tpublic properties: PropertySet;\n\t/**\n\t * {@inheritDoc ISerializableInterval.propertyManager}\n\t * @deprecated - This API was never intended to be public and will be marked internal in a future release.\n\t */\n\tpublic propertyManager: PropertiesManager;\n\n\tconstructor(\n\t\tprivate readonly client: Client,\n\t\t/**\n\t\t * Start endpoint of this interval.\n\t\t * @remarks - This endpoint can be resolved into a character position using the SharedString it's a part of.\n\t\t */\n\t\tpublic start: LocalReferencePosition,\n\t\t/**\n\t\t * End endpoint of this interval.\n\t\t * @remarks - This endpoint can be resolved into a character position using the SharedString it's a part of.\n\t\t */\n\t\tpublic end: LocalReferencePosition,\n\t\tpublic intervalType: IntervalType,\n\t\tprops?: PropertySet,\n\t) {\n\t\tthis.propertyManager = new PropertiesManager();\n\t\tthis.properties = {};\n\n\t\tif (props) {\n\t\t\tthis.addProperties(props);\n\t\t}\n\t}\n\n\tprivate callbacks?: Record<\"beforePositionChange\" | \"afterPositionChange\", () => void>;\n\n\t/**\n\t * Subscribes to position change events on this interval if there are no current listeners.\n\t * @internal\n\t */\n\tpublic addPositionChangeListeners(\n\t\tbeforePositionChange: () => void,\n\t\tafterPositionChange: () => void,\n\t): void {\n\t\tif (this.callbacks === undefined) {\n\t\t\tthis.callbacks = {\n\t\t\t\tbeforePositionChange,\n\t\t\t\tafterPositionChange,\n\t\t\t};\n\n\t\t\tconst startCbs = (this.start.callbacks ??= {});\n\t\t\tconst endCbs = (this.end.callbacks ??= {});\n\t\t\tstartCbs.beforeSlide = endCbs.beforeSlide = beforePositionChange;\n\t\t\tstartCbs.afterSlide = endCbs.afterSlide = afterPositionChange;\n\t\t}\n\t}\n\n\t/**\n\t * Removes the currently subscribed position change listeners.\n\t * @internal\n\t */\n\tpublic removePositionChangeListeners(): void {\n\t\tif (this.callbacks) {\n\t\t\tthis.callbacks = undefined;\n\t\t\tthis.start.callbacks = undefined;\n\t\t\tthis.end.callbacks = undefined;\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc ISerializableInterval.serialize}\n\t * @internal\n\t */\n\tpublic serialize(): ISerializedInterval {\n\t\tconst startPosition = this.client.localReferencePositionToPosition(this.start);\n\t\tconst endPosition = this.client.localReferencePositionToPosition(this.end);\n\t\tconst serializedInterval: ISerializedInterval = {\n\t\t\tend: endPosition,\n\t\t\tintervalType: this.intervalType,\n\t\t\tsequenceNumber: this.client.getCurrentSeq(),\n\t\t\tstart: startPosition,\n\t\t};\n\n\t\tif (this.properties) {\n\t\t\tserializedInterval.properties = this.properties;\n\t\t}\n\n\t\treturn serializedInterval;\n\t}\n\n\t/**\n\t * {@inheritDoc IInterval.clone}\n\t */\n\tpublic clone() {\n\t\treturn new SequenceInterval(\n\t\t\tthis.client,\n\t\t\tthis.start,\n\t\t\tthis.end,\n\t\t\tthis.intervalType,\n\t\t\tthis.properties,\n\t\t);\n\t}\n\n\t/**\n\t * {@inheritDoc IInterval.compare}\n\t */\n\tpublic compare(b: SequenceInterval) {\n\t\tconst startResult = this.compareStart(b);\n\t\tif (startResult === 0) {\n\t\t\tconst endResult = this.compareEnd(b);\n\t\t\tif (endResult === 0) {\n\t\t\t\tconst thisId = this.getIntervalId();\n\t\t\t\tif (thisId) {\n\t\t\t\t\tconst bId = b.getIntervalId();\n\t\t\t\t\tif (bId) {\n\t\t\t\t\t\treturn thisId > bId ? 1 : thisId < bId ? -1 : 0;\n\t\t\t\t\t}\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t\treturn 0;\n\t\t\t} else {\n\t\t\t\treturn endResult;\n\t\t\t}\n\t\t} else {\n\t\t\treturn startResult;\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc IInterval.compareStart}\n\t */\n\tpublic compareStart(b: SequenceInterval) {\n\t\treturn compareReferencePositions(this.start, b.start);\n\t}\n\n\t/**\n\t * {@inheritDoc IInterval.compareEnd}\n\t */\n\tpublic compareEnd(b: SequenceInterval) {\n\t\treturn compareReferencePositions(this.end, b.end);\n\t}\n\n\t/**\n\t * {@inheritDoc IInterval.overlaps}\n\t */\n\tpublic overlaps(b: SequenceInterval) {\n\t\tconst result =\n\t\t\tcompareReferencePositions(this.start, b.end) <= 0 &&\n\t\t\tcompareReferencePositions(this.end, b.start) >= 0;\n\t\treturn result;\n\t}\n\n\t/**\n\t * {@inheritDoc ISerializableInterval.getIntervalId}\n\t */\n\tpublic getIntervalId(): string {\n\t\tconst id = this.properties?.[reservedIntervalIdKey];\n\t\tassert(id !== undefined, 0x5e2 /* interval ID should not be undefined */);\n\t\treturn `${id}`;\n\t}\n\n\t/**\n\t * {@inheritDoc IInterval.union}\n\t * @deprecated - This API was never intended to be public and will be marked internal in a future release.\n\t */\n\tpublic union(b: SequenceInterval) {\n\t\treturn new SequenceInterval(\n\t\t\tthis.client,\n\t\t\tminReferencePosition(this.start, b.start),\n\t\t\tmaxReferencePosition(this.end, b.end),\n\t\t\tthis.intervalType,\n\t\t);\n\t}\n\n\t/**\n\t * {@inheritDoc ISerializableInterval.addProperties}\n\t * @deprecated - This API was never intended to be public and will be marked internal in a future release.\n\t */\n\tpublic addProperties(\n\t\tnewProps: PropertySet,\n\t\tcollab: boolean = false,\n\t\tseq?: number,\n\t\top?: ICombiningOp,\n\t): PropertySet | undefined {\n\t\tthis.initializeProperties();\n\t\treturn this.propertyManager.addProperties(this.properties, newProps, op, seq, collab);\n\t}\n\n\t/**\n\t * @returns whether this interval overlaps two numerical positions.\n\t */\n\tpublic overlapsPos(bstart: number, bend: number) {\n\t\tconst startPos = this.client.localReferencePositionToPosition(this.start);\n\t\tconst endPos = this.client.localReferencePositionToPosition(this.end);\n\t\treturn endPos > bstart && startPos < bend;\n\t}\n\n\t/**\n\t * {@inheritDoc IInterval.modify}\n\t * @deprecated - This API was never intended to be public and will be marked internal in a future release.\n\t */\n\tpublic modify(\n\t\tlabel: string,\n\t\tstart: number,\n\t\tend: number,\n\t\top?: ISequencedDocumentMessage,\n\t\tlocalSeq?: number,\n\t) {\n\t\tconst getRefType = (baseType: ReferenceType): ReferenceType => {\n\t\t\tlet refType = baseType;\n\t\t\tif (op === undefined) {\n\t\t\t\trefType &= ~ReferenceType.SlideOnRemove;\n\t\t\t\trefType |= ReferenceType.StayOnRemove;\n\t\t\t}\n\t\t\treturn refType;\n\t\t};\n\n\t\tlet startRef = this.start;\n\t\tif (start !== undefined) {\n\t\t\tstartRef = createPositionReference(\n\t\t\t\tthis.client,\n\t\t\t\tstart,\n\t\t\t\tgetRefType(this.start.refType),\n\t\t\t\top,\n\t\t\t\tundefined,\n\t\t\t\tlocalSeq,\n\t\t\t);\n\t\t\tif (this.start.properties) {\n\t\t\t\tstartRef.addProperties(this.start.properties);\n\t\t\t}\n\t\t}\n\n\t\tlet endRef = this.end;\n\t\tif (end !== undefined) {\n\t\t\tendRef = createPositionReference(\n\t\t\t\tthis.client,\n\t\t\t\tend,\n\t\t\t\tgetRefType(this.end.refType),\n\t\t\t\top,\n\t\t\t\tundefined,\n\t\t\t\tlocalSeq,\n\t\t\t);\n\t\t\tif (this.end.properties) {\n\t\t\t\tendRef.addProperties(this.end.properties);\n\t\t\t}\n\t\t}\n\n\t\tconst newInterval = new SequenceInterval(this.client, startRef, endRef, this.intervalType);\n\t\tif (this.properties) {\n\t\t\tnewInterval.initializeProperties();\n\t\t\tthis.propertyManager.copyTo(\n\t\t\t\tthis.properties,\n\t\t\t\tnewInterval.properties,\n\t\t\t\tnewInterval.propertyManager,\n\t\t\t);\n\t\t}\n\t\treturn newInterval;\n\t}\n\n\tprivate initializeProperties(): void {\n\t\tif (!this.propertyManager) {\n\t\t\tthis.propertyManager = new PropertiesManager();\n\t\t}\n\t\tif (!this.properties) {\n\t\t\tthis.properties = createMap<any>();\n\t\t}\n\t}\n}\n\nfunction createPositionReferenceFromSegoff(\n\tclient: Client,\n\tsegoff: { segment: ISegment | undefined; offset: number | undefined },\n\trefType: ReferenceType,\n\top?: ISequencedDocumentMessage,\n\tlocalSeq?: number,\n\tfromSnapshot?: boolean,\n): LocalReferencePosition {\n\tif (segoff.segment) {\n\t\tconst ref = client.createLocalReferencePosition(\n\t\t\tsegoff.segment,\n\t\t\tsegoff.offset,\n\t\t\trefType,\n\t\t\tundefined,\n\t\t);\n\t\treturn ref;\n\t}\n\n\t// Creating references on detached segments is allowed for:\n\t// - Transient segments\n\t// - References coming from a remote client (location may have been concurrently removed)\n\t// - References being rebased to a new sequence number\n\t// (segment they originally referred to may have been removed with no suitable replacement)\n\tif (\n\t\t!op &&\n\t\t!localSeq &&\n\t\t!fromSnapshot &&\n\t\t!refTypeIncludesFlag(refType, ReferenceType.Transient)\n\t) {\n\t\tthrow new UsageError(\"Non-transient references need segment\");\n\t}\n\n\treturn createDetachedLocalReferencePosition(refType);\n}\n\nfunction createPositionReference(\n\tclient: Client,\n\tpos: number,\n\trefType: ReferenceType,\n\top?: ISequencedDocumentMessage,\n\tfromSnapshot?: boolean,\n\tlocalSeq?: number,\n): LocalReferencePosition {\n\tlet segoff;\n\tif (op) {\n\t\tassert(\n\t\t\t(refType & ReferenceType.SlideOnRemove) !== 0,\n\t\t\t0x2f5 /* op create references must be SlideOnRemove */,\n\t\t);\n\t\tsegoff = client.getContainingSegment(pos, {\n\t\t\treferenceSequenceNumber: op.referenceSequenceNumber,\n\t\t\tclientId: op.clientId,\n\t\t});\n\t\tsegoff = client.getSlideToSegment(segoff);\n\t} else {\n\t\tassert(\n\t\t\t(refType & ReferenceType.SlideOnRemove) === 0 || !!fromSnapshot,\n\t\t\t0x2f6 /* SlideOnRemove references must be op created */,\n\t\t);\n\t\tsegoff = client.getContainingSegment(pos, undefined, localSeq);\n\t}\n\treturn createPositionReferenceFromSegoff(client, segoff, refType, op, localSeq, fromSnapshot);\n}\n\nexport function createSequenceInterval(\n\tlabel: string,\n\tstart: number,\n\tend: number,\n\tclient: Client,\n\tintervalType: IntervalType,\n\top?: ISequencedDocumentMessage,\n\tfromSnapshot?: boolean,\n): SequenceInterval {\n\tlet beginRefType = ReferenceType.RangeBegin;\n\tlet endRefType = ReferenceType.RangeEnd;\n\tif (intervalType === IntervalType.Transient) {\n\t\tbeginRefType = ReferenceType.Transient;\n\t\tendRefType = ReferenceType.Transient;\n\t} else {\n\t\tif (intervalType === IntervalType.Nest) {\n\t\t\tbeginRefType = ReferenceType.NestBegin;\n\t\t\tendRefType = ReferenceType.NestEnd;\n\t\t}\n\t\t// All non-transient interval references must eventually be SlideOnRemove\n\t\t// To ensure eventual consistency, they must start as StayOnRemove when\n\t\t// pending (created locally and creation op is not acked)\n\t\tif (op || fromSnapshot) {\n\t\t\tbeginRefType |= ReferenceType.SlideOnRemove;\n\t\t\tendRefType |= ReferenceType.SlideOnRemove;\n\t\t} else {\n\t\t\tbeginRefType |= ReferenceType.StayOnRemove;\n\t\t\tendRefType |= ReferenceType.StayOnRemove;\n\t\t}\n\t}\n\n\tconst startLref = createPositionReference(client, start, beginRefType, op, fromSnapshot);\n\tconst endLref = createPositionReference(client, end, endRefType, op, fromSnapshot);\n\tconst rangeProp = {\n\t\t[reservedRangeLabelsKey]: [label],\n\t};\n\tstartLref.addProperties(rangeProp);\n\tendLref.addProperties(rangeProp);\n\n\tconst ival = new SequenceInterval(client, startLref, endLref, intervalType, rangeProp);\n\treturn ival;\n}\n\nexport function createIntervalIndex() {\n\tconst helpers: IIntervalHelpers<Interval> = {\n\t\tcompareEnds: compareIntervalEnds,\n\t\tcreate: createInterval,\n\t};\n\tconst lc = new LocalIntervalCollection<Interval>(undefined as any as Client, \"\", helpers);\n\treturn lc;\n}\n\n/**\n * Collection of intervals.\n *\n * Implementers of this interface will typically implement additional APIs to support efficiently querying a collection\n * of intervals in some manner, for example:\n * - \"find all intervals with start endpoint between these two points\"\n * - \"find all intervals which overlap this range\"\n * etc.\n */\nexport interface IntervalIndex<TInterval extends ISerializableInterval> {\n\t/**\n\t * Adds an interval to the index.\n\t * @remarks - Application code should never need to invoke this method on their index for production scenarios:\n\t * Fluid handles adding and removing intervals from an index in response to sequence or interval changes.\n\t */\n\tadd(interval: TInterval): void;\n\n\t/**\n\t * Removes an interval from the index.\n\t * @remarks - Application code should never need to invoke this method on their index for production scenarios:\n\t * Fluid handles adding and removing intervals from an index in response to sequence or interval changes.\n\t */\n\tremove(interval: TInterval): void;\n}\n\nclass OverlappingIntervalsIndex<TInterval extends ISerializableInterval>\n\timplements IntervalIndex<TInterval>\n{\n\tprivate readonly intervalTree = new IntervalTree<TInterval>();\n\n\tconstructor(\n\t\tprivate readonly client: Client,\n\t\tprivate readonly helpers: IIntervalHelpers<TInterval>,\n\t) {}\n\n\tpublic map(fn: (interval: TInterval) => void) {\n\t\tthis.intervalTree.map(fn);\n\t}\n\n\tpublic mapUntil(fn: (interval: TInterval) => boolean) {\n\t\tthis.intervalTree.mapUntil(fn);\n\t}\n\n\tpublic gatherIterationResults(\n\t\tresults: TInterval[],\n\t\titeratesForward: boolean,\n\t\tstart?: number,\n\t\tend?: number,\n\t) {\n\t\tif (this.intervalTree.intervals.isEmpty()) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (start === undefined && end === undefined) {\n\t\t\t// No start/end provided. Gather the whole tree in the specified order.\n\t\t\tif (iteratesForward) {\n\t\t\t\tthis.intervalTree.map((interval: TInterval) => {\n\t\t\t\t\tresults.push(interval);\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tthis.intervalTree.mapBackward((interval: TInterval) => {\n\t\t\t\t\tresults.push(interval);\n\t\t\t\t});\n\t\t\t}\n\t\t} else {\n\t\t\tconst transientInterval: TInterval = this.helpers.create(\n\t\t\t\t\"transient\",\n\t\t\t\tstart,\n\t\t\t\tend,\n\t\t\t\tthis.client,\n\t\t\t\tIntervalType.Transient,\n\t\t\t);\n\n\t\t\tif (start === undefined) {\n\t\t\t\t// Only end position provided. Since the tree is not sorted by end position,\n\t\t\t\t// walk the whole tree in the specified order, gathering intervals that match the end.\n\t\t\t\tif (iteratesForward) {\n\t\t\t\t\tthis.intervalTree.map((interval: TInterval) => {\n\t\t\t\t\t\tif (transientInterval.compareEnd(interval) === 0) {\n\t\t\t\t\t\t\tresults.push(interval);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tthis.intervalTree.mapBackward((interval: TInterval) => {\n\t\t\t\t\t\tif (transientInterval.compareEnd(interval) === 0) {\n\t\t\t\t\t\t\tresults.push(interval);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Start and (possibly) end provided. Walk the subtrees that may contain\n\t\t\t\t// this start position.\n\t\t\t\tconst compareFn =\n\t\t\t\t\tend === undefined\n\t\t\t\t\t\t? (node: IntervalNode<TInterval>) => {\n\t\t\t\t\t\t\t\treturn transientInterval.compareStart(node.key);\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: (node: IntervalNode<TInterval>) => {\n\t\t\t\t\t\t\t\treturn transientInterval.compare(node.key);\n\t\t\t\t\t\t };\n\t\t\t\tconst continueLeftFn = (cmpResult: number) => cmpResult <= 0;\n\t\t\t\tconst continueRightFn = (cmpResult: number) => cmpResult >= 0;\n\t\t\t\tconst actionFn = (node: IntervalNode<TInterval>) => {\n\t\t\t\t\tresults.push(node.key);\n\t\t\t\t};\n\n\t\t\t\tif (iteratesForward) {\n\t\t\t\t\tthis.intervalTree.intervals.walkExactMatchesForward(\n\t\t\t\t\t\tcompareFn,\n\t\t\t\t\t\tactionFn,\n\t\t\t\t\t\tcontinueLeftFn,\n\t\t\t\t\t\tcontinueRightFn,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tthis.intervalTree.intervals.walkExactMatchesBackward(\n\t\t\t\t\t\tcompareFn,\n\t\t\t\t\t\tactionFn,\n\t\t\t\t\t\tcontinueLeftFn,\n\t\t\t\t\t\tcontinueRightFn,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * @returns an array of all intervals contained in this collection that overlap the range\n\t * `[startPosition, endPosition)`.\n\t */\n\tpublic findOverlappingIntervals(startPosition: number, endPosition: number) {\n\t\tif (endPosition < startPosition || this.intervalTree.intervals.isEmpty()) {\n\t\t\treturn [];\n\t\t}\n\t\tconst transientInterval = this.helpers.create(\n\t\t\t\"transient\",\n\t\t\tstartPosition,\n\t\t\tendPosition,\n\t\t\tthis.client,\n\t\t\tIntervalType.Transient,\n\t\t);\n\n\t\tconst overlappingIntervalNodes = this.intervalTree.match(transientInterval);\n\t\treturn overlappingIntervalNodes.map((node) => node.key);\n\t}\n\n\tpublic remove(interval: TInterval) {\n\t\tthis.intervalTree.removeExisting(interval);\n\t}\n\n\tpublic add(interval: TInterval) {\n\t\tthis.intervalTree.put(interval);\n\t}\n}\n\nclass IdIntervalIndex<TInterval extends ISerializableInterval>\n\timplements IntervalIndex<TInterval>, Iterable<TInterval>\n{\n\tprivate readonly intervalIdMap: Map<string, TInterval> = new Map();\n\n\tpublic add(interval: TInterval) {\n\t\tconst id = interval.getIntervalId();\n\t\tassert(\n\t\t\tid !== undefined,\n\t\t\t0x2c0 /* \"ID must be created before adding interval to collection\" */,\n\t\t);\n\t\t// Make the ID immutable.\n\t\tObject.defineProperty(interval.properties, reservedIntervalIdKey, {\n\t\t\tconfigurable: false,\n\t\t\tenumerable: true,\n\t\t\twritable: false,\n\t\t});\n\t\tthis.intervalIdMap.set(id, interval);\n\t}\n\n\tpublic remove(interval: TInterval) {\n\t\tconst id = interval.getIntervalId();\n\t\tassert(id !== undefined, 0x311 /* expected id to exist on interval */);\n\t\tthis.intervalIdMap.delete(id);\n\t}\n\n\tpublic getIntervalById(id: string) {\n\t\treturn this.intervalIdMap.get(id);\n\t}\n\n\tpublic [Symbol.iterator]() {\n\t\treturn this.intervalIdMap.values();\n\t}\n}\n\nclass EndpointIndex<TInterval extends ISerializableInterval> implements IntervalIndex<TInterval> {\n\tprivate readonly endIntervalTree: RedBlackTree<TInterval, TInterval>;\n\n\tconstructor(\n\t\tprivate readonly client: Client,\n\t\tprivate readonly helpers: IIntervalHelpers<TInterval>,\n\t) {\n\t\t// eslint-disable-next-line @typescript-eslint/unbound-method\n\t\tthis.endIntervalTree = new RedBlackTree<TInterval, TInterval>(helpers.compareEnds);\n\t}\n\n\tpublic previousInterval(pos: number) {\n\t\tconst transientInterval = this.helpers.create(\n\t\t\t\"transient\",\n\t\t\tpos,\n\t\t\tpos,\n\t\t\tthis.client,\n\t\t\tIntervalType.Transient,\n\t\t);\n\t\tconst rbNode = this.endIntervalTree.floor(transientInterval);\n\t\tif (rbNode) {\n\t\t\treturn rbNode.data;\n\t\t}\n\t}\n\n\tpublic nextInterval(pos: number) {\n\t\tconst transientInterval = this.helpers.create(\n\t\t\t\"transient\",\n\t\t\tpos,\n\t\t\tpos,\n\t\t\tthis.client,\n\t\t\tIntervalType.Transient,\n\t\t);\n\t\tconst rbNode = this.endIntervalTree.ceil(transientInterval);\n\t\tif (rbNode) {\n\t\t\treturn rbNode.data;\n\t\t}\n\t}\n\n\tpublic add(interval: TInterval): void {\n\t\tthis.endIntervalTree.put(interval, interval);\n\t}\n\n\tpublic remove(interval: TInterval): void {\n\t\tthis.endIntervalTree.remove(interval);\n\t}\n}\n\nexport class LocalIntervalCollection<TInterval extends ISerializableInterval> {\n\tprivate static readonly legacyIdPrefix = \"legacy\";\n\tpublic readonly overlappingIntervalsIndex: OverlappingIntervalsIndex<TInterval>;\n\tpublic readonly idIntervalIndex: IdIntervalIndex<TInterval>;\n\tpublic readonly endIntervalIndex: EndpointIndex<TInterval>;\n\tprivate readonly indexes: IntervalIndex<TInterval>[];\n\n\tconstructor(\n\t\tprivate readonly client: Client,\n\t\tprivate readonly label: string,\n\t\tprivate readonly helpers: IIntervalHelpers<TInterval>,\n\t\t/** Callback invoked each time one of the endpoints of an interval slides. */\n\t\tprivate readonly onPositionChange?: (\n\t\t\tinterval: TInterval,\n\t\t\tpreviousInterval: TInterval,\n\t\t) => void,\n\t) {\n\t\tthis.overlappingIntervalsIndex = new OverlappingIntervalsIndex(client, helpers);\n\t\tthis.idIntervalIndex = new IdIntervalIndex();\n\t\tthis.endIntervalIndex = new EndpointIndex(client, helpers);\n\t\tthis.indexes = [\n\t\t\tthis.overlappingIntervalsIndex,\n\t\t\tthis.idIntervalIndex,\n\t\t\tthis.endIntervalIndex,\n\t\t];\n\t}\n\n\tpublic createLegacyId(start: number, end: number): string {\n\t\t// Create a non-unique ID based on start and end to be used on intervals that come from legacy clients\n\t\t// without ID's.\n\t\treturn `${LocalIntervalCollection.legacyIdPrefix}${start}-${end}`;\n\t}\n\n\t/**\n\t * Validates that a serialized interval has the ID property. Creates an ID\n\t * if one does not already exist\n\t *\n\t * @param serializedInterval - The interval to be checked\n\t * @returns The interval's existing or newly created id\n\t */\n\tpublic ensureSerializedId(serializedInterval: ISerializedInterval): string {\n\t\tlet id: string | undefined = serializedInterval.properties?.[reservedIntervalIdKey];\n\t\tif (id === undefined) {\n\t\t\t// Back-compat: 0.39 and earlier did not have IDs on intervals. If an interval from such a client\n\t\t\t// comes over the wire, create a non-unique one based on start/end.\n\t\t\t// This will allow all clients to refer to this interval consistently.\n\t\t\tid = this.createLegacyId(serializedInterval.start, serializedInterval.end);\n\t\t\tconst newProps = {\n\t\t\t\t[reservedIntervalIdKey]: id,\n\t\t\t};\n\t\t\tserializedInterval.properties = addProperties(serializedInterval.properties, newProps);\n\t\t}\n\t\t// Make the ID immutable for safety's sake.\n\t\tObject.defineProperty(serializedInterval.properties, reservedIntervalIdKey, {\n\t\t\tconfigurable: false,\n\t\t\tenumerable: true,\n\t\t\twritable: false,\n\t\t});\n\n\t\treturn id;\n\t}\n\n\tprivate removeIntervalFromIndexes(interval: TInterval) {\n\t\tfor (const index of this.indexes) {\n\t\t\tindex.remove(interval);\n\t\t}\n\t}\n\n\tpublic removeExistingInterval(interval: TInterval) {\n\t\tthis.removeIntervalFromIndexes(interval);\n\t\tthis.removeIntervalListeners(interval);\n\t}\n\n\tpublic createInterval(\n\t\tstart: number,\n\t\tend: number,\n\t\tintervalType: IntervalType,\n\t\top?: ISequencedDocumentMessage,\n\t): TInterval {\n\t\treturn this.helpers.create(this.label, start, end, this.client, intervalType, op);\n\t}\n\n\tpublic addInterval(\n\t\tstart: number,\n\t\tend: number,\n\t\tintervalType: IntervalType,\n\t\tprops?: PropertySet,\n\t\top?: ISequencedDocumentMessage,\n\t) {\n\t\tconst interval: TInterval = this.createInterval(start, end, intervalType, op);\n\t\tif (interval) {\n\t\t\tif (!interval.properties) {\n\t\t\t\tinterval.properties = createMap<any>();\n\t\t\t}\n\n\t\t\tif (props) {\n\t\t\t\tinterval.addProperties(props);\n\t\t\t}\n\t\t\tinterval.properties[reservedIntervalIdKey] ??= uuid();\n\t\t\tthis.add(interval);\n\t\t}\n\t\treturn interval;\n\t}\n\n\tprivate linkEndpointsToInterval(interval: TInterval): void {\n\t\tif (interval instanceof SequenceInterval) {\n\t\t\tinterval.start.addProperties({ interval });\n\t\t\tinterval.end.addProperties({ interval });\n\t\t}\n\t}\n\n\tprivate addIntervalToIndexes(interval: TInterval) {\n\t\tfor (const index of this.indexes) {\n\t\t\tindex.add(interval);\n\t\t}\n\t}\n\n\tpublic add(interval: TInterval): void {\n\t\tthis.linkEndpointsToInterval(interval);\n\t\tthis.addIntervalToIndexes(interval);\n\t\tthis.addIntervalListeners(interval);\n\t}\n\n\tpublic changeInterval(\n\t\tinterval: TInterval,\n\t\tstart: number | undefined,\n\t\tend: number | undefined,\n\t\top?: ISequencedDocumentMessage,\n\t\tlocalSeq?: number,\n\t) {\n\t\tconst newInterval = interval.modify(this.label, start, end, op, localSeq) as\n\t\t\t| TInterval\n\t\t\t| undefined;\n\t\tif (newInterval) {\n\t\t\tthis.removeExistingInterval(interval);\n\t\t\tthis.add(newInterval);\n\t\t}\n\t\treturn newInterval;\n\t}\n\n\tpublic serialize(): ISerializedIntervalCollectionV2 {\n\t\treturn {\n\t\t\tlabel: this.label,\n\t\t\tintervals: Array.from(this.idIntervalIndex, (interval) =>\n\t\t\t\tcompressInterval(interval.serialize()),\n\t\t\t),\n\t\t\tversion: 2,\n\t\t};\n\t}\n\n\tprivate addIntervalListeners(interval: TInterval) {\n\t\tconst cloneRef = (ref: LocalReferencePosition) => {\n\t\t\tconst segment = ref.getSegment();\n\t\t\tif (segment === undefined) {\n\t\t\t\t// Cloning is unnecessary: refs which have slid off the string entirely\n\t\t\t\t// never get slid back on. Creation code for refs doesn't accept undefined segment\n\t\t\t\t// either, so this must be special-cased.\n\t\t\t\treturn ref;\n\t\t\t}\n\n\t\t\treturn this.client.createLocalReferencePosition(\n\t\t\t\tsegment,\n\t\t\t\tref.getOffset(),\n\t\t\t\tReferenceType.Transient,\n\t\t\t\tref.properties,\n\t\t\t);\n\t\t};\n\t\tif (interval instanceof SequenceInterval) {\n\t\t\tlet previousInterval: (TInterval & SequenceInterval) | undefined;\n\t\t\tlet pendingChanges = 0;\n\t\t\tinterval.addPositionChangeListeners(\n\t\t\t\t() => {\n\t\t\t\t\tpendingChanges++;\n\t\t\t\t\t// Note: both start and end can change and invoke beforeSlide on each endpoint before afterSlide.\n\t\t\t\t\tif (!previousInterval) {\n\t\t\t\t\t\tpreviousInterval = interval.clone() as TInterval & SequenceInterval;\n\t\t\t\t\t\tpreviousInterval.start = cloneRef(previousInterval.start);\n\t\t\t\t\t\tpreviousInterval.end = cloneRef(previousInterval.end);\n\t\t\t\t\t\tthis.removeIntervalFromIndexes(interval);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tassert(\n\t\t\t\t\t\tpreviousInterval !== undefined,\n\t\t\t\t\t\t0x3fa /* Invalid interleaving of before/after slide */,\n\t\t\t\t\t);\n\t\t\t\t\tpendingChanges--;\n\t\t\t\t\tif (pendingChanges === 0) {\n\t\t\t\t\t\tthis.addIntervalToIndexes(interval);\n\t\t\t\t\t\tthis.onPositionChange?.(interval, previousInterval);\n\t\t\t\t\t\tpreviousInterval = undefined;\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate removeIntervalListeners(interval: TInterval) {\n\t\tif (interval instanceof SequenceInterval) {\n\t\t\tinterval.removePositionChangeListeners();\n\t\t}\n\t}\n}\n\nexport const compareSequenceIntervalEnds = (a: SequenceInterval, b: SequenceInterval): number =>\n\tcompareReferencePositions(a.end, b.end);\n\nclass SequenceIntervalCollectionFactory\n\timplements IValueFactory<IntervalCollection<SequenceInterval>>\n{\n\tpublic load(\n\t\temitter: IValueOpEmitter,\n\t\traw: ISerializedInterval[] | ISerializedIntervalCollectionV2 = [],\n\t): IntervalCollection<SequenceInterval> {\n\t\tconst helpers: IIntervalHelpers<SequenceInterval> = {\n\t\t\tcompareEnds: compareSequenceIntervalEnds,\n\t\t\tcreate: createSequenceInterval,\n\t\t};\n\t\treturn new IntervalCollection<SequenceInterval>(helpers, true, emitter, raw);\n\t}\n\n\tpublic store(\n\t\tvalue: IntervalCollection<SequenceInterval>,\n\t): ISerializedInterval[] | ISerializedIntervalCollectionV2 {\n\t\treturn value.serializeInternal();\n\t}\n}\n\nexport class SequenceIntervalCollectionValueType\n\timplements IValueType<IntervalCollection<SequenceInterval>>\n{\n\tpublic static Name = \"sharedStringIntervalCollection\";\n\n\tpublic get name(): string {\n\t\treturn SequenceIntervalCollectionValueType.Name;\n\t}\n\n\tpublic get factory(): IValueFactory<IntervalCollection<SequenceInterval>> {\n\t\treturn SequenceIntervalCollectionValueType._factory;\n\t}\n\n\tpublic get ops(): Map<string, IValueOperation<IntervalCollection<SequenceInterval>>> {\n\t\treturn SequenceIntervalCollectionValueType._ops;\n\t}\n\n\tprivate static readonly _factory: IValueFactory<IntervalCollection<SequenceInterval>> =\n\t\tnew SequenceIntervalCollectionFactory();\n\n\tprivate static readonly _ops = makeOpsMap<SequenceInterval>();\n}\n\nconst compareIntervalEnds = (a: Interval, b: Interval) => a.end - b.end;\n\nfunction createInterval(label: string, start: number, end: number, client: Client): Interval {\n\tconst rangeProp: PropertySet = {};\n\n\tif (label && label.length > 0) {\n\t\trangeProp[reservedRangeLabelsKey] = [label];\n\t}\n\n\treturn new Interval(start, end, rangeProp);\n}\n\nclass IntervalCollectionFactory implements IValueFactory<IntervalCollection<Interval>> {\n\tpublic load(\n\t\temitter: IValueOpEmitter,\n\t\traw: ISerializedInterval[] | ISerializedIntervalCollectionV2 = [],\n\t): IntervalCollection<Interval> {\n\t\tconst helpers: IIntervalHelpers<Interval> = {\n\t\t\tcompareEnds: compareIntervalEnds,\n\t\t\tcreate: createInterval,\n\t\t};\n\t\tconst collection = new IntervalCollection<Interval>(helpers, false, emitter, raw);\n\t\tcollection.attachGraph(undefined as any as Client, \"\");\n\t\treturn collection;\n\t}\n\n\tpublic store(value: IntervalCollection<Interval>): ISerializedIntervalCollectionV2 {\n\t\treturn value.serializeInternal();\n\t}\n}\n\nexport class IntervalCollectionValueType implements IValueType<IntervalCollection<Interval>> {\n\tpublic static Name = \"sharedIntervalCollection\";\n\n\tpublic get name(): string {\n\t\treturn IntervalCollectionValueType.Name;\n\t}\n\n\tpublic get factory(): IValueFactory<IntervalCollection<Interval>> {\n\t\treturn IntervalCollectionValueType._factory;\n\t}\n\n\tpublic get ops(): Map<string, IValueOperation<IntervalCollection<Interval>>> {\n\t\treturn IntervalCollectionValueType._ops;\n\t}\n\n\tprivate static readonly _factory: IValueFactory<IntervalCollection<Interval>> =\n\t\tnew IntervalCollectionFactory();\n\tprivate static readonly _ops = makeOpsMap<Interval>();\n}\n\nexport function makeOpsMap<T extends ISerializableInterval>(): Map<\n\tstring,\n\tIValueOperation<IntervalCollection<T>>\n> {\n\tconst rebase = (\n\t\tcollection: IntervalCollection<T>,\n\t\top: IValueTypeOperationValue,\n\t\tlocalOpMetadata: IMapMessageLocalMetadata,\n\t) => {\n\t\tconst { localSeq } = localOpMetadata;\n\t\tconst rebasedValue = collection.rebaseLocalInterval(op.opName, op.value, localSeq);\n\t\tconst rebasedOp = { ...op, value: rebasedValue };\n\t\treturn { rebasedOp, rebasedLocalOpMetadata: localOpMetadata };\n\t};\n\n\treturn new Map<string, IValueOperation<IntervalCollection<T>>>([\n\t\t[\n\t\t\t\"add\",\n\t\t\t{\n\t\t\t\tprocess: (collection, params, local, op, localOpMetadata) => {\n\t\t\t\t\t// if params is undefined, the interval was deleted during\n\t\t\t\t\t// rebasing\n\t\t\t\t\tif (!params) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tassert(op !== undefined, 0x3fb /* op should exist here */);\n\t\t\t\t\tcollection.ackAdd(params, local, op, localOpMetadata);\n\t\t\t\t},\n\t\t\t\trebase,\n\t\t\t},\n\t\t],\n\t\t[\n\t\t\t\"delete\",\n\t\t\t{\n\t\t\t\tprocess: (collection, params, local, op) => {\n\t\t\t\t\tassert(op !== undefined, 0x3fc /* op should exist here */);\n\t\t\t\t\tcollection.ackDelete(params, local, op);\n\t\t\t\t},\n\t\t\t\trebase: (collection, op, localOpMetadata) => {\n\t\t\t\t\t// Deletion of intervals is based on id, so requires no rebasing.\n\t\t\t\t\treturn { rebasedOp: op, rebasedLocalOpMetadata: localOpMetadata };\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t\t[\n\t\t\t\"change\",\n\t\t\t{\n\t\t\t\tprocess: (collection, params, local, op, localOpMetadata) => {\n\t\t\t\t\t// if params is undefined, the interval was deleted during\n\t\t\t\t\t// rebasing\n\t\t\t\t\tif (!params) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tassert(op !== undefined, 0x3fd /* op should exist here */);\n\t\t\t\t\tcollection.ackChange(params, local, op, localOpMetadata);\n\t\t\t\t},\n\t\t\t\trebase,\n\t\t\t},\n\t\t],\n\t]);\n}\n\nexport type DeserializeCallback = (properties: PropertySet) => void;\n\nexport class IntervalCollectionIterator<TInterval extends ISerializableInterval>\n\timplements Iterator<TInterval>\n{\n\tprivate readonly results: TInterval[];\n\tprivate index: number;\n\n\tconstructor(\n\t\tcollection: IntervalCollection<TInterval>,\n\t\titeratesForward: boolean = true,\n\t\tstart?: number,\n\t\tend?: number,\n\t) {\n\t\tthis.results = [];\n\t\tthis.index = 0;\n\n\t\tcollection.gatherIterationResults(this.results, iteratesForward, start, end);\n\t}\n\n\tpublic next(): IteratorResult<TInterval> {\n\t\tif (this.index < this.results.length) {\n\t\t\treturn {\n\t\t\t\tvalue: this.results[this.index++],\n\t\t\t\tdone: false,\n\t\t\t};\n\t\t}\n\n\t\treturn {\n\t\t\tvalue: undefined,\n\t\t\tdone: true,\n\t\t};\n\t}\n}\n\n/**\n * Change events emitted by `IntervalCollection`s\n */\nexport interface IIntervalCollectionEvent<TInterval extends ISerializableInterval> extends IEvent {\n\t/**\n\t * This event is invoked whenever the endpoints of an interval may have changed.\n\t * This can happen on:\n\t * - local endpoint modification\n\t * - ack of a remote endpoint modification\n\t * - position change due to segment sliding (slides due to mergeTree segment deletion will always appear local)\n\t * The `interval` argument reflects the new values.\n\t * `previousInterval` contains transient `ReferencePosition`s at the same location as the interval's original\n\t * endpoints. These references should be used for position information only.\n\t * `local` reflects whether the change originated locally.\n\t * `op` is defined if and only if the server has acked this change.\n\t */\n\t(\n\t\tevent: \"changeInterval\",\n\t\tlistener: (\n\t\t\tinterval: TInterval,\n\t\t\tpreviousInterval: TInterval,\n\t\t\tlocal: boolean,\n\t\t\top: ISequencedDocumentMessage | undefined,\n\t\t) => void,\n\t);\n\t/**\n\t * This event is invoked whenever an interval is added or removed from the collection.\n\t * `local` reflects whether the change originated locally.\n\t * `op` is defined if and only if the server has acked this change.\n\t */\n\t(\n\t\tevent: \"addInterval\" | \"deleteInterval\",\n\t\tlistener: (\n\t\t\tinterval: TInterval,\n\t\t\tlocal: boolean,\n\t\t\top: ISequencedDocumentMessage | undefined,\n\t\t) => void,\n\t);\n\t/**\n\t * This event is invoked whenever an interval's properties have changed.\n\t * `interval` reflects the state of the updated properties.\n\t * `propertyDeltas` is a map-like whose keys contain all values that were changed, and whose\n\t * values contain all previous values of the property set.\n\t * This object can be used directly in a call to `changeProperties` to revert the property change if desired.\n\t * `local` reflects whether the change originated locally.\n\t * `op` is defined if and only if the server has acked this change.\n\t */\n\t(\n\t\tevent: \"propertyChanged\",\n\t\tlistener: (\n\t\t\tinterval: TInterval,\n\t\t\tpropertyDeltas: PropertySet,\n\t\t\tlocal: boolean,\n\t\t\top: ISequencedDocumentMessage | undefined,\n\t\t) => void,\n\t);\n}\n\n/**\n * Collection of intervals that supports addition, modification, removal, and efficient spatial querying.\n * This class is not a DDS in its own right, but emits events on mutating operations such that it's possible to\n * integrate into a DDS.\n * This aligns with its usage in `SharedSegmentSequence`, which allows associating intervals to positions in the\n * sequence DDS which are broadcast to all other clients in an eventually consistent fashion.\n */\nexport class IntervalCollection<TInterval extends ISerializableInterval> extends TypedEventEmitter<\n\tIIntervalCollectionEvent<TInterval>\n> {\n\tprivate savedSerializedIntervals?: ISerializedInterval[];\n\tprivate localCollection: LocalIntervalCollection<TInterval> | undefined;\n\tprivate onDeserialize: DeserializeCallback | undefined;\n\tprivate client: Client | undefined;\n\tprivate readonly localSeqToSerializedInterval = new Map<\n\t\tnumber,\n\t\tISerializedInterval | SerializedIntervalDelta\n\t>();\n\tprivate readonly localSeqToRebasedInterval = new Map<\n\t\tnumber,\n\t\tISerializedInterval | SerializedIntervalDelta\n\t>();\n\tprivate readonly pendingChangesStart: Map<string, ISerializedInterval[]> = new Map<\n\t\tstring,\n\t\tISerializedInterval[]\n\t>();\n\tprivate readonly pendingChangesEnd: Map<string, ISerializedInterval[]> = new Map<\n\t\tstring,\n\t\tISerializedInterval[]\n\t>();\n\n\tpublic get attached(): boolean {\n\t\treturn !!this.localCollection;\n\t}\n\n\t/** @internal */\n\tconstructor(\n\t\tprivate readonly helpers: IIntervalHelpers<TInterval>,\n\t\tprivate readonly requiresClient: boolean,\n\t\tprivate readonly emitter: IValueOpEmitter,\n\t\tserializedIntervals: ISerializedInterval[] | ISerializedIntervalCollectionV2,\n\t) {\n\t\tsuper();\n\n\t\tthis.savedSerializedIntervals = Array.isArray(serializedIntervals)\n\t\t\t? serializedIntervals\n\t\t\t: serializedIntervals.intervals.map((i) =>\n\t\t\t\t\tdecompressInterval(i, serializedIntervals.label),\n\t\t\t );\n\t}\n\n\tprivate rebasePositionWithSegmentSlide(\n\t\tpos: number,\n\t\tseqNumberFrom: number,\n\t\tlocalSeq: number,\n\t): number | undefined {\n\t\tif (!this.client) {\n\t\t\tthrow new LoggingError(\"mergeTree client must exist\");\n\t\t}\n\t\tconst { clientId } = this.client.getCollabWindow();\n\t\tconst { segment, offset } = this.client.getContainingSegment(\n\t\t\tpos,\n\t\t\t{\n\t\t\t\treferenceSequenceNumber: seqNumberFrom,\n\t\t\t\tclientId: this.client.getLongClientId(clientId),\n\t\t\t},\n\t\t\tlocalSeq,\n\t\t);\n\n\t\t// if segment is undefined, it slid off the string\n\t\tassert(segment !== undefined, 0x54e /* No segment found */);\n\n\t\tconst segoff = this.client.getSlideToSegment({ segment, offset }) ?? segment;\n\n\t\t// case happens when rebasing op, but concurrently entire string has been deleted\n\t\tif (segoff.segment === undefined || segoff.offset === undefined) {\n\t\t\treturn DetachedReferencePosition;\n\t\t}\n\n\t\tassert(\n\t\t\toffset !== undefined && 0 <= offset && offset < segment.cachedLength,\n\t\t\t0x54f /* Invalid offset */,\n\t\t);\n\t\treturn this.client.findReconnectionPosition(segoff.segment, localSeq) + segoff.offset;\n\t}\n\n\tprivate computeRebasedPositions(\n\t\tlocalSeq: number,\n\t): ISerializedInterval | SerializedIntervalDelta {\n\t\tassert(\n\t\t\tthis.client !== undefined,\n\t\t\t0x550 /* Client should be defined when computing rebased position */,\n\t\t);\n\t\tconst original = this.localSeqToSerializedInterval.get(localSeq);\n\t\tassert(\n\t\t\toriginal !== undefined,\n\t\t\t0x551 /* Failed to store pending serialized interval info for this localSeq. */,\n\t\t);\n\t\tconst rebased = { ...original };\n\t\tconst { start, end, sequenceNumber } = original;\n\t\tif (start !== undefined) {\n\t\t\trebased.start = this.rebasePositionWithSegmentSlide(start, sequenceNumber, localSeq);\n\t\t}\n\t\tif (end !== undefined) {\n\t\t\trebased.end = this.rebasePositionWithSegmentSlide(end, sequenceNumber, localSeq);\n\t\t}\n\t\treturn rebased;\n\t}\n\n\t/** @internal */\n\tpublic attachGraph(client: Client, label: string) {\n\t\tif (this.attached) {\n\t\t\tthrow new LoggingError(\"Only supports one Sequence attach\");\n\t\t}\n\n\t\tif (client === undefined && this.requiresClient) {\n\t\t\tthrow new LoggingError(\"Client required for this collection\");\n\t\t}\n\n\t\t// Instantiate the local interval collection based on the saved intervals\n\t\tthis.client = client;\n\t\tif (client) {\n\t\t\tclient.on(\"normalize\", () => {\n\t\t\t\tfor (const localSeq of this.localSeqToSerializedInterval.keys()) {\n\t\t\t\t\tthis.localSeqToRebasedInterval.set(\n\t\t\t\t\t\tlocalSeq,\n\t\t\t\t\t\tthis.computeRebasedPositions(localSeq),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\n\t\tthis.localCollection = new LocalIntervalCollection<TInterval>(\n\t\t\tclient,\n\t\t\tlabel,\n\t\t\tthis.helpers,\n\t\t\t(interval, previousInterval) => this.emitChange(interval, previousInterval, true),\n\t\t);\n\t\tif (this.savedSerializedIntervals) {\n\t\t\tfor (const serializedInterval of this.savedSerializedIntervals) {\n\t\t\t\tthis.localCollection.ensureSerializedId(serializedInterval);\n\t\t\t\tconst { start, end, intervalType, properties } = serializedInterval;\n\t\t\t\tconst interval = this.helpers.create(\n\t\t\t\t\tlabel,\n\t\t\t\t\tstart,\n\t\t\t\t\tend,\n\t\t\t\t\tclient,\n\t\t\t\t\tintervalType,\n\t\t\t\t\tundefined,\n\t\t\t\t\ttrue,\n\t\t\t\t);\n\t\t\t\tif (properties) {\n\t\t\t\t\tinterval.addProperties(properties);\n\t\t\t\t}\n\t\t\t\tthis.localCollection.add(interval);\n\t\t\t}\n\t\t}\n\t\tthis.savedSerializedIntervals = undefined;\n\t}\n\n\t/**\n\t * Gets the next local sequence number, modifying this client's collab window in doing so.\n\t */\n\tprivate getNextLocalSeq(): number {\n\t\tif (this.client) {\n\t\t\treturn ++this.client.getCollabWindow().localSeq;\n\t\t}\n\n\t\treturn 0;\n\t}\n\n\tprivate emitChange(\n\t\tinterval: TInterval,\n\t\tpreviousInterval: TInterval,\n\t\tlocal: boolean,\n\t\top?: ISequencedDocumentMessage,\n\t): void {\n\t\t// Temporarily make references transient so that positional queries work (non-transient refs\n\t\t// on resolve to DetachedPosition on any segments that don't contain them). The original refType\n\t\t// is restored as single-endpoint changes re-use previous references.\n\t\tlet startRefType: ReferenceType;\n\t\tlet endRefType: ReferenceType;\n\t\tif (previousInterval instanceof SequenceInterval) {\n\t\t\tstartRefType = previousInterval.start.refType;\n\t\t\tendRefType = previousInterval.end.refType;\n\t\t\tpreviousInterval.start.refType = ReferenceType.Transient;\n\t\t\tpreviousInterval.end.refType = ReferenceType.Transient;\n\t\t\tthis.emit(\"changeInterval\", interval, previousInterval, local, op);\n\t\t\tpreviousInterval.start.refType = startRefType;\n\t\t\tpreviousInterval.end.refType = endRefType;\n\t\t} else {\n\t\t\tthis.emit(\"changeInterval\", interval, previousInterval, local, op);\n\t\t}\n\t}\n\n\t/**\n\t * @returns the interval in this collection that has the provided `id`.\n\t * If no interval in the collection has this `id`, returns `undefined`.\n\t */\n\tpublic getIntervalById(id: string) {\n\t\tif (!this.localCollection) {\n\t\t\tthrow new LoggingError(\"attach must be called before accessing intervals\");\n\t\t}\n\t\treturn this.localCollection.idIntervalIndex.getIntervalById(id);\n\t}\n\n\t/**\n\t * Creates a new interval and add it to the collection.\n\t * @param start - interval start position (inclusive)\n\t * @param end - interval end position (exclusive)\n\t * @param intervalType - type of the interval. All intervals are SlideOnRemove. Intervals may not be Transient.\n\t * @param props - properties of the interval\n\t * @returns - the created interval\n\t * @remarks - See documentation on {@link SequenceInterval} for comments on interval endpoint semantics: there are subtleties\n\t * with how the current half-open behavior is represented.\n\t */\n\tpublic add(\n\t\tstart: number,\n\t\tend: number,\n\t\tintervalType: IntervalType,\n\t\tprops?: PropertySet,\n\t): TInterval {\n\t\tif (!this.localCollection) {\n\t\t\tthrow new LoggingError(\"attach must be called prior to adding intervals\");\n\t\t}\n\t\tif (intervalType & IntervalType.Transient) {\n\t\t\tthrow new LoggingError(\"Can not add transient intervals\");\n\t\t}\n\n\t\tconst interval: TInterval = this.localCollection.addInterval(\n\t\t\tstart,\n\t\t\tend,\n\t\t\tintervalType,\n\t\t\tprops,\n\t\t);\n\n\t\tif (interval) {\n\t\t\tconst serializedInterval = {\n\t\t\t\tend,\n\t\t\t\tintervalType,\n\t\t\t\tproperties: interval.properties,\n\t\t\t\tsequenceNumber: this.client?.getCurrentSeq() ?? 0,\n\t\t\t\tstart,\n\t\t\t};\n\t\t\tconst localSeq = this.getNextLocalSeq();\n\t\t\tthis.localSeqToSerializedInterval.set(localSeq, serializedInterval);\n\t\t\t// Local ops get submitted to the server. Remote ops have the deserializer run.\n\t\t\tthis.emitter.emit(\"add\", undefined, serializedInterval, { localSeq });\n\t\t}\n\n\t\tthis.emit(\"addInterval\", interval, true, undefined);\n\n\t\treturn interval;\n\t}\n\n\tprivate deleteExistingInterval(\n\t\tinterval: TInterval,\n\t\tlocal: boolean,\n\t\top?: ISequencedDocumentMessage,\n\t) {\n\t\tif (!this.localCollection) {\n\t\t\tthrow new LoggingError(\"Attach must be called before accessing intervals\");\n\t\t}\n\t\t// The given interval is known to exist in the collection.\n\t\tthis.localCollection.removeExistingInterval(interval);\n\n\t\tif (interval) {\n\t\t\t// Local ops get submitted to the server. Remote ops have the deserializer run.\n\t\t\tif (local) {\n\t\t\t\tthis.emitter.emit(\"delete\", undefined, interval.serialize(), {\n\t\t\t\t\tlocalSeq: this.getNextLocalSeq(),\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tif (this.onDeserialize) {\n\t\t\t\t\tthis.onDeserialize(interval);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthis.emit(\"deleteInterval\", interval, local, op);\n\t}\n\n\t/**\n\t * Removes an interval from the collection.\n\t * @param id - Id of the interval to remove\n\t * @returns the removed interval\n\t */\n\tpublic removeIntervalById(id: string) {\n\t\tif (!this.localCollection) {\n\t\t\tthrow new LoggingError(\"Attach must be called before accessing intervals\");\n\t\t}\n\t\tconst interval = this.localCollection.idIntervalIndex.getIntervalById(id);\n\t\tif (interval) {\n\t\t\tthis.deleteExistingInterval(interval, true, undefined);\n\t\t}\n\t\treturn interval;\n\t}\n\n\t/**\n\t * Changes the properties on an existing interval.\n\t * @param id - Id of the interval whose properties should be changed\n\t * @param props - Property set to apply to the interval. Shallow merging is used between any existing properties\n\t * and `prop`, i.e. the interval will end up with a property object equivalent to `{ ...oldProps, ...props }`.\n\t */\n\tpublic changeProperties(id: string, props: PropertySet) {\n\t\tif (!this.attached) {\n\t\t\tthrow new LoggingError(\"Attach must be called before accessing intervals\");\n\t\t}\n\t\tif (typeof id !== \"string\") {\n\t\t\tthrow new LoggingError(\"Change API requires an ID that is a string\");\n\t\t}\n\t\tif (!props) {\n\t\t\tthrow new LoggingError(\"changeProperties should be called with a property set\");\n\t\t}\n\n\t\tconst interval = this.getIntervalById(id);\n\t\tif (interval) {\n\t\t\t// Pass Unassigned as the sequence number to indicate that this is a local op that is waiting for an ack.\n\t\t\tconst deltaProps = interval.addProperties(props, true, UnassignedSequenceNumber);\n\t\t\tconst serializedInterval: ISerializedInterval = interval.serialize();\n\n\t\t\t// Emit a change op that will only change properties. Add the ID to\n\t\t\t// the property bag provided by the caller.\n\t\t\tserializedInterval.start = undefined as any;\n\t\t\tserializedInterval.end = undefined as any;\n\n\t\t\tserializedInterval.properties = props;\n\t\t\tserializedInterval.properties[reservedIntervalIdKey] = interval.getIntervalId();\n\t\t\tconst localSeq = this.getNextLocalSeq();\n\t\t\tthis.localSeqToSerializedInterval.set(localSeq, serializedInterval);\n\t\t\tthis.emitter.emit(\"change\", undefined, serializedInterval, { localSeq });\n\t\t\tthis.emit(\"propertyChanged\", interval, deltaProps, true, undefined);\n\t\t}\n\t}\n\n\t/**\n\t * Changes the endpoints of an existing interval.\n\t * @param id - Id of the interval to change\n\t * @param start - New start value, if defined. `undefined` signifies this endpoint should be left unchanged.\n\t * @param end - New end value, if defined. `undefined` signifies this endpoint should be left unchanged.\n\t * @returns the interval that was changed, if it existed in the collection.\n\t */\n\tpublic change(id: string, start?: number, end?: number): TInterval | undefined {\n\t\tif (!this.localCollection) {\n\t\t\tthrow new LoggingError(\"Attach must be called before accessing intervals\");\n\t\t}\n\n\t\t// Force id to be a string.\n\t\tif (typeof id !== \"string\") {\n\t\t\tthrow new LoggingError(\"Change API requires an ID that is a string\");\n\t\t}\n\n\t\tconst interval = this.getIntervalById(id);\n\t\tif (interval) {\n\t\t\tconst newInterval = this.localCollection.changeInterval(interval, start, end);\n\t\t\tif (!newInterval) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tconst serializedInterval: SerializedIntervalDelta = interval.serialize();\n\t\t\tserializedInterval.start = start;\n\t\t\tserializedInterval.end = end;\n\t\t\t// Emit a property bag containing only the ID, as we don't intend for this op to change any properties.\n\t\t\tserializedInterval.properties = {\n\t\t\t\t[reservedIntervalIdKey]: interval.getIntervalId(),\n\t\t\t};\n\t\t\tconst localSeq = this.getNextLocalSeq();\n\t\t\tthis.localSeqToSerializedInterval.set(localSeq, serializedInterval);\n\t\t\tthis.emitter.emit(\"change\", undefined, serializedInterval, { localSeq });\n\t\t\tthis.addPendingChange(id, serializedInterval);\n\t\t\tthis.emitChange(newInterval, interval, true);\n\t\t\treturn newInterval;\n\t\t}\n\t\t// No interval to change\n\t\treturn undefined;\n\t}\n\n\tprivate addPendingChange(id: string, serializedInterval: SerializedIntervalDelta) {\n\t\tif (serializedInterval.start !== undefined) {\n\t\t\tthis.addPendingChangeHelper(id, this.pendingChangesStart, serializedInterval);\n\t\t}\n\t\tif (serializedInterval.end !== undefined) {\n\t\t\tthis.addPendingChangeHelper(id, this.pendingChangesEnd, serializedInterval);\n\t\t}\n\t}\n\n\tprivate addPendingChangeHelper(\n\t\tid: string,\n\t\tpendingChanges: Map<string, SerializedIntervalDelta[]>,\n\t\tserializedInterval: SerializedIntervalDelta,\n\t) {\n\t\tlet entries: SerializedIntervalDelta[] | undefined = pendingChanges.get(id);\n\t\tif (!entries) {\n\t\t\tentries = [];\n\t\t\tpendingChanges.set(id, entries);\n\t\t}\n\t\tentries.push(serializedInterval);\n\t}\n\n\tprivate removePendingChange(serializedInterval: SerializedIntervalDelta) {\n\t\t// Change ops always have an ID.\n\t\tconst id: string = serializedInterval.properties?.[reservedIntervalIdKey];\n\t\tif (serializedInterval.start !== undefined) {\n\t\t\tthis.removePendingChangeHelper(id, this.pendingChangesStart, serializedInterval);\n\t\t}\n\t\tif (serializedInterval.end !== undefined) {\n\t\t\tthis.removePendingChangeHelper(id, this.pendingChangesEnd, serializedInterval);\n\t\t}\n\t}\n\n\tprivate removePendingChangeHelper(\n\t\tid: string,\n\t\tpendingChanges: Map<string, SerializedIntervalDelta[]>,\n\t\tserializedInterval: SerializedIntervalDelta,\n\t) {\n\t\tconst entries = pendingChanges.get(id);\n\t\tif (entries) {\n\t\t\tconst pendingChange = entries.shift();\n\t\t\tif (entries.length === 0) {\n\t\t\t\tpendingChanges.delete(id);\n\t\t\t}\n\t\t\tif (\n\t\t\t\tpendingChange?.start !== serializedInterval.start ||\n\t\t\t\tpendingChange?.end !== serializedInterval.end\n\t\t\t) {\n\t\t\t\tthrow new LoggingError(\"Mismatch in pending changes\");\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate hasPendingChangeStart(id: string) {\n\t\tconst entries = this.pendingChangesStart.get(id);\n\t\treturn entries && entries.length !== 0;\n\t}\n\n\tprivate hasPendingChangeEnd(id: string) {\n\t\tconst entries = this.pendingChangesEnd.get(id);\n\t\treturn entries && entries.length !== 0;\n\t}\n\n\t/** @internal */\n\tpublic ackChange(\n\t\tserializedInterval: ISerializedInterval,\n\t\tlocal: boolean,\n\t\top: ISequencedDocumentMessage,\n\t\tlocalOpMetadata: IMapMessageLocalMetadata | undefined,\n\t) {\n\t\tif (!this.localCollection) {\n\t\t\tthrow new LoggingError(\"Attach must be called before accessing intervals\");\n\t\t}\n\n\t\tif (local) {\n\t\t\tassert(\n\t\t\t\tlocalOpMetadata !== undefined,\n\t\t\t\t0x552 /* op metadata should be defined for local op */,\n\t\t\t);\n\t\t\tthis.localSeqToSerializedInterval.delete(localOpMetadata?.localSeq);\n\t\t\t// This is an ack from the server. Remove the pending change.\n\t\t\tthis.removePendingChange(serializedInterval);\n\t\t}\n\n\t\t// Note that the ID is in the property bag only to allow us to find the interval.\n\t\t// This API cannot change the ID, and writing to the ID property will result in an exception. So we\n\t\t// strip it out of the properties here.\n\t\tconst { [reservedIntervalIdKey]: id, ...newProps } = serializedInterval.properties ?? {};\n\t\tassert(id !== undefined, 0x3fe /* id must exist on the interval */);\n\t\tconst interval: TInterval | undefined = this.getIntervalById(id);\n\t\tif (!interval) {\n\t\t\t// The interval has been removed locally; no-op.\n\t\t\treturn;\n\t\t}\n\n\t\tif (local) {\n\t\t\t// Let the propertyManager prune its pending change-properties set.\n\t\t\tinterval.propertyManager?.ackPendingProperties({\n\t\t\t\ttype: MergeTreeDeltaType.ANNOTATE,\n\t\t\t\tprops: serializedInterval.properties ?? {},\n\t\t\t});\n\n\t\t\tthis.ackInterval(interval, op);\n\t\t} else {\n\t\t\t// If there are pending changes with this ID, don't apply the remote start/end change, as the local ack\n\t\t\t// should be the winning change.\n\t\t\tlet start: number | undefined;\n\t\t\tlet end: number | undefined;\n\t\t\t// Track pending start/end independently of one another.\n\t\t\tif (!this.hasPendingChangeStart(id)) {\n\t\t\t\tstart = serializedInterval.start;\n\t\t\t}\n\t\t\tif (!this.hasPendingChangeEnd(id)) {\n\t\t\t\tend = serializedInterval.end;\n\t\t\t}\n\n\t\t\tlet newInterval = interval;\n\t\t\tif (start !== undefined || end !== undefined) {\n\t\t\t\t// If changeInterval gives us a new interval, work with that one. Otherwise keep working with\n\t\t\t\t// the one we originally found in the tree.\n\t\t\t\tnewInterval =\n\t\t\t\t\tthis.localCollection.changeInterval(interval, start, end, op) ?? interval;\n\t\t\t}\n\t\t\tconst deltaProps = newInterval.addProperties(newProps, true, op.sequenceNumber);\n\t\t\tif (this.onDeserialize) {\n\t\t\t\tthis.onDeserialize(newInterval);\n\t\t\t}\n\n\t\t\tif (newInterval !== interval) {\n\t\t\t\tthis.emitChange(newInterval, interval, local, op);\n\t\t\t}\n\n\t\t\tconst changedProperties = Object.keys(newProps).length > 0;\n\t\t\tif (changedProperties) {\n\t\t\t\tthis.emit(\"propertyChanged\", interval, deltaProps, local, op);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * @deprecated - This functionality was useful when adding two intervals at the same start/end positions resulted\n\t * in a conflict. This is no longer the case (as of PR#6407), as interval collections support multiple intervals\n\t * at the same location and gives each interval a unique id.\n\t *\n\t * As such, the conflict resolver is never invoked and unnecessary. This API will be removed in an upcoming release.\n\t */\n\tpublic addConflictResolver(_: IntervalConflictResolver<TInterval>): void {\n\t\tif (!this.localCollection) {\n\t\t\tthrow new LoggingError(\"attachSequence must be called\");\n\t\t}\n\t}\n\n\tpublic attachDeserializer(onDeserialize: DeserializeCallback): void {\n\t\t// If no deserializer is specified can skip all processing work\n\t\tif (!onDeserialize) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Start by storing the callbacks so that any subsequent modifications make use of them\n\t\tthis.onDeserialize = onDeserialize;\n\n\t\t// Trigger the async prepare work across all values in the collection\n\t\tif (this.attached) {\n\t\t\tthis.map(onDeserialize);\n\t\t}\n\t}\n\n\t/**\n\t * Returns new interval after rebasing. If undefined, the interval was\n\t * deleted as a result of rebasing. This can occur if the interval applies\n\t * to a range that no longer exists, and the interval was unable to slide.\n\t *\n\t * @internal\n\t */\n\tpublic rebaseLocalInterval(\n\t\topName: string,\n\t\tserializedInterval: SerializedIntervalDelta,\n\t\tlocalSeq: number,\n\t): SerializedIntervalDelta | undefined {\n\t\tif (!this.client) {\n\t\t\t// If there's no associated mergeTree client, the originally submitted op is still correct.\n\t\t\treturn serializedInterval;\n\t\t}\n\t\tif (!this.attached) {\n\t\t\tthrow new LoggingError(\"attachSequence must be called\");\n\t\t}\n\n\t\tconst { intervalType, properties } = serializedInterval;\n\n\t\tconst { start: startRebased, end: endRebased } =\n\t\t\tthis.localSeqToRebasedInterval.get(localSeq) ?? this.computeRebasedPositions(localSeq);\n\n\t\tconst intervalId = properties?.[reservedIntervalIdKey];\n\t\tconst localInterval = this.localCollection?.idIntervalIndex.getIntervalById(intervalId);\n\n\t\tconst rebased: SerializedIntervalDelta = {\n\t\t\tstart: startRebased,\n\t\t\tend: endRebased,\n\t\t\tintervalType,\n\t\t\tsequenceNumber: this.client?.getCurrentSeq() ?? 0,\n\t\t\tproperties,\n\t\t};\n\n\t\tif (\n\t\t\topName === \"change\" &&\n\t\t\t(this.hasPendingChangeStart(intervalId) || this.hasPendingChangeEnd(intervalId))\n\t\t) {\n\t\t\tthis.removePendingChange(serializedInterval);\n\t\t\tthis.addPendingChange(intervalId, rebased);\n\t\t}\n\n\t\t// if the interval slid off the string, rebase the op to be a noop and delete the interval.\n\t\tif (\n\t\t\tstartRebased === DetachedReferencePosition ||\n\t\t\tendRebased === DetachedReferencePosition\n\t\t) {\n\t\t\tif (localInterval) {\n\t\t\t\tthis.localCollection?.removeExistingInterval(localInterval);\n\t\t\t}\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif (localInterval !== undefined) {\n\t\t\t// we know we must be using `SequenceInterval` because `this.client` exists\n\t\t\tassert(\n\t\t\t\tlocalInterval instanceof SequenceInterval,\n\t\t\t\t0x3a0 /* localInterval must be `SequenceInterval` when used with client */,\n\t\t\t);\n\t\t\t// The rebased op may place this interval's endpoints on different segments. Calling `changeInterval` here\n\t\t\t// updates the local client's state to be consistent with the emitted op.\n\t\t\tthis.localCollection?.changeInterval(\n\t\t\t\tlocalInterval,\n\t\t\t\tstartRebased,\n\t\t\t\tendRebased,\n\t\t\t\tundefined,\n\t\t\t\tlocalSeq,\n\t\t\t);\n\t\t}\n\n\t\treturn rebased;\n\t}\n\n\tprivate getSlideToSegment(lref: LocalReferencePosition) {\n\t\tif (!this.client) {\n\t\t\tthrow new LoggingError(\"client does not exist\");\n\t\t}\n\t\tconst segoff = { segment: lref.getSegment(), offset: lref.getOffset() };\n\t\tif (segoff.segment?.localRefs?.has(lref) !== true) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst newSegoff = this.client.getSlideToSegment(segoff);\n\t\tconst value: { segment: ISegment | undefined; offset: number | undefined } | undefined =\n\t\t\tsegoff.segment === newSegoff.segment && segoff.offset === newSegoff.offset\n\t\t\t\t? undefined\n\t\t\t\t: newSegoff;\n\t\treturn value;\n\t}\n\n\tprivate setSlideOnRemove(lref: LocalReferencePosition) {\n\t\tlet refType = lref.refType;\n\t\trefType = refType & ~ReferenceType.StayOnRemove;\n\t\trefType = refType | ReferenceType.SlideOnRemove;\n\t\tlref.refType = refType;\n\t}\n\n\tprivate ackInterval(interval: TInterval, op: ISequencedDocumentMessage) {\n\t\t// Only SequenceIntervals need potential sliding\n\t\tif (!(interval instanceof SequenceInterval)) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (\n\t\t\t!refTypeIncludesFlag(interval.start, ReferenceType.StayOnRemove) &&\n\t\t\t!refTypeIncludesFlag(interval.end, ReferenceType.StayOnRemove)\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst newStart = this.getSlideToSegment(interval.start);\n\t\tconst newEnd = this.getSlideToSegment(interval.end);\n\n\t\tconst id = interval.properties[reservedIntervalIdKey];\n\t\tconst hasPendingStartChange = this.hasPendingChangeStart(id);\n\t\tconst hasPendingEndChange = this.hasPendingChangeEnd(id);\n\n\t\tif (!hasPendingStartChange) {\n\t\t\tthis.setSlideOnRemove(interval.start);\n\t\t}\n\n\t\tif (!hasPendingEndChange) {\n\t\t\tthis.setSlideOnRemove(interval.end);\n\t\t}\n\n\t\tconst needsStartUpdate = newStart !== undefined && !hasPendingStartChange;\n\t\tconst needsEndUpdate = newEnd !== undefined && !hasPendingEndChange;\n\n\t\tif (needsStartUpdate || needsEndUpdate) {\n\t\t\tif (!this.localCollection) {\n\t\t\t\tthrow new LoggingError(\"Attach must be called before accessing intervals\");\n\t\t\t}\n\n\t\t\t// `interval`'s endpoints will get modified in-place, so clone it prior to doing so for event emission.\n\t\t\tconst oldInterval = interval.clone() as TInterval & SequenceInterval;\n\n\t\t\t// In this case, where we change the start or end of an interval,\n\t\t\t// it is necessary to remove and re-add the interval listeners.\n\t\t\t// This ensures that the correct listeners are added to the LocalReferencePosition.\n\t\t\tthis.localCollection.removeExistingInterval(interval);\n\t\t\tif (!this.client) {\n\t\t\t\tthrow new LoggingError(\"client does not exist\");\n\t\t\t}\n\n\t\t\tif (needsStartUpdate) {\n\t\t\t\tconst props = interval.start.properties;\n\t\t\t\tinterval.start = createPositionReferenceFromSegoff(\n\t\t\t\t\tthis.client,\n\t\t\t\t\tnewStart,\n\t\t\t\t\tinterval.start.refType,\n\t\t\t\t\top,\n\t\t\t\t);\n\t\t\t\tif (props) {\n\t\t\t\t\tinterval.start.addProperties(props);\n\t\t\t\t}\n\t\t\t\tconst oldSeg = oldInterval.start.getSegment();\n\t\t\t\t// remove and rebuild start interval as transient for event\n\t\t\t\tthis.client.removeLocalReferencePosition(oldInterval.start);\n\t\t\t\toldInterval.start.refType = ReferenceType.Transient;\n\t\t\t\toldSeg?.localRefs?.addLocalRef(oldInterval.start, oldInterval.start.getOffset());\n\t\t\t}\n\t\t\tif (needsEndUpdate) {\n\t\t\t\tconst props = interval.end.properties;\n\t\t\t\tinterval.end = createPositionReferenceFromSegoff(\n\t\t\t\t\tthis.client,\n\t\t\t\t\tnewEnd,\n\t\t\t\t\tinterval.end.refType,\n\t\t\t\t\top,\n\t\t\t\t);\n\t\t\t\tif (props) {\n\t\t\t\t\tinterval.end.addProperties(props);\n\t\t\t\t}\n\t\t\t\t// remove and rebuild end interval as transient for event\n\t\t\t\tconst oldSeg = oldInterval.end.getSegment();\n\t\t\t\tthis.client.removeLocalReferencePosition(oldInterval.end);\n\t\t\t\toldInterval.end.refType = ReferenceType.Transient;\n\t\t\t\toldSeg?.localRefs?.addLocalRef(oldInterval.end, oldInterval.end.getOffset());\n\t\t\t}\n\t\t\tthis.localCollection.add(interval);\n\t\t\tthis.emitChange(interval, oldInterval as TInterval, true, op);\n\t\t}\n\t}\n\n\t/** @internal */\n\tpublic ackAdd(\n\t\tserializedInterval: ISerializedInterval,\n\t\tlocal: boolean,\n\t\top: ISequencedDocumentMessage,\n\t\tlocalOpMetadata: IMapMessageLocalMetadata | undefined,\n\t) {\n\t\tif (local) {\n\t\t\tassert(\n\t\t\t\tlocalOpMetadata !== undefined,\n\t\t\t\t0x553 /* op metadata should be defined for local op */,\n\t\t\t);\n\t\t\tthis.localSeqToSerializedInterval.delete(localOpMetadata.localSeq);\n\t\t\tconst id: string = serializedInterval.properties?.[reservedIntervalIdKey];\n\t\t\tconst localInterval = this.getIntervalById(id);\n\t\t\tif (localInterval) {\n\t\t\t\tthis.ackInterval(localInterval, op);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (!this.localCollection) {\n\t\t\tthrow new LoggingError(\"attachSequence must be called\");\n\t\t}\n\n\t\tthis.localCollection.ensureSerializedId(serializedInterval);\n\n\t\tconst interval: TInterval = this.localCollection.addInterval(\n\t\t\tserializedInterval.start,\n\t\t\tserializedInterval.end,\n\t\t\tserializedInterval.intervalType,\n\t\t\tserializedInterval.properties,\n\t\t\top,\n\t\t);\n\n\t\tif (interval) {\n\t\t\tif (this.onDeserialize) {\n\t\t\t\tthis.onDeserialize(interval);\n\t\t\t}\n\t\t}\n\n\t\tthis.emit(\"addInterval\", interval, local, op);\n\n\t\treturn interval;\n\t}\n\n\t/** @internal */\n\tpublic ackDelete(\n\t\tserializedInterval: ISerializedInterval,\n\t\tlocal: boolean,\n\t\top: ISequencedDocumentMessage,\n\t): void {\n\t\tif (local) {\n\t\t\t// Local ops were applied when the message was created and there's no \"pending delete\"\n\t\t\t// state to bookkeep: remote operation application takes into account possibility of\n\t\t\t// locally deleted interval whenever a lookup happens.\n\t\t\treturn;\n\t\t}\n\n\t\tif (!this.localCollection) {\n\t\t\tthrow new LoggingError(\"attach must be called prior to deleting intervals\");\n\t\t}\n\n\t\tconst id = this.localCollection.ensureSerializedId(serializedInterval);\n\t\tconst interval = this.localCollection.idIntervalIndex.getIntervalById(id);\n\t\tif (interval) {\n\t\t\tthis.deleteExistingInterval(interval, local, op);\n\t\t}\n\t}\n\n\t/**\n\t * @internal\n\t */\n\tpublic serializeInternal(): ISerializedIntervalCollectionV2 {\n\t\tif (!this.localCollection) {\n\t\t\tthrow new LoggingError(\"attachSequence must be called\");\n\t\t}\n\n\t\treturn this.localCollection.serialize();\n\t}\n\n\t/**\n\t * @returns an iterator over all intervals in this collection.\n\t */\n\tpublic [Symbol.iterator](): IntervalCollectionIterator<TInterval> {\n\t\tconst iterator = new IntervalCollectionIterator<TInterval>(this);\n\t\treturn iterator;\n\t}\n\n\t/**\n\t * @returns a forward iterator over all intervals in this collection with start point equal to `startPosition`.\n\t */\n\tpublic CreateForwardIteratorWithStartPosition(\n\t\tstartPosition: number,\n\t): IntervalCollectionIterator<TInterval> {\n\t\tconst iterator = new IntervalCollectionIterator<TInterval>(this, true, startPosition);\n\t\treturn iterator;\n\t}\n\n\t/**\n\t * @returns a backward iterator over all intervals in this collection with start point equal to `startPosition`.\n\t */\n\tpublic CreateBackwardIteratorWithStartPosition(\n\t\tstartPosition: number,\n\t): IntervalCollectionIterator<TInterval> {\n\t\tconst iterator = new IntervalCollectionIterator<TInterval>(this, false, startPosition);\n\t\treturn iterator;\n\t}\n\n\t/**\n\t * @returns a forward iterator over all intervals in this collection with end point equal to `endPosition`.\n\t */\n\tpublic CreateForwardIteratorWithEndPosition(\n\t\tendPosition: number,\n\t): IntervalCollectionIterator<TInterval> {\n\t\tconst iterator = new IntervalCollectionIterator<TInterval>(\n\t\t\tthis,\n\t\t\ttrue,\n\t\t\tundefined,\n\t\t\tendPosition,\n\t\t);\n\t\treturn iterator;\n\t}\n\n\t/**\n\t * @returns a backward iterator over all intervals in this collection with end point equal to `endPosition`.\n\t */\n\tpublic CreateBackwardIteratorWithEndPosition(\n\t\tendPosition: number,\n\t): IntervalCollectionIterator<TInterval> {\n\t\tconst iterator = new IntervalCollectionIterator<TInterval>(\n\t\t\tthis,\n\t\t\tfalse,\n\t\t\tundefined,\n\t\t\tendPosition,\n\t\t);\n\t\treturn iterator;\n\t}\n\n\t/**\n\t * Gathers iteration results that optionally match a start/end criteria into the provided array.\n\t * @param results - Array to gather the results into. In lieu of a return value, this array will be populated with\n\t * intervals matching the query upon edit.\n\t * @param iteratesForward - whether or not iteration should be in the forward direction\n\t * @param start - If provided, only match intervals whose start point is equal to `start`.\n\t * @param end - If provided, only match intervals whose end point is equal to `end`.\n\t */\n\tpublic gatherIterationResults(\n\t\tresults: TInterval[],\n\t\titeratesForward: boolean,\n\t\tstart?: number,\n\t\tend?: number,\n\t) {\n\t\tif (!this.localCollection) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.localCollection.overlappingIntervalsIndex.gatherIterationResults(\n\t\t\tresults,\n\t\t\titeratesForward,\n\t\t\tstart,\n\t\t\tend,\n\t\t);\n\t}\n\n\t/**\n\t * @returns an array of all intervals in this collection that overlap with the interval\n\t * `[startPosition, endPosition]`.\n\t */\n\tpublic findOverlappingIntervals(startPosition: number, endPosition: number): TInterval[] {\n\t\tif (!this.localCollection) {\n\t\t\tthrow new LoggingError(\"attachSequence must be called\");\n\t\t}\n\n\t\treturn this.localCollection.overlappingIntervalsIndex.findOverlappingIntervals(\n\t\t\tstartPosition,\n\t\t\tendPosition,\n\t\t);\n\t}\n\n\t/**\n\t * Applies a function to each interval in this collection.\n\t */\n\tpublic map(fn: (interval: TInterval) => void) {\n\t\tif (!this.localCollection) {\n\t\t\tthrow new LoggingError(\"attachSequence must be called\");\n\t\t}\n\n\t\tfor (const interval of this.localCollection.idIntervalIndex) {\n\t\t\tfn(interval);\n\t\t}\n\t}\n\n\tpublic previousInterval(pos: number): TInterval | undefined {\n\t\tif (!this.localCollection) {\n\t\t\tthrow new LoggingError(\"attachSequence must be called\");\n\t\t}\n\n\t\treturn this.localCollection.endIntervalIndex.previousInterval(pos);\n\t}\n\n\tpublic nextInterval(pos: number): TInterval | undefined {\n\t\tif (!this.localCollection) {\n\t\t\tthrow new LoggingError(\"attachSequence must be called\");\n\t\t}\n\n\t\treturn this.localCollection.endIntervalIndex.nextInterval(pos);\n\t}\n}\n\n/**\n * Information that identifies an interval within a `Sequence`.\n */\nexport interface IntervalLocator {\n\t/**\n\t * Label for the collection the interval is a part of\n\t */\n\tlabel: string;\n\t/**\n\t * Interval within that collection\n\t */\n\tinterval: SequenceInterval;\n}\n\n/**\n * Returns an object that can be used to find the interval a given LocalReferencePosition belongs to.\n * @returns undefined if the reference position is not the endpoint of any interval (e.g. it was created\n * on the merge tree directly by app code), otherwise an {@link IntervalLocator} for the interval this\n * endpoint is a part of.\n */\nexport function intervalLocatorFromEndpoint(\n\tpotentialEndpoint: LocalReferencePosition,\n): IntervalLocator | undefined {\n\tconst { interval, [reservedRangeLabelsKey]: collectionNameArray } =\n\t\tpotentialEndpoint.properties ?? {};\n\treturn interval && collectionNameArray?.length === 1\n\t\t? { label: collectionNameArray[0], interval }\n\t\t: undefined;\n}\n"]}