@fluidframework/presence 2.92.0 → 2.100.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 (260) hide show
  1. package/README.md +4 -4
  2. package/dist/alpha.d.ts +6 -4
  3. package/dist/beta.d.ts +5 -2
  4. package/dist/getPresence.d.ts +4 -9
  5. package/dist/getPresence.d.ts.map +1 -1
  6. package/dist/getPresence.js +6 -86
  7. package/dist/getPresence.js.map +1 -1
  8. package/dist/index.d.ts +4 -13
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +8 -8
  11. package/dist/index.js.map +1 -1
  12. package/dist/legacy.alpha.d.ts +6 -4
  13. package/dist/package.json +1 -15
  14. package/dist/public.d.ts +69 -0
  15. package/lib/alpha.d.ts +6 -4
  16. package/lib/beta.d.ts +5 -2
  17. package/lib/getPresence.d.ts +4 -9
  18. package/lib/getPresence.d.ts.map +1 -1
  19. package/lib/getPresence.js +6 -85
  20. package/lib/getPresence.js.map +1 -1
  21. package/lib/index.d.ts +4 -13
  22. package/lib/index.d.ts.map +1 -1
  23. package/lib/index.js +5 -4
  24. package/lib/index.js.map +1 -1
  25. package/lib/legacy.alpha.d.ts +6 -4
  26. package/lib/public.d.ts +69 -0
  27. package/lib/tsdoc-metadata.json +11 -0
  28. package/package.json +32 -78
  29. package/dist/baseTypes.d.ts +0 -24
  30. package/dist/baseTypes.d.ts.map +0 -1
  31. package/dist/baseTypes.js +0 -7
  32. package/dist/baseTypes.js.map +0 -1
  33. package/dist/broadcastControls.d.ts +0 -37
  34. package/dist/broadcastControls.d.ts.map +0 -1
  35. package/dist/broadcastControls.js +0 -60
  36. package/dist/broadcastControls.js.map +0 -1
  37. package/dist/broadcastControlsTypes.d.ts +0 -38
  38. package/dist/broadcastControlsTypes.d.ts.map +0 -1
  39. package/dist/broadcastControlsTypes.js +0 -7
  40. package/dist/broadcastControlsTypes.js.map +0 -1
  41. package/dist/exposedInternalTypes.d.ts +0 -138
  42. package/dist/exposedInternalTypes.d.ts.map +0 -1
  43. package/dist/exposedInternalTypes.js +0 -19
  44. package/dist/exposedInternalTypes.js.map +0 -1
  45. package/dist/exposedUtilityTypes.d.ts +0 -108
  46. package/dist/exposedUtilityTypes.d.ts.map +0 -1
  47. package/dist/exposedUtilityTypes.js +0 -7
  48. package/dist/exposedUtilityTypes.js.map +0 -1
  49. package/dist/internalUtils.d.ts +0 -125
  50. package/dist/internalUtils.d.ts.map +0 -1
  51. package/dist/internalUtils.js +0 -99
  52. package/dist/internalUtils.js.map +0 -1
  53. package/dist/latestMapTypes.d.ts +0 -343
  54. package/dist/latestMapTypes.d.ts.map +0 -1
  55. package/dist/latestMapTypes.js +0 -7
  56. package/dist/latestMapTypes.js.map +0 -1
  57. package/dist/latestMapValueManager.d.ts +0 -52
  58. package/dist/latestMapValueManager.d.ts.map +0 -1
  59. package/dist/latestMapValueManager.js +0 -250
  60. package/dist/latestMapValueManager.js.map +0 -1
  61. package/dist/latestTypes.d.ts +0 -183
  62. package/dist/latestTypes.d.ts.map +0 -1
  63. package/dist/latestTypes.js +0 -7
  64. package/dist/latestTypes.js.map +0 -1
  65. package/dist/latestValueManager.d.ts +0 -10
  66. package/dist/latestValueManager.d.ts.map +0 -1
  67. package/dist/latestValueManager.js +0 -117
  68. package/dist/latestValueManager.js.map +0 -1
  69. package/dist/latestValueTypes.d.ts +0 -108
  70. package/dist/latestValueTypes.d.ts.map +0 -1
  71. package/dist/latestValueTypes.js +0 -7
  72. package/dist/latestValueTypes.js.map +0 -1
  73. package/dist/notificationsManager.d.ts +0 -27
  74. package/dist/notificationsManager.d.ts.map +0 -1
  75. package/dist/notificationsManager.js +0 -98
  76. package/dist/notificationsManager.js.map +0 -1
  77. package/dist/notificationsManagerTypes.d.ts +0 -144
  78. package/dist/notificationsManagerTypes.d.ts.map +0 -1
  79. package/dist/notificationsManagerTypes.js +0 -7
  80. package/dist/notificationsManagerTypes.js.map +0 -1
  81. package/dist/packageVersion.d.ts +0 -9
  82. package/dist/packageVersion.d.ts.map +0 -1
  83. package/dist/packageVersion.js +0 -12
  84. package/dist/packageVersion.js.map +0 -1
  85. package/dist/presence.d.ts +0 -229
  86. package/dist/presence.d.ts.map +0 -1
  87. package/dist/presence.js +0 -23
  88. package/dist/presence.js.map +0 -1
  89. package/dist/presenceDatastoreManager.d.ts +0 -149
  90. package/dist/presenceDatastoreManager.d.ts.map +0 -1
  91. package/dist/presenceDatastoreManager.js +0 -667
  92. package/dist/presenceDatastoreManager.js.map +0 -1
  93. package/dist/presenceManager.d.ts +0 -16
  94. package/dist/presenceManager.d.ts.map +0 -1
  95. package/dist/presenceManager.js +0 -140
  96. package/dist/presenceManager.js.map +0 -1
  97. package/dist/presenceStates.d.ts +0 -102
  98. package/dist/presenceStates.d.ts.map +0 -1
  99. package/dist/presenceStates.js +0 -231
  100. package/dist/presenceStates.js.map +0 -1
  101. package/dist/protocol.d.ts +0 -111
  102. package/dist/protocol.d.ts.map +0 -1
  103. package/dist/protocol.js +0 -20
  104. package/dist/protocol.js.map +0 -1
  105. package/dist/runtimeTypes.d.ts +0 -26
  106. package/dist/runtimeTypes.d.ts.map +0 -1
  107. package/dist/runtimeTypes.js +0 -7
  108. package/dist/runtimeTypes.js.map +0 -1
  109. package/dist/stateDatastore.d.ts +0 -56
  110. package/dist/stateDatastore.d.ts.map +0 -1
  111. package/dist/stateDatastore.js +0 -22
  112. package/dist/stateDatastore.js.map +0 -1
  113. package/dist/stateFactory.d.ts +0 -18
  114. package/dist/stateFactory.d.ts.map +0 -1
  115. package/dist/stateFactory.js +0 -23
  116. package/dist/stateFactory.js.map +0 -1
  117. package/dist/statesManagerTypes.d.ts +0 -27
  118. package/dist/statesManagerTypes.d.ts.map +0 -1
  119. package/dist/statesManagerTypes.js +0 -7
  120. package/dist/statesManagerTypes.js.map +0 -1
  121. package/dist/systemWorkspace.d.ts +0 -58
  122. package/dist/systemWorkspace.d.ts.map +0 -1
  123. package/dist/systemWorkspace.js +0 -265
  124. package/dist/systemWorkspace.js.map +0 -1
  125. package/dist/timerManager.d.ts +0 -37
  126. package/dist/timerManager.d.ts.map +0 -1
  127. package/dist/timerManager.js +0 -65
  128. package/dist/timerManager.js.map +0 -1
  129. package/dist/types.d.ts +0 -132
  130. package/dist/types.d.ts.map +0 -1
  131. package/dist/types.js +0 -7
  132. package/dist/types.js.map +0 -1
  133. package/dist/validatableTypes.d.ts +0 -69
  134. package/dist/validatableTypes.d.ts.map +0 -1
  135. package/dist/validatableTypes.js +0 -7
  136. package/dist/validatableTypes.js.map +0 -1
  137. package/dist/validatedGetter.d.ts +0 -18
  138. package/dist/validatedGetter.d.ts.map +0 -1
  139. package/dist/validatedGetter.js +0 -43
  140. package/dist/validatedGetter.js.map +0 -1
  141. package/dist/valueManager.d.ts +0 -15
  142. package/dist/valueManager.d.ts.map +0 -1
  143. package/dist/valueManager.js +0 -22
  144. package/dist/valueManager.js.map +0 -1
  145. package/lib/baseTypes.d.ts +0 -24
  146. package/lib/baseTypes.d.ts.map +0 -1
  147. package/lib/baseTypes.js +0 -6
  148. package/lib/baseTypes.js.map +0 -1
  149. package/lib/broadcastControls.d.ts +0 -37
  150. package/lib/broadcastControls.d.ts.map +0 -1
  151. package/lib/broadcastControls.js +0 -55
  152. package/lib/broadcastControls.js.map +0 -1
  153. package/lib/broadcastControlsTypes.d.ts +0 -38
  154. package/lib/broadcastControlsTypes.d.ts.map +0 -1
  155. package/lib/broadcastControlsTypes.js +0 -6
  156. package/lib/broadcastControlsTypes.js.map +0 -1
  157. package/lib/exposedInternalTypes.d.ts +0 -138
  158. package/lib/exposedInternalTypes.d.ts.map +0 -1
  159. package/lib/exposedInternalTypes.js +0 -16
  160. package/lib/exposedInternalTypes.js.map +0 -1
  161. package/lib/exposedUtilityTypes.d.ts +0 -108
  162. package/lib/exposedUtilityTypes.d.ts.map +0 -1
  163. package/lib/exposedUtilityTypes.js +0 -6
  164. package/lib/exposedUtilityTypes.js.map +0 -1
  165. package/lib/internalUtils.d.ts +0 -125
  166. package/lib/internalUtils.d.ts.map +0 -1
  167. package/lib/internalUtils.js +0 -90
  168. package/lib/internalUtils.js.map +0 -1
  169. package/lib/latestMapTypes.d.ts +0 -343
  170. package/lib/latestMapTypes.d.ts.map +0 -1
  171. package/lib/latestMapTypes.js +0 -6
  172. package/lib/latestMapTypes.js.map +0 -1
  173. package/lib/latestMapValueManager.d.ts +0 -52
  174. package/lib/latestMapValueManager.d.ts.map +0 -1
  175. package/lib/latestMapValueManager.js +0 -246
  176. package/lib/latestMapValueManager.js.map +0 -1
  177. package/lib/latestTypes.d.ts +0 -183
  178. package/lib/latestTypes.d.ts.map +0 -1
  179. package/lib/latestTypes.js +0 -6
  180. package/lib/latestTypes.js.map +0 -1
  181. package/lib/latestValueManager.d.ts +0 -10
  182. package/lib/latestValueManager.d.ts.map +0 -1
  183. package/lib/latestValueManager.js +0 -113
  184. package/lib/latestValueManager.js.map +0 -1
  185. package/lib/latestValueTypes.d.ts +0 -108
  186. package/lib/latestValueTypes.d.ts.map +0 -1
  187. package/lib/latestValueTypes.js +0 -6
  188. package/lib/latestValueTypes.js.map +0 -1
  189. package/lib/notificationsManager.d.ts +0 -27
  190. package/lib/notificationsManager.d.ts.map +0 -1
  191. package/lib/notificationsManager.js +0 -94
  192. package/lib/notificationsManager.js.map +0 -1
  193. package/lib/notificationsManagerTypes.d.ts +0 -144
  194. package/lib/notificationsManagerTypes.d.ts.map +0 -1
  195. package/lib/notificationsManagerTypes.js +0 -6
  196. package/lib/notificationsManagerTypes.js.map +0 -1
  197. package/lib/packageVersion.d.ts +0 -9
  198. package/lib/packageVersion.d.ts.map +0 -1
  199. package/lib/packageVersion.js +0 -9
  200. package/lib/packageVersion.js.map +0 -1
  201. package/lib/presence.d.ts +0 -229
  202. package/lib/presence.d.ts.map +0 -1
  203. package/lib/presence.js +0 -20
  204. package/lib/presence.js.map +0 -1
  205. package/lib/presenceDatastoreManager.d.ts +0 -149
  206. package/lib/presenceDatastoreManager.d.ts.map +0 -1
  207. package/lib/presenceDatastoreManager.js +0 -663
  208. package/lib/presenceDatastoreManager.js.map +0 -1
  209. package/lib/presenceManager.d.ts +0 -16
  210. package/lib/presenceManager.d.ts.map +0 -1
  211. package/lib/presenceManager.js +0 -136
  212. package/lib/presenceManager.js.map +0 -1
  213. package/lib/presenceStates.d.ts +0 -102
  214. package/lib/presenceStates.d.ts.map +0 -1
  215. package/lib/presenceStates.js +0 -225
  216. package/lib/presenceStates.js.map +0 -1
  217. package/lib/protocol.d.ts +0 -111
  218. package/lib/protocol.d.ts.map +0 -1
  219. package/lib/protocol.js +0 -17
  220. package/lib/protocol.js.map +0 -1
  221. package/lib/runtimeTypes.d.ts +0 -26
  222. package/lib/runtimeTypes.d.ts.map +0 -1
  223. package/lib/runtimeTypes.js +0 -6
  224. package/lib/runtimeTypes.js.map +0 -1
  225. package/lib/stateDatastore.d.ts +0 -56
  226. package/lib/stateDatastore.d.ts.map +0 -1
  227. package/lib/stateDatastore.js +0 -17
  228. package/lib/stateDatastore.js.map +0 -1
  229. package/lib/stateFactory.d.ts +0 -18
  230. package/lib/stateFactory.d.ts.map +0 -1
  231. package/lib/stateFactory.js +0 -20
  232. package/lib/stateFactory.js.map +0 -1
  233. package/lib/statesManagerTypes.d.ts +0 -27
  234. package/lib/statesManagerTypes.d.ts.map +0 -1
  235. package/lib/statesManagerTypes.js +0 -6
  236. package/lib/statesManagerTypes.js.map +0 -1
  237. package/lib/systemWorkspace.d.ts +0 -58
  238. package/lib/systemWorkspace.d.ts.map +0 -1
  239. package/lib/systemWorkspace.js +0 -261
  240. package/lib/systemWorkspace.js.map +0 -1
  241. package/lib/timerManager.d.ts +0 -37
  242. package/lib/timerManager.d.ts.map +0 -1
  243. package/lib/timerManager.js +0 -61
  244. package/lib/timerManager.js.map +0 -1
  245. package/lib/types.d.ts +0 -132
  246. package/lib/types.d.ts.map +0 -1
  247. package/lib/types.js +0 -6
  248. package/lib/types.js.map +0 -1
  249. package/lib/validatableTypes.d.ts +0 -69
  250. package/lib/validatableTypes.d.ts.map +0 -1
  251. package/lib/validatableTypes.js +0 -6
  252. package/lib/validatableTypes.js.map +0 -1
  253. package/lib/validatedGetter.d.ts +0 -18
  254. package/lib/validatedGetter.d.ts.map +0 -1
  255. package/lib/validatedGetter.js +0 -39
  256. package/lib/validatedGetter.js.map +0 -1
  257. package/lib/valueManager.d.ts +0 -15
  258. package/lib/valueManager.d.ts.map +0 -1
  259. package/lib/valueManager.js +0 -17
  260. package/lib/valueManager.js.map +0 -1
