@fluidframework/sequence 0.59.3003 → 0.59.4000

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/dist/{mapKernel.d.ts → defaultMap.d.ts} +21 -145
  2. package/dist/defaultMap.d.ts.map +1 -0
  3. package/dist/defaultMap.js +317 -0
  4. package/dist/defaultMap.js.map +1 -0
  5. package/dist/{mapKernelInterfaces.d.ts → defaultMapInterfaces.d.ts} +9 -51
  6. package/dist/defaultMapInterfaces.d.ts.map +1 -0
  7. package/dist/{mapKernelInterfaces.js → defaultMapInterfaces.js} +1 -1
  8. package/dist/defaultMapInterfaces.js.map +1 -0
  9. package/dist/index.d.ts +1 -1
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js.map +1 -1
  12. package/dist/intervalCollection.d.ts +12 -3
  13. package/dist/intervalCollection.d.ts.map +1 -1
  14. package/dist/intervalCollection.js +44 -39
  15. package/dist/intervalCollection.js.map +1 -1
  16. package/dist/localValues.d.ts +7 -86
  17. package/dist/localValues.d.ts.map +1 -1
  18. package/dist/localValues.js +1 -131
  19. package/dist/localValues.js.map +1 -1
  20. package/dist/packageVersion.d.ts +1 -1
  21. package/dist/packageVersion.js +1 -1
  22. package/dist/packageVersion.js.map +1 -1
  23. package/dist/sequence.d.ts +5 -1
  24. package/dist/sequence.d.ts.map +1 -1
  25. package/dist/sequence.js +23 -23
  26. package/dist/sequence.js.map +1 -1
  27. package/dist/sharedIntervalCollection.d.ts +13 -5
  28. package/dist/sharedIntervalCollection.d.ts.map +1 -1
  29. package/dist/sharedIntervalCollection.js +16 -12
  30. package/dist/sharedIntervalCollection.js.map +1 -1
  31. package/lib/{mapKernel.d.ts → defaultMap.d.ts} +21 -145
  32. package/lib/defaultMap.d.ts.map +1 -0
  33. package/lib/defaultMap.js +313 -0
  34. package/lib/defaultMap.js.map +1 -0
  35. package/lib/{mapKernelInterfaces.d.ts → defaultMapInterfaces.d.ts} +9 -51
  36. package/lib/defaultMapInterfaces.d.ts.map +1 -0
  37. package/lib/{mapKernelInterfaces.js → defaultMapInterfaces.js} +1 -1
  38. package/lib/defaultMapInterfaces.js.map +1 -0
  39. package/lib/index.d.ts +1 -1
  40. package/lib/index.d.ts.map +1 -1
  41. package/lib/index.js.map +1 -1
  42. package/lib/intervalCollection.d.ts +12 -3
  43. package/lib/intervalCollection.d.ts.map +1 -1
  44. package/lib/intervalCollection.js +44 -39
  45. package/lib/intervalCollection.js.map +1 -1
  46. package/lib/localValues.d.ts +7 -86
  47. package/lib/localValues.d.ts.map +1 -1
  48. package/lib/localValues.js +1 -129
  49. package/lib/localValues.js.map +1 -1
  50. package/lib/packageVersion.d.ts +1 -1
  51. package/lib/packageVersion.js +1 -1
  52. package/lib/packageVersion.js.map +1 -1
  53. package/lib/sequence.d.ts +5 -1
  54. package/lib/sequence.d.ts.map +1 -1
  55. package/lib/sequence.js +23 -23
  56. package/lib/sequence.js.map +1 -1
  57. package/lib/sharedIntervalCollection.d.ts +13 -5
  58. package/lib/sharedIntervalCollection.d.ts.map +1 -1
  59. package/lib/sharedIntervalCollection.js +16 -12
  60. package/lib/sharedIntervalCollection.js.map +1 -1
  61. package/package.json +23 -18
  62. package/src/defaultMap.ts +453 -0
  63. package/src/{mapKernelInterfaces.ts → defaultMapInterfaces.ts} +14 -59
  64. package/src/index.ts +1 -1
  65. package/src/intervalCollection.ts +58 -43
  66. package/src/localValues.ts +6 -154
  67. package/src/packageVersion.ts +1 -1
  68. package/src/sequence.ts +32 -33
  69. package/src/sharedIntervalCollection.ts +22 -25
  70. package/dist/mapKernel.d.ts.map +0 -1
  71. package/dist/mapKernel.js +0 -599
  72. package/dist/mapKernel.js.map +0 -1
  73. package/dist/mapKernelInterfaces.d.ts.map +0 -1
  74. package/dist/mapKernelInterfaces.js.map +0 -1
  75. package/lib/mapKernel.d.ts.map +0 -1
  76. package/lib/mapKernel.js +0 -595
  77. package/lib/mapKernel.js.map +0 -1
  78. package/lib/mapKernelInterfaces.d.ts.map +0 -1
  79. package/lib/mapKernelInterfaces.js.map +0 -1
  80. package/src/mapKernel.ts +0 -850
