@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.
- package/.eslintrc.js +9 -12
- package/.mocharc.js +2 -2
- package/.vscode/launch.json +15 -14
- package/README.md +188 -179
- package/api-extractor.json +2 -2
- package/dist/defaultMap.d.ts.map +1 -1
- package/dist/defaultMap.js +5 -4
- package/dist/defaultMap.js.map +1 -1
- package/dist/defaultMapInterfaces.d.ts.map +1 -1
- package/dist/defaultMapInterfaces.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/intervalCollection.d.ts.map +1 -1
- package/dist/intervalCollection.js +50 -36
- package/dist/intervalCollection.js.map +1 -1
- package/dist/intervalTree.d.ts.map +1 -1
- package/dist/intervalTree.js.map +1 -1
- package/dist/localValues.d.ts.map +1 -1
- package/dist/localValues.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/sequence.d.ts +1 -1
- package/dist/sequence.d.ts.map +1 -1
- package/dist/sequence.js +13 -17
- package/dist/sequence.js.map +1 -1
- package/dist/sequenceDeltaEvent.d.ts.map +1 -1
- package/dist/sequenceDeltaEvent.js.map +1 -1
- package/dist/sequenceFactory.d.ts.map +1 -1
- package/dist/sequenceFactory.js.map +1 -1
- package/dist/sharedIntervalCollection.d.ts.map +1 -1
- package/dist/sharedIntervalCollection.js.map +1 -1
- package/dist/sharedSequence.d.ts.map +1 -1
- package/dist/sharedSequence.js +3 -3
- package/dist/sharedSequence.js.map +1 -1
- package/dist/sharedString.d.ts.map +1 -1
- package/dist/sharedString.js +5 -4
- package/dist/sharedString.js.map +1 -1
- package/lib/defaultMap.d.ts.map +1 -1
- package/lib/defaultMap.js +6 -5
- package/lib/defaultMap.js.map +1 -1
- package/lib/defaultMapInterfaces.d.ts.map +1 -1
- package/lib/defaultMapInterfaces.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/lib/intervalCollection.d.ts.map +1 -1
- package/lib/intervalCollection.js +50 -36
- package/lib/intervalCollection.js.map +1 -1
- package/lib/intervalTree.d.ts.map +1 -1
- package/lib/intervalTree.js.map +1 -1
- package/lib/localValues.d.ts.map +1 -1
- package/lib/localValues.js +1 -1
- package/lib/localValues.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/sequence.d.ts +1 -1
- package/lib/sequence.d.ts.map +1 -1
- package/lib/sequence.js +15 -19
- package/lib/sequence.js.map +1 -1
- package/lib/sequenceDeltaEvent.d.ts.map +1 -1
- package/lib/sequenceDeltaEvent.js.map +1 -1
- package/lib/sequenceFactory.d.ts.map +1 -1
- package/lib/sequenceFactory.js +1 -1
- package/lib/sequenceFactory.js.map +1 -1
- package/lib/sharedIntervalCollection.d.ts.map +1 -1
- package/lib/sharedIntervalCollection.js.map +1 -1
- package/lib/sharedSequence.d.ts.map +1 -1
- package/lib/sharedSequence.js +4 -4
- package/lib/sharedSequence.js.map +1 -1
- package/lib/sharedString.d.ts.map +1 -1
- package/lib/sharedString.js +5 -4
- package/lib/sharedString.js.map +1 -1
- package/package.json +55 -55
- package/prettier.config.cjs +1 -1
- package/src/defaultMap.ts +406 -405
- package/src/defaultMapInterfaces.ts +120 -115
- package/src/index.ts +27 -17
- package/src/intervalCollection.ts +2198 -1997
- package/src/intervalTree.ts +139 -139
- package/src/localValues.ts +64 -73
- package/src/packageVersion.ts +1 -1
- package/src/sequence.ts +739 -694
- package/src/sequenceDeltaEvent.ts +143 -137
- package/src/sequenceFactory.ts +48 -46
- package/src/sharedIntervalCollection.ts +150 -136
- package/src/sharedSequence.ts +165 -160
- package/src/sharedString.ts +385 -343
- package/tsconfig.esnext.json +6 -6
- package/tsconfig.json +8 -12
- package/.editorconfig +0 -7
|
@@ -5,16 +5,16 @@
|
|
|
5
5
|
|
|
6
6
|
import { assert } from "@fluidframework/common-utils";
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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<
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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<
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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
|
}
|
package/src/sequenceFactory.ts
CHANGED
|
@@ -4,63 +4,65 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
public static readonly Attributes: IChannelAttributes = {
|
|
22
|
+
type: SharedStringFactory.Type,
|
|
23
|
+
snapshotFormatVersion: "0.1",
|
|
24
|
+
packageVersion: pkgVersion,
|
|
25
|
+
};
|
|
29
26
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
public static segmentFromSpec(spec: any): SharedStringSegment {
|
|
28
|
+
const maybeText = TextSegment.fromJSONObject(spec);
|
|
29
|
+
if (maybeText) {
|
|
30
|
+
return maybeText;
|
|
31
|
+
}
|
|
33
32
|
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
const maybeMarker = Marker.fromJSONObject(spec);
|
|
34
|
+
if (maybeMarker) {
|
|
35
|
+
return maybeMarker;
|
|
36
|
+
}
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
throw new Error(`Unrecognized IJSONObject`);
|
|
39
|
+
}
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
public get type() {
|
|
42
|
+
return SharedStringFactory.Type;
|
|
43
|
+
}
|
|
43
44
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
public get attributes() {
|
|
46
|
+
return SharedStringFactory.Attributes;
|
|
47
|
+
}
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
}
|