@fluidframework/sequence 2.0.0-internal.3.0.2 → 2.0.0-internal.3.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.
Files changed (94) hide show
  1. package/.eslintrc.js +9 -12
  2. package/.mocharc.js +2 -2
  3. package/.vscode/launch.json +15 -14
  4. package/README.md +188 -179
  5. package/api-extractor.json +2 -2
  6. package/dist/defaultMap.d.ts.map +1 -1
  7. package/dist/defaultMap.js +5 -4
  8. package/dist/defaultMap.js.map +1 -1
  9. package/dist/defaultMapInterfaces.d.ts.map +1 -1
  10. package/dist/defaultMapInterfaces.js.map +1 -1
  11. package/dist/index.d.ts +2 -2
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js.map +1 -1
  14. package/dist/intervalCollection.d.ts.map +1 -1
  15. package/dist/intervalCollection.js +50 -36
  16. package/dist/intervalCollection.js.map +1 -1
  17. package/dist/intervalTree.d.ts.map +1 -1
  18. package/dist/intervalTree.js.map +1 -1
  19. package/dist/localValues.d.ts.map +1 -1
  20. package/dist/localValues.js.map +1 -1
  21. package/dist/packageVersion.d.ts +1 -1
  22. package/dist/packageVersion.js +1 -1
  23. package/dist/packageVersion.js.map +1 -1
  24. package/dist/sequence.d.ts +1 -1
  25. package/dist/sequence.d.ts.map +1 -1
  26. package/dist/sequence.js +13 -17
  27. package/dist/sequence.js.map +1 -1
  28. package/dist/sequenceDeltaEvent.d.ts.map +1 -1
  29. package/dist/sequenceDeltaEvent.js.map +1 -1
  30. package/dist/sequenceFactory.d.ts.map +1 -1
  31. package/dist/sequenceFactory.js.map +1 -1
  32. package/dist/sharedIntervalCollection.d.ts.map +1 -1
  33. package/dist/sharedIntervalCollection.js.map +1 -1
  34. package/dist/sharedSequence.d.ts.map +1 -1
  35. package/dist/sharedSequence.js +3 -3
  36. package/dist/sharedSequence.js.map +1 -1
  37. package/dist/sharedString.d.ts.map +1 -1
  38. package/dist/sharedString.js +5 -4
  39. package/dist/sharedString.js.map +1 -1
  40. package/lib/defaultMap.d.ts.map +1 -1
  41. package/lib/defaultMap.js +6 -5
  42. package/lib/defaultMap.js.map +1 -1
  43. package/lib/defaultMapInterfaces.d.ts.map +1 -1
  44. package/lib/defaultMapInterfaces.js.map +1 -1
  45. package/lib/index.d.ts +2 -2
  46. package/lib/index.d.ts.map +1 -1
  47. package/lib/index.js +2 -2
  48. package/lib/index.js.map +1 -1
  49. package/lib/intervalCollection.d.ts.map +1 -1
  50. package/lib/intervalCollection.js +50 -36
  51. package/lib/intervalCollection.js.map +1 -1
  52. package/lib/intervalTree.d.ts.map +1 -1
  53. package/lib/intervalTree.js.map +1 -1
  54. package/lib/localValues.d.ts.map +1 -1
  55. package/lib/localValues.js +1 -1
  56. package/lib/localValues.js.map +1 -1
  57. package/lib/packageVersion.d.ts +1 -1
  58. package/lib/packageVersion.js +1 -1
  59. package/lib/packageVersion.js.map +1 -1
  60. package/lib/sequence.d.ts +1 -1
  61. package/lib/sequence.d.ts.map +1 -1
  62. package/lib/sequence.js +15 -19
  63. package/lib/sequence.js.map +1 -1
  64. package/lib/sequenceDeltaEvent.d.ts.map +1 -1
  65. package/lib/sequenceDeltaEvent.js.map +1 -1
  66. package/lib/sequenceFactory.d.ts.map +1 -1
  67. package/lib/sequenceFactory.js +1 -1
  68. package/lib/sequenceFactory.js.map +1 -1
  69. package/lib/sharedIntervalCollection.d.ts.map +1 -1
  70. package/lib/sharedIntervalCollection.js.map +1 -1
  71. package/lib/sharedSequence.d.ts.map +1 -1
  72. package/lib/sharedSequence.js +4 -4
  73. package/lib/sharedSequence.js.map +1 -1
  74. package/lib/sharedString.d.ts.map +1 -1
  75. package/lib/sharedString.js +5 -4
  76. package/lib/sharedString.js.map +1 -1
  77. package/package.json +55 -55
  78. package/prettier.config.cjs +1 -1
  79. package/src/defaultMap.ts +406 -405
  80. package/src/defaultMapInterfaces.ts +120 -115
  81. package/src/index.ts +27 -17
  82. package/src/intervalCollection.ts +2198 -1997
  83. package/src/intervalTree.ts +139 -139
  84. package/src/localValues.ts +64 -73
  85. package/src/packageVersion.ts +1 -1
  86. package/src/sequence.ts +739 -694
  87. package/src/sequenceDeltaEvent.ts +143 -137
  88. package/src/sequenceFactory.ts +48 -46
  89. package/src/sharedIntervalCollection.ts +150 -136
  90. package/src/sharedSequence.ts +165 -160
  91. package/src/sharedString.ts +385 -343
  92. package/tsconfig.esnext.json +6 -6
  93. package/tsconfig.json +8 -12
  94. package/.editorconfig +0 -7
