@fluidframework/map 1.4.0-115997 → 2.0.0-dev-rc.1.0.0.224419

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