@fluidframework/sequence 1.2.0 → 2.0.0-internal.1.0.0.81589

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/intervalCollection.d.ts +17 -11
  2. package/dist/intervalCollection.d.ts.map +1 -1
  3. package/dist/intervalCollection.js +30 -42
  4. package/dist/intervalCollection.js.map +1 -1
  5. package/dist/packageVersion.d.ts +1 -1
  6. package/dist/packageVersion.d.ts.map +1 -1
  7. package/dist/packageVersion.js +1 -1
  8. package/dist/packageVersion.js.map +1 -1
  9. package/dist/sequence.d.ts +5 -17
  10. package/dist/sequence.d.ts.map +1 -1
  11. package/dist/sequence.js +4 -28
  12. package/dist/sequence.js.map +1 -1
  13. package/dist/sequenceDeltaEvent.d.ts +0 -6
  14. package/dist/sequenceDeltaEvent.d.ts.map +1 -1
  15. package/dist/sequenceDeltaEvent.js +0 -1
  16. package/dist/sequenceDeltaEvent.js.map +1 -1
  17. package/dist/sharedString.d.ts +4 -0
  18. package/dist/sharedString.d.ts.map +1 -1
  19. package/dist/sharedString.js +11 -0
  20. package/dist/sharedString.js.map +1 -1
  21. package/lib/intervalCollection.d.ts +17 -11
  22. package/lib/intervalCollection.d.ts.map +1 -1
  23. package/lib/intervalCollection.js +31 -43
  24. package/lib/intervalCollection.js.map +1 -1
  25. package/lib/packageVersion.d.ts +1 -1
  26. package/lib/packageVersion.d.ts.map +1 -1
  27. package/lib/packageVersion.js +1 -1
  28. package/lib/packageVersion.js.map +1 -1
  29. package/lib/sequence.d.ts +5 -17
  30. package/lib/sequence.d.ts.map +1 -1
  31. package/lib/sequence.js +5 -29
  32. package/lib/sequence.js.map +1 -1
  33. package/lib/sequenceDeltaEvent.d.ts +0 -6
  34. package/lib/sequenceDeltaEvent.d.ts.map +1 -1
  35. package/lib/sequenceDeltaEvent.js +0 -1
  36. package/lib/sequenceDeltaEvent.js.map +1 -1
  37. package/lib/sharedString.d.ts +4 -0
  38. package/lib/sharedString.d.ts.map +1 -1
  39. package/lib/sharedString.js +11 -0
  40. package/lib/sharedString.js.map +1 -1
  41. package/package.json +60 -20
  42. package/src/intervalCollection.ts +73 -65
  43. package/src/packageVersion.ts +1 -1
  44. package/src/sequence.ts +4 -36
  45. package/src/sequenceDeltaEvent.ts +0 -7
  46. package/src/sharedString.ts +13 -2
@@ -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, LocalReference, MergeTreeDeltaType, PropertiesManager, RedBlackTree, ReferenceType, refTypeIncludesFlag, reservedRangeLabelsKey, UnassignedSequenceNumber, } from "@fluidframework/merge-tree";
19
+ import { addProperties, compareReferencePositions, createMap, IntervalTree, MergeTreeDeltaType, minReferencePosition, PropertiesManager, RedBlackTree, ReferenceType, refTypeIncludesFlag, reservedRangeLabelsKey, UnassignedSequenceNumber, maxReferencePosition, createDetachedLocalReferencePosition, } 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";
@@ -180,7 +180,8 @@ export class Interval {
180
180
  }
181
181
  }
