@fluidframework/map 1.2.6 → 2.0.0-dev.1.3.0.96595

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 (69) hide show
  1. package/.eslintrc.js +4 -1
  2. package/.mocharc.js +12 -0
  3. package/dist/directory.d.ts +26 -7
  4. package/dist/directory.d.ts.map +1 -1
  5. package/dist/directory.js +10 -25
  6. package/dist/directory.js.map +1 -1
  7. package/dist/index.d.ts +2 -2
  8. package/dist/index.js +2 -2
  9. package/dist/index.js.map +1 -1
  10. package/dist/interfaces.d.ts +139 -181
  11. package/dist/interfaces.d.ts.map +1 -1
  12. package/dist/interfaces.js.map +1 -1
  13. package/dist/internalInterfaces.d.ts +62 -0
  14. package/dist/internalInterfaces.d.ts.map +1 -0
  15. package/dist/internalInterfaces.js +7 -0
  16. package/dist/internalInterfaces.js.map +1 -0
  17. package/dist/localValues.d.ts +3 -3
  18. package/dist/localValues.js +2 -2
  19. package/dist/localValues.js.map +1 -1
  20. package/dist/map.d.ts +3 -5
  21. package/dist/map.d.ts.map +1 -1
  22. package/dist/map.js +4 -7
  23. package/dist/map.js.map +1 -1
  24. package/dist/mapKernel.d.ts +10 -41
  25. package/dist/mapKernel.d.ts.map +1 -1
  26. package/dist/mapKernel.js +34 -25
  27. package/dist/mapKernel.js.map +1 -1
  28. package/dist/packageVersion.d.ts +1 -1
  29. package/dist/packageVersion.d.ts.map +1 -1
  30. package/dist/packageVersion.js +1 -1
  31. package/dist/packageVersion.js.map +1 -1
  32. package/lib/directory.d.ts +26 -7
  33. package/lib/directory.d.ts.map +1 -1
  34. package/lib/directory.js +10 -25
  35. package/lib/directory.js.map +1 -1
  36. package/lib/index.d.ts +2 -2
  37. package/lib/index.js +2 -2
  38. package/lib/index.js.map +1 -1
  39. package/lib/interfaces.d.ts +139 -181
  40. package/lib/interfaces.d.ts.map +1 -1
  41. package/lib/interfaces.js.map +1 -1
  42. package/lib/internalInterfaces.d.ts +62 -0
  43. package/lib/internalInterfaces.d.ts.map +1 -0
  44. package/lib/internalInterfaces.js +6 -0
  45. package/lib/internalInterfaces.js.map +1 -0
  46. package/lib/localValues.d.ts +3 -3
  47. package/lib/localValues.js +2 -2
  48. package/lib/localValues.js.map +1 -1
  49. package/lib/map.d.ts +3 -5
  50. package/lib/map.d.ts.map +1 -1
  51. package/lib/map.js +4 -7
  52. package/lib/map.js.map +1 -1
  53. package/lib/mapKernel.d.ts +10 -41
  54. package/lib/mapKernel.d.ts.map +1 -1
  55. package/lib/mapKernel.js +34 -25
  56. package/lib/mapKernel.js.map +1 -1
  57. package/lib/packageVersion.d.ts +1 -1
  58. package/lib/packageVersion.d.ts.map +1 -1
  59. package/lib/packageVersion.js +1 -1
  60. package/lib/packageVersion.js.map +1 -1
  61. package/package.json +61 -21
  62. package/src/directory.ts +36 -27
  63. package/src/index.ts +2 -2
  64. package/src/interfaces.ts +146 -181
  65. package/src/internalInterfaces.ts +72 -0
  66. package/src/localValues.ts +3 -3
  67. package/src/map.ts +8 -11
  68. package/src/mapKernel.ts +64 -96
  69. package/src/packageVersion.ts +1 -1
package/src/mapKernel.ts CHANGED
@@ -11,6 +11,14 @@ import {
11
11
  ISerializedValue,
12
12
  ISharedMapEvents,
13
13
  } from "./interfaces";
