@fluidframework/sequence 1.0.1 → 1.0.2

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.
@@ -71,8 +71,26 @@ export interface ISerializableInterval extends IInterval {
71
71
 
72
72
  export interface IIntervalHelpers<TInterval extends ISerializableInterval> {
73
73
  compareEnds(a: TInterval, b: TInterval): number;
74
- create(label: string, start: number, end: number,
75
- client: Client, intervalType?: IntervalType, op?: ISequencedDocumentMessage): TInterval;
74
+ /**
75
+ *
76
+ * @param label - label of the interval collection this interval is being added to. This parameter is
77
+ * irrelevant for transient intervals.
78
+ * @param start - numerical start position of the interval
79
+ * @param end - numberical end position of the interval
80
+ * @param client - client creating the interval
81
+ * @param intervalType - Type of interval to create. Default is SlideOnRemove
82
+ * @param op - If this create came from a remote client, op that created it. Default is undefined (i.e. local)
83
+ * @param fromSnapshot - If this create came from loading a snapshot. Default is false.
84
+ */
85
+ create(
86
+ label: string,
87
+ start: number,
88
+ end: number,
89
+ client: Client,
90
+ intervalType?: IntervalType,
91
+ op?: ISequencedDocumentMessage,
92
+ fromSnapshot?: boolean,
93
+ ): TInterval;
76
94
  }
77
95
 
78
96
  export class Interval implements ISerializableInterval {
@@ -343,14 +361,16 @@ function createPositionReference(
343
361
  client: Client,
344
362
  pos: number,
345
363
  refType: ReferenceType,
346
- op?: ISequencedDocumentMessage): LocalReference {
364
+ op?: ISequencedDocumentMessage,
365
+ fromSnapshot?: boolean): LocalReference {
347
366
  let segoff;
348
367
  if (op) {
349
368
  assert((refType & ReferenceType.SlideOnRemove) !== 0, 0x2f5 /* op create references must be SlideOnRemove */);
350
369
  segoff = client.getContainingSegment(pos, op);
351
370
  segoff = client.getSlideToSegment(segoff);
352
371
  } else {
353
- assert((refType & ReferenceType.SlideOnRemove) === 0, 0x2f6 /* SlideOnRemove references must be op created */);
372
+ assert((refType & ReferenceType.SlideOnRemove) === 0 || fromSnapshot,
373
+ 0x2f6 /* SlideOnRemove references must be op created */);
354
374
  segoff = client.getContainingSegment(pos);
355
375
  }
356
376
  return createPositionReferenceFromSegoff(client, segoff, refType, op);
@@ -362,7 +382,8 @@ function createSequenceInterval(
362
382
  end: number,
363
383
  client: Client,
364
384
  intervalType?: IntervalType,
365
- op?: ISequencedDocumentMessage): SequenceInterval {
385
+ op?: ISequencedDocumentMessage,
386
+ fromSnapshot?: boolean): SequenceInterval {
366
387
  let beginRefType = ReferenceType.RangeBegin;
367
388
  let endRefType = ReferenceType.RangeEnd;
368
389
  if (intervalType === IntervalType.Transient) {
@@ -376,7 +397,7 @@ function createSequenceInterval(
376
397
  // All non-transient interval references must eventually be SlideOnRemove
377
398
  // To ensure eventual consistency, they must start as StayOnRemove when
378
399
  // pending (created locally and creation op is not acked)
379
- if (op) {
400
+ if (op || fromSnapshot) {
380
401
  beginRefType |= ReferenceType.SlideOnRemove;
381
402
  endRefType |= ReferenceType.SlideOnRemove;
382
403
  } else {
@@ -385,8 +406,8 @@ function createSequenceInterval(
385
406
  }
386
407
  }
387
408
 
388
- const startLref = createPositionReference(client, start, beginRefType, op);
389
- const endLref = createPositionReference(client, end, endRefType, op);
409
+ const startLref = createPositionReference(client, start, beginRefType, op, fromSnapshot);
410
+ const endLref = createPositionReference(client, end, endRefType, op, fromSnapshot);
390
411
  startLref.pairedRef = endLref;
391
412
  endLref.pairedRef = startLref;
392
413
  const rangeProp = {
@@ -888,11 +909,18 @@ export class IntervalCollection<TInterval extends ISerializableInterval>
888
909
  if (this.savedSerializedIntervals) {
889
910
  for (const serializedInterval of this.savedSerializedIntervals) {
890
911
  this.localCollection.ensureSerializedId(serializedInterval);
891
- this.localCollection.addInterval(
892
- serializedInterval.start,
893
- serializedInterval.end,
894
- serializedInterval.intervalType,
895
- serializedInterval.properties);
912
+ const { start, end, intervalType, properties } = serializedInterval;
913
+ const interval = this.helpers.create(
914
+ label,
915
+ start,
916
+ end,
917
+ client,
918
+ intervalType,
919
+ undefined,
920
+ true,
921
+ );
922
+ interval.addProperties(properties);
923
+ this.localCollection.add(interval);
896
924
  }
897
925
  }
898
926
  this.savedSerializedIntervals = undefined;
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/sequence";
9
- export const pkgVersion = "1.0.1";
9
+ export const pkgVersion = "1.0.2";