@fluidframework/map 2.0.0-dev.2.3.0.115467 → 2.0.0-dev.4.1.0.148229

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 (72) hide show
  1. package/.eslintrc.js +12 -14
  2. package/.mocharc.js +2 -2
  3. package/README.md +3 -3
  4. package/api-extractor.json +2 -2
  5. package/dist/directory.d.ts +38 -5
  6. package/dist/directory.d.ts.map +1 -1
  7. package/dist/directory.js +285 -88
  8. package/dist/directory.js.map +1 -1
  9. package/dist/index.d.ts +1 -1
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js.map +1 -1
  12. package/dist/interfaces.d.ts +27 -17
  13. package/dist/interfaces.d.ts.map +1 -1
  14. package/dist/interfaces.js.map +1 -1
  15. package/dist/internalInterfaces.d.ts +39 -0
  16. package/dist/internalInterfaces.d.ts.map +1 -1
  17. package/dist/internalInterfaces.js.map +1 -1
  18. package/dist/localValues.d.ts +12 -3
  19. package/dist/localValues.d.ts.map +1 -1
  20. package/dist/localValues.js +10 -0
  21. package/dist/localValues.js.map +1 -1
  22. package/dist/map.d.ts +5 -5
  23. package/dist/map.d.ts.map +1 -1
  24. package/dist/map.js +15 -2
  25. package/dist/map.js.map +1 -1
  26. package/dist/mapKernel.d.ts +5 -5
  27. package/dist/mapKernel.d.ts.map +1 -1
  28. package/dist/mapKernel.js +58 -33
  29. package/dist/mapKernel.js.map +1 -1
  30. package/dist/packageVersion.d.ts +1 -1
  31. package/dist/packageVersion.js +1 -1
  32. package/dist/packageVersion.js.map +1 -1
  33. package/lib/directory.d.ts +38 -5
  34. package/lib/directory.d.ts.map +1 -1
  35. package/lib/directory.js +287 -90
  36. package/lib/directory.js.map +1 -1
  37. package/lib/index.d.ts +1 -1
  38. package/lib/index.d.ts.map +1 -1
  39. package/lib/index.js.map +1 -1
  40. package/lib/interfaces.d.ts +27 -17
  41. package/lib/interfaces.d.ts.map +1 -1
  42. package/lib/interfaces.js.map +1 -1
  43. package/lib/internalInterfaces.d.ts +39 -0
  44. package/lib/internalInterfaces.d.ts.map +1 -1
  45. package/lib/internalInterfaces.js.map +1 -1
  46. package/lib/localValues.d.ts +12 -3
  47. package/lib/localValues.d.ts.map +1 -1
  48. package/lib/localValues.js +10 -0
  49. package/lib/localValues.js.map +1 -1
  50. package/lib/map.d.ts +5 -5
  51. package/lib/map.d.ts.map +1 -1
  52. package/lib/map.js +16 -3
  53. package/lib/map.js.map +1 -1
  54. package/lib/mapKernel.d.ts +5 -5
  55. package/lib/mapKernel.d.ts.map +1 -1
  56. package/lib/mapKernel.js +59 -34
  57. package/lib/mapKernel.js.map +1 -1
  58. package/lib/packageVersion.d.ts +1 -1
  59. package/lib/packageVersion.js +1 -1
  60. package/lib/packageVersion.js.map +1 -1
  61. package/package.json +60 -59
  62. package/prettier.config.cjs +1 -1
  63. package/src/directory.ts +2207 -1848
  64. package/src/index.ts +1 -0
  65. package/src/interfaces.ts +309 -288
  66. package/src/internalInterfaces.ts +83 -38
  67. package/src/localValues.ts +95 -93
  68. package/src/map.ts +364 -345
  69. package/src/mapKernel.ts +729 -676
  70. package/src/packageVersion.ts +1 -1
  71. package/tsconfig.esnext.json +5 -5
  72. package/tsconfig.json +9 -15
@@ -9,64 +9,109 @@ import { ILocalValue } from "./localValues";
9
9
  /**
10
10
  * Operation indicating a value should be set for a key.
11
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;
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
27
  }
28
28
 
29
29
  /**
30
30
  * Operation indicating the map should be cleared.
31
31
  */