182
182
  export class SequenceInterval {
183
- constructor(start, end, intervalType, props) {
183
+ constructor(client, start, end, intervalType, props) {
184
+ this.client = client;
184
185
  this.start = start;
185
186
  this.end = end;
186
187
  this.intervalType = intervalType;
@@ -220,8 +221,8 @@ export class SequenceInterval {
220
221
  }
221
222
  }
222
223
  serialize(client) {
223
- const startPosition = this.start.toPosition();
224
- const endPosition = this.end.toPosition();
224
+ const startPosition = client.localReferencePositionToPosition(this.start);
225
+ const endPosition = client.localReferencePositionToPosition(this.end);
225
226
  const serializedInterval = {
226
227
  end: endPosition,
227
228
  intervalType: this.intervalType,
@@ -234,7 +235,7 @@ export class SequenceInterval {
234
235
  return serializedInterval;
235
236
  }
236
237
  clone() {
237
- return new SequenceInterval(this.start, this.end, this.intervalType, this.properties);
238
+ return new SequenceInterval(this.client, this.start, this.end, this.intervalType, this.properties);
238
239
  }
239
240
  compare(b) {
240
241
  const startResult = this.compareStart(b);
@@ -260,14 +261,14 @@ export class SequenceInterval {
260
261
  }
261
262
  }
262
263
  compareStart(b) {
263
- return this.start.compare(b.start);
264
+ return compareReferencePositions(this.start, b.start);
264
265
  }
265
266
  compareEnd(b) {
266
- return this.end.compare(b.end);
267
+ return compareReferencePositions(this.end, b.end);
267
268
  }
268
269
  overlaps(b) {
269
- const result = (this.start.compare(b.end) <= 0) &&
270
- (this.end.compare(b.start) >= 0);
270
+ const result = (compareReferencePositions(this.start, b.end) <= 0) &&
271
+ (compareReferencePositions(this.end, b.start) >= 0);
271
272
  return result;
272
273
  }
273
274
  getIntervalId() {
@@ -279,15 +280,15 @@ export class SequenceInterval {
279
280
  return `${id}`;
280
281
  }
281
282
  union(b) {
282
- return new SequenceInterval(this.start.min(b.start), this.end.max(b.end), this.intervalType);
283
+ return new SequenceInterval(this.client, minReferencePosition(this.start, b.start), maxReferencePosition(this.end, b.end), this.intervalType);
283
284
  }
284
285
  addProperties(newProps, collab = false, seq, op) {
285
286
  this.initializeProperties();
286
287
  return this.propertyManager.addProperties(this.properties, newProps, op, seq, collab);
287
288
  }
288
289
  overlapsPos(bstart, bend) {
289
- const startPos = this.start.toPosition();
290
- const endPos = this.start.toPosition();
290
+ const startPos = this.client.localReferencePositionToPosition(this.start);
291
+ const endPos = this.client.localReferencePositionToPosition(this.end);
291
292
  return (endPos > bstart) && (startPos < bend);
292
293
  }
293
294
  modify(label, start, end, op) {
@@ -301,17 +302,15 @@ export class SequenceInterval {
301
302
  };
302
303
  let startRef = this.start;
303
304
  if (start !== undefined) {
304
- startRef = createPositionReference(this.start.getClient(), start, getRefType(this.start.refType), op);
305
+ startRef = createPositionReference(this.client, start, getRefType(this.start.refType), op);
305
306
  startRef.addProperties(this.start.properties);
306
307
  }
307
308
  let endRef = this.end;
308
309
  if (end !== undefined) {
309
- endRef = createPositionReference(this.end.getClient(), end, getRefType(this.end.refType), op);
310
+ endRef = createPositionReference(this.client, end, getRefType(this.end.refType), op);
310
311
  endRef.addProperties(this.end.properties);
311
312
  }
312
- startRef.pairedRef = endRef;
313
- endRef.pairedRef = startRef;
314
- const newInterval = new SequenceInterval(startRef, endRef, this.intervalType);
313
+ const newInterval = new SequenceInterval(this.client, startRef, endRef, this.intervalType);
315
314
  if (this.properties) {
316
315
  newInterval.initializeProperties();
317
316
  this.propertyManager.copyTo(this.properties, newInterval.properties, newInterval.propertyManager);
@@ -336,10 +335,10 @@ function createPositionReferenceFromSegoff(client, segoff, refType, op) {
336
335
  if (!op && !refTypeIncludesFlag(refType, ReferenceType.Transient)) {
337
336
  throw new UsageError("Non-transient references need segment");
338
337
  }
339
- return new LocalReference(client, undefined, 0, refType);
340
338
  }
339
+ return createDetachedLocalReferencePosition(refType);
341
340
  }
342
- function createPositionReference(client, pos, refType, op) {
341
+ function createPositionReference(client, pos, refType, op, fromSnapshot) {
343
342
  let segoff;
344
343
  if (op) {
345
344
  assert((refType & ReferenceType.SlideOnRemove) !== 0, 0x2f5 /* op create references must be SlideOnRemove */);
@@ -347,12 +346,12 @@ function createPositionReference(client, pos, refType, op) {
347
346
  segoff = client.getSlideToSegment(segoff);
348
347
  }
349
348
  else {
350
- assert((refType & ReferenceType.SlideOnRemove) === 0, 0x2f6 /* SlideOnRemove references must be op created */);
349
+ assert((refType & ReferenceType.SlideOnRemove) === 0 || fromSnapshot, 0x2f6 /* SlideOnRemove references must be op created */);
351
350
  segoff = client.getContainingSegment(pos);
352
351
  }
353
352
  return createPositionReferenceFromSegoff(client, segoff, refType, op);
354
353
  }
355
- function createSequenceInterval(label, start, end, client, intervalType, op) {
354
+ function createSequenceInterval(label, start, end, client, intervalType, op, fromSnapshot) {
356
355
  let beginRefType = ReferenceType.RangeBegin;
357
356
  let endRefType = ReferenceType.RangeEnd;
358
357
  if (intervalType === IntervalType.Transient) {
@@ -367,7 +366,7 @@ function createSequenceInterval(label, start, end, client, intervalType, op) {
367
366
  // All non-transient interval references must eventually be SlideOnRemove
368
367
  // To ensure eventual consistency, they must start as StayOnRemove when
369
368
  // pending (created locally and creation op is not acked)
370
- if (op) {
369
+ if (op || fromSnapshot) {
371
370
  beginRefType |= ReferenceType.SlideOnRemove;
372
371
  endRefType |= ReferenceType.SlideOnRemove;
373
372
  }
@@ -376,16 +375,14 @@ function createSequenceInterval(label, start, end, client, intervalType, op) {
376
375
  endRefType |= ReferenceType.StayOnRemove;
377
376
  }
378
377
  }
379
- const startLref = createPositionReference(client, start, beginRefType, op);
380
- const endLref = createPositionReference(client, end, endRefType, op);
381
- startLref.pairedRef = endLref;
382
- endLref.pairedRef = startLref;
378
+ const startLref = createPositionReference(client, start, beginRefType, op, fromSnapshot);
379
+ const endLref = createPositionReference(client, end, endRefType, op, fromSnapshot);
383
380
  const rangeProp = {
384
381
  [reservedRangeLabelsKey]: [label],
385
382
  };
386
383
  startLref.addProperties(rangeProp);
387
384
  endLref.addProperties(rangeProp);
388
- const ival = new SequenceInterval(startLref, endLref, intervalType, rangeProp);
385
+ const ival = new SequenceInterval(client, startLref, endLref, intervalType, rangeProp);
389
386
  return ival;
390
387
  }
391
388
  export function defaultIntervalConflictResolver(a, b) {
@@ -641,7 +638,7 @@ export class LocalIntervalCollection {
641
638
  }
642
639
  }
643
640
  LocalIntervalCollection.legacyIdPrefix = "legacy";
644
- const compareSequenceIntervalEnds = (a, b) => a.end.compare(b.end);
641
+ const compareSequenceIntervalEnds = (a, b) => compareReferencePositions(a.end, b.end);
645
642
  class SequenceIntervalCollectionFactory {
646
643
  load(emitter, raw = []) {
647
644
  const helpers = {
@@ -794,7 +791,10 @@ export class IntervalCollection extends TypedEventEmitter {
794
791
  if (this.savedSerializedIntervals) {
795
792
  for (const serializedInterval of this.savedSerializedIntervals) {
796
793
  this.localCollection.ensureSerializedId(serializedInterval);
797
- this.localCollection.addInterval(serializedInterval.start, serializedInterval.end, serializedInterval.intervalType, serializedInterval.properties);
794
+ const { start, end, intervalType, properties } = serializedInterval;
795
+ const interval = this.helpers.create(label, start, end, client, intervalType, undefined, true);
796
+ interval.addProperties(properties);
797
+ this.localCollection.add(interval);
798
798
  }
799
799
  }
800
800
  this.savedSerializedIntervals = undefined;
@@ -966,10 +966,6 @@ export class IntervalCollection extends TypedEventEmitter {
966
966
  const entries = this.pendingChangesEnd.get(id);
967
967
  return entries && entries.length !== 0;
968
968
  }
969
- /** @deprecated - use ackChange */
970
- changeInterval(serializedInterval, local, op) {
971
- return this.ackChange(serializedInterval, local, op);
972
- }
973
969
  /** @internal */
974
970
  ackChange(serializedInterval, local, op) {
975
971
  var _a, _b, _c, _d;
@@ -1069,7 +1065,7 @@ export class IntervalCollection extends TypedEventEmitter {
1069
1065
  return rebased;
1070
1066
  }
1071
1067
  getSlideToSegment(lref) {
1072
- const segoff = { segment: lref.segment, offset: lref.offset };
1068
+ const segoff = { segment: lref.getSegment(), offset: lref.getOffset() };
1073
1069
  const newSegoff = this.client.getSlideToSegment(segoff);
1074
1070
  const value = (segoff.segment === newSegoff.segment && segoff.offset === newSegoff.offset) ? undefined : newSegoff;
1075
1071
  return value;
@@ -1105,7 +1101,7 @@ export class IntervalCollection extends TypedEventEmitter {
1105
1101
  if (needsStartUpdate || needsEndUpdate) {
1106
1102
  // In this case, where we change the start or end of an interval,
1107
1103
  // it is necessary to remove and re-add the interval listeners.
1108
- // This ensures that the correct listeners are added to the ReferencePosition.
1104
+ // This ensures that the correct listeners are added to the LocalReferencePosition.
1109
1105
  this.localCollection.removeExistingInterval(interval);
1110
1106
  if (needsStartUpdate) {
1111
1107
  const props = interval.start.properties;
@@ -1126,10 +1122,6 @@ export class IntervalCollection extends TypedEventEmitter {
1126
1122
  this.localCollection.add(interval);
1127
1123
  }
1128
1124
  }
1129
- /** @deprecated - use ackAdd */
1130
- addInternal(serializedInterval, local, op) {
1131
- return this.ackAdd(serializedInterval, local, op);
1132
- }
1133
1125
  /** @internal */
1134
1126
  ackAdd(serializedInterval, local, op) {
1135
1127
  var _a;
@@ -1154,10 +1146,6 @@ export class IntervalCollection extends TypedEventEmitter {
1154
1146
  this.emit("addInterval", interval, local, op);
1155
1147
  return interval;
1156
1148
  }
1157
- /** @deprecated - use ackDelete */
1158
- deleteInterval(serializedInterval, local, op) {
1159
- return this.ackDelete(serializedInterval, local, op);
1160
- }
1161
1149
  /** @internal */
1162
1150
  ackDelete(serializedInterval, local, op) {
1163
1151
  if (local) {