@fluidframework/map 1.2.7 → 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.
- package/.eslintrc.js +4 -1
- package/.mocharc.js +12 -0
- package/dist/directory.d.ts +26 -7
- package/dist/directory.d.ts.map +1 -1
- package/dist/directory.js +10 -25
- package/dist/directory.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +139 -181
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/interfaces.js.map +1 -1
- package/dist/internalInterfaces.d.ts +62 -0
- package/dist/internalInterfaces.d.ts.map +1 -0
- package/dist/internalInterfaces.js +7 -0
- package/dist/internalInterfaces.js.map +1 -0
- package/dist/localValues.d.ts +3 -3
- package/dist/localValues.js +2 -2
- package/dist/localValues.js.map +1 -1
- package/dist/map.d.ts +3 -5
- package/dist/map.d.ts.map +1 -1
- package/dist/map.js +4 -7
- package/dist/map.js.map +1 -1
- package/dist/mapKernel.d.ts +10 -41
- package/dist/mapKernel.d.ts.map +1 -1
- package/dist/mapKernel.js +34 -25
- package/dist/mapKernel.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.d.ts.map +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/lib/directory.d.ts +26 -7
- package/lib/directory.d.ts.map +1 -1
- package/lib/directory.js +10 -25
- package/lib/directory.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/lib/interfaces.d.ts +139 -181
- package/lib/interfaces.d.ts.map +1 -1
- package/lib/interfaces.js.map +1 -1
- package/lib/internalInterfaces.d.ts +62 -0
- package/lib/internalInterfaces.d.ts.map +1 -0
- package/lib/internalInterfaces.js +6 -0
- package/lib/internalInterfaces.js.map +1 -0
- package/lib/localValues.d.ts +3 -3
- package/lib/localValues.js +2 -2
- package/lib/localValues.js.map +1 -1
- package/lib/map.d.ts +3 -5
- package/lib/map.d.ts.map +1 -1
- package/lib/map.js +4 -7
- package/lib/map.js.map +1 -1
- package/lib/mapKernel.d.ts +10 -41
- package/lib/mapKernel.d.ts.map +1 -1
- package/lib/mapKernel.js +34 -25
- package/lib/mapKernel.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.d.ts.map +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/package.json +61 -21
- package/src/directory.ts +36 -27
- package/src/index.ts +2 -2
- package/src/interfaces.ts +146 -181
- package/src/internalInterfaces.ts +72 -0
- package/src/localValues.ts +3 -3
- package/src/map.ts +8 -11
- package/src/mapKernel.ts +64 -96
- 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:
|
|
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:
|
|
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
|
-
*
|
|
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
|
-
|
|
227
|
-
|
|
228
|
-
} else {
|
|
196
|
+
return nextVal.done
|
|
197
|
+
? { value: undefined, done: true }
|
|
229
198
|
// Unpack the stored value
|
|
230
|
-
|
|
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
|
-
|
|
250
|
-
|
|
251
|
-
} else {
|
|
217
|
+
return nextVal.done
|
|
218
|
+
? { value: undefined, done: true }
|
|
252
219
|
// Unpack the stored value
|
|
253
|
-
|
|
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
|
|
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.
|
|
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:
|
|
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:
|
|
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
|
-
|
|
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
|
|
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:
|
|
646
|
+
submit: (op: IMapDeleteOperation, localOpMetadata: MapKeyLocalOpMetadata) => {
|
|
679
647
|
this.resubmitMapKeyMessage(op, localOpMetadata);
|
|
680
648
|
},
|
|
681
|
-
|
|
649
|
+
applyStashedOp: (op: IMapDeleteOperation) => {
|
|
682
650
|
// We don't reuse the metadata pendingMessageId but send a new one on each submit.
|
|
683
|
-
|
|
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:
|
|
667
|
+
submit: (op: IMapSetOperation, localOpMetadata: MapKeyLocalOpMetadata) => {
|
|
699
668
|
this.resubmitMapKeyMessage(op, localOpMetadata);
|
|
700
669
|
},
|
|
701
|
-
|
|
670
|
+
applyStashedOp: (op: IMapSetOperation) => {
|
|
702
671
|
// We don't reuse the metadata pendingMessageId but send a new one on each submit.
|
|
703
|
-
|
|
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 =
|
|
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
|
|
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:
|
|
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
|
package/src/packageVersion.ts
CHANGED