@fluidframework/sequence 2.41.0 → 2.43.0-343119
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.
- package/CHANGELOG.md +4 -0
- package/api-report/sequence.legacy.alpha.api.md +13 -5
- package/dist/intervalCollection.d.ts +14 -19
- package/dist/intervalCollection.d.ts.map +1 -1
- package/dist/intervalCollection.js +113 -128
- package/dist/intervalCollection.js.map +1 -1
- package/dist/intervalCollectionMap.d.ts +3 -3
- package/dist/intervalCollectionMap.d.ts.map +1 -1
- package/dist/intervalCollectionMap.js.map +1 -1
- package/dist/intervalCollectionMapInterfaces.d.ts +22 -4
- package/dist/intervalCollectionMapInterfaces.d.ts.map +1 -1
- package/dist/intervalCollectionMapInterfaces.js.map +1 -1
- package/dist/intervalIndex/overlappingIntervalsIndex.d.ts +4 -4
- package/dist/intervalIndex/overlappingIntervalsIndex.d.ts.map +1 -1
- package/dist/intervalIndex/overlappingIntervalsIndex.js.map +1 -1
- package/dist/intervals/intervalUtils.d.ts +12 -1
- package/dist/intervals/intervalUtils.d.ts.map +1 -1
- package/dist/intervals/intervalUtils.js.map +1 -1
- package/dist/intervals/sequenceInterval.d.ts +18 -5
- package/dist/intervals/sequenceInterval.d.ts.map +1 -1
- package/dist/intervals/sequenceInterval.js +2 -1
- package/dist/intervals/sequenceInterval.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.d.ts.map +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/revertibles.d.ts.map +1 -1
- package/dist/revertibles.js +6 -3
- package/dist/revertibles.js.map +1 -1
- package/dist/sequence.d.ts +2 -1
- package/dist/sequence.d.ts.map +1 -1
- package/dist/sequence.js +6 -3
- package/dist/sequence.js.map +1 -1
- package/lib/intervalCollection.d.ts +14 -19
- package/lib/intervalCollection.d.ts.map +1 -1
- package/lib/intervalCollection.js +114 -129
- package/lib/intervalCollection.js.map +1 -1
- package/lib/intervalCollectionMap.d.ts +3 -3
- package/lib/intervalCollectionMap.d.ts.map +1 -1
- package/lib/intervalCollectionMap.js.map +1 -1
- package/lib/intervalCollectionMapInterfaces.d.ts +22 -4
- package/lib/intervalCollectionMapInterfaces.d.ts.map +1 -1
- package/lib/intervalCollectionMapInterfaces.js.map +1 -1
- package/lib/intervalIndex/overlappingIntervalsIndex.d.ts +4 -4
- package/lib/intervalIndex/overlappingIntervalsIndex.d.ts.map +1 -1
- package/lib/intervalIndex/overlappingIntervalsIndex.js +1 -1
- package/lib/intervalIndex/overlappingIntervalsIndex.js.map +1 -1
- package/lib/intervals/intervalUtils.d.ts +12 -1
- package/lib/intervals/intervalUtils.d.ts.map +1 -1
- package/lib/intervals/intervalUtils.js.map +1 -1
- package/lib/intervals/sequenceInterval.d.ts +18 -5
- package/lib/intervals/sequenceInterval.d.ts.map +1 -1
- package/lib/intervals/sequenceInterval.js +2 -1
- package/lib/intervals/sequenceInterval.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.d.ts.map +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/revertibles.d.ts.map +1 -1
- package/lib/revertibles.js +6 -3
- package/lib/revertibles.js.map +1 -1
- package/lib/sequence.d.ts +2 -1
- package/lib/sequence.d.ts.map +1 -1
- package/lib/sequence.js +6 -3
- package/lib/sequence.js.map +1 -1
- package/package.json +17 -17
- package/src/intervalCollection.ts +191 -195
- package/src/intervalCollectionMap.ts +4 -11
- package/src/intervalCollectionMapInterfaces.ts +25 -5
- package/src/intervalIndex/overlappingIntervalsIndex.ts +15 -11
- package/src/intervals/intervalUtils.ts +12 -1
- package/src/intervals/sequenceInterval.ts +22 -4
- package/src/packageVersion.ts +1 -1
- package/src/revertibles.ts +7 -6
- package/src/sequence.ts +11 -13
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,0BAA0B,CAAC;AACrC,QAAA,UAAU,GAAG,
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,0BAA0B,CAAC;AACrC,QAAA,UAAU,GAAG,eAAe,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/sequence\";\nexport const pkgVersion = \"2.43.0-343119\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"revertibles.d.ts","sourceRoot":"","sources":["../src/revertibles.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EACN,sBAAsB,EAEtB,wBAAwB,EAExB,WAAW,EAeX,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAyB,MAAM,sBAAsB,CAAC;AAC/F,OAAO,EAAuB,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAE,aAAa,EAAuB,MAAM,mBAAmB,CAAC;AAEvE;;;;GAIG;AACH,MAAM,MAAM,sBAAsB,GAAG,wBAAwB,GAAG,kBAAkB,CAAC;AAInF;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAC3B;IACA,KAAK,EAAE,OAAO,cAAc,CAAC,MAAM,CAAC;IACpC,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,KAAK,EAAE,sBAAsB,CAAC;IAC9B,GAAG,EAAE,sBAAsB,CAAC;CAC3B,GACD;IACA,KAAK,EAAE,OAAO,cAAc,CAAC,GAAG,CAAC;IACjC,QAAQ,EAAE,gBAAgB,CAAC;CAC1B,GACD;IACA,KAAK,EAAE,OAAO,cAA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AE,sBAAsB,EAAE,QA8BrC"}
|
package/dist/revertibles.js
CHANGED
|
@@ -232,9 +232,12 @@ function discardSharedStringRevertibles(sharedString, revertibles) {
|
|
|
232
232
|
}
|
|
233
233
|
exports.discardSharedStringRevertibles = discardSharedStringRevertibles;
|
|
234
234
|
function getSlidePosition(string, lref, pos) {
|
|
235
|
-
const
|
|
236
|
-
|
|
237
|
-
|
|
235
|
+
const segment = lref.getSegment();
|
|
236
|
+
const offset = lref.getOffset();
|
|
237
|
+
const slide = segment === undefined
|
|
238
|
+
? undefined
|
|
239
|
+
: (0, internal_2.getSlideToSegoff)({ segment, offset }, lref.slidingPreference);
|
|
240
|
+
return slide !== undefined &&
|
|
238
241
|
string.getPosition(slide.segment) !== -1 &&
|
|
239
242
|
(pos < 0 || pos >= string.getLength())
|
|
240
243
|
? string.getPosition(slide.segment) + slide.offset
|
package/dist/revertibles.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"revertibles.js","sourceRoot":"","sources":["../src/revertibles.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+BAA+B;AAE/B,kEAA8E;AAC9E,kEAoB6C;AAE7C,mDAA+F;AAW/F,MAAM,KAAK,GAAG,IAAI,GAAG,EAAkB,CAAC;AAkDxC,SAAS,wBAAwB,CAAC,QAA0B;IAC3D,MAAM,OAAO,GAAG,QAAQ,CAAC,aAAa,EAAE,CAAC;IACzC,OAAO,YAAY,CAAC,OAAO,CAAC,CAAC;AAC9B,CAAC;AAED,SAAS,YAAY,CAAC,UAAkB;IACvC,OAAO,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,UAAU,CAAC;AAC5C,CAAC;AAED;;;;GAIG;AACH,SAAgB,8BAA8B,CAC7C,QAA0B,EAC1B,WAAqC;IAErC,WAAW,CAAC,IAAI,CAAC;QAChB,KAAK,EAAE,yBAAc,CAAC,GAAG;QACzB,QAAQ;KACR,CAAC,CAAC;IAEH,OAAO,WAAW,CAAC;A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;YACvC,CAAC;QACF,CAAC;IACF,CAAC,CAAC,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,SAAgB,6BAA6B,CAC5C,YAA2B,EAC3B,WAAqC;IAErC,OAAO,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/B,oEAAoE;QACpE,MAAM,CAAC,GAAG,WAAW,CAAC,GAAG,EAAG,CAAC;QAC7B,IAAI,OAAO,IAAI,CAAC,EAAE,CAAC;YAClB,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC;YACtB,QAAQ,KAAK,EAAE,CAAC;gBACf,KAAK,yBAAc,CAAC,GAAG;oBACtB,cAAc,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;oBAChC,MAAM;gBACP,KAAK,yBAAc,CAAC,MAAM;oBACzB,iBAAiB,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;oBACnC,MAAM;gBACP,KAAK,yBAAc,CAAC,MAAM;oBACzB,iBAAiB,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;oBACnC,MAAM;gBACP,KAAK,yBAAc,CAAC,gBAAgB;oBACnC,0BAA0B,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;oBAC5C,MAAM;gBACP,KAAK,yBAAc,CAAC,eAAe;oBAClC,yBAAyB,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;oBAC3C,MAAM;gBACP;oBACC,IAAA,0BAAe,EAAC,KAAK,CAAC,CAAC;YACzB,CAAC;QACF,CAAC;aAAM,CAAC;YACP,IAAA,0CAA+B,EAAC,YAAY,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QACpD,CAAC;IACF,CAAC;AACF,CAAC;AAhCD,sEAgCC","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, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport {\n\tLocalReferencePosition,\n\tMergeTreeDeltaOperationType,\n\tMergeTreeDeltaRevertible,\n\tMergeTreeDeltaType,\n\tPropertySet,\n\tReferenceType,\n\tSlidingPreference, // eslint-disable-next-line import/no-deprecated\n\tappendToMergeTreeDeltaRevertibles,\n\tdiscardMergeTreeDeltaRevertible,\n\tgetSlideToSegoff,\n\tisMergeTreeDeltaRevertible,\n\trefTypeIncludesFlag,\n\trevertMergeTreeDeltaRevertibles,\n\tInteriorSequencePlace,\n\tSide,\n\ttype ISegmentInternal,\n\tsegmentIsRemoved,\n\tSortedSegmentSet,\n\ttype ISegment,\n} from \"@fluidframework/merge-tree/internal\";\n\nimport { IntervalOpType, SequenceInterval, SequenceIntervalClass } from \"./intervals/index.js\";\nimport { ISequenceDeltaRange, SequenceDeltaEvent } from \"./sequenceDeltaEvent.js\";\nimport { ISharedString, SharedStringSegment } from \"./sharedString.js\";\n\n/**\n * Data for undoing edits on SharedStrings and Intervals.\n * @legacy\n * @alpha\n */\nexport type SharedStringRevertible = MergeTreeDeltaRevertible | IntervalRevertible;\n\nconst idMap = new Map<string, string>();\n\n/**\n * Data for undoing edits affecting Intervals.\n * @legacy\n * @alpha\n */\nexport type IntervalRevertible =\n\t| {\n\t\t\tevent: typeof IntervalOpType.CHANGE;\n\t\t\tinterval: SequenceInterval;\n\t\t\tstart: LocalReferencePosition;\n\t\t\tend: LocalReferencePosition;\n\t }\n\t| {\n\t\t\tevent: typeof IntervalOpType.ADD;\n\t\t\tinterval: SequenceInterval;\n\t }\n\t| {\n\t\t\tevent: typeof IntervalOpType.DELETE;\n\t\t\tinterval: SequenceInterval;\n\t\t\tstart: LocalReferencePosition;\n\t\t\tend: LocalReferencePosition;\n\t }\n\t| {\n\t\t\tevent: typeof IntervalOpType.PROPERTY_CHANGED;\n\t\t\tinterval: SequenceInterval;\n\t\t\tpropertyDeltas: PropertySet;\n\t }\n\t| {\n\t\t\tevent: typeof IntervalOpType.POSITION_REMOVE;\n\t\t\tintervals: {\n\t\t\t\tintervalId: string;\n\t\t\t\tlabel: string;\n\t\t\t\tstartOffset?: number; // interval start index within a removed range\n\t\t\t\tendOffset?: number; // interval end index within a removed range\n\t\t\t}[];\n\t\t\t// local refs used by IntervalOpType.CHANGE and DELETE revertibles\n\t\t\trevertibleRefs: {\n\t\t\t\trevertible: IntervalRevertible;\n\t\t\t\toffset: number;\n\t\t\t\tisStart: boolean;\n\t\t\t}[];\n\t\t\tmergeTreeRevertible: MergeTreeDeltaRevertible;\n\t };\n\ntype TypedRevertible<T extends IntervalRevertible[\"event\"]> = IntervalRevertible & {\n\tevent: T;\n};\n\nfunction getUpdatedIdFromInterval(interval: SequenceInterval): string {\n\tconst maybeId = interval.getIntervalId();\n\treturn getUpdatedId(maybeId);\n}\n\nfunction getUpdatedId(intervalId: string): string {\n\treturn idMap.get(intervalId) ?? intervalId;\n}\n\n/**\n * Create revertibles for adding an interval\n * @legacy\n * @alpha\n */\nexport function appendAddIntervalToRevertibles(\n\tinterval: SequenceInterval,\n\trevertibles: SharedStringRevertible[],\n) {\n\trevertibles.push({\n\t\tevent: IntervalOpType.ADD,\n\t\tinterval,\n\t});\n\n\treturn revertibles;\n}\n\n/**\n * Create revertibles for deleting an interval\n * @legacy\n * @alpha\n */\nexport function appendDeleteIntervalToRevertibles(\n\tstring: ISharedString,\n\tinterval: SequenceInterval,\n\trevertibles: SharedStringRevertible[],\n): SharedStringRevertible[] {\n\tconst startSeg = interval.start.getSegment() as SharedStringSegment | undefined;\n\tif (!startSeg) {\n\t\treturn revertibles;\n\t}\n\tconst startType = segmentIsRemoved(startSeg)\n\t\t? ReferenceType.SlideOnRemove | ReferenceType.RangeBegin\n\t\t: ReferenceType.StayOnRemove | ReferenceType.RangeBegin;\n\tconst endSeg = interval.end.getSegment() as SharedStringSegment | undefined;\n\tif (!endSeg) {\n\t\treturn revertibles;\n\t}\n\tconst endType = segmentIsRemoved(startSeg)\n\t\t? ReferenceType.SlideOnRemove | ReferenceType.RangeEnd\n\t\t: ReferenceType.StayOnRemove | ReferenceType.RangeEnd;\n\tconst startRef = string.createLocalReferencePosition(\n\t\tstartSeg,\n\t\tinterval.start.getOffset(),\n\t\tstartType,\n\t\tundefined,\n\t\tinterval.start.slidingPreference,\n\t);\n\tconst endRef = string.createLocalReferencePosition(\n\t\tendSeg,\n\t\tinterval.end.getOffset(),\n\t\tendType,\n\t\tundefined,\n\t\tinterval.end.slidingPreference,\n\t);\n\tconst revertible = {\n\t\tevent: IntervalOpType.DELETE,\n\t\tinterval,\n\t\tstart: startRef,\n\t\tend: endRef,\n\t};\n\trevertible.start.addProperties({ revertible });\n\trevertible.end.addProperties({ revertible });\n\trevertibles.push(revertible);\n\n\treturn revertibles;\n}\n\n/**\n * Create revertibles for moving endpoints of an interval\n * @legacy\n * @alpha\n */\nexport function appendChangeIntervalToRevertibles(\n\tstring: ISharedString,\n\tnewInterval: SequenceInterval,\n\tpreviousInterval: SequenceInterval,\n\trevertibles: SharedStringRevertible[],\n) {\n\tconst startSeg = previousInterval.start.getSegment() as SharedStringSegment;\n\t// This logic is needed because the ReferenceType StayOnRemove cannot be used\n\t// on removed segments. This works for revertibles because the old position of the\n\t// interval within the removed segment is handled by the remove range revertible.\n\tconst startType = segmentIsRemoved(startSeg)\n\t\t? ReferenceType.SlideOnRemove | ReferenceType.RangeBegin\n\t\t: ReferenceType.StayOnRemove | ReferenceType.RangeBegin;\n\tconst endSeg = previousInterval.end.getSegment() as SharedStringSegment;\n\tconst endType = segmentIsRemoved(startSeg)\n\t\t? ReferenceType.SlideOnRemove | ReferenceType.RangeEnd\n\t\t: ReferenceType.StayOnRemove | ReferenceType.RangeEnd;\n\tconst prevStartRef = string.createLocalReferencePosition(\n\t\tstartSeg,\n\t\tpreviousInterval.start.getOffset(),\n\t\tstartType,\n\t\tundefined,\n\t\tpreviousInterval.start.slidingPreference,\n\t);\n\tconst prevEndRef = string.createLocalReferencePosition(\n\t\tendSeg,\n\t\tpreviousInterval.end.getOffset(),\n\t\tendType,\n\t\tundefined,\n\t\tpreviousInterval.end.slidingPreference,\n\t);\n\tconst revertible = {\n\t\tevent: IntervalOpType.CHANGE,\n\t\tinterval: newInterval,\n\t\tstart: prevStartRef,\n\t\tend: prevEndRef,\n\t};\n\trevertible.start.addProperties({ revertible });\n\trevertible.end.addProperties({ revertible });\n\trevertibles.push(revertible);\n\n\treturn revertibles;\n}\n\n/**\n * Create revertibles for changing properties of an interval\n * @legacy\n * @alpha\n */\nexport function appendIntervalPropertyChangedToRevertibles(\n\tinterval: SequenceInterval,\n\tdeltas: PropertySet,\n\trevertibles: SharedStringRevertible[],\n) {\n\trevertibles.push({\n\t\tevent: IntervalOpType.PROPERTY_CHANGED,\n\t\tinterval,\n\t\tpropertyDeltas: deltas,\n\t});\n\n\treturn revertibles;\n}\n\nfunction addIfIntervalEndpoint(\n\tref: LocalReferencePosition,\n\tsegmentLengths: number,\n\tstartIntervals: { offset: number; interval: SequenceInterval }[],\n\tendIntervals: { offset: number; interval: SequenceInterval }[],\n) {\n\tif (refTypeIncludesFlag(ref.refType, ReferenceType.RangeBegin)) {\n\t\tconst interval = ref.properties?.interval;\n\t\tif (interval && interval instanceof SequenceIntervalClass) {\n\t\t\tstartIntervals.push({ offset: segmentLengths + interval.start.getOffset(), interval });\n\t\t\treturn true;\n\t\t}\n\t} else if (refTypeIncludesFlag(ref.refType, ReferenceType.RangeEnd)) {\n\t\tconst interval = ref.properties?.interval;\n\t\tif (interval && interval instanceof SequenceIntervalClass) {\n\t\t\tendIntervals.push({ offset: segmentLengths + interval.end.getOffset(), interval });\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\nfunction addIfRevertibleRef(\n\tref: LocalReferencePosition,\n\tsegmentLengths: number,\n\trevertibleRefs: {\n\t\trevertible: IntervalRevertible;\n\t\toffset: number;\n\t\tisStart: boolean;\n\t}[],\n) {\n\tconst revertible = ref.properties?.revertible;\n\tif (revertible) {\n\t\trevertibleRefs.push({\n\t\t\trevertible,\n\t\t\toffset: segmentLengths + ref.getOffset(),\n\t\t\tisStart: refTypeIncludesFlag(ref.refType, ReferenceType.RangeBegin),\n\t\t});\n\t}\n}\n\n/**\n * Create revertibles for SharedStringDeltas, handling indirectly modified intervals\n * (e.g. reverting remove of a range that contains an interval will move the interval back)\n * @legacy\n * @alpha\n */\nexport function appendSharedStringDeltaToRevertibles(\n\tstring: ISharedString,\n\tdelta: SequenceDeltaEvent,\n\trevertibles: SharedStringRevertible[],\n) {\n\tif (delta.ranges.length === 0) {\n\t\treturn;\n\t}\n\tif (delta.deltaOperation === MergeTreeDeltaType.REMOVE) {\n\t\tconst startIntervals: { offset: number; interval: SequenceInterval }[] = [];\n\t\tconst endIntervals: { offset: number; interval: SequenceInterval }[] = [];\n\t\tconst revertibleRefs: {\n\t\t\trevertible: IntervalRevertible;\n\t\t\toffset: number;\n\t\t\tisStart: boolean;\n\t\t}[] = [];\n\t\tlet segmentLengths = 0;\n\n\t\t// find interval endpoints in each segment\n\t\tfor (const deltaRange of delta.ranges) {\n\t\t\tconst segment: ISegmentInternal = deltaRange.segment;\n\t\t\tconst refs = segment.localRefs;\n\t\t\tif (refs !== undefined && deltaRange.position !== -1) {\n\t\t\t\tfor (const ref of refs) {\n\t\t\t\t\taddIfIntervalEndpoint(ref, segmentLengths, startIntervals, endIntervals);\n\t\t\t\t\taddIfRevertibleRef(ref, segmentLengths, revertibleRefs);\n\t\t\t\t}\n\t\t\t}\n\t\t\tsegmentLengths += deltaRange.segment.cachedLength;\n\t\t}\n\n\t\tif (startIntervals.length > 0 || endIntervals.length > 0 || revertibleRefs.length > 0) {\n\t\t\tconst removeRevertibles: MergeTreeDeltaRevertible[] = [];\n\t\t\tappendToMergeTreeDeltaRevertibles(delta.deltaArgs, removeRevertibles);\n\t\t\tassert(\n\t\t\t\tremoveRevertibles.length === 1,\n\t\t\t\t0x6c4 /* Remove revertible should be a single delta */,\n\t\t\t);\n\n\t\t\tconst revertible: TypedRevertible<typeof IntervalOpType.POSITION_REMOVE> = {\n\t\t\t\tevent: IntervalOpType.POSITION_REMOVE,\n\t\t\t\tintervals: [],\n\t\t\t\trevertibleRefs,\n\t\t\t\tmergeTreeRevertible: removeRevertibles[0],\n\t\t\t};\n\n\t\t\t// add an interval for each startInterval, accounting for any corresponding endIntervals\n\t\t\tstartIntervals.forEach(({ interval, offset }) => {\n\t\t\t\t// find any corresponding end for this interval\n\t\t\t\tconst endIntervalIndex = endIntervals.findIndex((end) => {\n\t\t\t\t\treturn end.interval === interval;\n\t\t\t\t});\n\t\t\t\tlet endOffset: number | undefined;\n\t\t\t\tif (endIntervalIndex !== -1) {\n\t\t\t\t\tendOffset = endIntervals[endIntervalIndex].offset;\n\t\t\t\t\tendIntervals.splice(endIntervalIndex, 1);\n\t\t\t\t}\n\n\t\t\t\trevertible.intervals.push({\n\t\t\t\t\tintervalId: interval.getIntervalId(),\n\t\t\t\t\tlabel: interval.start.properties?.referenceRangeLabels[0],\n\t\t\t\t\tstartOffset: offset,\n\t\t\t\t\tendOffset,\n\t\t\t\t});\n\t\t\t});\n\n\t\t\t// add any remaining endIntervals that aren't matched with a startInterval\n\t\t\tendIntervals.forEach(({ interval, offset }) => {\n\t\t\t\trevertible.intervals.push({\n\t\t\t\t\tintervalId: interval.getIntervalId(),\n\t\t\t\t\tlabel: interval.start.properties?.referenceRangeLabels[0],\n\t\t\t\t\tendOffset: offset,\n\t\t\t\t});\n\t\t\t});\n\n\t\t\trevertibles.push(revertible);\n\t\t\treturn;\n\t\t}\n\t}\n\n\t// Handle any merge tree delta that is not REMOVE or is REMOVE with no interval endpoints\n\tconst mergeTreeRevertibles: MergeTreeDeltaRevertible[] = [];\n\t// Allow merging MergeTreeDeltaRevertible with previous\n\tif (\n\t\trevertibles.length > 0 &&\n\t\tisMergeTreeDeltaRevertible(revertibles[revertibles.length - 1])\n\t) {\n\t\tmergeTreeRevertibles.push(revertibles.pop() as MergeTreeDeltaRevertible);\n\t}\n\tappendToMergeTreeDeltaRevertibles(delta.deltaArgs, mergeTreeRevertibles);\n\trevertibles.push(...mergeTreeRevertibles);\n}\n\n/**\n * Clean up resources held by revertibles that are no longer needed.\n * @legacy\n * @alpha\n */\nexport function discardSharedStringRevertibles(\n\tsharedString: ISharedString,\n\trevertibles: SharedStringRevertible[],\n) {\n\trevertibles.forEach((r) => {\n\t\tif (isMergeTreeDeltaRevertible(r)) {\n\t\t\tdiscardMergeTreeDeltaRevertible([r]);\n\t\t} else if (r.event === IntervalOpType.CHANGE || r.event === IntervalOpType.DELETE) {\n\t\t\tsharedString.removeLocalReferencePosition(r.start);\n\t\t\tsharedString.removeLocalReferencePosition(r.end);\n\t\t}\n\t});\n}\n\nfunction getSlidePosition(\n\tstring: ISharedString,\n\tlref: LocalReferencePosition,\n\tpos: number,\n): number {\n\tconst slide = getSlideToSegoff(\n\t\t{ segment: lref.getSegment(), offset: undefined },\n\t\tlref.slidingPreference,\n\t);\n\treturn slide?.segment !== undefined &&\n\t\tslide.offset !== undefined &&\n\t\tstring.getPosition(slide.segment) !== -1 &&\n\t\t(pos < 0 || pos >= string.getLength())\n\t\t? string.getPosition(slide.segment) + slide.offset\n\t\t: pos;\n}\n\nfunction isValidRange(\n\tstart: number,\n\tstartSlide: SlidingPreference | undefined,\n\tend: number,\n\tendSlide: SlidingPreference | undefined,\n\tstring: ISharedString,\n) {\n\treturn (\n\t\tstart >= 0 &&\n\t\tstart < string.getLength() &&\n\t\tend >= 0 &&\n\t\tend < string.getLength() &&\n\t\t(start < end ||\n\t\t\t(start === end &&\n\t\t\t\t(startSlide === SlidingPreference.FORWARD || endSlide !== SlidingPreference.FORWARD)))\n\t);\n}\n\nfunction revertLocalAdd(\n\tstring: ISharedString,\n\trevertible: TypedRevertible<typeof IntervalOpType.ADD>,\n) {\n\tconst id = getUpdatedIdFromInterval(revertible.interval);\n\tconst label = revertible.interval.start.properties?.referenceRangeLabels[0];\n\tstring.getIntervalCollection(label).removeIntervalById(id);\n}\n\nfunction createSequencePlace(\n\tpos: number,\n\tnewSlidingPreference: SlidingPreference | undefined,\n\toldSlidingPreference: SlidingPreference | undefined = undefined,\n): number | InteriorSequencePlace {\n\treturn newSlidingPreference === SlidingPreference.BACKWARD ||\n\t\t(newSlidingPreference === undefined && oldSlidingPreference === SlidingPreference.BACKWARD)\n\t\t? {\n\t\t\t\tpos,\n\t\t\t\tside: Side.After,\n\t\t\t}\n\t\t: newSlidingPreference === SlidingPreference.FORWARD &&\n\t\t\t\toldSlidingPreference === SlidingPreference.BACKWARD\n\t\t\t? {\n\t\t\t\t\tpos,\n\t\t\t\t\tside: Side.Before,\n\t\t\t\t}\n\t\t\t: pos; // Avoid setting side if possible since stickiness may not be enabled\n}\n\nfunction revertLocalDelete(\n\tstring: ISharedString,\n\trevertible: TypedRevertible<typeof IntervalOpType.DELETE>,\n) {\n\tconst label = revertible.interval.start.properties?.referenceRangeLabels[0];\n\tconst collection = string.getIntervalCollection(label);\n\tconst start = string.localReferencePositionToPosition(revertible.start);\n\tconst startSlidePos = getSlidePosition(string, revertible.start, start);\n\tconst end = string.localReferencePositionToPosition(revertible.end);\n\tconst endSlidePos = getSlidePosition(string, revertible.end, end);\n\t// reusing the id causes eventual consistency bugs, so it is removed here and recreated in add\n\tconst { ...props } = revertible.interval.properties;\n\tconst intervalId = revertible.interval.getIntervalId();\n\tif (\n\t\tisValidRange(\n\t\t\tstartSlidePos,\n\t\t\trevertible.start.slidingPreference,\n\t\t\tendSlidePos,\n\t\t\trevertible.end.slidingPreference,\n\t\t\tstring,\n\t\t)\n\t) {\n\t\tconst int = collection.add({\n\t\t\tstart: createSequencePlace(startSlidePos, revertible.start.slidingPreference),\n\t\t\tend: createSequencePlace(endSlidePos, revertible.end.slidingPreference),\n\t\t\tprops,\n\t\t});\n\n\t\tidMap.forEach((newId, oldId) => {\n\t\t\tif (intervalId === newId) {\n\t\t\t\tidMap.set(oldId, getUpdatedIdFromInterval(int));\n\t\t\t}\n\t\t});\n\t\tidMap.set(intervalId, int.getIntervalId());\n\t}\n\n\tstring.removeLocalReferencePosition(revertible.start);\n\tstring.removeLocalReferencePosition(revertible.end);\n}\n\nfunction revertLocalChange(\n\tstring: ISharedString,\n\trevertible: TypedRevertible<typeof IntervalOpType.CHANGE>,\n) {\n\tconst label = revertible.interval.start.properties?.referenceRangeLabels[0];\n\tconst collection = string.getIntervalCollection(label);\n\tconst id = getUpdatedIdFromInterval(revertible.interval);\n\tconst start = string.localReferencePositionToPosition(revertible.start);\n\tconst startSlidePos = getSlidePosition(string, revertible.start, start);\n\tconst end = string.localReferencePositionToPosition(revertible.end);\n\tconst endSlidePos = getSlidePosition(string, revertible.end, end);\n\tconst interval = collection.getIntervalById(id);\n\tif (\n\t\tinterval !== undefined &&\n\t\tisValidRange(\n\t\t\tstartSlidePos,\n\t\t\trevertible.start.slidingPreference ?? interval.start.slidingPreference,\n\t\t\tendSlidePos,\n\t\t\trevertible.end.slidingPreference ?? interval.end.slidingPreference,\n\t\t\tstring,\n\t\t)\n\t) {\n\t\tcollection.change(id, {\n\t\t\tstart: createSequencePlace(\n\t\t\t\tstartSlidePos,\n\t\t\t\trevertible.start.slidingPreference,\n\t\t\t\tinterval.start.slidingPreference,\n\t\t\t),\n\t\t\tend: createSequencePlace(\n\t\t\t\tendSlidePos,\n\t\t\t\trevertible.end.slidingPreference,\n\t\t\t\tinterval.end.slidingPreference,\n\t\t\t),\n\t\t});\n\t}\n\n\tstring.removeLocalReferencePosition(revertible.start);\n\tstring.removeLocalReferencePosition(revertible.end);\n}\n\nfunction revertLocalPropertyChanged(\n\tstring: ISharedString,\n\trevertible: TypedRevertible<typeof IntervalOpType.PROPERTY_CHANGED>,\n) {\n\tconst label = revertible.interval.start.properties?.referenceRangeLabels[0];\n\tconst id = getUpdatedIdFromInterval(revertible.interval);\n\tconst newProps = revertible.propertyDeltas;\n\tstring.getIntervalCollection(label).change(id, { props: newProps });\n}\n\nfunction newPosition(offset: number | undefined, restoredRanges: SortedRangeSet) {\n\tif (offset === undefined) {\n\t\treturn undefined;\n\t}\n\n\tlet offsetFromSegment = offset;\n\tfor (const rangeInfo of restoredRanges.items) {\n\t\tif (offsetFromSegment < rangeInfo.length) {\n\t\t\t// find the segment inside the range\n\t\t\tfor (const range of rangeInfo.ranges) {\n\t\t\t\tif (range.segment.cachedLength > offsetFromSegment) {\n\t\t\t\t\treturn { segment: range.segment, offset: offsetFromSegment };\n\t\t\t\t}\n\t\t\t\toffsetFromSegment -= range.segment.cachedLength;\n\t\t\t}\n\t\t}\n\t\toffsetFromSegment -= rangeInfo.length;\n\t}\n\n\treturn undefined;\n}\n\nfunction newEndpointPosition(\n\toffset: number | undefined,\n\trestoredRanges: SortedRangeSet,\n\tsharedString: ISharedString,\n) {\n\tconst pos = newPosition(offset, restoredRanges);\n\treturn pos === undefined ? undefined : sharedString.getPosition(pos.segment) + pos.offset;\n}\n\ninterface RangeInfo {\n\tranges: readonly Readonly<ISequenceDeltaRange<MergeTreeDeltaOperationType>>[];\n\tlength: number;\n\tsegment: ISegment;\n}\n\n// eslint-disable-next-line import/no-deprecated\nclass SortedRangeSet extends SortedSegmentSet<RangeInfo> {}\n\nfunction revertLocalSequenceRemove(\n\tsharedString: ISharedString,\n\trevertible: TypedRevertible<typeof IntervalOpType.POSITION_REMOVE>,\n) {\n\tconst restoredRanges = new SortedRangeSet();\n\tconst saveSegments = (event: SequenceDeltaEvent) => {\n\t\tif (event.ranges.length > 0) {\n\t\t\tlet length = 0;\n\t\t\tevent.ranges.forEach((range) => {\n\t\t\t\tlength += range.segment.cachedLength;\n\t\t\t});\n\t\t\trestoredRanges.addOrUpdate({\n\t\t\t\tranges: event.ranges,\n\t\t\t\tlength,\n\t\t\t\tsegment: event.ranges[0].segment,\n\t\t\t});\n\t\t}\n\t};\n\tsharedString.on(\"sequenceDelta\", saveSegments);\n\trevertMergeTreeDeltaRevertibles(sharedString, [revertible.mergeTreeRevertible]);\n\tsharedString.off(\"sequenceDelta\", saveSegments);\n\n\trevertible.intervals.forEach((intervalInfo) => {\n\t\tconst intervalCollection = sharedString.getIntervalCollection(intervalInfo.label);\n\t\tconst intervalId = getUpdatedId(intervalInfo.intervalId);\n\t\tconst interval = intervalCollection.getIntervalById(intervalId);\n\t\tif (interval !== undefined) {\n\t\t\tconst start =\n\t\t\t\tnewEndpointPosition(intervalInfo.startOffset, restoredRanges, sharedString) ??\n\t\t\t\tsharedString.localReferencePositionToPosition(interval.start);\n\t\t\tconst end =\n\t\t\t\tnewEndpointPosition(intervalInfo.endOffset, restoredRanges, sharedString) ??\n\t\t\t\tsharedString.localReferencePositionToPosition(interval.end);\n\t\t\tif (\n\t\t\t\tisValidRange(\n\t\t\t\t\tstart,\n\t\t\t\t\tinterval.start.slidingPreference,\n\t\t\t\t\tend,\n\t\t\t\t\tinterval.end.slidingPreference,\n\t\t\t\t\tsharedString,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tintervalCollection.change(intervalId, {\n\t\t\t\t\tstart: createSequencePlace(start, interval.start.slidingPreference),\n\t\t\t\t\tend: createSequencePlace(end, interval.end.slidingPreference),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t});\n\n\t// fix up the local references used by delete and change revertibles\n\trevertible.revertibleRefs.forEach((revertibleRef) => {\n\t\tassert(\n\t\t\trevertibleRef.revertible.event === IntervalOpType.CHANGE ||\n\t\t\t\trevertibleRef.revertible.event === IntervalOpType.DELETE,\n\t\t\t0x6c5 /* revertible is not delete or change */,\n\t\t);\n\t\tconst pos = newPosition(revertibleRef.offset, restoredRanges);\n\t\tif (pos !== undefined) {\n\t\t\tif (revertibleRef.isStart) {\n\t\t\t\tsharedString.removeLocalReferencePosition(revertibleRef.revertible.start);\n\t\t\t\tconst newRef = sharedString.createLocalReferencePosition(\n\t\t\t\t\tpos.segment as SharedStringSegment,\n\t\t\t\t\tpos.offset,\n\t\t\t\t\tReferenceType.StayOnRemove | ReferenceType.RangeBegin,\n\t\t\t\t\t{ revertible: revertibleRef.revertible },\n\t\t\t\t\trevertibleRef.revertible.start.slidingPreference,\n\t\t\t\t);\n\t\t\t\trevertibleRef.revertible.start = newRef;\n\t\t\t} else {\n\t\t\t\tsharedString.removeLocalReferencePosition(revertibleRef.revertible.end);\n\t\t\t\tconst newRef = sharedString.createLocalReferencePosition(\n\t\t\t\t\tpos.segment as SharedStringSegment,\n\t\t\t\t\tpos.offset,\n\t\t\t\t\tReferenceType.StayOnRemove | ReferenceType.RangeEnd,\n\t\t\t\t\t{ revertible: revertibleRef.revertible },\n\t\t\t\t\trevertibleRef.revertible.end.slidingPreference,\n\t\t\t\t);\n\t\t\t\trevertibleRef.revertible.end = newRef;\n\t\t\t}\n\t\t}\n\t});\n}\n\n/**\n * Invoke revertibles to reverse prior edits\n * @legacy\n * @alpha\n */\nexport function revertSharedStringRevertibles(\n\tsharedString: ISharedString,\n\trevertibles: SharedStringRevertible[],\n) {\n\twhile (revertibles.length > 0) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst r = revertibles.pop()!;\n\t\tif (\"event\" in r) {\n\t\t\tconst event = r.event;\n\t\t\tswitch (event) {\n\t\t\t\tcase IntervalOpType.ADD:\n\t\t\t\t\trevertLocalAdd(sharedString, r);\n\t\t\t\t\tbreak;\n\t\t\t\tcase IntervalOpType.DELETE:\n\t\t\t\t\trevertLocalDelete(sharedString, r);\n\t\t\t\t\tbreak;\n\t\t\t\tcase IntervalOpType.CHANGE:\n\t\t\t\t\trevertLocalChange(sharedString, r);\n\t\t\t\t\tbreak;\n\t\t\t\tcase IntervalOpType.PROPERTY_CHANGED:\n\t\t\t\t\trevertLocalPropertyChanged(sharedString, r);\n\t\t\t\t\tbreak;\n\t\t\t\tcase IntervalOpType.POSITION_REMOVE:\n\t\t\t\t\trevertLocalSequenceRemove(sharedString, r);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tunreachableCase(event);\n\t\t\t}\n\t\t} else {\n\t\t\trevertMergeTreeDeltaRevertibles(sharedString, [r]);\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"revertibles.js","sourceRoot":"","sources":["../src/revertibles.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AAK,yBAAc,CAAC,MAAM;oBACzB,iBAAiB,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;oBACnC,MAAM;gBACP,KAAK,yBAAc,CAAC,gBAAgB;oBACnC,0BAA0B,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;oBAC5C,MAAM;gBACP,KAAK,yBAAc,CAAC,eAAe;oBAClC,yBAAyB,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;oBAC3C,MAAM;gBACP;oBACC,IAAA,0BAAe,EAAC,KAAK,CAAC,CAAC;YACzB,CAAC;QACF,CAAC;aAAM,CAAC;YACP,IAAA,0CAA+B,EAAC,YAAY,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QACpD,CAAC;IACF,CAAC;AACF,CAAC;AAhCD,sEAgCC","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, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport {\n\tLocalReferencePosition,\n\tMergeTreeDeltaOperationType,\n\tMergeTreeDeltaRevertible,\n\tMergeTreeDeltaType,\n\tPropertySet,\n\tReferenceType,\n\tSlidingPreference, // eslint-disable-next-line import/no-deprecated\n\tappendToMergeTreeDeltaRevertibles,\n\tdiscardMergeTreeDeltaRevertible,\n\tgetSlideToSegoff,\n\tisMergeTreeDeltaRevertible,\n\trefTypeIncludesFlag,\n\trevertMergeTreeDeltaRevertibles,\n\tInteriorSequencePlace,\n\tSide,\n\ttype ISegmentInternal,\n\tsegmentIsRemoved,\n\tSortedSegmentSet,\n\ttype ISegment,\n} from \"@fluidframework/merge-tree/internal\";\n\nimport { IntervalOpType, SequenceInterval, SequenceIntervalClass } from \"./intervals/index.js\";\nimport { ISequenceDeltaRange, SequenceDeltaEvent } from \"./sequenceDeltaEvent.js\";\nimport { ISharedString, SharedStringSegment } from \"./sharedString.js\";\n\n/**\n * Data for undoing edits on SharedStrings and Intervals.\n * @legacy\n * @alpha\n */\nexport type SharedStringRevertible = MergeTreeDeltaRevertible | IntervalRevertible;\n\nconst idMap = new Map<string, string>();\n\n/**\n * Data for undoing edits affecting Intervals.\n * @legacy\n * @alpha\n */\nexport type IntervalRevertible =\n\t| {\n\t\t\tevent: typeof IntervalOpType.CHANGE;\n\t\t\tinterval: SequenceInterval;\n\t\t\tstart: LocalReferencePosition;\n\t\t\tend: LocalReferencePosition;\n\t }\n\t| {\n\t\t\tevent: typeof IntervalOpType.ADD;\n\t\t\tinterval: SequenceInterval;\n\t }\n\t| {\n\t\t\tevent: typeof IntervalOpType.DELETE;\n\t\t\tinterval: SequenceInterval;\n\t\t\tstart: LocalReferencePosition;\n\t\t\tend: LocalReferencePosition;\n\t }\n\t| {\n\t\t\tevent: typeof IntervalOpType.PROPERTY_CHANGED;\n\t\t\tinterval: SequenceInterval;\n\t\t\tpropertyDeltas: PropertySet;\n\t }\n\t| {\n\t\t\tevent: typeof IntervalOpType.POSITION_REMOVE;\n\t\t\tintervals: {\n\t\t\t\tintervalId: string;\n\t\t\t\tlabel: string;\n\t\t\t\tstartOffset?: number; // interval start index within a removed range\n\t\t\t\tendOffset?: number; // interval end index within a removed range\n\t\t\t}[];\n\t\t\t// local refs used by IntervalOpType.CHANGE and DELETE revertibles\n\t\t\trevertibleRefs: {\n\t\t\t\trevertible: IntervalRevertible;\n\t\t\t\toffset: number;\n\t\t\t\tisStart: boolean;\n\t\t\t}[];\n\t\t\tmergeTreeRevertible: MergeTreeDeltaRevertible;\n\t };\n\ntype TypedRevertible<T extends IntervalRevertible[\"event\"]> = IntervalRevertible & {\n\tevent: T;\n};\n\nfunction getUpdatedIdFromInterval(interval: SequenceInterval): string {\n\tconst maybeId = interval.getIntervalId();\n\treturn getUpdatedId(maybeId);\n}\n\nfunction getUpdatedId(intervalId: string): string {\n\treturn idMap.get(intervalId) ?? intervalId;\n}\n\n/**\n * Create revertibles for adding an interval\n * @legacy\n * @alpha\n */\nexport function appendAddIntervalToRevertibles(\n\tinterval: SequenceInterval,\n\trevertibles: SharedStringRevertible[],\n) {\n\trevertibles.push({\n\t\tevent: IntervalOpType.ADD,\n\t\tinterval,\n\t});\n\n\treturn revertibles;\n}\n\n/**\n * Create revertibles for deleting an interval\n * @legacy\n * @alpha\n */\nexport function appendDeleteIntervalToRevertibles(\n\tstring: ISharedString,\n\tinterval: SequenceInterval,\n\trevertibles: SharedStringRevertible[],\n): SharedStringRevertible[] {\n\tconst startSeg = interval.start.getSegment() as SharedStringSegment | undefined;\n\tif (!startSeg) {\n\t\treturn revertibles;\n\t}\n\tconst startType = segmentIsRemoved(startSeg)\n\t\t? ReferenceType.SlideOnRemove | ReferenceType.RangeBegin\n\t\t: ReferenceType.StayOnRemove | ReferenceType.RangeBegin;\n\tconst endSeg = interval.end.getSegment() as SharedStringSegment | undefined;\n\tif (!endSeg) {\n\t\treturn revertibles;\n\t}\n\tconst endType = segmentIsRemoved(startSeg)\n\t\t? ReferenceType.SlideOnRemove | ReferenceType.RangeEnd\n\t\t: ReferenceType.StayOnRemove | ReferenceType.RangeEnd;\n\tconst startRef = string.createLocalReferencePosition(\n\t\tstartSeg,\n\t\tinterval.start.getOffset(),\n\t\tstartType,\n\t\tundefined,\n\t\tinterval.start.slidingPreference,\n\t);\n\tconst endRef = string.createLocalReferencePosition(\n\t\tendSeg,\n\t\tinterval.end.getOffset(),\n\t\tendType,\n\t\tundefined,\n\t\tinterval.end.slidingPreference,\n\t);\n\tconst revertible = {\n\t\tevent: IntervalOpType.DELETE,\n\t\tinterval,\n\t\tstart: startRef,\n\t\tend: endRef,\n\t};\n\trevertible.start.addProperties({ revertible });\n\trevertible.end.addProperties({ revertible });\n\trevertibles.push(revertible);\n\n\treturn revertibles;\n}\n\n/**\n * Create revertibles for moving endpoints of an interval\n * @legacy\n * @alpha\n */\nexport function appendChangeIntervalToRevertibles(\n\tstring: ISharedString,\n\tnewInterval: SequenceInterval,\n\tpreviousInterval: SequenceInterval,\n\trevertibles: SharedStringRevertible[],\n) {\n\tconst startSeg = previousInterval.start.getSegment() as SharedStringSegment;\n\t// This logic is needed because the ReferenceType StayOnRemove cannot be used\n\t// on removed segments. This works for revertibles because the old position of the\n\t// interval within the removed segment is handled by the remove range revertible.\n\tconst startType = segmentIsRemoved(startSeg)\n\t\t? ReferenceType.SlideOnRemove | ReferenceType.RangeBegin\n\t\t: ReferenceType.StayOnRemove | ReferenceType.RangeBegin;\n\tconst endSeg = previousInterval.end.getSegment() as SharedStringSegment;\n\tconst endType = segmentIsRemoved(startSeg)\n\t\t? ReferenceType.SlideOnRemove | ReferenceType.RangeEnd\n\t\t: ReferenceType.StayOnRemove | ReferenceType.RangeEnd;\n\tconst prevStartRef = string.createLocalReferencePosition(\n\t\tstartSeg,\n\t\tpreviousInterval.start.getOffset(),\n\t\tstartType,\n\t\tundefined,\n\t\tpreviousInterval.start.slidingPreference,\n\t);\n\tconst prevEndRef = string.createLocalReferencePosition(\n\t\tendSeg,\n\t\tpreviousInterval.end.getOffset(),\n\t\tendType,\n\t\tundefined,\n\t\tpreviousInterval.end.slidingPreference,\n\t);\n\tconst revertible = {\n\t\tevent: IntervalOpType.CHANGE,\n\t\tinterval: newInterval,\n\t\tstart: prevStartRef,\n\t\tend: prevEndRef,\n\t};\n\trevertible.start.addProperties({ revertible });\n\trevertible.end.addProperties({ revertible });\n\trevertibles.push(revertible);\n\n\treturn revertibles;\n}\n\n/**\n * Create revertibles for changing properties of an interval\n * @legacy\n * @alpha\n */\nexport function appendIntervalPropertyChangedToRevertibles(\n\tinterval: SequenceInterval,\n\tdeltas: PropertySet,\n\trevertibles: SharedStringRevertible[],\n) {\n\trevertibles.push({\n\t\tevent: IntervalOpType.PROPERTY_CHANGED,\n\t\tinterval,\n\t\tpropertyDeltas: deltas,\n\t});\n\n\treturn revertibles;\n}\n\nfunction addIfIntervalEndpoint(\n\tref: LocalReferencePosition,\n\tsegmentLengths: number,\n\tstartIntervals: { offset: number; interval: SequenceInterval }[],\n\tendIntervals: { offset: number; interval: SequenceInterval }[],\n) {\n\tif (refTypeIncludesFlag(ref.refType, ReferenceType.RangeBegin)) {\n\t\tconst interval = ref.properties?.interval;\n\t\tif (interval && interval instanceof SequenceIntervalClass) {\n\t\t\tstartIntervals.push({ offset: segmentLengths + interval.start.getOffset(), interval });\n\t\t\treturn true;\n\t\t}\n\t} else if (refTypeIncludesFlag(ref.refType, ReferenceType.RangeEnd)) {\n\t\tconst interval = ref.properties?.interval;\n\t\tif (interval && interval instanceof SequenceIntervalClass) {\n\t\t\tendIntervals.push({ offset: segmentLengths + interval.end.getOffset(), interval });\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\nfunction addIfRevertibleRef(\n\tref: LocalReferencePosition,\n\tsegmentLengths: number,\n\trevertibleRefs: {\n\t\trevertible: IntervalRevertible;\n\t\toffset: number;\n\t\tisStart: boolean;\n\t}[],\n) {\n\tconst revertible = ref.properties?.revertible;\n\tif (revertible) {\n\t\trevertibleRefs.push({\n\t\t\trevertible,\n\t\t\toffset: segmentLengths + ref.getOffset(),\n\t\t\tisStart: refTypeIncludesFlag(ref.refType, ReferenceType.RangeBegin),\n\t\t});\n\t}\n}\n\n/**\n * Create revertibles for SharedStringDeltas, handling indirectly modified intervals\n * (e.g. reverting remove of a range that contains an interval will move the interval back)\n * @legacy\n * @alpha\n */\nexport function appendSharedStringDeltaToRevertibles(\n\tstring: ISharedString,\n\tdelta: SequenceDeltaEvent,\n\trevertibles: SharedStringRevertible[],\n) {\n\tif (delta.ranges.length === 0) {\n\t\treturn;\n\t}\n\tif (delta.deltaOperation === MergeTreeDeltaType.REMOVE) {\n\t\tconst startIntervals: { offset: number; interval: SequenceInterval }[] = [];\n\t\tconst endIntervals: { offset: number; interval: SequenceInterval }[] = [];\n\t\tconst revertibleRefs: {\n\t\t\trevertible: IntervalRevertible;\n\t\t\toffset: number;\n\t\t\tisStart: boolean;\n\t\t}[] = [];\n\t\tlet segmentLengths = 0;\n\n\t\t// find interval endpoints in each segment\n\t\tfor (const deltaRange of delta.ranges) {\n\t\t\tconst segment: ISegmentInternal = deltaRange.segment;\n\t\t\tconst refs = segment.localRefs;\n\t\t\tif (refs !== undefined && deltaRange.position !== -1) {\n\t\t\t\tfor (const ref of refs) {\n\t\t\t\t\taddIfIntervalEndpoint(ref, segmentLengths, startIntervals, endIntervals);\n\t\t\t\t\taddIfRevertibleRef(ref, segmentLengths, revertibleRefs);\n\t\t\t\t}\n\t\t\t}\n\t\t\tsegmentLengths += deltaRange.segment.cachedLength;\n\t\t}\n\n\t\tif (startIntervals.length > 0 || endIntervals.length > 0 || revertibleRefs.length > 0) {\n\t\t\tconst removeRevertibles: MergeTreeDeltaRevertible[] = [];\n\t\t\tappendToMergeTreeDeltaRevertibles(delta.deltaArgs, removeRevertibles);\n\t\t\tassert(\n\t\t\t\tremoveRevertibles.length === 1,\n\t\t\t\t0x6c4 /* Remove revertible should be a single delta */,\n\t\t\t);\n\n\t\t\tconst revertible: TypedRevertible<typeof IntervalOpType.POSITION_REMOVE> = {\n\t\t\t\tevent: IntervalOpType.POSITION_REMOVE,\n\t\t\t\tintervals: [],\n\t\t\t\trevertibleRefs,\n\t\t\t\tmergeTreeRevertible: removeRevertibles[0],\n\t\t\t};\n\n\t\t\t// add an interval for each startInterval, accounting for any corresponding endIntervals\n\t\t\tstartIntervals.forEach(({ interval, offset }) => {\n\t\t\t\t// find any corresponding end for this interval\n\t\t\t\tconst endIntervalIndex = endIntervals.findIndex((end) => {\n\t\t\t\t\treturn end.interval === interval;\n\t\t\t\t});\n\t\t\t\tlet endOffset: number | undefined;\n\t\t\t\tif (endIntervalIndex !== -1) {\n\t\t\t\t\tendOffset = endIntervals[endIntervalIndex].offset;\n\t\t\t\t\tendIntervals.splice(endIntervalIndex, 1);\n\t\t\t\t}\n\n\t\t\t\trevertible.intervals.push({\n\t\t\t\t\tintervalId: interval.getIntervalId(),\n\t\t\t\t\tlabel: interval.start.properties?.referenceRangeLabels[0],\n\t\t\t\t\tstartOffset: offset,\n\t\t\t\t\tendOffset,\n\t\t\t\t});\n\t\t\t});\n\n\t\t\t// add any remaining endIntervals that aren't matched with a startInterval\n\t\t\tendIntervals.forEach(({ interval, offset }) => {\n\t\t\t\trevertible.intervals.push({\n\t\t\t\t\tintervalId: interval.getIntervalId(),\n\t\t\t\t\tlabel: interval.start.properties?.referenceRangeLabels[0],\n\t\t\t\t\tendOffset: offset,\n\t\t\t\t});\n\t\t\t});\n\n\t\t\trevertibles.push(revertible);\n\t\t\treturn;\n\t\t}\n\t}\n\n\t// Handle any merge tree delta that is not REMOVE or is REMOVE with no interval endpoints\n\tconst mergeTreeRevertibles: MergeTreeDeltaRevertible[] = [];\n\t// Allow merging MergeTreeDeltaRevertible with previous\n\tif (\n\t\trevertibles.length > 0 &&\n\t\tisMergeTreeDeltaRevertible(revertibles[revertibles.length - 1])\n\t) {\n\t\tmergeTreeRevertibles.push(revertibles.pop() as MergeTreeDeltaRevertible);\n\t}\n\tappendToMergeTreeDeltaRevertibles(delta.deltaArgs, mergeTreeRevertibles);\n\trevertibles.push(...mergeTreeRevertibles);\n}\n\n/**\n * Clean up resources held by revertibles that are no longer needed.\n * @legacy\n * @alpha\n */\nexport function discardSharedStringRevertibles(\n\tsharedString: ISharedString,\n\trevertibles: SharedStringRevertible[],\n) {\n\trevertibles.forEach((r) => {\n\t\tif (isMergeTreeDeltaRevertible(r)) {\n\t\t\tdiscardMergeTreeDeltaRevertible([r]);\n\t\t} else if (r.event === IntervalOpType.CHANGE || r.event === IntervalOpType.DELETE) {\n\t\t\tsharedString.removeLocalReferencePosition(r.start);\n\t\t\tsharedString.removeLocalReferencePosition(r.end);\n\t\t}\n\t});\n}\n\nfunction getSlidePosition(\n\tstring: ISharedString,\n\tlref: LocalReferencePosition,\n\tpos: number,\n): number {\n\tconst segment = lref.getSegment();\n\tconst offset = lref.getOffset();\n\tconst slide =\n\t\tsegment === undefined\n\t\t\t? undefined\n\t\t\t: getSlideToSegoff({ segment, offset }, lref.slidingPreference);\n\treturn slide !== undefined &&\n\t\tstring.getPosition(slide.segment) !== -1 &&\n\t\t(pos < 0 || pos >= string.getLength())\n\t\t? string.getPosition(slide.segment) + slide.offset\n\t\t: pos;\n}\n\nfunction isValidRange(\n\tstart: number,\n\tstartSlide: SlidingPreference | undefined,\n\tend: number,\n\tendSlide: SlidingPreference | undefined,\n\tstring: ISharedString,\n) {\n\treturn (\n\t\tstart >= 0 &&\n\t\tstart < string.getLength() &&\n\t\tend >= 0 &&\n\t\tend < string.getLength() &&\n\t\t(start < end ||\n\t\t\t(start === end &&\n\t\t\t\t(startSlide === SlidingPreference.FORWARD || endSlide !== SlidingPreference.FORWARD)))\n\t);\n}\n\nfunction revertLocalAdd(\n\tstring: ISharedString,\n\trevertible: TypedRevertible<typeof IntervalOpType.ADD>,\n) {\n\tconst id = getUpdatedIdFromInterval(revertible.interval);\n\tconst label = revertible.interval.start.properties?.referenceRangeLabels[0];\n\tstring.getIntervalCollection(label).removeIntervalById(id);\n}\n\nfunction createSequencePlace(\n\tpos: number,\n\tnewSlidingPreference: SlidingPreference | undefined,\n\toldSlidingPreference: SlidingPreference | undefined = undefined,\n): number | InteriorSequencePlace {\n\treturn newSlidingPreference === SlidingPreference.BACKWARD ||\n\t\t(newSlidingPreference === undefined && oldSlidingPreference === SlidingPreference.BACKWARD)\n\t\t? {\n\t\t\t\tpos,\n\t\t\t\tside: Side.After,\n\t\t\t}\n\t\t: newSlidingPreference === SlidingPreference.FORWARD &&\n\t\t\t\toldSlidingPreference === SlidingPreference.BACKWARD\n\t\t\t? {\n\t\t\t\t\tpos,\n\t\t\t\t\tside: Side.Before,\n\t\t\t\t}\n\t\t\t: pos; // Avoid setting side if possible since stickiness may not be enabled\n}\n\nfunction revertLocalDelete(\n\tstring: ISharedString,\n\trevertible: TypedRevertible<typeof IntervalOpType.DELETE>,\n) {\n\tconst label = revertible.interval.start.properties?.referenceRangeLabels[0];\n\tconst collection = string.getIntervalCollection(label);\n\tconst start = string.localReferencePositionToPosition(revertible.start);\n\tconst startSlidePos = getSlidePosition(string, revertible.start, start);\n\tconst end = string.localReferencePositionToPosition(revertible.end);\n\tconst endSlidePos = getSlidePosition(string, revertible.end, end);\n\t// reusing the id causes eventual consistency bugs, so it is removed here and recreated in add\n\tconst { ...props } = revertible.interval.properties;\n\tconst intervalId = revertible.interval.getIntervalId();\n\tif (\n\t\tisValidRange(\n\t\t\tstartSlidePos,\n\t\t\trevertible.start.slidingPreference,\n\t\t\tendSlidePos,\n\t\t\trevertible.end.slidingPreference,\n\t\t\tstring,\n\t\t)\n\t) {\n\t\tconst int = collection.add({\n\t\t\tstart: createSequencePlace(startSlidePos, revertible.start.slidingPreference),\n\t\t\tend: createSequencePlace(endSlidePos, revertible.end.slidingPreference),\n\t\t\tprops,\n\t\t});\n\n\t\tidMap.forEach((newId, oldId) => {\n\t\t\tif (intervalId === newId) {\n\t\t\t\tidMap.set(oldId, getUpdatedIdFromInterval(int));\n\t\t\t}\n\t\t});\n\t\tidMap.set(intervalId, int.getIntervalId());\n\t}\n\n\tstring.removeLocalReferencePosition(revertible.start);\n\tstring.removeLocalReferencePosition(revertible.end);\n}\n\nfunction revertLocalChange(\n\tstring: ISharedString,\n\trevertible: TypedRevertible<typeof IntervalOpType.CHANGE>,\n) {\n\tconst label = revertible.interval.start.properties?.referenceRangeLabels[0];\n\tconst collection = string.getIntervalCollection(label);\n\tconst id = getUpdatedIdFromInterval(revertible.interval);\n\tconst start = string.localReferencePositionToPosition(revertible.start);\n\tconst startSlidePos = getSlidePosition(string, revertible.start, start);\n\tconst end = string.localReferencePositionToPosition(revertible.end);\n\tconst endSlidePos = getSlidePosition(string, revertible.end, end);\n\tconst interval = collection.getIntervalById(id);\n\tif (\n\t\tinterval !== undefined &&\n\t\tisValidRange(\n\t\t\tstartSlidePos,\n\t\t\trevertible.start.slidingPreference ?? interval.start.slidingPreference,\n\t\t\tendSlidePos,\n\t\t\trevertible.end.slidingPreference ?? interval.end.slidingPreference,\n\t\t\tstring,\n\t\t)\n\t) {\n\t\tcollection.change(id, {\n\t\t\tstart: createSequencePlace(\n\t\t\t\tstartSlidePos,\n\t\t\t\trevertible.start.slidingPreference,\n\t\t\t\tinterval.start.slidingPreference,\n\t\t\t),\n\t\t\tend: createSequencePlace(\n\t\t\t\tendSlidePos,\n\t\t\t\trevertible.end.slidingPreference,\n\t\t\t\tinterval.end.slidingPreference,\n\t\t\t),\n\t\t});\n\t}\n\n\tstring.removeLocalReferencePosition(revertible.start);\n\tstring.removeLocalReferencePosition(revertible.end);\n}\n\nfunction revertLocalPropertyChanged(\n\tstring: ISharedString,\n\trevertible: TypedRevertible<typeof IntervalOpType.PROPERTY_CHANGED>,\n) {\n\tconst label = revertible.interval.start.properties?.referenceRangeLabels[0];\n\tconst id = getUpdatedIdFromInterval(revertible.interval);\n\tconst newProps = revertible.propertyDeltas;\n\tstring.getIntervalCollection(label).change(id, { props: newProps });\n}\n\nfunction newPosition(offset: number | undefined, restoredRanges: SortedRangeSet) {\n\tif (offset === undefined) {\n\t\treturn undefined;\n\t}\n\n\tlet offsetFromSegment = offset;\n\tfor (const rangeInfo of restoredRanges.items) {\n\t\tif (offsetFromSegment < rangeInfo.length) {\n\t\t\t// find the segment inside the range\n\t\t\tfor (const range of rangeInfo.ranges) {\n\t\t\t\tif (range.segment.cachedLength > offsetFromSegment) {\n\t\t\t\t\treturn { segment: range.segment, offset: offsetFromSegment };\n\t\t\t\t}\n\t\t\t\toffsetFromSegment -= range.segment.cachedLength;\n\t\t\t}\n\t\t}\n\t\toffsetFromSegment -= rangeInfo.length;\n\t}\n\n\treturn undefined;\n}\n\nfunction newEndpointPosition(\n\toffset: number | undefined,\n\trestoredRanges: SortedRangeSet,\n\tsharedString: ISharedString,\n) {\n\tconst pos = newPosition(offset, restoredRanges);\n\treturn pos === undefined ? undefined : sharedString.getPosition(pos.segment) + pos.offset;\n}\n\ninterface RangeInfo {\n\tranges: readonly Readonly<ISequenceDeltaRange<MergeTreeDeltaOperationType>>[];\n\tlength: number;\n\tsegment: ISegment;\n}\n\n// eslint-disable-next-line import/no-deprecated\nclass SortedRangeSet extends SortedSegmentSet<RangeInfo> {}\n\nfunction revertLocalSequenceRemove(\n\tsharedString: ISharedString,\n\trevertible: TypedRevertible<typeof IntervalOpType.POSITION_REMOVE>,\n) {\n\tconst restoredRanges = new SortedRangeSet();\n\tconst saveSegments = (event: SequenceDeltaEvent) => {\n\t\tif (event.ranges.length > 0) {\n\t\t\tlet length = 0;\n\t\t\tevent.ranges.forEach((range) => {\n\t\t\t\tlength += range.segment.cachedLength;\n\t\t\t});\n\t\t\trestoredRanges.addOrUpdate({\n\t\t\t\tranges: event.ranges,\n\t\t\t\tlength,\n\t\t\t\tsegment: event.ranges[0].segment,\n\t\t\t});\n\t\t}\n\t};\n\tsharedString.on(\"sequenceDelta\", saveSegments);\n\trevertMergeTreeDeltaRevertibles(sharedString, [revertible.mergeTreeRevertible]);\n\tsharedString.off(\"sequenceDelta\", saveSegments);\n\n\trevertible.intervals.forEach((intervalInfo) => {\n\t\tconst intervalCollection = sharedString.getIntervalCollection(intervalInfo.label);\n\t\tconst intervalId = getUpdatedId(intervalInfo.intervalId);\n\t\tconst interval = intervalCollection.getIntervalById(intervalId);\n\t\tif (interval !== undefined) {\n\t\t\tconst start =\n\t\t\t\tnewEndpointPosition(intervalInfo.startOffset, restoredRanges, sharedString) ??\n\t\t\t\tsharedString.localReferencePositionToPosition(interval.start);\n\t\t\tconst end =\n\t\t\t\tnewEndpointPosition(intervalInfo.endOffset, restoredRanges, sharedString) ??\n\t\t\t\tsharedString.localReferencePositionToPosition(interval.end);\n\t\t\tif (\n\t\t\t\tisValidRange(\n\t\t\t\t\tstart,\n\t\t\t\t\tinterval.start.slidingPreference,\n\t\t\t\t\tend,\n\t\t\t\t\tinterval.end.slidingPreference,\n\t\t\t\t\tsharedString,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tintervalCollection.change(intervalId, {\n\t\t\t\t\tstart: createSequencePlace(start, interval.start.slidingPreference),\n\t\t\t\t\tend: createSequencePlace(end, interval.end.slidingPreference),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t});\n\n\t// fix up the local references used by delete and change revertibles\n\trevertible.revertibleRefs.forEach((revertibleRef) => {\n\t\tassert(\n\t\t\trevertibleRef.revertible.event === IntervalOpType.CHANGE ||\n\t\t\t\trevertibleRef.revertible.event === IntervalOpType.DELETE,\n\t\t\t0x6c5 /* revertible is not delete or change */,\n\t\t);\n\t\tconst pos = newPosition(revertibleRef.offset, restoredRanges);\n\t\tif (pos !== undefined) {\n\t\t\tif (revertibleRef.isStart) {\n\t\t\t\tsharedString.removeLocalReferencePosition(revertibleRef.revertible.start);\n\t\t\t\tconst newRef = sharedString.createLocalReferencePosition(\n\t\t\t\t\tpos.segment as SharedStringSegment,\n\t\t\t\t\tpos.offset,\n\t\t\t\t\tReferenceType.StayOnRemove | ReferenceType.RangeBegin,\n\t\t\t\t\t{ revertible: revertibleRef.revertible },\n\t\t\t\t\trevertibleRef.revertible.start.slidingPreference,\n\t\t\t\t);\n\t\t\t\trevertibleRef.revertible.start = newRef;\n\t\t\t} else {\n\t\t\t\tsharedString.removeLocalReferencePosition(revertibleRef.revertible.end);\n\t\t\t\tconst newRef = sharedString.createLocalReferencePosition(\n\t\t\t\t\tpos.segment as SharedStringSegment,\n\t\t\t\t\tpos.offset,\n\t\t\t\t\tReferenceType.StayOnRemove | ReferenceType.RangeEnd,\n\t\t\t\t\t{ revertible: revertibleRef.revertible },\n\t\t\t\t\trevertibleRef.revertible.end.slidingPreference,\n\t\t\t\t);\n\t\t\t\trevertibleRef.revertible.end = newRef;\n\t\t\t}\n\t\t}\n\t});\n}\n\n/**\n * Invoke revertibles to reverse prior edits\n * @legacy\n * @alpha\n */\nexport function revertSharedStringRevertibles(\n\tsharedString: ISharedString,\n\trevertibles: SharedStringRevertible[],\n) {\n\twhile (revertibles.length > 0) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst r = revertibles.pop()!;\n\t\tif (\"event\" in r) {\n\t\t\tconst event = r.event;\n\t\t\tswitch (event) {\n\t\t\t\tcase IntervalOpType.ADD:\n\t\t\t\t\trevertLocalAdd(sharedString, r);\n\t\t\t\t\tbreak;\n\t\t\t\tcase IntervalOpType.DELETE:\n\t\t\t\t\trevertLocalDelete(sharedString, r);\n\t\t\t\t\tbreak;\n\t\t\t\tcase IntervalOpType.CHANGE:\n\t\t\t\t\trevertLocalChange(sharedString, r);\n\t\t\t\t\tbreak;\n\t\t\t\tcase IntervalOpType.PROPERTY_CHANGED:\n\t\t\t\t\trevertLocalPropertyChanged(sharedString, r);\n\t\t\t\t\tbreak;\n\t\t\t\tcase IntervalOpType.POSITION_REMOVE:\n\t\t\t\t\trevertLocalSequenceRemove(sharedString, r);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tunreachableCase(event);\n\t\t\t}\n\t\t} else {\n\t\t\trevertMergeTreeDeltaRevertibles(sharedString, [r]);\n\t\t}\n\t}\n}\n"]}
|
package/dist/sequence.d.ts
CHANGED
|
@@ -349,7 +349,8 @@ export declare abstract class SharedSegmentSequence<T extends ISegment> extends
|
|
|
349
349
|
/**
|
|
350
350
|
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.reSubmitCore}
|
|
351
351
|
*/
|
|
352
|
-
protected reSubmitCore(content: any, localOpMetadata: unknown): void;
|
|
352
|
+
protected reSubmitCore(content: any, localOpMetadata: unknown, squash?: boolean): void;
|
|
353
|
+
protected reSubmitSquashed(content: unknown, localOpMetadata: unknown): void;
|
|
353
354
|
/**
|
|
354
355
|
* Revert an op
|
|
355
356
|
*/
|
package/dist/sequence.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sequence.d.ts","sourceRoot":"","sources":["../src/sequence.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAExE,OAAO,EACN,kBAAkB,EAClB,s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S,CAAC,YAAY;IAEtB;;OAEG;IACH,SAAS,CAAC,YAAY,CAAC,OAAO,EAAE,GAAG,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,GAAE,OAAe;IAetF,SAAS,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO,GAAG,IAAI;IAI5E;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE,eAAe,EAAE,OAAO,GAAG,IAAI;IAYhE;;OAEG;cACa,QAAQ,CAAC,OAAO,EAAE,sBAAsB;IAoDxD;;OAEG;IACH,SAAS,CAAC,WAAW,CACpB,OAAO,EAAE,yBAAyB,EAClC,KAAK,EAAE,OAAO,EACd,eAAe,EAAE,OAAO;IA+BzB;;OAEG;IACH,SAAS,CAAC,SAAS;IAQnB;;OAEG;IACH,SAAS,CAAC,mBAAmB;IAK7B;;OAEG;IACH,SAAS,CAAC,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,IAAI;IAM5C,OAAO,CAAC,kBAAkB;IAiB1B;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAwC3B,OAAO,CAAC,+BAA+B;IAYvC,OAAO,CAAC,6BAA6B;IAoBrC;;;OAGG;IACH,OAAO,CAAC,iBAAiB;CASzB;AA4BD;;GAEG;AACH,wBAAgB,yBAAyB,SAExC"}
|
package/dist/sequence.js
CHANGED
|
@@ -162,7 +162,7 @@ class SharedSegmentSequence extends internal_5.SharedObject {
|
|
|
162
162
|
this.guardReentrancy(() => this.client.localTransaction(groupOp));
|
|
163
163
|
}
|
|
164
164
|
getContainingSegment(pos) {
|
|
165
|
-
return this.client.getContainingSegment(pos);
|
|
165
|
+
return (this.client.getContainingSegment(pos) ?? { segment: undefined, offset: undefined });
|
|
166
166
|
}
|
|
167
167
|
getLength() {
|
|
168
168
|
return this.client.getLength();
|
|
@@ -279,15 +279,18 @@ class SharedSegmentSequence extends internal_5.SharedObject {
|
|
|
279
279
|
/**
|
|
280
280
|
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.reSubmitCore}
|
|
281
281
|
*/
|
|
282
|
-
reSubmitCore(content, localOpMetadata) {
|
|
282
|
+
reSubmitCore(content, localOpMetadata, squash = false) {
|
|
283
283
|
const originalRefSeq = this.inFlightRefSeqs.shift();
|
|
284
284
|
(0, internal_1.assert)(originalRefSeq !== undefined, 0x8bb /* Expected a recorded refSeq when resubmitting an op */);
|
|
285
285
|
this.useResubmitRefSeq(originalRefSeq, () => {
|
|
286
286
|
if (!this.intervalCollections.tryResubmitMessage(content, localOpMetadata)) {
|
|
287
|
-
this.submitSequenceMessage(this.client.regeneratePendingOp(content, localOpMetadata));
|
|
287
|
+
this.submitSequenceMessage(this.client.regeneratePendingOp(content, localOpMetadata, squash));
|
|
288
288
|
}
|
|
289
289
|
});
|
|
290
290
|
}
|
|
291
|
+
reSubmitSquashed(content, localOpMetadata) {
|
|
292
|
+
this.reSubmitCore(content, localOpMetadata, true);
|
|
293
|
+
}
|
|
291
294
|
/**
|
|
292
295
|
* Revert an op
|
|
293
296
|
*/
|
package/dist/sequence.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sequence.js","sourceRoot":"","sources":["../src/sequence.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,+DAA8D;AAE9D,kEAA6D;AAM7D,0EAGqD;AACrD,kEA+B6C;AAK7C,qEAGgD;AAChD,0EAKqD;AACrD,uEAKkD;AAClD,4EAAuC;AAGvC,yEAAkF;AAKlF,mEAKiC;AAEjC,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAClC,MAAM,WAAW,GAAG,SAAS,CAAC;AAkS9B;;GAEG;AACH,MAAsB,qBACrB,SAAQ,uBAA0C;IAiB1C,MAAM,CAAC,kBAAkB,CAAC,KAAyB;QAC1D,MAAM,GAAG,GAAwB,EAAE,CAAC;QACpC,KAAK,MAAM,CAAC,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;YAC9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ACF,CAAC;CACD;AArpBD,sDAqpBC;AAED,SAAS,wBAAwB,CAChC,YAAqC;IAErC,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,SAAS,gBAAgB,CAAI,QAAiB;QAC7C,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;YACf,YAAY,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC;QACD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC;YACJ,OAAO,QAAQ,EAAE,CAAC;QACnB,CAAC;gBAAS,CAAC;YACV,KAAK,EAAE,CAAC;QACT,CAAC;IACF,CAAC;IAED,OAAO,gBAAgB,CAAC;AACzB,CAAC;AAED;;;;GAIG;AACH,IAAI,mBAAmB,GAAG,CAAC,CAAC;AAE5B;;GAEG;AACH,SAAgB,yBAAyB;IACxC,mBAAmB,GAAG,CAAC,CAAC;AACzB,CAAC;AAFD,8DAEC;AAED,MAAM,sBAAsB,GAAG,2CAA2C,CAAC;AAC3E,MAAM,kBAAkB,GAAG,wBAAwB,CAAC,GAAG,EAAE;IACxD,MAAM,IAAI,uBAAY,CAAC,sBAAsB,CAAC,CAAC;AAChD,CAAC,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport { IEventThisPlaceHolder } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport {\n\tMessageType,\n\tISequencedDocumentMessage,\n} from \"@fluidframework/driver-definitions/internal\";\nimport {\n\tClient,\n\tIJSONSegment,\n\tIMergeTreeAnnotateMsg,\n\tIMergeTreeDeltaOp,\n\t// eslint-disable-next-line import/no-deprecated\n\tIMergeTreeGroupMsg,\n\t// eslint-disable-next-line import/no-deprecated\n\tIMergeTreeObliterateMsg,\n\tIMergeTreeOp,\n\tIMergeTreeRemoveMsg,\n\tIRelativePosition,\n\tISegment,\n\tISegmentAction,\n\tLocalReferencePosition,\n\tMergeTreeDeltaType,\n\tMergeTreeRevertibleDriver,\n\tPropertySet,\n\tReferencePosition,\n\tReferenceType,\n\tSlidingPreference,\n\tcreateAnnotateRangeOp,\n\t// eslint-disable-next-line import/no-deprecated\n\tcreateGroupOp,\n\tcreateInsertOp,\n\tcreateObliterateRangeOp,\n\tcreateRemoveRangeOp,\n\tmatchProperties,\n\ttype AdjustParams,\n\ttype InteriorSequencePlace,\n\ttype MapLike,\n} from \"@fluidframework/merge-tree/internal\";\nimport {\n\tISummaryTreeWithStats,\n\tITelemetryContext,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport {\n\tObjectStoragePartition,\n\tSummaryTreeBuilder,\n} from \"@fluidframework/runtime-utils/internal\";\nimport {\n\tIFluidSerializer,\n\tISharedObjectEvents,\n\tSharedObject,\n\ttype ISharedObject,\n} from \"@fluidframework/shared-object-base/internal\";\nimport {\n\tLoggingError,\n\tcreateChildLogger,\n\tcreateConfigBasedOptionsProxy,\n\tloggerToMonitoringContext,\n} from \"@fluidframework/telemetry-utils/internal\";\nimport Deque from \"double-ended-queue\";\n\nimport { type ISequenceIntervalCollection } from \"./intervalCollection.js\";\nimport { IMapOperation, IntervalCollectionMap } from \"./intervalCollectionMap.js\";\nimport {\n\tIMapMessageLocalMetadata,\n\ttype SequenceOptions,\n} from \"./intervalCollectionMapInterfaces.js\";\nimport {\n\tSequenceDeltaEvent,\n\tSequenceDeltaEventClass,\n\tSequenceMaintenanceEvent,\n\tSequenceMaintenanceEventClass,\n} from \"./sequenceDeltaEvent.js\";\n\nconst snapshotFileName = \"header\";\nconst contentPath = \"content\";\n\n/**\n * Events emitted in response to changes to the sequence data.\n *\n * @remarks\n *\n * The following is the list of events emitted.\n *\n * ### \"sequenceDelta\"\n *\n * The sequenceDelta event is emitted when segments are inserted, annotated, or removed.\n *\n * #### Listener signature\n *\n * ```typescript\n * (event: SequenceDeltaEvent, target: IEventThisPlaceHolder) => void\n * ```\n * - `event` - Various information on the segments that were modified.\n *\n * - `target` - The sequence itself.\n *\n * ### \"maintenance\"\n *\n * The maintenance event is emitted when segments are modified during merge-tree maintenance.\n *\n * #### Listener signature\n *\n * ```typescript\n * (event: SequenceMaintenanceEvent, target: IEventThisPlaceHolder) => void\n * ```\n * - `event` - Various information on the segments that were modified.\n *\n * - `target` - The sequence itself.\n * @legacy\n * @alpha\n */\nexport interface ISharedSegmentSequenceEvents extends ISharedObjectEvents {\n\t(\n\t\tevent: \"createIntervalCollection\",\n\t\tlistener: (label: string, local: boolean, target: IEventThisPlaceHolder) => void,\n\t): void;\n\t(\n\t\tevent: \"sequenceDelta\",\n\t\tlistener: (event: SequenceDeltaEvent, target: IEventThisPlaceHolder) => void,\n\t): void;\n\t(\n\t\tevent: \"maintenance\",\n\t\tlistener: (event: SequenceMaintenanceEvent, target: IEventThisPlaceHolder) => void,\n\t): void;\n}\n\n/**\n * @legacy\n * @alpha\n */\nexport interface ISharedSegmentSequence<T extends ISegment>\n\textends ISharedObject<ISharedSegmentSequenceEvents>,\n\t\tMergeTreeRevertibleDriver {\n\t/**\n\t * Creates a `LocalReferencePosition` on this SharedString. If the refType does not include\n\t * ReferenceType.Transient, the returned reference will be added to the localRefs on the provided segment.\n\t * @param segment - Segment to add the local reference on\n\t * @param offset - Offset on the segment at which to place the local reference\n\t * @param refType - ReferenceType for the created local reference\n\t * @param properties - PropertySet to place on the created local reference\n\t */\n\tcreateLocalReferencePosition(\n\t\tsegment: T,\n\t\toffset: number,\n\t\trefType: ReferenceType,\n\t\tproperties: PropertySet | undefined,\n\t\tslidingPreference?: SlidingPreference,\n\t\tcanSlideToEndpoint?: boolean,\n\t): LocalReferencePosition;\n\n\t/**\n\t * Removes a `LocalReferencePosition` from this SharedString.\n\t */\n\tremoveLocalReferencePosition(\n\t\tlref: LocalReferencePosition,\n\t): LocalReferencePosition | undefined;\n\n\t/**\n\t * Returns the length of the current sequence for the client\n\t */\n\tgetLength(): number;\n\n\t/**\n\t * Returns the current position of a segment, and -1 if the segment\n\t * does not exist in this sequence\n\t * @param segment - The segment to get the position of\n\t */\n\tgetPosition(segment: ISegment): number;\n\n\t/**\n\t * Resolves a `ReferencePosition` into a character position using this client's perspective.\n\t *\n\t * Reference positions that point to a character that has been removed will\n\t * always return the position of the nearest non-removed character, regardless\n\t * of `ReferenceType`. To handle this case specifically, one may wish\n\t * to look at the segment returned by `ReferencePosition.getSegment`.\n\t */\n\tlocalReferencePositionToPosition(lref: ReferencePosition): number;\n\n\t/**\n\t * Walk the underlying segments of the sequence.\n\t * The walked segments may extend beyond the range if the segments cross the\n\t * ranges start or end boundaries.\n\t *\n\t * Set split range to true to ensure only segments within the range are walked.\n\t *\n\t * @param handler - The function to handle each segment. Traversal ends if\n\t * this function returns true.\n\t * @param start - Optional. The start of range walk.\n\t * @param end - Optional. The end of range walk\n\t * @param accum - Optional. An object that will be passed to the handler for accumulation\n\t * @param splitRange - Optional. Splits boundary segments on the range boundaries. Defaults to false.\n\t */\n\twalkSegments<TClientData>(\n\t\thandler: ISegmentAction<TClientData>,\n\t\tstart?: number,\n\t\tend?: number,\n\t\taccum?: TClientData,\n\t\tsplitRange?: boolean,\n\t): void;\n\n\t/**\n\t * Inserts a segment directly before a `ReferencePosition`.\n\t * @param refPos - The reference position to insert the segment at\n\t * @param segment - The segment to insert\n\t */\n\tinsertAtReferencePosition(pos: ReferencePosition, segment: T): void;\n\n\t/**\n\t * Finds the segment information (i.e. segment + offset) corresponding to a character position in the SharedString.\n\t * If the position is past the end of the string, `segment` and `offset` on the returned object may be undefined.\n\t * @param pos - Character position (index) into the current local view of the SharedString.\n\t */\n\tgetContainingSegment(pos: number): {\n\t\tsegment: T | undefined;\n\t\toffset: number | undefined;\n\t};\n\n\tgetPropertiesAtPosition(pos: number): PropertySet | undefined;\n\n\t/**\n\t * @returns An iterable object that enumerates the IntervalCollection labels.\n\t *\n\t * @example\n\t *\n\t * ```typescript\n\t * const iter = this.getIntervalCollectionKeys();\n\t * for (key of iter)\n\t * const collection = this.getIntervalCollection(key);\n\t * ...\n\t * ```\n\t */\n\tgetIntervalCollectionLabels(): IterableIterator<string>;\n\n\t/**\n\t * Retrieves the interval collection keyed on `label`. If no such interval collection exists,\n\t * creates one.\n\t */\n\tgetIntervalCollection(label: string): ISequenceIntervalCollection;\n\n\t/**\n\t * Obliterate is similar to remove, but differs in that segments concurrently\n\t * inserted into an obliterated range will also be removed.\n\t * Inserts are considered concurrent to an obliterate iff the insert op's seq is after the obliterate op's refSeq\n\t * and the insert's refSeq is before the obliterates seq.\n\t * Inserts made by the client which most recently obliterated a range containing the insert position\n\t * are not considered concurrent to any obliteration (the last client to obliterate gets the right to insert).\n\t *\n\t * The endpoints can either be inclusive or exclusive.\n\t * Exclusive endpoints allow the obliterated range to \"grow\" to include adjacent concurrently inserted segments on that side.\n\t *\n\t * @param start - The start of the range to obliterate.\n\t * Inclusive if side is Before or a number is provided.\n\t * @param end - The end of the range to obliterate. Inclusive if side is After.\n\t * If a number is provided it is treated as exclusive,\n\t * but the endpoint does not expand in order to preserve existing behavior.\n\t *\n\t * @example Given the initial state `\"|ABC>\"`,\n\t * `obliterateRange({ pos: 0, side: Side.After }, { pos: 4, side: Side.Before })` obliterates `\"ABC\"`, leaving only `\"|>\"`.\n\t * `insertFromSpec(1, { text: \"AAA\"})` would insert `\"AAA\"` before |, resulting in `\"|AAA>\"`.\n\t * If another client does the same thing but inserts `\"BBB\"` and gets sequenced later, all clients will eventually see `|BBB>`.\n\t */\n\tobliterateRange(\n\t\tstart: number | InteriorSequencePlace,\n\t\tend: number | InteriorSequencePlace,\n\t): void;\n\n\t/**\n\t * @returns The most recent sequence number which has been acked by the server and processed by this\n\t * SharedSegmentSequence.\n\t */\n\tgetCurrentSeq(): number;\n\n\t/**\n\t * Annotates the range with the provided properties\n\t *\n\t * @param start - The inclusive start position of the range to annotate\n\t * @param end - The exclusive end position of the range to annotate\n\t * @param props - The properties to annotate the range with\n\t *\n\t */\n\tannotateRange(start: number, end: number, props: PropertySet): void;\n\n\t/**\n\t * Annotates a specified range within the sequence by applying the provided adjustments.\n\t *\n\t * @param start - The inclusive start position of the range to annotate. This is a zero-based index.\n\t * @param end - The exclusive end position of the range to annotate. This is a zero-based index.\n\t * @param adjust - A map-like object specifying the properties to adjust. Each key-value pair represents a property and its corresponding adjustment to be applied over the range.\n\t * An adjustment is defined by an object containing a `delta` to be added to the current property value, and optional `min` and `max` constraints to limit the adjusted value.\n\t *\n\t * @remarks\n\t * The range is defined by the start and end positions, where the start position is inclusive and the end position is exclusive.\n\t * The properties provided in the adjust parameter will be applied to the specified range. Each adjustment modifies the current value of the property by adding the specified `value`.\n\t * If the current value is not a number, the `delta` will be summed with 0 to compute the new value. The optional `min` and `max` constraints are applied after the adjustment to ensure the final value falls within the specified bounds.\n\t */\n\tannotateAdjustRange(start: number, end: number, adjust: MapLike<AdjustParams>): void;\n\n\t/**\n\t * @param start - The inclusive start of the range to remove\n\t * @param end - The exclusive end of the range to remove\n\t */\n\tremoveRange(start: number, end: number): void;\n\n\t/**\n\t * Resolves a remote client's position against the local sequence\n\t * and returns the remote client's position relative to the local\n\t * sequence. The client ref seq must be above the minimum sequence number\n\t * or the return value will be undefined.\n\t * Generally this method is used in conjunction with signals which provide\n\t * point in time values for the below parameters, and is useful for things\n\t * like displaying user position. It should not be used with persisted values\n\t * as persisted values will quickly become invalid as the remoteClientRefSeq\n\t * moves below the minimum sequence number\n\t * @param remoteClientPosition - The remote client's position to resolve\n\t * @param remoteClientRefSeq - The reference sequence number of the remote client\n\t * @param remoteClientId - The client id of the remote client\n\t */\n\tresolveRemoteClientPosition(\n\t\tremoteClientPosition: number,\n\t\tremoteClientRefSeq: number,\n\t\tremoteClientId: string,\n\t): number | undefined;\n\n\t// #region APIs we might want to remove\n\t/**\n\t * Initializes the object as a local, non-shared object. This object can become shared after\n\t * it is attached to the document.\n\t * @privateRemarks\n\t * TODO: determine if this API (from SharedObject) is needed by users of the encapsulated API, declarative API or both,\n\t * and handle exposing it in a consistent way for all SharedObjects if needed.\n\t */\n\tinitializeLocal(): void;\n\n\t/**\n\t * @deprecated The ability to create group ops will be removed in an upcoming\n\t * release, as group ops are redundant with the native batching capabilities\n\t * of the runtime\n\t */\n\t// eslint-disable-next-line import/no-deprecated\n\tgroupOperation(groupOp: IMergeTreeGroupMsg): void;\n\n\tgetRangeExtentsOfPosition(pos: number): {\n\t\tposStart: number | undefined;\n\t\tposAfterEnd: number | undefined;\n\t};\n\n\t/**\n\t * Inserts a segment\n\t * @param start - The position to insert the segment at\n\t * @param spec - The segment to inserts spec\n\t */\n\tinsertFromSpec(pos: number, spec: IJSONSegment): void;\n\n\t/**\n\t * Given a position specified relative to a marker id, lookup the marker\n\t * and convert the position to a character position.\n\t * @param relativePos - Id of marker (may be indirect) and whether position is before or after marker.\n\t */\n\tposFromRelativePos(relativePos: IRelativePosition): number;\n\n\t// #endregion\n}\n\n/**\n * @internal\n */\nexport abstract class SharedSegmentSequence<T extends ISegment>\n\textends SharedObject<ISharedSegmentSequenceEvents>\n\timplements ISharedSegmentSequence<T>\n{\n\t/**\n\t * This is a safeguard to avoid problematic reentrancy of local ops. This type of scenario occurs if the user of SharedString subscribes\n\t * to the `sequenceDelta` event and uses the callback for a local op to submit further local ops.\n\t * Historically (before 2.0.0-internal.6.1.0), doing so would result in eventual consistency issues or a corrupted document.\n\t * These issues were fixed in #16815 which makes such reentrancy no different from applying the ops in order but not from within the change events,\n\t * but there is still little test coverage for reentrant scenarios.\n\t * Additionally, applications submitting ops from inside change events need to take extreme care that their data models also support reentrancy.\n\t * Since this is likely not the case, by default SharedString throws when encountering reentrant ops.\n\t *\n\t * An application using SharedString which explicitly wants to opt in to allowing reentrancy anyway can set `sharedStringPreventReentrancy`\n\t * on the data store options to `false`.\n\t */\n\tprotected guardReentrancy: <TRet>(callback: () => TRet) => TRet;\n\n\tprivate static createOpsFromDelta(event: SequenceDeltaEvent): IMergeTreeDeltaOp[] {\n\t\tconst ops: IMergeTreeDeltaOp[] = [];\n\t\tfor (const r of event.ranges) {\n\t\t\tswitch (event.deltaOperation) {\n\t\t\t\tcase MergeTreeDeltaType.ANNOTATE: {\n\t\t\t\t\tconst lastAnnotate = ops[ops.length - 1] as IMergeTreeAnnotateMsg;\n\t\t\t\t\tconst props: PropertySet = {};\n\t\t\t\t\tfor (const key of Object.keys(r.propertyDeltas)) {\n\t\t\t\t\t\tprops[key] = r.segment.properties?.[key] ?? null;\n\t\t\t\t\t}\n\t\t\t\t\tif (\n\t\t\t\t\t\tlastAnnotate &&\n\t\t\t\t\t\tlastAnnotate.pos2 === r.position &&\n\t\t\t\t\t\tmatchProperties(lastAnnotate.props, props)\n\t\t\t\t\t) {\n\t\t\t\t\t\tlastAnnotate.pos2 += r.segment.cachedLength;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tops.push(\n\t\t\t\t\t\t\tcreateAnnotateRangeOp(r.position, r.position + r.segment.cachedLength, props),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase MergeTreeDeltaType.INSERT:\n\t\t\t\t\tops.push(createInsertOp(r.position, r.segment.clone().toJSONObject()));\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase MergeTreeDeltaType.REMOVE: {\n\t\t\t\t\tconst lastRem = ops[ops.length - 1] as IMergeTreeRemoveMsg;\n\t\t\t\t\tif (lastRem?.pos1 === r.position) {\n\t\t\t\t\t\tassert(lastRem.pos2 !== undefined, 0x3ff /* pos2 should not be undefined here */);\n\t\t\t\t\t\tlastRem.pos2 += r.segment.cachedLength;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tops.push(createRemoveRangeOp(r.position, r.position + r.segment.cachedLength));\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase MergeTreeDeltaType.OBLITERATE: {\n\t\t\t\t\t// eslint-disable-next-line import/no-deprecated\n\t\t\t\t\tconst lastRem = ops[ops.length - 1] as IMergeTreeObliterateMsg;\n\t\t\t\t\tif (lastRem?.pos1 === r.position) {\n\t\t\t\t\t\tassert(lastRem.pos2 !== undefined, 0x874 /* pos2 should not be undefined here */);\n\t\t\t\t\t\tlastRem.pos2 += r.segment.cachedLength;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tops.push(createObliterateRangeOp(r.position, r.position + r.segment.cachedLength));\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tdefault:\n\t\t\t}\n\t\t}\n\t\treturn ops;\n\t}\n\n\t/**\n\t * Note: this field only provides a lower-bound on the reference sequence numbers for in-flight ops.\n\t * The exact reason isn't understood, but some e2e tests suggest that the runtime may sometimes process\n\t * incoming leave/join ops before putting an op that this DDS submits over the wire.\n\t *\n\t * E.g. SharedString submits an op while deltaManager has lastSequenceNumber = 10, but before the runtime\n\t * puts this op over the wire, it processes a client join/leave op with sequence number 11, so the referenceSequenceNumber\n\t * on the SharedString op is 11.\n\t *\n\t * The reference sequence numbers placed in this queue are also not accurate for stashed ops due to how the applyStashedOp\n\t * flow works at the runtime level. This is a legitimate bug, and AB#6602 tracks one way to fix it (stop reaching all the way\n\t * to deltaManager's lastSequenceNumber to obtain refSeq, instead leveraging some analogous notion on the container or datastore\n\t * runtime).\n\t */\n\tprivate readonly inFlightRefSeqs = new Deque<number>();\n\n\tprivate ongoingResubmitRefSeq: number | undefined;\n\n\t/**\n\t * Gets the reference sequence number (i.e. sequence number of the runtime's last processed op) for an op submitted\n\t * in the current context.\n\t *\n\t * This value can be optionally overridden using `useResubmitRefSeq`.\n\t * IntervalCollection's resubmit logic currently relies on preserving merge information from when the op was originally submitted,\n\t * even if the op is resubmitted more than once. Thus during resubmit, `inFlightRefSeqs` gets populated with the\n\t * original refSeq rather than the refSeq at the time of reconnection.\n\t *\n\t * @remarks - In some not fully understood cases, the runtime may process incoming ops before putting an op that this\n\t * DDS submits over the wire. See `inFlightRefSeqs` for more details.\n\t */\n\tprivate get currentRefSeq() {\n\t\treturn this.ongoingResubmitRefSeq ?? this.deltaManager.lastSequenceNumber;\n\t}\n\n\tprotected client: Client;\n\tprivate messagesSinceMSNChange: ISequencedDocumentMessage[] = [];\n\tprivate readonly intervalCollections: IntervalCollectionMap;\n\tconstructor(\n\t\tdataStoreRuntime: IFluidDataStoreRuntime,\n\t\tpublic id: string,\n\t\tattributes: IChannelAttributes,\n\t\tpublic readonly segmentFromSpec: (spec: IJSONSegment) => ISegment,\n\t) {\n\t\tsuper(id, dataStoreRuntime, attributes, \"fluid_sequence_\");\n\n\t\tconst getMinInFlightRefSeq = () => this.inFlightRefSeqs.get(0);\n\t\tthis.guardReentrancy =\n\t\t\t(dataStoreRuntime.options.sharedStringPreventReentrancy ?? true)\n\t\t\t\t? ensureNoReentrancy\n\t\t\t\t: createReentrancyDetector((depth) => {\n\t\t\t\t\t\tif (totalReentrancyLogs > 0) {\n\t\t\t\t\t\t\ttotalReentrancyLogs--;\n\t\t\t\t\t\t\tthis.logger.sendTelemetryEvent(\n\t\t\t\t\t\t\t\t{ eventName: \"LocalOpReentry\", depth },\n\t\t\t\t\t\t\t\tnew LoggingError(reentrancyErrorMessage),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\n\t\tconst options = createConfigBasedOptionsProxy<SequenceOptions>(\n\t\t\tloggerToMonitoringContext(this.logger).config,\n\t\t\t\"Fluid.Sequence\",\n\t\t\t{\n\t\t\t\tmergeTreeEnableObliterate: (c, n) => c.getBoolean(n),\n\t\t\t\tmergeTreeEnableSidedObliterate: (c, n) => c.getBoolean(n),\n\t\t\t\tintervalStickinessEnabled: (c, n) => c.getBoolean(n),\n\t\t\t\tmergeTreeReferencesCanSlideToEndpoint: (c, n) => c.getBoolean(n),\n\t\t\t\tmergeTreeEnableAnnotateAdjust: (c, n) => c.getBoolean(n),\n\t\t\t},\n\t\t\tdataStoreRuntime.options,\n\t\t);\n\n\t\tthis.client = new Client(\n\t\t\tsegmentFromSpec,\n\t\t\tcreateChildLogger({\n\t\t\t\tlogger: this.logger,\n\t\t\t\tnamespace: \"SharedSegmentSequence.MergeTreeClient\",\n\t\t\t}),\n\t\t\toptions,\n\t\t\tgetMinInFlightRefSeq,\n\t\t);\n\n\t\tthis.client.prependListener(\"delta\", (opArgs, deltaArgs) => {\n\t\t\tconst event = new SequenceDeltaEventClass(opArgs, deltaArgs, this.client);\n\t\t\tif (event.isLocal && event.opArgs.rollback !== true) {\n\t\t\t\tthis.submitSequenceMessage(opArgs.op);\n\t\t\t}\n\t\t\tif (deltaArgs.deltaSegments.length > 0) {\n\t\t\t\tthis.emit(\"sequenceDelta\", event, this);\n\t\t\t}\n\t\t});\n\n\t\tthis.client.on(\"maintenance\", (args, opArgs) => {\n\t\t\tthis.emit(\n\t\t\t\t\"maintenance\",\n\t\t\t\tnew SequenceMaintenanceEventClass(opArgs, args, this.client),\n\t\t\t\tthis,\n\t\t\t);\n\t\t});\n\n\t\tthis.intervalCollections = new IntervalCollectionMap(\n\t\t\tthis.serializer,\n\t\t\tthis.handle,\n\t\t\t(op, localOpMetadata) => {\n\t\t\t\tif (!this.isAttached()) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tthis.inFlightRefSeqs.push(this.currentRefSeq);\n\t\t\t\tthis.submitLocalMessage(op, localOpMetadata);\n\t\t\t},\n\t\t\toptions,\n\t\t);\n\t}\n\n\tpublic removeRange(start: number, end: number): void {\n\t\tthis.guardReentrancy(() => this.client.removeRangeLocal(start, end));\n\t}\n\n\tpublic obliterateRange(\n\t\tstart: number | InteriorSequencePlace,\n\t\tend: number | InteriorSequencePlace,\n\t): void {\n\t\tthis.guardReentrancy(() => this.client.obliterateRangeLocal(start, end));\n\t}\n\n\t// eslint-disable-next-line import/no-deprecated\n\tpublic groupOperation(groupOp: IMergeTreeGroupMsg): void {\n\t\tthis.guardReentrancy(() => this.client.localTransaction(groupOp));\n\t}\n\n\tpublic getContainingSegment(pos: number): {\n\t\tsegment: T | undefined;\n\t\toffset: number | undefined;\n\t} {\n\t\treturn this.client.getContainingSegment<T>(pos);\n\t}\n\n\tpublic getLength(): number {\n\t\treturn this.client.getLength();\n\t}\n\n\tpublic getPosition(segment: ISegment): number {\n\t\treturn this.client.getPosition(segment);\n\t}\n\n\tpublic annotateRange(start: number, end: number, props: PropertySet): void {\n\t\tthis.guardReentrancy(() => this.client.annotateRangeLocal(start, end, props));\n\t}\n\n\tpublic annotateAdjustRange(start: number, end: number, adjust: MapLike<AdjustParams>): void {\n\t\tthis.guardReentrancy(() => this.client.annotateAdjustRangeLocal(start, end, adjust));\n\t}\n\n\tpublic getPropertiesAtPosition(pos: number): PropertySet | undefined {\n\t\treturn this.client.getPropertiesAtPosition(pos);\n\t}\n\n\tpublic getRangeExtentsOfPosition(pos: number): {\n\t\tposStart: number | undefined;\n\t\tposAfterEnd: number | undefined;\n\t} {\n\t\treturn this.client.getRangeExtentsOfPosition(pos);\n\t}\n\n\tpublic createLocalReferencePosition(\n\t\tsegment: T,\n\t\toffset: number,\n\t\trefType: ReferenceType,\n\t\tproperties: PropertySet | undefined,\n\t\tslidingPreference?: SlidingPreference,\n\t\tcanSlideToEndpoint?: boolean,\n\t): LocalReferencePosition {\n\t\treturn this.client.createLocalReferencePosition(\n\t\t\tsegment,\n\t\t\toffset,\n\t\t\trefType,\n\t\t\tproperties,\n\t\t\tslidingPreference,\n\t\t\tcanSlideToEndpoint,\n\t\t);\n\t}\n\n\tpublic localReferencePositionToPosition(lref: ReferencePosition): number {\n\t\treturn this.client.localReferencePositionToPosition(lref);\n\t}\n\n\tpublic removeLocalReferencePosition(\n\t\tlref: LocalReferencePosition,\n\t): LocalReferencePosition | undefined {\n\t\treturn this.client.removeLocalReferencePosition(lref);\n\t}\n\n\tpublic resolveRemoteClientPosition(\n\t\tremoteClientPosition: number,\n\t\tremoteClientRefSeq: number,\n\t\tremoteClientId: string,\n\t): number | undefined {\n\t\treturn this.client.resolveRemoteClientPosition(\n\t\t\tremoteClientPosition,\n\t\t\tremoteClientRefSeq,\n\t\t\tremoteClientId,\n\t\t);\n\t}\n\n\tprivate submitSequenceMessage(message: IMergeTreeOp) {\n\t\tif (!this.isAttached()) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.inFlightRefSeqs.push(this.currentRefSeq);\n\n\t\tconst metadata = this.client.peekPendingSegmentGroups(\n\t\t\tmessage.type === MergeTreeDeltaType.GROUP ? message.ops.length : 1,\n\t\t);\n\n\t\tthis.submitLocalMessage(message, metadata);\n\t}\n\n\tpublic posFromRelativePos(relativePos: IRelativePosition): number {\n\t\treturn this.client.posFromRelativePos(relativePos);\n\t}\n\n\tpublic walkSegments<TClientData>(\n\t\thandler: ISegmentAction<TClientData>,\n\t\tstart?: number,\n\t\tend?: number,\n\t\taccum?: TClientData,\n\t\tsplitRange: boolean = false,\n\t): void {\n\t\tthis.client.walkSegments(handler, start, end, accum as TClientData, splitRange);\n\t}\n\n\tpublic getCurrentSeq(): number {\n\t\treturn this.client.getCurrentSeq();\n\t}\n\n\tpublic insertAtReferencePosition(pos: ReferencePosition, segment: T): void {\n\t\tthis.guardReentrancy(() => this.client.insertAtReferencePositionLocal(pos, segment));\n\t}\n\n\tpublic insertFromSpec(pos: number, spec: IJSONSegment): void {\n\t\tconst segment = this.segmentFromSpec(spec);\n\t\tthis.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));\n\t}\n\n\tpublic getIntervalCollection(label: string): ISequenceIntervalCollection {\n\t\treturn this.intervalCollections.get(label);\n\t}\n\n\tpublic getIntervalCollectionLabels(): IterableIterator<string> {\n\t\treturn this.intervalCollections.keys();\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.summarizeCore}\n\t */\n\tprotected summarizeCore(\n\t\tserializer: IFluidSerializer,\n\t\ttelemetryContext?: ITelemetryContext,\n\t): ISummaryTreeWithStats {\n\t\tconst builder = new SummaryTreeBuilder();\n\n\t\t// conditionally write the interval collection blob\n\t\t// only if it has entries\n\t\tif (this.intervalCollections.size > 0) {\n\t\t\tbuilder.addBlob(snapshotFileName, this.intervalCollections.serialize(serializer));\n\t\t}\n\n\t\tbuilder.addWithStats(contentPath, this.summarizeMergeTree(serializer));\n\n\t\treturn builder.getSummaryTree();\n\t}\n\n\t/**\n\t * Runs serializer over the GC data for this SharedMatrix.\n\t * All the IFluidHandle's represent routes to other objects.\n\t */\n\tprotected processGCDataCore(serializer: IFluidSerializer) {\n\t\tif (this.intervalCollections.size > 0) {\n\t\t\tthis.intervalCollections.serialize(serializer);\n\t\t}\n\n\t\tthis.client.serializeGCData(this.handle, serializer);\n\t}\n\n\t/**\n\t * Replace the range specified from start to end with the provided segment\n\t * This is done by inserting the segment at the end of the range, followed\n\t * by removing the contents of the range\n\t * For a zero or reverse range (start \\>= end), insert at end do not remove anything\n\t * @param start - The start of the range to replace\n\t * @param end - The end of the range to replace\n\t * @param segment - The segment that will replace the range\n\t */\n\tprotected replaceRange(start: number, end: number, segment: ISegment): void {\n\t\t// Insert at the max end of the range when start > end, but still remove the range later\n\t\tconst insertIndex: number = Math.max(start, end);\n\n\t\t// Insert first, so local references can slide to the inserted seg if any\n\t\tconst insert = this.guardReentrancy(() =>\n\t\t\tthis.client.insertSegmentLocal(insertIndex, segment),\n\t\t);\n\n\t\tif (insert && start < end) {\n\t\t\tthis.removeRange(start, end);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.onConnect}\n\t */\n\tprotected onConnect() {\n\t\t// Update merge tree collaboration information with new client ID and then resend pending ops\n\t\tthis.client.startOrUpdateCollaboration(this.runtime.clientId);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.onDisconnect}\n\t */\n\tprotected onDisconnect() {}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.reSubmitCore}\n\t */\n\tprotected reSubmitCore(content: any, localOpMetadata: unknown) {\n\t\tconst originalRefSeq = this.inFlightRefSeqs.shift();\n\t\tassert(\n\t\t\toriginalRefSeq !== undefined,\n\t\t\t0x8bb /* Expected a recorded refSeq when resubmitting an op */,\n\t\t);\n\t\tthis.useResubmitRefSeq(originalRefSeq, () => {\n\t\t\tif (\n\t\t\t\t!this.intervalCollections.tryResubmitMessage(\n\t\t\t\t\tcontent,\n\t\t\t\t\tlocalOpMetadata as IMapMessageLocalMetadata,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tthis.submitSequenceMessage(\n\t\t\t\t\tthis.client.regeneratePendingOp(content as IMergeTreeOp, localOpMetadata),\n\t\t\t\t);\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Revert an op\n\t */\n\tprotected rollback(content: any, localOpMetadata: unknown): void {\n\t\tconst originalRefSeq = this.inFlightRefSeqs.pop();\n\t\tassert(\n\t\t\toriginalRefSeq !== undefined,\n\t\t\t0xb7f /* Expected a recorded refSeq when rolling back an op */,\n\t\t);\n\n\t\tif (!this.intervalCollections.tryRollback(content, localOpMetadata)) {\n\t\t\tthis.client.rollback(content, localOpMetadata);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n\t */\n\tprotected async loadCore(storage: IChannelStorageService) {\n\t\tif (await storage.contains(snapshotFileName)) {\n\t\t\tconst blob = await storage.readBlob(snapshotFileName);\n\t\t\tconst header = bufferToString(blob, \"utf8\");\n\t\t\tthis.intervalCollections.populate(header);\n\t\t}\n\n\t\ttry {\n\t\t\t// this will load the header, and return a promise\n\t\t\t// that will resolve when the body is loaded\n\t\t\t// and the catchup ops are available.\n\t\t\tconst { catchupOpsP } = await this.client.load(\n\t\t\t\tthis.runtime,\n\t\t\t\tnew ObjectStoragePartition(storage, contentPath),\n\t\t\t\tthis.serializer,\n\t\t\t);\n\n\t\t\t// process the catch up ops, and finishing the loading process\n\t\t\t(await catchupOpsP).forEach((m) => {\n\t\t\t\tconst collabWindow = this.client.getCollabWindow();\n\t\t\t\tif (\n\t\t\t\t\tm.minimumSequenceNumber < collabWindow.minSeq ||\n\t\t\t\t\tm.referenceSequenceNumber < collabWindow.minSeq ||\n\t\t\t\t\tm.sequenceNumber <= collabWindow.minSeq ||\n\t\t\t\t\t// sequenceNumber could be the same if messages are part of a grouped batch\n\t\t\t\t\tm.sequenceNumber < collabWindow.currentSeq\n\t\t\t\t) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Invalid catchup operations in snapshot: ${JSON.stringify({\n\t\t\t\t\t\t\top: {\n\t\t\t\t\t\t\t\tseq: m.sequenceNumber,\n\t\t\t\t\t\t\t\tminSeq: m.minimumSequenceNumber,\n\t\t\t\t\t\t\t\trefSeq: m.referenceSequenceNumber,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tcollabWindow: {\n\t\t\t\t\t\t\t\tseq: collabWindow.currentSeq,\n\t\t\t\t\t\t\t\tminSeq: collabWindow.minSeq,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t})}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tthis.processMergeTreeMsg(m);\n\t\t\t});\n\n\t\t\t// Initialize the interval collections\n\t\t\tthis.initializeIntervalCollections();\n\t\t} catch (error) {\n\t\t\tthis.logger.sendErrorEvent({ eventName: \"SequenceLoadFailed\" }, error);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.processCore}\n\t */\n\tprotected processCore(\n\t\tmessage: ISequencedDocumentMessage,\n\t\tlocal: boolean,\n\t\tlocalOpMetadata: unknown,\n\t) {\n\t\tif (local) {\n\t\t\tconst recordedRefSeq = this.inFlightRefSeqs.shift();\n\t\t\tassert(recordedRefSeq !== undefined, 0x8bc /* No pending recorded refSeq found */);\n\t\t\t// TODO: AB#7076: Some equivalent assert should be enabled. This fails some e2e stashed op tests because\n\t\t\t// the deltaManager may have seen more messages than the runtime has processed while amidst the stashed op\n\t\t\t// flow, so e.g. when `applyStashedOp` is called and the DDS is put in a state where it expects an ack for\n\t\t\t// one of its messages, the delta manager has actually already seen subsequent messages from collaborators\n\t\t\t// which the in-flight message is concurrent to.\n\t\t\t// See \"handles stashed ops created on top of sequenced local ops\" for one such test case.\n\t\t\t// assert(recordedRefSeq <= message.referenceSequenceNumber, \"RefSeq mismatch\");\n\t\t}\n\n\t\tassert(\n\t\t\tmessage.type === MessageType.Operation,\n\t\t\t0x073 /* \"Sequence message not operation\" */,\n\t\t);\n\n\t\tconst handled = this.intervalCollections.tryProcessMessage(\n\t\t\tmessage.contents as IMapOperation,\n\t\t\tlocal,\n\t\t\tmessage,\n\t\t\tlocalOpMetadata,\n\t\t);\n\n\t\tif (!handled) {\n\t\t\tthis.processMergeTreeMsg(message, local);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.didAttach}\n\t */\n\tprotected didAttach() {\n\t\t// If we are not local, and we've attached we need to start generating and sending ops\n\t\t// so start collaboration and provide a default client id incase we are not connected\n\t\tif (this.isAttached()) {\n\t\t\tthis.client.startOrUpdateCollaboration(this.runtime.clientId ?? \"attached\");\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.initializeLocalCore}\n\t */\n\tprotected initializeLocalCore() {\n\t\tsuper.initializeLocalCore();\n\t\tthis.initializeIntervalCollections();\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}\n\t */\n\tprotected applyStashedOp(content: any): void {\n\t\tif (!this.intervalCollections.tryApplyStashedOp(content)) {\n\t\t\tthis.client.applyStashedOp(content);\n\t\t}\n\t}\n\n\tprivate summarizeMergeTree(serializer: IFluidSerializer): ISummaryTreeWithStats {\n\t\tconst minSeq = this.deltaManager.minimumSequenceNumber;\n\n\t\tthis.processMinSequenceNumberChanged(minSeq);\n\n\t\tthis.messagesSinceMSNChange.forEach((m) => {\n\t\t\tm.minimumSequenceNumber = minSeq;\n\t\t});\n\n\t\treturn this.client.summarize(\n\t\t\tthis.runtime,\n\t\t\tthis.handle,\n\t\t\tserializer,\n\t\t\tthis.messagesSinceMSNChange,\n\t\t);\n\t}\n\n\t/**\n\t *\n\t * @param message - Message with decoded and hydrated handles\n\t */\n\tprivate processMergeTreeMsg(message: ISequencedDocumentMessage, local?: boolean) {\n\t\tconst ops: IMergeTreeDeltaOp[] = [];\n\t\tfunction transformOps(event: SequenceDeltaEvent) {\n\t\t\tops.push(...SharedSegmentSequence.createOpsFromDelta(event));\n\t\t}\n\t\tconst needsTransformation = message.referenceSequenceNumber !== message.sequenceNumber - 1;\n\t\tlet stashMessage: Readonly<ISequencedDocumentMessage> = message;\n\t\tif (this.runtime.options.newMergeTreeSnapshotFormat !== true) {\n\t\t\tif (needsTransformation) {\n\t\t\t\tthis.on(\"sequenceDelta\", transformOps);\n\t\t\t}\n\t\t}\n\n\t\tthis.client.applyMsg(message, local);\n\n\t\tif (this.runtime.options.newMergeTreeSnapshotFormat !== true) {\n\t\t\tif (needsTransformation) {\n\t\t\t\tthis.removeListener(\"sequenceDelta\", transformOps);\n\t\t\t\t// shallow clone the message as we only overwrite top level properties,\n\t\t\t\t// like referenceSequenceNumber and content only\n\t\t\t\tstashMessage = {\n\t\t\t\t\t...message,\n\t\t\t\t\treferenceSequenceNumber: stashMessage.sequenceNumber - 1,\n\t\t\t\t\t// eslint-disable-next-line import/no-deprecated\n\t\t\t\t\tcontents: ops.length !== 1 ? createGroupOp(...ops) : ops[0],\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tthis.messagesSinceMSNChange.push(stashMessage);\n\n\t\t\t// Do GC every once in a while...\n\t\t\tif (\n\t\t\t\tthis.messagesSinceMSNChange.length > 20 &&\n\t\t\t\tthis.messagesSinceMSNChange[20].sequenceNumber < message.minimumSequenceNumber\n\t\t\t) {\n\t\t\t\tthis.processMinSequenceNumberChanged(message.minimumSequenceNumber);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate processMinSequenceNumberChanged(minSeq: number) {\n\t\tlet index = 0;\n\t\tfor (; index < this.messagesSinceMSNChange.length; index++) {\n\t\t\tif (this.messagesSinceMSNChange[index].sequenceNumber > minSeq) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (index !== 0) {\n\t\t\tthis.messagesSinceMSNChange = this.messagesSinceMSNChange.slice(index);\n\t\t}\n\t}\n\n\tprivate initializeIntervalCollections() {\n\t\t// Listen and initialize new SharedIntervalCollections\n\t\tthis.intervalCollections.events.on(\n\t\t\t\"createIntervalCollection\",\n\t\t\t(key: string, local: boolean) => {\n\t\t\t\tconst intervalCollection = this.intervalCollections.get(key);\n\t\t\t\tif (!intervalCollection.attached) {\n\t\t\t\t\tintervalCollection.attachGraph(this.client, key);\n\t\t\t\t}\n\t\t\t\tthis.emit(\"createIntervalCollection\", key, local, this);\n\t\t\t},\n\t\t);\n\n\t\t// Initialize existing SharedIntervalCollections\n\t\tfor (const key of this.intervalCollections.keys()) {\n\t\t\tconst intervalCollection = this.intervalCollections.get(key);\n\t\t\tintervalCollection.attachGraph(this.client, key);\n\t\t}\n\t}\n\n\t/**\n\t * Overrides the \"currently applicable reference sequence number\" for the duration of the callback.\n\t * See remarks on `currentRefSeq` for more context.\n\t */\n\tprivate useResubmitRefSeq(refSeq: number, callback: () => void) {\n\t\tconst previousResubmitRefSeq = this.ongoingResubmitRefSeq;\n\t\tthis.ongoingResubmitRefSeq = refSeq;\n\t\ttry {\n\t\t\tcallback();\n\t\t} finally {\n\t\t\tthis.ongoingResubmitRefSeq = previousResubmitRefSeq;\n\t\t}\n\t}\n}\n\nfunction createReentrancyDetector(\n\tonReentrancy: (depth: number) => void,\n): <T>(callback: () => T) => T {\n\tlet depth = 0;\n\tfunction detectReentrancy<T>(callback: () => T): T {\n\t\tif (depth > 0) {\n\t\t\tonReentrancy(depth);\n\t\t}\n\t\tdepth++;\n\t\ttry {\n\t\t\treturn callback();\n\t\t} finally {\n\t\t\tdepth--;\n\t\t}\n\t}\n\n\treturn detectReentrancy;\n}\n\n/**\n * Apps which generate reentrant behavior may do so at a high frequency.\n * Logging even per-SharedSegmentSequence instance might be too noisy, and having a few logs from a session\n * is likely enough.\n */\nlet totalReentrancyLogs = 3;\n\n/**\n * Resets the reentrancy log counter. Test-only API.\n */\nexport function resetReentrancyLogCounter() {\n\ttotalReentrancyLogs = 3;\n}\n\nconst reentrancyErrorMessage = \"Reentrancy detected in sequence local ops\";\nconst ensureNoReentrancy = createReentrancyDetector(() => {\n\tthrow new LoggingError(reentrancyErrorMessage);\n});\n"]}
|
|
1
|
+
{"version":3,"file":"sequence.js","sourceRoot":"","sources":["../src/sequence.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,+DAA8D;AAE9D,kEAA6D;AAM7D,0EAGqD;AACrD,kEA+B6C;AAK7C,qEAGgD;AAChD,0EAKqD;AACrD,uEAKkD;AAClD,4EAAuC;AAGvC,yEAAkF;AAElF,mEAKiC;AAEjC,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAClC,MAAM,WAAW,GAAG,SAAS,CAAC;AAkS9B;;GAEG;AACH,MAAsB,qBACrB,SAAQ,uBAA0C;IAiB1C,MAAM,CAAC,kBAAkB,CAAC,KAAyB;QAC1D,MAAM,GAAG,GAAwB,EAAE,CAAC;QACpC,KAAK,MAAM,CAAC,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;YAC9B,QAAQ,KAAK,CAAC,cAAc,EAAE,CAAC;gBAC9B,KAAK,6BAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC;oBAClC,MAAM,YAAY,GAAG,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAA0B,CAAC;oBAClE,MAAM,KAAK,GAAgB,EAAE,CAAC;oBAC9B,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,EAAE,CAAC;wBACjD,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,C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,QAAiB;QAC7C,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;YACf,YAAY,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC;QACD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC;YACJ,OAAO,QAAQ,EAAE,CAAC;QACnB,CAAC;gBAAS,CAAC;YACV,KAAK,EAAE,CAAC;QACT,CAAC;IACF,CAAC;IAED,OAAO,gBAAgB,CAAC;AACzB,CAAC;AAED;;;;GAIG;AACH,IAAI,mBAAmB,GAAG,CAAC,CAAC;AAE5B;;GAEG;AACH,SAAgB,yBAAyB;IACxC,mBAAmB,GAAG,CAAC,CAAC;AACzB,CAAC;AAFD,8DAEC;AAED,MAAM,sBAAsB,GAAG,2CAA2C,CAAC;AAC3E,MAAM,kBAAkB,GAAG,wBAAwB,CAAC,GAAG,EAAE;IACxD,MAAM,IAAI,uBAAY,CAAC,sBAAsB,CAAC,CAAC;AAChD,CAAC,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport { IEventThisPlaceHolder } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport {\n\tMessageType,\n\tISequencedDocumentMessage,\n} from \"@fluidframework/driver-definitions/internal\";\nimport {\n\tClient,\n\tIJSONSegment,\n\tIMergeTreeAnnotateMsg,\n\tIMergeTreeDeltaOp,\n\t// eslint-disable-next-line import/no-deprecated\n\tIMergeTreeGroupMsg,\n\t// eslint-disable-next-line import/no-deprecated\n\tIMergeTreeObliterateMsg,\n\tIMergeTreeOp,\n\tIMergeTreeRemoveMsg,\n\tIRelativePosition,\n\tISegment,\n\tISegmentAction,\n\tLocalReferencePosition,\n\tMergeTreeDeltaType,\n\tMergeTreeRevertibleDriver,\n\tPropertySet,\n\tReferencePosition,\n\tReferenceType,\n\tSlidingPreference,\n\tcreateAnnotateRangeOp,\n\t// eslint-disable-next-line import/no-deprecated\n\tcreateGroupOp,\n\tcreateInsertOp,\n\tcreateObliterateRangeOp,\n\tcreateRemoveRangeOp,\n\tmatchProperties,\n\ttype AdjustParams,\n\ttype InteriorSequencePlace,\n\ttype MapLike,\n} from \"@fluidframework/merge-tree/internal\";\nimport {\n\tISummaryTreeWithStats,\n\tITelemetryContext,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport {\n\tObjectStoragePartition,\n\tSummaryTreeBuilder,\n} from \"@fluidframework/runtime-utils/internal\";\nimport {\n\tIFluidSerializer,\n\tISharedObjectEvents,\n\tSharedObject,\n\ttype ISharedObject,\n} from \"@fluidframework/shared-object-base/internal\";\nimport {\n\tLoggingError,\n\tcreateChildLogger,\n\tcreateConfigBasedOptionsProxy,\n\tloggerToMonitoringContext,\n} from \"@fluidframework/telemetry-utils/internal\";\nimport Deque from \"double-ended-queue\";\n\nimport { type ISequenceIntervalCollection } from \"./intervalCollection.js\";\nimport { IMapOperation, IntervalCollectionMap } from \"./intervalCollectionMap.js\";\nimport { type SequenceOptions } from \"./intervalCollectionMapInterfaces.js\";\nimport {\n\tSequenceDeltaEvent,\n\tSequenceDeltaEventClass,\n\tSequenceMaintenanceEvent,\n\tSequenceMaintenanceEventClass,\n} from \"./sequenceDeltaEvent.js\";\n\nconst snapshotFileName = \"header\";\nconst contentPath = \"content\";\n\n/**\n * Events emitted in response to changes to the sequence data.\n *\n * @remarks\n *\n * The following is the list of events emitted.\n *\n * ### \"sequenceDelta\"\n *\n * The sequenceDelta event is emitted when segments are inserted, annotated, or removed.\n *\n * #### Listener signature\n *\n * ```typescript\n * (event: SequenceDeltaEvent, target: IEventThisPlaceHolder) => void\n * ```\n * - `event` - Various information on the segments that were modified.\n *\n * - `target` - The sequence itself.\n *\n * ### \"maintenance\"\n *\n * The maintenance event is emitted when segments are modified during merge-tree maintenance.\n *\n * #### Listener signature\n *\n * ```typescript\n * (event: SequenceMaintenanceEvent, target: IEventThisPlaceHolder) => void\n * ```\n * - `event` - Various information on the segments that were modified.\n *\n * - `target` - The sequence itself.\n * @legacy\n * @alpha\n */\nexport interface ISharedSegmentSequenceEvents extends ISharedObjectEvents {\n\t(\n\t\tevent: \"createIntervalCollection\",\n\t\tlistener: (label: string, local: boolean, target: IEventThisPlaceHolder) => void,\n\t): void;\n\t(\n\t\tevent: \"sequenceDelta\",\n\t\tlistener: (event: SequenceDeltaEvent, target: IEventThisPlaceHolder) => void,\n\t): void;\n\t(\n\t\tevent: \"maintenance\",\n\t\tlistener: (event: SequenceMaintenanceEvent, target: IEventThisPlaceHolder) => void,\n\t): void;\n}\n\n/**\n * @legacy\n * @alpha\n */\nexport interface ISharedSegmentSequence<T extends ISegment>\n\textends ISharedObject<ISharedSegmentSequenceEvents>,\n\t\tMergeTreeRevertibleDriver {\n\t/**\n\t * Creates a `LocalReferencePosition` on this SharedString. If the refType does not include\n\t * ReferenceType.Transient, the returned reference will be added to the localRefs on the provided segment.\n\t * @param segment - Segment to add the local reference on\n\t * @param offset - Offset on the segment at which to place the local reference\n\t * @param refType - ReferenceType for the created local reference\n\t * @param properties - PropertySet to place on the created local reference\n\t */\n\tcreateLocalReferencePosition(\n\t\tsegment: T,\n\t\toffset: number,\n\t\trefType: ReferenceType,\n\t\tproperties: PropertySet | undefined,\n\t\tslidingPreference?: SlidingPreference,\n\t\tcanSlideToEndpoint?: boolean,\n\t): LocalReferencePosition;\n\n\t/**\n\t * Removes a `LocalReferencePosition` from this SharedString.\n\t */\n\tremoveLocalReferencePosition(\n\t\tlref: LocalReferencePosition,\n\t): LocalReferencePosition | undefined;\n\n\t/**\n\t * Returns the length of the current sequence for the client\n\t */\n\tgetLength(): number;\n\n\t/**\n\t * Returns the current position of a segment, and -1 if the segment\n\t * does not exist in this sequence\n\t * @param segment - The segment to get the position of\n\t */\n\tgetPosition(segment: ISegment): number;\n\n\t/**\n\t * Resolves a `ReferencePosition` into a character position using this client's perspective.\n\t *\n\t * Reference positions that point to a character that has been removed will\n\t * always return the position of the nearest non-removed character, regardless\n\t * of `ReferenceType`. To handle this case specifically, one may wish\n\t * to look at the segment returned by `ReferencePosition.getSegment`.\n\t */\n\tlocalReferencePositionToPosition(lref: ReferencePosition): number;\n\n\t/**\n\t * Walk the underlying segments of the sequence.\n\t * The walked segments may extend beyond the range if the segments cross the\n\t * ranges start or end boundaries.\n\t *\n\t * Set split range to true to ensure only segments within the range are walked.\n\t *\n\t * @param handler - The function to handle each segment. Traversal ends if\n\t * this function returns true.\n\t * @param start - Optional. The start of range walk.\n\t * @param end - Optional. The end of range walk\n\t * @param accum - Optional. An object that will be passed to the handler for accumulation\n\t * @param splitRange - Optional. Splits boundary segments on the range boundaries. Defaults to false.\n\t */\n\twalkSegments<TClientData>(\n\t\thandler: ISegmentAction<TClientData>,\n\t\tstart?: number,\n\t\tend?: number,\n\t\taccum?: TClientData,\n\t\tsplitRange?: boolean,\n\t): void;\n\n\t/**\n\t * Inserts a segment directly before a `ReferencePosition`.\n\t * @param refPos - The reference position to insert the segment at\n\t * @param segment - The segment to insert\n\t */\n\tinsertAtReferencePosition(pos: ReferencePosition, segment: T): void;\n\n\t/**\n\t * Finds the segment information (i.e. segment + offset) corresponding to a character position in the SharedString.\n\t * If the position is past the end of the string, `segment` and `offset` on the returned object may be undefined.\n\t * @param pos - Character position (index) into the current local view of the SharedString.\n\t */\n\tgetContainingSegment(pos: number): {\n\t\tsegment: T | undefined;\n\t\toffset: number | undefined;\n\t};\n\n\tgetPropertiesAtPosition(pos: number): PropertySet | undefined;\n\n\t/**\n\t * @returns An iterable object that enumerates the IntervalCollection labels.\n\t *\n\t * @example\n\t *\n\t * ```typescript\n\t * const iter = this.getIntervalCollectionKeys();\n\t * for (key of iter)\n\t * const collection = this.getIntervalCollection(key);\n\t * ...\n\t * ```\n\t */\n\tgetIntervalCollectionLabels(): IterableIterator<string>;\n\n\t/**\n\t * Retrieves the interval collection keyed on `label`. If no such interval collection exists,\n\t * creates one.\n\t */\n\tgetIntervalCollection(label: string): ISequenceIntervalCollection;\n\n\t/**\n\t * Obliterate is similar to remove, but differs in that segments concurrently\n\t * inserted into an obliterated range will also be removed.\n\t * Inserts are considered concurrent to an obliterate iff the insert op's seq is after the obliterate op's refSeq\n\t * and the insert's refSeq is before the obliterates seq.\n\t * Inserts made by the client which most recently obliterated a range containing the insert position\n\t * are not considered concurrent to any obliteration (the last client to obliterate gets the right to insert).\n\t *\n\t * The endpoints can either be inclusive or exclusive.\n\t * Exclusive endpoints allow the obliterated range to \"grow\" to include adjacent concurrently inserted segments on that side.\n\t *\n\t * @param start - The start of the range to obliterate.\n\t * Inclusive if side is Before or a number is provided.\n\t * @param end - The end of the range to obliterate. Inclusive if side is After.\n\t * If a number is provided it is treated as exclusive,\n\t * but the endpoint does not expand in order to preserve existing behavior.\n\t *\n\t * @example Given the initial state `\"|ABC>\"`,\n\t * `obliterateRange({ pos: 0, side: Side.After }, { pos: 4, side: Side.Before })` obliterates `\"ABC\"`, leaving only `\"|>\"`.\n\t * `insertFromSpec(1, { text: \"AAA\"})` would insert `\"AAA\"` before |, resulting in `\"|AAA>\"`.\n\t * If another client does the same thing but inserts `\"BBB\"` and gets sequenced later, all clients will eventually see `|BBB>`.\n\t */\n\tobliterateRange(\n\t\tstart: number | InteriorSequencePlace,\n\t\tend: number | InteriorSequencePlace,\n\t): void;\n\n\t/**\n\t * @returns The most recent sequence number which has been acked by the server and processed by this\n\t * SharedSegmentSequence.\n\t */\n\tgetCurrentSeq(): number;\n\n\t/**\n\t * Annotates the range with the provided properties\n\t *\n\t * @param start - The inclusive start position of the range to annotate\n\t * @param end - The exclusive end position of the range to annotate\n\t * @param props - The properties to annotate the range with\n\t *\n\t */\n\tannotateRange(start: number, end: number, props: PropertySet): void;\n\n\t/**\n\t * Annotates a specified range within the sequence by applying the provided adjustments.\n\t *\n\t * @param start - The inclusive start position of the range to annotate. This is a zero-based index.\n\t * @param end - The exclusive end position of the range to annotate. This is a zero-based index.\n\t * @param adjust - A map-like object specifying the properties to adjust. Each key-value pair represents a property and its corresponding adjustment to be applied over the range.\n\t * An adjustment is defined by an object containing a `delta` to be added to the current property value, and optional `min` and `max` constraints to limit the adjusted value.\n\t *\n\t * @remarks\n\t * The range is defined by the start and end positions, where the start position is inclusive and the end position is exclusive.\n\t * The properties provided in the adjust parameter will be applied to the specified range. Each adjustment modifies the current value of the property by adding the specified `value`.\n\t * If the current value is not a number, the `delta` will be summed with 0 to compute the new value. The optional `min` and `max` constraints are applied after the adjustment to ensure the final value falls within the specified bounds.\n\t */\n\tannotateAdjustRange(start: number, end: number, adjust: MapLike<AdjustParams>): void;\n\n\t/**\n\t * @param start - The inclusive start of the range to remove\n\t * @param end - The exclusive end of the range to remove\n\t */\n\tremoveRange(start: number, end: number): void;\n\n\t/**\n\t * Resolves a remote client's position against the local sequence\n\t * and returns the remote client's position relative to the local\n\t * sequence. The client ref seq must be above the minimum sequence number\n\t * or the return value will be undefined.\n\t * Generally this method is used in conjunction with signals which provide\n\t * point in time values for the below parameters, and is useful for things\n\t * like displaying user position. It should not be used with persisted values\n\t * as persisted values will quickly become invalid as the remoteClientRefSeq\n\t * moves below the minimum sequence number\n\t * @param remoteClientPosition - The remote client's position to resolve\n\t * @param remoteClientRefSeq - The reference sequence number of the remote client\n\t * @param remoteClientId - The client id of the remote client\n\t */\n\tresolveRemoteClientPosition(\n\t\tremoteClientPosition: number,\n\t\tremoteClientRefSeq: number,\n\t\tremoteClientId: string,\n\t): number | undefined;\n\n\t// #region APIs we might want to remove\n\t/**\n\t * Initializes the object as a local, non-shared object. This object can become shared after\n\t * it is attached to the document.\n\t * @privateRemarks\n\t * TODO: determine if this API (from SharedObject) is needed by users of the encapsulated API, declarative API or both,\n\t * and handle exposing it in a consistent way for all SharedObjects if needed.\n\t */\n\tinitializeLocal(): void;\n\n\t/**\n\t * @deprecated The ability to create group ops will be removed in an upcoming\n\t * release, as group ops are redundant with the native batching capabilities\n\t * of the runtime\n\t */\n\t// eslint-disable-next-line import/no-deprecated\n\tgroupOperation(groupOp: IMergeTreeGroupMsg): void;\n\n\tgetRangeExtentsOfPosition(pos: number): {\n\t\tposStart: number | undefined;\n\t\tposAfterEnd: number | undefined;\n\t};\n\n\t/**\n\t * Inserts a segment\n\t * @param start - The position to insert the segment at\n\t * @param spec - The segment to inserts spec\n\t */\n\tinsertFromSpec(pos: number, spec: IJSONSegment): void;\n\n\t/**\n\t * Given a position specified relative to a marker id, lookup the marker\n\t * and convert the position to a character position.\n\t * @param relativePos - Id of marker (may be indirect) and whether position is before or after marker.\n\t */\n\tposFromRelativePos(relativePos: IRelativePosition): number;\n\n\t// #endregion\n}\n\n/**\n * @internal\n */\nexport abstract class SharedSegmentSequence<T extends ISegment>\n\textends SharedObject<ISharedSegmentSequenceEvents>\n\timplements ISharedSegmentSequence<T>\n{\n\t/**\n\t * This is a safeguard to avoid problematic reentrancy of local ops. This type of scenario occurs if the user of SharedString subscribes\n\t * to the `sequenceDelta` event and uses the callback for a local op to submit further local ops.\n\t * Historically (before 2.0.0-internal.6.1.0), doing so would result in eventual consistency issues or a corrupted document.\n\t * These issues were fixed in #16815 which makes such reentrancy no different from applying the ops in order but not from within the change events,\n\t * but there is still little test coverage for reentrant scenarios.\n\t * Additionally, applications submitting ops from inside change events need to take extreme care that their data models also support reentrancy.\n\t * Since this is likely not the case, by default SharedString throws when encountering reentrant ops.\n\t *\n\t * An application using SharedString which explicitly wants to opt in to allowing reentrancy anyway can set `sharedStringPreventReentrancy`\n\t * on the data store options to `false`.\n\t */\n\tprotected guardReentrancy: <TRet>(callback: () => TRet) => TRet;\n\n\tprivate static createOpsFromDelta(event: SequenceDeltaEvent): IMergeTreeDeltaOp[] {\n\t\tconst ops: IMergeTreeDeltaOp[] = [];\n\t\tfor (const r of event.ranges) {\n\t\t\tswitch (event.deltaOperation) {\n\t\t\t\tcase MergeTreeDeltaType.ANNOTATE: {\n\t\t\t\t\tconst lastAnnotate = ops[ops.length - 1] as IMergeTreeAnnotateMsg;\n\t\t\t\t\tconst props: PropertySet = {};\n\t\t\t\t\tfor (const key of Object.keys(r.propertyDeltas)) {\n\t\t\t\t\t\tprops[key] = r.segment.properties?.[key] ?? null;\n\t\t\t\t\t}\n\t\t\t\t\tif (\n\t\t\t\t\t\tlastAnnotate &&\n\t\t\t\t\t\tlastAnnotate.pos2 === r.position &&\n\t\t\t\t\t\tmatchProperties(lastAnnotate.props, props)\n\t\t\t\t\t) {\n\t\t\t\t\t\tlastAnnotate.pos2 += r.segment.cachedLength;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tops.push(\n\t\t\t\t\t\t\tcreateAnnotateRangeOp(r.position, r.position + r.segment.cachedLength, props),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase MergeTreeDeltaType.INSERT:\n\t\t\t\t\tops.push(createInsertOp(r.position, r.segment.clone().toJSONObject()));\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase MergeTreeDeltaType.REMOVE: {\n\t\t\t\t\tconst lastRem = ops[ops.length - 1] as IMergeTreeRemoveMsg;\n\t\t\t\t\tif (lastRem?.pos1 === r.position) {\n\t\t\t\t\t\tassert(lastRem.pos2 !== undefined, 0x3ff /* pos2 should not be undefined here */);\n\t\t\t\t\t\tlastRem.pos2 += r.segment.cachedLength;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tops.push(createRemoveRangeOp(r.position, r.position + r.segment.cachedLength));\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase MergeTreeDeltaType.OBLITERATE: {\n\t\t\t\t\t// eslint-disable-next-line import/no-deprecated\n\t\t\t\t\tconst lastRem = ops[ops.length - 1] as IMergeTreeObliterateMsg;\n\t\t\t\t\tif (lastRem?.pos1 === r.position) {\n\t\t\t\t\t\tassert(lastRem.pos2 !== undefined, 0x874 /* pos2 should not be undefined here */);\n\t\t\t\t\t\tlastRem.pos2 += r.segment.cachedLength;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tops.push(createObliterateRangeOp(r.position, r.position + r.segment.cachedLength));\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tdefault:\n\t\t\t}\n\t\t}\n\t\treturn ops;\n\t}\n\n\t/**\n\t * Note: this field only provides a lower-bound on the reference sequence numbers for in-flight ops.\n\t * The exact reason isn't understood, but some e2e tests suggest that the runtime may sometimes process\n\t * incoming leave/join ops before putting an op that this DDS submits over the wire.\n\t *\n\t * E.g. SharedString submits an op while deltaManager has lastSequenceNumber = 10, but before the runtime\n\t * puts this op over the wire, it processes a client join/leave op with sequence number 11, so the referenceSequenceNumber\n\t * on the SharedString op is 11.\n\t *\n\t * The reference sequence numbers placed in this queue are also not accurate for stashed ops due to how the applyStashedOp\n\t * flow works at the runtime level. This is a legitimate bug, and AB#6602 tracks one way to fix it (stop reaching all the way\n\t * to deltaManager's lastSequenceNumber to obtain refSeq, instead leveraging some analogous notion on the container or datastore\n\t * runtime).\n\t */\n\tprivate readonly inFlightRefSeqs = new Deque<number>();\n\n\tprivate ongoingResubmitRefSeq: number | undefined;\n\n\t/**\n\t * Gets the reference sequence number (i.e. sequence number of the runtime's last processed op) for an op submitted\n\t * in the current context.\n\t *\n\t * This value can be optionally overridden using `useResubmitRefSeq`.\n\t * IntervalCollection's resubmit logic currently relies on preserving merge information from when the op was originally submitted,\n\t * even if the op is resubmitted more than once. Thus during resubmit, `inFlightRefSeqs` gets populated with the\n\t * original refSeq rather than the refSeq at the time of reconnection.\n\t *\n\t * @remarks - In some not fully understood cases, the runtime may process incoming ops before putting an op that this\n\t * DDS submits over the wire. See `inFlightRefSeqs` for more details.\n\t */\n\tprivate get currentRefSeq() {\n\t\treturn this.ongoingResubmitRefSeq ?? this.deltaManager.lastSequenceNumber;\n\t}\n\n\tprotected client: Client;\n\tprivate messagesSinceMSNChange: ISequencedDocumentMessage[] = [];\n\tprivate readonly intervalCollections: IntervalCollectionMap;\n\tconstructor(\n\t\tdataStoreRuntime: IFluidDataStoreRuntime,\n\t\tpublic id: string,\n\t\tattributes: IChannelAttributes,\n\t\tpublic readonly segmentFromSpec: (spec: IJSONSegment) => ISegment,\n\t) {\n\t\tsuper(id, dataStoreRuntime, attributes, \"fluid_sequence_\");\n\n\t\tconst getMinInFlightRefSeq = () => this.inFlightRefSeqs.get(0);\n\t\tthis.guardReentrancy =\n\t\t\t(dataStoreRuntime.options.sharedStringPreventReentrancy ?? true)\n\t\t\t\t? ensureNoReentrancy\n\t\t\t\t: createReentrancyDetector((depth) => {\n\t\t\t\t\t\tif (totalReentrancyLogs > 0) {\n\t\t\t\t\t\t\ttotalReentrancyLogs--;\n\t\t\t\t\t\t\tthis.logger.sendTelemetryEvent(\n\t\t\t\t\t\t\t\t{ eventName: \"LocalOpReentry\", depth },\n\t\t\t\t\t\t\t\tnew LoggingError(reentrancyErrorMessage),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\n\t\tconst options = createConfigBasedOptionsProxy<SequenceOptions>(\n\t\t\tloggerToMonitoringContext(this.logger).config,\n\t\t\t\"Fluid.Sequence\",\n\t\t\t{\n\t\t\t\tmergeTreeEnableObliterate: (c, n) => c.getBoolean(n),\n\t\t\t\tmergeTreeEnableSidedObliterate: (c, n) => c.getBoolean(n),\n\t\t\t\tintervalStickinessEnabled: (c, n) => c.getBoolean(n),\n\t\t\t\tmergeTreeReferencesCanSlideToEndpoint: (c, n) => c.getBoolean(n),\n\t\t\t\tmergeTreeEnableAnnotateAdjust: (c, n) => c.getBoolean(n),\n\t\t\t},\n\t\t\tdataStoreRuntime.options,\n\t\t);\n\n\t\tthis.client = new Client(\n\t\t\tsegmentFromSpec,\n\t\t\tcreateChildLogger({\n\t\t\t\tlogger: this.logger,\n\t\t\t\tnamespace: \"SharedSegmentSequence.MergeTreeClient\",\n\t\t\t}),\n\t\t\toptions,\n\t\t\tgetMinInFlightRefSeq,\n\t\t);\n\n\t\tthis.client.prependListener(\"delta\", (opArgs, deltaArgs) => {\n\t\t\tconst event = new SequenceDeltaEventClass(opArgs, deltaArgs, this.client);\n\t\t\tif (event.isLocal && event.opArgs.rollback !== true) {\n\t\t\t\tthis.submitSequenceMessage(opArgs.op);\n\t\t\t}\n\t\t\tif (deltaArgs.deltaSegments.length > 0) {\n\t\t\t\tthis.emit(\"sequenceDelta\", event, this);\n\t\t\t}\n\t\t});\n\n\t\tthis.client.on(\"maintenance\", (args, opArgs) => {\n\t\t\tthis.emit(\n\t\t\t\t\"maintenance\",\n\t\t\t\tnew SequenceMaintenanceEventClass(opArgs, args, this.client),\n\t\t\t\tthis,\n\t\t\t);\n\t\t});\n\n\t\tthis.intervalCollections = new IntervalCollectionMap(\n\t\t\tthis.serializer,\n\t\t\tthis.handle,\n\t\t\t(op, localOpMetadata) => {\n\t\t\t\tif (!this.isAttached()) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tthis.inFlightRefSeqs.push(this.currentRefSeq);\n\t\t\t\tthis.submitLocalMessage(op, localOpMetadata);\n\t\t\t},\n\t\t\toptions,\n\t\t);\n\t}\n\n\tpublic removeRange(start: number, end: number): void {\n\t\tthis.guardReentrancy(() => this.client.removeRangeLocal(start, end));\n\t}\n\n\tpublic obliterateRange(\n\t\tstart: number | InteriorSequencePlace,\n\t\tend: number | InteriorSequencePlace,\n\t): void {\n\t\tthis.guardReentrancy(() => this.client.obliterateRangeLocal(start, end));\n\t}\n\n\t// eslint-disable-next-line import/no-deprecated\n\tpublic groupOperation(groupOp: IMergeTreeGroupMsg): void {\n\t\tthis.guardReentrancy(() => this.client.localTransaction(groupOp));\n\t}\n\n\tpublic getContainingSegment(pos: number): {\n\t\tsegment: T | undefined;\n\t\toffset: number | undefined;\n\t} {\n\t\treturn (\n\t\t\tthis.client.getContainingSegment<T>(pos) ?? { segment: undefined, offset: undefined }\n\t\t);\n\t}\n\n\tpublic getLength(): number {\n\t\treturn this.client.getLength();\n\t}\n\n\tpublic getPosition(segment: ISegment): number {\n\t\treturn this.client.getPosition(segment);\n\t}\n\n\tpublic annotateRange(start: number, end: number, props: PropertySet): void {\n\t\tthis.guardReentrancy(() => this.client.annotateRangeLocal(start, end, props));\n\t}\n\n\tpublic annotateAdjustRange(start: number, end: number, adjust: MapLike<AdjustParams>): void {\n\t\tthis.guardReentrancy(() => this.client.annotateAdjustRangeLocal(start, end, adjust));\n\t}\n\n\tpublic getPropertiesAtPosition(pos: number): PropertySet | undefined {\n\t\treturn this.client.getPropertiesAtPosition(pos);\n\t}\n\n\tpublic getRangeExtentsOfPosition(pos: number): {\n\t\tposStart: number | undefined;\n\t\tposAfterEnd: number | undefined;\n\t} {\n\t\treturn this.client.getRangeExtentsOfPosition(pos);\n\t}\n\n\tpublic createLocalReferencePosition(\n\t\tsegment: T,\n\t\toffset: number,\n\t\trefType: ReferenceType,\n\t\tproperties: PropertySet | undefined,\n\t\tslidingPreference?: SlidingPreference,\n\t\tcanSlideToEndpoint?: boolean,\n\t): LocalReferencePosition {\n\t\treturn this.client.createLocalReferencePosition(\n\t\t\tsegment,\n\t\t\toffset,\n\t\t\trefType,\n\t\t\tproperties,\n\t\t\tslidingPreference,\n\t\t\tcanSlideToEndpoint,\n\t\t);\n\t}\n\n\tpublic localReferencePositionToPosition(lref: ReferencePosition): number {\n\t\treturn this.client.localReferencePositionToPosition(lref);\n\t}\n\n\tpublic removeLocalReferencePosition(\n\t\tlref: LocalReferencePosition,\n\t): LocalReferencePosition | undefined {\n\t\treturn this.client.removeLocalReferencePosition(lref);\n\t}\n\n\tpublic resolveRemoteClientPosition(\n\t\tremoteClientPosition: number,\n\t\tremoteClientRefSeq: number,\n\t\tremoteClientId: string,\n\t): number | undefined {\n\t\treturn this.client.resolveRemoteClientPosition(\n\t\t\tremoteClientPosition,\n\t\t\tremoteClientRefSeq,\n\t\t\tremoteClientId,\n\t\t);\n\t}\n\n\tprivate submitSequenceMessage(message: IMergeTreeOp) {\n\t\tif (!this.isAttached()) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.inFlightRefSeqs.push(this.currentRefSeq);\n\n\t\tconst metadata = this.client.peekPendingSegmentGroups(\n\t\t\tmessage.type === MergeTreeDeltaType.GROUP ? message.ops.length : 1,\n\t\t);\n\n\t\tthis.submitLocalMessage(message, metadata);\n\t}\n\n\tpublic posFromRelativePos(relativePos: IRelativePosition): number {\n\t\treturn this.client.posFromRelativePos(relativePos);\n\t}\n\n\tpublic walkSegments<TClientData>(\n\t\thandler: ISegmentAction<TClientData>,\n\t\tstart?: number,\n\t\tend?: number,\n\t\taccum?: TClientData,\n\t\tsplitRange: boolean = false,\n\t): void {\n\t\tthis.client.walkSegments(handler, start, end, accum as TClientData, splitRange);\n\t}\n\n\tpublic getCurrentSeq(): number {\n\t\treturn this.client.getCurrentSeq();\n\t}\n\n\tpublic insertAtReferencePosition(pos: ReferencePosition, segment: T): void {\n\t\tthis.guardReentrancy(() => this.client.insertAtReferencePositionLocal(pos, segment));\n\t}\n\n\tpublic insertFromSpec(pos: number, spec: IJSONSegment): void {\n\t\tconst segment = this.segmentFromSpec(spec);\n\t\tthis.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));\n\t}\n\n\tpublic getIntervalCollection(label: string): ISequenceIntervalCollection {\n\t\treturn this.intervalCollections.get(label);\n\t}\n\n\tpublic getIntervalCollectionLabels(): IterableIterator<string> {\n\t\treturn this.intervalCollections.keys();\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.summarizeCore}\n\t */\n\tprotected summarizeCore(\n\t\tserializer: IFluidSerializer,\n\t\ttelemetryContext?: ITelemetryContext,\n\t): ISummaryTreeWithStats {\n\t\tconst builder = new SummaryTreeBuilder();\n\n\t\t// conditionally write the interval collection blob\n\t\t// only if it has entries\n\t\tif (this.intervalCollections.size > 0) {\n\t\t\tbuilder.addBlob(snapshotFileName, this.intervalCollections.serialize(serializer));\n\t\t}\n\n\t\tbuilder.addWithStats(contentPath, this.summarizeMergeTree(serializer));\n\n\t\treturn builder.getSummaryTree();\n\t}\n\n\t/**\n\t * Runs serializer over the GC data for this SharedMatrix.\n\t * All the IFluidHandle's represent routes to other objects.\n\t */\n\tprotected processGCDataCore(serializer: IFluidSerializer) {\n\t\tif (this.intervalCollections.size > 0) {\n\t\t\tthis.intervalCollections.serialize(serializer);\n\t\t}\n\n\t\tthis.client.serializeGCData(this.handle, serializer);\n\t}\n\n\t/**\n\t * Replace the range specified from start to end with the provided segment\n\t * This is done by inserting the segment at the end of the range, followed\n\t * by removing the contents of the range\n\t * For a zero or reverse range (start \\>= end), insert at end do not remove anything\n\t * @param start - The start of the range to replace\n\t * @param end - The end of the range to replace\n\t * @param segment - The segment that will replace the range\n\t */\n\tprotected replaceRange(start: number, end: number, segment: ISegment): void {\n\t\t// Insert at the max end of the range when start > end, but still remove the range later\n\t\tconst insertIndex: number = Math.max(start, end);\n\n\t\t// Insert first, so local references can slide to the inserted seg if any\n\t\tconst insert = this.guardReentrancy(() =>\n\t\t\tthis.client.insertSegmentLocal(insertIndex, segment),\n\t\t);\n\n\t\tif (insert && start < end) {\n\t\t\tthis.removeRange(start, end);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.onConnect}\n\t */\n\tprotected onConnect() {\n\t\t// Update merge tree collaboration information with new client ID and then resend pending ops\n\t\tthis.client.startOrUpdateCollaboration(this.runtime.clientId);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.onDisconnect}\n\t */\n\tprotected onDisconnect() {}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.reSubmitCore}\n\t */\n\tprotected reSubmitCore(content: any, localOpMetadata: unknown, squash: boolean = false) {\n\t\tconst originalRefSeq = this.inFlightRefSeqs.shift();\n\t\tassert(\n\t\t\toriginalRefSeq !== undefined,\n\t\t\t0x8bb /* Expected a recorded refSeq when resubmitting an op */,\n\t\t);\n\t\tthis.useResubmitRefSeq(originalRefSeq, () => {\n\t\t\tif (!this.intervalCollections.tryResubmitMessage(content, localOpMetadata)) {\n\t\t\t\tthis.submitSequenceMessage(\n\t\t\t\t\tthis.client.regeneratePendingOp(content as IMergeTreeOp, localOpMetadata, squash),\n\t\t\t\t);\n\t\t\t}\n\t\t});\n\t}\n\n\tprotected reSubmitSquashed(content: unknown, localOpMetadata: unknown): void {\n\t\tthis.reSubmitCore(content, localOpMetadata, true);\n\t}\n\n\t/**\n\t * Revert an op\n\t */\n\tprotected rollback(content: any, localOpMetadata: unknown): void {\n\t\tconst originalRefSeq = this.inFlightRefSeqs.pop();\n\t\tassert(\n\t\t\toriginalRefSeq !== undefined,\n\t\t\t0xb7f /* Expected a recorded refSeq when rolling back an op */,\n\t\t);\n\n\t\tif (!this.intervalCollections.tryRollback(content, localOpMetadata)) {\n\t\t\tthis.client.rollback(content, localOpMetadata);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n\t */\n\tprotected async loadCore(storage: IChannelStorageService) {\n\t\tif (await storage.contains(snapshotFileName)) {\n\t\t\tconst blob = await storage.readBlob(snapshotFileName);\n\t\t\tconst header = bufferToString(blob, \"utf8\");\n\t\t\tthis.intervalCollections.populate(header);\n\t\t}\n\n\t\ttry {\n\t\t\t// this will load the header, and return a promise\n\t\t\t// that will resolve when the body is loaded\n\t\t\t// and the catchup ops are available.\n\t\t\tconst { catchupOpsP } = await this.client.load(\n\t\t\t\tthis.runtime,\n\t\t\t\tnew ObjectStoragePartition(storage, contentPath),\n\t\t\t\tthis.serializer,\n\t\t\t);\n\n\t\t\t// process the catch up ops, and finishing the loading process\n\t\t\t(await catchupOpsP).forEach((m) => {\n\t\t\t\tconst collabWindow = this.client.getCollabWindow();\n\t\t\t\tif (\n\t\t\t\t\tm.minimumSequenceNumber < collabWindow.minSeq ||\n\t\t\t\t\tm.referenceSequenceNumber < collabWindow.minSeq ||\n\t\t\t\t\tm.sequenceNumber <= collabWindow.minSeq ||\n\t\t\t\t\t// sequenceNumber could be the same if messages are part of a grouped batch\n\t\t\t\t\tm.sequenceNumber < collabWindow.currentSeq\n\t\t\t\t) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Invalid catchup operations in snapshot: ${JSON.stringify({\n\t\t\t\t\t\t\top: {\n\t\t\t\t\t\t\t\tseq: m.sequenceNumber,\n\t\t\t\t\t\t\t\tminSeq: m.minimumSequenceNumber,\n\t\t\t\t\t\t\t\trefSeq: m.referenceSequenceNumber,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tcollabWindow: {\n\t\t\t\t\t\t\t\tseq: collabWindow.currentSeq,\n\t\t\t\t\t\t\t\tminSeq: collabWindow.minSeq,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t})}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tthis.processMergeTreeMsg(m);\n\t\t\t});\n\n\t\t\t// Initialize the interval collections\n\t\t\tthis.initializeIntervalCollections();\n\t\t} catch (error) {\n\t\t\tthis.logger.sendErrorEvent({ eventName: \"SequenceLoadFailed\" }, error);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.processCore}\n\t */\n\tprotected processCore(\n\t\tmessage: ISequencedDocumentMessage,\n\t\tlocal: boolean,\n\t\tlocalOpMetadata: unknown,\n\t) {\n\t\tif (local) {\n\t\t\tconst recordedRefSeq = this.inFlightRefSeqs.shift();\n\t\t\tassert(recordedRefSeq !== undefined, 0x8bc /* No pending recorded refSeq found */);\n\t\t\t// TODO: AB#7076: Some equivalent assert should be enabled. This fails some e2e stashed op tests because\n\t\t\t// the deltaManager may have seen more messages than the runtime has processed while amidst the stashed op\n\t\t\t// flow, so e.g. when `applyStashedOp` is called and the DDS is put in a state where it expects an ack for\n\t\t\t// one of its messages, the delta manager has actually already seen subsequent messages from collaborators\n\t\t\t// which the in-flight message is concurrent to.\n\t\t\t// See \"handles stashed ops created on top of sequenced local ops\" for one such test case.\n\t\t\t// assert(recordedRefSeq <= message.referenceSequenceNumber, \"RefSeq mismatch\");\n\t\t}\n\n\t\tassert(\n\t\t\tmessage.type === MessageType.Operation,\n\t\t\t0x073 /* \"Sequence message not operation\" */,\n\t\t);\n\n\t\tconst handled = this.intervalCollections.tryProcessMessage(\n\t\t\tmessage.contents as IMapOperation,\n\t\t\tlocal,\n\t\t\tmessage,\n\t\t\tlocalOpMetadata,\n\t\t);\n\n\t\tif (!handled) {\n\t\t\tthis.processMergeTreeMsg(message, local);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.didAttach}\n\t */\n\tprotected didAttach() {\n\t\t// If we are not local, and we've attached we need to start generating and sending ops\n\t\t// so start collaboration and provide a default client id incase we are not connected\n\t\tif (this.isAttached()) {\n\t\t\tthis.client.startOrUpdateCollaboration(this.runtime.clientId ?? \"attached\");\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.initializeLocalCore}\n\t */\n\tprotected initializeLocalCore() {\n\t\tsuper.initializeLocalCore();\n\t\tthis.initializeIntervalCollections();\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}\n\t */\n\tprotected applyStashedOp(content: any): void {\n\t\tif (!this.intervalCollections.tryApplyStashedOp(content)) {\n\t\t\tthis.client.applyStashedOp(content);\n\t\t}\n\t}\n\n\tprivate summarizeMergeTree(serializer: IFluidSerializer): ISummaryTreeWithStats {\n\t\tconst minSeq = this.deltaManager.minimumSequenceNumber;\n\n\t\tthis.processMinSequenceNumberChanged(minSeq);\n\n\t\tthis.messagesSinceMSNChange.forEach((m) => {\n\t\t\tm.minimumSequenceNumber = minSeq;\n\t\t});\n\n\t\treturn this.client.summarize(\n\t\t\tthis.runtime,\n\t\t\tthis.handle,\n\t\t\tserializer,\n\t\t\tthis.messagesSinceMSNChange,\n\t\t);\n\t}\n\n\t/**\n\t *\n\t * @param message - Message with decoded and hydrated handles\n\t */\n\tprivate processMergeTreeMsg(message: ISequencedDocumentMessage, local?: boolean) {\n\t\tconst ops: IMergeTreeDeltaOp[] = [];\n\t\tfunction transformOps(event: SequenceDeltaEvent) {\n\t\t\tops.push(...SharedSegmentSequence.createOpsFromDelta(event));\n\t\t}\n\t\tconst needsTransformation = message.referenceSequenceNumber !== message.sequenceNumber - 1;\n\t\tlet stashMessage: Readonly<ISequencedDocumentMessage> = message;\n\t\tif (this.runtime.options.newMergeTreeSnapshotFormat !== true) {\n\t\t\tif (needsTransformation) {\n\t\t\t\tthis.on(\"sequenceDelta\", transformOps);\n\t\t\t}\n\t\t}\n\n\t\tthis.client.applyMsg(message, local);\n\n\t\tif (this.runtime.options.newMergeTreeSnapshotFormat !== true) {\n\t\t\tif (needsTransformation) {\n\t\t\t\tthis.removeListener(\"sequenceDelta\", transformOps);\n\t\t\t\t// shallow clone the message as we only overwrite top level properties,\n\t\t\t\t// like referenceSequenceNumber and content only\n\t\t\t\tstashMessage = {\n\t\t\t\t\t...message,\n\t\t\t\t\treferenceSequenceNumber: stashMessage.sequenceNumber - 1,\n\t\t\t\t\t// eslint-disable-next-line import/no-deprecated\n\t\t\t\t\tcontents: ops.length !== 1 ? createGroupOp(...ops) : ops[0],\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tthis.messagesSinceMSNChange.push(stashMessage);\n\n\t\t\t// Do GC every once in a while...\n\t\t\tif (\n\t\t\t\tthis.messagesSinceMSNChange.length > 20 &&\n\t\t\t\tthis.messagesSinceMSNChange[20].sequenceNumber < message.minimumSequenceNumber\n\t\t\t) {\n\t\t\t\tthis.processMinSequenceNumberChanged(message.minimumSequenceNumber);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate processMinSequenceNumberChanged(minSeq: number) {\n\t\tlet index = 0;\n\t\tfor (; index < this.messagesSinceMSNChange.length; index++) {\n\t\t\tif (this.messagesSinceMSNChange[index].sequenceNumber > minSeq) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (index !== 0) {\n\t\t\tthis.messagesSinceMSNChange = this.messagesSinceMSNChange.slice(index);\n\t\t}\n\t}\n\n\tprivate initializeIntervalCollections() {\n\t\t// Listen and initialize new SharedIntervalCollections\n\t\tthis.intervalCollections.events.on(\n\t\t\t\"createIntervalCollection\",\n\t\t\t(key: string, local: boolean) => {\n\t\t\t\tconst intervalCollection = this.intervalCollections.get(key);\n\t\t\t\tif (!intervalCollection.attached) {\n\t\t\t\t\tintervalCollection.attachGraph(this.client, key);\n\t\t\t\t}\n\t\t\t\tthis.emit(\"createIntervalCollection\", key, local, this);\n\t\t\t},\n\t\t);\n\n\t\t// Initialize existing SharedIntervalCollections\n\t\tfor (const key of this.intervalCollections.keys()) {\n\t\t\tconst intervalCollection = this.intervalCollections.get(key);\n\t\t\tintervalCollection.attachGraph(this.client, key);\n\t\t}\n\t}\n\n\t/**\n\t * Overrides the \"currently applicable reference sequence number\" for the duration of the callback.\n\t * See remarks on `currentRefSeq` for more context.\n\t */\n\tprivate useResubmitRefSeq(refSeq: number, callback: () => void) {\n\t\tconst previousResubmitRefSeq = this.ongoingResubmitRefSeq;\n\t\tthis.ongoingResubmitRefSeq = refSeq;\n\t\ttry {\n\t\t\tcallback();\n\t\t} finally {\n\t\t\tthis.ongoingResubmitRefSeq = previousResubmitRefSeq;\n\t\t}\n\t}\n}\n\nfunction createReentrancyDetector(\n\tonReentrancy: (depth: number) => void,\n): <T>(callback: () => T) => T {\n\tlet depth = 0;\n\tfunction detectReentrancy<T>(callback: () => T): T {\n\t\tif (depth > 0) {\n\t\t\tonReentrancy(depth);\n\t\t}\n\t\tdepth++;\n\t\ttry {\n\t\t\treturn callback();\n\t\t} finally {\n\t\t\tdepth--;\n\t\t}\n\t}\n\n\treturn detectReentrancy;\n}\n\n/**\n * Apps which generate reentrant behavior may do so at a high frequency.\n * Logging even per-SharedSegmentSequence instance might be too noisy, and having a few logs from a session\n * is likely enough.\n */\nlet totalReentrancyLogs = 3;\n\n/**\n * Resets the reentrancy log counter. Test-only API.\n */\nexport function resetReentrancyLogCounter() {\n\ttotalReentrancyLogs = 3;\n}\n\nconst reentrancyErrorMessage = \"Reentrancy detected in sequence local ops\";\nconst ensureNoReentrancy = createReentrancyDetector(() => {\n\tthrow new LoggingError(reentrancyErrorMessage);\n});\n"]}
|