@fluidframework/map 1.2.1 → 2.0.0-internal.1.0.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.
Files changed (60) 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/internalInterfaces.d.ts +62 -0
  9. package/dist/internalInterfaces.d.ts.map +1 -0
  10. package/dist/internalInterfaces.js +7 -0
  11. package/dist/internalInterfaces.js.map +1 -0
  12. package/dist/localValues.d.ts +3 -3
  13. package/dist/localValues.js +2 -2
  14. package/dist/localValues.js.map +1 -1
  15. package/dist/map.d.ts +3 -5
  16. package/dist/map.d.ts.map +1 -1
  17. package/dist/map.js +4 -7
  18. package/dist/map.js.map +1 -1
  19. package/dist/mapKernel.d.ts +10 -41
  20. package/dist/mapKernel.d.ts.map +1 -1
  21. package/dist/mapKernel.js +28 -13
  22. package/dist/mapKernel.js.map +1 -1
  23. package/dist/packageVersion.d.ts +1 -1
  24. package/dist/packageVersion.d.ts.map +1 -1
  25. package/dist/packageVersion.js +1 -1
  26. package/dist/packageVersion.js.map +1 -1
  27. package/lib/directory.d.ts +26 -7
  28. package/lib/directory.d.ts.map +1 -1
  29. package/lib/directory.js +4 -11
  30. package/lib/directory.js.map +1 -1
  31. package/lib/interfaces.d.ts +139 -181
  32. package/lib/interfaces.d.ts.map +1 -1
  33. package/lib/interfaces.js.map +1 -1
  34. package/lib/internalInterfaces.d.ts +62 -0
  35. package/lib/internalInterfaces.d.ts.map +1 -0
  36. package/lib/internalInterfaces.js +6 -0
  37. package/lib/internalInterfaces.js.map +1 -0
  38. package/lib/localValues.d.ts +3 -3
  39. package/lib/localValues.js +2 -2
  40. package/lib/localValues.js.map +1 -1
  41. package/lib/map.d.ts +3 -5
  42. package/lib/map.d.ts.map +1 -1
  43. package/lib/map.js +4 -7
  44. package/lib/map.js.map +1 -1
  45. package/lib/mapKernel.d.ts +10 -41
  46. package/lib/mapKernel.d.ts.map +1 -1
  47. package/lib/mapKernel.js +28 -13
  48. package/lib/mapKernel.js.map +1 -1
  49. package/lib/packageVersion.d.ts +1 -1
  50. package/lib/packageVersion.d.ts.map +1 -1
  51. package/lib/packageVersion.js +1 -1
  52. package/lib/packageVersion.js.map +1 -1
  53. package/package.json +54 -17
  54. package/src/directory.ts +30 -15
  55. package/src/interfaces.ts +146 -181
  56. package/src/internalInterfaces.ts +72 -0
  57. package/src/localValues.ts +3 -3
  58. package/src/map.ts +8 -11
  59. package/src/mapKernel.ts +58 -86
  60. package/src/packageVersion.ts +1 -1
@@ -0,0 +1,72 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { ISerializableValue } from "./interfaces";
7
+ import { ILocalValue } from "./localValues";
8
+
9
+ /**
10
+ * Operation indicating a value should be set for a key.
11
+ */
12
+ export interface IMapSetOperation {
13
+ /**
14
+ * String identifier of the operation type.
15
+ */
16
+ type: "set";
17
+
18
+ /**
19
+ * Map key being modified.
20
+ */
21
+ key: string;
22
+
23
+ /**
24
+ * Value to be set on the key.
25
+ */
26
+ value: ISerializableValue;
27
+ }
28
+
29
+ /**
30
+ * Operation indicating the map should be cleared.
31
+ */
32
+ export interface IMapClearOperation {
33
+ /**
34
+ * String identifier of the operation type.
35
+ */
36
+ type: "clear";
37
+ }
38
+
39
+ /**
40
+ * Operation indicating a key should be deleted from the map.
41
+ */
42
+ export interface IMapDeleteOperation {
43
+ /**
44
+ * String identifier of the operation type.
45
+ */
46
+ type: "delete";
47
+
48
+ /**
49
+ * Map key being modified.
50
+ */
51
+ key: string;
52
+ }
53
+
54
+ export interface IMapKeyEditLocalOpMetadata {
55
+ type: "edit";
56
+ pendingMessageId: number;
57
+ previousValue: ILocalValue;
58
+ }
59
+
60
+ export interface IMapKeyAddLocalOpMetadata {
61
+ type: "add";
62
+ pendingMessageId: number;
63
+ }
64
+
65
+ export interface IMapClearLocalOpMetadata {
66
+ type: "clear";
67
+ pendingMessageId: number;
68
+ previousMap?: Map<string, ILocalValue>;
69
+ }
70
+
71
+ export type MapKeyLocalOpMetadata = IMapKeyEditLocalOpMetadata | IMapKeyAddLocalOpMetadata;
72
+ export type MapLocalOpMetadata = IMapClearLocalOpMetadata | MapKeyLocalOpMetadata;
@@ -17,7 +17,7 @@ import {
17
17
  } from "./interfaces";
