@fluidframework/sequence 2.0.0-internal.3.0.2 → 2.0.0-internal.3.2.0

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 (94) hide show
  1. package/.eslintrc.js +9 -12
  2. package/.mocharc.js +2 -2
  3. package/.vscode/launch.json +15 -14
  4. package/README.md +188 -179
  5. package/api-extractor.json +2 -2
  6. package/dist/defaultMap.d.ts.map +1 -1
  7. package/dist/defaultMap.js +5 -4
  8. package/dist/defaultMap.js.map +1 -1
  9. package/dist/defaultMapInterfaces.d.ts.map +1 -1
  10. package/dist/defaultMapInterfaces.js.map +1 -1
  11. package/dist/index.d.ts +2 -2
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js.map +1 -1
  14. package/dist/intervalCollection.d.ts.map +1 -1
  15. package/dist/intervalCollection.js +50 -36
  16. package/dist/intervalCollection.js.map +1 -1
  17. package/dist/intervalTree.d.ts.map +1 -1
  18. package/dist/intervalTree.js.map +1 -1
  19. package/dist/localValues.d.ts.map +1 -1
  20. package/dist/localValues.js.map +1 -1
  21. package/dist/packageVersion.d.ts +1 -1
  22. package/dist/packageVersion.js +1 -1
  23. package/dist/packageVersion.js.map +1 -1
  24. package/dist/sequence.d.ts +1 -1
  25. package/dist/sequence.d.ts.map +1 -1
  26. package/dist/sequence.js +13 -17
  27. package/dist/sequence.js.map +1 -1
  28. package/dist/sequenceDeltaEvent.d.ts.map +1 -1
  29. package/dist/sequenceDeltaEvent.js.map +1 -1
  30. package/dist/sequenceFactory.d.ts.map +1 -1
  31. package/dist/sequenceFactory.js.map +1 -1
  32. package/dist/sharedIntervalCollection.d.ts.map +1 -1
  33. package/dist/sharedIntervalCollection.js.map +1 -1
  34. package/dist/sharedSequence.d.ts.map +1 -1
  35. package/dist/sharedSequence.js +3 -3
  36. package/dist/sharedSequence.js.map +1 -1
  37. package/dist/sharedString.d.ts.map +1 -1
  38. package/dist/sharedString.js +5 -4
  39. package/dist/sharedString.js.map +1 -1
  40. package/lib/defaultMap.d.ts.map +1 -1
  41. package/lib/defaultMap.js +6 -5
  42. package/lib/defaultMap.js.map +1 -1
  43. package/lib/defaultMapInterfaces.d.ts.map +1 -1
  44. package/lib/defaultMapInterfaces.js.map +1 -1
  45. package/lib/index.d.ts +2 -2
  46. package/lib/index.d.ts.map +1 -1
  47. package/lib/index.js +2 -2
  48. package/lib/index.js.map +1 -1
  49. package/lib/intervalCollection.d.ts.map +1 -1
  50. package/lib/intervalCollection.js +50 -36
  51. package/lib/intervalCollection.js.map +1 -1
  52. package/lib/intervalTree.d.ts.map +1 -1
  53. package/lib/intervalTree.js.map +1 -1
  54. package/lib/localValues.d.ts.map +1 -1
  55. package/lib/localValues.js +1 -1
  56. package/lib/localValues.js.map +1 -1
  57. package/lib/packageVersion.d.ts +1 -1
  58. package/lib/packageVersion.js +1 -1
  59. package/lib/packageVersion.js.map +1 -1
  60. package/lib/sequence.d.ts +1 -1
  61. package/lib/sequence.d.ts.map +1 -1
  62. package/lib/sequence.js +15 -19
  63. package/lib/sequence.js.map +1 -1
  64. package/lib/sequenceDeltaEvent.d.ts.map +1 -1
  65. package/lib/sequenceDeltaEvent.js.map +1 -1
  66. package/lib/sequenceFactory.d.ts.map +1 -1
  67. package/lib/sequenceFactory.js +1 -1
  68. package/lib/sequenceFactory.js.map +1 -1
  69. package/lib/sharedIntervalCollection.d.ts.map +1 -1
  70. package/lib/sharedIntervalCollection.js.map +1 -1
  71. package/lib/sharedSequence.d.ts.map +1 -1
  72. package/lib/sharedSequence.js +4 -4
  73. package/lib/sharedSequence.js.map +1 -1
  74. package/lib/sharedString.d.ts.map +1 -1
  75. package/lib/sharedString.js +5 -4
  76. package/lib/sharedString.js.map +1 -1
  77. package/package.json +55 -55
  78. package/prettier.config.cjs +1 -1
  79. package/src/defaultMap.ts +406 -405
  80. package/src/defaultMapInterfaces.ts +120 -115
  81. package/src/index.ts +27 -17
  82. package/src/intervalCollection.ts +2198 -1997
  83. package/src/intervalTree.ts +139 -139
  84. package/src/localValues.ts +64 -73
  85. package/src/packageVersion.ts +1 -1
  86. package/src/sequence.ts +739 -694
  87. package/src/sequenceDeltaEvent.ts +143 -137
  88. package/src/sequenceFactory.ts +48 -46
  89. package/src/sharedIntervalCollection.ts +150 -136
  90. package/src/sharedSequence.ts +165 -160
  91. package/src/sharedString.ts +385 -343
  92. package/tsconfig.esnext.json +6 -6
  93. package/tsconfig.json +8 -12
  94. package/.editorconfig +0 -7