package/dist/mapKernel.js DELETED
@@ -1,599 +0,0 @@
1
- "use strict";
2
- /*!
3
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
- * Licensed under the MIT License.
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.MapKernel = void 0;
8
- const shared_object_base_1 = require("@fluidframework/shared-object-base");
9
- const common_utils_1 = require("@fluidframework/common-utils");
10
- const localValues_1 = require("./localValues");
11
- /**
12
- * A SharedMap is a map-like distributed data structure.
13
- */
14
- class MapKernel {
15
- /**
16
- * Create a new shared map kernel.
17
- * @param serializer - The serializer to serialize / parse handles
18
- * @param handle - The handle of the shared object using the kernel
19
- * @param submitMessage - A callback to submit a message through the shared object
20
- * @param isAttached - To query whether the shared object should generate ops
21
- * @param valueTypes - The value types to register
22
- * @param eventEmitter - The object that will emit map events
23
- */
24
- constructor(serializer, handle, submitMessage, isAttached, valueTypes, eventEmitter = new common_utils_1.TypedEventEmitter()) {
25
- this.serializer = serializer;
26
- this.handle = handle;
27
- this.submitMessage = submitMessage;
28
- this.isAttached = isAttached;
29
- this.eventEmitter = eventEmitter;
30
- /**
31
- * Mapping of op types to message handlers.
32
- */
33
- this.messageHandlers = new Map();
34
- /**
35
- * The in-memory data the map is storing.
36
- */
37
- this.data = new Map();
38
- /**
39
- * Keys that have been modified locally but not yet ack'd from the server.
40
- */
41
- this.pendingKeys = new Map();
42
- /**
43
- * This is used to assign a unique id to every outgoing operation and helps in tracking unacked ops.
44
- */
45
- this.pendingMessageId = -1;
46
- /**
47
- * If a clear has been performed locally but not yet ack'd from the server, then this stores the pending id
48
- * of that clear operation. Otherwise, is -1.
49
- */
50
- this.pendingClearMessageId = -1;
51
- this.lastProcessedSeq = -1;
52
- this.localValueMaker = new localValues_1.LocalValueMaker(serializer);
53
- this.messageHandlers = this.getMessageHandlers();
54
- for (const type of valueTypes) {
55
- this.localValueMaker.registerValueType(type);
56
- }
57
- }
58
- /**
59
- * The number of key/value pairs stored in the map.
60
- */
61
- get size() {
62
- return this.data.size;
63
- }
64
- /**
65
- * Get an iterator over the keys in this map.
66
- * @returns The iterator
67
- */
68
- keys() {
69
- return this.data.keys();
70
- }
71
- /**
72
- * Get an iterator over the entries in this map.
73
- * @returns The iterator
74
- */
75
- entries() {
76
- const localEntriesIterator = this.data.entries();
77
- const iterator = {
78
- next() {
79
- const nextVal = localEntriesIterator.next();
80
- if (nextVal.done) {
81
- return { value: undefined, done: true };
82
- }
83
- else {
84
- // Unpack the stored value
85
- return { value: [nextVal.value[0], nextVal.value[1].value], done: false };
86
- }
87
- },
88
- [Symbol.iterator]() {
89
- return this;
90
- },
91
- };
92
- return iterator;
93
- }
94
- /**
95
- * Get an iterator over the values in this map.
96
- * @returns The iterator
97
- */
98
- values() {
99
- const localValuesIterator = this.data.values();
100
- const iterator = {
101
- next() {
102
- const nextVal = localValuesIterator.next();
103
- if (nextVal.done) {
104
- return { value: undefined, done: true };
105
- }
106
- else {
107
- // Unpack the stored value
108
- return { value: nextVal.value.value, done: false };
109
- }
110
- },
111
- [Symbol.iterator]() {
112
- return this;
113
- },
114
- };
115
- return iterator;
116
- }
117
- /**
118
- * Get an iterator over the entries in this map.
119
- * @returns The iterator
120
- */
121
- [Symbol.iterator]() {
122
- return this.entries();
123
- }
124
- /**
125
- * Executes the given callback on each entry in the map.
126
- * @param callbackFn - Callback function
127
- */
128
- forEach(callbackFn) {
129
- this.data.forEach((localValue, key, m) => {
130
- callbackFn(localValue.value, key, m);
131
- });
132
- }
133
- /**
134
- * {@inheritDoc ISharedMap.get}
135
- */
136
- get(key) {
137
- if (!this.data.has(key)) {
138
- return undefined;
139
- }
140
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
141
- const localValue = this.data.get(key);
142
- return localValue.value;
143
- }
144
- /**
145
- * {@inheritDoc ISharedMap.wait}
146
- */
147
- async wait(key) {
148
- // Return immediately if the value already exists
149
- if (this.has(key)) {
150
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
151
- return this.get(key);
152
- }
153
- // Otherwise subscribe to changes
154
- return new Promise((resolve) => {
155
- const callback = (changed) => {
156
- if (key === changed.key) {
157
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
158
- resolve(this.get(changed.key));
159
- this.eventEmitter.removeListener("create", callback);
160
- }
161
- };
162
- this.eventEmitter.on("create", callback);
163
- });
164
- }
165
- /**
166
- * Check if a key exists in the map.
167
- * @param key - The key to check
168
- * @returns True if the key exists, false otherwise
169
- */
170
- has(key) {
171
- return this.data.has(key);
172
- }
173
- /**
174
- * {@inheritDoc ISharedMap.set}
175
- */
176
- set(key, value) {
177
- // Undefined/null keys can't be serialized to JSON in the manner we currently snapshot.
178
- if (key === undefined || key === null) {
179
- throw new Error("Undefined and null keys are not supported");
180
- }
181
- // Create a local value and serialize it.
182
- const localValue = this.localValueMaker.fromInMemory(value);
183
- const serializableValue = (0, localValues_1.makeSerializable)(localValue, this.serializer, this.handle);
184
- // Set the value locally.
185
- this.setCore(key, localValue, true, undefined);
186
- // If we are not attached, don't submit the op.
187
- if (!this.isAttached()) {
188
- return;
189
- }
190
- const op = {
191
- key,
192
- type: "set",
193
- value: serializableValue,
194
- };
195
- this.submitMapKeyMessage(op);
196
- }
197
- /**
198
- * {@inheritDoc IValueTypeCreator.createValueType}
199
- */
200
- createValueType(key, type, params) {
201
- // Create a local value and serialize it.
202
- const localValue = this.localValueMaker.makeValueType(type, this.makeMapValueOpEmitter(key), params);
203
- // TODO ideally we could use makeSerialized in this case as well. But the interval
204
- // collection has assumptions of attach being called prior. Given the IFluidSerializer it
205
- // may be possible to remove custom value type serialization entirely.
206
- const transformedValue = (0, shared_object_base_1.makeHandlesSerializable)(params, this.serializer, this.handle);
207
- // Set the value locally.
208
- this.setCore(key, localValue, true, undefined);
209
- // If we are not attached, don't submit the op.
210
- if (!this.isAttached()) {
211
- return this;
212
- }
213
- // This is a special form of serialized valuetype only used for set, containing info for initialization.
214
- // After initialization, the serialized form will need to come from the .store of the value type's factory.
215
- const serializableValue = { type, value: transformedValue };
216
- const op = {
217
- key,
218
- type: "set",
219
- value: serializableValue,
220
- };
221
- this.submitMapKeyMessage(op);
222
- return this;
223
- }
224
- /**
225
- * Delete a key from the map.
226
- * @param key - Key to delete
227
- * @returns True if the key existed and was deleted, false if it did not exist
228
- */
229
- delete(key) {
230
- // Delete the key locally first.
231
- const successfullyRemoved = this.deleteCore(key, true, undefined);
232
- // If we are not attached, don't submit the op.
233
- if (!this.isAttached()) {
234
- return successfullyRemoved;
235
- }
236
- const op = {
237
- key,
238
- type: "delete",
239
- };
240
- this.submitMapKeyMessage(op);
241
- return successfullyRemoved;
242
- }
243
- /**
244
- * Clear all data from the map.
245
- */
246
- clear() {
247
- // Clear the data locally first.
248
- this.clearCore(true, undefined);
249
- // If we are not attached, don't submit the op.
250
- if (!this.isAttached()) {
251
- return;
252
- }
253
- const op = {
254
- type: "clear",
255
- };
256
- this.submitMapClearMessage(op);
257
- }
258
- /**
259
- * Serializes the data stored in the shared map to a JSON string
260
- * @param serializer - The serializer to use to serialize handles in its values.
261
- * @returns A JSON string containing serialized map data
262
- */
263
- getSerializedStorage(serializer) {
264
- const serializableMapData = {};
265
- this.data.forEach((localValue, key) => {
266
- serializableMapData[key] = localValue.makeSerialized(serializer, this.handle);
267
- });
268
- return serializableMapData;
269
- }
270
- getSerializableStorage(serializer) {
271
- const serializableMapData = {};
272
- this.data.forEach((localValue, key) => {
273
- serializableMapData[key] = (0, localValues_1.makeSerializable)(localValue, serializer, this.handle);
274
- });
275
- return serializableMapData;
276
- }
277
- serialize(serializer) {
278
- return JSON.stringify(this.getSerializableStorage(serializer));
279
- }
280
- /**
281
- * Populate the kernel with the given map data.
282
- * @param data - A JSON string containing serialized map data
283
- */
284
- populateFromSerializable(json) {
285
- for (const [key, serializable] of Object.entries(json)) {
286
- const localValue = {
287
- key,
288
- value: this.makeLocal(key, serializable),
289
- };
290
- this.data.set(localValue.key, localValue.value);
291
- }
292
- }
293
- populate(json) {
294
- this.populateFromSerializable(JSON.parse(json));
295
- }
296
- /**
297
- * Submit the given op if a handler is registered.
298
- * @param op - The operation to attempt to submit
299
- * @param localOpMetadata - The local metadata associated with the op. This is kept locally by the runtime
300
- * and not sent to the server. This will be sent back when this message is received back from the server. This is
301
- * also sent if we are asked to resubmit the message.
302
- * @returns True if the operation was submitted, false otherwise.
303
- */
304
- trySubmitMessage(op, localOpMetadata) {
305
- const type = op.type;
306
- if (this.messageHandlers.has(type)) {
307
- const mapLocalMetadata = localOpMetadata;
308
- // we don't know how to rebase these operations, so if any other op has come in
309
- // we will fail.
310
- if (this.lastProcessedSeq !== (mapLocalMetadata === null || mapLocalMetadata === void 0 ? void 0 : mapLocalMetadata.lastProcessedSeq)) {
311
- throw new Error("SharedInterval does not support reconnect in presence of external changes");
312
- }
313
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
314
- this.messageHandlers.get(type).submit(op);
315
- return true;
316
- }
317
- return false;
318
- }
319
- tryGetStashedOpLocalMetadata(op) {
320
- const type = op.type;
321
- if (this.messageHandlers.has(type)) {
322
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
323
- return this.messageHandlers.get(type).getStashedOpLocalMetadata(op);
324
- }
325
- throw new Error("no apply stashed op handler");
326
- }
327
- /**
328
- * Process the given op if a handler is registered.
329
- * @param message - The message to process
330
- * @param local - Whether the message originated from the local client
331
- * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.
332
- * For messages from a remote client, this will be undefined.
333
- * @returns True if the operation was processed, false otherwise.
334
- */
335
- tryProcessMessage(op, local, message, localOpMetadata) {
336
- // track the seq of every incoming message, so we can detect if any
337
- // changes happened during a resubmit
338
- this.lastProcessedSeq = message.sequenceNumber;
339
- if (this.messageHandlers.has(op.type)) {
340
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
341
- this.messageHandlers
342
- .get(op.type)
343
- .process(op, local, message, localOpMetadata);
344
- return true;
345
- }
346
- return false;
347
- }
348
- /**
349
- * Set implementation used for both locally sourced sets as well as incoming remote sets.
350
- * @param key - The key being set
351
- * @param value - The value being set
352
- * @param local - Whether the message originated from the local client
353
- * @param op - The message if from a remote set, or null if from a local set
354
- */
355
- setCore(key, value, local, op) {
356
- const previousValue = this.get(key);
357
- this.data.set(key, value);
358
- const event = { key, previousValue };
359
- this.eventEmitter.emit("create", event, local, op, this.eventEmitter);
360
- }
361
- /**
362
- * Clear implementation used for both locally sourced clears as well as incoming remote clears.
363
- * @param local - Whether the message originated from the local client
364
- * @param op - The message if from a remote clear, or null if from a local clear
365
- */
366
- clearCore(local, op) {
367
- this.data.clear();
368
- this.eventEmitter.emit("clear", local, op, this.eventEmitter);
369
- }
370
- /**
371
- * Delete implementation used for both locally sourced deletes as well as incoming remote deletes.
372
- * @param key - The key being deleted
373
- * @param local - Whether the message originated from the local client
374
- * @param op - The message if from a remote delete, or null if from a local delete
375
- * @returns True if the key existed and was deleted, false if it did not exist
376
- */
377
- deleteCore(key, local, op) {
378
- const previousValue = this.get(key);
379
- const successfullyRemoved = this.data.delete(key);
380
- if (successfullyRemoved) {
381
- const event = { key, previousValue };
382
- this.eventEmitter.emit("valueChanged", event, local, op, this.eventEmitter);
383
- }
384
- return successfullyRemoved;
385
- }
386
- /**
387
- * Clear all keys in memory in response to a remote clear, but retain keys we have modified but not yet been ack'd.
388
- */
389
- clearExceptPendingKeys() {
390
- // Assuming the pendingKeys is small and the map is large
391
- // we will get the value for the pendingKeys and clear the map
392
- const temp = new Map();
393
- this.pendingKeys.forEach((value, key) => {
394
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
395
- temp.set(key, this.data.get(key));
396
- });
397
- this.data.clear();
398
- temp.forEach((value, key) => {
399
- this.data.set(key, value);
400
- });
401
- }
402
- /**
403
- * The remote ISerializableValue we're receiving (either as a result of a load or an incoming set op) will
404
- * have the information we need to create a real object, but will not be the real object yet. For example,
405
- * we might know it's a map and the map's ID but not have the actual map or its data yet. makeLocal's
406
- * job is to convert that information into a real object for local usage.
407
- * @param key - The key that the caller intends to store the local value into (used for ops later). But
408
- * doesn't actually store the local value into that key. So better not lie!
409
- * @param serializable - The remote information that we can convert into a real object
410
- * @returns The local value that was produced
411
- */
412
- makeLocal(key, serializable) {
413
- if (serializable.type === shared_object_base_1.ValueType[shared_object_base_1.ValueType.Plain] || serializable.type === shared_object_base_1.ValueType[shared_object_base_1.ValueType.Shared]) {
414
- return this.localValueMaker.fromSerializable(serializable);
415
- }
416
- else {
417
- return this.localValueMaker.fromSerializableValueType(serializable, this.makeMapValueOpEmitter(key));
418
- }
419
- }
420
- /**
421
- * If our local operations that have not yet been ack'd will eventually overwrite an incoming operation, we should
422
- * not process the incoming operation.
423
- * @param op - Operation to check
424
- * @param local - Whether the message originated from the local client
425
- * @param message - The message
426
- * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.
427
- * For messages from a remote client, this will be undefined.
428
- * @returns True if the operation should be processed, false otherwise
429
- */
430
- needProcessKeyOperation(op, local, localOpMetadata) {
431
- if (this.pendingClearMessageId !== -1) {
432
- if (local) {
433
- (0, common_utils_1.assert)((localOpMetadata === null || localOpMetadata === void 0 ? void 0 : localOpMetadata.pendingClearMessageId) !== undefined
434
- && localOpMetadata.pendingClearMessageId < this.pendingClearMessageId, 0x1f1 /* "Received out of order op when there is an unacked clear message" */);
435
- }
436
- // If we have an unacked clear, we can ignore all ops.
437
- return false;
438
- }
439
- if (this.pendingKeys.has(op.key)) {
440
- // Found an unacked op. Clear it from the map if the pendingMessageId in the map matches this message's
441
- // and don't process the op.
442
- if (local) {
443
- (0, common_utils_1.assert)(localOpMetadata !== undefined, 0x1f2 /* `pendingMessageId is missing from the local client's ${op.type} operation` */);
444
- const pendingMessageId = localOpMetadata.pendingMessageId;
445
- const pendingKeyMessageId = this.pendingKeys.get(op.key);
446
- if (pendingKeyMessageId === pendingMessageId) {
447
- this.pendingKeys.delete(op.key);
448
- }
449
- }
450
- return false;
451
- }
452
- // If we don't have a NACK op on the key, we need to process the remote ops.
453
- return !local;
454
- }
455
- /**
456
- * Get the message handlers for the map.
457
- * @returns A map of string op names to IMapMessageHandlers for those ops
458
- */
459
- getMessageHandlers() {
460
- const messageHandlers = new Map();
461
- messageHandlers.set("clear", {
462
- process: (op, local, message, localOpMetadata) => {
463
- if (local) {
464
- (0, common_utils_1.assert)(localOpMetadata !== undefined, 0x1f3 /* "pendingMessageId is missing from the local client's clear operation" */);
465
- const pendingMessageId = localOpMetadata === null || localOpMetadata === void 0 ? void 0 : localOpMetadata.pendingMessageId;
466
- if (this.pendingClearMessageId === pendingMessageId) {
467
- this.pendingClearMessageId = -1;
468
- }
469
- return;
470
- }
471
- if (this.pendingKeys.size !== 0) {
472
- this.clearExceptPendingKeys();
473
- return;
474
- }
475
- this.clearCore(local, message);
476
- },
477
- submit: (op) => {
478
- // We don't reuse the metadata but send a new one on each submit.
479
- this.submitMapClearMessage(op);
480
- },
481
- getStashedOpLocalMetadata: (op) => {
482
- // We don't reuse the metadata but send a new one on each submit.
483
- return this.getMapClearMessageLocalMetadata(op);
484
- },
485
- });
486
- messageHandlers.set("delete", {
487
- process: (op, local, message, localOpMetadata) => {
488
- if (!this.needProcessKeyOperation(op, local, localOpMetadata)) {
489
- return;
490
- }
491
- this.deleteCore(op.key, local, message);
492
- },
493
- submit: (op) => {
494
- // We don't reuse the metadata but send a new one on each submit.
495
- this.submitMapKeyMessage(op);
496
- },
497
- getStashedOpLocalMetadata: (op) => {
498
- // We don't reuse the metadata but send a new one on each submit.
499
- return this.getMapKeyMessageLocalMetadata(op);
500
- },
501
- });
502
- messageHandlers.set("set", {
503
- process: (op, local, message, localOpMetadata) => {
504
- if (!this.needProcessKeyOperation(op, local, localOpMetadata)) {
505
- return;
506
- }
507
- // needProcessKeyOperation should have returned false if local is true
508
- const context = this.makeLocal(op.key, op.value);
509
- this.setCore(op.key, context, local, message);
510
- },
511
- submit: (op) => {
512
- // We don't reuse the metadata but send a new one on each submit.
513
- this.submitMapKeyMessage(op);
514
- },
515
- getStashedOpLocalMetadata: (op) => {
516
- // We don't reuse the metadata but send a new one on each submit.
517
- return this.getMapKeyMessageLocalMetadata(op);
518
- },
519
- });
520
- // Ops with type "act" describe actions taken by custom value type handlers of whatever item is
521
- // being addressed. These custom handlers can be retrieved from the ValueTypeLocalValue which has
522
- // stashed its valueType (and therefore its handlers). We also emit a valueChanged for anyone
523
- // watching for manipulations of that item.
524
- messageHandlers.set("act", {
525
- process: (op, local, message, localOpMetadata) => {
526
- // Local value might not exist if we deleted it
527
- const localValue = this.data.get(op.key);
528
- if (!localValue) {
529
- return;
530
- }
531
- const handler = localValue.getOpHandler(op.value.opName);
532
- const previousValue = localValue.value;
533
- const translatedValue = (0, shared_object_base_1.parseHandles)(op.value.value, this.serializer);
534
- handler.process(previousValue, translatedValue, local, message);
535
- const event = { key: op.key, previousValue };
536
- this.eventEmitter.emit("valueChanged", event, local, message, this.eventEmitter);
537
- },
538
- submit: (op) => {
539
- this.submitMessage(op, { lastProcessedSeq: this.lastProcessedSeq });
540
- },
541
- getStashedOpLocalMetadata: (op) => {
542
- (0, common_utils_1.assert)(false, 0x016 /* "apply stashed op not implemented for custom value type ops" */);
543
- },
544
- });
545
- return messageHandlers;
546
- }
547
- getMapClearMessageLocalMetadata(op) {
548
- const pendingMessageId = ++this.pendingMessageId;
549
- this.pendingClearMessageId = pendingMessageId;
550
- return pendingMessageId;
551
- }
552
- /**
553
- * Submit a clear message to remote clients.
554
- * @param op - The clear message
555
- */
556
- submitMapClearMessage(op) {
557
- const pendingClearMessageId = this.getMapClearMessageLocalMetadata(op);
558
- this.submitMessage(op, { pendingClearMessageId, lastProcessedSeq: this.lastProcessedSeq });
559
- }
560
- getMapKeyMessageLocalMetadata(op) {
561
- const pendingMessageId = ++this.pendingMessageId;
562
- this.pendingKeys.set(op.key, pendingMessageId);
563
- return pendingMessageId;
564
- }
565
- /**
566
- * Submit a map key message to remote clients.
567
- * @param op - The map key message
568
- */
569
- submitMapKeyMessage(op) {
570
- const pendingMessageId = this.getMapKeyMessageLocalMetadata(op);
571
- this.submitMessage(op, { pendingMessageId, lastProcessedSeq: this.lastProcessedSeq });
572
- }
573
- /**
574
- * Create an emitter for a value type to emit ops from the given key.
575
- * @alpha
576
- * @param key - The key of the map that the value type will be stored on
577
- * @returns A value op emitter for the given key
578
- */
579
- makeMapValueOpEmitter(key) {
580
- const emit = (opName, previousValue, params) => {
581
- const translatedParams = (0, shared_object_base_1.makeHandlesSerializable)(params, this.serializer, this.handle);
582
- const op = {
583
- key,
584
- type: "act",
585
- value: {
586
- opName,
587
- value: translatedParams,
588
- },
589
- };
590
- // Send the localOpMetadata as undefined because we don't care about the ack.
591
- this.submitMessage(op, { lastProcessedSeq: this.lastProcessedSeq });
592
- const event = { key, previousValue };
593
- this.eventEmitter.emit("valueChanged", event, true, null, this.eventEmitter);
594
- };
595
- return { emit };
596
- }
597
- }
598
- exports.MapKernel = MapKernel;
599
- //# sourceMappingURL=mapKernel.js.map