@@ -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;IACpB,mDAAY,CAAA;IACZ,+CAAU,CAAA;IAEV;;;;;OAKG;IACH,iEAAmB,CAAA;IAEnB;;;OAGG;IACH,yDAAe,CAAA;AACnB,CAAC,EAjBW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAiBvB;AAsDD;;;GAGG;AACH,SAAS,kBAAkB,CAAC,QAAsC,EAAE,KAAc;IAC9E,OAAO;QACH,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;KACpE,CAAC;AACN,CAAC;AAED;;;GAGG;AACH,SAAS,gBAAgB,CAAC,QAA6B;IACnD,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,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,EAAE,CAAC,CAAC;IACjC,CAAC;IAEM,gBAAgB,CAAC,GAAW;QAC/B,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;YACvB,MAAM,IAAI,8BAAY,CAAC,+BAA+B,CAAC,CAAC;SAC3D;QAED,OAAO,IAAI,CAAC,eAAe,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACtD,CAAC;IAEM,YAAY,CAAC,GAAW;QAC3B,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;YACvB,MAAM,IAAI,8BAAY,CAAC,+BAA+B,CAAC,CAAC;SAC3D;QAED,OAAO,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;IAClD,CAAC;CACJ;AAlzBD,gDAkzBC;AAgBD;;;;;GAKG;AACH,SAAgB,2BAA2B,CAAC,iBAAyC;;IACjF,MAAM,EACF,QAAQ,EACR,CAAC,mCAAsB,CAAC,EAAE,mBAAmB,GAChD,GAAG,MAAA,iBAAiB,CAAC,UAAU,mCAAI,EAAE,CAAC;IACvC,OAAO,CAAC,QAAQ,IAAI,CAAA,mBAAmB,aAAnB,mBAAmB,uBAAnB,mBAAmB,CAAE,MAAM,MAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,mBAAmB,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AACrH,CAAC;AAND,kEAMC","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 addProperties,\n Client,\n compareReferencePositions,\n ConflictAction,\n createMap,\n ICombiningOp,\n ISegment,\n MergeTreeDeltaType,\n minReferencePosition,\n PropertiesManager,\n PropertySet,\n RedBlackTree,\n LocalReferencePosition,\n ReferenceType,\n refTypeIncludesFlag,\n reservedRangeLabelsKey,\n UnassignedSequenceNumber,\n maxReferencePosition,\n createDetachedLocalReferencePosition,\n DetachedReferencePosition,\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 IMapMessageLocalMetadata,\n IValueFactory,\n IValueOpEmitter,\n IValueOperation,\n IValueType,\n IValueTypeOperationValue,\n} from \"./defaultMapInterfaces\";\nimport { IInterval, IntervalConflictResolver, IntervalTree, IntervalNode } from \"./intervalTree\";\n\nconst reservedIntervalIdKey = \"intervalId\";\n\nexport enum IntervalType {\n Simple = 0x0,\n Nest = 0x1,\n\n /**\n * SlideOnRemove indicates that the ends of the interval will slide if the segment\n * they reference is removed and acked.\n * See `packages\\dds\\merge-tree\\REFERENCEPOSITIONS.md` for details\n * SlideOnRemove is the default interval behavior and does not need to be specified.\n */\n SlideOnRemove = 0x2, // SlideOnRemove is default behavior - all intervals are SlideOnRemove\n\n /**\n * A temporary interval, used internally\n * @internal\n */\n Transient = 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 /**\n * Sequence number at which `start` and `end` should be interpreted\n *\n * @remarks - It's unclear that this is necessary to store here.\n * This should just be the refSeq on the op that modified the interval, which should be available via other means.\n * At the time of writing, it's not plumbed through to the reconnect/rebase code, however, which does need it.\n */\n sequenceNumber: number;\n /** Start position of the interval (inclusive) */\n start: number;\n /** End position of the interval (inclusive) */\n end: number;\n /** Interval type to create */\n intervalType: IntervalType;\n /** Any properties the interval has */\n properties?: 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 =\n Omit<ISerializedInterval, \"start\" | \"end\" | \"properties\">\n & Partial<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 label: string;\n version: 2;\n intervals: 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(interval: CompressedSerializedInterval, label?: string): ISerializedInterval {\n return {\n start: interval[0],\n end: interval[1],\n sequenceNumber: interval[2],\n intervalType: interval[3],\n properties: { ...interval[4], [reservedRangeLabelsKey]: [label] },\n };\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 const { start, end, sequenceNumber, intervalType, properties } = interval;\n\n return [\n start,\n end,\n sequenceNumber,\n intervalType,\n // remove the `referenceRangeLabels` property as it is already stored\n // in the `label` field of the summary\n { ...properties, [reservedRangeLabelsKey]: undefined },\n ];\n}\n\nexport interface ISerializableInterval extends IInterval {\n /** Serializable bag of properties associated with the interval. */\n properties: PropertySet;\n /** @internal */\n propertyManager: PropertiesManager;\n /** @internal */\n serialize(): ISerializedInterval;\n /** @internal */\n addProperties(props: PropertySet, collaborating?: boolean, seq?: number):\n PropertySet | undefined;\n /**\n * Gets the id associated with this interval.\n * When the interval is used as part of an interval collection, this id can be used to modify or remove the\n * interval.\n * @remarks - This signature includes `undefined` strictly for backwards-compatibility reasons, as older versions\n * of Fluid didn't always write interval ids.\n */\n getIntervalId(): string | undefined;\n}\n\nexport interface IIntervalHelpers<TInterval extends ISerializableInterval> {\n compareEnds(a: TInterval, b: TInterval): number;\n /**\n *\n * @param label - label of the interval collection this interval is being added to. This parameter is\n * irrelevant for transient intervals.\n * @param start - numerical start position of the interval\n * @param end - numberical end position of the interval\n * @param client - client creating the interval\n * @param intervalType - Type of interval to create. Default is SlideOnRemove\n * @param op - If this create came from a remote client, op that created it. Default is undefined (i.e. local)\n * @param fromSnapshot - If this create came from loading a snapshot. Default is false.\n */\n create(\n label: string,\n start: number | undefined,\n end: number | undefined,\n client: Client | undefined,\n intervalType: IntervalType,\n op?: ISequencedDocumentMessage,\n fromSnapshot?: boolean,\n ): TInterval;\n}\n\n/**\n * Serializable interval whose endpoints are plain-old numbers.\n */\nexport class Interval implements ISerializableInterval {\n /**\n * {@inheritDoc ISerializableInterval.properties}\n */\n public properties: PropertySet;\n /** @internal */\n public auxProps: PropertySet[] | undefined;\n /**\n * {@inheritDoc ISerializableInterval.propertyManager}\n */\n public propertyManager: PropertiesManager;\n constructor(\n public start: number,\n public end: number,\n props?: PropertySet,\n ) {\n this.propertyManager = new PropertiesManager();\n this.properties = {};\n\n if (props) {\n this.addProperties(props);\n }\n }\n\n /**\n * {@inheritDoc ISerializableInterval.getIntervalId}\n */\n public getIntervalId(): string | undefined {\n const id = this.properties?.[reservedIntervalIdKey];\n if (id === undefined) {\n return undefined;\n }\n return `${id}`;\n }\n\n /**\n * @returns an array containing any auxiliary property sets added with `addPropertySet`.\n */\n public getAdditionalPropertySets(): PropertySet[] {\n return this.auxProps ?? [];\n }\n\n /**\n * Adds an auxiliary set of properties to this interval.\n * These properties can be recovered using `getAdditionalPropertySets`\n * @param props - set of properties to add\n * @remarks - This gets called as part of the default conflict resolver for `IntervalCollection<Interval>`\n * (i.e. non-sequence-based interval collections). However, the additional properties don't get serialized.\n * This functionality seems half-baked.\n */\n public addPropertySet(props: PropertySet) {\n if (this.auxProps === undefined) {\n this.auxProps = [];\n }\n this.auxProps.push(props);\n }\n\n /**\n * {@inheritDoc ISerializableInterval.serialize}\n * @internal\n */\n public serialize(): ISerializedInterval {\n const serializedInterval: ISerializedInterval = {\n end: this.end,\n intervalType: 0,\n sequenceNumber: 0,\n start: this.start,\n };\n if (this.properties) {\n serializedInterval.properties = this.properties;\n }\n return serializedInterval;\n }\n\n /**\n * {@inheritDoc IInterval.clone}\n */\n public clone() {\n return new Interval(this.start, this.end, this.properties);\n }\n\n /**\n * {@inheritDoc IInterval.compare}\n */\n public compare(b: Interval) {\n const startResult = this.compareStart(b);\n if (startResult === 0) {\n const endResult = this.compareEnd(b);\n if (endResult === 0) {\n const thisId = this.getIntervalId();\n if (thisId) {\n const bId = b.getIntervalId();\n if (bId) {\n return thisId > bId ? 1 : thisId < bId ? -1 : 0;\n }\n return 0;\n }\n return 0;\n } else {\n return endResult;\n }\n } else {\n return startResult;\n }\n }\n\n /**\n * {@inheritDoc IInterval.compareStart}\n */\n public compareStart(b: Interval) {\n return this.start - b.start;\n }\n\n /**\n * {@inheritDoc IInterval.compareEnd}\n */\n public compareEnd(b: Interval) {\n return this.end - b.end;\n }\n\n /**\n * {@inheritDoc IInterval.overlaps}\n */\n public overlaps(b: Interval) {\n const result = (this.start <= b.end) &&\n (this.end >= b.start);\n return result;\n }\n\n /**\n * {@inheritDoc IInterval.union}\n */\n public union(b: Interval) {\n return new Interval(Math.min(this.start, b.start),\n Math.max(this.end, b.end), this.properties);\n }\n\n public getProperties() {\n return this.properties;\n }\n\n /**\n * {@inheritDoc ISerializableInterval.addProperties}\n */\n public addProperties(\n newProps: PropertySet,\n collaborating: boolean = false,\n seq?: number,\n op?: ICombiningOp,\n ): PropertySet | undefined {\n if (newProps) {\n this.initializeProperties();\n return this.propertyManager.addProperties(this.properties, newProps, op, seq, collaborating);\n }\n }\n\n /**\n * {@inheritDoc IInterval.modify}\n */\n public modify(label: string, start: number, end: number, op?: ISequencedDocumentMessage) {\n const startPos = start ?? this.start;\n const endPos = end ?? this.end;\n if (this.start === startPos && this.end === endPos) {\n // Return undefined to indicate that no change is necessary.\n return;\n }\n const newInterval = new Interval(startPos, endPos);\n if (this.properties) {\n newInterval.initializeProperties();\n this.propertyManager.copyTo(this.properties, newInterval.properties, newInterval.propertyManager);\n }\n return newInterval;\n }\n\n private initializeProperties(): void {\n if (!this.propertyManager) {\n this.propertyManager = new PropertiesManager();\n }\n if (!this.properties) {\n this.properties = createMap<any>();\n }\n }\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 */\nexport class SequenceInterval implements ISerializableInterval {\n /**\n * {@inheritDoc ISerializableInterval.properties}\n */\n public properties: PropertySet;\n /**\n * {@inheritDoc ISerializableInterval.propertyManager}\n */\n public propertyManager: PropertiesManager;\n\n constructor(\n private readonly client: Client,\n /**\n * Start endpoint of this interval.\n * @remarks - This endpoint can be resolved into a character position using the SharedString it's a part of.\n */\n public start: LocalReferencePosition,\n /**\n * End endpoint of this interval.\n * @remarks - This endpoint can be resolved into a character position using the SharedString it's a part of.\n */\n public end: LocalReferencePosition,\n public intervalType: IntervalType,\n props?: PropertySet,\n ) {\n this.propertyManager = new PropertiesManager();\n this.properties = {};\n\n if (props) {\n this.addProperties(props);\n }\n }\n\n private callbacks?: Record<\"beforePositionChange\" | \"afterPositionChange\", () => void>;\n\n /**\n * Subscribes to position change events on this interval if there are no current listeners.\n * @internal\n */\n public addPositionChangeListeners(beforePositionChange: () => void, afterPositionChange: () => void): void {\n if (this.callbacks === undefined) {\n this.callbacks = {\n beforePositionChange,\n afterPositionChange,\n };\n\n const startCbs = this.start.callbacks ??= {};\n const endCbs = this.end.callbacks ??= {};\n startCbs.beforeSlide = endCbs.beforeSlide = beforePositionChange;\n startCbs.afterSlide = endCbs.afterSlide = afterPositionChange;\n }\n }\n\n /**\n * Removes the currently subscribed position change listeners.\n * @internal\n */\n public removePositionChangeListeners(): void {\n if (this.callbacks) {\n this.callbacks = undefined;\n this.start.callbacks = undefined;\n this.end.callbacks = undefined;\n }\n }\n\n /**\n * {@inheritDoc ISerializableInterval.serialize}\n * @internal\n */\n public serialize(): ISerializedInterval {\n const startPosition = this.client.localReferencePositionToPosition(this.start);\n const endPosition = this.client.localReferencePositionToPosition(this.end);\n const serializedInterval: ISerializedInterval = {\n end: endPosition,\n intervalType: this.intervalType,\n sequenceNumber: this.client.getCurrentSeq(),\n start: startPosition,\n };\n\n if (this.properties) {\n serializedInterval.properties = this.properties;\n }\n\n return serializedInterval;\n }\n\n /**\n * {@inheritDoc IInterval.clone}\n */\n public clone() {\n return new SequenceInterval(this.client, this.start, this.end, this.intervalType, this.properties);\n }\n\n /**\n * {@inheritDoc IInterval.compare}\n */\n public compare(b: SequenceInterval) {\n const startResult = this.compareStart(b);\n if (startResult === 0) {\n const endResult = this.compareEnd(b);\n if (endResult === 0) {\n const thisId = this.getIntervalId();\n if (thisId) {\n const bId = b.getIntervalId();\n if (bId) {\n return thisId > bId ? 1 : thisId < bId ? -1 : 0;\n }\n return 0;\n }\n return 0;\n } else {\n return endResult;\n }\n } else {\n return startResult;\n }\n }\n\n /**\n * {@inheritDoc IInterval.compareStart}\n */\n public compareStart(b: SequenceInterval) {\n return compareReferencePositions(this.start, b.start);\n }\n\n /**\n * {@inheritDoc IInterval.compareEnd}\n */\n public compareEnd(b: SequenceInterval) {\n return compareReferencePositions(this.end, b.end);\n }\n\n /**\n * {@inheritDoc IInterval.overlaps}\n */\n public overlaps(b: SequenceInterval) {\n const result = (compareReferencePositions(this.start, b.end) <= 0) &&\n (compareReferencePositions(this.end, b.start) >= 0);\n return result;\n }\n\n /**\n * {@inheritDoc ISerializableInterval.getIntervalId}\n */\n public getIntervalId(): string | undefined {\n const id = this.properties?.[reservedIntervalIdKey];\n if (id === undefined) {\n return undefined;\n }\n return `${id}`;\n }\n\n /**\n * {@inheritDoc IInterval.union}\n */\n public union(b: SequenceInterval) {\n return new SequenceInterval(this.client, minReferencePosition(this.start, b.start),\n maxReferencePosition(this.end, b.end), this.intervalType);\n }\n\n /**\n * {@inheritDoc ISerializableInterval.addProperties}\n */\n public addProperties(\n newProps: PropertySet,\n collab: boolean = false,\n seq?: number,\n op?: ICombiningOp,\n ): PropertySet | undefined {\n this.initializeProperties();\n return this.propertyManager.addProperties(this.properties, newProps, op, seq, collab);\n }\n\n /**\n * @returns whether this interval overlaps two numerical positions.\n * @remarks - this is currently strict overlap, which doesn't align with the endpoint treatment of`.overlaps()`\n */\n public overlapsPos(bstart: number, bend: number) {\n const startPos = this.client.localReferencePositionToPosition(this.start);\n const endPos = this.client.localReferencePositionToPosition(this.end);\n return (endPos > bstart) && (startPos < bend);\n }\n\n /**\n * {@inheritDoc IInterval.modify}\n */\n public modify(label: string, start: number, end: number, op?: ISequencedDocumentMessage, localSeq?: number) {\n const getRefType = (baseType: ReferenceType): ReferenceType => {\n let refType = baseType;\n if (op === undefined) {\n refType &= ~ReferenceType.SlideOnRemove;\n refType |= ReferenceType.StayOnRemove;\n }\n return refType;\n };\n\n let startRef = this.start;\n if (start !== undefined) {\n startRef = createPositionReference(\n this.client, start, getRefType(this.start.refType), op, undefined, localSeq,\n );\n if (this.start.properties) {\n startRef.addProperties(this.start.properties);\n }\n }\n\n let endRef = this.end;\n if (end !== undefined) {\n endRef = createPositionReference(\n this.client, end, getRefType(this.end.refType), op, undefined, localSeq,\n );\n if (this.end.properties) {\n endRef.addProperties(this.end.properties);\n }\n }\n\n const newInterval = new SequenceInterval(this.client, startRef, endRef, this.intervalType);\n if (this.properties) {\n newInterval.initializeProperties();\n this.propertyManager.copyTo(this.properties, newInterval.properties, newInterval.propertyManager);\n }\n return newInterval;\n }\n\n private initializeProperties(): void {\n if (!this.propertyManager) {\n this.propertyManager = new PropertiesManager();\n }\n if (!this.properties) {\n this.properties = createMap<any>();\n }\n }\n}\n\nfunction createPositionReferenceFromSegoff(\n client: Client,\n segoff: { segment: ISegment | undefined; offset: number | undefined; },\n refType: ReferenceType,\n op?: ISequencedDocumentMessage,\n localSeq?: number): LocalReferencePosition {\n if (segoff.segment) {\n const ref = client.createLocalReferencePosition(segoff.segment, segoff.offset, refType, undefined);\n return ref;\n }\n\n // Creating references on detached segments is allowed for:\n // - Transient segments\n // - References coming from a remote client (location may have been concurrently removed)\n // - References being rebased to a new sequence number\n // (segment they originally referred to may have been removed with no suitable replacement)\n if (!op && !localSeq && !refTypeIncludesFlag(refType, ReferenceType.Transient)) {\n throw new UsageError(\"Non-transient references need segment\");\n }\n\n return createDetachedLocalReferencePosition(refType);\n}\n\nfunction createPositionReference(\n client: Client,\n pos: number,\n refType: ReferenceType,\n op?: ISequencedDocumentMessage,\n fromSnapshot?: boolean,\n localSeq?: number,\n): LocalReferencePosition {\n let segoff;\n if (op) {\n assert((refType & ReferenceType.SlideOnRemove) !== 0, 0x2f5 /* op create references must be SlideOnRemove */);\n segoff = client.getContainingSegment(pos, { referenceSequenceNumber: op.referenceSequenceNumber, clientId: op.clientId });\n segoff = client.getSlideToSegment(segoff);\n } else {\n assert((refType & ReferenceType.SlideOnRemove) === 0 || !!fromSnapshot,\n 0x2f6 /* SlideOnRemove references must be op created */);\n segoff = client.getContainingSegment(pos, undefined, localSeq);\n }\n return createPositionReferenceFromSegoff(client, segoff, refType, op, localSeq);\n}\n\nexport function createSequenceInterval(\n label: string,\n start: number,\n end: number,\n client: Client,\n intervalType: IntervalType,\n op?: ISequencedDocumentMessage,\n fromSnapshot?: boolean,\n): SequenceInterval {\n let beginRefType = ReferenceType.RangeBegin;\n let endRefType = ReferenceType.RangeEnd;\n if (intervalType === IntervalType.Transient) {\n beginRefType = ReferenceType.Transient;\n endRefType = ReferenceType.Transient;\n } else {\n if (intervalType === IntervalType.Nest) {\n beginRefType = ReferenceType.NestBegin;\n endRefType = ReferenceType.NestEnd;\n }\n // All non-transient interval references must eventually be SlideOnRemove\n // To ensure eventual consistency, they must start as StayOnRemove when\n // pending (created locally and creation op is not acked)\n if (op || fromSnapshot) {\n beginRefType |= ReferenceType.SlideOnRemove;\n endRefType |= ReferenceType.SlideOnRemove;\n } else {\n beginRefType |= ReferenceType.StayOnRemove;\n endRefType |= ReferenceType.StayOnRemove;\n }\n }\n\n const startLref = createPositionReference(client, start, beginRefType, op, fromSnapshot);\n const endLref = createPositionReference(client, end, endRefType, op, fromSnapshot);\n const rangeProp = {\n [reservedRangeLabelsKey]: [label],\n };\n startLref.addProperties(rangeProp);\n endLref.addProperties(rangeProp);\n\n const ival = new SequenceInterval(\n client,\n startLref,\n endLref,\n intervalType,\n rangeProp,\n );\n return ival;\n}\n\nexport function defaultIntervalConflictResolver(a: Interval, b: Interval) {\n a.addPropertySet(b.properties);\n return a;\n}\n\nexport function createIntervalIndex(conflict?: IntervalConflictResolver<Interval>) {\n const helpers: IIntervalHelpers<Interval> = {\n compareEnds: compareIntervalEnds,\n create: createInterval,\n };\n const lc = new LocalIntervalCollection<Interval>(undefined as any as Client, \"\", helpers);\n if (conflict) {\n lc.addConflictResolver(conflict);\n } else {\n lc.addConflictResolver(defaultIntervalConflictResolver);\n }\n return lc;\n}\n\nexport class LocalIntervalCollection<TInterval extends ISerializableInterval> {\n private readonly intervalTree = new IntervalTree<TInterval>();\n private readonly endIntervalTree: RedBlackTree<TInterval, TInterval>;\n private readonly intervalIdMap: Map<string, TInterval> = new Map();\n private conflictResolver: IntervalConflictResolver<TInterval> | undefined;\n private endConflictResolver: ConflictAction<TInterval, TInterval> | undefined;\n\n private static readonly legacyIdPrefix = \"legacy\";\n\n constructor(\n private readonly client: Client,\n private readonly label: string,\n private readonly helpers: IIntervalHelpers<TInterval>,\n /** Callback invoked each time one of the endpoints of an interval slides. */\n private readonly onPositionChange?: (interval: TInterval, previousInterval: TInterval) => void,\n ) {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.endIntervalTree = new RedBlackTree<TInterval, TInterval>(helpers.compareEnds);\n }\n\n public addConflictResolver(conflictResolver: IntervalConflictResolver<TInterval>) {\n this.conflictResolver = conflictResolver;\n this.endConflictResolver =\n (key: TInterval, currentKey: TInterval) => {\n const ival = conflictResolver(key, currentKey);\n return {\n data: ival,\n key: ival,\n };\n };\n }\n\n public map(fn: (interval: TInterval) => void) {\n this.intervalTree.map(fn);\n }\n\n public createLegacyId(start: number, end: number): string {\n // Create a non-unique ID based on start and end to be used on intervals that come from legacy clients\n // without ID's.\n return `${LocalIntervalCollection.legacyIdPrefix}${start}-${end}`;\n }\n\n /**\n * Validates that a serialized interval has the ID property. Creates an ID\n * if one does not already exist\n *\n * @param serializedInterval - The interval to be checked\n * @returns The interval's existing or newly created id\n */\n public ensureSerializedId(serializedInterval: ISerializedInterval): string {\n let id: string | undefined = serializedInterval.properties?.[reservedIntervalIdKey];\n if (id === undefined) {\n // An interval came over the wire without an ID, so create a non-unique one based on start/end.\n // This will allow all clients to refer to this interval consistently.\n id = this.createLegacyId(serializedInterval.start, serializedInterval.end);\n const newProps = {\n [reservedIntervalIdKey]: id,\n };\n serializedInterval.properties = addProperties(serializedInterval.properties, newProps);\n }\n // Make the ID immutable for safety's sake.\n Object.defineProperty(serializedInterval.properties, reservedIntervalIdKey, {\n configurable: false,\n enumerable: true,\n writable: false,\n });\n\n return id;\n }\n\n public mapUntil(fn: (interval: TInterval) => boolean) {\n this.intervalTree.mapUntil(fn);\n }\n\n public gatherIterationResults(\n results: TInterval[],\n iteratesForward: boolean,\n start?: number,\n end?: number) {\n if (this.intervalTree.intervals.isEmpty()) {\n return;\n }\n\n if (start === undefined && end === undefined) {\n // No start/end provided. Gather the whole tree in the specified order.\n if (iteratesForward) {\n this.intervalTree.map((interval: TInterval) => {\n results.push(interval);\n });\n } else {\n this.intervalTree.mapBackward((interval: TInterval) => {\n results.push(interval);\n });\n }\n } else {\n const transientInterval: TInterval = this.helpers.create(\n \"transient\",\n start,\n end,\n this.client,\n IntervalType.Transient,\n );\n\n if (start === undefined) {\n // Only end position provided. Since the tree is not sorted by end position,\n // walk the whole tree in the specified order, gathering intervals that match the end.\n if (iteratesForward) {\n this.intervalTree.map((interval: TInterval) => {\n if (transientInterval.compareEnd(interval) === 0) {\n results.push(interval);\n }\n });\n } else {\n this.intervalTree.mapBackward((interval: TInterval) => {\n if (transientInterval.compareEnd(interval) === 0) {\n results.push(interval);\n }\n });\n }\n } else {\n // Start and (possibly) end provided. Walk the subtrees that may contain\n // this start position.\n const compareFn =\n end === undefined ?\n (node: IntervalNode<TInterval>) => {\n return transientInterval.compareStart(node.key);\n } :\n (node: IntervalNode<TInterval>) => {\n return transientInterval.compare(node.key);\n };\n const continueLeftFn = (cmpResult: number) => cmpResult <= 0;\n const continueRightFn = (cmpResult: number) => cmpResult >= 0;\n const actionFn = (node: IntervalNode<TInterval>) => {\n results.push(node.key);\n };\n\n if (iteratesForward) {\n this.intervalTree.intervals.walkExactMatchesForward(\n compareFn, actionFn, continueLeftFn, continueRightFn,\n );\n } else {\n this.intervalTree.intervals.walkExactMatchesBackward(\n compareFn, actionFn, continueLeftFn, continueRightFn,\n );\n }\n }\n }\n }\n\n /**\n * @returns an array of all intervals contained in this collection that overlap the range\n * `[startPosition, endPosition]`.\n */\n public findOverlappingIntervals(startPosition: number, endPosition: number) {\n if (endPosition < startPosition || this.intervalTree.intervals.isEmpty()) {\n return [];\n }\n const transientInterval =\n this.helpers.create(\n \"transient\",\n startPosition,\n endPosition,\n this.client,\n IntervalType.Transient);\n\n const overlappingIntervalNodes = this.intervalTree.match(transientInterval);\n return overlappingIntervalNodes.map((node) => node.key);\n }\n\n public previousInterval(pos: number) {\n const transientInterval = this.helpers.create(\n \"transient\", pos, pos, this.client, IntervalType.Transient);\n const rbNode = this.endIntervalTree.floor(transientInterval);\n if (rbNode) {\n return rbNode.data;\n }\n }\n\n public nextInterval(pos: number) {\n const transientInterval = this.helpers.create(\n \"transient\", pos, pos, this.client, IntervalType.Transient);\n const rbNode = this.endIntervalTree.ceil(transientInterval);\n if (rbNode) {\n return rbNode.data;\n }\n }\n\n public removeInterval(startPosition: number, endPosition: number) {\n const transientInterval = this.helpers.create(\n \"transient\", startPosition, endPosition, this.client, IntervalType.Transient);\n this.intervalTree.remove(transientInterval);\n this.endIntervalTree.remove(transientInterval);\n return transientInterval;\n }\n\n private removeIntervalFromIndex(interval: TInterval) {\n this.intervalTree.removeExisting(interval);\n this.endIntervalTree.remove(interval);\n\n const id = interval.getIntervalId();\n\n assert(id !== undefined, 0x311 /* expected id to exist on interval */);\n\n this.intervalIdMap.delete(id);\n }\n\n public removeExistingInterval(interval: TInterval) {\n this.removeIntervalFromIndex(interval);\n this.removeIntervalListeners(interval);\n }\n\n public createInterval(\n start: number,\n end: number,\n intervalType: IntervalType,\n op?: ISequencedDocumentMessage): TInterval {\n return this.helpers.create(this.label, start, end, this.client, intervalType, op);\n }\n\n public addInterval(\n start: number,\n end: number,\n intervalType: IntervalType,\n props?: PropertySet,\n op?: ISequencedDocumentMessage) {\n const interval: TInterval = this.createInterval(start, end, intervalType, op);\n if (interval) {\n if (!interval.properties) {\n interval.properties = createMap<any>();\n }\n\n if (props) {\n interval.addProperties(props);\n }\n interval.properties[reservedIntervalIdKey] ??= uuid();\n this.add(interval);\n }\n return interval;\n }\n\n private linkEndpointsToInterval(interval: TInterval): void {\n if (interval instanceof SequenceInterval) {\n interval.start.addProperties({ interval });\n interval.end.addProperties({ interval });\n }\n }\n\n private addIntervalToIndex(interval: TInterval) {\n const id = interval.getIntervalId();\n assert(id !== undefined, 0x2c0 /* \"ID must be created before adding interval to collection\" */);\n // Make the ID immutable.\n Object.defineProperty(interval.properties, reservedIntervalIdKey, {\n configurable: false,\n enumerable: true,\n writable: false,\n });\n this.intervalTree.put(interval, this.conflictResolver);\n this.endIntervalTree.put(interval, interval, this.endConflictResolver);\n this.intervalIdMap.set(id, interval);\n }\n\n public add(interval: TInterval): void {\n this.linkEndpointsToInterval(interval);\n this.addIntervalToIndex(interval);\n this.addIntervalListeners(interval);\n }\n\n public getIntervalById(id: string) {\n return this.intervalIdMap.get(id);\n }\n\n public changeInterval(\n interval: TInterval,\n start: number | undefined,\n end: number | undefined,\n op?: ISequencedDocumentMessage,\n localSeq?: number,\n ) {\n const newInterval = interval.modify(this.label, start, end, op, localSeq) as TInterval | undefined;\n if (newInterval) {\n this.removeExistingInterval(interval);\n this.add(newInterval);\n }\n return newInterval;\n }\n\n public serialize(): ISerializedIntervalCollectionV2 {\n const intervals = this.intervalTree.intervals.keys();\n return {\n label: this.label,\n intervals: intervals.map((interval) => compressInterval(interval.serialize())),\n version: 2,\n };\n }\n\n private addIntervalListeners(interval: TInterval) {\n const cloneRef = (ref: LocalReferencePosition) => {\n const segment = ref.getSegment();\n if (segment === undefined) {\n // Cloning is unnecessary: refs which have slid off the string entirely\n // never get slid back on. Creation code for refs doesn't accept undefined segment\n // either, so this must be special-cased.\n return ref;\n }\n\n return this.client.createLocalReferencePosition(\n segment,\n ref.getOffset(),\n ReferenceType.Transient,\n ref.properties,\n );\n };\n if (interval instanceof SequenceInterval) {\n let previousInterval: TInterval & SequenceInterval | undefined;\n let pendingChanges = 0;\n interval.addPositionChangeListeners(\n () => {\n pendingChanges++;\n // Note: both start and end can change and invoke beforeSlide on each endpoint before afterSlide.\n if (!previousInterval) {\n previousInterval = interval.clone() as TInterval & SequenceInterval;\n previousInterval.start = cloneRef(previousInterval.start);\n previousInterval.end = cloneRef(previousInterval.end);\n this.removeIntervalFromIndex(interval);\n }\n },\n () => {\n assert(previousInterval !== undefined, 0x3fa /* Invalid interleaving of before/after slide */);\n pendingChanges--;\n if (pendingChanges === 0) {\n this.addIntervalToIndex(interval);\n this.onPositionChange?.(interval, previousInterval);\n previousInterval = undefined;\n }\n },\n );\n }\n }\n\n private removeIntervalListeners(interval: TInterval) {\n if (interval instanceof SequenceInterval) {\n interval.removePositionChangeListeners();\n }\n }\n}\n\nexport const compareSequenceIntervalEnds = (a: SequenceInterval, b: SequenceInterval): number =>\n compareReferencePositions(a.end, b.end);\n\nclass SequenceIntervalCollectionFactory\n implements IValueFactory<IntervalCollection<SequenceInterval>> {\n public load(\n emitter: IValueOpEmitter,\n raw: ISerializedInterval[] | ISerializedIntervalCollectionV2 = [],\n ): IntervalCollection<SequenceInterval> {\n const helpers: IIntervalHelpers<SequenceInterval> = {\n compareEnds: compareSequenceIntervalEnds,\n create: createSequenceInterval,\n };\n return new IntervalCollection<SequenceInterval>(helpers, true, emitter, raw);\n }\n\n public store(value: IntervalCollection<SequenceInterval>): ISerializedInterval[] | ISerializedIntervalCollectionV2 {\n return value.serializeInternal();\n }\n}\n\nexport class SequenceIntervalCollectionValueType\n implements IValueType<IntervalCollection<SequenceInterval>> {\n public static Name = \"sharedStringIntervalCollection\";\n\n public get name(): string {\n return SequenceIntervalCollectionValueType.Name;\n }\n\n public get factory(): IValueFactory<IntervalCollection<SequenceInterval>> {\n return SequenceIntervalCollectionValueType._factory;\n }\n\n public get ops(): Map<string, IValueOperation<IntervalCollection<SequenceInterval>>> {\n return SequenceIntervalCollectionValueType._ops;\n }\n\n private static readonly _factory: IValueFactory<IntervalCollection<SequenceInterval>> =\n new SequenceIntervalCollectionFactory();\n\n private 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 const rangeProp: PropertySet = {};\n\n if (label && label.length > 0) {\n rangeProp[reservedRangeLabelsKey] = [label];\n }\n\n return new Interval(start, end, rangeProp);\n}\n\nclass IntervalCollectionFactory\n implements IValueFactory<IntervalCollection<Interval>> {\n public load(\n emitter: IValueOpEmitter,\n raw: ISerializedInterval[] | ISerializedIntervalCollectionV2 = [],\n ): IntervalCollection<Interval> {\n const helpers: IIntervalHelpers<Interval> = {\n compareEnds: compareIntervalEnds,\n create: createInterval,\n };\n const collection = new IntervalCollection<Interval>(helpers, false, emitter, raw);\n collection.attachGraph(undefined as any as Client, \"\");\n return collection;\n }\n\n public store(value: IntervalCollection<Interval>): ISerializedIntervalCollectionV2 {\n return value.serializeInternal();\n }\n}\n\nexport class IntervalCollectionValueType\n implements IValueType<IntervalCollection<Interval>> {\n public static Name = \"sharedIntervalCollection\";\n\n public get name(): string {\n return IntervalCollectionValueType.Name;\n }\n\n public get factory(): IValueFactory<IntervalCollection<Interval>> {\n return IntervalCollectionValueType._factory;\n }\n\n public get ops(): Map<string, IValueOperation<IntervalCollection<Interval>>> {\n return IntervalCollectionValueType._ops;\n }\n\n private static readonly _factory: IValueFactory<IntervalCollection<Interval>> =\n new IntervalCollectionFactory();\n private static readonly _ops = makeOpsMap<Interval>();\n}\n\nexport function makeOpsMap<T extends ISerializableInterval>(): Map<string, IValueOperation<IntervalCollection<T>>> {\n const rebase = (\n collection: IntervalCollection<T>,\n op: IValueTypeOperationValue,\n localOpMetadata: IMapMessageLocalMetadata,\n ) => {\n const { localSeq } = localOpMetadata;\n const rebasedValue = collection.rebaseLocalInterval(op.opName, op.value, localSeq);\n const rebasedOp = { ...op, value: rebasedValue };\n return { rebasedOp, rebasedLocalOpMetadata: localOpMetadata };\n };\n\n return new Map<string, IValueOperation<IntervalCollection<T>>>(\n [[\n \"add\",\n {\n process: (collection, params, local, op, localOpMetadata) => {\n // if params is undefined, the interval was deleted during\n // rebasing\n if (!params) {\n return;\n }\n assert(op !== undefined, 0x3fb /* op should exist here */);\n collection.ackAdd(params, local, op, localOpMetadata);\n },\n rebase,\n },\n ],\n [\n \"delete\",\n {\n process: (collection, params, local, op) => {\n assert(op !== undefined, 0x3fc /* op should exist here */);\n collection.ackDelete(params, local, op);\n },\n rebase: (collection, op, localOpMetadata) => {\n // Deletion of intervals is based on id, so requires no rebasing.\n return { rebasedOp: op, rebasedLocalOpMetadata: localOpMetadata };\n },\n },\n ],\n [\n \"change\",\n {\n process: (collection, params, local, op, localOpMetadata) => {\n // if params is undefined, the interval was deleted during\n // rebasing\n if (!params) {\n return;\n }\n assert(op !== undefined, 0x3fd /* op should exist here */);\n collection.ackChange(params, local, op, localOpMetadata);\n },\n rebase,\n },\n ]]);\n}\n\nexport type DeserializeCallback = (properties: PropertySet) => void;\n\nexport class IntervalCollectionIterator<TInterval extends ISerializableInterval>\n implements Iterator<TInterval> {\n private readonly results: TInterval[];\n private index: number;\n\n constructor(\n collection: IntervalCollection<TInterval>,\n iteratesForward: boolean = true,\n start?: number,\n end?: number) {\n this.results = [];\n this.index = 0;\n\n collection.gatherIterationResults(this.results, iteratesForward, start, end);\n }\n\n public next(): IteratorResult<TInterval> {\n if (this.index < this.results.length) {\n return {\n value: this.results[this.index++],\n done: false,\n };\n }\n\n return {\n value: undefined,\n done: true,\n };\n }\n}\n\n/**\n * Change events emitted by `IntervalCollection`s\n */\nexport interface IIntervalCollectionEvent<TInterval extends ISerializableInterval> extends IEvent {\n /**\n * This event is invoked whenever the endpoints of an interval may have changed.\n * This can happen on:\n * - local endpoint modification\n * - ack of a remote endpoint modification\n * - position change due to segment sliding (slides due to mergeTree segment deletion will always appear local)\n * The `interval` argument reflects the new values.\n * `previousInterval` contains transient `ReferencePosition`s at the same location as the interval's original\n * endpoints. These references should be used for position information only.\n * `local` reflects whether the change originated locally.\n * `op` is defined if and only if the server has acked this change.\n */\n (event: \"changeInterval\",\n listener: (\n interval: TInterval,\n previousInterval: TInterval,\n local: boolean,\n op: ISequencedDocumentMessage | undefined\n ) => void);\n /**\n * This event is invoked whenever an interval is added or removed from the collection.\n * `local` reflects whether the change originated locally.\n * `op` is defined if and only if the server has acked this change.\n */\n (event: \"addInterval\" | \"deleteInterval\",\n listener: (interval: TInterval, local: boolean, op: ISequencedDocumentMessage | undefined) => void);\n /**\n * This event is invoked whenever an interval's properties have changed.\n * `interval` reflects the state of the updated properties.\n * `propertyDeltas` is a map-like whose keys contain all values that were changed, and whose\n * values contain all previous values of the property set.\n * This object can be used directly in a call to `changeProperties` to revert the property change if desired.\n * `local` reflects whether the change originated locally.\n * `op` is defined if and only if the server has acked this change.\n */\n (event: \"propertyChanged\",\n listener: (\n interval: TInterval,\n propertyDeltas: PropertySet,\n local: boolean,\n op: ISequencedDocumentMessage | undefined\n ) => void);\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>\n extends TypedEventEmitter<IIntervalCollectionEvent<TInterval>> {\n private savedSerializedIntervals?: ISerializedInterval[];\n private localCollection: LocalIntervalCollection<TInterval> | undefined;\n private onDeserialize: DeserializeCallback | undefined;\n private client: Client | undefined;\n private readonly localSeqToSerializedInterval = new Map<number, ISerializedInterval | SerializedIntervalDelta>();\n private readonly localSeqToRebasedInterval = new Map<number, ISerializedInterval | SerializedIntervalDelta>();\n private readonly pendingChangesStart: Map<string, ISerializedInterval[]> = new Map<string, ISerializedInterval[]>();\n private readonly pendingChangesEnd: Map<string, ISerializedInterval[]> = new Map<string, ISerializedInterval[]>();\n\n public get attached(): boolean {\n return !!this.localCollection;\n }\n\n /** @internal */\n constructor(\n private readonly helpers: IIntervalHelpers<TInterval>,\n private readonly requiresClient: boolean,\n private readonly emitter: IValueOpEmitter,\n serializedIntervals: ISerializedInterval[] | ISerializedIntervalCollectionV2,\n ) {\n super();\n\n this.savedSerializedIntervals = Array.isArray(serializedIntervals)\n ? serializedIntervals\n : serializedIntervals.intervals.map((i) => decompressInterval(i, serializedIntervals.label));\n }\n\n private rebasePositionWithSegmentSlide(\n pos: number,\n seqNumberFrom: number,\n localSeq: number\n ): number | undefined {\n if (!this.client) {\n throw new LoggingError(\"mergeTree client must exist\");\n }\n const { clientId } = this.client.getCollabWindow();\n const { segment, offset } = this.client.getContainingSegment(pos, { referenceSequenceNumber: seqNumberFrom, clientId: this.client.getLongClientId(clientId) }, localSeq);\n\n // if segment is undefined, it slid off the string\n assert(segment !== undefined, 0x54e /* No segment found */);\n\n const segoff = this.client.getSlideToSegment({ segment, offset }) ?? segment;\n\n // case happens when rebasing op, but concurrently entire string has been deleted\n if (segoff.segment === undefined || segoff.offset === undefined) {\n return DetachedReferencePosition;\n }\n\n assert(offset !== undefined && 0 <= offset && offset < segment.cachedLength, 0x54f /* Invalid offset */);\n return this.client.findReconnectionPosition(segoff.segment, localSeq) + segoff.offset;\n }\n\n private computeRebasedPositions(localSeq: number): ISerializedInterval | SerializedIntervalDelta {\n assert(this.client !== undefined, 0x550 /* Client should be defined when computing rebased position */);\n const original = this.localSeqToSerializedInterval.get(localSeq);\n assert(original !== undefined, 0x551 /* Failed to store pending serialized interval info for this localSeq. */);\n const rebased = { ...original };\n const { start, end, sequenceNumber } = original;\n if (start !== undefined) {\n rebased.start = this.rebasePositionWithSegmentSlide(start, sequenceNumber, localSeq);\n }\n if (end !== undefined) {\n rebased.end = this.rebasePositionWithSegmentSlide(end, sequenceNumber, localSeq);\n }\n return rebased;\n }\n\n /** @internal */\n public attachGraph(client: Client, label: string) {\n if (this.attached) {\n throw new LoggingError(\"Only supports one Sequence attach\");\n }\n\n if ((client === undefined) && (this.requiresClient)) {\n throw new LoggingError(\"Client required for this collection\");\n }\n\n // Instantiate the local interval collection based on the saved intervals\n this.client = client;\n if (client) {\n client.on(\"normalize\", () => {\n for (const localSeq of this.localSeqToSerializedInterval.keys()) {\n this.localSeqToRebasedInterval.set(localSeq, this.computeRebasedPositions(localSeq));\n }\n });\n }\n\n this.localCollection = new LocalIntervalCollection<TInterval>(\n client,\n label,\n this.helpers,\n (interval, previousInterval) => this.emitChange(interval, previousInterval, true),\n );\n if (this.savedSerializedIntervals) {\n for (const serializedInterval of this.savedSerializedIntervals) {\n this.localCollection.ensureSerializedId(serializedInterval);\n const { start, end, intervalType, properties } = serializedInterval;\n const interval = this.helpers.create(\n label,\n start,\n end,\n client,\n intervalType,\n undefined,\n true,\n );\n if (properties) {\n interval.addProperties(properties);\n }\n this.localCollection.add(interval);\n }\n }\n this.savedSerializedIntervals = undefined;\n }\n\n /**\n * Gets the next local sequence number, modifying this client's collab window in doing so.\n */\n private getNextLocalSeq(): number {\n if (this.client) {\n return ++this.client.getCollabWindow().localSeq;\n }\n\n return 0;\n }\n\n private emitChange(\n interval: TInterval,\n previousInterval: TInterval,\n local: boolean,\n op?: ISequencedDocumentMessage,\n ): void {\n // Temporarily make references transient so that positional queries work (non-transient refs\n // on resolve to DetachedPosition on any segments that don't contain them). The original refType\n // is restored as single-endpoint changes re-use previous references.\n let startRefType: ReferenceType;\n let endRefType: ReferenceType;\n if (previousInterval instanceof SequenceInterval) {\n startRefType = previousInterval.start.refType;\n endRefType = previousInterval.end.refType;\n previousInterval.start.refType = ReferenceType.Transient;\n previousInterval.end.refType = ReferenceType.Transient;\n this.emit(\"changeInterval\", interval, previousInterval, local, op);\n previousInterval.start.refType = startRefType;\n previousInterval.end.refType = endRefType;\n } else {\n this.emit(\"changeInterval\", interval, previousInterval, local, op);\n }\n }\n\n /**\n * @returns the interval in this collection that has the provided `id`.\n * If no interval in the collection has this `id`, returns `undefined`.\n */\n public getIntervalById(id: string) {\n if (!this.localCollection) {\n throw new LoggingError(\"attach must be called before accessing intervals\");\n }\n return this.localCollection.getIntervalById(id);\n }\n\n /**\n * Creates a new interval and add it to the collection.\n * @param start - interval start position\n * @param end - interval end position\n * @param intervalType - type of the interval. All intervals are SlideOnRemove. Intervals may not be Transient.\n * @param props - properties of the interval\n * @returns - the created interval\n */\n public add(\n start: number,\n end: number,\n intervalType: IntervalType,\n props?: PropertySet,\n ): TInterval {\n if (!this.localCollection) {\n throw new LoggingError(\"attach must be called prior to adding intervals\");\n }\n if (intervalType & IntervalType.Transient) {\n throw new LoggingError(\"Can not add transient intervals\");\n }\n\n const interval: TInterval = this.localCollection.addInterval(start, end, intervalType, props);\n\n if (interval) {\n const serializedInterval = {\n end,\n intervalType,\n properties: interval.properties,\n sequenceNumber: this.client?.getCurrentSeq() ?? 0,\n start,\n };\n const localSeq = this.getNextLocalSeq();\n this.localSeqToSerializedInterval.set(localSeq, serializedInterval);\n // Local ops get submitted to the server. Remote ops have the deserializer run.\n this.emitter.emit(\"add\", undefined, serializedInterval, { localSeq });\n }\n\n this.emit(\"addInterval\", interval, true, undefined);\n\n return interval;\n }\n\n private deleteExistingInterval(interval: TInterval, local: boolean, op?: ISequencedDocumentMessage) {\n if (!this.localCollection) {\n throw new LoggingError(\"Attach must be called before accessing intervals\");\n }\n // The given interval is known to exist in the collection.\n this.localCollection.removeExistingInterval(interval);\n\n if (interval) {\n // Local ops get submitted to the server. Remote ops have the deserializer run.\n if (local) {\n this.emitter.emit(\n \"delete\",\n undefined,\n interval.serialize(),\n { localSeq: this.getNextLocalSeq() },\n );\n } else {\n if (this.onDeserialize) {\n this.onDeserialize(interval);\n }\n }\n }\n\n this.emit(\"deleteInterval\", interval, local, op);\n }\n\n /**\n * Removes an interval from the collection.\n * @param id - Id of the interval to remove\n * @returns the removed interval\n */\n public removeIntervalById(id: string) {\n if (!this.localCollection) {\n throw new LoggingError(\"Attach must be called before accessing intervals\");\n }\n const interval = this.localCollection.getIntervalById(id);\n if (interval) {\n this.deleteExistingInterval(interval, true, undefined);\n }\n return interval;\n }\n\n /**\n * Changes the properties on an existing interval.\n * @param id - Id of the interval whose properties should be changed\n * @param props - Property set to apply to the interval. Shallow merging is used between any existing properties\n * and `prop`, i.e. the interval will end up with a property object equivalent to `{ ...oldProps, ...props }`.\n */\n public changeProperties(id: string, props: PropertySet) {\n if (!this.attached) {\n throw new LoggingError(\"Attach must be called before accessing intervals\");\n }\n if (typeof (id) !== \"string\") {\n throw new LoggingError(\"Change API requires an ID that is a string\");\n }\n if (!props) {\n throw new LoggingError(\"changeProperties should be called with a property set\");\n }\n\n const interval = this.getIntervalById(id);\n if (interval) {\n // Pass Unassigned as the sequence number to indicate that this is a local op that is waiting for an ack.\n const deltaProps = interval.addProperties(props, true, UnassignedSequenceNumber);\n const serializedInterval: ISerializedInterval = interval.serialize();\n\n // Emit a change op that will only change properties. Add the ID to\n // the property bag provided by the caller.\n serializedInterval.start = undefined as any;\n serializedInterval.end = undefined as any;\n\n serializedInterval.properties = props;\n serializedInterval.properties[reservedIntervalIdKey] = interval.getIntervalId();\n const localSeq = this.getNextLocalSeq();\n this.localSeqToSerializedInterval.set(localSeq, serializedInterval);\n this.emitter.emit(\"change\", undefined, serializedInterval, { localSeq });\n this.emit(\"propertyChanged\", interval, deltaProps, true, undefined);\n }\n }\n\n /**\n * Changes the endpoints of an existing interval.\n * @param id - Id of the interval to change\n * @param start - New start value, if defined. `undefined` signifies this endpoint should be left unchanged.\n * @param end - New end value, if defined. `undefined` signifies this endpoint should be left unchanged.\n * @returns the interval that was changed, if it existed in the collection.\n */\n public change(id: string, start?: number, end?: number): TInterval | undefined {\n if (!this.localCollection) {\n throw new LoggingError(\"Attach must be called before accessing intervals\");\n }\n\n // Force id to be a string.\n if (typeof (id) !== \"string\") {\n throw new LoggingError(\"Change API requires an ID that is a string\");\n }\n\n const interval = this.getIntervalById(id);\n if (interval) {\n const newInterval = this.localCollection.changeInterval(interval, start, end);\n if (!newInterval) {\n return undefined;\n }\n const serializedInterval: SerializedIntervalDelta = interval.serialize();\n serializedInterval.start = start;\n serializedInterval.end = end;\n // Emit a property bag containing only the ID, as we don't intend for this op to change any properties.\n serializedInterval.properties =\n {\n [reservedIntervalIdKey]: interval.getIntervalId(),\n };\n const localSeq = this.getNextLocalSeq();\n this.localSeqToSerializedInterval.set(localSeq, serializedInterval);\n this.emitter.emit(\"change\", undefined, serializedInterval, { localSeq });\n this.addPendingChange(id, serializedInterval);\n this.emitChange(newInterval, interval, true);\n return newInterval;\n }\n // No interval to change\n return undefined;\n }\n\n private addPendingChange(id: string, serializedInterval: SerializedIntervalDelta) {\n if (serializedInterval.start !== undefined) {\n this.addPendingChangeHelper(id, this.pendingChangesStart, serializedInterval);\n }\n if (serializedInterval.end !== undefined) {\n this.addPendingChangeHelper(id, this.pendingChangesEnd, serializedInterval);\n }\n }\n\n private addPendingChangeHelper(\n id: string,\n pendingChanges: Map<string, SerializedIntervalDelta[]>,\n serializedInterval: SerializedIntervalDelta,\n ) {\n let entries: SerializedIntervalDelta[] | undefined = pendingChanges.get(id);\n if (!entries) {\n entries = [];\n pendingChanges.set(id, entries);\n }\n entries.push(serializedInterval);\n }\n\n private removePendingChange(serializedInterval: SerializedIntervalDelta) {\n // Change ops always have an ID.\n const id: string = serializedInterval.properties?.[reservedIntervalIdKey];\n if (serializedInterval.start !== undefined) {\n this.removePendingChangeHelper(id, this.pendingChangesStart, serializedInterval);\n }\n if (serializedInterval.end !== undefined) {\n this.removePendingChangeHelper(id, this.pendingChangesEnd, serializedInterval);\n }\n }\n\n private removePendingChangeHelper(\n id: string,\n pendingChanges: Map<string, SerializedIntervalDelta[]>,\n serializedInterval: SerializedIntervalDelta,\n ) {\n const entries = pendingChanges.get(id);\n if (entries) {\n const pendingChange = entries.shift();\n if (entries.length === 0) {\n pendingChanges.delete(id);\n }\n if (pendingChange?.start !== serializedInterval.start ||\n pendingChange?.end !== serializedInterval.end) {\n throw new LoggingError(\"Mismatch in pending changes\");\n }\n }\n }\n\n private hasPendingChangeStart(id: string) {\n const entries = this.pendingChangesStart.get(id);\n return entries && entries.length !== 0;\n }\n\n private hasPendingChangeEnd(id: string) {\n const entries = this.pendingChangesEnd.get(id);\n return entries && entries.length !== 0;\n }\n\n /** @internal */\n public ackChange(\n serializedInterval: ISerializedInterval,\n local: boolean,\n op: ISequencedDocumentMessage,\n localOpMetadata: IMapMessageLocalMetadata | undefined,\n ) {\n if (!this.localCollection) {\n throw new LoggingError(\"Attach must be called before accessing intervals\");\n }\n\n if (local) {\n assert(localOpMetadata !== undefined, 0x552 /* op metadata should be defined for local op */);\n this.localSeqToSerializedInterval.delete(localOpMetadata?.localSeq);\n // This is an ack from the server. Remove the pending change.\n this.removePendingChange(serializedInterval);\n }\n\n // Note that the ID is in the property bag only to allow us to find the interval.\n // This API cannot change the ID, and writing to the ID property will result in an exception. So we\n // strip it out of the properties here.\n const { [reservedIntervalIdKey]: id, ...newProps } = serializedInterval.properties ?? {};\n assert(id !== undefined, 0x3fe /* id must exist on the interval */);\n const interval: TInterval | undefined = this.getIntervalById(id);\n if (!interval) {\n // The interval has been removed locally; no-op.\n return;\n }\n\n if (local) {\n // Let the propertyManager prune its pending change-properties set.\n interval.propertyManager?.ackPendingProperties(\n {\n type: MergeTreeDeltaType.ANNOTATE,\n props: serializedInterval.properties ?? {},\n });\n\n this.ackInterval(interval, op);\n } else {\n // If there are pending changes with this ID, don't apply the remote start/end change, as the local ack\n // should be the winning change.\n let start: number | undefined;\n let end: number | undefined;\n // Track pending start/end independently of one another.\n if (!this.hasPendingChangeStart(id)) {\n start = serializedInterval.start;\n }\n if (!this.hasPendingChangeEnd(id)) {\n end = serializedInterval.end;\n }\n\n let newInterval = interval;\n if (start !== undefined || end !== undefined) {\n // If changeInterval gives us a new interval, work with that one. Otherwise keep working with\n // the one we originally found in the tree.\n newInterval = this.localCollection.changeInterval(interval, start, end, op) ?? interval;\n }\n const deltaProps = newInterval.addProperties(newProps, true, op.sequenceNumber);\n if (this.onDeserialize) {\n this.onDeserialize(newInterval);\n }\n\n if (newInterval !== interval) {\n this.emitChange(newInterval, interval, local, op);\n }\n\n const changedProperties = Object.keys(newProps).length > 0;\n if (changedProperties) {\n this.emit(\"propertyChanged\", interval, deltaProps, local, op);\n }\n }\n }\n\n public addConflictResolver(conflictResolver: IntervalConflictResolver<TInterval>): void {\n if (!this.localCollection) {\n throw new LoggingError(\"attachSequence must be called\");\n }\n this.localCollection.addConflictResolver(conflictResolver);\n }\n\n public attachDeserializer(onDeserialize: DeserializeCallback): void {\n // If no deserializer is specified can skip all processing work\n if (!onDeserialize) {\n return;\n }\n\n // Start by storing the callbacks so that any subsequent modifications make use of them\n this.onDeserialize = onDeserialize;\n\n // Trigger the async prepare work across all values in the collection\n this.localCollection?.map((interval) => {\n onDeserialize(interval);\n });\n }\n\n /**\n * Returns new interval after rebasing. If undefined, the interval was\n * deleted as a result of rebasing. This can occur if the interval applies\n * to a range that no longer exists, and the interval was unable to slide.\n *\n * @internal\n */\n public rebaseLocalInterval(\n opName: string,\n serializedInterval: SerializedIntervalDelta,\n localSeq: number,\n ): SerializedIntervalDelta | undefined {\n if (!this.client) {\n // If there's no associated mergeTree client, the originally submitted op is still correct.\n return serializedInterval;\n }\n if (!this.attached) {\n throw new LoggingError(\"attachSequence must be called\");\n }\n\n const { intervalType, properties } = serializedInterval;\n\n const { start: startRebased, end: endRebased } = this.localSeqToRebasedInterval.get(localSeq)\n ?? this.computeRebasedPositions(localSeq);\n\n const intervalId = properties?.[reservedIntervalIdKey];\n const localInterval = this.localCollection?.getIntervalById(intervalId);\n\n const rebased: SerializedIntervalDelta = {\n start: startRebased,\n end: endRebased,\n intervalType,\n sequenceNumber: this.client?.getCurrentSeq() ?? 0,\n properties,\n };\n\n if (opName === \"change\" && (this.hasPendingChangeStart(intervalId) || this.hasPendingChangeEnd(intervalId))) {\n this.removePendingChange(serializedInterval);\n this.addPendingChange(intervalId, rebased);\n }\n\n // if the interval slid off the string, rebase the op to be a noop and delete the interval.\n if (startRebased === DetachedReferencePosition || endRebased === DetachedReferencePosition) {\n if (localInterval) {\n this.localCollection?.removeExistingInterval(localInterval);\n }\n return undefined;\n }\n\n if (localInterval !== undefined) {\n // we know we must be using `SequenceInterval` because `this.client` exists\n assert(\n localInterval instanceof SequenceInterval,\n 0x3a0 /* localInterval must be `SequenceInterval` when used with client */,\n );\n // The rebased op may place this interval's endpoints on different segments. Calling `changeInterval` here\n // updates the local client's state to be consistent with the emitted op.\n this.localCollection?.changeInterval(localInterval, startRebased, endRebased, undefined, localSeq);\n }\n\n return rebased;\n }\n\n private getSlideToSegment(lref: LocalReferencePosition) {\n if (!this.client) {\n throw new LoggingError(\"client does not exist\");\n }\n const segoff = { segment: lref.getSegment(), offset: lref.getOffset() };\n if (segoff.segment?.localRefs?.has(lref) !== true) {\n return undefined;\n }\n const newSegoff = this.client.getSlideToSegment(segoff);\n const value: { segment: ISegment | undefined; offset: number | undefined; } | undefined\n = (segoff.segment === newSegoff.segment && segoff.offset === newSegoff.offset) ? undefined : newSegoff;\n return value;\n }\n\n private setSlideOnRemove(lref: LocalReferencePosition) {\n let refType = lref.refType;\n refType = refType & ~ReferenceType.StayOnRemove;\n refType = refType | ReferenceType.SlideOnRemove;\n lref.refType = refType;\n }\n\n private ackInterval(interval: TInterval, op: ISequencedDocumentMessage) {\n // Only SequenceIntervals need potential sliding\n if (!(interval instanceof SequenceInterval)) {\n return;\n }\n\n if (!refTypeIncludesFlag(interval.start, ReferenceType.StayOnRemove) &&\n !refTypeIncludesFlag(interval.end, ReferenceType.StayOnRemove)) {\n return;\n }\n\n const newStart = this.getSlideToSegment(interval.start);\n const newEnd = this.getSlideToSegment(interval.end);\n\n const id = interval.properties[reservedIntervalIdKey];\n const hasPendingStartChange = this.hasPendingChangeStart(id);\n const hasPendingEndChange = this.hasPendingChangeEnd(id);\n\n if (!hasPendingStartChange) {\n this.setSlideOnRemove(interval.start);\n }\n\n if (!hasPendingEndChange) {\n this.setSlideOnRemove(interval.end);\n }\n\n const needsStartUpdate = newStart !== undefined && !hasPendingStartChange;\n const needsEndUpdate = newEnd !== undefined && !hasPendingEndChange;\n\n if (needsStartUpdate || needsEndUpdate) {\n if (!this.localCollection) {\n throw new LoggingError(\"Attach must be called before accessing intervals\");\n }\n\n // `interval`'s endpoints will get modified in-place, so clone it prior to doing so for event emission.\n const oldInterval = interval.clone() as TInterval & SequenceInterval;\n\n // In this case, where we change the start or end of an interval,\n // it is necessary to remove and re-add the interval listeners.\n // This ensures that the correct listeners are added to the LocalReferencePosition.\n this.localCollection.removeExistingInterval(interval);\n if (!this.client) {\n throw new LoggingError(\"client does not exist\");\n }\n\n if (needsStartUpdate) {\n const props = interval.start.properties;\n interval.start = createPositionReferenceFromSegoff(this.client, newStart, interval.start.refType, op);\n if (props) {\n interval.start.addProperties(props);\n }\n const oldSeg = oldInterval.start.getSegment();\n // remove and rebuild start interval as transient for event\n this.client.removeLocalReferencePosition(oldInterval.start);\n oldInterval.start.refType = ReferenceType.Transient;\n oldSeg?.localRefs?.addLocalRef(\n oldInterval.start,\n oldInterval.start.getOffset());\n }\n if (needsEndUpdate) {\n const props = interval.end.properties;\n interval.end = createPositionReferenceFromSegoff(this.client, newEnd, interval.end.refType, op);\n if (props) {\n interval.end.addProperties(props);\n }\n // remove and rebuild end interval as transient for event\n const oldSeg = oldInterval.end.getSegment();\n this.client.removeLocalReferencePosition(oldInterval.end);\n oldInterval.end.refType = ReferenceType.Transient;\n oldSeg?.localRefs?.addLocalRef(\n oldInterval.end,\n oldInterval.end.getOffset());\n }\n this.localCollection.add(interval);\n this.emitChange(interval, oldInterval as TInterval, true, op);\n }\n }\n\n /** @internal */\n public ackAdd(\n serializedInterval: ISerializedInterval,\n local: boolean,\n op: ISequencedDocumentMessage,\n localOpMetadata: IMapMessageLocalMetadata | undefined,\n ) {\n if (local) {\n assert(localOpMetadata !== undefined, 0x553 /* op metadata should be defined for local op */);\n this.localSeqToSerializedInterval.delete(localOpMetadata.localSeq);\n const id: string = serializedInterval.properties?.[reservedIntervalIdKey];\n const localInterval = this.getIntervalById(id);\n if (localInterval) {\n this.ackInterval(localInterval, op);\n }\n return;\n }\n\n if (!this.localCollection) {\n throw new LoggingError(\"attachSequence must be called\");\n }\n\n this.localCollection.ensureSerializedId(serializedInterval);\n\n const interval: TInterval = this.localCollection.addInterval(\n serializedInterval.start,\n serializedInterval.end,\n serializedInterval.intervalType,\n serializedInterval.properties,\n op);\n\n if (interval) {\n if (this.onDeserialize) {\n this.onDeserialize(interval);\n }\n }\n\n this.emit(\"addInterval\", interval, local, op);\n\n return interval;\n }\n\n /** @internal */\n public ackDelete(\n serializedInterval: ISerializedInterval,\n local: boolean,\n op: ISequencedDocumentMessage): void {\n if (local) {\n // Local ops were applied when the message was created and there's no \"pending delete\"\n // state to bookkeep: remote operation application takes into account possibility of\n // locally deleted interval whenever a lookup happens.\n return;\n }\n\n if (!this.localCollection) {\n throw new LoggingError(\"attach must be called prior to deleting intervals\");\n }\n\n const id = this.localCollection.ensureSerializedId(serializedInterval);\n const interval = this.localCollection.getIntervalById(id);\n if (interval) {\n this.deleteExistingInterval(interval, local, op);\n }\n }\n\n /**\n * @internal\n */\n public serializeInternal(): ISerializedIntervalCollectionV2 {\n if (!this.localCollection) {\n throw new LoggingError(\"attachSequence must be called\");\n }\n\n return this.localCollection.serialize();\n }\n\n /**\n * @returns an iterator over all intervals in this collection.\n */\n public [Symbol.iterator](): IntervalCollectionIterator<TInterval> {\n const iterator = new IntervalCollectionIterator<TInterval>(this);\n return iterator;\n }\n\n /**\n * @returns a forward iterator over all intervals in this collection with start point equal to `startPosition`.\n */\n public CreateForwardIteratorWithStartPosition(startPosition: number): IntervalCollectionIterator<TInterval> {\n const iterator = new IntervalCollectionIterator<TInterval>(this, true, startPosition);\n return iterator;\n }\n\n /**\n * @returns a backward iterator over all intervals in this collection with start point equal to `startPosition`.\n */\n public CreateBackwardIteratorWithStartPosition(startPosition: number): IntervalCollectionIterator<TInterval> {\n const iterator = new IntervalCollectionIterator<TInterval>(this, false, startPosition);\n return iterator;\n }\n\n /**\n * @returns a forward iterator over all intervals in this collection with end point equal to `endPosition`.\n */\n public CreateForwardIteratorWithEndPosition(endPosition: number): IntervalCollectionIterator<TInterval> {\n const iterator = new IntervalCollectionIterator<TInterval>(this, true, undefined, endPosition);\n return iterator;\n }\n\n /**\n * @returns a backward iterator over all intervals in this collection with end point equal to `endPosition`.\n */\n public CreateBackwardIteratorWithEndPosition(endPosition: number): IntervalCollectionIterator<TInterval> {\n const iterator = new IntervalCollectionIterator<TInterval>(this, false, undefined, endPosition);\n return iterator;\n }\n\n /**\n * Gathers iteration results that optionally match a start/end criteria into the provided array.\n * @param results - Array to gather the results into. In lieu of a return value, this array will be populated with\n * intervals matching the query upon edit.\n * @param iteratesForward - whether or not iteration should be in the forward direction\n * @param start - If provided, only match intervals whose start point is equal to `start`.\n * @param end - If provided, only match intervals whose end point is equal to `end`.\n */\n public gatherIterationResults(\n results: TInterval[],\n iteratesForward: boolean,\n start?: number,\n end?: number) {\n if (!this.localCollection) {\n return;\n }\n\n this.localCollection.gatherIterationResults(results, iteratesForward, start, end);\n }\n\n /**\n * @returns an array of all intervals in this collection that overlap with the interval\n * `[startPosition, endPosition]`.\n */\n public findOverlappingIntervals(startPosition: number, endPosition: number): TInterval[] {\n if (!this.localCollection) {\n throw new LoggingError(\"attachSequence must be called\");\n }\n\n return this.localCollection.findOverlappingIntervals(startPosition, endPosition);\n }\n\n /**\n * Applies a function to each interval in this collection.\n */\n public map(fn: (interval: TInterval) => void) {\n if (!this.localCollection) {\n throw new LoggingError(\"attachSequence must be called\");\n }\n\n this.localCollection.map(fn);\n }\n\n public previousInterval(pos: number): TInterval | undefined {\n if (!this.localCollection) {\n throw new LoggingError(\"attachSequence must be called\");\n }\n\n return this.localCollection.previousInterval(pos);\n }\n\n public nextInterval(pos: number): TInterval | undefined {\n if (!this.localCollection) {\n throw new LoggingError(\"attachSequence must be called\");\n }\n\n return this.localCollection.nextInterval(pos);\n }\n}\n\n/**\n * Information that identifies an interval within a `Sequence`.\n */\nexport interface IntervalLocator {\n /**\n * Label for the collection the interval is a part of\n */\n label: string;\n /**\n * Interval within that collection\n */\n interval: 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(potentialEndpoint: LocalReferencePosition): IntervalLocator | undefined {\n const {\n interval,\n [reservedRangeLabelsKey]: collectionNameArray,\n } = potentialEndpoint.properties ?? {};\n return (interval && collectionNameArray?.length === 1) ? { label: collectionNameArray[0], interval } : 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,2DAqBoC;AAEpC,qEAA+D;AAC/D,+BAAkC;AASlC,iDAAiG;AAEjG,MAAM,qBAAqB,GAAG,YAAY,CAAC;AAE3C,IAAY,YAiBX;AAjBD,WAAY,YAAY;IACvB,mDAAY,CAAA;IAC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EAQC","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 (inclusive) */\n\tstart: number;\n\t/** End position of the interval (inclusive) */\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 */\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 | undefined {\n\t\tconst id = this.properties?.[reservedIntervalIdKey];\n\t\tif (id === undefined) {\n\t\t\treturn undefined;\n\t\t}\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 */\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 */\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 */\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 */\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 */\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 | undefined {\n\t\tconst id = this.properties?.[reservedIntervalIdKey];\n\t\tif (id === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn `${id}`;\n\t}\n\n\t/**\n\t * {@inheritDoc IInterval.union}\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 */\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 * @remarks - this is currently strict overlap, which doesn't align with the endpoint treatment of`.overlaps()`\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 */\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): 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 (!op && !localSeq && !refTypeIncludesFlag(refType, ReferenceType.Transient)) {\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);\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\n\t * @param end - interval end position\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 */\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\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"]}