@fluidframework/map 1.2.2 → 2.0.0-internal.1.0.0.82159

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 (51) hide show
  1. package/dist/directory.d.ts +26 -7
  2. package/dist/directory.d.ts.map +1 -1
  3. package/dist/directory.js +4 -11
  4. package/dist/directory.js.map +1 -1
  5. package/dist/interfaces.d.ts +139 -181
  6. package/dist/interfaces.d.ts.map +1 -1
  7. package/dist/interfaces.js.map +1 -1
  8. package/dist/localValues.d.ts +3 -3
  9. package/dist/localValues.js +2 -2
  10. package/dist/localValues.js.map +1 -1
  11. package/dist/map.d.ts +3 -5
  12. package/dist/map.d.ts.map +1 -1
  13. package/dist/map.js +4 -7
  14. package/dist/map.js.map +1 -1
  15. package/dist/mapKernel.d.ts +9 -2
  16. package/dist/mapKernel.d.ts.map +1 -1
  17. package/dist/mapKernel.js +28 -13
  18. package/dist/mapKernel.js.map +1 -1
  19. package/dist/packageVersion.d.ts +1 -1
  20. package/dist/packageVersion.d.ts.map +1 -1
  21. package/dist/packageVersion.js +1 -1
  22. package/dist/packageVersion.js.map +1 -1
  23. package/lib/directory.d.ts +26 -7
  24. package/lib/directory.d.ts.map +1 -1
  25. package/lib/directory.js +4 -11
  26. package/lib/directory.js.map +1 -1
  27. package/lib/interfaces.d.ts +139 -181
  28. package/lib/interfaces.d.ts.map +1 -1
  29. package/lib/interfaces.js.map +1 -1
  30. package/lib/localValues.d.ts +3 -3
  31. package/lib/localValues.js +2 -2
  32. package/lib/localValues.js.map +1 -1
  33. package/lib/map.d.ts +3 -5
  34. package/lib/map.d.ts.map +1 -1
  35. package/lib/map.js +4 -7
  36. package/lib/map.js.map +1 -1
  37. package/lib/mapKernel.d.ts +9 -2
  38. package/lib/mapKernel.d.ts.map +1 -1
  39. package/lib/mapKernel.js +28 -13
  40. package/lib/mapKernel.js.map +1 -1
  41. package/lib/packageVersion.d.ts +1 -1
  42. package/lib/packageVersion.d.ts.map +1 -1
  43. package/lib/packageVersion.js +1 -1
  44. package/lib/packageVersion.js.map +1 -1
  45. package/package.json +53 -16
  46. package/src/directory.ts +30 -15
  47. package/src/interfaces.ts +146 -181
  48. package/src/localValues.ts +3 -3
  49. package/src/map.ts +8 -11
  50. package/src/mapKernel.ts +42 -16
  51. package/src/packageVersion.ts +1 -1
package/src/mapKernel.ts CHANGED
@@ -41,7 +41,7 @@ interface IMapMessageHandler {
41
41
  */
42
42
  submit(op: IMapOperation, localOpMetadata: unknown): void;
43
43
 
44
- getStashedOpLocalMetadata(op: IMapOperation): unknown;
44
+ applyStashedOp(op: IMapOperation): unknown;
45
45
  }
46
46
 
47
47
  /**
@@ -101,12 +101,19 @@ export type IMapOperation = IMapKeyOperation | IMapClearOperation;
101
101
 
102
102
  /**
103
103
  * 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
104
+ *
105
+ * @remarks Directly used in
106
+ * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
107
+ * | JSON.stringify}, direct result from
108
+ * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse | JSON.parse}.
105
109
  */
106
110
  export interface IMapDataObjectSerializable {
107
111
  [key: string]: ISerializableValue;
108
112
  }
109
113
 
114
+ /**
115
+ * Serialized key/value data.
116
+ */
110
117
  export interface IMapDataObjectSerialized {
111
118
  [key: string]: ISerializedValue;
112
119
  }
