@fluidframework/sequence 2.0.0-dev.7.4.0.217212 → 2.0.0-dev.7.4.0.221926
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 +57 -0
- package/api-extractor.json +0 -3
- package/api-report/sequence.api.md +33 -25
- package/dist/intervalCollection.d.ts +31 -6
- package/dist/intervalCollection.d.ts.map +1 -1
- package/dist/intervalCollection.js +45 -43
- package/dist/intervalCollection.js.map +1 -1
- package/dist/intervalIndex/intervalIndex.d.ts +1 -1
- package/dist/intervalIndex/intervalIndex.js.map +1 -1
- package/dist/intervals/intervalUtils.d.ts +6 -7
- package/dist/intervals/intervalUtils.d.ts.map +1 -1
- package/dist/intervals/intervalUtils.js +2 -2
- package/dist/intervals/intervalUtils.js.map +1 -1
- package/dist/intervals/sequenceInterval.d.ts +1 -1
- package/dist/intervals/sequenceInterval.js +1 -1
- package/dist/intervals/sequenceInterval.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/sequence-alpha.d.ts +1188 -106
- package/dist/sequence-beta.d.ts +44 -0
- package/dist/sequence-public.d.ts +44 -0
- package/dist/sequence-untrimmed.d.ts +40 -26
- package/dist/sequence.d.ts +2 -2
- package/dist/sequence.js +1 -1
- package/dist/sequence.js.map +1 -1
- package/dist/sequenceDeltaEvent.d.ts +4 -4
- package/dist/sequenceDeltaEvent.js +3 -3
- package/dist/sequenceDeltaEvent.js.map +1 -1
- package/dist/sequenceFactory.d.ts +1 -1
- package/dist/sequenceFactory.js +1 -1
- package/dist/sequenceFactory.js.map +1 -1
- package/dist/sharedIntervalCollection.d.ts +1 -1
- package/dist/sharedIntervalCollection.js.map +1 -1
- package/dist/sharedString.d.ts +3 -3
- package/dist/sharedString.js +1 -1
- package/dist/sharedString.js.map +1 -1
- package/lib/defaultMap.js +22 -18
- package/lib/defaultMap.js.map +1 -1
- package/lib/defaultMapInterfaces.js +2 -1
- package/lib/defaultMapInterfaces.js.map +1 -1
- package/lib/index.js +45 -10
- package/lib/index.js.map +1 -1
- package/lib/intervalCollection.d.ts +31 -6
- package/lib/intervalCollection.d.ts.map +1 -1
- package/lib/intervalCollection.js +169 -154
- package/lib/intervalCollection.js.map +1 -1
- package/lib/intervalIndex/endpointInRangeIndex.js +17 -12
- package/lib/intervalIndex/endpointInRangeIndex.js.map +1 -1
- package/lib/intervalIndex/endpointIndex.js +13 -8
- package/lib/intervalIndex/endpointIndex.js.map +1 -1
- package/lib/intervalIndex/idIntervalIndex.js +8 -4
- package/lib/intervalIndex/idIntervalIndex.js.map +1 -1
- package/lib/intervalIndex/index.js +19 -6
- package/lib/intervalIndex/index.js.map +1 -1
- package/lib/intervalIndex/intervalIndex.d.ts +1 -1
- package/lib/intervalIndex/intervalIndex.js +2 -1
- package/lib/intervalIndex/intervalIndex.js.map +1 -1
- package/lib/intervalIndex/intervalIndexUtils.js +8 -4
- package/lib/intervalIndex/intervalIndexUtils.js.map +1 -1
- package/lib/intervalIndex/overlappingIntervalsIndex.js +15 -10
- package/lib/intervalIndex/overlappingIntervalsIndex.js.map +1 -1
- package/lib/intervalIndex/overlappingSequenceIntervalsIndex.js +14 -10
- package/lib/intervalIndex/overlappingSequenceIntervalsIndex.js.map +1 -1
- package/lib/intervalIndex/sequenceIntervalIndexes.js +2 -1
- package/lib/intervalIndex/sequenceIntervalIndexes.js.map +1 -1
- package/lib/intervalIndex/startpointInRangeIndex.js +17 -12
- package/lib/intervalIndex/startpointInRangeIndex.js.map +1 -1
- package/lib/intervalTree.js +9 -4
- package/lib/intervalTree.js.map +1 -1
- package/lib/intervals/index.js +18 -3
- package/lib/intervals/index.js.map +1 -1
- package/lib/intervals/interval.js +18 -13
- package/lib/intervals/interval.js.map +1 -1
- package/lib/intervals/intervalUtils.d.ts +6 -7
- package/lib/intervals/intervalUtils.d.ts.map +1 -1
- package/lib/intervals/intervalUtils.js +20 -15
- package/lib/intervals/intervalUtils.js.map +1 -1
- package/lib/intervals/sequenceInterval.d.ts +1 -1
- package/lib/intervals/sequenceInterval.js +66 -60
- package/lib/intervals/sequenceInterval.js.map +1 -1
- package/lib/localValues.js +9 -4
- package/lib/localValues.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +5 -2
- package/lib/packageVersion.js.map +1 -1
- package/lib/revertibles.js +69 -59
- package/lib/revertibles.js.map +1 -1
- package/lib/sequence-alpha.d.ts +1188 -106
- package/lib/sequence-beta.d.ts +44 -0
- package/lib/sequence-public.d.ts +44 -0
- package/lib/sequence-untrimmed.d.ts +40 -26
- package/lib/sequence.d.ts +2 -2
- package/lib/sequence.js +45 -40
- package/lib/sequence.js.map +1 -1
- package/lib/sequenceDeltaEvent.d.ts +4 -4
- package/lib/sequenceDeltaEvent.js +16 -10
- package/lib/sequenceDeltaEvent.js.map +1 -1
- package/lib/sequenceFactory.d.ts +1 -1
- package/lib/sequenceFactory.js +14 -10
- package/lib/sequenceFactory.js.map +1 -1
- package/lib/sharedIntervalCollection.d.ts +1 -1
- package/lib/sharedIntervalCollection.js +18 -13
- package/lib/sharedIntervalCollection.js.map +1 -1
- package/lib/sharedSequence.js +11 -6
- package/lib/sharedSequence.js.map +1 -1
- package/lib/sharedString.d.ts +3 -3
- package/lib/sharedString.js +22 -17
- package/lib/sharedString.js.map +1 -1
- package/package.json +18 -17
- package/sequence.test-files.tar +0 -0
- package/src/intervalCollection.ts +88 -55
- package/src/intervalIndex/intervalIndex.ts +1 -1
- package/src/intervals/intervalUtils.ts +6 -7
- package/src/intervals/sequenceInterval.ts +1 -1
- package/src/packageVersion.ts +1 -1
- package/src/sequence.ts +2 -2
- package/src/sequenceDeltaEvent.ts +4 -4
- package/src/sequenceFactory.ts +1 -1
- package/src/sharedIntervalCollection.ts +1 -1
- package/src/sharedString.ts +3 -3
|
@@ -1,46 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/*!
|
|
2
3
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
4
|
* Licensed under the MIT License.
|
|
4
5
|
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.intervalLocatorFromEndpoint = exports.IntervalCollection = exports.makeOpsMap = exports.IntervalCollectionValueType = exports.SequenceIntervalCollectionValueType = exports.LocalIntervalCollection = exports.createIntervalIndex = exports.computeStickinessFromSide = exports.endpointPosAndSide = exports.sidesFromStickiness = exports.Side = void 0;
|
|
5
8
|
/* eslint-disable no-bitwise */
|
|
6
9
|
/* eslint-disable import/no-deprecated */
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const client_utils_1 = require("@fluid-internal/client-utils");
|
|
11
|
+
const core_utils_1 = require("@fluidframework/core-utils");
|
|
12
|
+
const merge_tree_1 = require("@fluidframework/merge-tree");
|
|
13
|
+
const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
|
|
14
|
+
const uuid_1 = require("uuid");
|
|
15
|
+
const intervals_1 = require("./intervals");
|
|
16
|
+
const intervalIndex_1 = require("./intervalIndex");
|
|
14
17
|
/**
|
|
15
18
|
* Defines a side relative to a character in a sequence.
|
|
16
19
|
*
|
|
17
20
|
* @remarks See {@link SequencePlace} for additional context on usage.
|
|
18
|
-
* @
|
|
21
|
+
* @alpha
|
|
19
22
|
*/
|
|
20
|
-
|
|
23
|
+
var Side;
|
|
21
24
|
(function (Side) {
|
|
22
25
|
Side[Side["Before"] = 0] = "Before";
|
|
23
26
|
Side[Side["After"] = 1] = "After";
|
|
24
|
-
})(Side || (Side = {}));
|
|
27
|
+
})(Side || (exports.Side = Side = {}));
|
|
25
28
|
const reservedIntervalIdKey = "intervalId";
|
|
26
|
-
|
|
27
|
-
const startSide = (stickiness & IntervalStickiness.START) !== 0 ? Side.After : Side.Before;
|
|
28
|
-
const endSide = (stickiness & IntervalStickiness.END) !== 0 ? Side.Before : Side.After;
|
|
29
|
+
function sidesFromStickiness(stickiness) {
|
|
30
|
+
const startSide = (stickiness & intervals_1.IntervalStickiness.START) !== 0 ? Side.After : Side.Before;
|
|
31
|
+
const endSide = (stickiness & intervals_1.IntervalStickiness.END) !== 0 ? Side.Before : Side.After;
|
|
29
32
|
return { startSide, endSide };
|
|
30
33
|
}
|
|
34
|
+
exports.sidesFromStickiness = sidesFromStickiness;
|
|
31
35
|
/**
|
|
32
36
|
* Decompress an interval after loading a summary from JSON. The exact format
|
|
33
37
|
* of this compression is unspecified and subject to change
|
|
34
38
|
*/
|
|
35
39
|
function decompressInterval(interval, label) {
|
|
36
|
-
const stickiness = interval[5] ?? IntervalStickiness.END;
|
|
40
|
+
const stickiness = interval[5] ?? intervals_1.IntervalStickiness.END;
|
|
37
41
|
const { startSide, endSide } = sidesFromStickiness(stickiness);
|
|
38
42
|
return {
|
|
39
43
|
start: interval[0],
|
|
40
44
|
end: interval[1],
|
|
41
45
|
sequenceNumber: interval[2],
|
|
42
46
|
intervalType: interval[3],
|
|
43
|
-
properties: { ...interval[4], [reservedRangeLabelsKey]: [label] },
|
|
47
|
+
properties: { ...interval[4], [merge_tree_1.reservedRangeLabelsKey]: [label] },
|
|
44
48
|
stickiness,
|
|
45
49
|
startSide,
|
|
46
50
|
endSide,
|
|
@@ -59,15 +63,15 @@ function compressInterval(interval) {
|
|
|
59
63
|
intervalType,
|
|
60
64
|
// remove the `referenceRangeLabels` property as it is already stored
|
|
61
65
|
// in the `label` field of the summary
|
|
62
|
-
{ ...properties, [reservedRangeLabelsKey]: undefined },
|
|
66
|
+
{ ...properties, [merge_tree_1.reservedRangeLabelsKey]: undefined },
|
|
63
67
|
];
|
|
64
|
-
if (interval.stickiness !== undefined && interval.stickiness !== IntervalStickiness.END) {
|
|
68
|
+
if (interval.stickiness !== undefined && interval.stickiness !== intervals_1.IntervalStickiness.END) {
|
|
65
69
|
// reassignment to make it easier for typescript to reason about types
|
|
66
70
|
base = [...base, interval.stickiness];
|
|
67
71
|
}
|
|
68
72
|
return base;
|
|
69
73
|
}
|
|
70
|
-
|
|
74
|
+
function endpointPosAndSide(start, end) {
|
|
71
75
|
const startIsPlainEndpoint = typeof start === "number" || start === "start" || start === "end";
|
|
72
76
|
const endIsPlainEndpoint = typeof end === "number" || end === "start" || end === "end";
|
|
73
77
|
const startSide = startIsPlainEndpoint ? Side.Before : start?.side;
|
|
@@ -81,30 +85,33 @@ export function endpointPosAndSide(start, end) {
|
|
|
81
85
|
endPos,
|
|
82
86
|
};
|
|
83
87
|
}
|
|
88
|
+
exports.endpointPosAndSide = endpointPosAndSide;
|
|
84
89
|
function toSequencePlace(pos, side) {
|
|
85
90
|
return typeof pos === "number" ? { pos, side } : pos;
|
|
86
91
|
}
|
|
87
92
|
function toOptionalSequencePlace(pos, side = Side.Before) {
|
|
88
93
|
return typeof pos === "number" ? { pos, side } : pos;
|
|
89
94
|
}
|
|
90
|
-
|
|
91
|
-
let stickiness = IntervalStickiness.NONE;
|
|
95
|
+
function computeStickinessFromSide(startPos = -1, startSide = Side.Before, endPos = -1, endSide = Side.Before) {
|
|
96
|
+
let stickiness = intervals_1.IntervalStickiness.NONE;
|
|
92
97
|
if (startSide === Side.After || startPos === "start") {
|
|
93
|
-
stickiness |= IntervalStickiness.START;
|
|
98
|
+
stickiness |= intervals_1.IntervalStickiness.START;
|
|
94
99
|
}
|
|
95
100
|
if (endSide === Side.Before || endPos === "end") {
|
|
96
|
-
stickiness |= IntervalStickiness.END;
|
|
101
|
+
stickiness |= intervals_1.IntervalStickiness.END;
|
|
97
102
|
}
|
|
98
103
|
return stickiness;
|
|
99
104
|
}
|
|
100
|
-
|
|
105
|
+
exports.computeStickinessFromSide = computeStickinessFromSide;
|
|
106
|
+
function createIntervalIndex() {
|
|
101
107
|
const helpers = {
|
|
102
|
-
create: createInterval,
|
|
108
|
+
create: intervals_1.createInterval,
|
|
103
109
|
};
|
|
104
110
|
const lc = new LocalIntervalCollection(undefined, "", helpers, {});
|
|
105
111
|
return lc;
|
|
106
112
|
}
|
|
107
|
-
|
|
113
|
+
exports.createIntervalIndex = createIntervalIndex;
|
|
114
|
+
class LocalIntervalCollection {
|
|
108
115
|
constructor(client, label, helpers, options,
|
|
109
116
|
/** Callback invoked each time one of the endpoints of an interval slides. */
|
|
110
117
|
onPositionChange) {
|
|
@@ -113,9 +120,9 @@ export class LocalIntervalCollection {
|
|
|
113
120
|
this.helpers = helpers;
|
|
114
121
|
this.options = options;
|
|
115
122
|
this.onPositionChange = onPositionChange;
|
|
116
|
-
this.overlappingIntervalsIndex = new OverlappingIntervalsIndex(client, helpers);
|
|
117
|
-
this.idIntervalIndex = createIdIntervalIndex();
|
|
118
|
-
this.endIntervalIndex = new EndpointIndex(client, helpers);
|
|
123
|
+
this.overlappingIntervalsIndex = new intervalIndex_1.OverlappingIntervalsIndex(client, helpers);
|
|
124
|
+
this.idIntervalIndex = (0, intervalIndex_1.createIdIntervalIndex)();
|
|
125
|
+
this.endIntervalIndex = new intervalIndex_1.EndpointIndex(client, helpers);
|
|
119
126
|
this.indexes = new Set([
|
|
120
127
|
this.overlappingIntervalsIndex,
|
|
121
128
|
this.idIntervalIndex,
|
|
@@ -144,7 +151,7 @@ export class LocalIntervalCollection {
|
|
|
144
151
|
const newProps = {
|
|
145
152
|
[reservedIntervalIdKey]: id,
|
|
146
153
|
};
|
|
147
|
-
serializedInterval.properties = addProperties(serializedInterval.properties, newProps);
|
|
154
|
+
serializedInterval.properties = (0, merge_tree_1.addProperties)(serializedInterval.properties, newProps);
|
|
148
155
|
}
|
|
149
156
|
// Make the ID immutable for safety's sake.
|
|
150
157
|
Object.defineProperty(serializedInterval.properties, reservedIntervalIdKey, {
|
|
@@ -177,25 +184,25 @@ export class LocalIntervalCollection {
|
|
|
177
184
|
const interval = this.createInterval(start, end, intervalType, op);
|
|
178
185
|
if (interval) {
|
|
179
186
|
if (!interval.properties) {
|
|
180
|
-
interval.properties = createMap();
|
|
187
|
+
interval.properties = (0, merge_tree_1.createMap)();
|
|
181
188
|
}
|
|
182
189
|
if (props) {
|
|
183
190
|
// This check is intended to prevent scenarios where a random interval is created and then
|
|
184
191
|
// inserted into a collection. The aim is to ensure that the collection is created first
|
|
185
192
|
// then the user can create/add intervals based on the collection
|
|
186
|
-
if (props[reservedRangeLabelsKey] !== undefined &&
|
|
187
|
-
props[reservedRangeLabelsKey][0] !== this.label) {
|
|
188
|
-
throw new LoggingError("Adding an interval that belongs to another interval collection is not permitted");
|
|
193
|
+
if (props[merge_tree_1.reservedRangeLabelsKey] !== undefined &&
|
|
194
|
+
props[merge_tree_1.reservedRangeLabelsKey][0] !== this.label) {
|
|
195
|
+
throw new telemetry_utils_1.LoggingError("Adding an interval that belongs to another interval collection is not permitted");
|
|
189
196
|
}
|
|
190
197
|
interval.addProperties(props);
|
|
191
198
|
}
|
|
192
|
-
(_a = interval.properties)[reservedIntervalIdKey] ?? (_a[reservedIntervalIdKey] =
|
|
199
|
+
(_a = interval.properties)[reservedIntervalIdKey] ?? (_a[reservedIntervalIdKey] = (0, uuid_1.v4)());
|
|
193
200
|
this.add(interval);
|
|
194
201
|
}
|
|
195
202
|
return interval;
|
|
196
203
|
}
|
|
197
204
|
linkEndpointsToInterval(interval) {
|
|
198
|
-
if (interval instanceof SequenceInterval) {
|
|
205
|
+
if (interval instanceof intervals_1.SequenceInterval) {
|
|
199
206
|
interval.start.addProperties({ interval });
|
|
200
207
|
interval.end.addProperties({ interval });
|
|
201
208
|
}
|
|
@@ -234,9 +241,9 @@ export class LocalIntervalCollection {
|
|
|
234
241
|
// either, so this must be special-cased.
|
|
235
242
|
return ref;
|
|
236
243
|
}
|
|
237
|
-
return this.client.createLocalReferencePosition(segment, ref.getOffset(), ReferenceType.Transient, ref.properties, ref.slidingPreference, ref.canSlideToEndpoint);
|
|
244
|
+
return this.client.createLocalReferencePosition(segment, ref.getOffset(), merge_tree_1.ReferenceType.Transient, ref.properties, ref.slidingPreference, ref.canSlideToEndpoint);
|
|
238
245
|
};
|
|
239
|
-
if (interval instanceof SequenceInterval) {
|
|
246
|
+
if (interval instanceof intervals_1.SequenceInterval) {
|
|
240
247
|
let previousInterval;
|
|
241
248
|
let pendingChanges = 0;
|
|
242
249
|
interval.addPositionChangeListeners(() => {
|
|
@@ -249,7 +256,7 @@ export class LocalIntervalCollection {
|
|
|
249
256
|
this.removeIntervalFromIndexes(interval);
|
|
250
257
|
}
|
|
251
258
|
}, () => {
|
|
252
|
-
assert(previousInterval !== undefined, 0x3fa /* Invalid interleaving of before/after slide */);
|
|
259
|
+
(0, core_utils_1.assert)(previousInterval !== undefined, 0x3fa /* Invalid interleaving of before/after slide */);
|
|
253
260
|
pendingChanges--;
|
|
254
261
|
if (pendingChanges === 0) {
|
|
255
262
|
this.addIntervalToIndexes(interval);
|
|
@@ -260,21 +267,22 @@ export class LocalIntervalCollection {
|
|
|
260
267
|
}
|
|
261
268
|
}
|
|
262
269
|
removeIntervalListeners(interval) {
|
|
263
|
-
if (interval instanceof SequenceInterval) {
|
|
270
|
+
if (interval instanceof intervals_1.SequenceInterval) {
|
|
264
271
|
interval.removePositionChangeListeners();
|
|
265
272
|
}
|
|
266
273
|
}
|
|
267
274
|
}
|
|
275
|
+
exports.LocalIntervalCollection = LocalIntervalCollection;
|
|
268
276
|
LocalIntervalCollection.legacyIdPrefix = "legacy";
|
|
269
277
|
class SequenceIntervalCollectionFactory {
|
|
270
278
|
load(emitter, raw = [], options) {
|
|
271
|
-
return new IntervalCollection(sequenceIntervalHelpers, true, emitter, raw, options);
|
|
279
|
+
return new IntervalCollection(intervals_1.sequenceIntervalHelpers, true, emitter, raw, options);
|
|
272
280
|
}
|
|
273
281
|
store(value) {
|
|
274
282
|
return value.serializeInternal();
|
|
275
283
|
}
|
|
276
284
|
}
|
|
277
|
-
|
|
285
|
+
class SequenceIntervalCollectionValueType {
|
|
278
286
|
get name() {
|
|
279
287
|
return SequenceIntervalCollectionValueType.Name;
|
|
280
288
|
}
|
|
@@ -285,13 +293,14 @@ export class SequenceIntervalCollectionValueType {
|
|
|
285
293
|
return SequenceIntervalCollectionValueType._ops;
|
|
286
294
|
}
|
|
287
295
|
}
|
|
296
|
+
exports.SequenceIntervalCollectionValueType = SequenceIntervalCollectionValueType;
|
|
288
297
|
SequenceIntervalCollectionValueType.Name = "sharedStringIntervalCollection";
|
|
289
298
|
SequenceIntervalCollectionValueType._factory = new SequenceIntervalCollectionFactory();
|
|
290
299
|
SequenceIntervalCollectionValueType._ops = makeOpsMap();
|
|
291
300
|
class IntervalCollectionFactory {
|
|
292
301
|
load(emitter, raw = [], options) {
|
|
293
302
|
const helpers = {
|
|
294
|
-
create: createInterval,
|
|
303
|
+
create: intervals_1.createInterval,
|
|
295
304
|
};
|
|
296
305
|
const collection = new IntervalCollection(helpers, false, emitter, raw, options);
|
|
297
306
|
collection.attachGraph(undefined, "");
|
|
@@ -301,7 +310,7 @@ class IntervalCollectionFactory {
|
|
|
301
310
|
return value.serializeInternal();
|
|
302
311
|
}
|
|
303
312
|
}
|
|
304
|
-
|
|
313
|
+
class IntervalCollectionValueType {
|
|
305
314
|
get name() {
|
|
306
315
|
return IntervalCollectionValueType.Name;
|
|
307
316
|
}
|
|
@@ -312,10 +321,11 @@ export class IntervalCollectionValueType {
|
|
|
312
321
|
return IntervalCollectionValueType._ops;
|
|
313
322
|
}
|
|
314
323
|
}
|
|
324
|
+
exports.IntervalCollectionValueType = IntervalCollectionValueType;
|
|
315
325
|
IntervalCollectionValueType.Name = "sharedIntervalCollection";
|
|
316
326
|
IntervalCollectionValueType._factory = new IntervalCollectionFactory();
|
|
317
327
|
IntervalCollectionValueType._ops = makeOpsMap();
|
|
318
|
-
|
|
328
|
+
function makeOpsMap() {
|
|
319
329
|
const rebase = (collection, op, localOpMetadata) => {
|
|
320
330
|
const { localSeq } = localOpMetadata;
|
|
321
331
|
const rebasedValue = collection.rebaseLocalInterval(op.opName, op.value, localSeq);
|
|
@@ -327,7 +337,7 @@ export function makeOpsMap() {
|
|
|
327
337
|
};
|
|
328
338
|
return new Map([
|
|
329
339
|
[
|
|
330
|
-
IntervalOpType.ADD,
|
|
340
|
+
intervals_1.IntervalOpType.ADD,
|
|
331
341
|
{
|
|
332
342
|
process: (collection, params, local, op, localOpMetadata) => {
|
|
333
343
|
// if params is undefined, the interval was deleted during
|
|
@@ -335,17 +345,17 @@ export function makeOpsMap() {
|
|
|
335
345
|
if (!params) {
|
|
336
346
|
return;
|
|
337
347
|
}
|
|
338
|
-
assert(op !== undefined, 0x3fb /* op should exist here */);
|
|
348
|
+
(0, core_utils_1.assert)(op !== undefined, 0x3fb /* op should exist here */);
|
|
339
349
|
collection.ackAdd(params, local, op, localOpMetadata);
|
|
340
350
|
},
|
|
341
351
|
rebase,
|
|
342
352
|
},
|
|
343
353
|
],
|
|
344
354
|
[
|
|
345
|
-
IntervalOpType.DELETE,
|
|
355
|
+
intervals_1.IntervalOpType.DELETE,
|
|
346
356
|
{
|
|
347
357
|
process: (collection, params, local, op) => {
|
|
348
|
-
assert(op !== undefined, 0x3fc /* op should exist here */);
|
|
358
|
+
(0, core_utils_1.assert)(op !== undefined, 0x3fc /* op should exist here */);
|
|
349
359
|
collection.ackDelete(params, local, op);
|
|
350
360
|
},
|
|
351
361
|
rebase: (collection, op, localOpMetadata) => {
|
|
@@ -355,7 +365,7 @@ export function makeOpsMap() {
|
|
|
355
365
|
},
|
|
356
366
|
],
|
|
357
367
|
[
|
|
358
|
-
IntervalOpType.CHANGE,
|
|
368
|
+
intervals_1.IntervalOpType.CHANGE,
|
|
359
369
|
{
|
|
360
370
|
process: (collection, params, local, op, localOpMetadata) => {
|
|
361
371
|
// if params is undefined, the interval was deleted during
|
|
@@ -363,7 +373,7 @@ export function makeOpsMap() {
|
|
|
363
373
|
if (!params) {
|
|
364
374
|
return;
|
|
365
375
|
}
|
|
366
|
-
assert(op !== undefined, 0x3fd /* op should exist here */);
|
|
376
|
+
(0, core_utils_1.assert)(op !== undefined, 0x3fd /* op should exist here */);
|
|
367
377
|
collection.ackChange(params, local, op, localOpMetadata);
|
|
368
378
|
},
|
|
369
379
|
rebase,
|
|
@@ -371,6 +381,7 @@ export function makeOpsMap() {
|
|
|
371
381
|
],
|
|
372
382
|
]);
|
|
373
383
|
}
|
|
384
|
+
exports.makeOpsMap = makeOpsMap;
|
|
374
385
|
class IntervalCollectionIterator {
|
|
375
386
|
constructor(collection, iteratesForward = true, start, end) {
|
|
376
387
|
this.results = [];
|
|
@@ -398,7 +409,7 @@ const isSequencePlace = (place) => {
|
|
|
398
409
|
/**
|
|
399
410
|
* {@inheritdoc IIntervalCollection}
|
|
400
411
|
*/
|
|
401
|
-
|
|
412
|
+
class IntervalCollection extends client_utils_1.TypedEventEmitter {
|
|
402
413
|
get attached() {
|
|
403
414
|
return !!this.localCollection;
|
|
404
415
|
}
|
|
@@ -422,7 +433,7 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
422
433
|
*/
|
|
423
434
|
attachIndex(index) {
|
|
424
435
|
if (!this.attached) {
|
|
425
|
-
throw new LoggingError("The local interval collection must exist");
|
|
436
|
+
throw new telemetry_utils_1.LoggingError("The local interval collection must exist");
|
|
426
437
|
}
|
|
427
438
|
for (const interval of this) {
|
|
428
439
|
index.add(interval);
|
|
@@ -434,7 +445,7 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
434
445
|
*/
|
|
435
446
|
detachIndex(index) {
|
|
436
447
|
if (!this.attached) {
|
|
437
|
-
throw new LoggingError("The local interval collection must exist");
|
|
448
|
+
throw new telemetry_utils_1.LoggingError("The local interval collection must exist");
|
|
438
449
|
}
|
|
439
450
|
// Avoid removing intervals if the index does not exist
|
|
440
451
|
if (!this.localCollection?.removeIndex(index)) {
|
|
@@ -447,7 +458,7 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
447
458
|
}
|
|
448
459
|
rebasePositionWithSegmentSlide(pos, seqNumberFrom, localSeq) {
|
|
449
460
|
if (!this.client) {
|
|
450
|
-
throw new LoggingError("mergeTree client must exist");
|
|
461
|
+
throw new telemetry_utils_1.LoggingError("mergeTree client must exist");
|
|
451
462
|
}
|
|
452
463
|
if (pos === "start" || pos === "end") {
|
|
453
464
|
return pos;
|
|
@@ -458,19 +469,19 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
458
469
|
clientId: this.client.getLongClientId(clientId),
|
|
459
470
|
}, localSeq);
|
|
460
471
|
// if segment is undefined, it slid off the string
|
|
461
|
-
assert(segment !== undefined, 0x54e /* No segment found */);
|
|
462
|
-
const segoff = getSlideToSegoff({ segment, offset }, undefined, this.options.mergeTreeReferencesCanSlideToEndpoint) ?? segment;
|
|
472
|
+
(0, core_utils_1.assert)(segment !== undefined, 0x54e /* No segment found */);
|
|
473
|
+
const segoff = (0, merge_tree_1.getSlideToSegoff)({ segment, offset }, undefined, this.options.mergeTreeReferencesCanSlideToEndpoint) ?? segment;
|
|
463
474
|
// case happens when rebasing op, but concurrently entire string has been deleted
|
|
464
475
|
if (segoff.segment === undefined || segoff.offset === undefined) {
|
|
465
|
-
return DetachedReferencePosition;
|
|
476
|
+
return merge_tree_1.DetachedReferencePosition;
|
|
466
477
|
}
|
|
467
|
-
assert(offset !== undefined && 0 <= offset && offset < segment.cachedLength, 0x54f /* Invalid offset */);
|
|
478
|
+
(0, core_utils_1.assert)(offset !== undefined && 0 <= offset && offset < segment.cachedLength, 0x54f /* Invalid offset */);
|
|
468
479
|
return this.client.findReconnectionPosition(segoff.segment, localSeq) + segoff.offset;
|
|
469
480
|
}
|
|
470
481
|
computeRebasedPositions(localSeq) {
|
|
471
|
-
assert(this.client !== undefined, 0x550 /* Client should be defined when computing rebased position */);
|
|
482
|
+
(0, core_utils_1.assert)(this.client !== undefined, 0x550 /* Client should be defined when computing rebased position */);
|
|
472
483
|
const original = this.localSeqToSerializedInterval.get(localSeq);
|
|
473
|
-
assert(original !== undefined, 0x551 /* Failed to store pending serialized interval info for this localSeq. */);
|
|
484
|
+
(0, core_utils_1.assert)(original !== undefined, 0x551 /* Failed to store pending serialized interval info for this localSeq. */);
|
|
474
485
|
const rebased = { ...original };
|
|
475
486
|
const { start, end, sequenceNumber } = original;
|
|
476
487
|
if (start !== undefined) {
|
|
@@ -484,10 +495,10 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
484
495
|
/** @internal */
|
|
485
496
|
attachGraph(client, label) {
|
|
486
497
|
if (this.attached) {
|
|
487
|
-
throw new LoggingError("Only supports one Sequence attach");
|
|
498
|
+
throw new telemetry_utils_1.LoggingError("Only supports one Sequence attach");
|
|
488
499
|
}
|
|
489
500
|
if (client === undefined && this.requiresClient) {
|
|
490
|
-
throw new LoggingError("Client required for this collection");
|
|
501
|
+
throw new telemetry_utils_1.LoggingError("Client required for this collection");
|
|
491
502
|
}
|
|
492
503
|
// Instantiate the local interval collection based on the saved intervals
|
|
493
504
|
this.client = client;
|
|
@@ -533,11 +544,11 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
533
544
|
// is restored as single-endpoint changes re-use previous references.
|
|
534
545
|
let startRefType;
|
|
535
546
|
let endRefType;
|
|
536
|
-
if (previousInterval instanceof SequenceInterval) {
|
|
547
|
+
if (previousInterval instanceof intervals_1.SequenceInterval) {
|
|
537
548
|
startRefType = previousInterval.start.refType;
|
|
538
549
|
endRefType = previousInterval.end.refType;
|
|
539
|
-
previousInterval.start.refType = ReferenceType.Transient;
|
|
540
|
-
previousInterval.end.refType = ReferenceType.Transient;
|
|
550
|
+
previousInterval.start.refType = merge_tree_1.ReferenceType.Transient;
|
|
551
|
+
previousInterval.end.refType = merge_tree_1.ReferenceType.Transient;
|
|
541
552
|
this.emit("changeInterval", interval, previousInterval, local, op, slide);
|
|
542
553
|
previousInterval.start.refType = startRefType;
|
|
543
554
|
previousInterval.end.refType = endRefType;
|
|
@@ -551,14 +562,14 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
551
562
|
*/
|
|
552
563
|
getIntervalById(id) {
|
|
553
564
|
if (!this.localCollection) {
|
|
554
|
-
throw new LoggingError("attach must be called before accessing intervals");
|
|
565
|
+
throw new telemetry_utils_1.LoggingError("attach must be called before accessing intervals");
|
|
555
566
|
}
|
|
556
567
|
return this.localCollection.idIntervalIndex.getIntervalById(id);
|
|
557
568
|
}
|
|
558
569
|
assertStickinessEnabled(start, end) {
|
|
559
570
|
if (!(typeof start === "number" && typeof end === "number") &&
|
|
560
571
|
!this.options.intervalStickinessEnabled) {
|
|
561
|
-
throw new UsageError("attempted to set interval stickiness without enabling `intervalStickinessEnabled` feature flag");
|
|
572
|
+
throw new telemetry_utils_1.UsageError("attempted to set interval stickiness without enabling `intervalStickinessEnabled` feature flag");
|
|
562
573
|
}
|
|
563
574
|
}
|
|
564
575
|
add(start, end, intervalType, props) {
|
|
@@ -568,26 +579,26 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
568
579
|
let properties;
|
|
569
580
|
if (isSequencePlace(start)) {
|
|
570
581
|
intStart = start;
|
|
571
|
-
assert(end !== undefined, 0x7c0 /* end must be defined */);
|
|
582
|
+
(0, core_utils_1.assert)(end !== undefined, 0x7c0 /* end must be defined */);
|
|
572
583
|
intEnd = end;
|
|
573
|
-
assert(intervalType !== undefined, 0x7c1 /* intervalType must be defined */);
|
|
584
|
+
(0, core_utils_1.assert)(intervalType !== undefined, 0x7c1 /* intervalType must be defined */);
|
|
574
585
|
type = intervalType;
|
|
575
586
|
properties = props;
|
|
576
587
|
}
|
|
577
588
|
else {
|
|
578
589
|
intStart = start.start;
|
|
579
590
|
intEnd = start.end;
|
|
580
|
-
type = IntervalType.SlideOnRemove;
|
|
591
|
+
type = intervals_1.IntervalType.SlideOnRemove;
|
|
581
592
|
properties = start.props;
|
|
582
593
|
}
|
|
583
594
|
if (!this.localCollection) {
|
|
584
|
-
throw new LoggingError("attach must be called prior to adding intervals");
|
|
595
|
+
throw new telemetry_utils_1.LoggingError("attach must be called prior to adding intervals");
|
|
585
596
|
}
|
|
586
|
-
if (type & IntervalType.Transient) {
|
|
587
|
-
throw new LoggingError("Can not add transient intervals");
|
|
597
|
+
if (type & intervals_1.IntervalType.Transient) {
|
|
598
|
+
throw new telemetry_utils_1.LoggingError("Can not add transient intervals");
|
|
588
599
|
}
|
|
589
600
|
const { startSide, endSide, startPos, endPos } = endpointPosAndSide(intStart, intEnd);
|
|
590
|
-
assert(startPos !== undefined &&
|
|
601
|
+
(0, core_utils_1.assert)(startPos !== undefined &&
|
|
591
602
|
endPos !== undefined &&
|
|
592
603
|
startSide !== undefined &&
|
|
593
604
|
endSide !== undefined, 0x793 /* start and end cannot be undefined because they were not passed in as undefined */);
|
|
@@ -595,7 +606,7 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
595
606
|
this.assertStickinessEnabled(intStart, intEnd);
|
|
596
607
|
const interval = this.localCollection.addInterval(toSequencePlace(startPos, startSide), toSequencePlace(endPos, endSide), type, properties);
|
|
597
608
|
if (interval) {
|
|
598
|
-
if (!this.isCollaborating && interval instanceof SequenceInterval) {
|
|
609
|
+
if (!this.isCollaborating && interval instanceof intervals_1.SequenceInterval) {
|
|
599
610
|
setSlideOnRemove(interval.start);
|
|
600
611
|
setSlideOnRemove(interval.end);
|
|
601
612
|
}
|
|
@@ -619,7 +630,7 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
619
630
|
}
|
|
620
631
|
deleteExistingInterval(interval, local, op) {
|
|
621
632
|
if (!this.localCollection) {
|
|
622
|
-
throw new LoggingError("Attach must be called before accessing intervals");
|
|
633
|
+
throw new telemetry_utils_1.LoggingError("Attach must be called before accessing intervals");
|
|
623
634
|
}
|
|
624
635
|
// The given interval is known to exist in the collection.
|
|
625
636
|
this.localCollection.removeExistingInterval(interval);
|
|
@@ -643,7 +654,7 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
643
654
|
*/
|
|
644
655
|
removeIntervalById(id) {
|
|
645
656
|
if (!this.localCollection) {
|
|
646
|
-
throw new LoggingError("Attach must be called before accessing intervals");
|
|
657
|
+
throw new telemetry_utils_1.LoggingError("Attach must be called before accessing intervals");
|
|
647
658
|
}
|
|
648
659
|
const interval = this.localCollection.idIntervalIndex.getIntervalById(id);
|
|
649
660
|
if (interval) {
|
|
@@ -653,58 +664,54 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
653
664
|
}
|
|
654
665
|
/**
|
|
655
666
|
* {@inheritdoc IIntervalCollection.changeProperties}
|
|
667
|
+
* @deprecated - call change with the id and an object containing the new props values
|
|
656
668
|
*/
|
|
657
669
|
changeProperties(id, props) {
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
// once it has been inserted into the collection.
|
|
669
|
-
if (props[reservedRangeLabelsKey] !== undefined) {
|
|
670
|
-
throw new LoggingError("The label property should not be modified once inserted to the collection");
|
|
670
|
+
this.change(id, { props });
|
|
671
|
+
}
|
|
672
|
+
change(arg1, arg2, arg3) {
|
|
673
|
+
const id = arg1;
|
|
674
|
+
let start;
|
|
675
|
+
let end;
|
|
676
|
+
let props;
|
|
677
|
+
if (isSequencePlace(arg2)) {
|
|
678
|
+
start = arg2;
|
|
679
|
+
end = arg3;
|
|
671
680
|
}
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
// Emit a change op that will only change properties. Add the ID to
|
|
677
|
-
// the property bag provided by the caller.
|
|
678
|
-
serializedInterval.start = undefined;
|
|
679
|
-
serializedInterval.end = undefined;
|
|
680
|
-
serializedInterval.properties = props;
|
|
681
|
-
serializedInterval.properties[reservedIntervalIdKey] = interval.getIntervalId();
|
|
682
|
-
const localSeq = this.getNextLocalSeq();
|
|
683
|
-
this.localSeqToSerializedInterval.set(localSeq, serializedInterval);
|
|
684
|
-
this.emitter.emit("change", undefined, serializedInterval, { localSeq });
|
|
685
|
-
this.emit("propertyChanged", interval, deltaProps, true, undefined);
|
|
681
|
+
else {
|
|
682
|
+
start = arg2.start;
|
|
683
|
+
end = arg2.end;
|
|
684
|
+
props = arg2.props;
|
|
686
685
|
}
|
|
687
|
-
}
|
|
688
|
-
/**
|
|
689
|
-
* {@inheritdoc IIntervalCollection.change}
|
|
690
|
-
*/
|
|
691
|
-
change(id, start, end) {
|
|
692
686
|
if (!this.localCollection) {
|
|
693
|
-
throw new LoggingError("Attach must be called before accessing intervals");
|
|
687
|
+
throw new telemetry_utils_1.LoggingError("Attach must be called before accessing intervals");
|
|
694
688
|
}
|
|
695
689
|
// Force id to be a string.
|
|
696
690
|
if (typeof id !== "string") {
|
|
697
|
-
throw new
|
|
691
|
+
throw new telemetry_utils_1.UsageError("Change API requires an ID that is a string");
|
|
692
|
+
}
|
|
693
|
+
// Ensure that both start and end are defined or both are undefined.
|
|
694
|
+
if ((start === undefined) !== (end === undefined)) {
|
|
695
|
+
throw new telemetry_utils_1.UsageError("Change API requires both start and end to be defined or undefined");
|
|
696
|
+
}
|
|
697
|
+
// prevent the overwriting of an interval label, it should remain unchanged
|
|
698
|
+
// once it has been inserted into the collection.
|
|
699
|
+
if (props?.[merge_tree_1.reservedRangeLabelsKey] !== undefined) {
|
|
700
|
+
throw new telemetry_utils_1.UsageError("The label property should not be modified once inserted to the collection");
|
|
698
701
|
}
|
|
699
702
|
const interval = this.getIntervalById(id);
|
|
700
703
|
if (interval) {
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
+
let deltaProps;
|
|
705
|
+
let newInterval;
|
|
706
|
+
if (props !== undefined) {
|
|
707
|
+
deltaProps = interval.addProperties(props, true, this.isCollaborating ? merge_tree_1.UnassignedSequenceNumber : merge_tree_1.UniversalSequenceNumber);
|
|
704
708
|
}
|
|
705
|
-
if (
|
|
706
|
-
|
|
707
|
-
|
|
709
|
+
if (start !== undefined && end !== undefined) {
|
|
710
|
+
newInterval = this.localCollection.changeInterval(interval, start, end);
|
|
711
|
+
if (!this.isCollaborating && newInterval instanceof intervals_1.SequenceInterval) {
|
|
712
|
+
setSlideOnRemove(newInterval.start);
|
|
713
|
+
setSlideOnRemove(newInterval.end);
|
|
714
|
+
}
|
|
708
715
|
}
|
|
709
716
|
const serializedInterval = interval.serialize();
|
|
710
717
|
const { startPos, startSide, endPos, endSide } = endpointPosAndSide(start, end);
|
|
@@ -714,15 +721,21 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
714
721
|
serializedInterval.startSide = startSide;
|
|
715
722
|
serializedInterval.endSide = endSide;
|
|
716
723
|
serializedInterval.stickiness = stickiness;
|
|
717
|
-
// Emit a property bag containing
|
|
724
|
+
// Emit a property bag containing the ID and the other (if any) properties changed
|
|
718
725
|
serializedInterval.properties = {
|
|
719
726
|
[reservedIntervalIdKey]: interval.getIntervalId(),
|
|
727
|
+
...props,
|
|
720
728
|
};
|
|
721
729
|
const localSeq = this.getNextLocalSeq();
|
|
722
730
|
this.localSeqToSerializedInterval.set(localSeq, serializedInterval);
|
|
723
731
|
this.emitter.emit("change", undefined, serializedInterval, { localSeq });
|
|
724
|
-
|
|
725
|
-
|
|
732
|
+
if (deltaProps !== undefined) {
|
|
733
|
+
this.emit("propertyChanged", interval, deltaProps, true, undefined);
|
|
734
|
+
}
|
|
735
|
+
if (newInterval) {
|
|
736
|
+
this.addPendingChange(id, serializedInterval);
|
|
737
|
+
this.emitChange(newInterval, interval, true, false);
|
|
738
|
+
}
|
|
726
739
|
return newInterval;
|
|
727
740
|
}
|
|
728
741
|
// No interval to change
|
|
@@ -769,7 +782,7 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
769
782
|
}
|
|
770
783
|
if (pendingChange?.start !== serializedInterval.start ||
|
|
771
784
|
pendingChange?.end !== serializedInterval.end) {
|
|
772
|
-
throw new LoggingError("Mismatch in pending changes");
|
|
785
|
+
throw new telemetry_utils_1.LoggingError("Mismatch in pending changes");
|
|
773
786
|
}
|
|
774
787
|
}
|
|
775
788
|
}
|
|
@@ -784,10 +797,10 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
784
797
|
/** @internal */
|
|
785
798
|
ackChange(serializedInterval, local, op, localOpMetadata) {
|
|
786
799
|
if (!this.localCollection) {
|
|
787
|
-
throw new LoggingError("Attach must be called before accessing intervals");
|
|
800
|
+
throw new telemetry_utils_1.LoggingError("Attach must be called before accessing intervals");
|
|
788
801
|
}
|
|
789
802
|
if (local) {
|
|
790
|
-
assert(localOpMetadata !== undefined, 0x552 /* op metadata should be defined for local op */);
|
|
803
|
+
(0, core_utils_1.assert)(localOpMetadata !== undefined, 0x552 /* op metadata should be defined for local op */);
|
|
791
804
|
this.localSeqToSerializedInterval.delete(localOpMetadata?.localSeq);
|
|
792
805
|
// This is an ack from the server. Remove the pending change.
|
|
793
806
|
this.removePendingChange(serializedInterval);
|
|
@@ -796,7 +809,7 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
796
809
|
// This API cannot change the ID, and writing to the ID property will result in an exception. So we
|
|
797
810
|
// strip it out of the properties here.
|
|
798
811
|
const { [reservedIntervalIdKey]: id, ...newProps } = serializedInterval.properties ?? {};
|
|
799
|
-
assert(id !== undefined, 0x3fe /* id must exist on the interval */);
|
|
812
|
+
(0, core_utils_1.assert)(id !== undefined, 0x3fe /* id must exist on the interval */);
|
|
800
813
|
const interval = this.getIntervalById(id);
|
|
801
814
|
if (!interval) {
|
|
802
815
|
// The interval has been removed locally; no-op.
|
|
@@ -805,7 +818,7 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
805
818
|
if (local) {
|
|
806
819
|
// Let the propertyManager prune its pending change-properties set.
|
|
807
820
|
interval.propertyManager?.ackPendingProperties({
|
|
808
|
-
type: MergeTreeDeltaType.ANNOTATE,
|
|
821
|
+
type: merge_tree_1.MergeTreeDeltaType.ANNOTATE,
|
|
809
822
|
props: serializedInterval.properties ?? {},
|
|
810
823
|
});
|
|
811
824
|
this.ackInterval(interval, op);
|
|
@@ -870,7 +883,7 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
870
883
|
return serializedInterval;
|
|
871
884
|
}
|
|
872
885
|
if (!this.attached) {
|
|
873
|
-
throw new LoggingError("attachSequence must be called");
|
|
886
|
+
throw new telemetry_utils_1.LoggingError("attachSequence must be called");
|
|
874
887
|
}
|
|
875
888
|
const { intervalType, properties, stickiness, startSide, endSide } = serializedInterval;
|
|
876
889
|
const { start: startRebased, end: endRebased } = this.localSeqToRebasedInterval.get(localSeq) ?? this.computeRebasedPositions(localSeq);
|
|
@@ -893,8 +906,8 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
893
906
|
this.addPendingChange(intervalId, rebased);
|
|
894
907
|
}
|
|
895
908
|
// if the interval slid off the string, rebase the op to be a noop and delete the interval.
|
|
896
|
-
if (startRebased === DetachedReferencePosition ||
|
|
897
|
-
endRebased === DetachedReferencePosition) {
|
|
909
|
+
if (startRebased === merge_tree_1.DetachedReferencePosition ||
|
|
910
|
+
endRebased === merge_tree_1.DetachedReferencePosition) {
|
|
898
911
|
if (localInterval) {
|
|
899
912
|
this.localCollection?.removeExistingInterval(localInterval);
|
|
900
913
|
}
|
|
@@ -902,7 +915,7 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
902
915
|
}
|
|
903
916
|
if (localInterval !== undefined) {
|
|
904
917
|
// we know we must be using `SequenceInterval` because `this.client` exists
|
|
905
|
-
assert(localInterval instanceof SequenceInterval, 0x3a0 /* localInterval must be `SequenceInterval` when used with client */);
|
|
918
|
+
(0, core_utils_1.assert)(localInterval instanceof intervals_1.SequenceInterval, 0x3a0 /* localInterval must be `SequenceInterval` when used with client */);
|
|
906
919
|
// The rebased op may place this interval's endpoints on different segments. Calling `changeInterval` here
|
|
907
920
|
// updates the local client's state to be consistent with the emitted op.
|
|
908
921
|
this.localCollection?.changeInterval(localInterval, toOptionalSequencePlace(startRebased, startSide), toOptionalSequencePlace(endRebased, endSide), undefined, localSeq);
|
|
@@ -911,13 +924,13 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
911
924
|
}
|
|
912
925
|
getSlideToSegment(lref) {
|
|
913
926
|
if (!this.client) {
|
|
914
|
-
throw new LoggingError("client does not exist");
|
|
927
|
+
throw new telemetry_utils_1.LoggingError("client does not exist");
|
|
915
928
|
}
|
|
916
929
|
const segoff = { segment: lref.getSegment(), offset: lref.getOffset() };
|
|
917
930
|
if (segoff.segment?.localRefs?.has(lref) !== true) {
|
|
918
931
|
return undefined;
|
|
919
932
|
}
|
|
920
|
-
const newSegoff = getSlideToSegoff(segoff, undefined, this.options.mergeTreeReferencesCanSlideToEndpoint);
|
|
933
|
+
const newSegoff = (0, merge_tree_1.getSlideToSegoff)(segoff, undefined, this.options.mergeTreeReferencesCanSlideToEndpoint);
|
|
921
934
|
const value = segoff.segment === newSegoff.segment && segoff.offset === newSegoff.offset
|
|
922
935
|
? undefined
|
|
923
936
|
: newSegoff;
|
|
@@ -925,11 +938,11 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
925
938
|
}
|
|
926
939
|
ackInterval(interval, op) {
|
|
927
940
|
// Only SequenceIntervals need potential sliding
|
|
928
|
-
if (!(interval instanceof SequenceInterval)) {
|
|
941
|
+
if (!(interval instanceof intervals_1.SequenceInterval)) {
|
|
929
942
|
return;
|
|
930
943
|
}
|
|
931
|
-
if (!refTypeIncludesFlag(interval.start, ReferenceType.StayOnRemove) &&
|
|
932
|
-
!refTypeIncludesFlag(interval.end, ReferenceType.StayOnRemove)) {
|
|
944
|
+
if (!(0, merge_tree_1.refTypeIncludesFlag)(interval.start, merge_tree_1.ReferenceType.StayOnRemove) &&
|
|
945
|
+
!(0, merge_tree_1.refTypeIncludesFlag)(interval.end, merge_tree_1.ReferenceType.StayOnRemove)) {
|
|
933
946
|
return;
|
|
934
947
|
}
|
|
935
948
|
const newStart = this.getSlideToSegment(interval.start);
|
|
@@ -947,7 +960,7 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
947
960
|
const needsEndUpdate = newEnd !== undefined && !hasPendingEndChange;
|
|
948
961
|
if (needsStartUpdate || needsEndUpdate) {
|
|
949
962
|
if (!this.localCollection) {
|
|
950
|
-
throw new LoggingError("Attach must be called before accessing intervals");
|
|
963
|
+
throw new telemetry_utils_1.LoggingError("Attach must be called before accessing intervals");
|
|
951
964
|
}
|
|
952
965
|
// `interval`'s endpoints will get modified in-place, so clone it prior to doing so for event emission.
|
|
953
966
|
const oldInterval = interval.clone();
|
|
@@ -956,32 +969,32 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
956
969
|
// This ensures that the correct listeners are added to the LocalReferencePosition.
|
|
957
970
|
this.localCollection.removeExistingInterval(interval);
|
|
958
971
|
if (!this.client) {
|
|
959
|
-
throw new LoggingError("client does not exist");
|
|
972
|
+
throw new telemetry_utils_1.LoggingError("client does not exist");
|
|
960
973
|
}
|
|
961
974
|
if (needsStartUpdate) {
|
|
962
975
|
const props = interval.start.properties;
|
|
963
|
-
interval.start = createPositionReferenceFromSegoff(this.client, newStart, interval.start.refType, op, undefined, undefined, startReferenceSlidingPreference(interval.stickiness), startReferenceSlidingPreference(interval.stickiness) ===
|
|
964
|
-
SlidingPreference.BACKWARD);
|
|
976
|
+
interval.start = (0, intervals_1.createPositionReferenceFromSegoff)(this.client, newStart, interval.start.refType, op, undefined, undefined, (0, intervals_1.startReferenceSlidingPreference)(interval.stickiness), (0, intervals_1.startReferenceSlidingPreference)(interval.stickiness) ===
|
|
977
|
+
merge_tree_1.SlidingPreference.BACKWARD);
|
|
965
978
|
if (props) {
|
|
966
979
|
interval.start.addProperties(props);
|
|
967
980
|
}
|
|
968
981
|
const oldSeg = oldInterval.start.getSegment();
|
|
969
982
|
// remove and rebuild start interval as transient for event
|
|
970
983
|
this.client.removeLocalReferencePosition(oldInterval.start);
|
|
971
|
-
oldInterval.start.refType = ReferenceType.Transient;
|
|
984
|
+
oldInterval.start.refType = merge_tree_1.ReferenceType.Transient;
|
|
972
985
|
oldSeg?.localRefs?.addLocalRef(oldInterval.start, oldInterval.start.getOffset());
|
|
973
986
|
}
|
|
974
987
|
if (needsEndUpdate) {
|
|
975
988
|
const props = interval.end.properties;
|
|
976
|
-
interval.end = createPositionReferenceFromSegoff(this.client, newEnd, interval.end.refType, op, undefined, undefined, endReferenceSlidingPreference(interval.stickiness), endReferenceSlidingPreference(interval.stickiness) ===
|
|
977
|
-
SlidingPreference.FORWARD);
|
|
989
|
+
interval.end = (0, intervals_1.createPositionReferenceFromSegoff)(this.client, newEnd, interval.end.refType, op, undefined, undefined, (0, intervals_1.endReferenceSlidingPreference)(interval.stickiness), (0, intervals_1.endReferenceSlidingPreference)(interval.stickiness) ===
|
|
990
|
+
merge_tree_1.SlidingPreference.FORWARD);
|
|
978
991
|
if (props) {
|
|
979
992
|
interval.end.addProperties(props);
|
|
980
993
|
}
|
|
981
994
|
// remove and rebuild end interval as transient for event
|
|
982
995
|
const oldSeg = oldInterval.end.getSegment();
|
|
983
996
|
this.client.removeLocalReferencePosition(oldInterval.end);
|
|
984
|
-
oldInterval.end.refType = ReferenceType.Transient;
|
|
997
|
+
oldInterval.end.refType = merge_tree_1.ReferenceType.Transient;
|
|
985
998
|
oldSeg?.localRefs?.addLocalRef(oldInterval.end, oldInterval.end.getOffset());
|
|
986
999
|
}
|
|
987
1000
|
this.localCollection.add(interval);
|
|
@@ -991,7 +1004,7 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
991
1004
|
/** @internal */
|
|
992
1005
|
ackAdd(serializedInterval, local, op, localOpMetadata) {
|
|
993
1006
|
if (local) {
|
|
994
|
-
assert(localOpMetadata !== undefined, 0x553 /* op metadata should be defined for local op */);
|
|
1007
|
+
(0, core_utils_1.assert)(localOpMetadata !== undefined, 0x553 /* op metadata should be defined for local op */);
|
|
995
1008
|
this.localSeqToSerializedInterval.delete(localOpMetadata.localSeq);
|
|
996
1009
|
const id = serializedInterval.properties?.[reservedIntervalIdKey];
|
|
997
1010
|
const localInterval = this.getIntervalById(id);
|
|
@@ -1001,7 +1014,7 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
1001
1014
|
return;
|
|
1002
1015
|
}
|
|
1003
1016
|
if (!this.localCollection) {
|
|
1004
|
-
throw new LoggingError("attachSequence must be called");
|
|
1017
|
+
throw new telemetry_utils_1.LoggingError("attachSequence must be called");
|
|
1005
1018
|
}
|
|
1006
1019
|
this.localCollection.ensureSerializedId(serializedInterval);
|
|
1007
1020
|
const interval = this.localCollection.addInterval(toSequencePlace(serializedInterval.start, serializedInterval.startSide ?? Side.Before), toSequencePlace(serializedInterval.end, serializedInterval.endSide ?? Side.Before), serializedInterval.intervalType, serializedInterval.properties, op);
|
|
@@ -1022,7 +1035,7 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
1022
1035
|
return;
|
|
1023
1036
|
}
|
|
1024
1037
|
if (!this.localCollection) {
|
|
1025
|
-
throw new LoggingError("attach must be called prior to deleting intervals");
|
|
1038
|
+
throw new telemetry_utils_1.LoggingError("attach must be called prior to deleting intervals");
|
|
1026
1039
|
}
|
|
1027
1040
|
const id = this.localCollection.ensureSerializedId(serializedInterval);
|
|
1028
1041
|
const interval = this.localCollection.idIntervalIndex.getIntervalById(id);
|
|
@@ -1035,7 +1048,7 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
1035
1048
|
*/
|
|
1036
1049
|
serializeInternal() {
|
|
1037
1050
|
if (!this.localCollection) {
|
|
1038
|
-
throw new LoggingError("attachSequence must be called");
|
|
1051
|
+
throw new telemetry_utils_1.LoggingError("attachSequence must be called");
|
|
1039
1052
|
}
|
|
1040
1053
|
return this.localCollection.serialize();
|
|
1041
1054
|
}
|
|
@@ -1088,7 +1101,7 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
1088
1101
|
*/
|
|
1089
1102
|
findOverlappingIntervals(startPosition, endPosition) {
|
|
1090
1103
|
if (!this.localCollection) {
|
|
1091
|
-
throw new LoggingError("attachSequence must be called");
|
|
1104
|
+
throw new telemetry_utils_1.LoggingError("attachSequence must be called");
|
|
1092
1105
|
}
|
|
1093
1106
|
return this.localCollection.overlappingIntervalsIndex.findOverlappingIntervals(startPosition, endPosition);
|
|
1094
1107
|
}
|
|
@@ -1097,7 +1110,7 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
1097
1110
|
*/
|
|
1098
1111
|
map(fn) {
|
|
1099
1112
|
if (!this.localCollection) {
|
|
1100
|
-
throw new LoggingError("attachSequence must be called");
|
|
1113
|
+
throw new telemetry_utils_1.LoggingError("attachSequence must be called");
|
|
1101
1114
|
}
|
|
1102
1115
|
for (const interval of this.localCollection.idIntervalIndex) {
|
|
1103
1116
|
fn(interval);
|
|
@@ -1108,7 +1121,7 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
1108
1121
|
*/
|
|
1109
1122
|
previousInterval(pos) {
|
|
1110
1123
|
if (!this.localCollection) {
|
|
1111
|
-
throw new LoggingError("attachSequence must be called");
|
|
1124
|
+
throw new telemetry_utils_1.LoggingError("attachSequence must be called");
|
|
1112
1125
|
}
|
|
1113
1126
|
return this.localCollection.endIntervalIndex.previousInterval(pos);
|
|
1114
1127
|
}
|
|
@@ -1117,15 +1130,16 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
1117
1130
|
*/
|
|
1118
1131
|
nextInterval(pos) {
|
|
1119
1132
|
if (!this.localCollection) {
|
|
1120
|
-
throw new LoggingError("attachSequence must be called");
|
|
1133
|
+
throw new telemetry_utils_1.LoggingError("attachSequence must be called");
|
|
1121
1134
|
}
|
|
1122
1135
|
return this.localCollection.endIntervalIndex.nextInterval(pos);
|
|
1123
1136
|
}
|
|
1124
1137
|
}
|
|
1138
|
+
exports.IntervalCollection = IntervalCollection;
|
|
1125
1139
|
function setSlideOnRemove(lref) {
|
|
1126
1140
|
let refType = lref.refType;
|
|
1127
|
-
refType = refType & ~ReferenceType.StayOnRemove;
|
|
1128
|
-
refType = refType | ReferenceType.SlideOnRemove;
|
|
1141
|
+
refType = refType & ~merge_tree_1.ReferenceType.StayOnRemove;
|
|
1142
|
+
refType = refType | merge_tree_1.ReferenceType.SlideOnRemove;
|
|
1129
1143
|
lref.refType = refType;
|
|
1130
1144
|
}
|
|
1131
1145
|
/**
|
|
@@ -1135,10 +1149,11 @@ function setSlideOnRemove(lref) {
|
|
|
1135
1149
|
* endpoint is a part of.
|
|
1136
1150
|
* @internal
|
|
1137
1151
|
*/
|
|
1138
|
-
|
|
1139
|
-
const { interval, [reservedRangeLabelsKey]: collectionNameArray } = potentialEndpoint.properties ?? {};
|
|
1152
|
+
function intervalLocatorFromEndpoint(potentialEndpoint) {
|
|
1153
|
+
const { interval, [merge_tree_1.reservedRangeLabelsKey]: collectionNameArray } = potentialEndpoint.properties ?? {};
|
|
1140
1154
|
return interval && collectionNameArray?.length === 1
|
|
1141
1155
|
? { label: collectionNameArray[0], interval }
|
|
1142
1156
|
: undefined;
|
|
1143
1157
|
}
|
|
1158
|
+
exports.intervalLocatorFromEndpoint = intervalLocatorFromEndpoint;
|
|
1144
1159
|
//# sourceMappingURL=intervalCollection.js.map
|