@fluidframework/sequence 2.0.0-dev.3.1.0.125672 → 2.0.0-dev.4.2.0.153917

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.
@@ -84,9 +84,7 @@ export class Interval {
84
84
  getIntervalId() {
85
85
  var _a;
86
86
  const id = (_a = this.properties) === null || _a === void 0 ? void 0 : _a[reservedIntervalIdKey];
87
- if (id === undefined) {
88
- return undefined;
89
- }
87
+ assert(id !== undefined, 0x5e1 /* interval ID should not be undefined */);
90
88
  return `${id}`;
91
89
  }
92
90
  /**
@@ -179,6 +177,7 @@ export class Interval {
179
177
  }
180
178
  /**
181
179
  * {@inheritDoc IInterval.union}
180
+ * @deprecated - This API was never intended to be public and will be marked internal in a future release.
182
181
  */
183
182
  union(b) {
184
183
  return new Interval(Math.min(this.start, b.start), Math.max(this.end, b.end), this.properties);
@@ -188,6 +187,7 @@ export class Interval {
188
187
  }
189
188
  /**
190
189
  * {@inheritDoc ISerializableInterval.addProperties}
190
+ * @deprecated - This API was never intended to be public and will be marked internal in a future release.
191
191
  */
192
192
  addProperties(newProps, collaborating = false, seq, op) {
193
193
  if (newProps) {
@@ -197,6 +197,7 @@ export class Interval {
197
197
  }
198
198
  /**
199
199
  * {@inheritDoc IInterval.modify}
200
+ * @deprecated - This API was never intended to be public and will be marked internal in a future release.
200
201
  */
201
202
  modify(label, start, end, op) {
202
203
  const startPos = start !== null && start !== void 0 ? start : this.start;
@@ -225,6 +226,22 @@ export class Interval {
225
226
  * Interval impelmentation whose ends are associated with positions in a mutatable sequence.
226
227
  * As such, when content is inserted into the middle of the interval, the interval expands to
227
228
  * include that content.
229
+ *
230
+ * @remarks - The endpoint's position should be treated exclusively to get reasonable behavior--i.e.
231
+ * an interval referring to "hello" in "hello world" should have a start position of 0 and an end
232
+ * position of 5.
233
+ *
234
+ * To see why, consider what happens if "llo wor" is removed from the string to make "held".
235
+ * The interval's startpoint remains on the "h" (it isn't altered), but the interval's endpoint
236
+ * slides forward to the next unremoved position, which is the "l" in "held".
237
+ * Users would generally expect the interval to now refer to "he" (as it is the subset of content
238
+ * remaining after the removal), hence the "l" should be excluded.
239
+ * If the interval endpoint was treated inclusively, the interval would now refer to "hel", which
240
+ * is undesirable.
241
+ *
242
+ * Since the end of an interval is treated exclusively but cannot be greater than or equal to the
243
+ * length of the associated sequence, application models which leverage interval collections should
244
+ * consider inserting a marker at the end of the sequence to represent the end of the content.
228
245
  */
229
246
  export class SequenceInterval {
230
247
  constructor(client,
@@ -353,19 +370,19 @@ export class SequenceInterval {
353
370
  getIntervalId() {
354
371
  var _a;
355
372
  const id = (_a = this.properties) === null || _a === void 0 ? void 0 : _a[reservedIntervalIdKey];
356
- if (id === undefined) {
357
- return undefined;
358
- }
373
+ assert(id !== undefined, 0x5e2 /* interval ID should not be undefined */);
359
374
  return `${id}`;
360
375
  }
361
376
  /**
362
377
  * {@inheritDoc IInterval.union}
378
+ * @deprecated - This API was never intended to be public and will be marked internal in a future release.
363
379
  */
364
380
  union(b) {
365
381
  return new SequenceInterval(this.client, minReferencePosition(this.start, b.start), maxReferencePosition(this.end, b.end), this.intervalType);
366
382
  }
367
383
  /**
368
384
  * {@inheritDoc ISerializableInterval.addProperties}
385
+ * @deprecated - This API was never intended to be public and will be marked internal in a future release.
369
386
  */
370
387
  addProperties(newProps, collab = false, seq, op) {
371
388
  this.initializeProperties();
@@ -373,7 +390,6 @@ export class SequenceInterval {
373
390
  }
374
391
  /**
375
392
  * @returns whether this interval overlaps two numerical positions.
376
- * @remarks - this is currently strict overlap, which doesn't align with the endpoint treatment of`.overlaps()`
377
393
  */
378
394
  overlapsPos(bstart, bend) {
379
395
  const startPos = this.client.localReferencePositionToPosition(this.start);
@@ -382,6 +398,7 @@ export class SequenceInterval {
382
398
  }
383
399
  /**
384
400
  * {@inheritDoc IInterval.modify}
401
+ * @deprecated - This API was never intended to be public and will be marked internal in a future release.
385
402
  */
386
403
  modify(label, start, end, op, localSeq) {
387
404
  const getRefType = (baseType) => {
@@ -422,7 +439,7 @@ export class SequenceInterval {
422
439
  }
423
440
  }
424
441
  }
425
- function createPositionReferenceFromSegoff(client, segoff, refType, op, localSeq) {
442
+ function createPositionReferenceFromSegoff(client, segoff, refType, op, localSeq, fromSnapshot) {
426
443
  if (segoff.segment) {
427
444
  const ref = client.createLocalReferencePosition(segoff.segment, segoff.offset, refType, undefined);
428
445
  return ref;
@@ -432,7 +449,10 @@ function createPositionReferenceFromSegoff(client, segoff, refType, op, localSeq
432
449
  // - References coming from a remote client (location may have been concurrently removed)
433
450
  // - References being rebased to a new sequence number
434
451
  // (segment they originally referred to may have been removed with no suitable replacement)
435
- if (!op && !localSeq && !refTypeIncludesFlag(refType, ReferenceType.Transient)) {
452
+ if (!op &&
453
+ !localSeq &&
454
+ !fromSnapshot &&
455
+ !refTypeIncludesFlag(refType, ReferenceType.Transient)) {
436
456
  throw new UsageError("Non-transient references need segment");
437
457
  }
438
458
  return createDetachedLocalReferencePosition(refType);
@@ -451,7 +471,7 @@ function createPositionReference(client, pos, refType, op, fromSnapshot, localSe
451
471
  assert((refType & ReferenceType.SlideOnRemove) === 0 || !!fromSnapshot, 0x2f6 /* SlideOnRemove references must be op created */);
452
472
  segoff = client.getContainingSegment(pos, undefined, localSeq);
453
473
  }
454
- return createPositionReferenceFromSegoff(client, segoff, refType, op, localSeq);
474
+ return createPositionReferenceFromSegoff(client, segoff, refType, op, localSeq, fromSnapshot);
455
475
  }
456
476
  export function createSequenceInterval(label, start, end, client, intervalType, op, fromSnapshot) {
457
477
  let beginRefType = ReferenceType.RangeBegin;
@@ -629,7 +649,7 @@ export class LocalIntervalCollection {
629
649
  }
630
650
  /**
631
651
  * @returns an array of all intervals contained in this collection that overlap the range
632
- * `[startPosition, endPosition]`.
652
+ * `[startPosition, endPosition)`.
633
653
  */
634
654
  findOverlappingIntervals(startPosition, endPosition) {
635
655
  if (endPosition < startPosition || this.intervalTree.intervals.isEmpty()) {
@@ -1039,11 +1059,13 @@ export class IntervalCollection extends TypedEventEmitter {
1039
1059
  }
1040
1060
  /**
1041
1061
  * Creates a new interval and add it to the collection.
1042
- * @param start - interval start position
1043
- * @param end - interval end position
1062
+ * @param start - interval start position (inclusive)
1063
+ * @param end - interval end position (exclusive)
1044
1064
  * @param intervalType - type of the interval. All intervals are SlideOnRemove. Intervals may not be Transient.
1045
1065
  * @param props - properties of the interval
1046
1066
  * @returns - the created interval
1067
+ * @remarks - See documentation on {@link SequenceInterval} for comments on interval endpoint semantics: there are subtleties
1068
+ * with how the current half-open behavior is represented.
1047
1069
  */
1048
1070
  add(start, end, intervalType, props) {
1049
1071
  var _a, _b;
@@ -1287,6 +1309,13 @@ export class IntervalCollection extends TypedEventEmitter {
1287
1309
  }
1288
1310
  }
1289
1311
  }
1312
+ /**
1313
+ * @deprecated - This functionality was useful when adding two intervals at the same start/end positions resulted
1314
+ * in a conflict. This is no longer the case (as of PR#6407), as interval collections support multiple intervals
1315
+ * at the same location and gives each interval a unique id.
1316
+ *
1317
+ * As such, the conflict resolver is never invoked and unnecessary. This API will be removed in an upcoming release.
1318
+ */
1290
1319
  addConflictResolver(conflictResolver) {
1291
1320
  if (!this.localCollection) {
1292
1321
  throw new LoggingError("attachSequence must be called");