@@ -5,16 +5,16 @@
5
5
 
6
6
  import { assert } from "@fluidframework/common-utils";
7
7
  import {
8
- Client,
9
- IMergeTreeDeltaCallbackArgs,
10
- IMergeTreeDeltaOpArgs,
11
- IMergeTreeMaintenanceCallbackArgs,
12
- ISegment,
13
- MergeTreeDeltaOperationType,
14
- MergeTreeDeltaOperationTypes,
15
- MergeTreeMaintenanceType,
16
- PropertySet,
17
- SortedSegmentSet,
8
+ Client,
9
+ IMergeTreeDeltaCallbackArgs,
10
+ IMergeTreeDeltaOpArgs,
11
+ IMergeTreeMaintenanceCallbackArgs,
12
+ ISegment,
13
+ MergeTreeDeltaOperationType,
14
+ MergeTreeDeltaOperationTypes,
15
+ MergeTreeMaintenanceType,
16
+ PropertySet,
17
+ SortedSegmentSet,
18
18
  } from "@fluidframework/merge-tree";
19
19
 
20
20
  /**
@@ -24,71 +24,75 @@ import {
24
24
  * point in time at which the operation was applied.
25
25
  * They will not take into any future modifications performed to the underlying sequence and merge tree.
26
26
  */
