@fluidframework/sequence 2.1.1 → 2.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.
Files changed (92) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +2 -2
  3. package/api-report/sequence.legacy.alpha.api.md +5 -18
  4. package/api-report/sequence.legacy.public.api.md +6 -0
  5. package/dist/index.d.ts +2 -2
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +2 -2
  8. package/dist/index.js.map +1 -1
  9. package/dist/intervalCollection.d.ts +2 -57
  10. package/dist/intervalCollection.d.ts.map +1 -1
  11. package/dist/intervalCollection.js +13 -40
  12. package/dist/intervalCollection.js.map +1 -1
  13. package/dist/intervalCollectionMapInterfaces.d.ts +2 -2
  14. package/dist/intervalCollectionMapInterfaces.js.map +1 -1
  15. package/dist/intervalIndex/overlappingIntervalsIndex.d.ts +1 -2
  16. package/dist/intervalIndex/overlappingIntervalsIndex.d.ts.map +1 -1
  17. package/dist/intervalIndex/overlappingIntervalsIndex.js +3 -2
  18. package/dist/intervalIndex/overlappingIntervalsIndex.js.map +1 -1
  19. package/dist/intervals/interval.d.ts +1 -2
  20. package/dist/intervals/interval.d.ts.map +1 -1
  21. package/dist/intervals/interval.js +2 -2
  22. package/dist/intervals/interval.js.map +1 -1
  23. package/dist/intervals/intervalUtils.d.ts +9 -6
  24. package/dist/intervals/intervalUtils.d.ts.map +1 -1
  25. package/dist/intervals/intervalUtils.js.map +1 -1
  26. package/dist/intervals/sequenceInterval.d.ts +1 -2
  27. package/dist/intervals/sequenceInterval.d.ts.map +1 -1
  28. package/dist/intervals/sequenceInterval.js +12 -12
  29. package/dist/intervals/sequenceInterval.js.map +1 -1
  30. package/dist/packageVersion.d.ts +1 -1
  31. package/dist/packageVersion.js +1 -1
  32. package/dist/packageVersion.js.map +1 -1
  33. package/dist/revertibles.d.ts.map +1 -1
  34. package/dist/revertibles.js +2 -3
  35. package/dist/revertibles.js.map +1 -1
  36. package/dist/sharedSequence.d.ts +1 -1
  37. package/dist/sharedSequence.d.ts.map +1 -1
  38. package/dist/sharedSequence.js +4 -11
  39. package/dist/sharedSequence.js.map +1 -1
  40. package/dist/sharedString.d.ts.map +1 -1
  41. package/dist/sharedString.js +4 -20
  42. package/dist/sharedString.js.map +1 -1
  43. package/lib/index.d.ts +2 -2
  44. package/lib/index.d.ts.map +1 -1
  45. package/lib/index.js +2 -2
  46. package/lib/index.js.map +1 -1
  47. package/lib/intervalCollection.d.ts +2 -57
  48. package/lib/intervalCollection.d.ts.map +1 -1
  49. package/lib/intervalCollection.js +3 -29
  50. package/lib/intervalCollection.js.map +1 -1
  51. package/lib/intervalCollectionMapInterfaces.d.ts +2 -2
  52. package/lib/intervalCollectionMapInterfaces.js.map +1 -1
  53. package/lib/intervalIndex/overlappingIntervalsIndex.d.ts +1 -2
  54. package/lib/intervalIndex/overlappingIntervalsIndex.d.ts.map +1 -1
  55. package/lib/intervalIndex/overlappingIntervalsIndex.js +2 -1
  56. package/lib/intervalIndex/overlappingIntervalsIndex.js.map +1 -1
  57. package/lib/intervals/interval.d.ts +1 -2
  58. package/lib/intervals/interval.d.ts.map +1 -1
  59. package/lib/intervals/interval.js +3 -3
  60. package/lib/intervals/interval.js.map +1 -1
  61. package/lib/intervals/intervalUtils.d.ts +9 -6
  62. package/lib/intervals/intervalUtils.d.ts.map +1 -1
  63. package/lib/intervals/intervalUtils.js.map +1 -1
  64. package/lib/intervals/sequenceInterval.d.ts +1 -2
  65. package/lib/intervals/sequenceInterval.d.ts.map +1 -1
  66. package/lib/intervals/sequenceInterval.js +4 -4
  67. package/lib/intervals/sequenceInterval.js.map +1 -1
  68. package/lib/packageVersion.d.ts +1 -1
  69. package/lib/packageVersion.js +1 -1
  70. package/lib/packageVersion.js.map +1 -1
  71. package/lib/revertibles.d.ts.map +1 -1
  72. package/lib/revertibles.js +1 -2
  73. package/lib/revertibles.js.map +1 -1
  74. package/lib/sharedSequence.d.ts +1 -1
  75. package/lib/sharedSequence.d.ts.map +1 -1
  76. package/lib/sharedSequence.js +4 -11
  77. package/lib/sharedSequence.js.map +1 -1
  78. package/lib/sharedString.d.ts.map +1 -1
  79. package/lib/sharedString.js +4 -20
  80. package/lib/sharedString.js.map +1 -1
  81. package/package.json +20 -20
  82. package/src/index.ts +3 -3
  83. package/src/intervalCollection.ts +6 -77
  84. package/src/intervalCollectionMapInterfaces.ts +2 -2
  85. package/src/intervalIndex/overlappingIntervalsIndex.ts +5 -2
  86. package/src/intervals/interval.ts +8 -3
  87. package/src/intervals/intervalUtils.ts +12 -6
  88. package/src/intervals/sequenceInterval.ts +9 -5
  89. package/src/packageVersion.ts +1 -1
  90. package/src/revertibles.ts +2 -1
  91. package/src/sharedSequence.ts +7 -11
  92. package/src/sharedString.ts +12 -24