14
+ import {
15
+ IMapSetOperation,
16
+ IMapDeleteOperation,
17
+ IMapClearOperation,
18
+ IMapKeyEditLocalOpMetadata,
19
+ IMapKeyAddLocalOpMetadata,
20
+ IMapClearLocalOpMetadata,
21
+ } from "./internalInterfaces";
14
22
  import {
15
23
  ILocalValue,
16
24
  LocalValueMaker,
@@ -31,7 +39,7 @@ interface IMapMessageHandler {
31
39
  process(
32
40
  op: IMapOperation,
33
41
  local: boolean,
34
- localOpMetadata: unknown,
42
+ localOpMetadata: MapLocalOpMetadata,
35
43
  ): void;
36
44
 
37
45
  /**
@@ -39,44 +47,9 @@ interface IMapMessageHandler {
39
47
  * @param op - The map operation to submit
40
48
  * @param localOpMetadata - The metadata to be submitted with the message.
41
49
  */
42
- submit(op: IMapOperation, localOpMetadata: unknown): void;
43
-
44
- getStashedOpLocalMetadata(op: IMapOperation): unknown;
45
- }
46
-
47
- /**
48
- * Operation indicating a value should be set for a key.
49
- */
50
- export interface IMapSetOperation {
51
- /**
52
- * String identifier of the operation type.
53
- */
54
- type: "set";
55
-
56
- /**
57
- * Map key being modified.
58
- */
59
- key: string;
50
+ submit(op: IMapOperation, localOpMetadata: MapLocalOpMetadata): void;
60
51
 
61
- /**
62
- * Value to be set on the key.
63
- */
64
- value: ISerializableValue;
65
- }
66
-
67
- /**
68
- * Operation indicating a key should be deleted from the map.
69
- */
70
- export interface IMapDeleteOperation {
71
- /**
72
- * String identifier of the operation type.
73
- */
74
- type: "delete";
75
-
76
- /**
77
- * Map key being modified.
78
- */
79
- key: string;
52
+ applyStashedOp(op: IMapOperation): MapLocalOpMetadata;
80
53
  }
81
54
 
82
55
  /**
@@ -84,16 +57,6 @@ export interface IMapDeleteOperation {
84
57
  */
85
58
  export type IMapKeyOperation = IMapSetOperation | IMapDeleteOperation;
86
59
 
87
- /**
88
- * Operation indicating the map should be cleared.
89
- */
90
- export interface IMapClearOperation {
91
- /**
92
- * String identifier of the operation type.
93
- */
94
- type: "clear";
95
- }
96
-
97
60
  /**
98
61
  * Description of a map delta operation
99
62
  */
@@ -101,33 +64,23 @@ export type IMapOperation = IMapKeyOperation | IMapClearOperation;
101
64
 
102
65
  /**
103
66
  * Defines the in-memory object structure to be used for the conversion to/from serialized.
104
- * Directly used in JSON.stringify, direct result from JSON.parse
67
+ *
68
+ * @remarks Directly used in
69
+ * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
70
+ * | JSON.stringify}, direct result from
71
+ * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse | JSON.parse}.
105
72
  */
106
73
  export interface IMapDataObjectSerializable {
107
74
  [key: string]: ISerializableValue;
108
75
  }
109
76
 
77
+ /**
78
+ * Serialized key/value data.
79
+ */
110
80
  export interface IMapDataObjectSerialized {
111
81
  [key: string]: ISerializedValue;
112
82
  }
113
83
 
114
- interface IMapKeyEditLocalOpMetadata {
115
- type: "edit";
116
- pendingMessageId: number;
117
- previousValue?: ILocalValue;
118
- }
119
-
120
- interface IMapKeyAddLocalOpMetadata {
121
- type: "add";
122
- pendingMessageId: number;
123
- }
124
-
125
- interface IMapClearLocalOpMetadata {
126
- type: "clear";
127
- pendingMessageId: number;
128
- previousMap?: Map<string, ILocalValue>;
129
- }
130
-
131
84
  type MapKeyLocalOpMetadata = IMapKeyEditLocalOpMetadata | IMapKeyAddLocalOpMetadata;
132
85
  type MapLocalOpMetadata = IMapClearLocalOpMetadata | MapKeyLocalOpMetadata;
133
86
 
@@ -145,6 +98,23 @@ function isMapLocalOpMetadata(metadata: any): metadata is MapLocalOpMetadata {
145
98
  (metadata.type === "add" || metadata.type === "edit" || metadata.type === "clear");
146
99
  }
147
100
 
101
+ function createClearLocalOpMetadata(op: IMapClearOperation,
102
+ pendingClearMessageId: number, previousMap?: Map<string, ILocalValue>): IMapClearLocalOpMetadata {
103
+ const localMetadata: IMapClearLocalOpMetadata = {
104
+ type: "clear",
105
+ pendingMessageId: pendingClearMessageId, previousMap,
106
+ };
107
+ return localMetadata;
108
+ }
109
+
110
+ function createKeyLocalOpMetadata(op: IMapKeyOperation,
111
+ pendingMessageId: number, previousValue?: ILocalValue): MapKeyLocalOpMetadata {
112
+ const localMetadata: MapKeyLocalOpMetadata = previousValue ?
113
+ { type: "edit", pendingMessageId, previousValue } :
114
+ { type: "add", pendingMessageId };
115
+ return localMetadata;
116
+ }
117
+
148
118
  /**
149
119
  * A SharedMap is a map-like distributed data structure.
150
120
  */
@@ -223,12 +193,10 @@ export class MapKernel {
223
193
  const iterator = {
224
194
  next(): IteratorResult<[string, any]> {
225
195
  const nextVal = localEntriesIterator.next();
226
- if (nextVal.done) {
227
- return { value: undefined, done: true };
228
- } else {
196
+ return nextVal.done
197
+ ? { value: undefined, done: true }
229
198
  // Unpack the stored value
230
- return { value: [nextVal.value[0], nextVal.value[1].value], done: false };
231
- }
199
+ : { value: [nextVal.value[0], nextVal.value[1].value], done: false };
232
200
  },
233
201
  [Symbol.iterator]() {
234
202
  return this;
@@ -246,12 +214,10 @@ export class MapKernel {
246
214
  const iterator = {
247
215
  next(): IteratorResult<any> {
248
216
  const nextVal = localValuesIterator.next();
249
- if (nextVal.done) {
250
- return { value: undefined, done: true };
251
- } else {
217
+ return nextVal.done
218
+ ? { value: undefined, done: true }
252
219
  // Unpack the stored value
253
- return { value: nextVal.value.value, done: false };
254
- }
220
+ : { value: nextVal.value.value, done: false };
255
221
  },
256
222
  [Symbol.iterator]() {
257
223
  return this;
@@ -431,16 +397,16 @@ export class MapKernel {
431
397
  if (handler === undefined) {
432
398
  return false;
433
399
  }
434
- handler.submit(op as IMapOperation, localOpMetadata);
400
+ handler.submit(op as IMapOperation, localOpMetadata as MapLocalOpMetadata);
435
401
  return true;
436
402
  }
437
403
 
438
- public tryGetStashedOpLocalMetadata(op: any): unknown {
404
+ public tryApplyStashedOp(op: any): unknown {
439
405
  const handler = this.messageHandlers.get(op.type);
440
406
  if (handler === undefined) {
441
407
  throw new Error("no apply stashed op handler");
442
408
  }
443
- return handler.getStashedOpLocalMetadata(op as IMapOperation);
409
+ return handler.applyStashedOp(op as IMapOperation);
444
410
  }
445
411
 
446
412
  /**
@@ -460,7 +426,7 @@ export class MapKernel {
460
426
  if (handler === undefined) {
461
427
  return false;
462
428
  }
463
- handler.process(op, local, localOpMetadata);
429
+ handler.process(op, local, localOpMetadata as MapLocalOpMetadata);
464
430
  return true;
465
431
  }
466
432
 
@@ -595,7 +561,7 @@ export class MapKernel {
595
561
  private needProcessKeyOperation(
596
562
  op: IMapKeyOperation,
597
563
  local: boolean,
598
- localOpMetadata: unknown,
564
+ localOpMetadata: MapLocalOpMetadata,
599
565
  ): boolean {
600
566
  if (this.pendingClearMessageIds.length > 0) {
601
567
  if (local) {
@@ -653,7 +619,7 @@ export class MapKernel {
653
619
  }
654
620
  this.clearCore(local);
655
621
  },
656
- submit: (op: IMapClearOperation, localOpMetadata: unknown) => {
622
+ submit: (op: IMapClearOperation, localOpMetadata: IMapClearLocalOpMetadata) => {
657
623
  assert(isClearLocalOpMetadata(localOpMetadata), 0x2fc /* Invalid localOpMetadata for clear */);
658
624
  // We don't reuse the metadata pendingMessageId but send a new one on each submit.
659
625
  const pendingClearMessageId = this.pendingClearMessageIds.shift();
@@ -661,9 +627,11 @@ export class MapKernel {
661
627
  0x2fd /* pendingMessageId does not match */);
662
628
  this.submitMapClearMessage(op, localOpMetadata.previousMap);
663
629
  },
664
- getStashedOpLocalMetadata: (op: IMapClearOperation) => {
630
+ applyStashedOp: (op: IMapClearOperation) => {
631
+ const copy = new Map<string, ILocalValue>(this.data);
632
+ this.clearCore(true);
665
633
  // We don't reuse the metadata pendingMessageId but send a new one on each submit.
666
- return { type: "clear", pendingMessageId: this.getMapClearMessageId() };
634
+ return createClearLocalOpMetadata(op, this.getMapClearMessageId(), copy);
667
635
  },
668
636
  });
669
637
  messageHandlers.set(
@@ -675,12 +643,13 @@ export class MapKernel {
675
643
  }
676
644
  this.deleteCore(op.key, local);
677
645
  },
678
- submit: (op: IMapDeleteOperation, localOpMetadata: unknown) => {
646
+ submit: (op: IMapDeleteOperation, localOpMetadata: MapKeyLocalOpMetadata) => {
679
647
  this.resubmitMapKeyMessage(op, localOpMetadata);
680
648
  },
681
- getStashedOpLocalMetadata: (op: IMapDeleteOperation) => {
649
+ applyStashedOp: (op: IMapDeleteOperation) => {
682
650
  // We don't reuse the metadata pendingMessageId but send a new one on each submit.
683
- return { type: "edit", pendingMessageId: this.getMapKeyMessageId(op) };
651
+ const previousValue = this.deleteCore(op.key, true);
652
+ return createKeyLocalOpMetadata(op, this.getMapKeyMessageId(op), previousValue);
684
653
  },
685
654
  });
686
655
  messageHandlers.set(
@@ -695,12 +664,14 @@ export class MapKernel {
695
664
  const context = this.makeLocal(op.key, op.value);
696
665
  this.setCore(op.key, context, local);
697
666
  },
698
- submit: (op: IMapSetOperation, localOpMetadata: unknown) => {
667
+ submit: (op: IMapSetOperation, localOpMetadata: MapKeyLocalOpMetadata) => {
699
668
  this.resubmitMapKeyMessage(op, localOpMetadata);
700
669
  },
701
- getStashedOpLocalMetadata: (op: IMapSetOperation) => {
670
+ applyStashedOp: (op: IMapSetOperation) => {
702
671
  // We don't reuse the metadata pendingMessageId but send a new one on each submit.
703
- return { type: "edit", pendingMessageId: this.getMapKeyMessageId(op) };
672
+ const context = this.makeLocal(op.key, op.value);
673
+ const previousValue = this.setCore(op.key, context, true);
674
+ return createKeyLocalOpMetadata(op, this.getMapKeyMessageId(op), previousValue);
704
675
  },
705
676
  });
706
677
 
@@ -718,7 +689,7 @@ export class MapKernel {
718
689
  * @param op - The clear message
719
690
  */
720
691
  private submitMapClearMessage(op: IMapClearOperation, previousMap?: Map<string, ILocalValue>): void {
721
- const metadata = { type: "clear", pendingMessageId: this.getMapClearMessageId(), previousMap };
692
+ const metadata = createClearLocalOpMetadata(op, this.getMapClearMessageId(), previousMap);
722
693
  this.submitMessage(op, metadata);
723
694
  }
724
695
 
@@ -739,10 +710,7 @@ export class MapKernel {
739
710
  * @param previousValue - The value of the key before this op
740
711
  */
741
712
  private submitMapKeyMessage(op: IMapKeyOperation, previousValue?: ILocalValue): void {
742
- const pendingMessageId = this.getMapKeyMessageId(op);
743
- const localMetadata = previousValue ?
744
- { type: "edit", pendingMessageId, previousValue } :
745
- { type: "add", pendingMessageId };
713
+ const localMetadata = createKeyLocalOpMetadata(op, this.getMapKeyMessageId(op), previousValue);
746
714
  this.submitMessage(op, localMetadata);
747
715
  }
748
716
 
@@ -751,7 +719,7 @@ export class MapKernel {
751
719
  * @param op - The map key message
752
720
  * @param localOpMetadata - Metadata from the previous submit
753
721
  */
754
- private resubmitMapKeyMessage(op: IMapKeyOperation, localOpMetadata: unknown): void {
722
+ private resubmitMapKeyMessage(op: IMapKeyOperation, localOpMetadata: MapLocalOpMetadata): void {
755
723
  assert(isMapKeyLocalOpMetadata(localOpMetadata), 0x2fe /* Invalid localOpMetadata in submit */);
756
724
 
757
725
  // clear the old pending message id
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/map";
9
- export const pkgVersion = "1.2.6";
9
+ export const pkgVersion = "2.0.0-dev.1.3.0.96595";