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