@@ -26,6 +26,9 @@ import {
26
26
  getSlideToSegoff,
27
27
  refTypeIncludesFlag,
28
28
  reservedRangeLabelsKey,
29
+ Side,
30
+ SequencePlace,
31
+ endpointPosAndSide,
29
32
  } from "@fluidframework/merge-tree/internal";
30
33
  import { LoggingError, UsageError } from "@fluidframework/telemetry-utils/internal";
31
34
  import { v4 as uuid } from "uuid";
@@ -65,58 +68,6 @@ import {
65
68
  startReferenceSlidingPreference,
66
69
  } from "./intervals/index.js";
67
70
 
68
- /**
69
- * Defines a position and side relative to a character in a sequence.
70
- *
71
- * For this purpose, sequences look like:
72
- *
73
- * `{start} - {character 0} - {character 1} - ... - {character N} - {end}`
74
- *
75
- * Each `{value}` in the diagram is a character within a sequence.
76
- * Each `-` in the above diagram is a position where text could be inserted.
77
- * Each position between a `{value}` and a `-` is a `SequencePlace`.
78
- *
79
- * The special endpoints `{start}` and `{end}` refer to positions outside the
80
- * contents of the string.
81
- *
82
- * This gives us 2N + 2 possible positions to refer to within a string, where N
83
- * is the number of characters.
84
- *
85
- * If the position is specified with a bare number, the side defaults to
86
- * `Side.Before`.
87
- *
88
- * If a SequencePlace is the endpoint of a range (e.g. start/end of an interval or search range),
89
- * the Side value means it is exclusive if it is nearer to the other position and inclusive if it is farther.
90
- * E.g. the start of a range with Side.After is exclusive of the character at the position.
91
- * @legacy
92
- * @alpha
93
- */
94
- export type SequencePlace = number | "start" | "end" | InteriorSequencePlace;
95
-
96
- /**
97
- * A sequence place that does not refer to the special endpoint segments.
98
- *
99
- * See {@link SequencePlace} for additional context.
100
- * @legacy
101
- * @alpha
102
- */
103
- export interface InteriorSequencePlace {
104
- pos: number;
105
- side: Side;
106
- }
107
-
108
- /**
109
- * Defines a side relative to a character in a sequence.
110
- *
111
- * @remarks See {@link SequencePlace} for additional context on usage.
112
- * @legacy
113
- * @alpha
114
- */
115
- export enum Side {
116
- Before = 0,
117
- After = 1,
118
- }
119
-
120
71
  export const reservedIntervalIdKey = "intervalId";
121
72
 
122
73
  export interface ISerializedIntervalCollectionV2 {
@@ -179,28 +130,6 @@ function compressInterval(interval: ISerializedInterval): CompressedSerializedIn
179
130
  return base;
180
131
  }
181
132
 
