@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
package/src/intervalTree.ts
CHANGED
|
@@ -4,18 +4,18 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
IIntegerRange,
|
|
8
|
+
RBNode,
|
|
9
|
+
IRBAugmentation,
|
|
10
|
+
IRBMatcher,
|
|
11
|
+
RedBlackTree,
|
|
12
|
+
ConflictAction,
|
|
13
|
+
RBNodeActions,
|
|
14
14
|
} from "@fluidframework/merge-tree";
|
|
15
15
|
import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
|
|
16
16
|
|
|
17
17
|
export interface AugmentedIntervalNode {
|
|
18
|
-
|
|
18
|
+
minmax: IInterval;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export const integerRangeToString = (range: IIntegerRange) => `[${range.start},${range.end})`;
|
|
@@ -24,53 +24,53 @@ export const integerRangeToString = (range: IIntegerRange) => `[${range.start},$
|
|
|
24
24
|
* Basic interval abstraction
|
|
25
25
|
*/
|
|
26
26
|
export interface IInterval {
|
|
27
|
-
|
|
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
|
-
|
|
27
|
+
/**
|
|
28
|
+
* @returns a new interval object with identical semantics.
|
|
29
|
+
*/
|
|
30
|
+
clone(): IInterval;
|
|
31
|
+
/**
|
|
32
|
+
* Compares this interval to `b` with standard comparator semantics:
|
|
33
|
+
* - returns -1 if this is less than `b`
|
|
34
|
+
* - returns 1 if this is greater than `b`
|
|
35
|
+
* - returns 0 if this is equivalent to `b`
|
|
36
|
+
* @param b - Interval to compare against
|
|
37
|
+
*/
|
|
38
|
+
compare(b: IInterval): number;
|
|
39
|
+
/**
|
|
40
|
+
* Compares the start endpoint of this interval to `b`'s start endpoint.
|
|
41
|
+
* Standard comparator semantics apply.
|
|
42
|
+
* @param b - Interval to compare against
|
|
43
|
+
*/
|
|
44
|
+
compareStart(b: IInterval): number;
|
|
45
|
+
/**
|
|
46
|
+
* Compares the end endpoint of this interval to `b`'s end endpoint.
|
|
47
|
+
* Standard comparator semantics apply.
|
|
48
|
+
* @param b - Interval to compare against
|
|
49
|
+
*/
|
|
50
|
+
compareEnd(b: IInterval): number;
|
|
51
|
+
/**
|
|
52
|
+
* Modifies one or more of the endpoints of this interval, returning a new interval representing the result.
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
modify(
|
|
56
|
+
label: string,
|
|
57
|
+
start: number | undefined,
|
|
58
|
+
end: number | undefined,
|
|
59
|
+
op?: ISequencedDocumentMessage,
|
|
60
|
+
localSeq?: number,
|
|
61
|
+
): IInterval | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* @returns whether this interval overlaps with `b`.
|
|
64
|
+
* Since intervals are inclusive, this includes cases where endpoints are equal.
|
|
65
|
+
*/
|
|
66
|
+
overlaps(b: IInterval): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Unions this interval with `b`, returning a new interval.
|
|
69
|
+
* The union operates as a convex hull, i.e. if the two intervals are disjoint, the return value includes
|
|
70
|
+
* intermediate values between the two intervals.
|
|
71
|
+
* @internal
|
|
72
|
+
*/
|
|
73
|
+
union(b: IInterval): IInterval;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
const intervalComparer = (a: IInterval, b: IInterval) => a.compare(b);
|
|
@@ -79,88 +79,88 @@ export type IntervalNode<T extends IInterval> = RBNode<T, AugmentedIntervalNode>
|
|
|
79
79
|
|
|
80
80
|
export type IntervalConflictResolver<TInterval> = (a: TInterval, b: TInterval) => TInterval;
|
|
81
81
|
|
|
82
|
-
export class IntervalTree<T extends IInterval>
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
82
|
+
export class IntervalTree<T extends IInterval>
|
|
83
|
+
implements IRBAugmentation<T, AugmentedIntervalNode>, IRBMatcher<T, AugmentedIntervalNode>
|
|
84
|
+
{
|
|
85
|
+
public intervals = new RedBlackTree<T, AugmentedIntervalNode>(intervalComparer, this);
|
|
86
|
+
|
|
87
|
+
public remove(x: T) {
|
|
88
|
+
this.intervals.remove(x);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
public removeExisting(x: T) {
|
|
92
|
+
this.intervals.removeExisting(x);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public put(x: T, conflict?: IntervalConflictResolver<T>) {
|
|
96
|
+
let rbConflict: ConflictAction<T, AugmentedIntervalNode> | undefined;
|
|
97
|
+
if (conflict) {
|
|
98
|
+
rbConflict = (key: T, currentKey: T) => {
|
|
99
|
+
const ival = conflict(key, currentKey);
|
|
100
|
+
return {
|
|
101
|
+
key: ival,
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
this.intervals.put(x, { minmax: x.clone() }, rbConflict);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
public map(fn: (x: T) => void) {
|
|
109
|
+
const actions: RBNodeActions<T, AugmentedIntervalNode> = {
|
|
110
|
+
infix: (node) => {
|
|
111
|
+
fn(node.key);
|
|
112
|
+
return true;
|
|
113
|
+
},
|
|
114
|
+
showStructure: true,
|
|
115
|
+
};
|
|
116
|
+
this.intervals.walk(actions);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
public mapUntil(fn: (X: T) => boolean) {
|
|
120
|
+
const actions: RBNodeActions<T, AugmentedIntervalNode> = {
|
|
121
|
+
infix: (node) => {
|
|
122
|
+
return fn(node.key);
|
|
123
|
+
},
|
|
124
|
+
showStructure: true,
|
|
125
|
+
};
|
|
126
|
+
this.intervals.walk(actions);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
public mapBackward(fn: (x: T) => void) {
|
|
130
|
+
const actions: RBNodeActions<T, AugmentedIntervalNode> = {
|
|
131
|
+
infix: (node) => {
|
|
132
|
+
fn(node.key);
|
|
133
|
+
return true;
|
|
134
|
+
},
|
|
135
|
+
showStructure: true,
|
|
136
|
+
};
|
|
137
|
+
this.intervals.walkBackward(actions);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// TODO: toString()
|
|
141
|
+
public match(x: T) {
|
|
142
|
+
return this.intervals.gather(x, this);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
public matchNode(node: IntervalNode<T> | undefined, key: T) {
|
|
146
|
+
return !!node && node.key.overlaps(key);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
public continueSubtree(node: IntervalNode<T> | undefined, key: T) {
|
|
150
|
+
return !!node && node.data.minmax.overlaps(key);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
public update(node: IntervalNode<T>) {
|
|
154
|
+
if (node.left && node.right) {
|
|
155
|
+
node.data.minmax = node.key.union(node.left.data.minmax.union(node.right.data.minmax));
|
|
156
|
+
} else {
|
|
157
|
+
if (node.left) {
|
|
158
|
+
node.data.minmax = node.key.union(node.left.data.minmax);
|
|
159
|
+
} else if (node.right) {
|
|
160
|
+
node.data.minmax = node.key.union(node.right.data.minmax);
|
|
161
|
+
} else {
|
|
162
|
+
node.data.minmax = node.key.clone();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
166
|
}
|
package/src/localValues.ts
CHANGED
|
@@ -4,52 +4,47 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { IFluidHandle } from "@fluidframework/core-interfaces";
|
|
7
|
+
import { IFluidSerializer, serializeHandles } from "@fluidframework/shared-object-base";
|
|
7
8
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
ISerializableValue,
|
|
13
|
-
ISerializedValue,
|
|
14
|
-
IValueOperation,
|
|
15
|
-
IValueType,
|
|
9
|
+
ISerializableValue,
|
|
10
|
+
ISerializedValue,
|
|
11
|
+
IValueOperation,
|
|
12
|
+
IValueType,
|
|
16
13
|
} from "./defaultMapInterfaces";
|
|
17
14
|
|
|
18
15
|
/**
|
|
19
16
|
* A local value to be stored in a container type DDS.
|
|
20
17
|
*/
|
|
21
18
|
export interface ILocalValue<T = any> {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Type indicator of the value stored within.
|
|
21
|
+
*/
|
|
22
|
+
readonly type: string;
|
|
26
23
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
/**
|
|
25
|
+
* The in-memory value stored within.
|
|
26
|
+
*/
|
|
27
|
+
readonly value: T;
|
|
31
28
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
serializer: IFluidSerializer,
|
|
40
|
-
bind: IFluidHandle,
|
|
41
|
-
): ISerializedValue;
|
|
29
|
+
/**
|
|
30
|
+
* Retrieve the serialized form of the value stored within.
|
|
31
|
+
* @param serializer - Data store runtime's serializer
|
|
32
|
+
* @param bind - Container type's handle
|
|
33
|
+
* @returns The serialized form of the contained value
|
|
34
|
+
*/
|
|
35
|
+
makeSerialized(serializer: IFluidSerializer, bind: IFluidHandle): ISerializedValue;
|
|
42
36
|
}
|
|
43
37
|
|
|
44
38
|
export function makeSerializable(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
39
|
+
localValue: ILocalValue,
|
|
40
|
+
serializer: IFluidSerializer,
|
|
41
|
+
bind: IFluidHandle,
|
|
42
|
+
): ISerializableValue {
|
|
43
|
+
const value = localValue.makeSerialized(serializer, bind);
|
|
44
|
+
return {
|
|
45
|
+
type: value.type,
|
|
46
|
+
value: value.value && JSON.parse(value.value),
|
|
47
|
+
};
|
|
53
48
|
}
|
|
54
49
|
|
|
55
50
|
/**
|
|
@@ -58,48 +53,44 @@ export function makeSerializable(
|
|
|
58
53
|
* @alpha
|
|
59
54
|
*/
|
|
60
55
|
export class ValueTypeLocalValue<T> implements ILocalValue<T> {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
56
|
+
/**
|
|
57
|
+
* Create a new ValueTypeLocalValue.
|
|
58
|
+
* @param value - The instance of the value type stored within
|
|
59
|
+
* @param valueType - The type object of the value type stored within
|
|
60
|
+
*/
|
|
61
|
+
constructor(public readonly value: T, private readonly valueType: IValueType<T>) {}
|
|
68
62
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
63
|
+
/**
|
|
64
|
+
* {@inheritDoc ILocalValue."type"}
|
|
65
|
+
*/
|
|
66
|
+
public get type(): string {
|
|
67
|
+
return this.valueType.name;
|
|
68
|
+
}
|
|
75
69
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
): ISerializedValue {
|
|
83
|
-
const storedValueType = this.valueType.factory.store(this.value);
|
|
84
|
-
const value = serializeHandles(storedValueType, serializer, bind);
|
|
70
|
+
/**
|
|
71
|
+
* {@inheritDoc ILocalValue.makeSerialized}
|
|
72
|
+
*/
|
|
73
|
+
public makeSerialized(serializer: IFluidSerializer, bind: IFluidHandle): ISerializedValue {
|
|
74
|
+
const storedValueType = this.valueType.factory.store(this.value);
|
|
75
|
+
const value = serializeHandles(storedValueType, serializer, bind);
|
|
85
76
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
77
|
+
return {
|
|
78
|
+
type: this.type,
|
|
79
|
+
value,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
91
82
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
83
|
+
/**
|
|
84
|
+
* Get the handler for a given op of this value type.
|
|
85
|
+
* @param opName - The name of the operation that needs processing
|
|
86
|
+
* @returns The object which can process the given op
|
|
87
|
+
*/
|
|
88
|
+
public getOpHandler(opName: string): IValueOperation<T> {
|
|
89
|
+
const handler = this.valueType.ops.get(opName);
|
|
90
|
+
if (!handler) {
|
|
91
|
+
throw new Error("Unknown type message");
|
|
92
|
+
}
|
|
102
93
|
|
|
103
|
-
|
|
104
|
-
|
|
94
|
+
return handler;
|
|
95
|
+
}
|
|
105
96
|
}
|
package/src/packageVersion.ts
CHANGED