32
- export interface IMapClearOperation {
33
- /**
34
- * String identifier of the operation type.
35
- */
36
- type: "clear";
32
+ export interface IMapClearOperation {
33
+ /**
34
+ * String identifier of the operation type.
35
+ */
36
+ type: "clear";
37
37
  }
38
38
 
39
39
  /**
40
40
  * Operation indicating a key should be deleted from the map.
41
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;
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
52
  }
53
53
 
54
+ /**
55
+ * Metadata for an local `edit` operation.
56
+ */
54
57
  export interface IMapKeyEditLocalOpMetadata {
55
- type: "edit";
56
- pendingMessageId: number;
57
- previousValue: ILocalValue;
58
+ /**
59
+ * String identifier of the operation type.
60
+ */
61
+ type: "edit";
62
+
63
+ /**
64
+ * Unique identifier for the local operation.
65
+ */
66
+ pendingMessageId: number;
67
+
68
+ /**
69
+ * Local value prior to the edit.
70
+ */
71
+ previousValue: ILocalValue;
58
72
  }
59
73
 
74
+ /**
75
+ * Metadata for an local `add` operation.
76
+ */
60
77
  export interface IMapKeyAddLocalOpMetadata {
61
- type: "add";
62
- pendingMessageId: number;
78
+ /**
79
+ * String identifier of the operation type.
80
+ */
81
+ type: "add";
82
+
83
+ /**
84
+ * Unique identifier for the local operation.
85
+ */
86
+ pendingMessageId: number;
63
87
  }
64
88
 
89
+ /**
90
+ * Metadata for an local `clear` operation.
91
+ */
65
92
  export interface IMapClearLocalOpMetadata {
66
- type: "clear";
67
- pendingMessageId: number;
68
- previousMap?: Map<string, ILocalValue>;
93
+ /**
94
+ * String identifier of the operation type.
95
+ */
96
+ type: "clear";
97
+
98
+ /**
99
+ * Unique identifier for the local operation.
100
+ */
101
+ pendingMessageId: number;
102
+
103
+ /**
104
+ * Local map contents prior to clearing it.
105
+ */
106
+ previousMap?: Map<string, ILocalValue>;
69
107
  }
70
108
 
109
+ /**
110
+ * Metadata for a local operation associated with a specific key entry in the map.
111
+ */
71
112
  export type MapKeyLocalOpMetadata = IMapKeyEditLocalOpMetadata | IMapKeyAddLocalOpMetadata;
113
+
114
+ /**
115
+ * Metadata for a local operation.
116
+ */
72
117
  export type MapLocalOpMetadata = IMapClearLocalOpMetadata | MapKeyLocalOpMetadata;
@@ -5,88 +5,91 @@
5
5
 
6
6
  import { IFluidHandle } from "@fluidframework/core-interfaces";
7
7
  import {
8
- IFluidSerializer,
9
- ISerializedHandle,
10
- parseHandles,
11
- serializeHandles,
12
- ValueType,
8
+ IFluidSerializer,
9
+ ISerializedHandle,
10
+ parseHandles,
11
+ serializeHandles,
12
+ ValueType,
13
13
  } from "@fluidframework/shared-object-base";
14
- import {
15
- ISerializableValue,
16
- ISerializedValue,
17
- } from "./interfaces";
14
+ import { ISerializableValue, ISerializedValue } from "./interfaces";
18
15
 
19
16
  /**
20
17
  * A local value to be stored in a container type Distributed Data Store (DDS).
21
18
  */
22
19
  export interface ILocalValue {
23
- /**
24
- * Type indicator of the value stored within.
25
- */
26
- readonly type: string;
20
+ /**
21
+ * Type indicator of the value stored within.
22
+ */
23
+ readonly type: string;
27
24
 
28
- /**
29
- * The in-memory value stored within.
30
- */
31
- readonly value: any;
25
+ /**
26
+ * The in-memory value stored within.
27
+ */
28
+ // TODO: Use `unknown` instead (breaking change).
29
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
+ readonly value: any;
32
31
 
33
- /**
34
- * Retrieve the serialized form of the value stored within.
35
- * @param serializer - Data store runtime's serializer
36
- * @param bind - Container type's handle
37
- * @returns The serialized form of the contained value
38
- */
39
- makeSerialized(
40
- serializer: IFluidSerializer,
41
- bind: IFluidHandle,
42
- ): ISerializedValue;
32
+ /**
33
+ * Retrieve the serialized form of the value stored within.
34
+ * @param serializer - Data store runtime's serializer
35
+ * @param bind - Container type's handle
36
+ * @returns The serialized form of the contained value
37
+ */
38
+ makeSerialized(serializer: IFluidSerializer, bind: IFluidHandle): ISerializedValue;
43
39
  }
44
40
 
41
+ /**
42
+ * Converts the provided `localValue` to its serialized form.
43
+ *
44
+ * @param localValue - The value to serialize.
45
+ * @param serializer - Data store runtime's serializer.
46
+ * @param bind - Container type's handle.
47
+ *
48
+ * @see {@link ILocalValue.makeSerialized}
49
+ */
45
50
  export function makeSerializable(
46
- localValue: ILocalValue,
47
- serializer: IFluidSerializer,
48
- bind: IFluidHandle): ISerializableValue {
49
- const value = localValue.makeSerialized(serializer, bind);
50
- return {
51
- type: value.type,
52
- value: value.value && JSON.parse(value.value),
53
- };
51
+ localValue: ILocalValue,
52
+ serializer: IFluidSerializer,
53
+ bind: IFluidHandle,
54
+ ): ISerializableValue {
55
+ const value = localValue.makeSerialized(serializer, bind);
56
+ return {
57
+ type: value.type,
58
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
59
+ value: value.value && JSON.parse(value.value),
60
+ };
54
61
  }
55
62
 
56
63
  /**
57
64
  * Manages a contained plain value. May also contain shared object handles.
58
65
  */
59
66
  export class PlainLocalValue implements ILocalValue {
60
- /**
61
- * Create a new PlainLocalValue.
62
- * @param value - The value to store, which may contain shared object handles
63
- */
64
- constructor(public readonly value: any) {
65
- }
67
+ /**
68
+ * Create a new PlainLocalValue.
69
+ * @param value - The value to store, which may contain shared object handles
70
+ */
71
+ public constructor(public readonly value: unknown) {}
66
72
 
67
- /**
68
- * {@inheritDoc ILocalValue."type"}
69
- */
70
- public get type(): string {
71
- return ValueType[ValueType.Plain];
72
- }
73
+ /**
74
+ * {@inheritDoc ILocalValue."type"}
75
+ */
76
+ public get type(): string {
77
+ return ValueType[ValueType.Plain];
78
+ }
73
79
 
74
- /**
75
- * {@inheritDoc ILocalValue.makeSerialized}
76
- */
77
- public makeSerialized(
78
- serializer: IFluidSerializer,
79
- bind: IFluidHandle,
80
- ): ISerializedValue {
81
- // Stringify to convert to the serialized handle values - and then parse in order to create
82
- // a POJO for the op
83
- const value = serializeHandles(this.value, serializer, bind);
80
+ /**
81
+ * {@inheritDoc ILocalValue.makeSerialized}
82
+ */
83
+ public makeSerialized(serializer: IFluidSerializer, bind: IFluidHandle): ISerializedValue {
84
+ // Stringify to convert to the serialized handle values - and then parse in order to create
85
+ // a POJO for the op
86
+ const value = serializeHandles(this.value, serializer, bind);
84
87
 
85
- return {
86
- type: this.type,
87
- value,
88
- };
89
- }
88
+ return {
89
+ type: this.type,
90
+ value,
91
+ };
92
+ }
90
93
  }
91
94
 
92
95
  /**
@@ -94,39 +97,38 @@ export class PlainLocalValue implements ILocalValue {
94
97
  * values with minimal awareness of how those objects are stored, serialized, and deserialized.
95
98
  */
96
99
  export class LocalValueMaker {
97
- /**
98
- * Create a new LocalValueMaker.
99
- * @param serializer - The serializer to serialize / parse handles.
100
- */
101
- constructor(private readonly serializer: IFluidSerializer) {
102
- }
100
+ /**
101
+ * Create a new LocalValueMaker.
102
+ * @param serializer - The serializer to serialize / parse handles.
103
+ */
104
+ public constructor(private readonly serializer: IFluidSerializer) {}
103
105
 
104
- /**
105
- * Create a new local value from an incoming serialized value.
106
- * @param serializable - The serializable value to make local
107
- */
108
- public fromSerializable(serializable: ISerializableValue): ILocalValue {
109
- // Migrate from old shared value to handles
110
- if (serializable.type === ValueType[ValueType.Shared]) {
111
- serializable.type = ValueType[ValueType.Plain];
112
- const handle: ISerializedHandle = {
113
- type: "__fluid_handle__",
114
- url: serializable.value as string,
115
- };
116
- serializable.value = handle;
117
- }
106
+ /**
107
+ * Create a new local value from an incoming serialized value.
108
+ * @param serializable - The serializable value to make local
109
+ */
110
+ public fromSerializable(serializable: ISerializableValue): ILocalValue {
111
+ // Migrate from old shared value to handles
112
+ if (serializable.type === ValueType[ValueType.Shared]) {
113
+ serializable.type = ValueType[ValueType.Plain];
114
+ const handle: ISerializedHandle = {
115
+ type: "__fluid_handle__",
116
+ url: serializable.value as string,
117
+ };
118
+ serializable.value = handle;
119
+ }
118
120
 
119
- const translatedValue = parseHandles(serializable.value, this.serializer);
121
+ const translatedValue: unknown = parseHandles(serializable.value, this.serializer);
120
122
 
121
- return new PlainLocalValue(translatedValue);
122
- }
123
+ return new PlainLocalValue(translatedValue);
124
+ }
123
125
 
124
- /**
125
- * Create a new local value containing a given plain object.
126
- * @param value - The value to store
127
- * @returns An ILocalValue containing the value
128
- */
129
- public fromInMemory(value: any): ILocalValue {
130
- return new PlainLocalValue(value);
131
- }
126
+ /**
127
+ * Create a new local value containing a given plain object.
128
+ * @param value - The value to store
129
+ * @returns An ILocalValue containing the value
130
+ */
131
+ public fromInMemory(value: unknown): ILocalValue {
132
+ return new PlainLocalValue(value);
133
+ }
132
134
  }