182
- export function endpointPosAndSide(
183
- start: SequencePlace | undefined,
184
- end: SequencePlace | undefined,
185
- ) {
186
- const startIsPlainEndpoint =
187
- typeof start === "number" || start === "start" || start === "end";
188
- const endIsPlainEndpoint = typeof end === "number" || end === "start" || end === "end";
189
-
190
- const startSide = startIsPlainEndpoint ? Side.Before : start?.side;
191
- const endSide = endIsPlainEndpoint ? Side.Before : end?.side;
192
-
193
- const startPos = startIsPlainEndpoint ? start : start?.pos;
194
- const endPos = endIsPlainEndpoint ? end : end?.pos;
195
-
196
- return {
197
- startSide,
198
- endSide,
199
- startPos,
200
- endPos,
201
- };
202
- }
203
-
204
133
  export function toSequencePlace(
205
134
  pos: number | "start" | "end",
206
135
  side: Side | undefined,
@@ -375,7 +304,7 @@ export class LocalIntervalCollection<TInterval extends ISerializableInterval> {
375
304
  "Adding an interval that belongs to another interval collection is not permitted",
376
305
  );
377
306
  }
378
- interval.addProperties(props);
307
+ interval.properties = addProperties(interval.properties, props);
379
308
  }
380
309
  interval.properties[reservedIntervalIdKey] ??= uuid();
381
310
  this.add(interval);
@@ -816,7 +745,7 @@ export interface IIntervalCollection<TInterval extends ISerializableInterval>
816
745
  * it is possible to control whether the interval expands to include content
817
746
  * inserted at its start or end.
818
747
  *
819
- * See {@link SequencePlace} for more details on the model.
748
+ * See {@link @fluidframework/merge-tree#SequencePlace} for more details on the model.
820
749
  *
821
750
  * @example
822
751
  *
@@ -1189,7 +1118,7 @@ export class IntervalCollection<TInterval extends ISerializableInterval>
1189
1118
  this.options.mergeTreeReferencesCanSlideToEndpoint,
1190
1119
  );
1191
1120
  if (properties) {
1192
- interval.addProperties(properties);
1121
+ interval.properties = addProperties(interval.properties, properties);
1193
1122
  }
1194
1123
  this.localCollection.add(interval);
1195
1124
  }