27
- export abstract class SequenceEvent<TOperation extends MergeTreeDeltaOperationTypes = MergeTreeDeltaOperationTypes> {
28
- public readonly deltaOperation: TOperation;
29
- private readonly sortedRanges: Lazy<SortedSegmentSet<ISequenceDeltaRange<TOperation>>>;
30
- private readonly pFirst: Lazy<ISequenceDeltaRange<TOperation>>;
31
- private readonly pLast: Lazy<ISequenceDeltaRange<TOperation>>;
32
-
33
- constructor(
34
- public readonly deltaArgs: IMergeTreeDeltaCallbackArgs<TOperation>,
35
- private readonly mergeTreeClient: Client,
36
- ) {
37
- assert(deltaArgs.deltaSegments.length > 0, 0x2d8 /* "Empty change event should not be emitted." */);
38
- this.deltaOperation = deltaArgs.operation;
39
-
40
- this.sortedRanges = new Lazy<SortedSegmentSet<ISequenceDeltaRange<TOperation>>>(
41
- () => {
42
- const set = new SortedSegmentSet<ISequenceDeltaRange<TOperation>>();
43
- this.deltaArgs.deltaSegments.forEach((delta) => {
44
- const newRange: ISequenceDeltaRange<TOperation> = {
45
- operation: this.deltaArgs.operation,
46
- position: this.mergeTreeClient.getPosition(delta.segment),
47
- propertyDeltas: delta.propertyDeltas ?? {},
48
- segment: delta.segment,
49
- };
50
- set.addOrUpdate(newRange);
51
- });
52
- return set;
53
- });
54
-
55
- this.pFirst = new Lazy<ISequenceDeltaRange<TOperation>>(
56
- () => this.sortedRanges.value.items[0],
57
- );
58
-
59
- this.pLast = new Lazy<ISequenceDeltaRange<TOperation>>(
60
- () => this.sortedRanges.value.items[this.sortedRanges.value.size - 1],
61
- );
62
- }
63
-
64
- /**
65
- * The in-order ranges affected by this delta.
66
- * These may not be continuous.
67
- */
68
- public get ranges(): readonly Readonly<ISequenceDeltaRange<TOperation>>[] {
69
- return this.sortedRanges.value.items;
70
- }
71
-
72
- /**
73
- * The client id of the client that made the change which caused the delta event
74
- */
75
- public get clientId(): string | undefined {
76
- return this.mergeTreeClient.longClientId;
77
- }
78
-
79
- /**
80
- * The first of the modified ranges.
81
- */
82
- public get first(): Readonly<ISequenceDeltaRange<TOperation>> {
83
- return this.pFirst.value;
84
- }
85
-
86
- /**
87
- * The last of the modified ranges.
88
- */
89
- public get last(): Readonly<ISequenceDeltaRange<TOperation>> {
90
- return this.pLast.value;
91
- }
27
+ export abstract class SequenceEvent<
28
+ TOperation extends MergeTreeDeltaOperationTypes = MergeTreeDeltaOperationTypes,
29
+ > {
30
+ public readonly deltaOperation: TOperation;
31
+ private readonly sortedRanges: Lazy<SortedSegmentSet<ISequenceDeltaRange<TOperation>>>;
32
+ private readonly pFirst: Lazy<ISequenceDeltaRange<TOperation>>;
33
+ private readonly pLast: Lazy<ISequenceDeltaRange<TOperation>>;
34
+
35
+ constructor(
36
+ public readonly deltaArgs: IMergeTreeDeltaCallbackArgs<TOperation>,
37
+ private readonly mergeTreeClient: Client,
38
+ ) {
39
+ assert(
40
+ deltaArgs.deltaSegments.length > 0,
41
+ 0x2d8 /* "Empty change event should not be emitted." */,
42
+ );
43
+ this.deltaOperation = deltaArgs.operation;
44
+
45
+ this.sortedRanges = new Lazy<SortedSegmentSet<ISequenceDeltaRange<TOperation>>>(() => {
46
+ const set = new SortedSegmentSet<ISequenceDeltaRange<TOperation>>();
47
+ this.deltaArgs.deltaSegments.forEach((delta) => {
48
+ const newRange: ISequenceDeltaRange<TOperation> = {
49
+ operation: this.deltaArgs.operation,
50
+ position: this.mergeTreeClient.getPosition(delta.segment),
51
+ propertyDeltas: delta.propertyDeltas ?? {},
52
+ segment: delta.segment,
53
+ };
54
+ set.addOrUpdate(newRange);
55
+ });
56
+ return set;
57
+ });
58
+
59
+ this.pFirst = new Lazy<ISequenceDeltaRange<TOperation>>(
60
+ () => this.sortedRanges.value.items[0],
61
+ );
62
+
63
+ this.pLast = new Lazy<ISequenceDeltaRange<TOperation>>(
64
+ () => this.sortedRanges.value.items[this.sortedRanges.value.size - 1],
65
+ );
66
+ }
67
+
68
+ /**
69
+ * The in-order ranges affected by this delta.
70
+ * These may not be continuous.
71
+ */
72
+ public get ranges(): readonly Readonly<ISequenceDeltaRange<TOperation>>[] {
73
+ return this.sortedRanges.value.items;
74
+ }
75
+
76
+ /**
77
+ * The client id of the client that made the change which caused the delta event
78
+ */
79
+ public get clientId(): string | undefined {
80
+ return this.mergeTreeClient.longClientId;
81
+ }
82
+
83
+ /**
84
+ * The first of the modified ranges.
85
+ */
86
+ public get first(): Readonly<ISequenceDeltaRange<TOperation>> {
87
+ return this.pFirst.value;
88
+ }
89
+
90
+ /**
91
+ * The last of the modified ranges.
92
+ */
93
+ public get last(): Readonly<ISequenceDeltaRange<TOperation>> {
94
+ return this.pLast.value;
95
+ }
92
96
  }
93
97
 
94
98
  /**
@@ -103,19 +107,19 @@ export abstract class SequenceEvent<TOperation extends MergeTreeDeltaOperationTy
103
107
  * Ops may get multiple events. For instance, an insert-replace will get a remove then an insert event.
104
108
  */
105
109
  export class SequenceDeltaEvent extends SequenceEvent<MergeTreeDeltaOperationType> {
106
- /**
107
- * Whether the event was caused by a locally-made change.
108
- */
109
- public readonly isLocal: boolean;
110
-
111
- constructor(
112
- public readonly opArgs: IMergeTreeDeltaOpArgs,
113
- deltaArgs: IMergeTreeDeltaCallbackArgs,
114
- mergeTreeClient: Client,
115
- ) {
116
- super(deltaArgs, mergeTreeClient);
117
- this.isLocal = opArgs.sequencedMessage === undefined;
118
- }
110
+ /**
111
+ * Whether the event was caused by a locally-made change.
112
+ */
113
+ public readonly isLocal: boolean;
114
+
115
+ constructor(
116
+ public readonly opArgs: IMergeTreeDeltaOpArgs,
117
+ deltaArgs: IMergeTreeDeltaCallbackArgs,
118
+ mergeTreeClient: Client,
119
+ ) {
120
+ super(deltaArgs, mergeTreeClient);
121
+ this.isLocal = opArgs.sequencedMessage === undefined;
122
+ }
119
123
  }
120
124
 
121
125
  /**
@@ -126,61 +130,63 @@ export class SequenceDeltaEvent extends SequenceEvent<MergeTreeDeltaOperationTyp
126
130
  * They will not take into consideration any future modifications performed to the underlying sequence and merge tree.
127
131
  */
128
132
  export class SequenceMaintenanceEvent extends SequenceEvent<MergeTreeMaintenanceType> {
129
- constructor(
130
- public readonly opArgs: IMergeTreeDeltaOpArgs | undefined,
131
- deltaArgs: IMergeTreeMaintenanceCallbackArgs,
132
- mergeTreeClient: Client,
133
- ) {
134
- super(deltaArgs, mergeTreeClient);
135
- }
133
+ constructor(
134
+ public readonly opArgs: IMergeTreeDeltaOpArgs | undefined,
135
+ deltaArgs: IMergeTreeMaintenanceCallbackArgs,
136
+ mergeTreeClient: Client,
137
+ ) {
138
+ super(deltaArgs, mergeTreeClient);
139
+ }
136
140
  }
137
141
 
138
142
  /**
139
143
  * A range that has changed corresponding to a segment modification.
140
144
  */
141
- export interface ISequenceDeltaRange<TOperation extends MergeTreeDeltaOperationTypes = MergeTreeDeltaOperationTypes> {
142
- /**
143
- * The type of operation that changed this range.
144
- * @remarks - Consuming code should typically compare this to the enum values defined in
145
- * `MergeTreeDeltaOperationTypes`.
146
- */
147
- operation: TOperation;
148
- /**
149
- * The index of the start of the range.
150
- */
151
- position: number;
152
- /**
153
- * The segment that corresponds to the range.
154
- */
155
- segment: ISegment;
156
- /**
157
- * Deltas object which contains all modified properties with their previous values.
158
- * Since `undefined` doesn't survive a round-trip through JSON serialization, the old value being absent
159
- * is instead encoded with `null`.
160
- * @remarks - This object is motivated by undo/redo scenarios, and provides a convenient "inverse op" to apply to
161
- * undo a property change.
162
- * @example - If a segment initially had properties `{ foo: "1", bar: 2 }` and it was annotated with
163
- * `{ foo: 3, baz: 5 }`, the corresponding event would have a `propertyDeltas` of `{ foo: "1", baz: null }`.
164
- */
165
- propertyDeltas: PropertySet;
145
+ export interface ISequenceDeltaRange<
146
+ TOperation extends MergeTreeDeltaOperationTypes = MergeTreeDeltaOperationTypes,
147
+ > {
148
+ /**
149
+ * The type of operation that changed this range.
150
+ * @remarks - Consuming code should typically compare this to the enum values defined in
151
+ * `MergeTreeDeltaOperationTypes`.
152
+ */
153
+ operation: TOperation;
154
+ /**
155
+ * The index of the start of the range.
156
+ */
157
+ position: number;
158
+ /**
159
+ * The segment that corresponds to the range.
160
+ */
161
+ segment: ISegment;
162
+ /**
163
+ * Deltas object which contains all modified properties with their previous values.
164
+ * Since `undefined` doesn't survive a round-trip through JSON serialization, the old value being absent
165
+ * is instead encoded with `null`.
166
+ * @remarks - This object is motivated by undo/redo scenarios, and provides a convenient "inverse op" to apply to
167
+ * undo a property change.
168
+ * @example - If a segment initially had properties `{ foo: "1", bar: 2 }` and it was annotated with
169
+ * `{ foo: 3, baz: 5 }`, the corresponding event would have a `propertyDeltas` of `{ foo: "1", baz: null }`.
170
+ */
171
+ propertyDeltas: PropertySet;
166
172
  }
167
173
 
168
174
  class Lazy<T> {
169
- private pValue: T | undefined;
170
- private pEvaluated: boolean;
171
- constructor(private readonly valueGenerator: () => T) {
172
- this.pEvaluated = false;
173
- }
174
-
175
- public get evaluated(): boolean {
176
- return this.pEvaluated;
177
- }
178
-
179
- public get value(): T {
180
- if (!this.pEvaluated) {
181
- this.pEvaluated = true;
182
- this.pValue = this.valueGenerator();
183
- }
184
- return this.pValue as T;
185
- }
175
+ private pValue: T | undefined;
176
+ private pEvaluated: boolean;
177
+ constructor(private readonly valueGenerator: () => T) {
178
+ this.pEvaluated = false;
179
+ }
180
+
181
+ public get evaluated(): boolean {
182
+ return this.pEvaluated;
183
+ }
184
+
185
+ public get value(): T {
186
+ if (!this.pEvaluated) {
187
+ this.pEvaluated = true;
188
+ this.pValue = this.valueGenerator();
189
+ }
190
+ return this.pValue as T;
191
+ }
186
192
  }
@@ -4,63 +4,65 @@
4
4
  */
5
5
 
6
6
  import {
7
- IChannelAttributes,
8
- IFluidDataStoreRuntime,
9
- IChannelServices,
10
- IChannelFactory,
7
+ IChannelAttributes,
8
+ IFluidDataStoreRuntime,
9
+ IChannelServices,
10
+ IChannelFactory,
11
11
  } from "@fluidframework/datastore-definitions";
12
- import {
13
- Marker,
14
- TextSegment,
15
- } from "@fluidframework/merge-tree";
12
+ import { Marker, TextSegment } from "@fluidframework/merge-tree";
16
13
  import { pkgVersion } from "./packageVersion";
17
14
  import { SharedString, SharedStringSegment } from "./sharedString";
18
15
 
19
16
  export class SharedStringFactory implements IChannelFactory {
20
- // TODO rename back to https://graph.microsoft.com/types/mergeTree/string once paparazzi is able to dynamically
21
- // load code
22
- public static Type = "https://graph.microsoft.com/types/mergeTree";
17
+ // TODO rename back to https://graph.microsoft.com/types/mergeTree/string once paparazzi is able to dynamically
18
+ // load code
19
+ public static Type = "https://graph.microsoft.com/types/mergeTree";
23
20
 
24
- public static readonly Attributes: IChannelAttributes = {
25
- type: SharedStringFactory.Type,
26
- snapshotFormatVersion: "0.1",
27
- packageVersion: pkgVersion,
28
- };
21
+ public static readonly Attributes: IChannelAttributes = {
22
+ type: SharedStringFactory.Type,
23
+ snapshotFormatVersion: "0.1",
24
+ packageVersion: pkgVersion,
25
+ };
29
26
 
30
- public static segmentFromSpec(spec: any): SharedStringSegment {
31
- const maybeText = TextSegment.fromJSONObject(spec);
32
- if (maybeText) { return maybeText; }
27
+ public static segmentFromSpec(spec: any): SharedStringSegment {
28
+ const maybeText = TextSegment.fromJSONObject(spec);
29
+ if (maybeText) {
30
+ return maybeText;
31
+ }
33
32
 
34
- const maybeMarker = Marker.fromJSONObject(spec);
35
- if (maybeMarker) { return maybeMarker; }
33
+ const maybeMarker = Marker.fromJSONObject(spec);
34
+ if (maybeMarker) {
35
+ return maybeMarker;
36
+ }
36
37
 
37
- throw new Error(`Unrecognized IJSONObject`);
38
- }
38
+ throw new Error(`Unrecognized IJSONObject`);
39
+ }
39
40
 
40
- public get type() {
41
- return SharedStringFactory.Type;
42
- }
41
+ public get type() {
42
+ return SharedStringFactory.Type;
43
+ }
43
44
 
44
- public get attributes() {
45
- return SharedStringFactory.Attributes;
46
- }
45
+ public get attributes() {
46
+ return SharedStringFactory.Attributes;
47
+ }
47
48
 
48
- /**
49
- * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.load}
50
- */
51
- public async load(
52
- runtime: IFluidDataStoreRuntime,
53
- id: string,
54
- services: IChannelServices,
55
- attributes: IChannelAttributes): Promise<SharedString> {
56
- const sharedString = new SharedString(runtime, id, attributes);
57
- await sharedString.load(services);
58
- return sharedString;
59
- }
49
+ /**
50
+ * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.load}
51
+ */
52
+ public async load(
53
+ runtime: IFluidDataStoreRuntime,
54
+ id: string,
55
+ services: IChannelServices,
56
+ attributes: IChannelAttributes,
57
+ ): Promise<SharedString> {
58
+ const sharedString = new SharedString(runtime, id, attributes);
59
+ await sharedString.load(services);
60
+ return sharedString;
61
+ }
60
62
 
61
- public create(document: IFluidDataStoreRuntime, id: string): SharedString {
62
- const sharedString = new SharedString(document, id, this.attributes);
63
- sharedString.initializeLocal();
64
- return sharedString;
65
- }
63
+ public create(document: IFluidDataStoreRuntime, id: string): SharedString {
64
+ const sharedString = new SharedString(document, id, this.attributes);
65
+ sharedString.initializeLocal();
66
+ return sharedString;
67
+ }
66
68
  }