@fluidframework/sequence 1.2.0 → 1.2.1

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.
@@ -128,8 +128,26 @@ export interface ISerializableInterval extends IInterval {
128
128
 
129
129
  export interface IIntervalHelpers<TInterval extends ISerializableInterval> {
130
130
  compareEnds(a: TInterval, b: TInterval): number;
131
- create(label: string, start: number, end: number,
132
- client: Client, intervalType?: IntervalType, op?: ISequencedDocumentMessage): TInterval;
131
+ /**
132
+ *
133
+ * @param label - label of the interval collection this interval is being added to. This parameter is
134
+ * irrelevant for transient intervals.
135
+ * @param start - numerical start position of the interval
136
+ * @param end - numberical end position of the interval
137
+ * @param client - client creating the interval
138
+ * @param intervalType - Type of interval to create. Default is SlideOnRemove
139
+ * @param op - If this create came from a remote client, op that created it. Default is undefined (i.e. local)
140
+ * @param fromSnapshot - If this create came from loading a snapshot. Default is false.
141
+ */
142
+ create(
143
+ label: string,
144
+ start: number,
145
+ end: number,
146
+ client: Client,
147
+ intervalType?: IntervalType,
148
+ op?: ISequencedDocumentMessage,
149
+ fromSnapshot?: boolean,
150
+ ): TInterval;
133
151
  }
134
152
 
135
153
  export class Interval implements ISerializableInterval {
@@ -471,14 +489,16 @@ function createPositionReference(
471
489
  client: Client,
472
490
  pos: number,
473
491
  refType: ReferenceType,
474
- op?: ISequencedDocumentMessage): LocalReference {
492
+ op?: ISequencedDocumentMessage,
493
+ fromSnapshot?: boolean): LocalReference {
475
494
  let segoff;
476
495
  if (op) {
477
496
  assert((refType & ReferenceType.SlideOnRemove) !== 0, 0x2f5 /* op create references must be SlideOnRemove */);
478
497
  segoff = client.getContainingSegment(pos, op);
479
498
  segoff = client.getSlideToSegment(segoff);
480
499
  } else {
481
- assert((refType & ReferenceType.SlideOnRemove) === 0, 0x2f6 /* SlideOnRemove references must be op created */);
500
+ assert((refType & ReferenceType.SlideOnRemove) === 0 || fromSnapshot,
501
+ 0x2f6 /* SlideOnRemove references must be op created */);
482
502
  segoff = client.getContainingSegment(pos);
483
503
  }
484
504
  return createPositionReferenceFromSegoff(client, segoff, refType, op);
@@ -490,7 +510,8 @@ function createSequenceInterval(
490
510
  end: number,
491
511
  client: Client,
492
512
  intervalType?: IntervalType,
493
- op?: ISequencedDocumentMessage): SequenceInterval {
513
+ op?: ISequencedDocumentMessage,
514
+ fromSnapshot?: boolean): SequenceInterval {
494
515
  let beginRefType = ReferenceType.RangeBegin;
495
516
  let endRefType = ReferenceType.RangeEnd;
496
517
  if (intervalType === IntervalType.Transient) {
@@ -504,7 +525,7 @@ function createSequenceInterval(
504
525
  // All non-transient interval references must eventually be SlideOnRemove
505
526
  // To ensure eventual consistency, they must start as StayOnRemove when
506
527
  // pending (created locally and creation op is not acked)
507
- if (op) {
528
+ if (op || fromSnapshot) {
508
529
  beginRefType |= ReferenceType.SlideOnRemove;
509
530
  endRefType |= ReferenceType.SlideOnRemove;
510
531
  } else {
@@ -513,8 +534,8 @@ function createSequenceInterval(
513
534
  }
514
535
  }
515
536
 
516
- const startLref = createPositionReference(client, start, beginRefType, op);
517
- const endLref = createPositionReference(client, end, endRefType, op);
537
+ const startLref = createPositionReference(client, start, beginRefType, op, fromSnapshot);
538
+ const endLref = createPositionReference(client, end, endRefType, op, fromSnapshot);
518
539
  startLref.pairedRef = endLref;
519
540
  endLref.pairedRef = startLref;
520
541
  const rangeProp = {
@@ -1086,11 +1107,18 @@ export class IntervalCollection<TInterval extends ISerializableInterval>
1086
1107
  if (this.savedSerializedIntervals) {
1087
1108
  for (const serializedInterval of this.savedSerializedIntervals) {
1088
1109
  this.localCollection.ensureSerializedId(serializedInterval);
1089
- this.localCollection.addInterval(
1090
- serializedInterval.start,
1091
- serializedInterval.end,
1092
- serializedInterval.intervalType,
1093
- serializedInterval.properties);
1110
+ const { start, end, intervalType, properties } = serializedInterval;
1111
+ const interval = this.helpers.create(
1112
+ label,
1113
+ start,
1114
+ end,
1115
+ client,
1116
+ intervalType,
1117
+ undefined,
1118
+ true,
1119
+ );
1120
+ interval.addProperties(properties);
1121
+ this.localCollection.add(interval);
1094
1122
  }
1095
1123
  }
1096
1124
  this.savedSerializedIntervals = undefined;
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/sequence";
9
- export const pkgVersion = "1.2.0";
9
+ export const pkgVersion = "1.2.1";