@fluidframework/sequence 1.0.0 → 1.1.0-76254
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/README.md +18 -6
- package/dist/defaultMap.d.ts +2 -6
- package/dist/defaultMap.d.ts.map +1 -1
- package/dist/defaultMap.js +27 -37
- package/dist/defaultMap.js.map +1 -1
- package/dist/defaultMapInterfaces.d.ts +24 -3
- 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 +72 -8
- package/dist/intervalCollection.d.ts.map +1 -1
- package/dist/intervalCollection.js +325 -155
- package/dist/intervalCollection.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.d.ts.map +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/sequence.d.ts +4 -5
- package/dist/sequence.d.ts.map +1 -1
- package/dist/sequence.js +11 -15
- package/dist/sequence.js.map +1 -1
- package/dist/sharedIntervalCollection.d.ts.map +1 -1
- package/dist/sharedIntervalCollection.js +1 -1
- package/dist/sharedIntervalCollection.js.map +1 -1
- package/dist/sharedSequence.js.map +1 -1
- package/dist/sparsematrix.js +2 -2
- package/dist/sparsematrix.js.map +1 -1
- package/lib/defaultMap.d.ts +2 -6
- package/lib/defaultMap.d.ts.map +1 -1
- package/lib/defaultMap.js +27 -37
- package/lib/defaultMap.js.map +1 -1
- package/lib/defaultMapInterfaces.d.ts +24 -3
- 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.map +1 -1
- package/lib/intervalCollection.d.ts +72 -8
- package/lib/intervalCollection.d.ts.map +1 -1
- package/lib/intervalCollection.js +325 -155
- package/lib/intervalCollection.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.d.ts.map +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/sequence.d.ts +4 -5
- package/lib/sequence.d.ts.map +1 -1
- package/lib/sequence.js +11 -15
- package/lib/sequence.js.map +1 -1
- package/lib/sharedIntervalCollection.d.ts.map +1 -1
- package/lib/sharedIntervalCollection.js +1 -1
- package/lib/sharedIntervalCollection.js.map +1 -1
- package/lib/sharedSequence.js.map +1 -1
- package/lib/sparsematrix.js +2 -2
- package/lib/sparsematrix.js.map +1 -1
- package/package.json +20 -44
- package/src/defaultMap.ts +39 -41
- package/src/defaultMapInterfaces.ts +28 -3
- package/src/index.ts +3 -0
- package/src/intervalCollection.ts +447 -181
- package/src/packageVersion.ts +1 -1
- package/src/sequence.ts +17 -21
- package/src/sharedIntervalCollection.ts +3 -2
- package/src/sharedSequence.ts +1 -1
- package/src/sparsematrix.ts +2 -2
package/README.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# @fluidframework/sequence
|
|
2
2
|
|
|
3
|
-
The **@fluidframework/sequence** packages supports distributed data structures which are list-like.
|
|
4
|
-
SharedString for storing and simultaneously editing a sequence of text.
|
|
5
|
-
DDS but it has additional specialized features and behaviors for working with text.
|
|
3
|
+
The **@fluidframework/sequence** packages supports distributed data structures which are list-like.
|
|
4
|
+
It includes [SharedString]({{< relref "string.md" >}}) for storing and simultaneously editing a sequence of text.
|
|
5
|
+
Note that SharedString is a sequence DDS but it has additional specialized features and behaviors for working with text.
|
|
6
6
|
|
|
7
|
-
Sequence DDSes share a common base class, SharedSegmentSequence
|
|
8
|
-
*sequence*
|
|
7
|
+
Sequence DDSes share a common base class, `SharedSegmentSequence`.
|
|
8
|
+
For the remainder of this document, the term *sequence* will refer to this base class.
|
|
9
9
|
|
|
10
|
-
*Item*s are the individual units that are stored within the sequence (e.g. in a SharedString the items are characters),
|
|
10
|
+
*Item*s are the individual units that are stored within the sequence (e.g. in a SharedString, the items are characters),
|
|
11
11
|
but regardless of the type of data stored in the sequence, every item in a sequence is at a specific *position* starting
|
|
12
12
|
at 0, similar to an array. However, sequences differ from arrays in that the positions can move as local and remote
|
|
13
13
|
editors make modifications to the sequence.
|
|
@@ -46,6 +46,8 @@ farther position is closer to the length. -->
|
|
|
46
46
|
Sequences support three basic operations: insert, remove, and annotate. Insert and remove are used to add and remove
|
|
47
47
|
items from the sequence, while annotate is used to add metadata to items.
|
|
48
48
|
|
|
49
|
+
### Insert
|
|
50
|
+
|
|
49
51
|
Insert operations on the sequence take a single position argument along with the content. This position is inclusive and
|
|
50
52
|
can be any position in the sequence including 0, to insert at the beginning of the sequence, and the length of the
|
|
51
53
|
sequence, to insert at the end.
|
|
@@ -74,6 +76,8 @@ sequence, to insert at the end.
|
|
|
74
76
|
// positions: 012345678
|
|
75
77
|
```
|
|
76
78
|
|
|
79
|
+
### Remove
|
|
80
|
+
|
|
77
81
|
Remove operations take a start and an end position, referred to as a *range*. The start position is inclusive and can be
|
|
78
82
|
any position in the sequence from 0 to its `length - 1`. The start position cannot be the length of the sequence like it
|
|
79
83
|
can in insert, because there is nothing at that position. The end position is exclusive and must be greater than the
|
|
@@ -94,6 +98,8 @@ start, so it can be any value from 1 to *n* (where *n* is the length of the sequ
|
|
|
94
98
|
// positions:
|
|
95
99
|
```
|
|
96
100
|
|
|
101
|
+
### Annotate
|
|
102
|
+
|
|
97
103
|
Annotate operations can add or remove map-like properties to or from items in the sequence. They can store any JSON
|
|
98
104
|
serializable data and have the same merge behavior as a [SharedMap][] (last writer wins). Annotate takes a start and end
|
|
99
105
|
position which work the same way as the start and end of the remove operation. In addition to start and end, annotate
|
|
@@ -137,6 +143,8 @@ specified range. Setting a property key to null will remove that property from t
|
|
|
137
143
|
// props5 = { decoration: "underline" }
|
|
138
144
|
```
|
|
139
145
|
|
|
146
|
+
### Sequence delta event
|
|
147
|
+
|
|
140
148
|
Whenever an operation is performed on a sequence a *sequenceDelta* event will be raised. This event provides the ranges
|
|
141
149
|
affected by the operation, the type of the operation, and the properties that were changes by the operation.
|
|
142
150
|
|
|
@@ -147,6 +155,8 @@ final state. However, the intermediate states seen by each collaborator may not
|
|
|
147
155
|
intermediate states occur when two or more collaborators modify the same position in the sequence which results in a
|
|
148
156
|
conflict.
|
|
149
157
|
|
|
158
|
+
### Merge strategy for insert
|
|
159
|
+
|
|
150
160
|
Consider a sequence like this:
|
|
151
161
|
|
|
152
162
|
```bash
|
|
@@ -229,6 +239,8 @@ Another way to consider this behavior is that a remove operation will only remov
|
|
|
229
239
|
the order. Anything inserted after a remove operation will be ignored. The sequence also detects overlapping remove
|
|
230
240
|
operations, and the merge resolution is straightforward -- the data is removed.
|
|
231
241
|
|
|
242
|
+
### Merge strategy for annotate
|
|
243
|
+
|
|
232
244
|
As mentioned above, annotate operations behave like operations on SharedMaps. The merge strategy used is last writer
|
|
233
245
|
wins. If two collaborators set the same key on the annotate properties the operation that gets ordered last will
|
|
234
246
|
determine the value.
|
package/dist/defaultMap.d.ts
CHANGED
|
@@ -6,10 +6,7 @@ import { IFluidHandle } from "@fluidframework/core-interfaces";
|
|
|
6
6
|
import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
|
|
7
7
|
import { IFluidSerializer } from "@fluidframework/shared-object-base";
|
|
8
8
|
import { TypedEventEmitter } from "@fluidframework/common-utils";
|
|
9
|
-
import { ISerializableValue, ISerializedValue, IValueType, IValueTypeOperationValue, ISharedDefaultMapEvents } from "./defaultMapInterfaces";
|
|
10
|
-
export interface IMapMessageLocalMetadata {
|
|
11
|
-
lastProcessedSeq: number;
|
|
12
|
-
}
|
|
9
|
+
import { ISerializableValue, ISerializedValue, IValueType, IValueTypeOperationValue, ISharedDefaultMapEvents, IMapMessageLocalMetadata } from "./defaultMapInterfaces";
|
|
13
10
|
/**
|
|
14
11
|
* Describes an operation specific to a value type.
|
|
15
12
|
*/
|
|
@@ -67,7 +64,6 @@ export declare class DefaultMap<T> {
|
|
|
67
64
|
* The in-memory data the map is storing.
|
|
68
65
|
*/
|
|
69
66
|
private readonly data;
|
|
70
|
-
private lastProcessedSeq;
|
|
71
67
|
/**
|
|
72
68
|
* Create a new default map.
|
|
73
69
|
* @param serializer - The serializer to serialize / parse handles
|
|
@@ -134,7 +130,7 @@ export declare class DefaultMap<T> {
|
|
|
134
130
|
* also sent if we are asked to resubmit the message.
|
|
135
131
|
* @returns True if the operation was submitted, false otherwise.
|
|
136
132
|
*/
|
|
137
|
-
|
|
133
|
+
tryResubmitMessage(op: any, localOpMetadata: IMapMessageLocalMetadata): boolean;
|
|
138
134
|
tryGetStashedOpLocalMetadata(op: any): unknown;
|
|
139
135
|
/**
|
|
140
136
|
* Process the given op if a handler is registered.
|
package/dist/defaultMap.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultMap.d.ts","sourceRoot":"","sources":["../src/defaultMap.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AACjF,OAAO,EACH,gBAAgB,EAInB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAU,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAKzE,OAAO,EACH,kBAAkB,EAClB,gBAAgB,EAGhB,UAAU,EACV,wBAAwB,EACxB,uBAAuB,
|
|
1
|
+
{"version":3,"file":"defaultMap.d.ts","sourceRoot":"","sources":["../src/defaultMap.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AACjF,OAAO,EACH,gBAAgB,EAInB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAU,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAKzE,OAAO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IACH,OAAO,CAAC,qBAAqB;CAwBhC"}
|
package/dist/defaultMap.js
CHANGED
|
@@ -38,7 +38,6 @@ class DefaultMap {
|
|
|
38
38
|
* The in-memory data the map is storing.
|
|
39
39
|
*/
|
|
40
40
|
this.data = new Map();
|
|
41
|
-
this.lastProcessedSeq = -1;
|
|
42
41
|
this.messageHandlers = this.getMessageHandlers();
|
|
43
42
|
}
|
|
44
43
|
/**
|
|
@@ -63,13 +62,9 @@ class DefaultMap {
|
|
|
63
62
|
const iterator = {
|
|
64
63
|
next() {
|
|
65
64
|
const nextVal = localEntriesIterator.next();
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
else {
|
|
70
|
-
// Unpack the stored value
|
|
71
|
-
return { value: [nextVal.value[0], nextVal.value[1].value], done: false };
|
|
72
|
-
}
|
|
65
|
+
return nextVal.done
|
|
66
|
+
? { value: undefined, done: true }
|
|
67
|
+
: { value: [nextVal.value[0], nextVal.value[1].value], done: false }; // Unpack the stored value
|
|
73
68
|
},
|
|
74
69
|
[Symbol.iterator]() {
|
|
75
70
|
return this;
|
|
@@ -86,13 +81,9 @@ class DefaultMap {
|
|
|
86
81
|
const iterator = {
|
|
87
82
|
next() {
|
|
88
83
|
const nextVal = localValuesIterator.next();
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
else {
|
|
93
|
-
// Unpack the stored value
|
|
94
|
-
return { value: nextVal.value.value, done: false };
|
|
95
|
-
}
|
|
84
|
+
return nextVal.done
|
|
85
|
+
? { value: undefined, done: true }
|
|
86
|
+
: { value: nextVal.value.value, done: false }; // Unpack the stored value
|
|
96
87
|
},
|
|
97
88
|
[Symbol.iterator]() {
|
|
98
89
|
return this;
|
|
@@ -120,10 +111,8 @@ class DefaultMap {
|
|
|
120
111
|
* {@inheritDoc ISharedMap.get}
|
|
121
112
|
*/
|
|
122
113
|
get(key) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
localValue = this.createCore(key, true);
|
|
126
|
-
}
|
|
114
|
+
var _a;
|
|
115
|
+
const localValue = (_a = this.data.get(key)) !== null && _a !== void 0 ? _a : this.createCore(key, true);
|
|
127
116
|
return localValue.value;
|
|
128
117
|
}
|
|
129
118
|
/**
|
|
@@ -168,8 +157,13 @@ class DefaultMap {
|
|
|
168
157
|
|| serializable.type === shared_object_base_1.ValueType[shared_object_base_1.ValueType.Shared]) {
|
|
169
158
|
continue;
|
|
170
159
|
}
|
|
160
|
+
// Back-compat: Sequence previously arbitrarily prefixed all interval collection keys with
|
|
161
|
+
// "intervalCollections/". This would burden users trying to iterate the collection and
|
|
162
|
+
// access its value, as well as those trying to match a create message to its underlying
|
|
163
|
+
// collection. See https://github.com/microsoft/FluidFramework/issues/10557 for more context.
|
|
164
|
+
const normalizedKey = key.startsWith("intervalCollections/") ? key.substring(20) : key;
|
|
171
165
|
const localValue = {
|
|
172
|
-
key,
|
|
166
|
+
key: normalizedKey,
|
|
173
167
|
value: this.makeLocal(key, serializable),
|
|
174
168
|
};
|
|
175
169
|
this.data.set(localValue.key, localValue.value);
|
|
@@ -186,17 +180,11 @@ class DefaultMap {
|
|
|
186
180
|
* also sent if we are asked to resubmit the message.
|
|
187
181
|
* @returns True if the operation was submitted, false otherwise.
|
|
188
182
|
*/
|
|
189
|
-
|
|
183
|
+
tryResubmitMessage(op, localOpMetadata) {
|
|
190
184
|
const type = op.type;
|
|
191
185
|
const handler = this.messageHandlers.get(type);
|
|
192
186
|
if (handler !== undefined) {
|
|
193
|
-
|
|
194
|
-
// we don't know how to rebase these operations, so if any other op has come in
|
|
195
|
-
// we will fail.
|
|
196
|
-
if (this.lastProcessedSeq !== (mapLocalMetadata === null || mapLocalMetadata === void 0 ? void 0 : mapLocalMetadata.lastProcessedSeq)) {
|
|
197
|
-
throw new Error("SharedInterval does not support reconnect in presence of external changes");
|
|
198
|
-
}
|
|
199
|
-
handler.submit(op);
|
|
187
|
+
handler.resubmit(op, localOpMetadata);
|
|
200
188
|
return true;
|
|
201
189
|
}
|
|
202
190
|
return false;
|
|
@@ -218,9 +206,6 @@ class DefaultMap {
|
|
|
218
206
|
* @returns True if the operation was processed, false otherwise.
|
|
219
207
|
*/
|
|
220
208
|
tryProcessMessage(op, local, message, localOpMetadata) {
|
|
221
|
-
// track the seq of every incoming message, so we can detect if any
|
|
222
|
-
// changes happened during a resubmit
|
|
223
|
-
this.lastProcessedSeq = message.sequenceNumber;
|
|
224
209
|
const handler = this.messageHandlers.get(op.type);
|
|
225
210
|
if (handler !== undefined) {
|
|
226
211
|
handler.process(op, local, message, localOpMetadata);
|
|
@@ -275,12 +260,18 @@ class DefaultMap {
|
|
|
275
260
|
const handler = localValue.getOpHandler(op.value.opName);
|
|
276
261
|
const previousValue = localValue.value;
|
|
277
262
|
const translatedValue = (0, shared_object_base_1.parseHandles)(op.value.value, this.serializer);
|
|
278
|
-
handler.process(previousValue, translatedValue, local, message);
|
|
263
|
+
handler.process(previousValue, translatedValue, local, message, localOpMetadata);
|
|
279
264
|
const event = { key: op.key, previousValue };
|
|
280
265
|
this.eventEmitter.emit("valueChanged", event, local, message, this.eventEmitter);
|
|
281
266
|
},
|
|
282
|
-
submit: (op) => {
|
|
283
|
-
this.submitMessage(op,
|
|
267
|
+
submit: (op, localOpMetadata) => {
|
|
268
|
+
this.submitMessage(op, localOpMetadata);
|
|
269
|
+
},
|
|
270
|
+
resubmit: (op, localOpMetadata) => {
|
|
271
|
+
const localValue = this.data.get(op.key);
|
|
272
|
+
const handler = localValue.getOpHandler(op.value.opName);
|
|
273
|
+
const { rebasedOp, rebasedLocalOpMetadata, } = handler.rebase(localValue.value, op.value, localOpMetadata);
|
|
274
|
+
this.submitMessage(Object.assign(Object.assign({}, op), { value: rebasedOp }), rebasedLocalOpMetadata);
|
|
284
275
|
},
|
|
285
276
|
getStashedOpLocalMetadata: (op) => {
|
|
286
277
|
(0, common_utils_1.assert)(false, 0x016 /* "apply stashed op not implemented for custom value type ops" */);
|
|
@@ -295,7 +286,7 @@ class DefaultMap {
|
|
|
295
286
|
* @returns A value op emitter for the given key
|
|
296
287
|
*/
|
|
297
288
|
makeMapValueOpEmitter(key) {
|
|
298
|
-
const emit = (opName, previousValue, params) => {
|
|
289
|
+
const emit = (opName, previousValue, params, localOpMetadata) => {
|
|
299
290
|
const translatedParams = (0, shared_object_base_1.makeHandlesSerializable)(params, this.serializer, this.handle);
|
|
300
291
|
const op = {
|
|
301
292
|
key,
|
|
@@ -305,8 +296,7 @@ class DefaultMap {
|
|
|
305
296
|
value: translatedParams,
|
|
306
297
|
},
|
|
307
298
|
};
|
|
308
|
-
|
|
309
|
-
this.submitMessage(op, { lastProcessedSeq: this.lastProcessedSeq });
|
|
299
|
+
this.submitMessage(op, localOpMetadata);
|
|
310
300
|
const event = { key, previousValue };
|
|
311
301
|
this.eventEmitter.emit("valueChanged", event, true, null, this.eventEmitter);
|
|
312
302
|
};
|
package/dist/defaultMap.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultMap.js","sourceRoot":"","sources":["../src/defaultMap.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH,2EAK4C;AAC5C,+DAAyE;AACzE,+CAGuB;AAiFvB;;;;;;GAMG;AACH,MAAa,UAAU;IAoBnB;;;;;;;OAOG;IACH,YACqB,UAA4B,EAC5B,MAAoB,EACpB,aAA2E,EAC3E,IAAmB,EACpB,eAAe,IAAI,gCAAiB,EAA2B;QAJ9D,eAAU,GAAV,UAAU,CAAkB;QAC5B,WAAM,GAAN,MAAM,CAAc;QACpB,kBAAa,GAAb,aAAa,CAA8D;QAC3E,SAAI,GAAJ,IAAI,CAAe;QACpB,iBAAY,GAAZ,YAAY,CAAmD;QAzBnF;;WAEG;QACc,oBAAe,GAA4C,IAAI,GAAG,EAAE,CAAC;QAEtF;;WAEG;QACc,SAAI,GAAG,IAAI,GAAG,EAAkC,CAAC;QAE1D,qBAAgB,GAAW,CAAC,CAAC,CAAC;QAiBlC,IAAI,CAAC,eAAe,GAAG,IA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KAAK,CAAC,kEAAkE,CAAC,CAAC;YAC5F,CAAC;SACJ,CAAC,CAAC;QAEP,OAAO,eAAe,CAAC;IAC3B,CAAC;IAED;;;;;OAKG;IACK,qBAAqB,CAAC,GAAW;QACrC,MAAM,IAAI,GAAG,CAAC,MAAc,EAAE,aAAkB,EAAE,MAAW,EAAE,EAAE;YAC7D,MAAM,gBAAgB,GAAG,IAAA,4CAAuB,EAC5C,MAAM,EACN,IAAI,CAAC,UAAU,EACf,IAAI,CAAC,MAAM,CAAC,CAAC;YAEjB,MAAM,EAAE,GAA2B;gBAC/B,GAAG;gBACH,IAAI,EAAE,KAAK;gBACX,KAAK,EAAE;oBACH,MAAM;oBACN,KAAK,EAAE,gBAAgB;iBAC1B;aACJ,CAAC;YACF,6EAA6E;YAC7E,IAAI,CAAC,aAAa,CAAC,EAAE,EAAE,EAAE,gBAAgB,EAAE,IAAI,CAAC,gBAAgB,EAAE,CAAC,CAAC;YAEpE,MAAM,KAAK,GAAkB,EAAE,GAAG,EAAE,aAAa,EAAE,CAAC;YACpD,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,cAAc,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QACjF,CAAC,CAAC;QAEF,OAAO,EAAE,IAAI,EAAE,CAAC;IACpB,CAAC;CACJ;AA3VD,gCA2VC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport {\n IFluidSerializer,\n makeHandlesSerializable,\n parseHandles,\n ValueType,\n} from \"@fluidframework/shared-object-base\";\nimport { assert, TypedEventEmitter } from \"@fluidframework/common-utils\";\nimport {\n makeSerializable,\n ValueTypeLocalValue,\n} from \"./localValues\";\nimport {\n ISerializableValue,\n ISerializedValue,\n IValueChanged,\n IValueOpEmitter,\n IValueType,\n IValueTypeOperationValue,\n ISharedDefaultMapEvents,\n} from \"./defaultMapInterfaces\";\n\n/**\n * Defines the means to process and submit a given op on a map.\n */\ninterface IMapMessageHandler {\n /**\n * Apply the given operation.\n * @param op - The map operation to apply\n * @param local - Whether the message originated from the local client\n * @param message - The full message. Not provided for stashed ops.\n * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n * For messages from a remote client, this will be undefined.\n */\n process(\n op: IMapOperation,\n local: boolean,\n message: ISequencedDocumentMessage | undefined,\n localOpMetadata: IMapMessageLocalMetadata,\n ): void;\n\n /**\n * Communicate the operation to remote clients.\n * @param op - The map operation to submit\n */\n submit(op: IMapOperation): void;\n\n getStashedOpLocalMetadata(op: IMapOperation): unknown;\n}\n\nexport interface IMapMessageLocalMetadata {\n lastProcessedSeq: number;\n}\n\n/**\n * Describes an operation specific to a value type.\n */\nexport interface IMapValueTypeOperation {\n /**\n * String identifier of the operation type.\n */\n type: \"act\";\n\n /**\n * Map key being modified.\n */\n key: string;\n\n /**\n * Value of the operation, specific to the value type.\n * @alpha\n */\n value: IValueTypeOperationValue;\n}\n\n/**\n * Description of a map delta operation\n */\nexport type IMapOperation = IMapValueTypeOperation;\n\n/**\n * Defines the in-memory object structure to be used for the conversion to/from serialized.\n * Directly used in JSON.stringify, direct result from JSON.parse\n */\nexport interface IMapDataObjectSerializable {\n [key: string]: ISerializableValue;\n}\n\nexport interface IMapDataObjectSerialized {\n [key: string]: ISerializedValue;\n}\n\n/**\n * A DefaultMap is a map-like distributed data structure, supporting operations on values stored by\n * string key locations.\n *\n * Creation of values is implicit on access (either via `get` or a remote op application referring to\n * a collection that wasn't previously known)\n */\nexport class DefaultMap<T> {\n /**\n * The number of key/value pairs stored in the map.\n */\n public get size(): number {\n return this.data.size;\n }\n\n /**\n * Mapping of op types to message handlers.\n */\n private readonly messageHandlers: ReadonlyMap<string, IMapMessageHandler> = new Map();\n\n /**\n * The in-memory data the map is storing.\n */\n private readonly data = new Map<string, ValueTypeLocalValue<T>>();\n\n private lastProcessedSeq: number = -1;\n\n /**\n * Create a new default map.\n * @param serializer - The serializer to serialize / parse handles\n * @param handle - The handle of the shared object using the kernel\n * @param submitMessage - A callback to submit a message through the shared object\n * @param type - The value type to create at values of this map\n * @param eventEmitter - The object that will emit map events\n */\n constructor(\n private readonly serializer: IFluidSerializer,\n private readonly handle: IFluidHandle,\n private readonly submitMessage: (op: any, localOpMetadata: IMapMessageLocalMetadata) => void,\n private readonly type: IValueType<T>,\n public readonly eventEmitter = new TypedEventEmitter<ISharedDefaultMapEvents>(),\n ) {\n this.messageHandlers = this.getMessageHandlers();\n }\n\n /**\n * Get an iterator over the keys in this map.\n * @returns The iterator\n */\n public keys(): IterableIterator<string> {\n return this.data.keys();\n }\n\n /**\n * Get an iterator over the entries in this map.\n * @returns The iterator\n */\n public entries(): IterableIterator<[string, any]> {\n const localEntriesIterator = this.data.entries();\n const iterator = {\n next(): IteratorResult<[string, any]> {\n const nextVal = localEntriesIterator.next();\n if (nextVal.done) {\n return { value: undefined, done: true };\n } else {\n // Unpack the stored value\n return { value: [nextVal.value[0], nextVal.value[1].value], done: false };\n }\n },\n [Symbol.iterator]() {\n return this;\n },\n };\n return iterator;\n }\n\n /**\n * Get an iterator over the values in this map.\n * @returns The iterator\n */\n public values(): IterableIterator<any> {\n const localValuesIterator = this.data.values();\n const iterator = {\n next(): IteratorResult<any> {\n const nextVal = localValuesIterator.next();\n if (nextVal.done) {\n return { value: undefined, done: true };\n } else {\n // Unpack the stored value\n return { value: nextVal.value.value, done: false };\n }\n },\n [Symbol.iterator]() {\n return this;\n },\n };\n return iterator;\n }\n\n /**\n * Get an iterator over the entries in this map.\n * @returns The iterator\n */\n public [Symbol.iterator](): IterableIterator<[string, any]> {\n return this.entries();\n }\n\n /**\n * Executes the given callback on each entry in the map.\n * @param callbackFn - Callback function\n */\n public forEach(callbackFn: (value: any, key: string, map: Map<string, any>) => void): void {\n this.data.forEach((localValue, key, m) => {\n callbackFn(localValue.value, key, m);\n });\n }\n\n /**\n * {@inheritDoc ISharedMap.get}\n */\n public get(key: string): T {\n let localValue = this.data.get(key);\n if (!this.data.has(key)) {\n localValue = this.createCore(key, true);\n }\n return localValue.value;\n }\n\n /**\n * Check if a key exists in the map.\n * @param key - The key to check\n * @returns True if the key exists, false otherwise\n */\n public has(key: string): boolean {\n return this.data.has(key);\n }\n\n /**\n * Serializes the data stored in the shared map to a JSON string\n * @param serializer - The serializer to use to serialize handles in its values.\n * @returns A JSON string containing serialized map data\n */\n public getSerializedStorage(serializer: IFluidSerializer): IMapDataObjectSerialized {\n const serializableMapData: IMapDataObjectSerialized = {};\n this.data.forEach((localValue, key) => {\n serializableMapData[key] = localValue.makeSerialized(serializer, this.handle);\n });\n return serializableMapData;\n }\n\n public getSerializableStorage(serializer: IFluidSerializer): IMapDataObjectSerializable {\n const serializableMapData: IMapDataObjectSerializable = {};\n this.data.forEach((localValue, key) => {\n serializableMapData[key] = makeSerializable(localValue, serializer, this.handle);\n });\n return serializableMapData;\n }\n\n public serialize(serializer: IFluidSerializer): string {\n return JSON.stringify(this.getSerializableStorage(serializer));\n }\n\n /**\n * Populate the kernel with the given map data.\n * @param data - A JSON string containing serialized map data\n */\n public populateFromSerializable(json: IMapDataObjectSerializable): void {\n for (const [key, serializable] of Object.entries(json)) {\n // Back-compat: legacy documents may have handles to an intervalCollection map kernel.\n // These collections should be empty, and ValueTypes are no longer supported.\n if (serializable.type === ValueType[ValueType.Plain]\n || serializable.type === ValueType[ValueType.Shared]) {\n continue;\n }\n\n const localValue = {\n key,\n value: this.makeLocal(key, serializable),\n };\n\n this.data.set(localValue.key, localValue.value);\n }\n }\n\n public populate(json: string): void {\n this.populateFromSerializable(JSON.parse(json) as IMapDataObjectSerializable);\n }\n\n /**\n * Submit the given op if a handler is registered.\n * @param op - The operation to attempt to submit\n * @param localOpMetadata - The local metadata associated with the op. This is kept locally by the runtime\n * and not sent to the server. This will be sent back when this message is received back from the server. This is\n * also sent if we are asked to resubmit the message.\n * @returns True if the operation was submitted, false otherwise.\n */\n public trySubmitMessage(op: any, localOpMetadata: IMapMessageLocalMetadata): boolean {\n const type: string = op.type;\n const handler = this.messageHandlers.get(type);\n if (handler !== undefined) {\n const mapLocalMetadata: Partial<IMapMessageLocalMetadata> = localOpMetadata;\n // we don't know how to rebase these operations, so if any other op has come in\n // we will fail.\n if (this.lastProcessedSeq !== mapLocalMetadata?.lastProcessedSeq) {\n throw new Error(\"SharedInterval does not support reconnect in presence of external changes\");\n }\n handler.submit(op as IMapOperation);\n return true;\n }\n return false;\n }\n\n public tryGetStashedOpLocalMetadata(op: any): unknown {\n const type: string = op.type;\n if (this.messageHandlers.has(type)) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return this.messageHandlers.get(type)!.getStashedOpLocalMetadata(op as IMapOperation);\n }\n throw new Error(\"no apply stashed op handler\");\n }\n\n /**\n * Process the given op if a handler is registered.\n * @param message - The message to process\n * @param local - Whether the message originated from the local client\n * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n * For messages from a remote client, this will be undefined.\n * @returns True if the operation was processed, false otherwise.\n */\n public tryProcessMessage(\n op: IMapOperation,\n local: boolean,\n message: ISequencedDocumentMessage | undefined,\n localOpMetadata: unknown,\n ): boolean {\n // track the seq of every incoming message, so we can detect if any\n // changes happened during a resubmit\n this.lastProcessedSeq = message.sequenceNumber;\n const handler = this.messageHandlers.get(op.type);\n if (handler !== undefined) {\n handler.process(op, local, message, localOpMetadata as IMapMessageLocalMetadata);\n return true;\n }\n return false;\n }\n\n /**\n * Initializes a default ValueType at the provided key.\n * Should be used when a map operation incurs creation.\n * @param key - The key being initialized\n * @param local - Whether the message originated from the local client\n */\n private createCore(key: string, local: boolean): ValueTypeLocalValue<T> {\n const localValue = new ValueTypeLocalValue(\n this.type.factory.load(this.makeMapValueOpEmitter(key), undefined),\n this.type,\n );\n const previousValue = this.data.get(key);\n this.data.set(key, localValue);\n const event: IValueChanged = { key, previousValue };\n this.eventEmitter.emit(\"create\", event, local, this.eventEmitter);\n return localValue;\n }\n\n /**\n * The remote ISerializableValue we're receiving (either as a result of a load or an incoming set op) will\n * have the information we need to create a real object, but will not be the real object yet. For example,\n * we might know it's a map and the map's ID but not have the actual map or its data yet. makeLocal's\n * job is to convert that information into a real object for local usage.\n * @param key - The key that the caller intends to store the local value into (used for ops later). But\n * doesn't actually store the local value into that key. So better not lie!\n * @param serializable - The remote information that we can convert into a real object\n * @returns The local value that was produced\n */\n private makeLocal(key: string, serializable: ISerializableValue): ValueTypeLocalValue<T> {\n assert(serializable.type !== ValueType[ValueType.Plain] && serializable.type !== ValueType[ValueType.Shared],\n 0x2e1 /* \"Support for plain value types removed.\" */);\n\n serializable.value = parseHandles(serializable.value, this.serializer);\n const localValue = this.type.factory.load(\n this.makeMapValueOpEmitter(key),\n serializable.value,\n );\n return new ValueTypeLocalValue(localValue, this.type);\n }\n\n /**\n * Get the message handlers for the map.\n * @returns A map of string op names to IMapMessageHandlers for those ops\n */\n private getMessageHandlers() {\n const messageHandlers = new Map<string, IMapMessageHandler>();\n // Ops with type \"act\" describe actions taken by custom value type handlers of whatever item is\n // being addressed. These custom handlers can be retrieved from the ValueTypeLocalValue which has\n // stashed its valueType (and therefore its handlers). We also emit a valueChanged for anyone\n // watching for manipulations of that item.\n messageHandlers.set(\n \"act\",\n {\n process: (op: IMapValueTypeOperation, local, message, localOpMetadata) => {\n const localValue = this.data.get(op.key) ?? this.createCore(op.key, local);\n const handler = localValue.getOpHandler(op.value.opName);\n const previousValue = localValue.value;\n const translatedValue = parseHandles(\n op.value.value,\n this.serializer);\n handler.process(previousValue, translatedValue, local, message);\n const event: IValueChanged = { key: op.key, previousValue };\n this.eventEmitter.emit(\"valueChanged\", event, local, message, this.eventEmitter);\n },\n submit: (op: IMapValueTypeOperation) => {\n this.submitMessage(\n op,\n { lastProcessedSeq: this.lastProcessedSeq },\n );\n },\n getStashedOpLocalMetadata: (op: IMapValueTypeOperation) => {\n assert(false, 0x016 /* \"apply stashed op not implemented for custom value type ops\" */);\n },\n });\n\n return messageHandlers;\n }\n\n /**\n * Create an emitter for a value type to emit ops from the given key.\n * @alpha\n * @param key - The key of the map that the value type will be stored on\n * @returns A value op emitter for the given key\n */\n private makeMapValueOpEmitter(key: string): IValueOpEmitter {\n const emit = (opName: string, previousValue: any, params: any) => {\n const translatedParams = makeHandlesSerializable(\n params,\n this.serializer,\n this.handle);\n\n const op: IMapValueTypeOperation = {\n key,\n type: \"act\",\n value: {\n opName,\n value: translatedParams,\n },\n };\n // Send the localOpMetadata as undefined because we don't care about the ack.\n this.submitMessage(op, { lastProcessedSeq: this.lastProcessedSeq });\n\n const event: IValueChanged = { key, previousValue };\n this.eventEmitter.emit(\"valueChanged\", event, true, null, this.eventEmitter);\n };\n\n return { emit };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"defaultMap.js","sourceRoot":"","sources":["../src/defaultMap.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH,2EAK4C;AAC5C,+DAAyE;AACzE,+CAGuB;AAgFvB;;;;;;GAMG;AACH,MAAa,UAAU;IAkBnB;;;;;;;OAOG;IACH,YACqB,UAA4B,EAC5B,MAAoB,EACpB,aAA2E,EAC3E,IAAmB,EACpB,eAAe,IAAI,gCAAiB,EAA2B;QAJ9D,eAAU,GAAV,UAAU,CAAkB;QAC5B,WAAM,GAAN,MAAM,CAAc;QACpB,kBAAa,GAAb,aAAa,CAA8D;QAC3E,SAAI,GAAJ,IAAI,CAAe;QACpB,iBAAY,GAAZ,YAAY,CAAmD;QAvBnF;;WAEG;QACc,oBAAe,GAA4C,IAAI,GAAG,EAAE,CAAC;QAEtF;;WAEG;QACc,SAAI,GAAG,IAAI,GAAG,EAAkC,CAAC;QAiB9D,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,kBAAkB,EAAE,CAAC;IACrD,CAAC;IAjCD;;OAEG;IACH,IAAW,IAAI;QACX,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CA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AAS,KACzB,sBAAsB,CACzB,CAAC;YACN,CAAC;YACD,yBAAyB,EAAE,CAAC,EAA0B,EAAE,EAAE;gBACtD,IAAA,qBAAM,EAAC,KAAK,EAAE,KAAK,CAAC,kEAAkE,CAAC,CAAC;YAC5F,CAAC;SACJ,CAAC,CAAC;QAEP,OAAO,eAAe,CAAC;IAC3B,CAAC;IAED;;;;;OAKG;IACK,qBAAqB,CAAC,GAAW;QACrC,MAAM,IAAI,GAAG,CAAC,MAAc,EAAE,aAAkB,EAAE,MAAW,EAAE,eAAyC,EAAE,EAAE;YACxG,MAAM,gBAAgB,GAAG,IAAA,4CAAuB,EAC5C,MAAM,EACN,IAAI,CAAC,UAAU,EACf,IAAI,CAAC,MAAM,CAAC,CAAC;YAEjB,MAAM,EAAE,GAA2B;gBAC/B,GAAG;gBACH,IAAI,EAAE,KAAK;gBACX,KAAK,EAAE;oBACH,MAAM;oBACN,KAAK,EAAE,gBAAgB;iBAC1B;aACJ,CAAC;YAEF,IAAI,CAAC,aAAa,CAAC,EAAE,EAAE,eAAe,CAAC,CAAC;YAExC,MAAM,KAAK,GAAkB,EAAE,GAAG,EAAE,aAAa,EAAE,CAAC;YACpD,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,cAAc,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QACjF,CAAC,CAAC;QAEF,OAAO,EAAE,IAAI,EAAE,CAAC;IACpB,CAAC;CACJ;AA1VD,gCA0VC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport {\n IFluidSerializer,\n makeHandlesSerializable,\n parseHandles,\n ValueType,\n} from \"@fluidframework/shared-object-base\";\nimport { assert, TypedEventEmitter } from \"@fluidframework/common-utils\";\nimport {\n makeSerializable,\n ValueTypeLocalValue,\n} from \"./localValues\";\nimport {\n ISerializableValue,\n ISerializedValue,\n IValueChanged,\n IValueOpEmitter,\n IValueType,\n IValueTypeOperationValue,\n ISharedDefaultMapEvents,\n IMapMessageLocalMetadata,\n} from \"./defaultMapInterfaces\";\n\n/**\n * Defines the means to process and submit a given op on a map.\n */\ninterface IMapMessageHandler {\n /**\n * Apply the given operation.\n * @param op - The map operation to apply\n * @param local - Whether the message originated from the local client\n * @param message - The full message. Not provided for stashed ops.\n * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n * For messages from a remote client, this will be undefined.\n */\n process(\n op: IMapOperation,\n local: boolean,\n message: ISequencedDocumentMessage | undefined,\n localOpMetadata: IMapMessageLocalMetadata,\n ): void;\n\n /**\n * Communicate the operation to remote clients.\n * @param op - The map operation to submit\n */\n submit(op: IMapOperation, localOpMetadata: IMapMessageLocalMetadata): void;\n\n resubmit(op: IMapOperation, localOpMetadata: IMapMessageLocalMetadata): void;\n\n getStashedOpLocalMetadata(op: IMapOperation): unknown;\n}\n\n/**\n * Describes an operation specific to a value type.\n */\nexport interface IMapValueTypeOperation {\n /**\n * String identifier of the operation type.\n */\n type: \"act\";\n\n /**\n * Map key being modified.\n */\n key: string;\n\n /**\n * Value of the operation, specific to the value type.\n * @alpha\n */\n value: IValueTypeOperationValue;\n}\n\n/**\n * Description of a map delta operation\n */\nexport type IMapOperation = IMapValueTypeOperation;\n\n/**\n * Defines the in-memory object structure to be used for the conversion to/from serialized.\n * Directly used in JSON.stringify, direct result from JSON.parse\n */\nexport interface IMapDataObjectSerializable {\n [key: string]: ISerializableValue;\n}\n\nexport interface IMapDataObjectSerialized {\n [key: string]: ISerializedValue;\n}\n\n/**\n * A DefaultMap is a map-like distributed data structure, supporting operations on values stored by\n * string key locations.\n *\n * Creation of values is implicit on access (either via `get` or a remote op application referring to\n * a collection that wasn't previously known)\n */\nexport class DefaultMap<T> {\n /**\n * The number of key/value pairs stored in the map.\n */\n public get size(): number {\n return this.data.size;\n }\n\n /**\n * Mapping of op types to message handlers.\n */\n private readonly messageHandlers: ReadonlyMap<string, IMapMessageHandler> = new Map();\n\n /**\n * The in-memory data the map is storing.\n */\n private readonly data = new Map<string, ValueTypeLocalValue<T>>();\n\n /**\n * Create a new default map.\n * @param serializer - The serializer to serialize / parse handles\n * @param handle - The handle of the shared object using the kernel\n * @param submitMessage - A callback to submit a message through the shared object\n * @param type - The value type to create at values of this map\n * @param eventEmitter - The object that will emit map events\n */\n constructor(\n private readonly serializer: IFluidSerializer,\n private readonly handle: IFluidHandle,\n private readonly submitMessage: (op: any, localOpMetadata: IMapMessageLocalMetadata) => void,\n private readonly type: IValueType<T>,\n public readonly eventEmitter = new TypedEventEmitter<ISharedDefaultMapEvents>(),\n ) {\n this.messageHandlers = this.getMessageHandlers();\n }\n\n /**\n * Get an iterator over the keys in this map.\n * @returns The iterator\n */\n public keys(): IterableIterator<string> {\n return this.data.keys();\n }\n\n /**\n * Get an iterator over the entries in this map.\n * @returns The iterator\n */\n public entries(): IterableIterator<[string, any]> {\n const localEntriesIterator = this.data.entries();\n const iterator = {\n next(): IteratorResult<[string, any]> {\n const nextVal = localEntriesIterator.next();\n return nextVal.done\n ? { value: undefined, done: true }\n : { value: [nextVal.value[0], nextVal.value[1].value], done: false }; // Unpack the stored value\n },\n [Symbol.iterator]() {\n return this;\n },\n };\n return iterator;\n }\n\n /**\n * Get an iterator over the values in this map.\n * @returns The iterator\n */\n public values(): IterableIterator<any> {\n const localValuesIterator = this.data.values();\n const iterator = {\n next(): IteratorResult<any> {\n const nextVal = localValuesIterator.next();\n return nextVal.done\n ? { value: undefined, done: true }\n : { value: nextVal.value.value, done: false }; // Unpack the stored value\n },\n [Symbol.iterator]() {\n return this;\n },\n };\n return iterator;\n }\n\n /**\n * Get an iterator over the entries in this map.\n * @returns The iterator\n */\n public [Symbol.iterator](): IterableIterator<[string, any]> {\n return this.entries();\n }\n\n /**\n * Executes the given callback on each entry in the map.\n * @param callbackFn - Callback function\n */\n public forEach(callbackFn: (value: any, key: string, map: Map<string, any>) => void): void {\n this.data.forEach((localValue, key, m) => {\n callbackFn(localValue.value, key, m);\n });\n }\n\n /**\n * {@inheritDoc ISharedMap.get}\n */\n public get(key: string): T {\n const localValue = this.data.get(key) ?? this.createCore(key, true);\n\n return localValue.value;\n }\n\n /**\n * Check if a key exists in the map.\n * @param key - The key to check\n * @returns True if the key exists, false otherwise\n */\n public has(key: string): boolean {\n return this.data.has(key);\n }\n\n /**\n * Serializes the data stored in the shared map to a JSON string\n * @param serializer - The serializer to use to serialize handles in its values.\n * @returns A JSON string containing serialized map data\n */\n public getSerializedStorage(serializer: IFluidSerializer): IMapDataObjectSerialized {\n const serializableMapData: IMapDataObjectSerialized = {};\n this.data.forEach((localValue, key) => {\n serializableMapData[key] = localValue.makeSerialized(serializer, this.handle);\n });\n return serializableMapData;\n }\n\n public getSerializableStorage(serializer: IFluidSerializer): IMapDataObjectSerializable {\n const serializableMapData: IMapDataObjectSerializable = {};\n this.data.forEach((localValue, key) => {\n serializableMapData[key] = makeSerializable(localValue, serializer, this.handle);\n });\n return serializableMapData;\n }\n\n public serialize(serializer: IFluidSerializer): string {\n return JSON.stringify(this.getSerializableStorage(serializer));\n }\n\n /**\n * Populate the kernel with the given map data.\n * @param data - A JSON string containing serialized map data\n */\n public populateFromSerializable(json: IMapDataObjectSerializable): void {\n for (const [key, serializable] of Object.entries(json)) {\n // Back-compat: legacy documents may have handles to an intervalCollection map kernel.\n // These collections should be empty, and ValueTypes are no longer supported.\n if (serializable.type === ValueType[ValueType.Plain]\n || serializable.type === ValueType[ValueType.Shared]) {\n continue;\n }\n\n // Back-compat: Sequence previously arbitrarily prefixed all interval collection keys with\n // \"intervalCollections/\". This would burden users trying to iterate the collection and\n // access its value, as well as those trying to match a create message to its underlying\n // collection. See https://github.com/microsoft/FluidFramework/issues/10557 for more context.\n const normalizedKey = key.startsWith(\"intervalCollections/\") ? key.substring(20) : key;\n\n const localValue = {\n key: normalizedKey,\n value: this.makeLocal(key, serializable),\n };\n\n this.data.set(localValue.key, localValue.value);\n }\n }\n\n public populate(json: string): void {\n this.populateFromSerializable(JSON.parse(json) as IMapDataObjectSerializable);\n }\n\n /**\n * Submit the given op if a handler is registered.\n * @param op - The operation to attempt to submit\n * @param localOpMetadata - The local metadata associated with the op. This is kept locally by the runtime\n * and not sent to the server. This will be sent back when this message is received back from the server. This is\n * also sent if we are asked to resubmit the message.\n * @returns True if the operation was submitted, false otherwise.\n */\n public tryResubmitMessage(op: any, localOpMetadata: IMapMessageLocalMetadata): boolean {\n const type: string = op.type;\n const handler = this.messageHandlers.get(type);\n if (handler !== undefined) {\n handler.resubmit(op as IMapOperation, localOpMetadata);\n return true;\n }\n return false;\n }\n\n public tryGetStashedOpLocalMetadata(op: any): unknown {\n const type: string = op.type;\n if (this.messageHandlers.has(type)) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return this.messageHandlers.get(type)!.getStashedOpLocalMetadata(op as IMapOperation);\n }\n throw new Error(\"no apply stashed op handler\");\n }\n\n /**\n * Process the given op if a handler is registered.\n * @param message - The message to process\n * @param local - Whether the message originated from the local client\n * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n * For messages from a remote client, this will be undefined.\n * @returns True if the operation was processed, false otherwise.\n */\n public tryProcessMessage(\n op: IMapOperation,\n local: boolean,\n message: ISequencedDocumentMessage | undefined,\n localOpMetadata: unknown,\n ): boolean {\n const handler = this.messageHandlers.get(op.type);\n if (handler !== undefined) {\n handler.process(op, local, message, localOpMetadata as IMapMessageLocalMetadata);\n return true;\n }\n return false;\n }\n\n /**\n * Initializes a default ValueType at the provided key.\n * Should be used when a map operation incurs creation.\n * @param key - The key being initialized\n * @param local - Whether the message originated from the local client\n */\n private createCore(key: string, local: boolean): ValueTypeLocalValue<T> {\n const localValue = new ValueTypeLocalValue(\n this.type.factory.load(this.makeMapValueOpEmitter(key), undefined),\n this.type,\n );\n const previousValue = this.data.get(key);\n this.data.set(key, localValue);\n const event: IValueChanged = { key, previousValue };\n this.eventEmitter.emit(\"create\", event, local, this.eventEmitter);\n return localValue;\n }\n\n /**\n * The remote ISerializableValue we're receiving (either as a result of a load or an incoming set op) will\n * have the information we need to create a real object, but will not be the real object yet. For example,\n * we might know it's a map and the map's ID but not have the actual map or its data yet. makeLocal's\n * job is to convert that information into a real object for local usage.\n * @param key - The key that the caller intends to store the local value into (used for ops later). But\n * doesn't actually store the local value into that key. So better not lie!\n * @param serializable - The remote information that we can convert into a real object\n * @returns The local value that was produced\n */\n private makeLocal(key: string, serializable: ISerializableValue): ValueTypeLocalValue<T> {\n assert(serializable.type !== ValueType[ValueType.Plain] && serializable.type !== ValueType[ValueType.Shared],\n 0x2e1 /* \"Support for plain value types removed.\" */);\n\n serializable.value = parseHandles(serializable.value, this.serializer);\n const localValue = this.type.factory.load(\n this.makeMapValueOpEmitter(key),\n serializable.value,\n );\n return new ValueTypeLocalValue(localValue, this.type);\n }\n\n /**\n * Get the message handlers for the map.\n * @returns A map of string op names to IMapMessageHandlers for those ops\n */\n private getMessageHandlers() {\n const messageHandlers = new Map<string, IMapMessageHandler>();\n // Ops with type \"act\" describe actions taken by custom value type handlers of whatever item is\n // being addressed. These custom handlers can be retrieved from the ValueTypeLocalValue which has\n // stashed its valueType (and therefore its handlers). We also emit a valueChanged for anyone\n // watching for manipulations of that item.\n messageHandlers.set(\n \"act\",\n {\n process: (op: IMapValueTypeOperation, local, message, localOpMetadata) => {\n const localValue = this.data.get(op.key) ?? this.createCore(op.key, local);\n const handler = localValue.getOpHandler(op.value.opName);\n const previousValue = localValue.value;\n const translatedValue = parseHandles(\n op.value.value,\n this.serializer);\n handler.process(previousValue, translatedValue, local, message, localOpMetadata);\n const event: IValueChanged = { key: op.key, previousValue };\n this.eventEmitter.emit(\"valueChanged\", event, local, message, this.eventEmitter);\n },\n submit: (op: IMapValueTypeOperation, localOpMetadata: IMapMessageLocalMetadata) => {\n this.submitMessage(\n op,\n localOpMetadata,\n );\n },\n resubmit: (op: IMapValueTypeOperation, localOpMetadata: IMapMessageLocalMetadata) => {\n const localValue = this.data.get(op.key);\n const handler = localValue.getOpHandler(op.value.opName);\n const {\n rebasedOp,\n rebasedLocalOpMetadata,\n } = handler.rebase(localValue.value, op.value, localOpMetadata);\n this.submitMessage(\n { ...op, value: rebasedOp },\n rebasedLocalOpMetadata,\n );\n },\n getStashedOpLocalMetadata: (op: IMapValueTypeOperation) => {\n assert(false, 0x016 /* \"apply stashed op not implemented for custom value type ops\" */);\n },\n });\n\n return messageHandlers;\n }\n\n /**\n * Create an emitter for a value type to emit ops from the given key.\n * @alpha\n * @param key - The key of the map that the value type will be stored on\n * @returns A value op emitter for the given key\n */\n private makeMapValueOpEmitter(key: string): IValueOpEmitter {\n const emit = (opName: string, previousValue: any, params: any, localOpMetadata: IMapMessageLocalMetadata) => {\n const translatedParams = makeHandlesSerializable(\n params,\n this.serializer,\n this.handle);\n\n const op: IMapValueTypeOperation = {\n key,\n type: \"act\",\n value: {\n opName,\n value: translatedParams,\n },\n };\n\n this.submitMessage(op, localOpMetadata);\n\n const event: IValueChanged = { key, previousValue };\n this.eventEmitter.emit(\"valueChanged\", event, true, null, this.eventEmitter);\n };\n\n return { emit };\n }\n}\n"]}
|
|
@@ -20,6 +20,7 @@ export interface IValueChanged {
|
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
22
|
* Value types are given an IValueOpEmitter to emit their ops through the container type that holds them.
|
|
23
|
+
* @internal
|
|
23
24
|
*/
|
|
24
25
|
export interface IValueOpEmitter {
|
|
25
26
|
/**
|
|
@@ -27,9 +28,16 @@ export interface IValueOpEmitter {
|
|
|
27
28
|
* @param opName - Name of the emitted operation
|
|
28
29
|
* @param previousValue - JSONable previous value as defined by the value type
|
|
29
30
|
* @param params - JSONable params for the operation as defined by the value type
|
|
30
|
-
* @
|
|
31
|
+
* @param localOpMetadata - JSONable local metadata which should be submitted with the op
|
|
32
|
+
* @internal
|
|
31
33
|
*/
|
|
32
|
-
emit(opName: string, previousValue: any, params: any): void;
|
|
34
|
+
emit(opName: string, previousValue: any, params: any, localOpMetadata: IMapMessageLocalMetadata): void;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
export interface IMapMessageLocalMetadata {
|
|
40
|
+
localSeq: number;
|
|
33
41
|
}
|
|
34
42
|
/**
|
|
35
43
|
* A value factory is used to serialize/deserialize value types to a map
|
|
@@ -65,9 +73,22 @@ export interface IValueOperation<T> {
|
|
|
65
73
|
* @param params - The params on the incoming operation
|
|
66
74
|
* @param local - Whether the operation originated from this client
|
|
67
75
|
* @param message - The operation itself
|
|
76
|
+
* @param localOpMetadata - any local metadata submitted by `IValueOpEmitter.emit`.
|
|
68
77
|
* @alpha
|
|
69
78
|
*/
|
|
70
|
-
process(value: T, params: any, local: boolean, message: ISequencedDocumentMessage | undefined): any;
|
|
79
|
+
process(value: T, params: any, local: boolean, message: ISequencedDocumentMessage | undefined, localOpMetadata: IMapMessageLocalMetadata | undefined): any;
|
|
80
|
+
/**
|
|
81
|
+
* Rebases an `op` on `value` from its original perspective (ref/local seq) to the current
|
|
82
|
+
* perspective. Should be invoked on reconnection.
|
|
83
|
+
* @param value - The current value stored at the given key, which should be the value type.
|
|
84
|
+
* @param op - The op to be rebased.
|
|
85
|
+
* @param localOpMetadata - Any local metadata that was originally submitted with the op.
|
|
86
|
+
* @returns A rebased version of the op and any local metadata that should be submitted with it.
|
|
87
|
+
*/
|
|
88
|
+
rebase(value: T, op: IValueTypeOperationValue, localOpMetadata: IMapMessageLocalMetadata): {
|
|
89
|
+
rebasedOp: IValueTypeOperationValue;
|
|
90
|
+
rebasedLocalOpMetadata: IMapMessageLocalMetadata;
|
|
91
|
+
};
|
|
71
92
|
}
|
|
72
93
|
/**
|
|
73
94
|
* Defines a value type that can be registered on a container type.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultMapInterfaces.d.ts","sourceRoot":"","sources":["../src/defaultMapInterfaces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAE3E;;GAEG;AACH,MAAM,WAAW,aAAa;IAC1B;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,aAAa,EAAE,GAAG,CAAC;CACtB;AAED
|
|
1
|
+
{"version":3,"file":"defaultMapInterfaces.d.ts","sourceRoot":"","sources":["../src/defaultMapInterfaces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAE3E;;GAEG;AACH,MAAM,WAAW,aAAa;IAC1B;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,aAAa,EAAE,GAAG,CAAC;CACtB;AAED;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC5B;;;;;;;OAOG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,eAAe,EAAE,wBAAwB,GAAG,IAAI,CAAC;CAC1G;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACrC,QAAQ,EAAE,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC;IAC5B;;;;;;;OAOG;IACH,IAAI,CAAC,OAAO,EAAE,eAAe,EAAE,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC;IAE5C;;;;;;OAMG;IACH,KAAK,CAAC,KAAK,EAAE,CAAC,GAAG,GAAG,CAAC;CACxB;AAED;;;GA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;;OAEG;IACH,KAAK,EAAE,GAAG,CAAC;CACd"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultMapInterfaces.js","sourceRoot":"","sources":["../src/defaultMapInterfaces.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport { ISharedObjectEvents } from \"@fluidframework/shared-object-base\";\nimport { IEventThisPlaceHolder } from \"@fluidframework/common-definitions\";\n\n/**\n * Type of \"valueChanged\" event parameter.\n */\nexport interface IValueChanged {\n /**\n * The key storing the value that changed.\n */\n key: string;\n\n /**\n * The value that was stored at the key prior to the change.\n */\n previousValue: any;\n}\n\n/**\n * Value types are given an IValueOpEmitter to emit their ops through the container type that holds them.\n */\nexport interface IValueOpEmitter {\n /**\n * Called by the value type to emit a value type operation through the container type holding it.\n * @param opName - Name of the emitted operation\n * @param previousValue - JSONable previous value as defined by the value type\n * @param params - JSONable params for the operation as defined by the value type\n * @
|
|
1
|
+
{"version":3,"file":"defaultMapInterfaces.js","sourceRoot":"","sources":["../src/defaultMapInterfaces.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport { ISharedObjectEvents } from \"@fluidframework/shared-object-base\";\nimport { IEventThisPlaceHolder } from \"@fluidframework/common-definitions\";\n\n/**\n * Type of \"valueChanged\" event parameter.\n */\nexport interface IValueChanged {\n /**\n * The key storing the value that changed.\n */\n key: string;\n\n /**\n * The value that was stored at the key prior to the change.\n */\n previousValue: any;\n}\n\n/**\n * Value types are given an IValueOpEmitter to emit their ops through the container type that holds them.\n * @internal\n */\nexport interface IValueOpEmitter {\n /**\n * Called by the value type to emit a value type operation through the container type holding it.\n * @param opName - Name of the emitted operation\n * @param previousValue - JSONable previous value as defined by the value type\n * @param params - JSONable params for the operation as defined by the value type\n * @param localOpMetadata - JSONable local metadata which should be submitted with the op\n * @internal\n */\n emit(opName: string, previousValue: any, params: any, localOpMetadata: IMapMessageLocalMetadata): void;\n}\n\n/**\n * @internal\n */\nexport interface IMapMessageLocalMetadata {\n localSeq: number;\n}\n\n/**\n * A value factory is used to serialize/deserialize value types to a map\n * @alpha\n */\nexport interface IValueFactory<T> {\n /**\n * Create a new value type. Used both in creation of new value types, as well as in loading existing ones\n * from remote.\n * @param emitter - Emitter object that the created value type will use to emit operations\n * @param raw - Initialization parameters as defined by the value type\n * @returns The new value type\n * @alpha\n */\n load(emitter: IValueOpEmitter, raw: any): T;\n\n /**\n * Given a value type, provides a JSONable form of its data to be used for snapshotting. This data must be\n * loadable using the load method of its factory.\n * @param value - The value type to serialize\n * @returns The JSONable form of the value type\n * @alpha\n */\n store(value: T): any;\n}\n\n/**\n * Defines an operation that a value type is able to handle.\n * @alpha\n */\nexport interface IValueOperation<T> {\n /**\n * Performs the actual processing on the incoming operation.\n * @param value - The current value stored at the given key, which should be the value type\n * @param params - The params on the incoming operation\n * @param local - Whether the operation originated from this client\n * @param message - The operation itself\n * @param localOpMetadata - any local metadata submitted by `IValueOpEmitter.emit`.\n * @alpha\n */\n process(\n value: T,\n params: any,\n local: boolean,\n message: ISequencedDocumentMessage | undefined,\n localOpMetadata: IMapMessageLocalMetadata | undefined\n );\n\n /**\n * Rebases an `op` on `value` from its original perspective (ref/local seq) to the current\n * perspective. Should be invoked on reconnection.\n * @param value - The current value stored at the given key, which should be the value type.\n * @param op - The op to be rebased.\n * @param localOpMetadata - Any local metadata that was originally submitted with the op.\n * @returns A rebased version of the op and any local metadata that should be submitted with it.\n */\n rebase(\n value: T,\n op: IValueTypeOperationValue,\n localOpMetadata: IMapMessageLocalMetadata\n ): { rebasedOp: IValueTypeOperationValue; rebasedLocalOpMetadata: IMapMessageLocalMetadata; };\n}\n\n/**\n * Defines a value type that can be registered on a container type.\n */\nexport interface IValueType<T> {\n /**\n * Name of the value type.\n * @alpha\n */\n name: string;\n\n /**\n * Factory method used to convert to/from a JSON form of the type.\n * @alpha\n */\n factory: IValueFactory<T>;\n\n /**\n * Operations that can be applied to the value type.\n * @alpha\n */\n ops: Map<string, IValueOperation<T>>;\n}\n\nexport interface ISharedDefaultMapEvents extends ISharedObjectEvents {\n (event: \"valueChanged\" | \"create\", listener: (\n changed: IValueChanged,\n local: boolean,\n target: IEventThisPlaceHolder) => void);\n}\n\n/**\n * The _ready-for-serialization_ format of values contained in DDS contents. This allows us to use\n * ISerializableValue.type to understand whether they're storing a Plain JS object, a SharedObject, or a value type.\n * Note that the in-memory equivalent of ISerializableValue is ILocalValue (similarly holding a type, but with\n * the _in-memory representation_ of the value instead). An ISerializableValue is what gets passed to\n * JSON.stringify and comes out of JSON.parse. This format is used both for snapshots (loadCore/populate)\n * and ops (set).\n *\n * The DefaultMap impelmentation for sequence has been specialized to only support a single ValueType, which serializes\n * and deserializes via .store() and .load().\n */\nexport interface ISerializableValue {\n /**\n * A type annotation to help indicate how the value serializes.\n */\n type: string;\n\n /**\n * The JSONable representation of the value.\n */\n value: any;\n}\n\nexport interface ISerializedValue {\n /**\n * A type annotation to help indicate how the value serializes.\n */\n type: string;\n\n /**\n * String representation of the value.\n */\n value: string | undefined;\n}\n\n/**\n * ValueTypes handle ops slightly differently from SharedObjects or plain JS objects. Since the Map/Directory doesn't\n * know how to handle the ValueType's ops, those ops are instead passed along to the ValueType for processing.\n * IValueTypeOperationValue is that passed-along op. The opName on it is the ValueType-specific operation and the\n * value is whatever params the ValueType needs to complete that operation. Similar to ISerializableValue, it is\n * serializable via JSON.stringify/parse but differs in that it has no equivalency with an in-memory value - rather\n * it just describes an operation to be applied to an already-in-memory value.\n * @alpha\n */\nexport interface IValueTypeOperationValue {\n /**\n * The name of the operation.\n */\n opName: string;\n\n /**\n * The payload that is submitted along with the operation.\n */\n value: any;\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
export { DeserializeCallback, IIntervalCollectionEvent, IIntervalHelpers, Interval, IntervalCollection, IntervalCollectionIterator, IntervalType, ISerializableInterval, ISerializedInterval, SequenceInterval, } from "./intervalCollection";
|
|
6
|
-
export { IValueOpEmitter, } from "./defaultMapInterfaces";
|
|
5
|
+
export { DeserializeCallback, IIntervalCollectionEvent, IIntervalHelpers, Interval, IntervalCollection, IntervalCollectionIterator, IntervalType, ISerializableInterval, ISerializedInterval, SequenceInterval, ISerializedIntervalCollectionV2, CompressedSerializedInterval, } from "./intervalCollection";
|
|
6
|
+
export { IMapMessageLocalMetadata, IValueOpEmitter, } from "./defaultMapInterfaces";
|
|
7
7
|
export * from "./sharedString";
|
|
8
8
|
export * from "./sequence";
|
|
9
9
|
export * from "./sequenceFactory";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACH,mBAAmB,EACnB,wBAAwB,EACxB,gBAAgB,EAChB,QAAQ,EACR,kBAAkB,EAClB,0BAA0B,EAC1B,YAAY,EACZ,qBAAqB,EACrB,mBAAmB,EACnB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACH,mBAAmB,EACnB,wBAAwB,EACxB,gBAAgB,EAChB,QAAQ,EACR,kBAAkB,EAClB,0BAA0B,EAC1B,YAAY,EACZ,qBAAqB,EACrB,mBAAmB,EACnB,gBAAgB,EAChB,+BAA+B,EAC/B,4BAA4B,GAC/B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACH,wBAAwB,EACxB,eAAe,GAClB,MAAM,wBAAwB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,4BAA4B,CAAC"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;AAEH,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;AAEH,2DAa8B;AAT1B,8GAAA,QAAQ,OAAA;AACR,wHAAA,kBAAkB,OAAA;AAClB,gIAAA,0BAA0B,OAAA;AAC1B,kHAAA,YAAY,OAAA;AAGZ,sHAAA,gBAAgB,OAAA;AAQpB,iDAA+B;AAC/B,6CAA2B;AAC3B,oDAAkC;AAClC,uDAAqC;AACrC,mDAAiC;AACjC,yDAAuC;AACvC,yDAAuC;AACvC,iDAA+B;AAC/B,6DAA2C","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport {\n DeserializeCallback,\n IIntervalCollectionEvent,\n IIntervalHelpers,\n Interval,\n IntervalCollection,\n IntervalCollectionIterator,\n IntervalType,\n ISerializableInterval,\n ISerializedInterval,\n SequenceInterval,\n ISerializedIntervalCollectionV2,\n CompressedSerializedInterval,\n} from \"./intervalCollection\";\nexport {\n IMapMessageLocalMetadata,\n IValueOpEmitter,\n} from \"./defaultMapInterfaces\";\nexport * from \"./sharedString\";\nexport * from \"./sequence\";\nexport * from \"./sequenceFactory\";\nexport * from \"./sequenceDeltaEvent\";\nexport * from \"./sharedSequence\";\nexport * from \"./sharedObjectSequence\";\nexport * from \"./sharedNumberSequence\";\nexport * from \"./sparsematrix\";\nexport * from \"./sharedIntervalCollection\";\n"]}
|