@@ -1,246 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- import { createEmitter } from "@fluid-internal/client-utils";
6
- import { OptionalBroadcastControl } from "./broadcastControls.js";
7
- import { asDeeplyReadonly, asDeeplyReadonlyDeserializedJson, isValueRequiredState, objectEntries, objectKeys, toOpaqueJson, } from "./internalUtils.js";
8
- import { datastoreFromHandle } from "./stateDatastore.js";
9
- import { createValidatedGetter } from "./validatedGetter.js";
10
- import { brandIVM } from "./valueManager.js";
11
- class ValueMapImpl {
12
- constructor(value, emitter, localUpdate) {
13
- this.value = value;
14
- this.emitter = emitter;
15
- this.localUpdate = localUpdate;
16
- // All initial items are expected to be defined.
17
- // TODO assert all defined and/or update type.
18
- this.countDefined = Object.keys(value.items).length;
19
- }
20
- /**
21
- * Note: caller must ensure key exists in this.value.items.
22
- */
23
- updateItem(key, value) {
24
- this.value.rev += 1;
25
- // Caller is required to ensure key exists.
26
- const item = this.value.items[key];
27
- item.rev += 1;
28
- item.timestamp = Date.now();
29
- if (value === undefined) {
30
- delete item.value;
31
- }
32
- else {
33
- item.value = value;
34
- }
35
- const update = { rev: this.value.rev, items: { [key]: item } };
36
- this.localUpdate(update);
37
- }
38
- clear() {
39
- throw new Error("Method not implemented.");
40
- }
41
- delete(key) {
42
- const { items } = this.value;
43
- const hasKey = items[key]?.value !== undefined;
44
- if (hasKey) {
45
- this.countDefined -= 1;
46
- this.updateItem(key, undefined);
47
- this.emitter.emit("localItemRemoved", { key });
48
- }
49
- return hasKey;
50
- }
51
- forEach(callbackfn, thisArg) {
52
- for (const [key, item] of objectEntries(this.value.items)) {
53
- if (item.value !== undefined) {
54
- // TODO: AB#55932: try fixing typing of objectEntries to avoid this cast
55
- callbackfn(asDeeplyReadonlyDeserializedJson(item.value), key, this);
56
- }
57
- }
58
- }
59
- get(key) {
60
- return asDeeplyReadonlyDeserializedJson(this.value.items[key]?.value);
61
- }
62
- has(key) {
63
- return this.value.items[key]?.value !== undefined;
64
- }
65
- set(key, inValue) {
66
- const value = toOpaqueJson(inValue);
67
- if (!(key in this.value.items)) {
68
- this.countDefined += 1;
69
- this.value.items[key] = { rev: 0, timestamp: 0, value };
70
- }
71
- this.updateItem(key, value);
72
- this.emitter.emit("localItemUpdated", { key, value: asDeeplyReadonly(inValue) });
73
- return this;
74
- }
75
- get size() {
76
- return this.countDefined;
77
- }
78
- keys() {
79
- const keys = [];
80
- for (const [key, item] of objectEntries(this.value.items)) {
81
- if (item.value !== undefined) {
82
- // TODO: AB#55932: try fixing typing of objectEntries to avoid this cast
83
- keys.push(key);
84
- }
85
- }
86
- return keys[Symbol.iterator]();
87
- }
88
- }
89
- /**
90
- * Simply returns true for all given string keys.
91
- */
92
- function anyKeyIsValid(unvalidatedKey) {
93
- return true;
94
- }
95
- class LatestMapValueManagerImpl {
96
- constructor(key, datastore, value, controlSettings, validator, isValidKey) {
97
- this.key = key;
98
- this.datastore = datastore;
99
- this.value = value;
100
- this.validator = validator;
101
- this.isValidKey = isValidKey;
102
- this.events = createEmitter();
103
- this.controls = new OptionalBroadcastControl(controlSettings);
104
- this.local = new ValueMapImpl(value, this.events, (updates) => {
105
- datastore.localUpdate(key, updates, {
106
- allowableUpdateLatencyMs: this.controls.allowableUpdateLatencyMs,
107
- });
108
- });
109
- }
110
- get presence() {
111
- return this.datastore.presence;
112
- }
113
- *getRemotes() {
114
- const allKnownStates = this.datastore.knownValues(this.key);
115
- for (const attendeeId of objectKeys(allKnownStates.states)) {
116
- if (attendeeId !== allKnownStates.self) {
117
- const attendee = this.datastore.presence.attendees.getAttendee(attendeeId);
118
- const items = this.getRemote(attendee);
119
- yield { attendee, items };
120
- }
121
- }
122
- }
123
- getStateAttendees() {
124
- const allKnownStates = this.datastore.knownValues(this.key);
125
- return objectKeys(allKnownStates.states)
126
- .filter((attendeeId) => attendeeId !== allKnownStates.self)
127
- .map((attendeeId) => this.datastore.presence.attendees.getAttendee(attendeeId));
128
- }
129
- getRemote(attendee) {
130
- const validator = this.validator;
131
- const allKnownStates = this.datastore.knownValues(this.key);
132
- const attendeeId = attendee.attendeeId;
133
- const clientStateMap = allKnownStates.states[attendeeId];
134
- if (clientStateMap === undefined) {
135
- throw new Error("No entry for attendee");
136
- }
137
- const items = new Map();
138
- for (const [key, item] of objectEntries(clientStateMap.items)) {
139
- if (this.isValidKey(key) && isValueRequiredState(item)) {
140
- items.set(key, {
141
- value: createValidatedGetter(item, validator),
142
- metadata: { revision: item.rev, timestamp: item.timestamp },
143
- });
144
- }
145
- }
146
- return items;
147
- }
148
- update(attendee, _received, value) {
149
- const allKnownStates = this.datastore.knownValues(this.key);
150
- const attendeeId = attendee.attendeeId;
151
- const currentState = (allKnownStates.states[attendeeId] ??=
152
- // New attendee - prepare new attendee state directory
153
- {
154
- rev: value.rev,
155
- items: {},
156
- });
157
- // Accumulate individual update keys
158
- const updatedKeyItemPairs = [];
159
- for (const [key, item] of objectEntries(value.items)) {
160
- const currentItem = currentState.items[key];
161
- if (currentItem === undefined || currentItem.rev < item.rev) {
162
- updatedKeyItemPairs.push([key, item]);
163
- }
164
- }
165
- if (updatedKeyItemPairs.length === 0) {
166
- return [];
167
- }
168
- // Store updates
169
- if (value.rev > currentState.rev) {
170
- currentState.rev = value.rev;
171
- }
172
- const allUpdates = {
173
- attendee,
174
- items: new Map(),
175
- };
176
- const postUpdateActions = [];
177
- for (const [key, item] of updatedKeyItemPairs) {
178
- const hadPriorValue = currentState.items[key]?.value;
179
- currentState.items[key] = item;
180
- // Prepare update events, but only for valid keys.
181
- if (!this.isValidKey(key)) {
182
- continue;
183
- }
184
- const metadata = {
185
- revision: item.rev,
186
- timestamp: item.timestamp,
187
- };
188
- if (isValueRequiredState(item)) {
189
- const updatedItem = {
190
- attendee,
191
- key,
192
- value: createValidatedGetter(item, this.validator),
193
- metadata,
194
- };
195
- postUpdateActions.push(() => this.events.emit("remoteItemUpdated", updatedItem));
196
- allUpdates.items.set(key, {
197
- value: updatedItem.value,
198
- metadata,
199
- });
200
- }
201
- else if (hadPriorValue !== undefined) {
202
- postUpdateActions.push(() => this.events.emit("remoteItemRemoved", {
203
- attendee,
204
- key,
205
- metadata,
206
- }));
207
- }
208
- }
209
- this.datastore.update(this.key, attendeeId, currentState);
210
- // Only emit remoteUpdated if there are any individual updates, which
211
- // accounts for the case where all updates were for invalid keys.
212
- if (postUpdateActions.length > 0) {
213
- postUpdateActions.push(() => this.events.emit("remoteUpdated", allUpdates));
214
- }
215
- return postUpdateActions;
216
- }
217
- }
218
- /**
219
- * Factory for creating a {@link LatestMap} or {@link LatestMapRaw} State object.
220
- */
221
- export const latestMap = (args) => {
222
- const settings = args?.settings;
223
- const initialValues = args?.local;
224
- const validator = args?.validator;
225
- const isKeyValid = args?.keyValidator ?? anyKeyIsValid;
226
- const timestamp = Date.now();
227
- const value = { rev: 0, items: {} };
228
- // LatestMapRaw takes ownership of values within initialValues.
229
- if (initialValues !== undefined) {
230
- for (const [key, item] of objectEntries(initialValues)) {
231
- // TODO: AB#55932: try fixing typing of objectEntries to avoid this cast
232
- const assumedValidKey = key;
233
- value.items[assumedValidKey] = {
234
- rev: 0,
235
- timestamp,
236
- value: toOpaqueJson(item),
237
- };
238
- }
239
- }
240
- const factory = (key, datastoreHandle) => ({
241
- initialData: { value, allowableUpdateLatencyMs: settings?.allowableUpdateLatencyMs },
242
- manager: brandIVM(new LatestMapValueManagerImpl(key, datastoreFromHandle(datastoreHandle), value, settings, validator, isKeyValid)),
243
- });
244
- return Object.assign(factory, { instanceBase: LatestMapValueManagerImpl });
245
- };
246
- //# sourceMappingURL=latestMapValueManager.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"latestMapValueManager.js","sourceRoot":"","sources":["../src/latestMapValueManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAQ7D,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAGlE,OAAO,EACN,gBAAgB,EAChB,gCAAgC,EAChC,oBAAoB,EACpB,aAAa,EACb,UAAU,EACV,YAAY,GACZ,MAAM,oBAAoB,CAAC;AAa5B,OAAO,EAAE,mBAAmB,EAAuB,MAAM,qBAAqB,CAAC;AAG/E,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAkB7C,MAAM,YAAY;IAEjB,YACkB,KAAwC,EACxC,OAEhB,EACgB,WAMR;QAVQ,UAAK,GAAL,KAAK,CAAmC;QACxC,YAAO,GAAP,OAAO,CAEvB;QACgB,gBAAW,GAAX,WAAW,CAMnB;QAET,gDAAgD;QAChD,8CAA8C;QAC9C,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC;IACrD,CAAC;IAED;;OAEG;IACK,UAAU,CAAC,GAAM,EAAE,KAAmD;QAC7E,IAAI,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;QACpB,2CAA2C;QAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACnC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;QACd,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC5B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACzB,OAAO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AO,EAAE,QAAQ,CAKhB,IAAI,yBAAyB,CAC5B,GAAG,EACH,mBAAmB,CAAC,eAAe,CAAC,EACpC,KAAK,EACL,QAAQ,EACR,SAAS,EACT,UAAU,CACV,CACD;KACD,CAAC,CAAC;IACH,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,YAAY,EAAE,yBAAyB,EAAE,CAAC,CAAC;AAC5E,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { createEmitter } from \"@fluid-internal/client-utils\";\nimport type { IEmitter } from \"@fluidframework/core-interfaces/internal\";\nimport type {\n\tDeepReadonly,\n\tJsonDeserialized,\n\tJsonSerializable,\n} from \"@fluidframework/core-interfaces/internal/exposedUtilityTypes\";\n\nimport { OptionalBroadcastControl } from \"./broadcastControls.js\";\nimport type { BroadcastControlSettings } from \"./broadcastControlsTypes.js\";\nimport type { InternalTypes } from \"./exposedInternalTypes.js\";\nimport {\n\tasDeeplyReadonly,\n\tasDeeplyReadonlyDeserializedJson,\n\tisValueRequiredState,\n\tobjectEntries,\n\tobjectKeys,\n\ttoOpaqueJson,\n} from \"./internalUtils.js\";\nimport type {\n\tKeySchemaValidator,\n\tLatestMap,\n\tLatestMapClientData,\n\tLatestMapEvents,\n\tLatestMapFactory,\n\tLatestMapItemUpdatedClientData,\n\tLatestMapRaw,\n\tStateMap,\n} from \"./latestMapTypes.js\";\nimport type { LatestData, StateSchemaValidator, ValueAccessor } from \"./latestValueTypes.js\";\nimport type { AttendeeId, Attendee, Presence, SpecificAttendee } from \"./presence.js\";\nimport { datastoreFromHandle, type StateDatastore } from \"./stateDatastore.js\";\nimport type { PostUpdateAction, ValueManager } from \"./statesManagerTypes.js\";\nimport type { ValidatableOptionalState } from \"./validatableTypes.js\";\nimport { createValidatedGetter } from \"./validatedGetter.js\";\nimport { brandIVM } from \"./valueManager.js\";\n\n/**\n * Collection of validatable optional values in a \"map\" structure.\n *\n * @remarks\n * Validatable equivalent of {@link InternalTypes.MapValueState}.\n */\ninterface ValidatableMapValueState<T> {\n\trev: number;\n\titems: {\n\t\t// Caution: any particular item may or may not exist\n\t\t// Typescript does not support absent keys without forcing type to also be undefined.\n\t\t// See https://github.com/microsoft/TypeScript/issues/42810.\n\t\t[name in string]: ValidatableOptionalState<T>;\n\t};\n}\n\nclass ValueMapImpl<T, K extends string> implements StateMap<K, T> {\n\tprivate countDefined: number;\n\tpublic constructor(\n\t\tprivate readonly value: InternalTypes.MapValueState<T, K>,\n\t\tprivate readonly emitter: IEmitter<\n\t\t\tPick<LatestMapEvents<T, K, ValueAccessor<T>>, \"localItemUpdated\" | \"localItemRemoved\">\n\t\t>,\n\t\tprivate readonly localUpdate: (\n\t\t\tupdates: InternalTypes.MapValueState<\n\t\t\t\tT,\n\t\t\t\t// This should be `K`, but will only work if properties are optional.\n\t\t\t\tstring\n\t\t\t>,\n\t\t) => void,\n\t) {\n\t\t// All initial items are expected to be defined.\n\t\t// TODO assert all defined and/or update type.\n\t\tthis.countDefined = Object.keys(value.items).length;\n\t}\n\n\t/**\n\t * Note: caller must ensure key exists in this.value.items.\n\t */\n\tprivate updateItem(key: K, value: InternalTypes.ValueOptionalState<T>[\"value\"]): void {\n\t\tthis.value.rev += 1;\n\t\t// Caller is required to ensure key exists.\n\t\tconst item = this.value.items[key];\n\t\titem.rev += 1;\n\t\titem.timestamp = Date.now();\n\t\tif (value === undefined) {\n\t\t\tdelete item.value;\n\t\t} else {\n\t\t\titem.value = value;\n\t\t}\n\t\tconst update = { rev: this.value.rev, items: { [key]: item } };\n\t\tthis.localUpdate(update);\n\t}\n\n\tpublic clear(): void {\n\t\tthrow new Error(\"Method not implemented.\");\n\t}\n\tpublic delete(key: K): boolean {\n\t\tconst { items } = this.value;\n\t\tconst hasKey = items[key]?.value !== undefined;\n\t\tif (hasKey) {\n\t\t\tthis.countDefined -= 1;\n\t\t\tthis.updateItem(key, undefined);\n\t\t\tthis.emitter.emit(\"localItemRemoved\", { key });\n\t\t}\n\t\treturn hasKey;\n\t}\n\tpublic forEach(\n\t\tcallbackfn: (\n\t\t\tvalue: DeepReadonly<JsonDeserialized<T>>,\n\t\t\tkey: K,\n\t\t\tmap: StateMap<K, T>,\n\t\t) => void,\n\t\tthisArg?: unknown,\n\t): void {\n\t\tfor (const [key, item] of objectEntries(this.value.items)) {\n\t\t\tif (item.value !== undefined) {\n\t\t\t\t// TODO: AB#55932: try fixing typing of objectEntries to avoid this cast\n\t\t\t\tcallbackfn(asDeeplyReadonlyDeserializedJson(item.value), key as unknown as K, this);\n\t\t\t}\n\t\t}\n\t}\n\tpublic get(key: K): DeepReadonly<JsonDeserialized<T>> | undefined {\n\t\treturn asDeeplyReadonlyDeserializedJson(this.value.items[key]?.value);\n\t}\n\tpublic has(key: K): boolean {\n\t\treturn this.value.items[key]?.value !== undefined;\n\t}\n\tpublic set(key: K, inValue: JsonSerializable<T>): this {\n\t\tconst value = toOpaqueJson<T>(inValue);\n\t\tif (!(key in this.value.items)) {\n\t\t\tthis.countDefined += 1;\n\t\t\tthis.value.items[key] = { rev: 0, timestamp: 0, value };\n\t\t}\n\t\tthis.updateItem(key, value);\n\t\tthis.emitter.emit(\"localItemUpdated\", { key, value: asDeeplyReadonly(inValue) });\n\t\treturn this;\n\t}\n\tpublic get size(): number {\n\t\treturn this.countDefined;\n\t}\n\tpublic keys(): IterableIterator<K> {\n\t\tconst keys: K[] = [];\n\t\tfor (const [key, item] of objectEntries(this.value.items)) {\n\t\t\tif (item.value !== undefined) {\n\t\t\t\t// TODO: AB#55932: try fixing typing of objectEntries to avoid this cast\n\t\t\t\tkeys.push(key as unknown as K);\n\t\t\t}\n\t\t}\n\t\treturn keys[Symbol.iterator]();\n\t}\n}\n\n/**\n * Simply returns true for all given string keys.\n */\nfunction anyKeyIsValid<Keys extends string>(unvalidatedKey: string): unvalidatedKey is Keys {\n\treturn true;\n}\n\nclass LatestMapValueManagerImpl<\n\tT,\n\tRegistrationKey extends string,\n\tKeys extends string = string,\n> implements\n\t\tLatestMapRaw<T, Keys>,\n\t\tLatestMap<T, Keys>,\n\t\tRequired<ValueManager<T, InternalTypes.MapValueState<T, Keys>>>\n{\n\tpublic readonly events = createEmitter<LatestMapEvents<T, Keys, ValueAccessor<T>>>();\n\tpublic readonly controls: OptionalBroadcastControl;\n\n\tpublic constructor(\n\t\tprivate readonly key: RegistrationKey,\n\t\tprivate readonly datastore: StateDatastore<\n\t\t\tRegistrationKey,\n\t\t\tInternalTypes.MapValueState<T, Keys>,\n\t\t\tValidatableMapValueState<T>\n\t\t>,\n\t\tpublic readonly value: InternalTypes.MapValueState<T, Keys>,\n\t\tcontrolSettings: BroadcastControlSettings | undefined,\n\t\tprivate readonly validator: StateSchemaValidator<T> | undefined,\n\t\tprivate readonly isValidKey: KeySchemaValidator<Keys>,\n\t) {\n\t\tthis.controls = new OptionalBroadcastControl(controlSettings);\n\n\t\tthis.local = new ValueMapImpl<T, Keys>(\n\t\t\tvalue,\n\t\t\tthis.events,\n\t\t\t(updates: InternalTypes.MapValueState<T, Keys>) => {\n\t\t\t\tdatastore.localUpdate(key, updates, {\n\t\t\t\t\tallowableUpdateLatencyMs: this.controls.allowableUpdateLatencyMs,\n\t\t\t\t});\n\t\t\t},\n\t\t);\n\t}\n\n\tpublic get presence(): Presence {\n\t\treturn this.datastore.presence;\n\t}\n\n\tpublic readonly local: StateMap<Keys, T>;\n\n\tpublic *getRemotes(): IterableIterator<LatestMapClientData<T, Keys, ValueAccessor<T>>> {\n\t\tconst allKnownStates = this.datastore.knownValues(this.key);\n\t\tfor (const attendeeId of objectKeys(allKnownStates.states)) {\n\t\t\tif (attendeeId !== allKnownStates.self) {\n\t\t\t\tconst attendee = this.datastore.presence.attendees.getAttendee(attendeeId);\n\t\t\t\tconst items = this.getRemote(attendee);\n\t\t\t\tyield { attendee, items };\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic getStateAttendees(): Attendee[] {\n\t\tconst allKnownStates = this.datastore.knownValues(this.key);\n\t\treturn objectKeys(allKnownStates.states)\n\t\t\t.filter((attendeeId) => attendeeId !== allKnownStates.self)\n\t\t\t.map((attendeeId) => this.datastore.presence.attendees.getAttendee(attendeeId));\n\t}\n\n\tpublic getRemote(attendee: Attendee): ReadonlyMap<Keys, LatestData<T, ValueAccessor<T>>> {\n\t\tconst validator = this.validator;\n\t\tconst allKnownStates = this.datastore.knownValues(this.key);\n\t\tconst attendeeId = attendee.attendeeId;\n\t\tconst clientStateMap = allKnownStates.states[attendeeId];\n\t\tif (clientStateMap === undefined) {\n\t\t\tthrow new Error(\"No entry for attendee\");\n\t\t}\n\t\tconst items = new Map<Keys, LatestData<T, ValueAccessor<T>>>();\n\t\tfor (const [key, item] of objectEntries(clientStateMap.items)) {\n\t\t\tif (this.isValidKey(key) && isValueRequiredState(item)) {\n\t\t\t\titems.set(key, {\n\t\t\t\t\tvalue: createValidatedGetter(item, validator),\n\t\t\t\t\tmetadata: { revision: item.rev, timestamp: item.timestamp },\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\treturn items;\n\t}\n\n\tpublic update<SpecificAttendeeId extends AttendeeId>(\n\t\tattendee: SpecificAttendee<SpecificAttendeeId>,\n\t\t_received: number,\n\t\tvalue: InternalTypes.MapValueState<T, string>,\n\t): PostUpdateAction[] {\n\t\tconst allKnownStates = this.datastore.knownValues(this.key);\n\t\tconst attendeeId: SpecificAttendeeId = attendee.attendeeId;\n\t\tconst currentState = (allKnownStates.states[attendeeId] ??=\n\t\t\t// New attendee - prepare new attendee state directory\n\t\t\t{\n\t\t\t\trev: value.rev,\n\t\t\t\titems: {},\n\t\t\t});\n\t\t// Accumulate individual update keys\n\t\tconst updatedKeyItemPairs: [string, InternalTypes.ValueOptionalState<T>][] = [];\n\t\tfor (const [key, item] of objectEntries(value.items)) {\n\t\t\tconst currentItem = currentState.items[key];\n\t\t\tif (currentItem === undefined || currentItem.rev < item.rev) {\n\t\t\t\tupdatedKeyItemPairs.push([key, item]);\n\t\t\t}\n\t\t}\n\n\t\tif (updatedKeyItemPairs.length === 0) {\n\t\t\treturn [];\n\t\t}\n\n\t\t// Store updates\n\t\tif (value.rev > currentState.rev) {\n\t\t\tcurrentState.rev = value.rev;\n\t\t}\n\t\tconst allUpdates = {\n\t\t\tattendee,\n\t\t\titems: new Map<Keys, LatestData<T, ValueAccessor<T>>>(),\n\t\t};\n\t\tconst postUpdateActions: PostUpdateAction[] = [];\n\t\tfor (const [key, item] of updatedKeyItemPairs) {\n\t\t\tconst hadPriorValue = currentState.items[key]?.value;\n\t\t\tcurrentState.items[key] = item;\n\n\t\t\t// Prepare update events, but only for valid keys.\n\t\t\tif (!this.isValidKey(key)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst metadata = {\n\t\t\t\trevision: item.rev,\n\t\t\t\ttimestamp: item.timestamp,\n\t\t\t};\n\t\t\tif (isValueRequiredState(item)) {\n\t\t\t\tconst updatedItem = {\n\t\t\t\t\tattendee,\n\t\t\t\t\tkey,\n\t\t\t\t\tvalue: createValidatedGetter(item, this.validator),\n\t\t\t\t\tmetadata,\n\t\t\t\t} satisfies LatestMapItemUpdatedClientData<T, Keys, ValueAccessor<T>>;\n\t\t\t\tpostUpdateActions.push(() => this.events.emit(\"remoteItemUpdated\", updatedItem));\n\t\t\t\tallUpdates.items.set(key, {\n\t\t\t\t\tvalue: updatedItem.value,\n\t\t\t\t\tmetadata,\n\t\t\t\t});\n\t\t\t} else if (hadPriorValue !== undefined) {\n\t\t\t\tpostUpdateActions.push(() =>\n\t\t\t\t\tthis.events.emit(\"remoteItemRemoved\", {\n\t\t\t\t\t\tattendee,\n\t\t\t\t\t\tkey,\n\t\t\t\t\t\tmetadata,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tthis.datastore.update(this.key, attendeeId, currentState);\n\t\t// Only emit remoteUpdated if there are any individual updates, which\n\t\t// accounts for the case where all updates were for invalid keys.\n\t\tif (postUpdateActions.length > 0) {\n\t\t\tpostUpdateActions.push(() => this.events.emit(\"remoteUpdated\", allUpdates));\n\t\t}\n\t\treturn postUpdateActions;\n\t}\n}\n\n/**\n * Arguments that are passed to the {@link StateFactory.latestMap} function.\n *\n * @input\n * @beta\n */\nexport interface LatestMapArgumentsRaw<T, Keys extends string = string> {\n\t/**\n\t * The initial value of the local state.\n\t */\n\tlocal?: {\n\t\t[K in Keys]: JsonSerializable<T>;\n\t};\n\n\t/**\n\t * See {@link BroadcastControlSettings}.\n\t */\n\tsettings?: BroadcastControlSettings | undefined;\n}\n\n/**\n * Arguments that are passed to the {@link StateFactory.latestMap} function.\n *\n * @input\n * @beta\n */\nexport interface LatestMapArguments<T, Keys extends string = string>\n\textends LatestMapArgumentsRaw<T, Keys> {\n\t/**\n\t * An optional function that will be called at runtime to validate data value\n\t * under a key. A runtime validator is strongly recommended.\n\t * @see {@link StateSchemaValidator}.\n\t */\n\tvalidator: StateSchemaValidator<T>;\n\t/**\n\t * An optional function that will be called at runtime to validate the presence\n\t * data key. A runtime validator is strongly recommended when key type is not\n\t * simply `string`.\n\t * @see {@link KeySchemaValidator}.\n\t */\n\tkeyValidator?: KeySchemaValidator<Keys>;\n}\n\n/**\n * Factory for creating a {@link LatestMap} or {@link LatestMapRaw} State object.\n */\nexport const latestMap: LatestMapFactory = <\n\tT,\n\tKeys extends string = string,\n\tRegistrationKey extends string = string,\n>(\n\targs?: Partial<LatestMapArguments<T, Keys>>,\n): InternalTypes.ManagerFactory<\n\tRegistrationKey,\n\tInternalTypes.MapValueState<T, Keys>,\n\tLatestMapRaw<T, Keys> & LatestMap<T, Keys>\n> => {\n\tconst settings = args?.settings;\n\tconst initialValues = args?.local;\n\tconst validator = args?.validator;\n\tconst isKeyValid = args?.keyValidator ?? anyKeyIsValid;\n\n\tconst timestamp = Date.now();\n\tconst value: InternalTypes.MapValueState<\n\t\tT,\n\t\t// This should be `Keys`, but will only work if properties are optional.\n\t\tstring\n\t> = { rev: 0, items: {} };\n\t// LatestMapRaw takes ownership of values within initialValues.\n\tif (initialValues !== undefined) {\n\t\tfor (const [key, item] of objectEntries(initialValues)) {\n\t\t\t// TODO: AB#55932: try fixing typing of objectEntries to avoid this cast\n\t\t\tconst assumedValidKey = key as unknown as Keys;\n\t\t\tvalue.items[assumedValidKey] = {\n\t\t\t\trev: 0,\n\t\t\t\ttimestamp,\n\t\t\t\tvalue: toOpaqueJson(item),\n\t\t\t};\n\t\t}\n\t}\n\tconst factory = (\n\t\tkey: RegistrationKey,\n\t\tdatastoreHandle: InternalTypes.StateDatastoreHandle<\n\t\t\tRegistrationKey,\n\t\t\tInternalTypes.MapValueState<T, Keys>\n\t\t>,\n\t): {\n\t\tinitialData: { value: typeof value; allowableUpdateLatencyMs: number | undefined };\n\t\tmanager: InternalTypes.StateValue<LatestMapRaw<T, Keys> & LatestMap<T, Keys>>;\n\t} => ({\n\t\tinitialData: { value, allowableUpdateLatencyMs: settings?.allowableUpdateLatencyMs },\n\t\tmanager: brandIVM<\n\t\t\tLatestMapValueManagerImpl<T, RegistrationKey, Keys>,\n\t\t\tT,\n\t\t\tInternalTypes.MapValueState<T, Keys>\n\t\t>(\n\t\t\tnew LatestMapValueManagerImpl(\n\t\t\t\tkey,\n\t\t\t\tdatastoreFromHandle(datastoreHandle),\n\t\t\t\tvalue,\n\t\t\t\tsettings,\n\t\t\t\tvalidator,\n\t\t\t\tisKeyValid,\n\t\t\t),\n\t\t),\n\t});\n\treturn Object.assign(factory, { instanceBase: LatestMapValueManagerImpl });\n};\n"]}
@@ -1,183 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- import type { Listenable } from "@fluidframework/core-interfaces";
6
- import type { DeepReadonly, JsonDeserialized, JsonSerializable } from "@fluidframework/core-interfaces/internal/exposedUtilityTypes";
7
- import type { BroadcastControls, BroadcastControlSettings } from "./broadcastControlsTypes.js";
8
- import type { InternalTypes } from "./exposedInternalTypes.js";
9
- import type { LatestClientData, LatestData, ProxiedValueAccessor, RawValueAccessor, StateSchemaValidator, ValueAccessor } from "./latestValueTypes.js";
10
- import type { Attendee, Presence } from "./presence.js";
11
- /**
12
- * Events from {@link LatestRaw}.
13
- *
14
- * @sealed
15
- * @beta
16
- */
17
- export interface LatestEvents<T, TRemoteValueAccessor extends ValueAccessor<T> = ProxiedValueAccessor<T>> {
18
- /**
19
- * Raised when remote client's value is updated, which may be the same value.
20
- *
21
- * @eventProperty
22
- */
23
- remoteUpdated: (update: LatestClientData<T, TRemoteValueAccessor>) => void;
24
- /**
25
- * Raised when local client's value is updated, which may be the same value.
26
- *
27
- * @eventProperty
28
- */
29
- localUpdated: (update: {
30
- value: DeepReadonly<JsonSerializable<T>>;
31
- }) => void;
32
- }
33
- /**
34
- * Events from {@link LatestRaw}.
35
- *
36
- * @sealed
37
- * @beta
38
- */
39
- export type LatestRawEvents<T> = LatestEvents<T, RawValueAccessor<T>>;
40
- /**
41
- * State that provides the latest known value from this client to others and read access to their values.
42
- * All participant clients must provide a value.
43
- *
44
- * @remarks Create using {@link StateFactory}.{@link LatestFactory|latest} registered to {@link StatesWorkspace}.
45
- *
46
- * @sealed
47
- * @beta
48
- */
49
- export type LatestRaw<T> = Latest<T, RawValueAccessor<T>>;
50
- /**
51
- * State that provides the latest known value from this client to others and read access to their values.
52
- * All participant clients must provide a value.
53
- *
54
- * @remarks Create using {@link StateFactory}.{@link LatestFactory|latest} registered to {@link StatesWorkspace}.
55
- *
56
- * @sealed
57
- * @beta
58
- */
59
- export interface Latest<T, TRemoteAccessor extends ValueAccessor<T> = ProxiedValueAccessor<T>> {
60
- /**
61
- * Containing {@link Presence}
62
- */
63
- readonly presence: Presence;
64
- /**
65
- * Events for LatestRaw.
66
- */
67
- readonly events: Listenable<LatestEvents<T, TRemoteAccessor>>;
68
- /**
69
- * Controls for management of sending updates.
70
- */
71
- readonly controls: BroadcastControls;
72
- /**
73
- * Current state for this client.
74
- * State for this client that will be transmitted to all other connected clients.
75
- * @remarks Manager assumes ownership of the value and its references. Make a deep clone before
76
- * setting, if needed. No comparison is done to detect changes; all sets are transmitted.
77
- */
78
- get local(): DeepReadonly<JsonDeserialized<T>>;
79
- set local(value: JsonSerializable<T>);
80
- /**
81
- * Array of {@link Attendee}s that have provided states.
82
- */
83
- getStateAttendees(): Attendee[];
84
- /**
85
- * Iterable access to remote clients' values.
86
- */
87
- getRemotes(): IterableIterator<LatestClientData<T, TRemoteAccessor>>;
88
- /**
89
- * Access to a specific attendee's value.
90
- */
91
- getRemote(attendee: Attendee): LatestData<T, TRemoteAccessor>;
92
- }
93
- /**
94
- * Arguments that are passed to the {@link StateFactory}.{@link LatestFactory|latest} function to create a {@link LatestRaw} State object.
95
- *
96
- * @input
97
- * @beta
98
- */
99
- export interface LatestArgumentsRaw<T extends object | null> {
100
- /**
101
- * The initial value of the local state.
102
- *
103
- * @remarks
104
- * `latest` assumes ownership of the value and its references.
105
- * Make a deep clone before passing, if needed.
106
- */
107
- local: JsonSerializable<T>;
108
- /**
109
- * See {@link BroadcastControlSettings}.
110
- */
111
- settings?: BroadcastControlSettings | undefined;
112
- }
113
- /**
114
- * Arguments that are passed to the {@link StateFactory}.{@link LatestFactory|latest} function to create a {@link Latest} State object.
115
- *
116
- * @input
117
- * @beta
118
- */
119
- export interface LatestArguments<T extends object | null> extends LatestArgumentsRaw<T> {
120
- /**
121
- * See {@link StateSchemaValidator}.
122
- */
123
- validator: StateSchemaValidator<T>;
124
- }
125
- /**
126
- * Type alias for the return type of {@link LatestFactory} when called with
127
- * {@link LatestArguments}.
128
- *
129
- * @remarks
130
- * Use this type instead of any InternalPresenceTypes that may be revealed from
131
- * examining factory return type.
132
- *
133
- * @typeparam RegistrationKeyRestrictions - Optional type parameter to constrain
134
- * allowed registration keys for this State object within a workspace.
135
- * Specification is recommended to highlight connection between schema and
136
- * factory when spread across modules.
137
- *
138
- * @beta
139
- * @sealed
140
- */
141
- export type LatestConfiguration<T extends object | null, RegistrationKeyRestrictions extends string = string> = InternalTypes.ManagerFactory<RegistrationKeyRestrictions, InternalTypes.ValueRequiredState<T>, Latest<T>>;
142
- /**
143
- * Type alias for the return type of {@link LatestFactory} when called with
144
- * {@link LatestArgumentsRaw}.
145
- *
146
- * @remarks
147
- * Use this type instead of any InternalPresenceTypes that may be revealed from
148
- * examining factory return type.
149
- *
150
- * @typeparam RegistrationKeyRestrictions - Optional type parameter to constrain
151
- * allowed registration keys for this State object within a workspace.
152
- * Specification is recommended to highlight connection between schema and
153
- * factory when spread across modules.
154
- *
155
- * @beta
156
- * @sealed
157
- */
158
- export type LatestRawConfiguration<T extends object | null, RegistrationKeyRestrictions extends string = string> = InternalTypes.ManagerFactory<RegistrationKeyRestrictions, InternalTypes.ValueRequiredState<T>, LatestRaw<T>>;
159
- /**
160
- * Factory for creating a {@link Latest} or {@link LatestRaw} State object.
161
- *
162
- * @beta
163
- * @sealed
164
- */
165
- export interface LatestFactory {
166
- /**
167
- * Factory for creating a {@link Latest} State object.
168
- *
169
- * @remarks
170
- * This overload is used when called with {@link LatestArguments}.
171
- * That is, if a validator function is provided.
172
- */
173
- <T extends object | null, RegistrationKeyRestrictions extends string = string>(args: LatestArguments<T>): LatestConfiguration<T, RegistrationKeyRestrictions>;
174
- /**
175
- * Factory for creating a {@link LatestRaw} State object.
176
- *
177
- * @remarks
178
- * This overload is used when called with {@link LatestArgumentsRaw}.
179
- * That is, if a validator function is _not_ provided.
180
- */
181
- <T extends object | null, RegistrationKeyRestrictions extends string = string>(args: LatestArgumentsRaw<T>): LatestRawConfiguration<T, RegistrationKeyRestrictions>;
182
- }
183
- //# sourceMappingURL=latestTypes.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"latestTypes.d.ts","sourceRoot":"","sources":["../src/latestTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,KAAK,EACX,YAAY,EACZ,gBAAgB,EAChB,gBAAg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B,CAEjC,CAAC,SAAS,MAAM,GAAG,IAAI,EACvB,2BAA2B,SAAS,MAAM,GAAG,MAAM,IAChD,aAAa,CAAC,cAAc,CAC/B,2BAA2B,EAC3B,aAAa,CAAC,kBAAkB,CAAC,CAAC,CAAC,EACnC,SAAS,CAAC,CAAC,CAAC,CACZ,CAAC;AAEF;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC7B;;;;;;OAMG;IACH,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI,EAAE,2BAA2B,SAAS,MAAM,GAAG,MAAM,EAC5E,IAAI,EAAE,eAAe,CAAC,CAAC,CAAC,GACtB,mBAAmB,CAAC,CAAC,EAAE,2BAA2B,CAAC,CAAC;IAEvD;;;;;;OAMG;IACH,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI,EAAE,2BAA2B,SAAS,MAAM,GAAG,MAAM,EAC5E,IAAI,EAAE,kBAAkB,CAAC,CAAC,CAAC,GACzB,sBAAsB,CAAC,CAAC,EAAE,2BAA2B,CAAC,CAAC;CAC1D"}
@@ -1,6 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- export {};
6
- //# sourceMappingURL=latestTypes.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"latestTypes.js","sourceRoot":"","sources":["../src/latestTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { Listenable } from \"@fluidframework/core-interfaces\";\nimport type {\n\tDeepReadonly,\n\tJsonDeserialized,\n\tJsonSerializable,\n} from \"@fluidframework/core-interfaces/internal/exposedUtilityTypes\";\n\nimport type { BroadcastControls, BroadcastControlSettings } from \"./broadcastControlsTypes.js\";\nimport type { InternalTypes } from \"./exposedInternalTypes.js\";\nimport type {\n\tLatestClientData,\n\tLatestData,\n\tProxiedValueAccessor,\n\tRawValueAccessor,\n\tStateSchemaValidator,\n\tValueAccessor,\n} from \"./latestValueTypes.js\";\nimport type { Attendee, Presence } from \"./presence.js\";\n\n/**\n * Events from {@link LatestRaw}.\n *\n * @sealed\n * @beta\n */\nexport interface LatestEvents<\n\tT,\n\tTRemoteValueAccessor extends ValueAccessor<T> = ProxiedValueAccessor<T>,\n> {\n\t/**\n\t * Raised when remote client's value is updated, which may be the same value.\n\t *\n\t * @eventProperty\n\t */\n\tremoteUpdated: (update: LatestClientData<T, TRemoteValueAccessor>) => void;\n\n\t/**\n\t * Raised when local client's value is updated, which may be the same value.\n\t *\n\t * @eventProperty\n\t */\n\tlocalUpdated: (update: { value: DeepReadonly<JsonSerializable<T>> }) => void;\n}\n\n/**\n * Events from {@link LatestRaw}.\n *\n * @sealed\n * @beta\n */\nexport type LatestRawEvents<T> = LatestEvents<T, RawValueAccessor<T>>;\n\n/**\n * State that provides the latest known value from this client to others and read access to their values.\n * All participant clients must provide a value.\n *\n * @remarks Create using {@link StateFactory}.{@link LatestFactory|latest} registered to {@link StatesWorkspace}.\n *\n * @sealed\n * @beta\n */\nexport type LatestRaw<T> = Latest<T, RawValueAccessor<T>>;\n\n/**\n * State that provides the latest known value from this client to others and read access to their values.\n * All participant clients must provide a value.\n *\n * @remarks Create using {@link StateFactory}.{@link LatestFactory|latest} registered to {@link StatesWorkspace}.\n *\n * @sealed\n * @beta\n */\nexport interface Latest<\n\tT,\n\tTRemoteAccessor extends ValueAccessor<T> = ProxiedValueAccessor<T>,\n> {\n\t/**\n\t * Containing {@link Presence}\n\t */\n\treadonly presence: Presence;\n\n\t/**\n\t * Events for LatestRaw.\n\t */\n\treadonly events: Listenable<LatestEvents<T, TRemoteAccessor>>;\n\n\t/**\n\t * Controls for management of sending updates.\n\t */\n\treadonly controls: BroadcastControls;\n\n\t/**\n\t * Current state for this client.\n\t * State for this client that will be transmitted to all other connected clients.\n\t * @remarks Manager assumes ownership of the value and its references. Make a deep clone before\n\t * setting, if needed. No comparison is done to detect changes; all sets are transmitted.\n\t */\n\tget local(): DeepReadonly<JsonDeserialized<T>>;\n\tset local(value: JsonSerializable<T>);\n\n\t/**\n\t * Array of {@link Attendee}s that have provided states.\n\t */\n\tgetStateAttendees(): Attendee[];\n\n\t/**\n\t * Iterable access to remote clients' values.\n\t */\n\tgetRemotes(): IterableIterator<LatestClientData<T, TRemoteAccessor>>;\n\n\t/**\n\t * Access to a specific attendee's value.\n\t */\n\tgetRemote(attendee: Attendee): LatestData<T, TRemoteAccessor>;\n}\n\n/**\n * Arguments that are passed to the {@link StateFactory}.{@link LatestFactory|latest} function to create a {@link LatestRaw} State object.\n *\n * @input\n * @beta\n */\nexport interface LatestArgumentsRaw<T extends object | null> {\n\t/**\n\t * The initial value of the local state.\n\t *\n\t * @remarks\n\t * `latest` assumes ownership of the value and its references.\n\t * Make a deep clone before passing, if needed.\n\t */\n\tlocal: JsonSerializable<T>;\n\n\t/**\n\t * See {@link BroadcastControlSettings}.\n\t */\n\tsettings?: BroadcastControlSettings | undefined;\n}\n\n/**\n * Arguments that are passed to the {@link StateFactory}.{@link LatestFactory|latest} function to create a {@link Latest} State object.\n *\n * @input\n * @beta\n */\nexport interface LatestArguments<T extends object | null> extends LatestArgumentsRaw<T> {\n\t/**\n\t * See {@link StateSchemaValidator}.\n\t */\n\tvalidator: StateSchemaValidator<T>;\n}\n\n/**\n * Type alias for the return type of {@link LatestFactory} when called with\n * {@link LatestArguments}.\n *\n * @remarks\n * Use this type instead of any InternalPresenceTypes that may be revealed from\n * examining factory return type.\n *\n * @typeparam RegistrationKeyRestrictions - Optional type parameter to constrain\n * allowed registration keys for this State object within a workspace.\n * Specification is recommended to highlight connection between schema and\n * factory when spread across modules.\n *\n * @beta\n * @sealed\n */\nexport type LatestConfiguration<\n\t// eslint-disable-next-line @rushstack/no-new-null -- undefined is not a valid replacement for null\n\tT extends object | null,\n\tRegistrationKeyRestrictions extends string = string,\n> = InternalTypes.ManagerFactory<\n\tRegistrationKeyRestrictions,\n\tInternalTypes.ValueRequiredState<T>,\n\tLatest<T>\n>;\n\n/**\n * Type alias for the return type of {@link LatestFactory} when called with\n * {@link LatestArgumentsRaw}.\n *\n * @remarks\n * Use this type instead of any InternalPresenceTypes that may be revealed from\n * examining factory return type.\n *\n * @typeparam RegistrationKeyRestrictions - Optional type parameter to constrain\n * allowed registration keys for this State object within a workspace.\n * Specification is recommended to highlight connection between schema and\n * factory when spread across modules.\n *\n * @beta\n * @sealed\n */\nexport type LatestRawConfiguration<\n\t// eslint-disable-next-line @rushstack/no-new-null -- undefined is not a valid replacement for null\n\tT extends object | null,\n\tRegistrationKeyRestrictions extends string = string,\n> = InternalTypes.ManagerFactory<\n\tRegistrationKeyRestrictions,\n\tInternalTypes.ValueRequiredState<T>,\n\tLatestRaw<T>\n>;\n\n/**\n * Factory for creating a {@link Latest} or {@link LatestRaw} State object.\n *\n * @beta\n * @sealed\n */\nexport interface LatestFactory {\n\t/**\n\t * Factory for creating a {@link Latest} State object.\n\t *\n\t * @remarks\n\t * This overload is used when called with {@link LatestArguments}.\n\t * That is, if a validator function is provided.\n\t */\n\t<T extends object | null, RegistrationKeyRestrictions extends string = string>(\n\t\targs: LatestArguments<T>,\n\t): LatestConfiguration<T, RegistrationKeyRestrictions>;\n\n\t/**\n\t * Factory for creating a {@link LatestRaw} State object.\n\t *\n\t * @remarks\n\t * This overload is used when called with {@link LatestArgumentsRaw}.\n\t * That is, if a validator function is _not_ provided.\n\t */\n\t<T extends object | null, RegistrationKeyRestrictions extends string = string>(\n\t\targs: LatestArgumentsRaw<T>,\n\t): LatestRawConfiguration<T, RegistrationKeyRestrictions>;\n}\n"]}
@@ -1,10 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- import type { LatestFactory } from "./latestTypes.js";
6
- /**
7
- * Factory for creating a {@link Latest} or {@link LatestRaw} State object.
8
- */
9
- export declare const latest: LatestFactory;
10
- //# sourceMappingURL=latestValueManager.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"latestValueManager.d.ts","sourceRoot":"","sources":["../src/latestValueManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAoBH,OAAO,KAAK,EAKX,aAAa,EAEb,MAAM,kBAAkB,CAAC;AAuH1B;;GAEG;AACH,eAAO,MAAM,MAAM,EAAE,aAsCpB,CAAC"}
@@ -1,113 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- import { createEmitter } from "@fluid-internal/client-utils";
6
- import { shallowCloneObject } from "@fluidframework/core-utils/internal";
7
- import { OptionalBroadcastControl } from "./broadcastControls.js";
8
- import { asDeeplyReadonly, asDeeplyReadonlyDeserializedJson, objectEntries, toOpaqueJson, } from "./internalUtils.js";
9
- import { datastoreFromHandle } from "./stateDatastore.js";
10
- import { createValidatedGetter } from "./validatedGetter.js";
11
- import { brandIVM } from "./valueManager.js";
12
- class LatestValueManagerImpl {
13
- constructor(key, datastore, value, controlSettings, validator) {
14
- this.key = key;
15
- this.datastore = datastore;
16
- this.value = value;
17
- this.validator = validator;
18
- this.events = createEmitter();
19
- this.controls = new OptionalBroadcastControl(controlSettings);
20
- }
21
- get presence() {
22
- return this.datastore.presence;
23
- }
24
- get local() {
25
- return asDeeplyReadonlyDeserializedJson(this.value.value);
26
- }
27
- set local(value) {
28
- this.value.rev += 1;
29
- this.value.timestamp = Date.now();
30
- this.value.value = toOpaqueJson(value);
31
- this.datastore.localUpdate(this.key, this.value, {
32
- allowableUpdateLatencyMs: this.controls.allowableUpdateLatencyMs,
33
- });
34
- this.events.emit("localUpdated", { value: asDeeplyReadonly(value) });
35
- }
36
- *getRemotes() {
37
- const allKnownStates = this.datastore.knownValues(this.key);
38
- for (const [attendeeId, clientState] of objectEntries(allKnownStates.states)) {
39
- if (attendeeId !== allKnownStates.self) {
40
- yield {
41
- attendee: this.datastore.presence.attendees.getAttendee(attendeeId),
42
- value: createValidatedGetter(clientState, this.validator),
43
- metadata: {
44
- revision: clientState.rev,
45
- timestamp: clientState.timestamp,
46
- },
47
- };
48
- }
49
- }
50
- }
51
- getStateAttendees() {
52
- const allKnownStates = this.datastore.knownValues(this.key);
53
- return Object.keys(allKnownStates.states)
54
- .filter((attendeeId) => attendeeId !== allKnownStates.self)
55
- .map((attendeeId) => this.datastore.presence.attendees.getAttendee(attendeeId));
56
- }
57
- getRemote(attendee) {
58
- const allKnownStates = this.datastore.knownValues(this.key);
59
- const clientState = allKnownStates.states[attendee.attendeeId];
60
- if (clientState === undefined) {
61
- throw new Error("No entry for attendee");
62
- }
63
- return {
64
- value: createValidatedGetter(clientState, this.validator),
65
- metadata: { revision: clientState.rev, timestamp: Date.now() },
66
- };
67
- }
68
- update(attendee, _received, value) {
69
- const allKnownStates = this.datastore.knownValues(this.key);
70
- const attendeeId = attendee.attendeeId;
71
- const currentState = allKnownStates.states[attendeeId];
72
- if (currentState !== undefined && currentState.rev >= value.rev) {
73
- return [];
74
- }
75
- this.datastore.update(this.key, attendeeId, value);
76
- return [
77
- () => this.events.emit("remoteUpdated", {
78
- attendee,
79
- value: createValidatedGetter(value, this.validator),
80
- metadata: { revision: value.rev, timestamp: value.timestamp },
81
- }),
82
- ];
83
- }
84
- }
85
- /**
86
- * Shallow clone an object that might be null.
87
- *
88
- * @param value - The object to clone
89
- * @returns A shallow clone of the input value
90
- */
91
- function shallowCloneNullableObject(value) {
92
- return value === null ? value : shallowCloneObject(value);
93
- }
94
- /**
95
- * Factory for creating a {@link Latest} or {@link LatestRaw} State object.
96
- */
97
- export const latest = (args) => {
98
- const { local, settings, validator } = args;
99
- // Latest takes ownership of the initial local value but makes a shallow
100
- // copy for basic protection.
101
- const opaqueLocal = toOpaqueJson(local);
102
- const value = {
103
- rev: 0,
104
- timestamp: Date.now(),
105
- value: shallowCloneNullableObject(opaqueLocal),
106
- };
107
- const factory = (key, datastoreHandle) => ({
108
- initialData: { value, allowableUpdateLatencyMs: settings?.allowableUpdateLatencyMs },
109
- manager: brandIVM(new LatestValueManagerImpl(key, datastoreFromHandle(datastoreHandle), value, settings, validator)),
110
- });
111
- return Object.assign(factory, { instanceBase: LatestValueManagerImpl });
112
- };
113
- //# sourceMappingURL=latestValueManager.js.map