18
18
 
19
19
  /**
20
- * A local value to be stored in a container type DDS.
20
+ * A local value to be stored in a container type Distributed Data Store (DDS).
21
21
  */
22
22
  export interface ILocalValue {
23
23
  /**
@@ -90,8 +90,8 @@ export class PlainLocalValue implements ILocalValue {
90
90
  }
91
91
 
92
92
  /**
93
- * A LocalValueMaker enables a container type DDS to produce and store local values with minimal awareness of how
94
- * those objects are stored, serialized, and deserialized.
93
+ * Enables a container type {@link https://fluidframework.com/docs/build/dds/ | DDS} to produce and store local
94
+ * values with minimal awareness of how those objects are stored, serialized, and deserialized.
95
95
  */
96
96
  export class LocalValueMaker {
97
97
  /**
package/src/map.ts CHANGED
@@ -33,7 +33,8 @@ interface IMapSerializationFormat {
33
33
  const snapshotFileName = "header";
34
34
 
35
35
  /**
36
- * The factory that defines the map.
36
+ * {@link @fluidframework/datastore-definitions#IChannelFactory} for {@link SharedMap}.
37
+ *
37
38
  * @sealed
38
39
  */
39
40
  export class MapFactory implements IChannelFactory {
@@ -91,10 +92,7 @@ export class MapFactory implements IChannelFactory {
91
92
  }
92
93
 
93
94
  /**
94
- * The SharedMap distributed data structure can be used to store key-value pairs. It provides the same API for setting
95
- * and retrieving values that JavaScript developers are accustomed to with the
96
- * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map | Map} built-in object.
97
- * However, the keys of a SharedMap must be strings.
95
+ * {@inheritDoc ISharedMap}
98
96
  */
99
97
  export class SharedMap extends SharedObject<ISharedMapEvents> implements ISharedMap {
100
98
  /**
@@ -340,7 +338,7 @@ export class SharedMap extends SharedObject<ISharedMapEvents> implements IShared
340
338
  * {@inheritDoc @fluidframework/shared-object-base#SharedObject.onDisconnect}
341
339
  * @internal
342
340
  */
343
- protected onDisconnect() {}
341
+ protected onDisconnect() { }
344
342
 
345
343
  /**
346
344
  * {@inheritDoc @fluidframework/shared-object-base#SharedObject.reSubmitCore}
@@ -355,8 +353,7 @@ export class SharedMap extends SharedObject<ISharedMapEvents> implements IShared
355
353
  * @internal
356
354
  */
357
355
  protected applyStashedOp(content: any): unknown {
358
- this.kernel.tryProcessMessage(content, false, undefined);
359
- return this.kernel.tryGetStashedOpLocalMetadata(content);
356
+ return this.kernel.tryApplyStashedOp(content);
360
357
  }
361
358
 
362
359
  /**
@@ -373,7 +370,7 @@ export class SharedMap extends SharedObject<ISharedMapEvents> implements IShared
373
370
  * {@inheritDoc @fluidframework/shared-object-base#SharedObject.rollback}
374
371
  * @internal
375
372
  */
376
- protected rollback(content: any, localOpMetadata: unknown) {
377
- this.kernel.rollback(content, localOpMetadata);
378
- }
373
+ protected rollback(content: any, localOpMetadata: unknown) {
374
+ this.kernel.rollback(content, localOpMetadata);
375
+ }
379
376
  }
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
  */
@@ -431,16 +401,16 @@ export class MapKernel {
431
401
  if (handler === undefined) {
432
402
  return false;
433
403
  }
434
- handler.submit(op as IMapOperation, localOpMetadata);
404
+ handler.submit(op as IMapOperation, localOpMetadata as MapLocalOpMetadata);
435
405
  return true;
436
406
  }
437
407
 
438
- public tryGetStashedOpLocalMetadata(op: any): unknown {
408
+ public tryApplyStashedOp(op: any): unknown {
439
409
  const handler = this.messageHandlers.get(op.type);
440
410
  if (handler === undefined) {
441
411
  throw new Error("no apply stashed op handler");
442
412
  }
443
- return handler.getStashedOpLocalMetadata(op as IMapOperation);
413
+ return handler.applyStashedOp(op as IMapOperation);
444
414
  }
445
415
 
446
416
  /**
@@ -460,7 +430,7 @@ export class MapKernel {
460
430
  if (handler === undefined) {
461
431
  return false;
462
432
  }
463
- handler.process(op, local, localOpMetadata);
433
+ handler.process(op, local, localOpMetadata as MapLocalOpMetadata);
464
434
  return true;
465
435
  }
466
436
 
@@ -595,7 +565,7 @@ export class MapKernel {
595
565
  private needProcessKeyOperation(
596
566
  op: IMapKeyOperation,
597
567
  local: boolean,
598
- localOpMetadata: unknown,
568
+ localOpMetadata: MapLocalOpMetadata,
599
569
  ): boolean {
600
570
  if (this.pendingClearMessageIds.length > 0) {
601
571
  if (local) {
@@ -653,7 +623,7 @@ export class MapKernel {
653
623
  }
654
624
  this.clearCore(local);
655
625
  },
656
- submit: (op: IMapClearOperation, localOpMetadata: unknown) => {
626
+ submit: (op: IMapClearOperation, localOpMetadata: IMapClearLocalOpMetadata) => {
657
627
  assert(isClearLocalOpMetadata(localOpMetadata), 0x2fc /* Invalid localOpMetadata for clear */);
658
628
  // We don't reuse the metadata pendingMessageId but send a new one on each submit.
659
629
  const pendingClearMessageId = this.pendingClearMessageIds.shift();
@@ -661,9 +631,11 @@ export class MapKernel {
661
631
  0x2fd /* pendingMessageId does not match */);
662
632
  this.submitMapClearMessage(op, localOpMetadata.previousMap);
663
633
  },
664
- getStashedOpLocalMetadata: (op: IMapClearOperation) => {
634
+ applyStashedOp: (op: IMapClearOperation) => {
635
+ const copy = new Map<string, ILocalValue>(this.data);
636
+ this.clearCore(true);
665
637
  // We don't reuse the metadata pendingMessageId but send a new one on each submit.
666
- return { type: "clear", pendingMessageId: this.getMapClearMessageId() };
638
+ return createClearLocalOpMetadata(op, this.getMapClearMessageId(), copy);
667
639
  },
668
640
  });
669
641
  messageHandlers.set(
@@ -675,12 +647,13 @@ export class MapKernel {
675
647
  }
676
648
  this.deleteCore(op.key, local);
677
649
  },
678
- submit: (op: IMapDeleteOperation, localOpMetadata: unknown) => {
650
+ submit: (op: IMapDeleteOperation, localOpMetadata: MapKeyLocalOpMetadata) => {
679
651
  this.resubmitMapKeyMessage(op, localOpMetadata);
680
652
  },
681
- getStashedOpLocalMetadata: (op: IMapDeleteOperation) => {
653
+ applyStashedOp: (op: IMapDeleteOperation) => {
682
654
  // We don't reuse the metadata pendingMessageId but send a new one on each submit.
683
- return { type: "edit", pendingMessageId: this.getMapKeyMessageId(op) };
655
+ const previousValue = this.deleteCore(op.key, true);
656
+ return createKeyLocalOpMetadata(op, this.getMapKeyMessageId(op), previousValue);
684
657
  },
685
658
  });
686
659
  messageHandlers.set(
@@ -695,12 +668,14 @@ export class MapKernel {
695
668
  const context = this.makeLocal(op.key, op.value);
696
669
  this.setCore(op.key, context, local);
697
670
  },
698
- submit: (op: IMapSetOperation, localOpMetadata: unknown) => {
671
+ submit: (op: IMapSetOperation, localOpMetadata: MapKeyLocalOpMetadata) => {
699
672
  this.resubmitMapKeyMessage(op, localOpMetadata);
700
673
  },
701
- getStashedOpLocalMetadata: (op: IMapSetOperation) => {
674
+ applyStashedOp: (op: IMapSetOperation) => {
702
675
  // We don't reuse the metadata pendingMessageId but send a new one on each submit.
703
- return { type: "edit", pendingMessageId: this.getMapKeyMessageId(op) };
676
+ const context = this.makeLocal(op.key, op.value);
677
+ const previousValue = this.setCore(op.key, context, true);
678
+ return createKeyLocalOpMetadata(op, this.getMapKeyMessageId(op), previousValue);
704
679
  },
705
680
  });
706
681
 
@@ -718,7 +693,7 @@ export class MapKernel {
718
693
  * @param op - The clear message
719
694
  */
720
695
  private submitMapClearMessage(op: IMapClearOperation, previousMap?: Map<string, ILocalValue>): void {
721
- const metadata = { type: "clear", pendingMessageId: this.getMapClearMessageId(), previousMap };
696
+ const metadata = createClearLocalOpMetadata(op, this.getMapClearMessageId(), previousMap);
722
697
  this.submitMessage(op, metadata);
723
698
  }
724
699
 
@@ -739,10 +714,7 @@ export class MapKernel {
739
714
  * @param previousValue - The value of the key before this op
740
715
  */
741
716
  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 };
717
+ const localMetadata = createKeyLocalOpMetadata(op, this.getMapKeyMessageId(op), previousValue);
746
718
  this.submitMessage(op, localMetadata);
747
719
  }
748
720
 
@@ -751,7 +723,7 @@ export class MapKernel {
751
723
  * @param op - The map key message
752
724
  * @param localOpMetadata - Metadata from the previous submit
753
725
  */
754
- private resubmitMapKeyMessage(op: IMapKeyOperation, localOpMetadata: unknown): void {
726
+ private resubmitMapKeyMessage(op: IMapKeyOperation, localOpMetadata: MapLocalOpMetadata): void {
755
727
  assert(isMapKeyLocalOpMetadata(localOpMetadata), 0x2fe /* Invalid localOpMetadata in submit */);
756
728
 
757
729
  // 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.1";
9
+ export const pkgVersion = "2.0.0-internal.1.0.0";