@fluidframework/map 2.0.0-internal.2.2.0 → 2.0.0-internal.2.3.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.
- package/.eslintrc.js +4 -1
- package/dist/directory.d.ts +5 -4
- package/dist/directory.d.ts.map +1 -1
- package/dist/directory.js +26 -11
- package/dist/directory.js.map +1 -1
- package/dist/interfaces.d.ts +3 -4
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/interfaces.js.map +1 -1
- package/dist/internalInterfaces.d.ts +39 -0
- package/dist/internalInterfaces.d.ts.map +1 -1
- package/dist/internalInterfaces.js.map +1 -1
- package/dist/localValues.d.ts +12 -3
- package/dist/localValues.d.ts.map +1 -1
- package/dist/localValues.js +10 -0
- package/dist/localValues.js.map +1 -1
- package/dist/map.d.ts +4 -4
- package/dist/map.d.ts.map +1 -1
- package/dist/map.js +11 -0
- package/dist/map.js.map +1 -1
- package/dist/mapKernel.d.ts +5 -5
- package/dist/mapKernel.d.ts.map +1 -1
- package/dist/mapKernel.js +25 -11
- package/dist/mapKernel.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/lib/directory.d.ts +5 -4
- package/lib/directory.d.ts.map +1 -1
- package/lib/directory.js +26 -11
- package/lib/directory.js.map +1 -1
- package/lib/interfaces.d.ts +3 -4
- package/lib/interfaces.d.ts.map +1 -1
- package/lib/interfaces.js.map +1 -1
- package/lib/internalInterfaces.d.ts +39 -0
- package/lib/internalInterfaces.d.ts.map +1 -1
- package/lib/internalInterfaces.js.map +1 -1
- package/lib/localValues.d.ts +12 -3
- package/lib/localValues.d.ts.map +1 -1
- package/lib/localValues.js +10 -0
- package/lib/localValues.js.map +1 -1
- package/lib/map.d.ts +4 -4
- package/lib/map.d.ts.map +1 -1
- package/lib/map.js +11 -0
- package/lib/map.js.map +1 -1
- package/lib/mapKernel.d.ts +5 -5
- package/lib/mapKernel.d.ts.map +1 -1
- package/lib/mapKernel.js +25 -11
- package/lib/mapKernel.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/package.json +17 -16
- package/src/directory.ts +85 -54
- package/src/interfaces.ts +19 -9
- package/src/internalInterfaces.ts +45 -0
- package/src/localValues.ts +18 -7
- package/src/map.ts +28 -17
- package/src/mapKernel.ts +50 -32
- package/src/packageVersion.ts +1 -1
package/src/localValues.ts
CHANGED
|
@@ -28,6 +28,8 @@ export interface ILocalValue {
|
|
|
28
28
|
/**
|
|
29
29
|
* The in-memory value stored within.
|
|
30
30
|
*/
|
|
31
|
+
// TODO: Use `unknown` instead (breaking change).
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
31
33
|
readonly value: any;
|
|
32
34
|
|
|
33
35
|
/**
|
|
@@ -42,13 +44,24 @@ export interface ILocalValue {
|
|
|
42
44
|
): ISerializedValue;
|
|
43
45
|
}
|
|
44
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Converts the provided `localValue` to its serialized form.
|
|
49
|
+
*
|
|
50
|
+
* @param localValue - The value to serialize.
|
|
51
|
+
* @param serializer - Data store runtime's serializer.
|
|
52
|
+
* @param bind - Container type's handle.
|
|
53
|
+
*
|
|
54
|
+
* @see {@link ILocalValue.makeSerialized}
|
|
55
|
+
*/
|
|
45
56
|
export function makeSerializable(
|
|
46
57
|
localValue: ILocalValue,
|
|
47
58
|
serializer: IFluidSerializer,
|
|
48
|
-
bind: IFluidHandle
|
|
59
|
+
bind: IFluidHandle,
|
|
60
|
+
): ISerializableValue {
|
|
49
61
|
const value = localValue.makeSerialized(serializer, bind);
|
|
50
62
|
return {
|
|
51
63
|
type: value.type,
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
52
65
|
value: value.value && JSON.parse(value.value),
|
|
53
66
|
};
|
|
54
67
|
}
|
|
@@ -61,8 +74,7 @@ export class PlainLocalValue implements ILocalValue {
|
|
|
61
74
|
* Create a new PlainLocalValue.
|
|
62
75
|
* @param value - The value to store, which may contain shared object handles
|
|
63
76
|
*/
|
|
64
|
-
constructor(public readonly value:
|
|
65
|
-
}
|
|
77
|
+
public constructor(public readonly value: unknown) { }
|
|
66
78
|
|
|
67
79
|
/**
|
|
68
80
|
* {@inheritDoc ILocalValue."type"}
|
|
@@ -98,8 +110,7 @@ export class LocalValueMaker {
|
|
|
98
110
|
* Create a new LocalValueMaker.
|
|
99
111
|
* @param serializer - The serializer to serialize / parse handles.
|
|
100
112
|
*/
|
|
101
|
-
constructor(private readonly serializer: IFluidSerializer) {
|
|
102
|
-
}
|
|
113
|
+
public constructor(private readonly serializer: IFluidSerializer) { }
|
|
103
114
|
|
|
104
115
|
/**
|
|
105
116
|
* Create a new local value from an incoming serialized value.
|
|
@@ -116,7 +127,7 @@ export class LocalValueMaker {
|
|
|
116
127
|
serializable.value = handle;
|
|
117
128
|
}
|
|
118
129
|
|
|
119
|
-
const translatedValue = parseHandles(serializable.value, this.serializer);
|
|
130
|
+
const translatedValue: unknown = parseHandles(serializable.value, this.serializer);
|
|
120
131
|
|
|
121
132
|
return new PlainLocalValue(translatedValue);
|
|
122
133
|
}
|
|
@@ -126,7 +137,7 @@ export class LocalValueMaker {
|
|
|
126
137
|
* @param value - The value to store
|
|
127
138
|
* @returns An ILocalValue containing the value
|
|
128
139
|
*/
|
|
129
|
-
public fromInMemory(value:
|
|
140
|
+
public fromInMemory(value: unknown): ILocalValue {
|
|
130
141
|
return new PlainLocalValue(value);
|
|
131
142
|
}
|
|
132
143
|
}
|
package/src/map.ts
CHANGED
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
ISharedMap,
|
|
23
23
|
ISharedMapEvents,
|
|
24
24
|
} from "./interfaces";
|
|
25
|
-
import { IMapDataObjectSerializable, MapKernel } from "./mapKernel";
|
|
25
|
+
import { IMapDataObjectSerializable, IMapOperation, MapKernel } from "./mapKernel";
|
|
26
26
|
import { pkgVersion } from "./packageVersion";
|
|
27
27
|
|
|
28
28
|
interface IMapSerializationFormat {
|
|
@@ -55,14 +55,14 @@ export class MapFactory implements IChannelFactory {
|
|
|
55
55
|
/**
|
|
56
56
|
* {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory."type"}
|
|
57
57
|
*/
|
|
58
|
-
public get type() {
|
|
58
|
+
public get type(): string {
|
|
59
59
|
return MapFactory.Type;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
63
|
* {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.attributes}
|
|
64
64
|
*/
|
|
65
|
-
public get attributes() {
|
|
65
|
+
public get attributes(): IChannelAttributes {
|
|
66
66
|
return MapFactory.Attributes;
|
|
67
67
|
}
|
|
68
68
|
|
|
@@ -137,7 +137,7 @@ export class SharedMap extends SharedObject<ISharedMapEvents> implements IShared
|
|
|
137
137
|
* @param runtime - Data store runtime.
|
|
138
138
|
* @param attributes - The attributes for the map.
|
|
139
139
|
*/
|
|
140
|
-
constructor(
|
|
140
|
+
public constructor(
|
|
141
141
|
id: string,
|
|
142
142
|
runtime: IFluidDataStoreRuntime,
|
|
143
143
|
attributes: IChannelAttributes,
|
|
@@ -164,6 +164,8 @@ export class SharedMap extends SharedObject<ISharedMapEvents> implements IShared
|
|
|
164
164
|
* Get an iterator over the entries in this map.
|
|
165
165
|
* @returns The iterator
|
|
166
166
|
*/
|
|
167
|
+
// TODO: Use `unknown` instead (breaking change).
|
|
168
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
167
169
|
public entries(): IterableIterator<[string, any]> {
|
|
168
170
|
return this.kernel.entries();
|
|
169
171
|
}
|
|
@@ -172,6 +174,8 @@ export class SharedMap extends SharedObject<ISharedMapEvents> implements IShared
|
|
|
172
174
|
* Get an iterator over the values in this map.
|
|
173
175
|
* @returns The iterator
|
|
174
176
|
*/
|
|
177
|
+
// TODO: Use `unknown` instead (breaking change).
|
|
178
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
175
179
|
public values(): IterableIterator<any> {
|
|
176
180
|
return this.kernel.values();
|
|
177
181
|
}
|
|
@@ -180,6 +184,8 @@ export class SharedMap extends SharedObject<ISharedMapEvents> implements IShared
|
|
|
180
184
|
* Get an iterator over the entries in this map.
|
|
181
185
|
* @returns The iterator
|
|
182
186
|
*/
|
|
187
|
+
// TODO: Use `unknown` instead (breaking change).
|
|
188
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
183
189
|
public [Symbol.iterator](): IterableIterator<[string, any]> {
|
|
184
190
|
return this.kernel.entries();
|
|
185
191
|
}
|
|
@@ -187,7 +193,7 @@ export class SharedMap extends SharedObject<ISharedMapEvents> implements IShared
|
|
|
187
193
|
/**
|
|
188
194
|
* The number of key/value pairs stored in the map.
|
|
189
195
|
*/
|
|
190
|
-
public get size() {
|
|
196
|
+
public get size(): number {
|
|
191
197
|
return this.kernel.size;
|
|
192
198
|
}
|
|
193
199
|
|
|
@@ -195,13 +201,18 @@ export class SharedMap extends SharedObject<ISharedMapEvents> implements IShared
|
|
|
195
201
|
* Executes the given callback on each entry in the map.
|
|
196
202
|
* @param callbackFn - Callback function
|
|
197
203
|
*/
|
|
204
|
+
// TODO: Use `unknown` instead (breaking change).
|
|
205
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
198
206
|
public forEach(callbackFn: (value: any, key: string, map: Map<string, any>) => void): void {
|
|
207
|
+
// eslint-disable-next-line unicorn/no-array-for-each, unicorn/no-array-callback-reference
|
|
199
208
|
this.kernel.forEach(callbackFn);
|
|
200
209
|
}
|
|
201
210
|
|
|
202
211
|
/**
|
|
203
212
|
* {@inheritDoc ISharedMap.get}
|
|
204
213
|
*/
|
|
214
|
+
// TODO: Use `unknown` instead (breaking change).
|
|
215
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
205
216
|
public get<T = any>(key: string): T | undefined {
|
|
206
217
|
return this.kernel.get<T>(key);
|
|
207
218
|
}
|
|
@@ -218,7 +229,7 @@ export class SharedMap extends SharedObject<ISharedMapEvents> implements IShared
|
|
|
218
229
|
/**
|
|
219
230
|
* {@inheritDoc ISharedMap.set}
|
|
220
231
|
*/
|
|
221
|
-
public set(key: string, value:
|
|
232
|
+
public set(key: string, value: unknown): this {
|
|
222
233
|
this.kernel.set(key, value);
|
|
223
234
|
return this;
|
|
224
235
|
}
|
|
@@ -282,7 +293,7 @@ export class SharedMap extends SharedObject<ISharedMapEvents> implements IShared
|
|
|
282
293
|
const content: IMapDataObjectSerializable = {
|
|
283
294
|
[key]: {
|
|
284
295
|
type: value.type,
|
|
285
|
-
value: JSON.parse(value.value),
|
|
296
|
+
value: JSON.parse(value.value) as unknown,
|
|
286
297
|
},
|
|
287
298
|
};
|
|
288
299
|
builder.addBlob(blobName, JSON.stringify(content));
|
|
@@ -302,7 +313,7 @@ export class SharedMap extends SharedObject<ISharedMapEvents> implements IShared
|
|
|
302
313
|
}
|
|
303
314
|
headerBlob[key] = {
|
|
304
315
|
type: value.type,
|
|
305
|
-
value: value.value === undefined ? undefined : JSON.parse(value.value),
|
|
316
|
+
value: value.value === undefined ? undefined : JSON.parse(value.value) as unknown,
|
|
306
317
|
};
|
|
307
318
|
}
|
|
308
319
|
}
|
|
@@ -320,7 +331,7 @@ export class SharedMap extends SharedObject<ISharedMapEvents> implements IShared
|
|
|
320
331
|
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}
|
|
321
332
|
* @internal
|
|
322
333
|
*/
|
|
323
|
-
protected async loadCore(storage: IChannelStorageService) {
|
|
334
|
+
protected async loadCore(storage: IChannelStorageService): Promise<void> {
|
|
324
335
|
const json = await readAndParse<object>(storage, snapshotFileName);
|
|
325
336
|
const newFormat = json as IMapSerializationFormat;
|
|
326
337
|
if (Array.isArray(newFormat.blobs)) {
|
|
@@ -338,31 +349,31 @@ export class SharedMap extends SharedObject<ISharedMapEvents> implements IShared
|
|
|
338
349
|
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.onDisconnect}
|
|
339
350
|
* @internal
|
|
340
351
|
*/
|
|
341
|
-
protected onDisconnect() { }
|
|
352
|
+
protected onDisconnect(): void { }
|
|
342
353
|
|
|
343
354
|
/**
|
|
344
355
|
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.reSubmitCore}
|
|
345
356
|
* @internal
|
|
346
357
|
*/
|
|
347
|
-
protected reSubmitCore(content:
|
|
348
|
-
this.kernel.trySubmitMessage(content, localOpMetadata);
|
|
358
|
+
protected reSubmitCore(content: unknown, localOpMetadata: unknown): void {
|
|
359
|
+
this.kernel.trySubmitMessage(content as IMapOperation, localOpMetadata);
|
|
349
360
|
}
|
|
350
361
|
|
|
351
362
|
/**
|
|
352
363
|
* {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}
|
|
353
364
|
* @internal
|
|
354
365
|
*/
|
|
355
|
-
protected applyStashedOp(content:
|
|
356
|
-
return this.kernel.tryApplyStashedOp(content);
|
|
366
|
+
protected applyStashedOp(content: unknown): unknown {
|
|
367
|
+
return this.kernel.tryApplyStashedOp(content as IMapOperation);
|
|
357
368
|
}
|
|
358
369
|
|
|
359
370
|
/**
|
|
360
371
|
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.processCore}
|
|
361
372
|
* @internal
|
|
362
373
|
*/
|
|
363
|
-
protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {
|
|
374
|
+
protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): void {
|
|
364
375
|
if (message.type === MessageType.Operation) {
|
|
365
|
-
this.kernel.tryProcessMessage(message.contents, local, localOpMetadata);
|
|
376
|
+
this.kernel.tryProcessMessage(message.contents as IMapOperation, local, localOpMetadata);
|
|
366
377
|
}
|
|
367
378
|
}
|
|
368
379
|
|
|
@@ -370,7 +381,7 @@ export class SharedMap extends SharedObject<ISharedMapEvents> implements IShared
|
|
|
370
381
|
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.rollback}
|
|
371
382
|
* @internal
|
|
372
383
|
*/
|
|
373
|
-
protected rollback(content:
|
|
384
|
+
protected rollback(content: unknown, localOpMetadata: unknown): void {
|
|
374
385
|
this.kernel.rollback(content, localOpMetadata);
|
|
375
386
|
}
|
|
376
387
|
}
|
package/src/mapKernel.ts
CHANGED
|
@@ -84,6 +84,8 @@ export interface IMapDataObjectSerialized {
|
|
|
84
84
|
type MapKeyLocalOpMetadata = IMapKeyEditLocalOpMetadata | IMapKeyAddLocalOpMetadata;
|
|
85
85
|
type MapLocalOpMetadata = IMapClearLocalOpMetadata | MapKeyLocalOpMetadata;
|
|
86
86
|
|
|
87
|
+
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */
|
|
88
|
+
|
|
87
89
|
function isMapKeyLocalOpMetadata(metadata: any): metadata is MapKeyLocalOpMetadata {
|
|
88
90
|
return metadata !== undefined && typeof metadata.pendingMessageId === "number" &&
|
|
89
91
|
(metadata.type === "add" || metadata.type === "edit");
|
|
@@ -98,6 +100,8 @@ function isMapLocalOpMetadata(metadata: any): metadata is MapLocalOpMetadata {
|
|
|
98
100
|
(metadata.type === "add" || metadata.type === "edit" || metadata.type === "clear");
|
|
99
101
|
}
|
|
100
102
|
|
|
103
|
+
/* eslint-enable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */
|
|
104
|
+
|
|
101
105
|
function createClearLocalOpMetadata(op: IMapClearOperation,
|
|
102
106
|
pendingClearMessageId: number, previousMap?: Map<string, ILocalValue>): IMapClearLocalOpMetadata {
|
|
103
107
|
const localMetadata: IMapClearLocalOpMetadata = {
|
|
@@ -165,10 +169,10 @@ export class MapKernel {
|
|
|
165
169
|
* @param valueTypes - The value types to register
|
|
166
170
|
* @param eventEmitter - The object that will emit map events
|
|
167
171
|
*/
|
|
168
|
-
constructor(
|
|
172
|
+
public constructor(
|
|
169
173
|
private readonly serializer: IFluidSerializer,
|
|
170
174
|
private readonly handle: IFluidHandle,
|
|
171
|
-
private readonly submitMessage: (op:
|
|
175
|
+
private readonly submitMessage: (op: unknown, localOpMetadata: unknown) => void,
|
|
172
176
|
private readonly isAttached: () => boolean,
|
|
173
177
|
private readonly eventEmitter: TypedEventEmitter<ISharedMapEvents>,
|
|
174
178
|
) {
|
|
@@ -188,17 +192,19 @@ export class MapKernel {
|
|
|
188
192
|
* Get an iterator over the entries in this map.
|
|
189
193
|
* @returns The iterator
|
|
190
194
|
*/
|
|
195
|
+
// TODO: Use `unknown` instead (breaking change).
|
|
196
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
191
197
|
public entries(): IterableIterator<[string, any]> {
|
|
192
198
|
const localEntriesIterator = this.data.entries();
|
|
193
199
|
const iterator = {
|
|
194
|
-
next(): IteratorResult<[string,
|
|
200
|
+
next(): IteratorResult<[string, unknown]> {
|
|
195
201
|
const nextVal = localEntriesIterator.next();
|
|
196
202
|
return nextVal.done
|
|
197
203
|
? { value: undefined, done: true }
|
|
198
204
|
// Unpack the stored value
|
|
199
205
|
: { value: [nextVal.value[0], nextVal.value[1].value], done: false };
|
|
200
206
|
},
|
|
201
|
-
[Symbol.iterator]() {
|
|
207
|
+
[Symbol.iterator](): IterableIterator<[string, unknown]> {
|
|
202
208
|
return this;
|
|
203
209
|
},
|
|
204
210
|
};
|
|
@@ -209,17 +215,19 @@ export class MapKernel {
|
|
|
209
215
|
* Get an iterator over the values in this map.
|
|
210
216
|
* @returns The iterator
|
|
211
217
|
*/
|
|
218
|
+
// TODO: Use `unknown` instead (breaking change).
|
|
219
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
212
220
|
public values(): IterableIterator<any> {
|
|
213
221
|
const localValuesIterator = this.data.values();
|
|
214
222
|
const iterator = {
|
|
215
|
-
next(): IteratorResult<
|
|
223
|
+
next(): IteratorResult<unknown> {
|
|
216
224
|
const nextVal = localValuesIterator.next();
|
|
217
225
|
return nextVal.done
|
|
218
226
|
? { value: undefined, done: true }
|
|
219
227
|
// Unpack the stored value
|
|
220
|
-
: { value: nextVal.value.value, done: false };
|
|
228
|
+
: { value: nextVal.value.value as unknown, done: false };
|
|
221
229
|
},
|
|
222
|
-
[Symbol.iterator]() {
|
|
230
|
+
[Symbol.iterator](): IterableIterator<unknown> {
|
|
223
231
|
return this;
|
|
224
232
|
},
|
|
225
233
|
};
|
|
@@ -230,6 +238,8 @@ export class MapKernel {
|
|
|
230
238
|
* Get an iterator over the entries in this map.
|
|
231
239
|
* @returns The iterator
|
|
232
240
|
*/
|
|
241
|
+
// TODO: Use `unknown` instead (breaking change).
|
|
242
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
233
243
|
public [Symbol.iterator](): IterableIterator<[string, any]> {
|
|
234
244
|
return this.entries();
|
|
235
245
|
}
|
|
@@ -238,7 +248,8 @@ export class MapKernel {
|
|
|
238
248
|
* Executes the given callback on each entry in the map.
|
|
239
249
|
* @param callbackFn - Callback function
|
|
240
250
|
*/
|
|
241
|
-
public forEach(callbackFn: (value:
|
|
251
|
+
public forEach(callbackFn: (value: unknown, key: string, map: Map<string, unknown>) => void): void {
|
|
252
|
+
// eslint-disable-next-line unicorn/no-array-for-each
|
|
242
253
|
this.data.forEach((localValue, key, m) => {
|
|
243
254
|
callbackFn(localValue.value, key, m);
|
|
244
255
|
});
|
|
@@ -247,6 +258,8 @@ export class MapKernel {
|
|
|
247
258
|
/**
|
|
248
259
|
* {@inheritDoc ISharedMap.get}
|
|
249
260
|
*/
|
|
261
|
+
// TODO: Use `unknown` instead (breaking change).
|
|
262
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
250
263
|
public get<T = any>(key: string): T | undefined {
|
|
251
264
|
const localValue = this.data.get(key);
|
|
252
265
|
return localValue === undefined ? undefined : localValue.value as T;
|
|
@@ -264,7 +277,7 @@ export class MapKernel {
|
|
|
264
277
|
/**
|
|
265
278
|
* {@inheritDoc ISharedMap.set}
|
|
266
279
|
*/
|
|
267
|
-
public set(key: string, value:
|
|
280
|
+
public set(key: string, value: unknown): void {
|
|
268
281
|
// Undefined/null keys can't be serialized to JSON in the manner we currently snapshot.
|
|
269
282
|
if (key === undefined || key === null) {
|
|
270
283
|
throw new Error("Undefined and null keys are not supported");
|
|
@@ -347,17 +360,17 @@ export class MapKernel {
|
|
|
347
360
|
*/
|
|
348
361
|
public getSerializedStorage(serializer: IFluidSerializer): IMapDataObjectSerialized {
|
|
349
362
|
const serializableMapData: IMapDataObjectSerialized = {};
|
|
350
|
-
this.data.
|
|
363
|
+
for (const [key, localValue] of this.data.entries()) {
|
|
351
364
|
serializableMapData[key] = localValue.makeSerialized(serializer, this.handle);
|
|
352
|
-
}
|
|
365
|
+
}
|
|
353
366
|
return serializableMapData;
|
|
354
367
|
}
|
|
355
368
|
|
|
356
369
|
public getSerializableStorage(serializer: IFluidSerializer): IMapDataObjectSerializable {
|
|
357
370
|
const serializableMapData: IMapDataObjectSerializable = {};
|
|
358
|
-
this.data.
|
|
371
|
+
for (const [key, localValue] of this.data.entries()) {
|
|
359
372
|
serializableMapData[key] = makeSerializable(localValue, serializer, this.handle);
|
|
360
|
-
}
|
|
373
|
+
}
|
|
361
374
|
return serializableMapData;
|
|
362
375
|
}
|
|
363
376
|
|
|
@@ -392,21 +405,21 @@ export class MapKernel {
|
|
|
392
405
|
* also sent if we are asked to resubmit the message.
|
|
393
406
|
* @returns True if the operation was submitted, false otherwise.
|
|
394
407
|
*/
|
|
395
|
-
public trySubmitMessage(op:
|
|
408
|
+
public trySubmitMessage(op: IMapOperation, localOpMetadata: unknown): boolean {
|
|
396
409
|
const handler = this.messageHandlers.get(op.type);
|
|
397
410
|
if (handler === undefined) {
|
|
398
411
|
return false;
|
|
399
412
|
}
|
|
400
|
-
handler.submit(op
|
|
413
|
+
handler.submit(op, localOpMetadata as MapLocalOpMetadata);
|
|
401
414
|
return true;
|
|
402
415
|
}
|
|
403
416
|
|
|
404
|
-
public tryApplyStashedOp(op:
|
|
417
|
+
public tryApplyStashedOp(op: IMapOperation): unknown {
|
|
405
418
|
const handler = this.messageHandlers.get(op.type);
|
|
406
419
|
if (handler === undefined) {
|
|
407
420
|
throw new Error("no apply stashed op handler");
|
|
408
421
|
}
|
|
409
|
-
return handler.applyStashedOp(op
|
|
422
|
+
return handler.applyStashedOp(op);
|
|
410
423
|
}
|
|
411
424
|
|
|
412
425
|
/**
|
|
@@ -430,12 +443,15 @@ export class MapKernel {
|
|
|
430
443
|
return true;
|
|
431
444
|
}
|
|
432
445
|
|
|
446
|
+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
447
|
+
|
|
433
448
|
/**
|
|
434
449
|
* Rollback a local op
|
|
435
450
|
* @param op - The operation to rollback
|
|
436
451
|
* @param localOpMetadata - The local metadata associated with the op.
|
|
437
452
|
*/
|
|
438
|
-
|
|
453
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
|
|
454
|
+
public rollback(op: any, localOpMetadata: unknown): void {
|
|
439
455
|
if (!isMapLocalOpMetadata(localOpMetadata)) {
|
|
440
456
|
throw new Error("Invalid localOpMetadata");
|
|
441
457
|
}
|
|
@@ -444,9 +460,9 @@ export class MapKernel {
|
|
|
444
460
|
if (localOpMetadata.previousMap === undefined) {
|
|
445
461
|
throw new Error("Cannot rollback without previous map");
|
|
446
462
|
}
|
|
447
|
-
localOpMetadata.previousMap.
|
|
463
|
+
for (const [key, localValue] of localOpMetadata.previousMap.entries()) {
|
|
448
464
|
this.setCore(key, localValue, true);
|
|
449
|
-
}
|
|
465
|
+
}
|
|
450
466
|
|
|
451
467
|
const lastPendingClearId = this.pendingClearMessageIds.pop();
|
|
452
468
|
if (lastPendingClearId === undefined || lastPendingClearId !== localOpMetadata.pendingMessageId) {
|
|
@@ -454,26 +470,28 @@ export class MapKernel {
|
|
|
454
470
|
}
|
|
455
471
|
} else if (op.type === "delete" || op.type === "set") {
|
|
456
472
|
if (localOpMetadata.type === "add") {
|
|
457
|
-
this.deleteCore(op.key, true);
|
|
473
|
+
this.deleteCore(op.key as string, true);
|
|
458
474
|
} else if (localOpMetadata.type === "edit" && localOpMetadata.previousValue !== undefined) {
|
|
459
|
-
this.setCore(op.key, localOpMetadata.previousValue, true);
|
|
475
|
+
this.setCore(op.key as string, localOpMetadata.previousValue, true);
|
|
460
476
|
} else {
|
|
461
477
|
throw new Error("Cannot rollback without previous value");
|
|
462
478
|
}
|
|
463
479
|
|
|
464
|
-
const pendingMessageIds = this.pendingKeys.get(op.key);
|
|
480
|
+
const pendingMessageIds = this.pendingKeys.get(op.key as string);
|
|
465
481
|
const lastPendingMessageId = pendingMessageIds?.pop();
|
|
466
482
|
if (!pendingMessageIds || lastPendingMessageId !== localOpMetadata.pendingMessageId) {
|
|
467
483
|
throw new Error("Rollback op does not match last pending");
|
|
468
484
|
}
|
|
469
485
|
if (pendingMessageIds.length === 0) {
|
|
470
|
-
this.pendingKeys.delete(op.key);
|
|
486
|
+
this.pendingKeys.delete(op.key as string);
|
|
471
487
|
}
|
|
472
488
|
} else {
|
|
473
489
|
throw new Error("Unsupported op for rollback");
|
|
474
490
|
}
|
|
475
491
|
}
|
|
476
492
|
|
|
493
|
+
/* eslint-enable @typescript-eslint/no-unsafe-member-access */
|
|
494
|
+
|
|
477
495
|
/**
|
|
478
496
|
* Set implementation used for both locally sourced sets as well as incoming remote sets.
|
|
479
497
|
* @param key - The key being set
|
|
@@ -483,7 +501,7 @@ export class MapKernel {
|
|
|
483
501
|
*/
|
|
484
502
|
private setCore(key: string, value: ILocalValue, local: boolean): ILocalValue | undefined {
|
|
485
503
|
const previousLocalValue = this.data.get(key);
|
|
486
|
-
const previousValue = previousLocalValue?.value;
|
|
504
|
+
const previousValue: unknown = previousLocalValue?.value;
|
|
487
505
|
this.data.set(key, value);
|
|
488
506
|
this.eventEmitter.emit("valueChanged", { key, previousValue }, local, this.eventEmitter);
|
|
489
507
|
return previousLocalValue;
|
|
@@ -506,7 +524,7 @@ export class MapKernel {
|
|
|
506
524
|
*/
|
|
507
525
|
private deleteCore(key: string, local: boolean): ILocalValue | undefined {
|
|
508
526
|
const previousLocalValue = this.data.get(key);
|
|
509
|
-
const previousValue = previousLocalValue?.value;
|
|
527
|
+
const previousValue: unknown = previousLocalValue?.value;
|
|
510
528
|
const successfullyRemoved = this.data.delete(key);
|
|
511
529
|
if (successfullyRemoved) {
|
|
512
530
|
this.eventEmitter.emit("valueChanged", { key, previousValue }, local, this.eventEmitter);
|
|
@@ -521,14 +539,14 @@ export class MapKernel {
|
|
|
521
539
|
// Assuming the pendingKeys is small and the map is large
|
|
522
540
|
// we will get the value for the pendingKeys and clear the map
|
|
523
541
|
const temp = new Map<string, ILocalValue>();
|
|
524
|
-
this.pendingKeys.
|
|
542
|
+
for (const key of this.pendingKeys.keys()) {
|
|
525
543
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
526
544
|
temp.set(key, this.data.get(key)!);
|
|
527
|
-
}
|
|
545
|
+
}
|
|
528
546
|
this.clearCore(false);
|
|
529
|
-
temp.
|
|
547
|
+
for (const [key, value] of temp.entries()) {
|
|
530
548
|
this.setCore(key, value, true);
|
|
531
|
-
}
|
|
549
|
+
}
|
|
532
550
|
}
|
|
533
551
|
|
|
534
552
|
/**
|
|
@@ -599,7 +617,7 @@ export class MapKernel {
|
|
|
599
617
|
* Get the message handlers for the map.
|
|
600
618
|
* @returns A map of string op names to IMapMessageHandlers for those ops
|
|
601
619
|
*/
|
|
602
|
-
private getMessageHandlers() {
|
|
620
|
+
private getMessageHandlers(): Map<string, IMapMessageHandler> {
|
|
603
621
|
const messageHandlers = new Map<string, IMapMessageHandler>();
|
|
604
622
|
messageHandlers.set(
|
|
605
623
|
"clear",
|
|
@@ -613,7 +631,7 @@ export class MapKernel {
|
|
|
613
631
|
0x2fb /* pendingMessageId does not match */);
|
|
614
632
|
return;
|
|
615
633
|
}
|
|
616
|
-
if (this.pendingKeys.size
|
|
634
|
+
if (this.pendingKeys.size > 0) {
|
|
617
635
|
this.clearExceptPendingKeys();
|
|
618
636
|
return;
|
|
619
637
|
}
|
package/src/packageVersion.ts
CHANGED