@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
@@ -4,18 +4,18 @@
4
4
  */
5
5
 
6
6
  import {
7
- IIntegerRange,
8
- RBNode,
9
- IRBAugmentation,
10
- IRBMatcher,
11
- RedBlackTree,
12
- ConflictAction,
13
- RBNodeActions,
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
- minmax: IInterval;
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
- * @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;
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> implements IRBAugmentation<T, AugmentedIntervalNode>,
83
- IRBMatcher<T, AugmentedIntervalNode> {
84
- public intervals = new RedBlackTree<T, AugmentedIntervalNode>(intervalComparer, this);
85
-
86
- public remove(x: T) {
87
- this.intervals.remove(x);
88
- }
89
-
90
- public removeExisting(x: T) {
91
- this.intervals.removeExisting(x);
92
- }
93
-
94
- public put(x: T, conflict?: IntervalConflictResolver<T>) {
95
- let rbConflict: ConflictAction<T, AugmentedIntervalNode> | undefined;
96
- if (conflict) {
97
- rbConflict = (key: T, currentKey: T) => {
98
- const ival = conflict(key, currentKey);
99
- return {
100
- key: ival,
101
- };
102
- };
103
- }
104
- this.intervals.put(x, { minmax: x.clone() }, rbConflict);
105
- }
106
-
107
- public map(fn: (x: T) => void) {
108
- const actions: RBNodeActions<T, AugmentedIntervalNode> = {
109
- infix: (node) => {
110
- fn(node.key);
111
- return true;
112
- },
113
- showStructure: true,
114
- };
115
- this.intervals.walk(actions);
116
- }
117
-
118
- public mapUntil(fn: (X: T) => boolean) {
119
- const actions: RBNodeActions<T, AugmentedIntervalNode> = {
120
- infix: (node) => {
121
- return fn(node.key);
122
- },
123
- showStructure: true,
124
- };
125
- this.intervals.walk(actions);
126
- }
127
-
128
- public mapBackward(fn: (x: T) => void) {
129
- const actions: RBNodeActions<T, AugmentedIntervalNode> = {
130
- infix: (node) => {
131
- fn(node.key);
132
- return true;
133
- },
134
- showStructure: true,
135
- };
136
- this.intervals.walkBackward(actions);
137
- }
138
-
139
- // TODO: toString()
140
- public match(x: T) {
141
- return this.intervals.gather(x, this);
142
- }
143
-
144
- public matchNode(node: IntervalNode<T> | undefined, key: T) {
145
- return !!node && node.key.overlaps(key);
146
- }
147
-
148
- public continueSubtree(node: IntervalNode<T> | undefined, key: T) {
149
- return !!node && node.data.minmax.overlaps(key);
150
- }
151
-
152
- public update(node: IntervalNode<T>) {
153
- if (node.left && node.right) {
154
- node.data.minmax = node.key.union(
155
- 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
- }
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
  }
@@ -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
- IFluidSerializer,
9
- serializeHandles,
10
- } from "@fluidframework/shared-object-base";
11
- import {
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
- * Type indicator of the value stored within.
24
- */
25
- readonly type: string;
19
+ /**
20
+ * Type indicator of the value stored within.
21
+ */
22
+ readonly type: string;
26
23
 
27
- /**
28
- * The in-memory value stored within.
29
- */
30
- readonly value: T;
24
+ /**
25
+ * The in-memory value stored within.
26
+ */
27
+ readonly value: T;
31
28
 
32
- /**
33
- * Retrieve the serialized form of the value stored within.
34
- * @param serializer - Data store runtime's serializer
35
- * @param bind - Container type's handle
36
- * @returns The serialized form of the contained value
37
- */
38
- makeSerialized(
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
- localValue: ILocalValue,
46
- serializer: IFluidSerializer,
47
- bind: IFluidHandle): ISerializableValue {
48
- const value = localValue.makeSerialized(serializer, bind);
49
- return {
50
- type: value.type,
51
- value: value.value && JSON.parse(value.value),
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
- * Create a new ValueTypeLocalValue.
63
- * @param value - The instance of the value type stored within
64
- * @param valueType - The type object of the value type stored within
65
- */
66
- constructor(public readonly value: T, private readonly valueType: IValueType<T>) {
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
- * {@inheritDoc ILocalValue."type"}
71
- */
72
- public get type(): string {
73
- return this.valueType.name;
74
- }
63
+ /**
64
+ * {@inheritDoc ILocalValue."type"}
65
+ */
66
+ public get type(): string {
67
+ return this.valueType.name;
68
+ }
75
69
 
76
- /**
77
- * {@inheritDoc ILocalValue.makeSerialized}
78
- */
79
- public makeSerialized(
80
- serializer: IFluidSerializer,
81
- bind: IFluidHandle,
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
- return {
87
- type: this.type,
88
- value,
89
- };
90
- }
77
+ return {
78
+ type: this.type,
79
+ value,
80
+ };
81
+ }
91
82
 
92
- /**
93
- * Get the handler for a given op of this value type.
94
- * @param opName - The name of the operation that needs processing
95
- * @returns The object which can process the given op
96
- */
97
- public getOpHandler(opName: string): IValueOperation<T> {
98
- const handler = this.valueType.ops.get(opName);
99
- if (!handler) {
100
- throw new Error("Unknown type message");
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
- return handler;
104
- }
94
+ return handler;
95
+ }
105
96
  }
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/sequence";
9
- export const pkgVersion = "2.0.0-internal.3.0.2";
9
+ export const pkgVersion = "2.0.0-internal.3.2.0";