@fluidframework/sequence 1.3.0 → 2.0.0-dev.1.4.5.105745
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/.mocharc.js +12 -0
- package/README.md +19 -18
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/intervalCollection.d.ts +51 -18
- package/dist/intervalCollection.d.ts.map +1 -1
- package/dist/intervalCollection.js +117 -73
- package/dist/intervalCollection.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/sequence.d.ts +13 -22
- package/dist/sequence.d.ts.map +1 -1
- package/dist/sequence.js +11 -32
- package/dist/sequence.js.map +1 -1
- package/dist/sequenceDeltaEvent.d.ts +0 -6
- package/dist/sequenceDeltaEvent.d.ts.map +1 -1
- package/dist/sequenceDeltaEvent.js +0 -1
- package/dist/sequenceDeltaEvent.js.map +1 -1
- package/dist/sharedIntervalCollection.d.ts +5 -5
- package/dist/sharedIntervalCollection.js +5 -5
- package/dist/sharedIntervalCollection.js.map +1 -1
- package/dist/sharedString.d.ts +30 -1
- package/dist/sharedString.d.ts.map +1 -1
- package/dist/sharedString.js +40 -5
- package/dist/sharedString.js.map +1 -1
- package/dist/sparsematrix.d.ts +28 -15
- package/dist/sparsematrix.d.ts.map +1 -1
- package/dist/sparsematrix.js +24 -13
- package/dist/sparsematrix.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/lib/intervalCollection.d.ts +51 -18
- package/lib/intervalCollection.d.ts.map +1 -1
- package/lib/intervalCollection.js +116 -73
- package/lib/intervalCollection.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/sequence.d.ts +13 -22
- package/lib/sequence.d.ts.map +1 -1
- package/lib/sequence.js +12 -33
- package/lib/sequence.js.map +1 -1
- package/lib/sequenceDeltaEvent.d.ts +0 -6
- package/lib/sequenceDeltaEvent.d.ts.map +1 -1
- package/lib/sequenceDeltaEvent.js +0 -1
- package/lib/sequenceDeltaEvent.js.map +1 -1
- package/lib/sharedIntervalCollection.d.ts +5 -5
- package/lib/sharedIntervalCollection.js +5 -5
- package/lib/sharedIntervalCollection.js.map +1 -1
- package/lib/sharedString.d.ts +30 -1
- package/lib/sharedString.d.ts.map +1 -1
- package/lib/sharedString.js +38 -4
- package/lib/sharedString.js.map +1 -1
- package/lib/sparsematrix.d.ts +28 -15
- package/lib/sparsematrix.d.ts.map +1 -1
- package/lib/sparsematrix.js +24 -13
- package/lib/sparsematrix.js.map +1 -1
- package/package.json +70 -25
- package/src/index.ts +3 -1
- package/src/intervalCollection.ts +209 -97
- package/src/packageVersion.ts +1 -1
- package/src/sequence.ts +12 -41
- package/src/sequenceDeltaEvent.ts +0 -7
- package/src/sharedIntervalCollection.ts +5 -5
- package/src/sharedString.ts +44 -6
- package/src/sparsematrix.ts +48 -35
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { TypedEventEmitter } from "@fluidframework/common-utils";
|
|
6
6
|
import { IEvent } from "@fluidframework/common-definitions";
|
|
7
|
-
import { Client, ICombiningOp, IInterval, IntervalConflictResolver,
|
|
7
|
+
import { Client, ICombiningOp, IInterval, IntervalConflictResolver, PropertiesManager, PropertySet, LocalReferencePosition } from "@fluidframework/merge-tree";
|
|
8
8
|
import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
|
|
9
9
|
import { IValueFactory, IValueOpEmitter, IValueOperation, IValueType } from "./defaultMapInterfaces";
|
|
10
10
|
export declare enum IntervalType {
|
|
@@ -18,8 +18,8 @@ export declare enum IntervalType {
|
|
|
18
18
|
*/
|
|
19
19
|
SlideOnRemove = 2,
|
|
20
20
|
/**
|
|
21
|
-
* @internal
|
|
22
21
|
* A temporary interval, used internally
|
|
22
|
+
* @internal
|
|
23
23
|
*/
|
|
24
24
|
Transient = 4
|
|
25
25
|
}
|
|
@@ -54,7 +54,18 @@ export interface ISerializableInterval extends IInterval {
|
|
|
54
54
|
}
|
|
55
55
|
export interface IIntervalHelpers<TInterval extends ISerializableInterval> {
|
|
56
56
|
compareEnds(a: TInterval, b: TInterval): number;
|
|
57
|
-
|
|
57
|
+
/**
|
|
58
|
+
*
|
|
59
|
+
* @param label - label of the interval collection this interval is being added to. This parameter is
|
|
60
|
+
* irrelevant for transient intervals.
|
|
61
|
+
* @param start - numerical start position of the interval
|
|
62
|
+
* @param end - numberical end position of the interval
|
|
63
|
+
* @param client - client creating the interval
|
|
64
|
+
* @param intervalType - Type of interval to create. Default is SlideOnRemove
|
|
65
|
+
* @param op - If this create came from a remote client, op that created it. Default is undefined (i.e. local)
|
|
66
|
+
* @param fromSnapshot - If this create came from loading a snapshot. Default is false.
|
|
67
|
+
*/
|
|
68
|
+
create(label: string, start: number, end: number, client: Client, intervalType?: IntervalType, op?: ISequencedDocumentMessage, fromSnapshot?: boolean): TInterval;
|
|
58
69
|
}
|
|
59
70
|
export declare class Interval implements ISerializableInterval {
|
|
60
71
|
start: number;
|
|
@@ -79,21 +90,22 @@ export declare class Interval implements ISerializableInterval {
|
|
|
79
90
|
private initializeProperties;
|
|
80
91
|
}
|
|
81
92
|
export declare class SequenceInterval implements ISerializableInterval {
|
|
82
|
-
|
|
83
|
-
|
|
93
|
+
private readonly client;
|
|
94
|
+
start: LocalReferencePosition;
|
|
95
|
+
end: LocalReferencePosition;
|
|
84
96
|
intervalType: IntervalType;
|
|
85
97
|
properties: PropertySet;
|
|
86
98
|
propertyManager: PropertiesManager;
|
|
87
|
-
constructor(start:
|
|
99
|
+
constructor(client: Client, start: LocalReferencePosition, end: LocalReferencePosition, intervalType: IntervalType, props?: PropertySet);
|
|
88
100
|
private callbacks?;
|
|
89
101
|
/**
|
|
90
|
-
* @internal
|
|
91
102
|
* Subscribes to position change events on this interval if there are no current listeners.
|
|
103
|
+
* @internal
|
|
92
104
|
*/
|
|
93
105
|
addPositionChangeListeners(beforePositionChange: () => void, afterPositionChange: () => void): void;
|
|
94
106
|
/**
|
|
95
|
-
* @internal
|
|
96
107
|
* Removes the currently subscribed position change listeners.
|
|
108
|
+
* @internal
|
|
97
109
|
*/
|
|
98
110
|
removePositionChangeListeners(): void;
|
|
99
111
|
serialize(client: Client): ISerializedInterval;
|
|
@@ -106,7 +118,7 @@ export declare class SequenceInterval implements ISerializableInterval {
|
|
|
106
118
|
union(b: SequenceInterval): SequenceInterval;
|
|
107
119
|
addProperties(newProps: PropertySet, collab?: boolean, seq?: number, op?: ICombiningOp): PropertySet | undefined;
|
|
108
120
|
overlapsPos(bstart: number, bend: number): boolean;
|
|
109
|
-
modify(label: string, start: number, end: number, op?: ISequencedDocumentMessage): SequenceInterval;
|
|
121
|
+
modify(label: string, start: number, end: number, op?: ISequencedDocumentMessage, localSeq?: number): SequenceInterval;
|
|
110
122
|
private initializeProperties;
|
|
111
123
|
}
|
|
112
124
|
export declare function defaultIntervalConflictResolver(a: Interval, b: Interval): Interval;
|
|
@@ -147,10 +159,11 @@ export declare class LocalIntervalCollection<TInterval extends ISerializableInte
|
|
|
147
159
|
removeExistingInterval(interval: TInterval): void;
|
|
148
160
|
createInterval(start: number, end: number, intervalType: IntervalType, op?: ISequencedDocumentMessage): TInterval;
|
|
149
161
|
addInterval(start: number, end: number, intervalType: IntervalType, props?: PropertySet, op?: ISequencedDocumentMessage): TInterval;
|
|
162
|
+
private linkEndpointsToInterval;
|
|
150
163
|
private addIntervalToIndex;
|
|
151
164
|
add(interval: TInterval): void;
|
|
152
165
|
getIntervalById(id: string): TInterval;
|
|
153
|
-
changeInterval(interval: TInterval, start: number, end: number, op?: ISequencedDocumentMessage): TInterval;
|
|
166
|
+
changeInterval(interval: TInterval, start: number, end: number, op?: ISequencedDocumentMessage, localSeq?: number): TInterval;
|
|
154
167
|
serialize(): ISerializedIntervalCollectionV2;
|
|
155
168
|
private addIntervalListeners;
|
|
156
169
|
private removeIntervalListeners;
|
|
@@ -233,23 +246,23 @@ export declare class IntervalCollection<TInterval extends ISerializableInterval>
|
|
|
233
246
|
private removePendingChangeHelper;
|
|
234
247
|
private hasPendingChangeStart;
|
|
235
248
|
private hasPendingChangeEnd;
|
|
236
|
-
/** @deprecated - use ackChange */
|
|
237
|
-
changeInterval(serializedInterval: ISerializedInterval, local: boolean, op: ISequencedDocumentMessage): void;
|
|
238
249
|
/** @internal */
|
|
239
250
|
ackChange(serializedInterval: ISerializedInterval, local: boolean, op: ISequencedDocumentMessage): void;
|
|
240
251
|
addConflictResolver(conflictResolver: IntervalConflictResolver<TInterval>): void;
|
|
241
252
|
attachDeserializer(onDeserialize: DeserializeCallback): void;
|
|
242
|
-
/**
|
|
243
|
-
|
|
253
|
+
/**
|
|
254
|
+
* Returns new interval after rebasing. If undefined, the interval was
|
|
255
|
+
* deleted as a result of rebasing. This can occur if the interval applies
|
|
256
|
+
* to a range that no longer exists, and the interval was unable to slide.
|
|
257
|
+
*
|
|
258
|
+
* @internal
|
|
259
|
+
*/
|
|
260
|
+
rebaseLocalInterval(opName: string, serializedInterval: ISerializedInterval, localSeq: number): ISerializedInterval | undefined;
|
|
244
261
|
private getSlideToSegment;
|
|
245
262
|
private setSlideOnRemove;
|
|
246
263
|
private ackInterval;
|
|
247
|
-
/** @deprecated - use ackAdd */
|
|
248
|
-
addInternal(serializedInterval: ISerializedInterval, local: boolean, op: ISequencedDocumentMessage): TInterval;
|
|
249
264
|
/** @internal */
|
|
250
265
|
ackAdd(serializedInterval: ISerializedInterval, local: boolean, op: ISequencedDocumentMessage): TInterval;
|
|
251
|
-
/** @deprecated - use ackDelete */
|
|
252
|
-
deleteInterval(serializedInterval: ISerializedInterval, local: boolean, op: ISequencedDocumentMessage): void;
|
|
253
266
|
/** @internal */
|
|
254
267
|
ackDelete(serializedInterval: ISerializedInterval, local: boolean, op: ISequencedDocumentMessage): void;
|
|
255
268
|
/**
|
|
@@ -267,4 +280,24 @@ export declare class IntervalCollection<TInterval extends ISerializableInterval>
|
|
|
267
280
|
previousInterval(pos: number): TInterval;
|
|
268
281
|
nextInterval(pos: number): TInterval;
|
|
269
282
|
}
|
|
283
|
+
/**
|
|
284
|
+
* Information that identifies an interval within a `Sequence`.
|
|
285
|
+
*/
|
|
286
|
+
export interface IntervalLocator {
|
|
287
|
+
/**
|
|
288
|
+
* Label for the collection the interval is a part of
|
|
289
|
+
*/
|
|
290
|
+
label: string;
|
|
291
|
+
/**
|
|
292
|
+
* Interval within that collection
|
|
293
|
+
*/
|
|
294
|
+
interval: SequenceInterval;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Returns an object that can be used to find the interval a given LocalReferencePosition belongs to.
|
|
298
|
+
* @returns undefined if the reference position is not the endpoint of any interval (e.g. it was created
|
|
299
|
+
* on the merge tree directly by app code), otherwise an {@link IntervalLocator} for the interval this
|
|
300
|
+
* endpoint is a part of.
|
|
301
|
+
*/
|
|
302
|
+
export declare function intervalLocatorFromEndpoint(potentialEndpoint: LocalReferencePosition): IntervalLocator | undefined;
|
|
270
303
|
//# sourceMappingURL=intervalCollection.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intervalCollection.d.ts","sourceRoot":"","sources":["../src/intervalCollection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAU,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AAE5D,OAAO,EAEH,MAAM,
|
|
1
|
+
{"version":3,"file":"intervalCollection.d.ts","sourceRoot":"","sources":["../src/intervalCollection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAU,iBAAiB,EAAE,MAAM,8BAA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C;IAK1D,sCAAsC,CAAC,aAAa,EAAE,MAAM,GAAG,0BAA0B,CAAC,SAAS,CAAC;IAKpG,uCAAuC,CAAC,aAAa,EAAE,MAAM,GAAG,0BAA0B,CAAC,SAAS,CAAC;IAKrG,oCAAoC,CAAC,WAAW,EAAE,MAAM,GAAG,0BAA0B,CAAC,SAAS,CAAC;IAKhG,qCAAqC,CAAC,WAAW,EAAE,MAAM,GAAG,0BAA0B,CAAC,SAAS,CAAC;IAKjG,sBAAsB,CACzB,OAAO,EAAE,SAAS,EAAE,EACpB,eAAe,EAAE,OAAO,EACxB,KAAK,CAAC,EAAE,MAAM,EACd,GAAG,CAAC,EAAE,MAAM;IAQT,wBAAwB,CAAC,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,SAAS,EAAE;IAQjF,GAAG,CAAC,EAAE,EAAE,CAAC,QAAQ,EAAE,SAAS,KAAK,IAAI;IAQrC,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS;IAQxC,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS;CAO9C;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC5B;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,QAAQ,EAAE,gBAAgB,CAAC;CAC9B;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,iBAAiB,EAAE,sBAAsB,GAAG,eAAe,GAAG,SAAS,CAMlH"}
|
|
@@ -16,7 +16,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
16
16
|
/* eslint-disable no-bitwise */
|
|
17
17
|
import { assert, TypedEventEmitter } from "@fluidframework/common-utils";
|
|
18
18
|
import { UsageError } from "@fluidframework/container-utils";
|
|
19
|
-
import { addProperties, createMap, IntervalTree,
|
|
19
|
+
import { addProperties, compareReferencePositions, createMap, IntervalTree, MergeTreeDeltaType, minReferencePosition, PropertiesManager, RedBlackTree, ReferenceType, refTypeIncludesFlag, reservedRangeLabelsKey, UnassignedSequenceNumber, maxReferencePosition, createDetachedLocalReferencePosition, DetachedReferencePosition, } from "@fluidframework/merge-tree";
|
|
20
20
|
import { LoggingError } from "@fluidframework/telemetry-utils";
|
|
21
21
|
import { v4 as uuid } from "uuid";
|
|
22
22
|
const reservedIntervalIdKey = "intervalId";
|
|
@@ -32,8 +32,8 @@ export var IntervalType;
|
|
|
32
32
|
*/
|
|
33
33
|
IntervalType[IntervalType["SlideOnRemove"] = 2] = "SlideOnRemove";
|
|
34
34
|
/**
|
|
35
|
-
* @internal
|
|
36
35
|
* A temporary interval, used internally
|
|
36
|
+
* @internal
|
|
37
37
|
*/
|
|
38
38
|
IntervalType[IntervalType["Transient"] = 4] = "Transient";
|
|
39
39
|
})(IntervalType || (IntervalType = {}));
|
|
@@ -47,7 +47,7 @@ function decompressInterval(interval, label) {
|
|
|
47
47
|
end: interval[1],
|
|
48
48
|
sequenceNumber: interval[2],
|
|
49
49
|
intervalType: interval[3],
|
|
50
|
-
properties: Object.assign(Object.assign({}, interval[4]), { [reservedRangeLabelsKey]: label }),
|
|
50
|
+
properties: Object.assign(Object.assign({}, interval[4]), { [reservedRangeLabelsKey]: [label] }),
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
@@ -92,10 +92,8 @@ export class Interval {
|
|
|
92
92
|
this.auxProps.push(props);
|
|
93
93
|
}
|
|
94
94
|
serialize(client) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
seq = client.getCurrentSeq();
|
|
98
|
-
}
|
|
95
|
+
var _a;
|
|
96
|
+
const seq = (_a = client === null || client === void 0 ? void 0 : client.getCurrentSeq()) !== null && _a !== void 0 ? _a : 0;
|
|
99
97
|
const serializedInterval = {
|
|
100
98
|
end: this.end,
|
|
101
99
|
intervalType: 0,
|
|
@@ -180,7 +178,8 @@ export class Interval {
|
|
|
180
178
|
}
|
|
181
179
|
}
|
|
182
180
|
export class SequenceInterval {
|
|
183
|
-
constructor(start, end, intervalType, props) {
|
|
181
|
+
constructor(client, start, end, intervalType, props) {
|
|
182
|
+
this.client = client;
|
|
184
183
|
this.start = start;
|
|
185
184
|
this.end = end;
|
|
186
185
|
this.intervalType = intervalType;
|
|
@@ -191,8 +190,8 @@ export class SequenceInterval {
|
|
|
191
190
|
}
|
|
192
191
|
}
|
|
193
192
|
/**
|
|
194
|
-
* @internal
|
|
195
193
|
* Subscribes to position change events on this interval if there are no current listeners.
|
|
194
|
+
* @internal
|
|
196
195
|
*/
|
|
197
196
|
addPositionChangeListeners(beforePositionChange, afterPositionChange) {
|
|
198
197
|
var _a, _b;
|
|
@@ -209,8 +208,8 @@ export class SequenceInterval {
|
|
|
209
208
|
}
|
|
210
209
|
}
|
|
211
210
|
/**
|
|
212
|
-
* @internal
|
|
213
211
|
* Removes the currently subscribed position change listeners.
|
|
212
|
+
* @internal
|
|
214
213
|
*/
|
|
215
214
|
removePositionChangeListeners() {
|
|
216
215
|
if (this.callbacks) {
|
|
@@ -220,8 +219,8 @@ export class SequenceInterval {
|
|
|
220
219
|
}
|
|
221
220
|
}
|
|
222
221
|
serialize(client) {
|
|
223
|
-
const startPosition = this.start
|
|
224
|
-
const endPosition = this.end
|
|
222
|
+
const startPosition = client.localReferencePositionToPosition(this.start);
|
|
223
|
+
const endPosition = client.localReferencePositionToPosition(this.end);
|
|
225
224
|
const serializedInterval = {
|
|
226
225
|
end: endPosition,
|
|
227
226
|
intervalType: this.intervalType,
|
|
@@ -234,7 +233,7 @@ export class SequenceInterval {
|
|
|
234
233
|
return serializedInterval;
|
|
235
234
|
}
|
|
236
235
|
clone() {
|
|
237
|
-
return new SequenceInterval(this.start, this.end, this.intervalType, this.properties);
|
|
236
|
+
return new SequenceInterval(this.client, this.start, this.end, this.intervalType, this.properties);
|
|
238
237
|
}
|
|
239
238
|
compare(b) {
|
|
240
239
|
const startResult = this.compareStart(b);
|
|
@@ -260,14 +259,14 @@ export class SequenceInterval {
|
|
|
260
259
|
}
|
|
261
260
|
}
|
|
262
261
|
compareStart(b) {
|
|
263
|
-
return this.start
|
|
262
|
+
return compareReferencePositions(this.start, b.start);
|
|
264
263
|
}
|
|
265
264
|
compareEnd(b) {
|
|
266
|
-
return this.end
|
|
265
|
+
return compareReferencePositions(this.end, b.end);
|
|
267
266
|
}
|
|
268
267
|
overlaps(b) {
|
|
269
|
-
const result = (this.start
|
|
270
|
-
(this.end
|
|
268
|
+
const result = (compareReferencePositions(this.start, b.end) <= 0) &&
|
|
269
|
+
(compareReferencePositions(this.end, b.start) >= 0);
|
|
271
270
|
return result;
|
|
272
271
|
}
|
|
273
272
|
getIntervalId() {
|
|
@@ -279,18 +278,18 @@ export class SequenceInterval {
|
|
|
279
278
|
return `${id}`;
|
|
280
279
|
}
|
|
281
280
|
union(b) {
|
|
282
|
-
return new SequenceInterval(this.start
|
|
281
|
+
return new SequenceInterval(this.client, minReferencePosition(this.start, b.start), maxReferencePosition(this.end, b.end), this.intervalType);
|
|
283
282
|
}
|
|
284
283
|
addProperties(newProps, collab = false, seq, op) {
|
|
285
284
|
this.initializeProperties();
|
|
286
285
|
return this.propertyManager.addProperties(this.properties, newProps, op, seq, collab);
|
|
287
286
|
}
|
|
288
287
|
overlapsPos(bstart, bend) {
|
|
289
|
-
const startPos = this.
|
|
290
|
-
const endPos = this.
|
|
288
|
+
const startPos = this.client.localReferencePositionToPosition(this.start);
|
|
289
|
+
const endPos = this.client.localReferencePositionToPosition(this.end);
|
|
291
290
|
return (endPos > bstart) && (startPos < bend);
|
|
292
291
|
}
|
|
293
|
-
modify(label, start, end, op) {
|
|
292
|
+
modify(label, start, end, op, localSeq) {
|
|
294
293
|
const getRefType = (baseType) => {
|
|
295
294
|
let refType = baseType;
|
|
296
295
|
if (op === undefined) {
|
|
@@ -301,17 +300,15 @@ export class SequenceInterval {
|
|
|
301
300
|
};
|
|
302
301
|
let startRef = this.start;
|
|
303
302
|
if (start !== undefined) {
|
|
304
|
-
startRef = createPositionReference(this.
|
|
303
|
+
startRef = createPositionReference(this.client, start, getRefType(this.start.refType), op, undefined, localSeq);
|
|
305
304
|
startRef.addProperties(this.start.properties);
|
|
306
305
|
}
|
|
307
306
|
let endRef = this.end;
|
|
308
307
|
if (end !== undefined) {
|
|
309
|
-
endRef = createPositionReference(this.
|
|
308
|
+
endRef = createPositionReference(this.client, end, getRefType(this.end.refType), op, undefined, localSeq);
|
|
310
309
|
endRef.addProperties(this.end.properties);
|
|
311
310
|
}
|
|
312
|
-
|
|
313
|
-
endRef.pairedRef = startRef;
|
|
314
|
-
const newInterval = new SequenceInterval(startRef, endRef, this.intervalType);
|
|
311
|
+
const newInterval = new SequenceInterval(this.client, startRef, endRef, this.intervalType);
|
|
315
312
|
if (this.properties) {
|
|
316
313
|
newInterval.initializeProperties();
|
|
317
314
|
this.propertyManager.copyTo(this.properties, newInterval.properties, newInterval.propertyManager);
|
|
@@ -332,14 +329,13 @@ function createPositionReferenceFromSegoff(client, segoff, refType, op) {
|
|
|
332
329
|
const ref = client.createLocalReferencePosition(segoff.segment, segoff.offset, refType, undefined);
|
|
333
330
|
return ref;
|
|
334
331
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
}
|
|
339
|
-
return new LocalReference(client, undefined, 0, refType);
|
|
332
|
+
if (!op && !refTypeIncludesFlag(refType, ReferenceType.Transient)) {
|
|
333
|
+
// reference to segment that dne locally
|
|
334
|
+
throw new UsageError("Non-transient references need segment");
|
|
340
335
|
}
|
|
336
|
+
return createDetachedLocalReferencePosition(refType);
|
|
341
337
|
}
|
|
342
|
-
function createPositionReference(client, pos, refType, op) {
|
|
338
|
+
function createPositionReference(client, pos, refType, op, fromSnapshot, localSeq) {
|
|
343
339
|
let segoff;
|
|
344
340
|
if (op) {
|
|
345
341
|
assert((refType & ReferenceType.SlideOnRemove) !== 0, 0x2f5 /* op create references must be SlideOnRemove */);
|
|
@@ -347,12 +343,12 @@ function createPositionReference(client, pos, refType, op) {
|
|
|
347
343
|
segoff = client.getSlideToSegment(segoff);
|
|
348
344
|
}
|
|
349
345
|
else {
|
|
350
|
-
assert((refType & ReferenceType.SlideOnRemove) === 0, 0x2f6 /* SlideOnRemove references must be op created */);
|
|
351
|
-
segoff = client.getContainingSegment(pos);
|
|
346
|
+
assert((refType & ReferenceType.SlideOnRemove) === 0 || fromSnapshot, 0x2f6 /* SlideOnRemove references must be op created */);
|
|
347
|
+
segoff = client.getContainingSegment(pos, undefined, localSeq);
|
|
352
348
|
}
|
|
353
349
|
return createPositionReferenceFromSegoff(client, segoff, refType, op);
|
|
354
350
|
}
|
|
355
|
-
function createSequenceInterval(label, start, end, client, intervalType, op) {
|
|
351
|
+
function createSequenceInterval(label, start, end, client, intervalType, op, fromSnapshot) {
|
|
356
352
|
let beginRefType = ReferenceType.RangeBegin;
|
|
357
353
|
let endRefType = ReferenceType.RangeEnd;
|
|
358
354
|
if (intervalType === IntervalType.Transient) {
|
|
@@ -367,7 +363,7 @@ function createSequenceInterval(label, start, end, client, intervalType, op) {
|
|
|
367
363
|
// All non-transient interval references must eventually be SlideOnRemove
|
|
368
364
|
// To ensure eventual consistency, they must start as StayOnRemove when
|
|
369
365
|
// pending (created locally and creation op is not acked)
|
|
370
|
-
if (op) {
|
|
366
|
+
if (op || fromSnapshot) {
|
|
371
367
|
beginRefType |= ReferenceType.SlideOnRemove;
|
|
372
368
|
endRefType |= ReferenceType.SlideOnRemove;
|
|
373
369
|
}
|
|
@@ -376,16 +372,14 @@ function createSequenceInterval(label, start, end, client, intervalType, op) {
|
|
|
376
372
|
endRefType |= ReferenceType.StayOnRemove;
|
|
377
373
|
}
|
|
378
374
|
}
|
|
379
|
-
const startLref = createPositionReference(client, start, beginRefType, op);
|
|
380
|
-
const endLref = createPositionReference(client, end, endRefType, op);
|
|
381
|
-
startLref.pairedRef = endLref;
|
|
382
|
-
endLref.pairedRef = startLref;
|
|
375
|
+
const startLref = createPositionReference(client, start, beginRefType, op, fromSnapshot);
|
|
376
|
+
const endLref = createPositionReference(client, end, endRefType, op, fromSnapshot);
|
|
383
377
|
const rangeProp = {
|
|
384
378
|
[reservedRangeLabelsKey]: [label],
|
|
385
379
|
};
|
|
386
380
|
startLref.addProperties(rangeProp);
|
|
387
381
|
endLref.addProperties(rangeProp);
|
|
388
|
-
const ival = new SequenceInterval(startLref, endLref, intervalType, rangeProp);
|
|
382
|
+
const ival = new SequenceInterval(client, startLref, endLref, intervalType, rangeProp);
|
|
389
383
|
return ival;
|
|
390
384
|
}
|
|
391
385
|
export function defaultIntervalConflictResolver(a, b) {
|
|
@@ -572,6 +566,8 @@ export class LocalIntervalCollection {
|
|
|
572
566
|
return this.helpers.create(this.label, start, end, this.client, intervalType, op);
|
|
573
567
|
}
|
|
574
568
|
addInterval(start, end, intervalType, props, op) {
|
|
569
|
+
var _a;
|
|
570
|
+
var _b;
|
|
575
571
|
const interval = this.createInterval(start, end, intervalType, op);
|
|
576
572
|
if (interval) {
|
|
577
573
|
if (!interval.properties) {
|
|
@@ -580,14 +576,17 @@ export class LocalIntervalCollection {
|
|
|
580
576
|
if (props) {
|
|
581
577
|
interval.addProperties(props);
|
|
582
578
|
}
|
|
583
|
-
|
|
584
|
-
// Create a new ID.
|
|
585
|
-
interval.properties[reservedIntervalIdKey] = uuid();
|
|
586
|
-
}
|
|
579
|
+
(_a = (_b = interval.properties)[reservedIntervalIdKey]) !== null && _a !== void 0 ? _a : (_b[reservedIntervalIdKey] = uuid());
|
|
587
580
|
this.add(interval);
|
|
588
581
|
}
|
|
589
582
|
return interval;
|
|
590
583
|
}
|
|
584
|
+
linkEndpointsToInterval(interval) {
|
|
585
|
+
if (interval instanceof SequenceInterval) {
|
|
586
|
+
interval.start.addProperties({ interval });
|
|
587
|
+
interval.end.addProperties({ interval });
|
|
588
|
+
}
|
|
589
|
+
}
|
|
591
590
|
addIntervalToIndex(interval) {
|
|
592
591
|
const id = interval.getIntervalId();
|
|
593
592
|
assert(id !== undefined, 0x2c0 /* "ID must be created before adding interval to collection" */);
|
|
@@ -602,14 +601,15 @@ export class LocalIntervalCollection {
|
|
|
602
601
|
this.intervalIdMap.set(id, interval);
|
|
603
602
|
}
|
|
604
603
|
add(interval) {
|
|
604
|
+
this.linkEndpointsToInterval(interval);
|
|
605
605
|
this.addIntervalToIndex(interval);
|
|
606
606
|
this.addIntervalListeners(interval);
|
|
607
607
|
}
|
|
608
608
|
getIntervalById(id) {
|
|
609
609
|
return this.intervalIdMap.get(id);
|
|
610
610
|
}
|
|
611
|
-
changeInterval(interval, start, end, op) {
|
|
612
|
-
const newInterval = interval.modify(this.label, start, end, op);
|
|
611
|
+
changeInterval(interval, start, end, op, localSeq) {
|
|
612
|
+
const newInterval = interval.modify(this.label, start, end, op, localSeq);
|
|
613
613
|
if (newInterval) {
|
|
614
614
|
this.removeExistingInterval(interval);
|
|
615
615
|
this.add(newInterval);
|
|
@@ -641,7 +641,7 @@ export class LocalIntervalCollection {
|
|
|
641
641
|
}
|
|
642
642
|
}
|
|
643
643
|
LocalIntervalCollection.legacyIdPrefix = "legacy";
|
|
644
|
-
const compareSequenceIntervalEnds = (a, b) => a.end
|
|
644
|
+
const compareSequenceIntervalEnds = (a, b) => compareReferencePositions(a.end, b.end);
|
|
645
645
|
class SequenceIntervalCollectionFactory {
|
|
646
646
|
load(emitter, raw = []) {
|
|
647
647
|
const helpers = {
|
|
@@ -715,6 +715,11 @@ function makeOpsMap() {
|
|
|
715
715
|
"add",
|
|
716
716
|
{
|
|
717
717
|
process: (collection, params, local, op) => {
|
|
718
|
+
// if params is undefined, the interval was deleted during
|
|
719
|
+
// rebasing
|
|
720
|
+
if (!params) {
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
718
723
|
collection.ackAdd(params, local, op);
|
|
719
724
|
},
|
|
720
725
|
rebase,
|
|
@@ -736,6 +741,11 @@ function makeOpsMap() {
|
|
|
736
741
|
"change",
|
|
737
742
|
{
|
|
738
743
|
process: (collection, params, local, op) => {
|
|
744
|
+
// if params is undefined, the interval was deleted during
|
|
745
|
+
// rebasing
|
|
746
|
+
if (!params) {
|
|
747
|
+
return;
|
|
748
|
+
}
|
|
739
749
|
collection.ackChange(params, local, op);
|
|
740
750
|
},
|
|
741
751
|
rebase,
|
|
@@ -770,13 +780,9 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
770
780
|
this.emitter = emitter;
|
|
771
781
|
this.pendingChangesStart = new Map();
|
|
772
782
|
this.pendingChangesEnd = new Map();
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
else {
|
|
777
|
-
this.savedSerializedIntervals =
|
|
778
|
-
serializedIntervals.intervals.map((i) => decompressInterval(i, serializedIntervals.label));
|
|
779
|
-
}
|
|
783
|
+
this.savedSerializedIntervals = Array.isArray(serializedIntervals)
|
|
784
|
+
? serializedIntervals
|
|
785
|
+
: serializedIntervals.intervals.map((i) => decompressInterval(i, serializedIntervals.label));
|
|
780
786
|
}
|
|
781
787
|
get attached() {
|
|
782
788
|
return !!this.localCollection;
|
|
@@ -794,7 +800,10 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
794
800
|
if (this.savedSerializedIntervals) {
|
|
795
801
|
for (const serializedInterval of this.savedSerializedIntervals) {
|
|
796
802
|
this.localCollection.ensureSerializedId(serializedInterval);
|
|
797
|
-
|
|
803
|
+
const { start, end, intervalType, properties } = serializedInterval;
|
|
804
|
+
const interval = this.helpers.create(label, start, end, client, intervalType, undefined, true);
|
|
805
|
+
interval.addProperties(properties);
|
|
806
|
+
this.localCollection.add(interval);
|
|
798
807
|
}
|
|
799
808
|
}
|
|
800
809
|
this.savedSerializedIntervals = undefined;
|
|
@@ -803,7 +812,10 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
803
812
|
* Gets the next local sequence number, modifying this client's collab window in doing so.
|
|
804
813
|
*/
|
|
805
814
|
getNextLocalSeq() {
|
|
806
|
-
|
|
815
|
+
if (this.client) {
|
|
816
|
+
return ++this.client.getCollabWindow().localSeq;
|
|
817
|
+
}
|
|
818
|
+
return 0;
|
|
807
819
|
}
|
|
808
820
|
getIntervalById(id) {
|
|
809
821
|
if (!this.attached) {
|
|
@@ -966,10 +978,6 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
966
978
|
const entries = this.pendingChangesEnd.get(id);
|
|
967
979
|
return entries && entries.length !== 0;
|
|
968
980
|
}
|
|
969
|
-
/** @deprecated - use ackChange */
|
|
970
|
-
changeInterval(serializedInterval, local, op) {
|
|
971
|
-
return this.ackChange(serializedInterval, local, op);
|
|
972
|
-
}
|
|
973
981
|
/** @internal */
|
|
974
982
|
ackChange(serializedInterval, local, op) {
|
|
975
983
|
var _a, _b, _c, _d;
|
|
@@ -1043,9 +1051,19 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
1043
1051
|
onDeserialize(interval);
|
|
1044
1052
|
});
|
|
1045
1053
|
}
|
|
1046
|
-
/**
|
|
1054
|
+
/**
|
|
1055
|
+
* Returns new interval after rebasing. If undefined, the interval was
|
|
1056
|
+
* deleted as a result of rebasing. This can occur if the interval applies
|
|
1057
|
+
* to a range that no longer exists, and the interval was unable to slide.
|
|
1058
|
+
*
|
|
1059
|
+
* @internal
|
|
1060
|
+
*/
|
|
1047
1061
|
rebaseLocalInterval(opName, serializedInterval, localSeq) {
|
|
1048
1062
|
var _a, _b;
|
|
1063
|
+
if (!this.client) {
|
|
1064
|
+
// If there's no associated mergeTree client, the originally submitted op is still correct.
|
|
1065
|
+
return serializedInterval;
|
|
1066
|
+
}
|
|
1049
1067
|
if (!this.attached) {
|
|
1050
1068
|
throw new LoggingError("attachSequence must be called");
|
|
1051
1069
|
}
|
|
@@ -1055,6 +1073,7 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
1055
1073
|
const endRebased = end === undefined ? undefined :
|
|
1056
1074
|
this.client.rebasePosition(end, sequenceNumber, localSeq);
|
|
1057
1075
|
const intervalId = properties === null || properties === void 0 ? void 0 : properties[reservedIntervalIdKey];
|
|
1076
|
+
const localInterval = this.localCollection.getIntervalById(intervalId);
|
|
1058
1077
|
const rebased = {
|
|
1059
1078
|
start: startRebased,
|
|
1060
1079
|
end: endRebased,
|
|
@@ -1066,10 +1085,31 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
1066
1085
|
this.removePendingChange(serializedInterval);
|
|
1067
1086
|
this.addPendingChange(intervalId, rebased);
|
|
1068
1087
|
}
|
|
1088
|
+
// if the interval slid off the string, rebase the op to be a noop and
|
|
1089
|
+
// delete the interval
|
|
1090
|
+
if (startRebased === DetachedReferencePosition || endRebased === DetachedReferencePosition) {
|
|
1091
|
+
if (localInterval) {
|
|
1092
|
+
this.localCollection.removeExistingInterval(localInterval);
|
|
1093
|
+
}
|
|
1094
|
+
return undefined;
|
|
1095
|
+
}
|
|
1096
|
+
if (!localInterval) {
|
|
1097
|
+
return rebased;
|
|
1098
|
+
}
|
|
1099
|
+
// we know we must be using `SequenceInterval` because `this.client` exists
|
|
1100
|
+
assert(localInterval instanceof SequenceInterval, 0x3a0 /* localInterval must be `SequenceInterval` when used with client */);
|
|
1101
|
+
const startSegment = this.getSlideToSegment(localInterval.start);
|
|
1102
|
+
const endSegment = this.getSlideToSegment(localInterval.end);
|
|
1103
|
+
// we need to slide because the reference has been removed
|
|
1104
|
+
if (startSegment || endSegment) {
|
|
1105
|
+
const newStart = startSegment && this.client.getPosition(startSegment.segment, localSeq) + startSegment.offset;
|
|
1106
|
+
const newEnd = endSegment && this.client.getPosition(endSegment.segment, localSeq) + endSegment.offset;
|
|
1107
|
+
this.localCollection.changeInterval(localInterval, newStart, newEnd, undefined, localSeq);
|
|
1108
|
+
}
|
|
1069
1109
|
return rebased;
|
|
1070
1110
|
}
|
|
1071
1111
|
getSlideToSegment(lref) {
|
|
1072
|
-
const segoff = { segment: lref.
|
|
1112
|
+
const segoff = { segment: lref.getSegment(), offset: lref.getOffset() };
|
|
1073
1113
|
const newSegoff = this.client.getSlideToSegment(segoff);
|
|
1074
1114
|
const value = (segoff.segment === newSegoff.segment && segoff.offset === newSegoff.offset) ? undefined : newSegoff;
|
|
1075
1115
|
return value;
|
|
@@ -1081,7 +1121,7 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
1081
1121
|
lref.refType = refType;
|
|
1082
1122
|
}
|
|
1083
1123
|
ackInterval(interval, op) {
|
|
1084
|
-
//
|
|
1124
|
+
// Only SequenceIntervals need potential sliding
|
|
1085
1125
|
if (!(interval instanceof SequenceInterval)) {
|
|
1086
1126
|
return;
|
|
1087
1127
|
}
|
|
@@ -1105,7 +1145,7 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
1105
1145
|
if (needsStartUpdate || needsEndUpdate) {
|
|
1106
1146
|
// In this case, where we change the start or end of an interval,
|
|
1107
1147
|
// it is necessary to remove and re-add the interval listeners.
|
|
1108
|
-
// This ensures that the correct listeners are added to the
|
|
1148
|
+
// This ensures that the correct listeners are added to the LocalReferencePosition.
|
|
1109
1149
|
this.localCollection.removeExistingInterval(interval);
|
|
1110
1150
|
if (needsStartUpdate) {
|
|
1111
1151
|
const props = interval.start.properties;
|
|
@@ -1126,10 +1166,6 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
1126
1166
|
this.localCollection.add(interval);
|
|
1127
1167
|
}
|
|
1128
1168
|
}
|
|
1129
|
-
/** @deprecated - use ackAdd */
|
|
1130
|
-
addInternal(serializedInterval, local, op) {
|
|
1131
|
-
return this.ackAdd(serializedInterval, local, op);
|
|
1132
|
-
}
|
|
1133
1169
|
/** @internal */
|
|
1134
1170
|
ackAdd(serializedInterval, local, op) {
|
|
1135
1171
|
var _a;
|
|
@@ -1154,10 +1190,6 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
1154
1190
|
this.emit("addInterval", interval, local, op);
|
|
1155
1191
|
return interval;
|
|
1156
1192
|
}
|
|
1157
|
-
/** @deprecated - use ackDelete */
|
|
1158
|
-
deleteInterval(serializedInterval, local, op) {
|
|
1159
|
-
return this.ackDelete(serializedInterval, local, op);
|
|
1160
|
-
}
|
|
1161
1193
|
/** @internal */
|
|
1162
1194
|
ackDelete(serializedInterval, local, op) {
|
|
1163
1195
|
if (local) {
|
|
@@ -1235,4 +1267,15 @@ export class IntervalCollection extends TypedEventEmitter {
|
|
|
1235
1267
|
return this.localCollection.nextInterval(pos);
|
|
1236
1268
|
}
|
|
1237
1269
|
}
|
|
1270
|
+
/**
|
|
1271
|
+
* Returns an object that can be used to find the interval a given LocalReferencePosition belongs to.
|
|
1272
|
+
* @returns undefined if the reference position is not the endpoint of any interval (e.g. it was created
|
|
1273
|
+
* on the merge tree directly by app code), otherwise an {@link IntervalLocator} for the interval this
|
|
1274
|
+
* endpoint is a part of.
|
|
1275
|
+
*/
|
|
1276
|
+
export function intervalLocatorFromEndpoint(potentialEndpoint) {
|
|
1277
|
+
var _a;
|
|
1278
|
+
const { interval, [reservedRangeLabelsKey]: collectionNameArray, } = (_a = potentialEndpoint.properties) !== null && _a !== void 0 ? _a : {};
|
|
1279
|
+
return (interval && (collectionNameArray === null || collectionNameArray === void 0 ? void 0 : collectionNameArray.length) === 1) ? { label: collectionNameArray[0], interval } : undefined;
|
|
1280
|
+
}
|
|
1238
1281
|
//# sourceMappingURL=intervalCollection.js.map
|