@@ -114,7 +121,7 @@ export interface IMapDataObjectSerialized {
114
121
  interface IMapKeyEditLocalOpMetadata {
115
122
  type: "edit";
116
123
  pendingMessageId: number;
117
- previousValue?: ILocalValue;
124
+ previousValue: ILocalValue;
118
125
  }
119
126
 
120
127
  interface IMapKeyAddLocalOpMetadata {
@@ -145,6 +152,23 @@ function isMapLocalOpMetadata(metadata: any): metadata is MapLocalOpMetadata {
145
152
  (metadata.type === "add" || metadata.type === "edit" || metadata.type === "clear");
146
153
  }
147
154
 
155
+ function createClearLocalOpMetadata(op: IMapClearOperation,
156
+ pendingClearMessageId: number, previousMap?: Map<string, ILocalValue>): IMapClearLocalOpMetadata {
157
+ const localMetadata: IMapClearLocalOpMetadata = {
158
+ type: "clear",
159
+ pendingMessageId: pendingClearMessageId, previousMap,
160
+ };
161
+ return localMetadata;
162
+ }
163
+
164
+ function createKeyLocalOpMetadata(op: IMapKeyOperation,
165
+ pendingMessageId: number, previousValue?: ILocalValue): MapKeyLocalOpMetadata {
166
+ const localMetadata: MapKeyLocalOpMetadata = previousValue ?
167
+ { type: "edit", pendingMessageId, previousValue } :
168
+ { type: "add", pendingMessageId };
169
+ return localMetadata;
170
+ }
171
+
148
172
  /**
149
173
  * A SharedMap is a map-like distributed data structure.
150
174
  */
@@ -435,12 +459,12 @@ export class MapKernel {
435
459
  return true;
436
460
  }
437
461
 
438
- public tryGetStashedOpLocalMetadata(op: any): unknown {
462
+ public tryApplyStashedOp(op: any): unknown {
439
463
  const handler = this.messageHandlers.get(op.type);
440
464
  if (handler === undefined) {
441
465
  throw new Error("no apply stashed op handler");
442
466
  }
443
- return handler.getStashedOpLocalMetadata(op as IMapOperation);
467
+ return handler.applyStashedOp(op as IMapOperation);
444
468
  }
445
469
 
446
470
  /**
@@ -661,9 +685,11 @@ export class MapKernel {
661
685
  0x2fd /* pendingMessageId does not match */);
662
686
  this.submitMapClearMessage(op, localOpMetadata.previousMap);
663
687
  },
664
- getStashedOpLocalMetadata: (op: IMapClearOperation) => {
688
+ applyStashedOp: (op: IMapClearOperation) => {
689
+ const copy = new Map<string, ILocalValue>(this.data);
690
+ this.clearCore(true);
665
691
  // We don't reuse the metadata pendingMessageId but send a new one on each submit.
666
- return { type: "clear", pendingMessageId: this.getMapClearMessageId() };
692
+ return createClearLocalOpMetadata(op, this.getMapClearMessageId(), copy);
667
693
  },
668
694
  });
669
695
  messageHandlers.set(
@@ -678,9 +704,10 @@ export class MapKernel {
678
704
  submit: (op: IMapDeleteOperation, localOpMetadata: unknown) => {
679
705
  this.resubmitMapKeyMessage(op, localOpMetadata);
680
706
  },
681
- getStashedOpLocalMetadata: (op: IMapDeleteOperation) => {
707
+ applyStashedOp: (op: IMapDeleteOperation) => {
682
708
  // We don't reuse the metadata pendingMessageId but send a new one on each submit.
683
- return { type: "edit", pendingMessageId: this.getMapKeyMessageId(op) };
709
+ const previousValue = this.deleteCore(op.key, true);
710
+ return createKeyLocalOpMetadata(op, this.getMapKeyMessageId(op), previousValue);
684
711
  },
685
712
  });
686
713
  messageHandlers.set(
@@ -698,9 +725,11 @@ export class MapKernel {
698
725
  submit: (op: IMapSetOperation, localOpMetadata: unknown) => {
699
726
  this.resubmitMapKeyMessage(op, localOpMetadata);
700
727
  },
701
- getStashedOpLocalMetadata: (op: IMapSetOperation) => {
728
+ applyStashedOp: (op: IMapSetOperation) => {
702
729
  // We don't reuse the metadata pendingMessageId but send a new one on each submit.
703
- return { type: "edit", pendingMessageId: this.getMapKeyMessageId(op) };
730
+ const context = this.makeLocal(op.key, op.value);
731
+ const previousValue = this.setCore(op.key, context, true);
732
+ return createKeyLocalOpMetadata(op, this.getMapKeyMessageId(op), previousValue);
704
733
  },
705
734
  });
706
735
 
@@ -718,7 +747,7 @@ export class MapKernel {
718
747
  * @param op - The clear message
719
748
  */
720
749
  private submitMapClearMessage(op: IMapClearOperation, previousMap?: Map<string, ILocalValue>): void {
721
- const metadata = { type: "clear", pendingMessageId: this.getMapClearMessageId(), previousMap };
750
+ const metadata = createClearLocalOpMetadata(op, this.getMapClearMessageId(), previousMap);
722
751
  this.submitMessage(op, metadata);
723
752
  }
724
753
 
@@ -739,10 +768,7 @@ export class MapKernel {
739
768
  * @param previousValue - The value of the key before this op
740
769
  */
741
770
  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 };
771
+ const localMetadata = createKeyLocalOpMetadata(op, this.getMapKeyMessageId(op), previousValue);
746
772
  this.submitMessage(op, localMetadata);
747
773
  }
748
774
 
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/map";
9
- export const pkgVersion = "1.2.2";
9
+ export const pkgVersion = "2.0.0-internal.1.0.0.82159";