@@ -71,10 +71,10 @@ export interface SequenceOptions
71
71
  > {
72
72
  /**
73
73
  * Enable the ability to use interval APIs that rely on positions before and
74
- * after individual characters, referred to as "sides". See {@link SequencePlace}
74
+ * after individual characters, referred to as "sides". See {@link @fluidframework/merge-tree#SequencePlace}
75
75
  * for additional context.
76
76
  *
77
- * This flag must be enabled to pass instances of {@link SequencePlace} to
77
+ * This flag must be enabled to pass instances of {@link @fluidframework/merge-tree#SequencePlace} to
78
78
  * any IIntervalCollection API.
79
79
  *
80
80
  * Also see the feature flag `mergeTreeReferencesCanSlideToEndpoint` to allow
@@ -5,9 +5,12 @@
5
5
 
6
6
  /* eslint-disable import/no-deprecated */
7
7
 
8
- import { Client } from "@fluidframework/merge-tree/internal";
8
+ import {
9
+ Client,
10
+ SequencePlace,
11
+ endpointPosAndSide,
12
+ } from "@fluidframework/merge-tree/internal";
9
13
 
10
- import { SequencePlace, endpointPosAndSide } from "../intervalCollection.js";
11
14
  import { IntervalNode, IntervalTree } from "../intervalTree.js";
12
15
  import {
13
16
  IIntervalHelpers,
@@ -12,10 +12,12 @@ import {
12
12
  PropertySet,
13
13
  createMap,
14
14
  reservedRangeLabelsKey,
15
+ SequencePlace,
16
+ addProperties,
15
17
  } from "@fluidframework/merge-tree/internal";
16
18
  import { UsageError } from "@fluidframework/telemetry-utils/internal";
17
19
 
18
- import { SequencePlace, reservedIntervalIdKey } from "../intervalCollection.js";
20
+ import { reservedIntervalIdKey } from "../intervalCollection.js";
19
21
 
20
22
  import {
21
23
  IIntervalHelpers,
@@ -47,7 +49,7 @@ export class Interval implements ISerializableInterval {
47
49
  props?: PropertySet,
48
50
  ) {
49
51
  if (props) {
50
- this.addProperties(props);
52
+ this.properties = addProperties(this.properties, props);
51
53
  }
52
54
  }
53
55
 
@@ -93,7 +95,10 @@ export class Interval implements ISerializableInterval {
93
95
  start: this.start,
94
96
  };
95
97
  if (this.properties) {
96
- serializedInterval.properties = { ...this.properties };
98
+ serializedInterval.properties = addProperties(
99
+ serializedInterval.properties,
100
+ this.properties,
101
+ );
97
102
  }
98
103
  return serializedInterval;
99
104
  }
@@ -9,13 +9,14 @@ import { ISequencedDocumentMessage } from "@fluidframework/driver-definitions/in
9
9
  import {
10
10
  // eslint-disable-next-line import/no-deprecated
11
11
  Client,
12
+ // eslint-disable-next-line import/no-deprecated
12
13
  PropertiesManager,
13
14
  PropertySet,
14
15
  SlidingPreference,
16
+ SequencePlace,
17
+ Side,
15
18
  } from "@fluidframework/merge-tree/internal";
16
19
 
17
- import { SequencePlace, Side } from "../intervalCollection.js";
18
-
19
20
  /**
20
21
  * Basic interval abstraction
21
22
  * @legacy
@@ -159,11 +160,16 @@ export interface ISerializedInterval {
159
160
  export interface ISerializableInterval extends IInterval {
160
161
  /** Serializable bag of properties associated with the interval. */
161
162
  properties: PropertySet;
162
- /***/
163
+ /**
164
+ * @deprecated - This property should not be used externally and will be removed in a subsequent release.
165
+ */
166
+ // eslint-disable-next-line import/no-deprecated
163
167
  propertyManager: PropertiesManager;
164
168
  /***/
165
169
  serialize(): ISerializedInterval;
166
- /***/
170
+ /**
171
+ * @deprecated - This function should not be used externally and will be removed in a subsequent release.
172
+ */
167
173
  addProperties(
168
174
  props: PropertySet,
169
175
  collaborating?: boolean,
@@ -235,9 +241,9 @@ export interface IIntervalHelpers<TInterval extends ISerializableInterval> {
235
241
  * @param op - If this create came from a remote client, op that created it. Default is undefined (i.e. local)
236
242
  * @param fromSnapshot - If this create came from loading a snapshot. Default is false.
237
243
  * @param startSide - The side on which the start position lays. See
238
- * {@link SequencePlace} for additional context
244
+ * {@link @fluidframework/merge-tree#SequencePlace} for additional context
239
245
  * @param endSide - The side on which the end position lays. See
240
- * {@link SequencePlace} for additional context
246
+ * {@link @fluidframework/merge-tree#SequencePlace} for additional context
241
247
  */
242
248
  create(
243
249
  label: string,
@@ -24,14 +24,15 @@ import {
24
24
  minReferencePosition,
25
25
  refTypeIncludesFlag,
26
26
  reservedRangeLabelsKey,
27
+ SequencePlace,
28
+ Side,
29
+ endpointPosAndSide,
30
+ addProperties,
27
31
  } from "@fluidframework/merge-tree/internal";
28
32
  import { UsageError } from "@fluidframework/telemetry-utils/internal";
29
33
 
30
34
  import {
31
- SequencePlace,
32
- Side,
33
35
  computeStickinessFromSide,
34
- endpointPosAndSide,
35
36
  reservedIntervalIdKey,
36
37
  sidesFromStickiness,
37
38
  } from "../intervalCollection.js";
@@ -144,7 +145,7 @@ export class SequenceInterval implements ISerializableInterval {
144
145
  public readonly endSide: Side = Side.Before,
145
146
  ) {
146
147
  if (props) {
147
- this.addProperties(props);
148
+ this.properties = addProperties(this.properties, props);
148
149
  }
149
150
  }
150
151
 
@@ -199,7 +200,10 @@ export class SequenceInterval implements ISerializableInterval {
199
200
  };
200
201
 
201
202
  if (this.properties) {
202
- serializedInterval.properties = { ...this.properties };
203
+ serializedInterval.properties = addProperties(
204
+ serializedInterval.properties,
205
+ this.properties,
206
+ );
203
207
  }
204
208
 
205
209
  return serializedInterval;
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/sequence";
9
- export const pkgVersion = "2.1.1";
9
+ export const pkgVersion = "2.2.1";
@@ -21,9 +21,10 @@ import {
21
21
  isMergeTreeDeltaRevertible,
22
22
  refTypeIncludesFlag,
23
23
  revertMergeTreeDeltaRevertibles,
24
+ InteriorSequencePlace,
25
+ Side,
24
26
  } from "@fluidframework/merge-tree/internal";
25
27
 
26
- import { InteriorSequencePlace, Side } from "./intervalCollection.js";
27
28
  import { IntervalOpType, SequenceInterval } from "./intervals/index.js";
28
29
  import { ISequenceDeltaRange, SequenceDeltaEvent } from "./sequenceDeltaEvent.js";
29
30
  import { ISharedString, SharedStringSegment } from "./sharedString.js";
@@ -39,19 +39,18 @@ export class SubSequence<T> extends BaseSegment {
39
39
  }
40
40
  public static fromJSONObject<U>(spec: any) {
41
41
  if (spec && typeof spec === "object" && "items" in spec) {
42
- const segment = new SubSequence<U>(spec.items);
43
- if (spec.props) {
44
- segment.addProperties(spec.props);
45
- }
46
- return segment;
42
+ return new SubSequence<U>(spec.items, spec.props);
47
43
  }
48
44
  return undefined;
49
45
  }
50
46
 
51
47
  public readonly type = SubSequence.typeString;
52
48
 
53
- constructor(public items: Serializable<T>[]) {
54
- super();
49
+ constructor(
50
+ public items: Serializable<T>[],
51
+ props?: PropertySet,
52
+ ) {
53
+ super(props);
55
54
  this.cachedLength = items.length;
56
55
  }
57
56
 
@@ -135,10 +134,7 @@ export class SharedSequence<T> extends SharedSegmentSequence<SubSequence<T>> {
135
134
  * @param props - Optional. Properties to set on the inserted items.
136
135
  */
137
136
  public insert(pos: number, items: Serializable<T>[], props?: PropertySet) {
138
- const segment = new SubSequence<T>(items);
139
- if (props) {
140
- segment.addProperties(props);
141
- }
137
+ const segment = new SubSequence<T>(items, props);
142
138
  this.client.insertSegmentLocal(pos, segment);
143
139
  }
144
140
 
@@ -170,25 +170,19 @@ export class SharedStringClass
170
170
  refType: ReferenceType,
171
171
  props?: PropertySet,
172
172
  ): void {
173
- const segment = new Marker(refType);
174
- if (props) {
175
- segment.addProperties(props);
176
- }
177
-
178
173
  const pos = this.posFromRelativePos(relativePos1);
179
- this.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));
174
+ this.guardReentrancy(() =>
175
+ this.client.insertSegmentLocal(pos, Marker.make(refType, props)),
176
+ );
180
177
  }
181
178
 
182
179
  /**
183
180
  * {@inheritDoc ISharedString.insertMarker}
184
181
  */
185
182
  public insertMarker(pos: number, refType: ReferenceType, props?: PropertySet): void {
186
- const segment = new Marker(refType);
187
- if (props) {
188
- segment.addProperties(props);
189
- }
190
-
191
- this.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));
183
+ this.guardReentrancy(() =>
184
+ this.client.insertSegmentLocal(pos, Marker.make(refType, props)),
185
+ );
192
186
  }
193
187
 
194
188
  /**
@@ -199,25 +193,19 @@ export class SharedStringClass
199
193
  text: string,
200
194
  props?: PropertySet,
201
195
  ): void {
202
- const segment = new TextSegment(text);
203
- if (props) {
204
- segment.addProperties(props);
205
- }
206
-
207
196
  const pos = this.posFromRelativePos(relativePos1);
208
- this.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));
197
+ this.guardReentrancy(() =>
198
+ this.client.insertSegmentLocal(pos, TextSegment.make(text, props)),
199
+ );
209
200
  }
210
201
 
211
202
  /**
212
203
  * {@inheritDoc ISharedString.insertText}
213
204
  */
214
205
  public insertText(pos: number, text: string, props?: PropertySet): void {
215
- const segment = new TextSegment(text);
216
- if (props) {
217
- segment.addProperties(props);
218
- }
219
-
220
- this.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));
206
+ this.guardReentrancy(() =>
207
+ this.client.insertSegmentLocal(pos, TextSegment.make(text, props)),
208
+ );
221
209
  }
222
210
 
223
211
  /**