@fluidframework/map 1.0.1 → 1.1.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/dist/directory.js +4 -4
- package/dist/directory.js.map +1 -1
- package/dist/interfaces.d.ts +13 -14
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/interfaces.js.map +1 -1
- package/dist/map.d.ts +5 -0
- package/dist/map.d.ts.map +1 -1
- package/dist/map.js +7 -0
- package/dist/map.js.map +1 -1
- package/dist/mapKernel.d.ts +20 -11
- package/dist/mapKernel.d.ts.map +1 -1
- package/dist/mapKernel.js +160 -82
- package/dist/mapKernel.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/lib/directory.js +4 -4
- package/lib/directory.js.map +1 -1
- package/lib/interfaces.d.ts +13 -14
- package/lib/interfaces.d.ts.map +1 -1
- package/lib/interfaces.js.map +1 -1
- package/lib/map.d.ts +5 -0
- package/lib/map.d.ts.map +1 -1
- package/lib/map.js +7 -0
- package/lib/map.js.map +1 -1
- package/lib/mapKernel.d.ts +20 -11
- package/lib/mapKernel.d.ts.map +1 -1
- package/lib/mapKernel.js +160 -82
- package/lib/mapKernel.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/package.json +15 -15
- package/src/directory.ts +4 -4
- package/src/interfaces.ts +14 -16
- package/src/map.ts +8 -0
- package/src/mapKernel.ts +195 -90
- package/src/packageVersion.ts +1 -1
package/dist/mapKernel.js
CHANGED
|
@@ -8,6 +8,17 @@ exports.MapKernel = void 0;
|
|
|
8
8
|
const shared_object_base_1 = require("@fluidframework/shared-object-base");
|
|
9
9
|
const common_utils_1 = require("@fluidframework/common-utils");
|
|
10
10
|
const localValues_1 = require("./localValues");
|
|
11
|
+
function isMapKeyLocalOpMetadata(metadata) {
|
|
12
|
+
return metadata !== undefined && typeof metadata.pendingMessageId === "number" &&
|
|
13
|
+
(metadata.type === "add" || metadata.type === "edit");
|
|
14
|
+
}
|
|
15
|
+
function isClearLocalOpMetadata(metadata) {
|
|
16
|
+
return metadata !== undefined && metadata.type === "clear" && typeof metadata.pendingMessageId === "number";
|
|
17
|
+
}
|
|
18
|
+
function isMapLocalOpMetadata(metadata) {
|
|
19
|
+
return metadata !== undefined && typeof metadata.pendingMessageId === "number" &&
|
|
20
|
+
(metadata.type === "add" || metadata.type === "edit" || metadata.type === "clear");
|
|
21
|
+
}
|
|
11
22
|
/**
|
|
12
23
|
* A SharedMap is a map-like distributed data structure.
|
|
13
24
|
*/
|
|
@@ -44,10 +55,9 @@ class MapKernel {
|
|
|
44
55
|
*/
|
|
45
56
|
this.pendingMessageId = -1;
|
|
46
57
|
/**
|
|
47
|
-
*
|
|
48
|
-
* of that clear operation. Otherwise, is -1.
|
|
58
|
+
* The pending ids of any clears that have been performed locally but not yet ack'd from the server
|
|
49
59
|
*/
|
|
50
|
-
this.
|
|
60
|
+
this.pendingClearMessageIds = [];
|
|
51
61
|
this.localValueMaker = new localValues_1.LocalValueMaker(serializer);
|
|
52
62
|
this.messageHandlers = this.getMessageHandlers();
|
|
53
63
|
}
|
|
@@ -130,12 +140,8 @@ class MapKernel {
|
|
|
130
140
|
* {@inheritDoc ISharedMap.get}
|
|
131
141
|
*/
|
|
132
142
|
get(key) {
|
|
133
|
-
if (!this.data.has(key)) {
|
|
134
|
-
return undefined;
|
|
135
|
-
}
|
|
136
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
137
143
|
const localValue = this.data.get(key);
|
|
138
|
-
return localValue.value;
|
|
144
|
+
return localValue === undefined ? undefined : localValue.value;
|
|
139
145
|
}
|
|
140
146
|
/**
|
|
141
147
|
* Check if a key exists in the map.
|
|
@@ -157,7 +163,7 @@ class MapKernel {
|
|
|
157
163
|
const localValue = this.localValueMaker.fromInMemory(value);
|
|
158
164
|
const serializableValue = (0, localValues_1.makeSerializable)(localValue, this.serializer, this.handle);
|
|
159
165
|
// Set the value locally.
|
|
160
|
-
this.setCore(key, localValue, true);
|
|
166
|
+
const previousValue = this.setCore(key, localValue, true);
|
|
161
167
|
// If we are not attached, don't submit the op.
|
|
162
168
|
if (!this.isAttached()) {
|
|
163
169
|
return;
|
|
@@ -167,7 +173,7 @@ class MapKernel {
|
|
|
167
173
|
type: "set",
|
|
168
174
|
value: serializableValue,
|
|
169
175
|
};
|
|
170
|
-
this.submitMapKeyMessage(op);
|
|
176
|
+
this.submitMapKeyMessage(op, previousValue);
|
|
171
177
|
}
|
|
172
178
|
/**
|
|
173
179
|
* Delete a key from the map.
|
|
@@ -176,22 +182,23 @@ class MapKernel {
|
|
|
176
182
|
*/
|
|
177
183
|
delete(key) {
|
|
178
184
|
// Delete the key locally first.
|
|
179
|
-
const
|
|
185
|
+
const previousValue = this.deleteCore(key, true);
|
|
180
186
|
// If we are not attached, don't submit the op.
|
|
181
187
|
if (!this.isAttached()) {
|
|
182
|
-
return
|
|
188
|
+
return previousValue !== undefined;
|
|
183
189
|
}
|
|
184
190
|
const op = {
|
|
185
191
|
key,
|
|
186
192
|
type: "delete",
|
|
187
193
|
};
|
|
188
|
-
this.submitMapKeyMessage(op);
|
|
189
|
-
return
|
|
194
|
+
this.submitMapKeyMessage(op, previousValue);
|
|
195
|
+
return previousValue !== undefined;
|
|
190
196
|
}
|
|
191
197
|
/**
|
|
192
198
|
* Clear all data from the map.
|
|
193
199
|
*/
|
|
194
200
|
clear() {
|
|
201
|
+
const copy = this.isAttached() ? new Map(this.data) : undefined;
|
|
195
202
|
// Clear the data locally first.
|
|
196
203
|
this.clearCore(true);
|
|
197
204
|
// If we are not attached, don't submit the op.
|
|
@@ -201,7 +208,7 @@ class MapKernel {
|
|
|
201
208
|
const op = {
|
|
202
209
|
type: "clear",
|
|
203
210
|
};
|
|
204
|
-
this.submitMapClearMessage(op);
|
|
211
|
+
this.submitMapClearMessage(op, copy);
|
|
205
212
|
}
|
|
206
213
|
/**
|
|
207
214
|
* Serializes the data stored in the shared map to a JSON string
|
|
@@ -250,57 +257,97 @@ class MapKernel {
|
|
|
250
257
|
* @returns True if the operation was submitted, false otherwise.
|
|
251
258
|
*/
|
|
252
259
|
trySubmitMessage(op, localOpMetadata) {
|
|
253
|
-
const
|
|
254
|
-
if (
|
|
255
|
-
|
|
256
|
-
this.messageHandlers.get(type).submit(op, localOpMetadata);
|
|
257
|
-
return true;
|
|
260
|
+
const handler = this.messageHandlers.get(op.type);
|
|
261
|
+
if (handler === undefined) {
|
|
262
|
+
return false;
|
|
258
263
|
}
|
|
259
|
-
|
|
264
|
+
handler.submit(op, localOpMetadata);
|
|
265
|
+
return true;
|
|
260
266
|
}
|
|
261
267
|
tryGetStashedOpLocalMetadata(op) {
|
|
262
|
-
const
|
|
263
|
-
if (
|
|
264
|
-
|
|
265
|
-
return this.messageHandlers.get(type).getStashedOpLocalMetadata(op);
|
|
268
|
+
const handler = this.messageHandlers.get(op.type);
|
|
269
|
+
if (handler === undefined) {
|
|
270
|
+
throw new Error("no apply stashed op handler");
|
|
266
271
|
}
|
|
267
|
-
|
|
272
|
+
return handler.getStashedOpLocalMetadata(op);
|
|
268
273
|
}
|
|
269
274
|
/**
|
|
270
275
|
* Process the given op if a handler is registered.
|
|
271
|
-
* @param
|
|
276
|
+
* @param op - The message to process
|
|
272
277
|
* @param local - Whether the message originated from the local client
|
|
273
278
|
* @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.
|
|
274
279
|
* For messages from a remote client, this will be undefined.
|
|
275
280
|
* @returns True if the operation was processed, false otherwise.
|
|
276
281
|
*/
|
|
277
282
|
tryProcessMessage(op, local, localOpMetadata) {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
283
|
+
const handler = this.messageHandlers.get(op.type);
|
|
284
|
+
if (handler === undefined) {
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
handler.process(op, local, localOpMetadata);
|
|
288
|
+
return true;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Rollback a local op
|
|
292
|
+
* @param op - The operation to rollback
|
|
293
|
+
* @param localOpMetadata - The local metadata associated with the op.
|
|
294
|
+
*/
|
|
295
|
+
rollback(op, localOpMetadata) {
|
|
296
|
+
if (!isMapLocalOpMetadata(localOpMetadata)) {
|
|
297
|
+
throw new Error("Invalid localOpMetadata");
|
|
298
|
+
}
|
|
299
|
+
if (op.type === "clear" && localOpMetadata.type === "clear") {
|
|
300
|
+
if (localOpMetadata.previousMap === undefined) {
|
|
301
|
+
throw new Error("Cannot rollback without previous map");
|
|
302
|
+
}
|
|
303
|
+
localOpMetadata.previousMap.forEach((localValue, key) => {
|
|
304
|
+
this.setCore(key, localValue, true);
|
|
305
|
+
});
|
|
306
|
+
const lastPendingClearId = this.pendingClearMessageIds.pop();
|
|
307
|
+
if (lastPendingClearId === undefined || lastPendingClearId !== localOpMetadata.pendingMessageId) {
|
|
308
|
+
throw new Error("Rollback op does match last clear");
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
else if (op.type === "delete" || op.type === "set") {
|
|
312
|
+
if (localOpMetadata.type === "add") {
|
|
313
|
+
this.deleteCore(op.key, true);
|
|
314
|
+
}
|
|
315
|
+
else if (localOpMetadata.type === "edit" && localOpMetadata.previousValue !== undefined) {
|
|
316
|
+
this.setCore(op.key, localOpMetadata.previousValue, true);
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
throw new Error("Cannot rollback without previous value");
|
|
320
|
+
}
|
|
321
|
+
const pendingMessageIds = this.pendingKeys.get(op.key);
|
|
322
|
+
const lastPendingMessageId = pendingMessageIds === null || pendingMessageIds === void 0 ? void 0 : pendingMessageIds.pop();
|
|
323
|
+
if (!pendingMessageIds || lastPendingMessageId !== localOpMetadata.pendingMessageId) {
|
|
324
|
+
throw new Error("Rollback op does not match last pending");
|
|
325
|
+
}
|
|
326
|
+
if (pendingMessageIds.length === 0) {
|
|
327
|
+
this.pendingKeys.delete(op.key);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
throw new Error("Unsupported op for rollback");
|
|
284
332
|
}
|
|
285
|
-
return false;
|
|
286
333
|
}
|
|
287
334
|
/**
|
|
288
335
|
* Set implementation used for both locally sourced sets as well as incoming remote sets.
|
|
289
336
|
* @param key - The key being set
|
|
290
337
|
* @param value - The value being set
|
|
291
338
|
* @param local - Whether the message originated from the local client
|
|
292
|
-
* @
|
|
339
|
+
* @returns Previous local value of the key, if any
|
|
293
340
|
*/
|
|
294
341
|
setCore(key, value, local) {
|
|
295
|
-
const
|
|
342
|
+
const previousLocalValue = this.data.get(key);
|
|
343
|
+
const previousValue = previousLocalValue === null || previousLocalValue === void 0 ? void 0 : previousLocalValue.value;
|
|
296
344
|
this.data.set(key, value);
|
|
297
|
-
|
|
298
|
-
|
|
345
|
+
this.eventEmitter.emit("valueChanged", { key, previousValue }, local, this.eventEmitter);
|
|
346
|
+
return previousLocalValue;
|
|
299
347
|
}
|
|
300
348
|
/**
|
|
301
349
|
* Clear implementation used for both locally sourced clears as well as incoming remote clears.
|
|
302
350
|
* @param local - Whether the message originated from the local client
|
|
303
|
-
* @param op - The message if from a remote clear, or null if from a local clear
|
|
304
351
|
*/
|
|
305
352
|
clearCore(local) {
|
|
306
353
|
this.data.clear();
|
|
@@ -310,17 +357,16 @@ class MapKernel {
|
|
|
310
357
|
* Delete implementation used for both locally sourced deletes as well as incoming remote deletes.
|
|
311
358
|
* @param key - The key being deleted
|
|
312
359
|
* @param local - Whether the message originated from the local client
|
|
313
|
-
* @
|
|
314
|
-
* @returns True if the key existed and was deleted, false if it did not exist
|
|
360
|
+
* @returns Previous local value of the key if it existed, undefined if it did not exist
|
|
315
361
|
*/
|
|
316
362
|
deleteCore(key, local) {
|
|
317
|
-
const
|
|
363
|
+
const previousLocalValue = this.data.get(key);
|
|
364
|
+
const previousValue = previousLocalValue === null || previousLocalValue === void 0 ? void 0 : previousLocalValue.value;
|
|
318
365
|
const successfullyRemoved = this.data.delete(key);
|
|
319
366
|
if (successfullyRemoved) {
|
|
320
|
-
|
|
321
|
-
this.eventEmitter.emit("valueChanged", event, local, this.eventEmitter);
|
|
367
|
+
this.eventEmitter.emit("valueChanged", { key, previousValue }, local, this.eventEmitter);
|
|
322
368
|
}
|
|
323
|
-
return
|
|
369
|
+
return previousLocalValue;
|
|
324
370
|
}
|
|
325
371
|
/**
|
|
326
372
|
* Clear all keys in memory in response to a remote clear, but retain keys we have modified but not yet been ack'd.
|
|
@@ -333,9 +379,9 @@ class MapKernel {
|
|
|
333
379
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
334
380
|
temp.set(key, this.data.get(key));
|
|
335
381
|
});
|
|
336
|
-
this.
|
|
382
|
+
this.clearCore(false);
|
|
337
383
|
temp.forEach((value, key) => {
|
|
338
|
-
this.
|
|
384
|
+
this.setCore(key, value, true);
|
|
339
385
|
});
|
|
340
386
|
}
|
|
341
387
|
/**
|
|
@@ -361,27 +407,29 @@ class MapKernel {
|
|
|
361
407
|
* not process the incoming operation.
|
|
362
408
|
* @param op - Operation to check
|
|
363
409
|
* @param local - Whether the message originated from the local client
|
|
364
|
-
* @param message - The message
|
|
365
410
|
* @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.
|
|
366
411
|
* For messages from a remote client, this will be undefined.
|
|
367
412
|
* @returns True if the operation should be processed, false otherwise
|
|
368
413
|
*/
|
|
369
414
|
needProcessKeyOperation(op, local, localOpMetadata) {
|
|
370
|
-
if (this.
|
|
415
|
+
if (this.pendingClearMessageIds.length > 0) {
|
|
371
416
|
if (local) {
|
|
372
|
-
(0, common_utils_1.assert)(localOpMetadata !== undefined && localOpMetadata
|
|
417
|
+
(0, common_utils_1.assert)(localOpMetadata !== undefined && isMapKeyLocalOpMetadata(localOpMetadata) &&
|
|
418
|
+
localOpMetadata.pendingMessageId < this.pendingClearMessageIds[0], 0x013 /* "Received out of order op when there is an unackd clear message" */);
|
|
373
419
|
}
|
|
374
420
|
// If we have an unack'd clear, we can ignore all ops.
|
|
375
421
|
return false;
|
|
376
422
|
}
|
|
377
|
-
|
|
423
|
+
const pendingKeyMessageId = this.pendingKeys.get(op.key);
|
|
424
|
+
if (pendingKeyMessageId !== undefined) {
|
|
378
425
|
// Found an unack'd op. Clear it from the map if the pendingMessageId in the map matches this message's
|
|
379
426
|
// and don't process the op.
|
|
380
427
|
if (local) {
|
|
381
|
-
(0, common_utils_1.assert)(localOpMetadata !== undefined, 0x014 /* pendingMessageId is missing from the local client's operation */);
|
|
382
|
-
const
|
|
383
|
-
|
|
384
|
-
|
|
428
|
+
(0, common_utils_1.assert)(localOpMetadata !== undefined && isMapKeyLocalOpMetadata(localOpMetadata), 0x014 /* pendingMessageId is missing from the local client's operation */);
|
|
429
|
+
const pendingMessageIds = this.pendingKeys.get(op.key);
|
|
430
|
+
(0, common_utils_1.assert)(pendingMessageIds !== undefined && pendingMessageIds[0] === localOpMetadata.pendingMessageId, 0x2fa /* Unexpected pending message received */);
|
|
431
|
+
pendingMessageIds.shift();
|
|
432
|
+
if (pendingMessageIds.length === 0) {
|
|
385
433
|
this.pendingKeys.delete(op.key);
|
|
386
434
|
}
|
|
387
435
|
}
|
|
@@ -399,11 +447,9 @@ class MapKernel {
|
|
|
399
447
|
messageHandlers.set("clear", {
|
|
400
448
|
process: (op, local, localOpMetadata) => {
|
|
401
449
|
if (local) {
|
|
402
|
-
(0, common_utils_1.assert)(localOpMetadata
|
|
403
|
-
const
|
|
404
|
-
|
|
405
|
-
this.pendingClearMessageId = -1;
|
|
406
|
-
}
|
|
450
|
+
(0, common_utils_1.assert)(isClearLocalOpMetadata(localOpMetadata), 0x015 /* "pendingMessageId is missing from the local client's clear operation" */);
|
|
451
|
+
const pendingClearMessageId = this.pendingClearMessageIds.shift();
|
|
452
|
+
(0, common_utils_1.assert)(pendingClearMessageId === localOpMetadata.pendingMessageId, 0x2fb /* pendingMessageId does not match */);
|
|
407
453
|
return;
|
|
408
454
|
}
|
|
409
455
|
if (this.pendingKeys.size !== 0) {
|
|
@@ -413,12 +459,15 @@ class MapKernel {
|
|
|
413
459
|
this.clearCore(local);
|
|
414
460
|
},
|
|
415
461
|
submit: (op, localOpMetadata) => {
|
|
416
|
-
|
|
417
|
-
|
|
462
|
+
(0, common_utils_1.assert)(isClearLocalOpMetadata(localOpMetadata), 0x2fc /* Invalid localOpMetadata for clear */);
|
|
463
|
+
// We don't reuse the metadata pendingMessageId but send a new one on each submit.
|
|
464
|
+
const pendingClearMessageId = this.pendingClearMessageIds.shift();
|
|
465
|
+
(0, common_utils_1.assert)(pendingClearMessageId === localOpMetadata.pendingMessageId, 0x2fd /* pendingMessageId does not match */);
|
|
466
|
+
this.submitMapClearMessage(op, localOpMetadata.previousMap);
|
|
418
467
|
},
|
|
419
468
|
getStashedOpLocalMetadata: (op) => {
|
|
420
|
-
// We don't reuse the metadata but send a new one on each submit.
|
|
421
|
-
return this.
|
|
469
|
+
// We don't reuse the metadata pendingMessageId but send a new one on each submit.
|
|
470
|
+
return { type: "clear", pendingMessageId: this.getMapClearMessageId() };
|
|
422
471
|
},
|
|
423
472
|
});
|
|
424
473
|
messageHandlers.set("delete", {
|
|
@@ -429,12 +478,11 @@ class MapKernel {
|
|
|
429
478
|
this.deleteCore(op.key, local);
|
|
430
479
|
},
|
|
431
480
|
submit: (op, localOpMetadata) => {
|
|
432
|
-
|
|
433
|
-
this.submitMapKeyMessage(op);
|
|
481
|
+
this.resubmitMapKeyMessage(op, localOpMetadata);
|
|
434
482
|
},
|
|
435
483
|
getStashedOpLocalMetadata: (op) => {
|
|
436
|
-
// We don't reuse the metadata but send a new one on each submit.
|
|
437
|
-
return this.
|
|
484
|
+
// We don't reuse the metadata pendingMessageId but send a new one on each submit.
|
|
485
|
+
return { type: "edit", pendingMessageId: this.getMapKeyMessageId(op) };
|
|
438
486
|
},
|
|
439
487
|
});
|
|
440
488
|
messageHandlers.set("set", {
|
|
@@ -447,41 +495,71 @@ class MapKernel {
|
|
|
447
495
|
this.setCore(op.key, context, local);
|
|
448
496
|
},
|
|
449
497
|
submit: (op, localOpMetadata) => {
|
|
450
|
-
|
|
451
|
-
this.submitMapKeyMessage(op);
|
|
498
|
+
this.resubmitMapKeyMessage(op, localOpMetadata);
|
|
452
499
|
},
|
|
453
500
|
getStashedOpLocalMetadata: (op) => {
|
|
454
|
-
// We don't reuse the metadata but send a new one on each submit.
|
|
455
|
-
return this.
|
|
501
|
+
// We don't reuse the metadata pendingMessageId but send a new one on each submit.
|
|
502
|
+
return { type: "edit", pendingMessageId: this.getMapKeyMessageId(op) };
|
|
456
503
|
},
|
|
457
504
|
});
|
|
458
505
|
return messageHandlers;
|
|
459
506
|
}
|
|
460
|
-
|
|
507
|
+
getMapClearMessageId() {
|
|
461
508
|
const pendingMessageId = ++this.pendingMessageId;
|
|
462
|
-
this.
|
|
509
|
+
this.pendingClearMessageIds.push(pendingMessageId);
|
|
463
510
|
return pendingMessageId;
|
|
464
511
|
}
|
|
465
512
|
/**
|
|
466
513
|
* Submit a clear message to remote clients.
|
|
467
514
|
* @param op - The clear message
|
|
468
515
|
*/
|
|
469
|
-
submitMapClearMessage(op) {
|
|
470
|
-
const
|
|
471
|
-
this.submitMessage(op,
|
|
516
|
+
submitMapClearMessage(op, previousMap) {
|
|
517
|
+
const metadata = { type: "clear", pendingMessageId: this.getMapClearMessageId(), previousMap };
|
|
518
|
+
this.submitMessage(op, metadata);
|
|
472
519
|
}
|
|
473
|
-
|
|
520
|
+
getMapKeyMessageId(op) {
|
|
474
521
|
const pendingMessageId = ++this.pendingMessageId;
|
|
475
|
-
this.pendingKeys.
|
|
522
|
+
const pendingMessageIds = this.pendingKeys.get(op.key);
|
|
523
|
+
if (pendingMessageIds !== undefined) {
|
|
524
|
+
pendingMessageIds.push(pendingMessageId);
|
|
525
|
+
}
|
|
526
|
+
else {
|
|
527
|
+
this.pendingKeys.set(op.key, [pendingMessageId]);
|
|
528
|
+
}
|
|
476
529
|
return pendingMessageId;
|
|
477
530
|
}
|
|
478
531
|
/**
|
|
479
532
|
* Submit a map key message to remote clients.
|
|
480
533
|
* @param op - The map key message
|
|
534
|
+
* @param previousValue - The value of the key before this op
|
|
535
|
+
*/
|
|
536
|
+
submitMapKeyMessage(op, previousValue) {
|
|
537
|
+
const pendingMessageId = this.getMapKeyMessageId(op);
|
|
538
|
+
const localMetadata = previousValue ?
|
|
539
|
+
{ type: "edit", pendingMessageId, previousValue } :
|
|
540
|
+
{ type: "add", pendingMessageId };
|
|
541
|
+
this.submitMessage(op, localMetadata);
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* Submit a map key message to remote clients based on a previous submit.
|
|
545
|
+
* @param op - The map key message
|
|
546
|
+
* @param localOpMetadata - Metadata from the previous submit
|
|
481
547
|
*/
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
548
|
+
resubmitMapKeyMessage(op, localOpMetadata) {
|
|
549
|
+
(0, common_utils_1.assert)(isMapKeyLocalOpMetadata(localOpMetadata), 0x2fe /* Invalid localOpMetadata in submit */);
|
|
550
|
+
// clear the old pending message id
|
|
551
|
+
const pendingMessageIds = this.pendingKeys.get(op.key);
|
|
552
|
+
(0, common_utils_1.assert)(pendingMessageIds !== undefined && pendingMessageIds[0] === localOpMetadata.pendingMessageId, 0x2ff /* Unexpected pending message received */);
|
|
553
|
+
pendingMessageIds.shift();
|
|
554
|
+
if (pendingMessageIds.length === 0) {
|
|
555
|
+
this.pendingKeys.delete(op.key);
|
|
556
|
+
}
|
|
557
|
+
// We don't reuse the metadata pendingMessageId but send a new one on each submit.
|
|
558
|
+
const pendingMessageId = this.getMapKeyMessageId(op);
|
|
559
|
+
const localMetadata = localOpMetadata.type === "edit" ?
|
|
560
|
+
{ type: "edit", pendingMessageId, previousValue: localOpMetadata.previousValue } :
|
|
561
|
+
{ type: "add", pendingMessageId };
|
|
562
|
+
this.submitMessage(op, localMetadata);
|
|
485
563
|
}
|
|
486
564
|
}
|
|
487
565
|
exports.MapKernel = MapKernel;
|
package/dist/mapKernel.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapKernel.js","sourceRoot":"","sources":["../src/mapKernel.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,2EAAiF;AACjF,+DAAyE;AAOzE,+CAIuB;AAgGvB;;GAEG;AACH,MAAa,SAAS;IAuClB;;;;;;;;OAQG;IACH,YACqB,UAA4B,EAC5B,MAAoB,EACpB,aAA0D,EAC1D,UAAyB,EACzB,YAAiD;QAJjD,eAAU,GAAV,UAAU,CAAkB;QAC5B,WAAM,GAAN,MAAM,CAAc;QACpB,kBAAa,GAAb,aAAa,CAA6C;QAC1D,eAAU,GAAV,UAAU,CAAe;QACzB,iBAAY,GAAZ,YAAY,CAAqC;QA7CtE;;WAEG;QACc,oBAAe,GAA4C,IAAI,GAAG,EAAE,CAAC;QAEtF;;WAEG;QACc,SAAI,GAAG,IAAI,GAAG,EAAuB,CAAC;QAEvD;;WAEG;QACc,gBAAW,GAAwB,IAAI,GAAG,EAAE,CAAC;QAE9D;;WAEG;QACK,qBAAgB,GAAW,CAAC,CAAC,CAAC;QAEtC;;;WAGG;QACK,0BAAqB,GAAW,CAAC,CAAC,CAAC;QAuBvC,IAAI,CAAC,eAAe,GAAG,IAAI,6BAAe,CAAC,UAAU,CAAC,CAAC;QACvD,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,kBAAkB,EAAE,CAAC;IACrD,CAAC;IAxDD;;OAEG;IACH,IAAW,IAAI;QACX,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;IAC1B,CAAC;IAqDD;;;OAGG;IACI,IAAI;QACP,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;IAC5B,CAAC;IAED;;;OAGG;IACI,OAAO;QACV,MAAM,oBAAoB,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QACjD,MAAM,QAA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AAE,gBAAgB,CAAC,CAAC;QAC/C,OAAO,gBAAgB,CAAC;IAC5B,CAAC;IAED;;;OAGG;IACK,mBAAmB,CAAC,EAAoB;QAC5C,MAAM,gBAAgB,GAAG,IAAI,CAAC,6BAA6B,CAAC,EAAE,CAAC,CAAC;QAChE,IAAI,CAAC,aAAa,CAAC,EAAE,EAAE,gBAAgB,CAAC,CAAC;IAC7C,CAAC;CACJ;AAtiBD,8BAsiBC","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 { IFluidSerializer, ValueType } from \"@fluidframework/shared-object-base\";\nimport { assert, TypedEventEmitter } from \"@fluidframework/common-utils\";\nimport {\n ISerializableValue,\n ISerializedValue,\n IValueChanged,\n ISharedMapEvents,\n} from \"./interfaces\";\nimport {\n ILocalValue,\n LocalValueMaker,\n makeSerializable,\n} from \"./localValues\";\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 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 localOpMetadata: unknown,\n ): void;\n\n /**\n * Communicate the operation to remote clients.\n * @param op - The map operation to submit\n * @param localOpMetadata - The metadata to be submitted with the message.\n */\n submit(op: IMapOperation, localOpMetadata: unknown): void;\n\n getStashedOpLocalMetadata(op: IMapOperation): unknown;\n}\n\n/**\n * Operation indicating a value should be set for a key.\n */\nexport interface IMapSetOperation {\n /**\n * String identifier of the operation type.\n */\n type: \"set\";\n\n /**\n * Map key being modified.\n */\n key: string;\n\n /**\n * Value to be set on the key.\n */\n value: ISerializableValue;\n}\n\n/**\n * Operation indicating a key should be deleted from the map.\n */\nexport interface IMapDeleteOperation {\n /**\n * String identifier of the operation type.\n */\n type: \"delete\";\n\n /**\n * Map key being modified.\n */\n key: string;\n}\n\n/**\n * Map key operations are one of several types.\n */\nexport type IMapKeyOperation = IMapSetOperation | IMapDeleteOperation;\n\n/**\n * Operation indicating the map should be cleared.\n */\nexport interface IMapClearOperation {\n /**\n * String identifier of the operation type.\n */\n type: \"clear\";\n}\n\n/**\n * Description of a map delta operation\n */\nexport type IMapOperation = IMapKeyOperation | IMapClearOperation;\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 SharedMap is a map-like distributed data structure.\n */\nexport class MapKernel {\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, ILocalValue>();\n\n /**\n * Keys that have been modified locally but not yet ack'd from the server.\n */\n private readonly pendingKeys: Map<string, number> = new Map();\n\n /**\n * This is used to assign a unique id to every outgoing operation and helps in tracking unack'd ops.\n */\n private pendingMessageId: number = -1;\n\n /**\n * If a clear has been performed locally but not yet ack'd from the server, then this stores the pending id\n * of that clear operation. Otherwise, is -1.\n */\n private pendingClearMessageId: number = -1;\n\n /**\n * Object to create encapsulations of the values stored in the map.\n */\n private readonly localValueMaker: LocalValueMaker;\n\n /**\n * Create a new shared map kernel.\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 isAttached - To query whether the shared object should generate ops\n * @param valueTypes - The value types to register\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: unknown) => void,\n private readonly isAttached: () => boolean,\n private readonly eventEmitter: TypedEventEmitter<ISharedMapEvents>,\n ) {\n this.localValueMaker = new LocalValueMaker(serializer);\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<T = any>(key: string): T | undefined {\n if (!this.data.has(key)) {\n return undefined;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const localValue = this.data.get(key)!;\n\n return localValue.value as T;\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 * {@inheritDoc ISharedMap.set}\n */\n public set(key: string, value: any) {\n // Undefined/null keys can't be serialized to JSON in the manner we currently snapshot.\n if (key === undefined || key === null) {\n throw new Error(\"Undefined and null keys are not supported\");\n }\n\n // Create a local value and serialize it.\n const localValue = this.localValueMaker.fromInMemory(value);\n const serializableValue = makeSerializable(\n localValue,\n this.serializer,\n this.handle);\n\n // Set the value locally.\n this.setCore(\n key,\n localValue,\n true,\n );\n\n // If we are not attached, don't submit the op.\n if (!this.isAttached()) {\n return;\n }\n\n const op: IMapSetOperation = {\n key,\n type: \"set\",\n value: serializableValue,\n };\n this.submitMapKeyMessage(op);\n }\n\n /**\n * Delete a key from the map.\n * @param key - Key to delete\n * @returns True if the key existed and was deleted, false if it did not exist\n */\n public delete(key: string): boolean {\n // Delete the key locally first.\n const successfullyRemoved = this.deleteCore(key, true);\n\n // If we are not attached, don't submit the op.\n if (!this.isAttached()) {\n return successfullyRemoved;\n }\n\n const op: IMapDeleteOperation = {\n key,\n type: \"delete\",\n };\n this.submitMapKeyMessage(op);\n\n return successfullyRemoved;\n }\n\n /**\n * Clear all data from the map.\n */\n public clear(): void {\n // Clear the data locally first.\n this.clearCore(true);\n\n // If we are not attached, don't submit the op.\n if (!this.isAttached()) {\n return;\n }\n\n const op: IMapClearOperation = {\n type: \"clear\",\n };\n this.submitMapClearMessage(op);\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 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: unknown): boolean {\n const type: string = op.type;\n if (this.messageHandlers.has(type)) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.messageHandlers.get(type)!.submit(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 localOpMetadata: unknown,\n ): boolean {\n if (this.messageHandlers.has(op.type)) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.messageHandlers\n .get(op.type)!\n .process(op, local, localOpMetadata);\n return true;\n }\n return false;\n }\n\n /**\n * Set implementation used for both locally sourced sets as well as incoming remote sets.\n * @param key - The key being set\n * @param value - The value being set\n * @param local - Whether the message originated from the local client\n * @param op - The message if from a remote set, or null if from a local set\n */\n private setCore(key: string, value: ILocalValue, local: boolean): void {\n const previousValue = this.get(key);\n this.data.set(key, value);\n const event: IValueChanged = { key, previousValue };\n this.eventEmitter.emit(\"valueChanged\", event, local, this.eventEmitter);\n }\n\n /**\n * Clear implementation used for both locally sourced clears as well as incoming remote clears.\n * @param local - Whether the message originated from the local client\n * @param op - The message if from a remote clear, or null if from a local clear\n */\n private clearCore(local: boolean): void {\n this.data.clear();\n this.eventEmitter.emit(\"clear\", local, this.eventEmitter);\n }\n\n /**\n * Delete implementation used for both locally sourced deletes as well as incoming remote deletes.\n * @param key - The key being deleted\n * @param local - Whether the message originated from the local client\n * @param op - The message if from a remote delete, or null if from a local delete\n * @returns True if the key existed and was deleted, false if it did not exist\n */\n private deleteCore(key: string, local: boolean): boolean {\n const previousValue = this.get(key);\n const successfullyRemoved = this.data.delete(key);\n if (successfullyRemoved) {\n const event: IValueChanged = { key, previousValue };\n this.eventEmitter.emit(\"valueChanged\", event, local, this.eventEmitter);\n }\n return successfullyRemoved;\n }\n\n /**\n * Clear all keys in memory in response to a remote clear, but retain keys we have modified but not yet been ack'd.\n */\n private clearExceptPendingKeys(): void {\n // Assuming the pendingKeys is small and the map is large\n // we will get the value for the pendingKeys and clear the map\n const temp = new Map<string, ILocalValue>();\n this.pendingKeys.forEach((value, key) => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n temp.set(key, this.data.get(key)!);\n });\n this.data.clear();\n temp.forEach((value, key) => {\n this.data.set(key, value);\n });\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): ILocalValue {\n if (serializable.type === ValueType[ValueType.Plain] || serializable.type === ValueType[ValueType.Shared]) {\n return this.localValueMaker.fromSerializable(serializable);\n } else {\n throw new Error(\"Unknown local value type\");\n }\n }\n\n /**\n * If our local operations that have not yet been ack'd will eventually overwrite an incoming operation, we should\n * not process the incoming operation.\n * @param op - Operation to check\n * @param local - Whether the message originated from the local client\n * @param message - The message\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 should be processed, false otherwise\n */\n private needProcessKeyOperation(\n op: IMapKeyOperation,\n local: boolean,\n localOpMetadata: unknown,\n ): boolean {\n if (this.pendingClearMessageId !== -1) {\n if (local) {\n assert(localOpMetadata !== undefined && localOpMetadata as number < this.pendingClearMessageId,\n 0x013 /* \"Received out of order op when there is an unackd clear message\" */);\n }\n // If we have an unack'd clear, we can ignore all ops.\n return false;\n }\n\n if (this.pendingKeys.has(op.key)) {\n // Found an unack'd op. Clear it from the map if the pendingMessageId in the map matches this message's\n // and don't process the op.\n if (local) {\n assert(localOpMetadata !== undefined,\n 0x014 /* pendingMessageId is missing from the local client's operation */);\n const pendingMessageId = localOpMetadata as number;\n const pendingKeyMessageId = this.pendingKeys.get(op.key);\n if (pendingKeyMessageId === pendingMessageId) {\n this.pendingKeys.delete(op.key);\n }\n }\n return false;\n }\n\n // If we don't have a NACK op on the key, we need to process the remote ops.\n return !local;\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 messageHandlers.set(\n \"clear\",\n {\n process: (op: IMapClearOperation, local, localOpMetadata) => {\n if (local) {\n assert(localOpMetadata !== undefined,\n 0x015 /* \"pendingMessageId is missing from the local client's clear operation\" */);\n const pendingMessageId = localOpMetadata as number;\n if (this.pendingClearMessageId === pendingMessageId) {\n this.pendingClearMessageId = -1;\n }\n return;\n }\n if (this.pendingKeys.size !== 0) {\n this.clearExceptPendingKeys();\n return;\n }\n this.clearCore(local);\n },\n submit: (op: IMapClearOperation, localOpMetadata: unknown) => {\n // We don't reuse the metadata but send a new one on each submit.\n this.submitMapClearMessage(op);\n },\n getStashedOpLocalMetadata: (op: IMapClearOperation) => {\n // We don't reuse the metadata but send a new one on each submit.\n return this.getMapClearMessageLocalMetadata(op);\n },\n });\n messageHandlers.set(\n \"delete\",\n {\n process: (op: IMapDeleteOperation, local, localOpMetadata) => {\n if (!this.needProcessKeyOperation(op, local, localOpMetadata)) {\n return;\n }\n this.deleteCore(op.key, local);\n },\n submit: (op: IMapDeleteOperation, localOpMetadata: unknown) => {\n // We don't reuse the metadata but send a new one on each submit.\n this.submitMapKeyMessage(op);\n },\n getStashedOpLocalMetadata: (op: IMapDeleteOperation) => {\n // We don't reuse the metadata but send a new one on each submit.\n return this.getMapKeyMessageLocalMetadata(op);\n },\n });\n messageHandlers.set(\n \"set\",\n {\n process: (op: IMapSetOperation, local, localOpMetadata) => {\n if (!this.needProcessKeyOperation(op, local, localOpMetadata)) {\n return;\n }\n\n // needProcessKeyOperation should have returned false if local is true\n const context = this.makeLocal(op.key, op.value);\n this.setCore(op.key, context, local);\n },\n submit: (op: IMapSetOperation, localOpMetadata: unknown) => {\n // We don't reuse the metadata but send a new one on each submit.\n this.submitMapKeyMessage(op);\n },\n getStashedOpLocalMetadata: (op: IMapSetOperation) => {\n // We don't reuse the metadata but send a new one on each submit.\n return this.getMapKeyMessageLocalMetadata(op);\n },\n });\n\n return messageHandlers;\n }\n\n private getMapClearMessageLocalMetadata(op: IMapClearOperation): number {\n const pendingMessageId = ++this.pendingMessageId;\n this.pendingClearMessageId = pendingMessageId;\n return pendingMessageId;\n }\n\n /**\n * Submit a clear message to remote clients.\n * @param op - The clear message\n */\n private submitMapClearMessage(op: IMapClearOperation): void {\n const pendingMessageId = this.getMapClearMessageLocalMetadata(op);\n this.submitMessage(op, pendingMessageId);\n }\n\n private getMapKeyMessageLocalMetadata(op: IMapKeyOperation): number {\n const pendingMessageId = ++this.pendingMessageId;\n this.pendingKeys.set(op.key, pendingMessageId);\n return pendingMessageId;\n }\n\n /**\n * Submit a map key message to remote clients.\n * @param op - The map key message\n */\n private submitMapKeyMessage(op: IMapKeyOperation): void {\n const pendingMessageId = this.getMapKeyMessageLocalMetadata(op);\n this.submitMessage(op, pendingMessageId);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"mapKernel.js","sourceRoot":"","sources":["../src/mapKernel.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,2EAAiF;AACjF,+DAAyE;AAMzE,+CAIuB;AAoHvB,SAAS,uBAAuB,CAAC,QAAa;IAC1C,OAAO,QAAQ,KAAK,SAAS,IAAI,OAAO,QAAQ,CAAC,gBAAgB,KAAK,QAAQ;QAC1E,CAAC,QAAQ,CAAC,IAAI,KAAK,KAAK,IAAI,QAAQ,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC;AAC9D,CAAC;AAED,SAAS,sBAAsB,CAAC,QAAa;IACzC,OAAO,QAAQ,KAAK,SAAS,IAAI,QAAQ,CAAC,IAAI,KAAK,OAAO,IAAI,OAAO,QAAQ,CAAC,gBAAgB,KAAK,QAAQ,CAAC;AAChH,CAAC;AAED,SAAS,oBAAoB,CAAC,QAAa;IACvC,OAAO,QAAQ,KAAK,SAAS,IAAI,OAAO,QAAQ,CAAC,gBAAgB,KAAK,QAAQ;QAC1E,CAAC,QAAQ,CAAC,IAAI,KAAK,KAAK,IAAI,QAAQ,CAAC,IAAI,KAAK,MAAM,IAAI,QAAQ,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC;AAC3F,CAAC;AAED;;GAEG;AACH,MAAa,SAAS;IAsClB;;;;;;;;OAQG;IACH,YACqB,UAA4B,EAC5B,MAAoB,EACpB,aAA0D,EAC1D,UAAyB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C,CAAC;QACrD,MAAM,aAAa,GAAG,eAAe,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC;YACnD,EAAE,IAAI,EAAE,MAAM,EAAE,gBAAgB,EAAE,aAAa,EAAE,eAAe,CAAC,aAAa,EAAE,CAAC,CAAC;YAClF,EAAE,IAAI,EAAE,KAAK,EAAE,gBAAgB,EAAE,CAAC;QACtC,IAAI,CAAC,aAAa,CAAC,EAAE,EAAE,aAAa,CAAC,CAAC;IAC1C,CAAC;CACJ;AA9mBD,8BA8mBC","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 { IFluidSerializer, ValueType } from \"@fluidframework/shared-object-base\";\nimport { assert, TypedEventEmitter } from \"@fluidframework/common-utils\";\nimport {\n ISerializableValue,\n ISerializedValue,\n ISharedMapEvents,\n} from \"./interfaces\";\nimport {\n ILocalValue,\n LocalValueMaker,\n makeSerializable,\n} from \"./localValues\";\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 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 localOpMetadata: unknown,\n ): void;\n\n /**\n * Communicate the operation to remote clients.\n * @param op - The map operation to submit\n * @param localOpMetadata - The metadata to be submitted with the message.\n */\n submit(op: IMapOperation, localOpMetadata: unknown): void;\n\n getStashedOpLocalMetadata(op: IMapOperation): unknown;\n}\n\n/**\n * Operation indicating a value should be set for a key.\n */\nexport interface IMapSetOperation {\n /**\n * String identifier of the operation type.\n */\n type: \"set\";\n\n /**\n * Map key being modified.\n */\n key: string;\n\n /**\n * Value to be set on the key.\n */\n value: ISerializableValue;\n}\n\n/**\n * Operation indicating a key should be deleted from the map.\n */\nexport interface IMapDeleteOperation {\n /**\n * String identifier of the operation type.\n */\n type: \"delete\";\n\n /**\n * Map key being modified.\n */\n key: string;\n}\n\n/**\n * Map key operations are one of several types.\n */\nexport type IMapKeyOperation = IMapSetOperation | IMapDeleteOperation;\n\n/**\n * Operation indicating the map should be cleared.\n */\nexport interface IMapClearOperation {\n /**\n * String identifier of the operation type.\n */\n type: \"clear\";\n}\n\n/**\n * Description of a map delta operation\n */\nexport type IMapOperation = IMapKeyOperation | IMapClearOperation;\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\ninterface IMapKeyEditLocalOpMetadata {\n type: \"edit\";\n pendingMessageId: number;\n previousValue?: ILocalValue;\n}\n\ninterface IMapKeyAddLocalOpMetadata {\n type: \"add\";\n pendingMessageId: number;\n}\n\ninterface IMapClearLocalOpMetadata {\n type: \"clear\";\n pendingMessageId: number;\n previousMap?: Map<string, ILocalValue>;\n}\n\ntype MapKeyLocalOpMetadata = IMapKeyEditLocalOpMetadata | IMapKeyAddLocalOpMetadata;\ntype MapLocalOpMetadata = IMapClearLocalOpMetadata | MapKeyLocalOpMetadata;\n\nfunction isMapKeyLocalOpMetadata(metadata: any): metadata is MapKeyLocalOpMetadata {\n return metadata !== undefined && typeof metadata.pendingMessageId === \"number\" &&\n (metadata.type === \"add\" || metadata.type === \"edit\");\n}\n\nfunction isClearLocalOpMetadata(metadata: any): metadata is IMapClearLocalOpMetadata {\n return metadata !== undefined && metadata.type === \"clear\" && typeof metadata.pendingMessageId === \"number\";\n}\n\nfunction isMapLocalOpMetadata(metadata: any): metadata is MapLocalOpMetadata {\n return metadata !== undefined && typeof metadata.pendingMessageId === \"number\" &&\n (metadata.type === \"add\" || metadata.type === \"edit\" || metadata.type === \"clear\");\n}\n\n/**\n * A SharedMap is a map-like distributed data structure.\n */\nexport class MapKernel {\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, ILocalValue>();\n\n /**\n * Keys that have been modified locally but not yet ack'd from the server.\n */\n private readonly pendingKeys: Map<string, number[]> = new Map();\n\n /**\n * This is used to assign a unique id to every outgoing operation and helps in tracking unack'd ops.\n */\n private pendingMessageId: number = -1;\n\n /**\n * The pending ids of any clears that have been performed locally but not yet ack'd from the server\n */\n private readonly pendingClearMessageIds: number[] = [];\n\n /**\n * Object to create encapsulations of the values stored in the map.\n */\n private readonly localValueMaker: LocalValueMaker;\n\n /**\n * Create a new shared map kernel.\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 isAttached - To query whether the shared object should generate ops\n * @param valueTypes - The value types to register\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: unknown) => void,\n private readonly isAttached: () => boolean,\n private readonly eventEmitter: TypedEventEmitter<ISharedMapEvents>,\n ) {\n this.localValueMaker = new LocalValueMaker(serializer);\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<T = any>(key: string): T | undefined {\n const localValue = this.data.get(key);\n return localValue === undefined ? undefined : localValue.value as T;\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 * {@inheritDoc ISharedMap.set}\n */\n public set(key: string, value: any) {\n // Undefined/null keys can't be serialized to JSON in the manner we currently snapshot.\n if (key === undefined || key === null) {\n throw new Error(\"Undefined and null keys are not supported\");\n }\n\n // Create a local value and serialize it.\n const localValue = this.localValueMaker.fromInMemory(value);\n const serializableValue = makeSerializable(\n localValue,\n this.serializer,\n this.handle);\n\n // Set the value locally.\n const previousValue = this.setCore(\n key,\n localValue,\n true,\n );\n\n // If we are not attached, don't submit the op.\n if (!this.isAttached()) {\n return;\n }\n\n const op: IMapSetOperation = {\n key,\n type: \"set\",\n value: serializableValue,\n };\n this.submitMapKeyMessage(op, previousValue);\n }\n\n /**\n * Delete a key from the map.\n * @param key - Key to delete\n * @returns True if the key existed and was deleted, false if it did not exist\n */\n public delete(key: string): boolean {\n // Delete the key locally first.\n const previousValue = this.deleteCore(key, true);\n\n // If we are not attached, don't submit the op.\n if (!this.isAttached()) {\n return previousValue !== undefined;\n }\n\n const op: IMapDeleteOperation = {\n key,\n type: \"delete\",\n };\n this.submitMapKeyMessage(op, previousValue);\n\n return previousValue !== undefined;\n }\n\n /**\n * Clear all data from the map.\n */\n public clear(): void {\n const copy = this.isAttached() ? new Map<string, ILocalValue>(this.data) : undefined;\n\n // Clear the data locally first.\n this.clearCore(true);\n\n // If we are not attached, don't submit the op.\n if (!this.isAttached()) {\n return;\n }\n\n const op: IMapClearOperation = {\n type: \"clear\",\n };\n this.submitMapClearMessage(op, copy);\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 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: unknown): boolean {\n const handler = this.messageHandlers.get(op.type);\n if (handler === undefined) {\n return false;\n }\n handler.submit(op as IMapOperation, localOpMetadata);\n return true;\n }\n\n public tryGetStashedOpLocalMetadata(op: any): unknown {\n const handler = this.messageHandlers.get(op.type);\n if (handler === undefined) {\n throw new Error(\"no apply stashed op handler\");\n }\n return handler.getStashedOpLocalMetadata(op as IMapOperation);\n }\n\n /**\n * Process the given op if a handler is registered.\n * @param op - 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 localOpMetadata: unknown,\n ): boolean {\n const handler = this.messageHandlers.get(op.type);\n if (handler === undefined) {\n return false;\n }\n handler.process(op, local, localOpMetadata);\n return true;\n }\n\n /**\n * Rollback a local op\n * @param op - The operation to rollback\n * @param localOpMetadata - The local metadata associated with the op.\n */\n public rollback(op: any, localOpMetadata: unknown) {\n if (!isMapLocalOpMetadata(localOpMetadata)) {\n throw new Error(\"Invalid localOpMetadata\");\n }\n\n if (op.type === \"clear\" && localOpMetadata.type === \"clear\") {\n if (localOpMetadata.previousMap === undefined) {\n throw new Error(\"Cannot rollback without previous map\");\n }\n localOpMetadata.previousMap.forEach((localValue, key) => {\n this.setCore(key, localValue, true);\n });\n\n const lastPendingClearId = this.pendingClearMessageIds.pop();\n if (lastPendingClearId === undefined || lastPendingClearId !== localOpMetadata.pendingMessageId) {\n throw new Error(\"Rollback op does match last clear\");\n }\n } else if (op.type === \"delete\" || op.type === \"set\") {\n if (localOpMetadata.type === \"add\") {\n this.deleteCore(op.key, true);\n } else if (localOpMetadata.type === \"edit\" && localOpMetadata.previousValue !== undefined) {\n this.setCore(op.key, localOpMetadata.previousValue, true);\n } else {\n throw new Error(\"Cannot rollback without previous value\");\n }\n\n const pendingMessageIds = this.pendingKeys.get(op.key);\n const lastPendingMessageId = pendingMessageIds?.pop();\n if (!pendingMessageIds || lastPendingMessageId !== localOpMetadata.pendingMessageId) {\n throw new Error(\"Rollback op does not match last pending\");\n }\n if (pendingMessageIds.length === 0) {\n this.pendingKeys.delete(op.key);\n }\n } else {\n throw new Error(\"Unsupported op for rollback\");\n }\n }\n\n /**\n * Set implementation used for both locally sourced sets as well as incoming remote sets.\n * @param key - The key being set\n * @param value - The value being set\n * @param local - Whether the message originated from the local client\n * @returns Previous local value of the key, if any\n */\n private setCore(key: string, value: ILocalValue, local: boolean): ILocalValue | undefined {\n const previousLocalValue = this.data.get(key);\n const previousValue = previousLocalValue?.value;\n this.data.set(key, value);\n this.eventEmitter.emit(\"valueChanged\", { key, previousValue }, local, this.eventEmitter);\n return previousLocalValue;\n }\n\n /**\n * Clear implementation used for both locally sourced clears as well as incoming remote clears.\n * @param local - Whether the message originated from the local client\n */\n private clearCore(local: boolean): void {\n this.data.clear();\n this.eventEmitter.emit(\"clear\", local, this.eventEmitter);\n }\n\n /**\n * Delete implementation used for both locally sourced deletes as well as incoming remote deletes.\n * @param key - The key being deleted\n * @param local - Whether the message originated from the local client\n * @returns Previous local value of the key if it existed, undefined if it did not exist\n */\n private deleteCore(key: string, local: boolean): ILocalValue | undefined {\n const previousLocalValue = this.data.get(key);\n const previousValue = previousLocalValue?.value;\n const successfullyRemoved = this.data.delete(key);\n if (successfullyRemoved) {\n this.eventEmitter.emit(\"valueChanged\", { key, previousValue }, local, this.eventEmitter);\n }\n return previousLocalValue;\n }\n\n /**\n * Clear all keys in memory in response to a remote clear, but retain keys we have modified but not yet been ack'd.\n */\n private clearExceptPendingKeys(): void {\n // Assuming the pendingKeys is small and the map is large\n // we will get the value for the pendingKeys and clear the map\n const temp = new Map<string, ILocalValue>();\n this.pendingKeys.forEach((value, key) => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n temp.set(key, this.data.get(key)!);\n });\n this.clearCore(false);\n temp.forEach((value, key) => {\n this.setCore(key, value, true);\n });\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): ILocalValue {\n if (serializable.type === ValueType[ValueType.Plain] || serializable.type === ValueType[ValueType.Shared]) {\n return this.localValueMaker.fromSerializable(serializable);\n } else {\n throw new Error(\"Unknown local value type\");\n }\n }\n\n /**\n * If our local operations that have not yet been ack'd will eventually overwrite an incoming operation, we should\n * not process the incoming operation.\n * @param op - Operation to check\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 should be processed, false otherwise\n */\n private needProcessKeyOperation(\n op: IMapKeyOperation,\n local: boolean,\n localOpMetadata: unknown,\n ): boolean {\n if (this.pendingClearMessageIds.length > 0) {\n if (local) {\n assert(localOpMetadata !== undefined && isMapKeyLocalOpMetadata(localOpMetadata) &&\n localOpMetadata.pendingMessageId < this.pendingClearMessageIds[0],\n 0x013 /* \"Received out of order op when there is an unackd clear message\" */);\n }\n // If we have an unack'd clear, we can ignore all ops.\n return false;\n }\n\n const pendingKeyMessageId = this.pendingKeys.get(op.key);\n if (pendingKeyMessageId !== undefined) {\n // Found an unack'd op. Clear it from the map if the pendingMessageId in the map matches this message's\n // and don't process the op.\n if (local) {\n assert(localOpMetadata !== undefined && isMapKeyLocalOpMetadata(localOpMetadata),\n 0x014 /* pendingMessageId is missing from the local client's operation */);\n const pendingMessageIds = this.pendingKeys.get(op.key);\n assert(pendingMessageIds !== undefined && pendingMessageIds[0] === localOpMetadata.pendingMessageId,\n 0x2fa /* Unexpected pending message received */);\n pendingMessageIds.shift();\n if (pendingMessageIds.length === 0) {\n this.pendingKeys.delete(op.key);\n }\n }\n return false;\n }\n\n // If we don't have a NACK op on the key, we need to process the remote ops.\n return !local;\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 messageHandlers.set(\n \"clear\",\n {\n process: (op: IMapClearOperation, local, localOpMetadata) => {\n if (local) {\n assert(isClearLocalOpMetadata(localOpMetadata),\n 0x015 /* \"pendingMessageId is missing from the local client's clear operation\" */);\n const pendingClearMessageId = this.pendingClearMessageIds.shift();\n assert(pendingClearMessageId === localOpMetadata.pendingMessageId,\n 0x2fb /* pendingMessageId does not match */);\n return;\n }\n if (this.pendingKeys.size !== 0) {\n this.clearExceptPendingKeys();\n return;\n }\n this.clearCore(local);\n },\n submit: (op: IMapClearOperation, localOpMetadata: unknown) => {\n assert(isClearLocalOpMetadata(localOpMetadata), 0x2fc /* Invalid localOpMetadata for clear */);\n // We don't reuse the metadata pendingMessageId but send a new one on each submit.\n const pendingClearMessageId = this.pendingClearMessageIds.shift();\n assert(pendingClearMessageId === localOpMetadata.pendingMessageId,\n 0x2fd /* pendingMessageId does not match */);\n this.submitMapClearMessage(op, localOpMetadata.previousMap);\n },\n getStashedOpLocalMetadata: (op: IMapClearOperation) => {\n // We don't reuse the metadata pendingMessageId but send a new one on each submit.\n return { type: \"clear\", pendingMessageId: this.getMapClearMessageId() };\n },\n });\n messageHandlers.set(\n \"delete\",\n {\n process: (op: IMapDeleteOperation, local, localOpMetadata) => {\n if (!this.needProcessKeyOperation(op, local, localOpMetadata)) {\n return;\n }\n this.deleteCore(op.key, local);\n },\n submit: (op: IMapDeleteOperation, localOpMetadata: unknown) => {\n this.resubmitMapKeyMessage(op, localOpMetadata);\n },\n getStashedOpLocalMetadata: (op: IMapDeleteOperation) => {\n // We don't reuse the metadata pendingMessageId but send a new one on each submit.\n return { type: \"edit\", pendingMessageId: this.getMapKeyMessageId(op) };\n },\n });\n messageHandlers.set(\n \"set\",\n {\n process: (op: IMapSetOperation, local, localOpMetadata) => {\n if (!this.needProcessKeyOperation(op, local, localOpMetadata)) {\n return;\n }\n\n // needProcessKeyOperation should have returned false if local is true\n const context = this.makeLocal(op.key, op.value);\n this.setCore(op.key, context, local);\n },\n submit: (op: IMapSetOperation, localOpMetadata: unknown) => {\n this.resubmitMapKeyMessage(op, localOpMetadata);\n },\n getStashedOpLocalMetadata: (op: IMapSetOperation) => {\n // We don't reuse the metadata pendingMessageId but send a new one on each submit.\n return { type: \"edit\", pendingMessageId: this.getMapKeyMessageId(op) };\n },\n });\n\n return messageHandlers;\n }\n\n private getMapClearMessageId(): number {\n const pendingMessageId = ++this.pendingMessageId;\n this.pendingClearMessageIds.push(pendingMessageId);\n return pendingMessageId;\n }\n\n /**\n * Submit a clear message to remote clients.\n * @param op - The clear message\n */\n private submitMapClearMessage(op: IMapClearOperation, previousMap?: Map<string, ILocalValue>): void {\n const metadata = { type: \"clear\", pendingMessageId: this.getMapClearMessageId(), previousMap };\n this.submitMessage(op, metadata);\n }\n\n private getMapKeyMessageId(op: IMapKeyOperation): number {\n const pendingMessageId = ++this.pendingMessageId;\n const pendingMessageIds = this.pendingKeys.get(op.key);\n if (pendingMessageIds !== undefined) {\n pendingMessageIds.push(pendingMessageId);\n } else {\n this.pendingKeys.set(op.key, [pendingMessageId]);\n }\n return pendingMessageId;\n }\n\n /**\n * Submit a map key message to remote clients.\n * @param op - The map key message\n * @param previousValue - The value of the key before this op\n */\n private submitMapKeyMessage(op: IMapKeyOperation, previousValue?: ILocalValue): void {\n const pendingMessageId = this.getMapKeyMessageId(op);\n const localMetadata = previousValue ?\n { type: \"edit\", pendingMessageId, previousValue } :\n { type: \"add\", pendingMessageId };\n this.submitMessage(op, localMetadata);\n }\n\n /**\n * Submit a map key message to remote clients based on a previous submit.\n * @param op - The map key message\n * @param localOpMetadata - Metadata from the previous submit\n */\n private resubmitMapKeyMessage(op: IMapKeyOperation, localOpMetadata: unknown): void {\n assert(isMapKeyLocalOpMetadata(localOpMetadata), 0x2fe /* Invalid localOpMetadata in submit */);\n\n // clear the old pending message id\n const pendingMessageIds = this.pendingKeys.get(op.key);\n assert(pendingMessageIds !== undefined && pendingMessageIds[0] === localOpMetadata.pendingMessageId,\n 0x2ff /* Unexpected pending message received */);\n pendingMessageIds.shift();\n if (pendingMessageIds.length === 0) {\n this.pendingKeys.delete(op.key);\n }\n\n // We don't reuse the metadata pendingMessageId but send a new one on each submit.\n const pendingMessageId = this.getMapKeyMessageId(op);\n const localMetadata = localOpMetadata.type === \"edit\" ?\n { type: \"edit\", pendingMessageId, previousValue: localOpMetadata.previousValue } :\n { type: \"add\", pendingMessageId };\n this.submitMessage(op, localMetadata);\n }\n}\n"]}
|
package/dist/packageVersion.d.ts
CHANGED
package/dist/packageVersion.js
CHANGED