@fluidframework/presence 2.12.0 → 2.20.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/dist/exposedInternalTypes.d.ts +2 -2
- package/dist/exposedInternalTypes.d.ts.map +1 -1
- package/dist/exposedInternalTypes.js.map +1 -1
- package/dist/internalTypes.d.ts +0 -6
- package/dist/internalTypes.d.ts.map +1 -1
- package/dist/internalTypes.js +0 -7
- package/dist/internalTypes.js.map +1 -1
- package/dist/internalUtils.d.ts +55 -0
- package/dist/internalUtils.d.ts.map +1 -0
- package/dist/internalUtils.js +50 -0
- package/dist/internalUtils.js.map +1 -0
- package/dist/latestMapValueManager.d.ts +1 -1
- package/dist/latestMapValueManager.d.ts.map +1 -1
- package/dist/latestMapValueManager.js +27 -17
- package/dist/latestMapValueManager.js.map +1 -1
- package/dist/latestValueManager.js +12 -12
- package/dist/latestValueManager.js.map +1 -1
- package/dist/presenceDatastoreManager.d.ts.map +1 -1
- package/dist/presenceDatastoreManager.js +10 -7
- package/dist/presenceDatastoreManager.js.map +1 -1
- package/dist/presenceStates.d.ts.map +1 -1
- package/dist/presenceStates.js +38 -39
- package/dist/presenceStates.js.map +1 -1
- package/dist/systemWorkspace.d.ts.map +1 -1
- package/dist/systemWorkspace.js +60 -34
- package/dist/systemWorkspace.js.map +1 -1
- package/lib/exposedInternalTypes.d.ts +2 -2
- package/lib/exposedInternalTypes.d.ts.map +1 -1
- package/lib/exposedInternalTypes.js.map +1 -1
- package/lib/internalTypes.d.ts +0 -6
- package/lib/internalTypes.d.ts.map +1 -1
- package/lib/internalTypes.js +1 -6
- package/lib/internalTypes.js.map +1 -1
- package/lib/internalUtils.d.ts +55 -0
- package/lib/internalUtils.d.ts.map +1 -0
- package/lib/internalUtils.js +46 -0
- package/lib/internalUtils.js.map +1 -0
- package/lib/latestMapValueManager.d.ts +1 -1
- package/lib/latestMapValueManager.d.ts.map +1 -1
- package/lib/latestMapValueManager.js +27 -17
- package/lib/latestMapValueManager.js.map +1 -1
- package/lib/latestValueManager.js +12 -12
- package/lib/latestValueManager.js.map +1 -1
- package/lib/presenceDatastoreManager.d.ts.map +1 -1
- package/lib/presenceDatastoreManager.js +10 -7
- package/lib/presenceDatastoreManager.js.map +1 -1
- package/lib/presenceStates.d.ts.map +1 -1
- package/lib/presenceStates.js +38 -39
- package/lib/presenceStates.js.map +1 -1
- package/lib/systemWorkspace.d.ts.map +1 -1
- package/lib/systemWorkspace.js +60 -34
- package/lib/systemWorkspace.js.map +1 -1
- package/package.json +19 -19
package/dist/systemWorkspace.js
CHANGED
|
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
exports.createSystemWorkspace = void 0;
|
|
8
8
|
const internal_1 = require("@fluidframework/core-utils/internal");
|
|
9
9
|
const presence_js_1 = require("./presence.js");
|
|
10
|
+
const timerManager_js_1 = require("./timerManager.js");
|
|
10
11
|
class SessionClient {
|
|
11
12
|
constructor(sessionId, connectionId = undefined) {
|
|
12
13
|
this.sessionId = sessionId;
|
|
@@ -16,10 +17,7 @@ class SessionClient {
|
|
|
16
17
|
* during a session.
|
|
17
18
|
*/
|
|
18
19
|
this.order = 0;
|
|
19
|
-
this.connectionStatus =
|
|
20
|
-
connectionId === undefined
|
|
21
|
-
? presence_js_1.SessionClientStatus.Disconnected
|
|
22
|
-
: presence_js_1.SessionClientStatus.Connected;
|
|
20
|
+
this.connectionStatus = presence_js_1.SessionClientStatus.Disconnected;
|
|
23
21
|
}
|
|
24
22
|
getConnectionId() {
|
|
25
23
|
if (this.connectionId === undefined) {
|
|
@@ -30,8 +28,7 @@ class SessionClient {
|
|
|
30
28
|
getConnectionStatus() {
|
|
31
29
|
return this.connectionStatus;
|
|
32
30
|
}
|
|
33
|
-
|
|
34
|
-
this.connectionId = connectionId;
|
|
31
|
+
setConnected() {
|
|
35
32
|
this.connectionStatus = presence_js_1.SessionClientStatus.Connected;
|
|
36
33
|
}
|
|
37
34
|
setDisconnected() {
|
|
@@ -51,6 +48,10 @@ class SystemWorkspaceImpl {
|
|
|
51
48
|
* An entry is for session ID if the value's `sessionId` matches the key.
|
|
52
49
|
*/
|
|
53
50
|
this.attendees = new Map();
|
|
51
|
+
// When local client disconnects, we lose the connectivity status updates for remote attendees in the session.
|
|
52
|
+
// Upon reconnect, we mark all other attendees connections as stale and update their status to disconnected after 30 seconds of inactivity.
|
|
53
|
+
this.staleConnectionClients = new Set();
|
|
54
|
+
this.staleConnectionTimer = new timerManager_js_1.TimerManager();
|
|
54
55
|
this.selfAttendee = new SessionClient(clientSessionId);
|
|
55
56
|
this.attendees.set(clientSessionId, this.selfAttendee);
|
|
56
57
|
}
|
|
@@ -58,28 +59,19 @@ class SystemWorkspaceImpl {
|
|
|
58
59
|
throw new Error("Method not implemented.");
|
|
59
60
|
}
|
|
60
61
|
processUpdate(_received, _timeModifier, remoteDatastore, senderConnectionId) {
|
|
61
|
-
const postUpdateActions = [];
|
|
62
62
|
const audienceMembers = this.audience.getMembers();
|
|
63
|
-
const
|
|
63
|
+
const joiningAttendees = new Set();
|
|
64
64
|
for (const [clientConnectionId, value] of Object.entries(remoteDatastore.clientToSessionId)) {
|
|
65
65
|
const clientSessionId = value.value;
|
|
66
|
-
const { attendee,
|
|
67
|
-
/* order */ value.rev
|
|
68
|
-
//
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (isNew) {
|
|
76
|
-
// If the attendee is both new and in audience (i.e. currently connected), emit an attendeeJoined event.
|
|
77
|
-
postUpdateActions.push(() => this.events.emit("attendeeJoined", attendee));
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
// If the attendee is not in the audience, they are considered disconnected.
|
|
81
|
-
if (!connectedAttendees.has(attendee)) {
|
|
82
|
-
attendee.setDisconnected();
|
|
66
|
+
const { attendee, isJoining } = this.ensureAttendee(clientSessionId, clientConnectionId,
|
|
67
|
+
/* order */ value.rev,
|
|
68
|
+
// If the attendee is present in audience OR if the attendee update is from the sending remote client itself,
|
|
69
|
+
// then the attendee is considered connected.
|
|
70
|
+
/* isConnected */ senderConnectionId === clientConnectionId ||
|
|
71
|
+
audienceMembers.has(clientConnectionId));
|
|
72
|
+
// If the attendee is joining the session, add them to the list of joining attendees to be announced later.
|
|
73
|
+
if (isJoining) {
|
|
74
|
+
joiningAttendees.add(attendee);
|
|
83
75
|
}
|
|
84
76
|
const knownSessionId = this.datastore.clientToSessionId[clientConnectionId];
|
|
85
77
|
if (knownSessionId === undefined) {
|
|
@@ -90,24 +82,46 @@ class SystemWorkspaceImpl {
|
|
|
90
82
|
}
|
|
91
83
|
}
|
|
92
84
|
// TODO: reorganize processUpdate and caller to process actions after all updates are processed.
|
|
93
|
-
for (const
|
|
94
|
-
|
|
85
|
+
for (const announcedAttendee of joiningAttendees) {
|
|
86
|
+
this.events.emit("attendeeJoined", announcedAttendee);
|
|
95
87
|
}
|
|
96
88
|
}
|
|
97
89
|
onConnectionAdded(clientConnectionId) {
|
|
90
|
+
(0, internal_1.assert)(this.selfAttendee.getConnectionStatus() === presence_js_1.SessionClientStatus.Disconnected, 0xaad /* Local client should be 'Disconnected' before adding new connection. */);
|
|
98
91
|
this.datastore.clientToSessionId[clientConnectionId] = {
|
|
99
92
|
rev: this.selfAttendee.order++,
|
|
100
93
|
timestamp: Date.now(),
|
|
101
94
|
value: this.selfAttendee.sessionId,
|
|
102
95
|
};
|
|
103
|
-
|
|
96
|
+
// Mark 'Connected' remote attendees connections as stale
|
|
97
|
+
for (const staleConnectionClient of this.attendees.values()) {
|
|
98
|
+
if (staleConnectionClient.getConnectionStatus() === presence_js_1.SessionClientStatus.Connected) {
|
|
99
|
+
this.staleConnectionClients.add(staleConnectionClient);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// Update the self attendee
|
|
103
|
+
this.selfAttendee.connectionId = clientConnectionId;
|
|
104
|
+
this.selfAttendee.setConnected();
|
|
104
105
|
this.attendees.set(clientConnectionId, this.selfAttendee);
|
|
106
|
+
this.staleConnectionTimer.setTimeout(() => {
|
|
107
|
+
for (const client of this.staleConnectionClients) {
|
|
108
|
+
client.setDisconnected();
|
|
109
|
+
}
|
|
110
|
+
for (const client of this.staleConnectionClients) {
|
|
111
|
+
this.events.emit("attendeeDisconnected", client);
|
|
112
|
+
}
|
|
113
|
+
this.staleConnectionClients.clear();
|
|
114
|
+
}, 30000);
|
|
105
115
|
}
|
|
106
116
|
removeClientConnectionId(clientConnectionId) {
|
|
107
117
|
const attendee = this.attendees.get(clientConnectionId);
|
|
108
118
|
if (!attendee) {
|
|
109
119
|
return;
|
|
110
120
|
}
|
|
121
|
+
// If the local connection is being removed, clear the stale connection timer
|
|
122
|
+
if (attendee === this.selfAttendee) {
|
|
123
|
+
this.staleConnectionTimer.clearTimeout();
|
|
124
|
+
}
|
|
111
125
|
// If the last known connectionID is different from the connection ID being removed, the attendee has reconnected,
|
|
112
126
|
// therefore we should not change the attendee connection status or emit a disconnect event.
|
|
113
127
|
const attendeeReconnected = attendee.getConnectionId() !== clientConnectionId;
|
|
@@ -115,6 +129,7 @@ class SystemWorkspaceImpl {
|
|
|
115
129
|
if (!attendeeReconnected && connected) {
|
|
116
130
|
attendee.setDisconnected();
|
|
117
131
|
this.events.emit("attendeeDisconnected", attendee);
|
|
132
|
+
this.staleConnectionClients.delete(attendee);
|
|
118
133
|
}
|
|
119
134
|
}
|
|
120
135
|
getAttendees() {
|
|
@@ -139,26 +154,37 @@ class SystemWorkspaceImpl {
|
|
|
139
154
|
* in the attendee map. If not present, SessionClient is created and added
|
|
140
155
|
* to map. If present, make sure the current connection ID is updated.
|
|
141
156
|
*/
|
|
142
|
-
ensureAttendee(clientSessionId, clientConnectionId, order) {
|
|
157
|
+
ensureAttendee(clientSessionId, clientConnectionId, order, isConnected) {
|
|
143
158
|
let attendee = this.attendees.get(clientSessionId);
|
|
144
|
-
let
|
|
159
|
+
let isJoining = false;
|
|
145
160
|
if (attendee === undefined) {
|
|
146
161
|
// New attendee. Create SessionClient and add session ID based
|
|
147
162
|
// entry to map.
|
|
148
163
|
attendee = new SessionClient(clientSessionId, clientConnectionId);
|
|
149
164
|
this.attendees.set(clientSessionId, attendee);
|
|
150
|
-
|
|
165
|
+
if (isConnected) {
|
|
166
|
+
attendee.setConnected();
|
|
167
|
+
isJoining = true;
|
|
168
|
+
}
|
|
151
169
|
}
|
|
152
170
|
else if (order > attendee.order) {
|
|
153
171
|
// The given association is newer than the one we have.
|
|
154
172
|
// Update the order and current connection ID.
|
|
155
173
|
attendee.order = order;
|
|
156
|
-
attendee
|
|
157
|
-
|
|
174
|
+
// Known attendee is joining the session if they are currently disconnected
|
|
175
|
+
if (attendee.getConnectionStatus() === presence_js_1.SessionClientStatus.Disconnected && isConnected) {
|
|
176
|
+
attendee.setConnected();
|
|
177
|
+
isJoining = true;
|
|
178
|
+
}
|
|
179
|
+
attendee.connectionId = clientConnectionId;
|
|
180
|
+
}
|
|
181
|
+
if (isConnected) {
|
|
182
|
+
// If the attendee is connected, remove them from the stale connection set
|
|
183
|
+
this.staleConnectionClients.delete(attendee);
|
|
158
184
|
}
|
|
159
185
|
// Always update entry for the connection ID. (Okay if already set.)
|
|
160
186
|
this.attendees.set(clientConnectionId, attendee);
|
|
161
|
-
return { attendee,
|
|
187
|
+
return { attendee, isJoining };
|
|
162
188
|
}
|
|
163
189
|
}
|
|
164
190
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"systemWorkspace.js","sourceRoot":"","sources":["../src/systemWorkspace.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH,kEAA6D;AAU7D,+CAAoD;AAepD,MAAM,aAAa;IASlB,YACiB,SAA0B,EAClC,eAA+C,SAAS;QADhD,cAAS,GAAT,SAAS,CAAiB;QAClC,iBAAY,GAAZ,YAAY,CAA4C;QAVjE;;;WAGG;QACI,UAAK,GAAW,CAAC,CAAC;QAQxB,IAAI,CAAC,gBAAgB;YACpB,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,KAAK,EAAE,CAAC;IAC5B,CAAC;CACD;AAED;;;;GAIG;AACH,SAAgB,qBAAqB,CACpC,eAAgC,EAChC,SAAmC,EACnC,MAAwD,EACxD,QAAmB;IAQnB,MAAM,SAAS,GAAG,IAAI,mBAAmB,CAAC,eAAe,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;IACxF,OAAO;QACN,SAAS;QACT,WAAW,EAAE;YACZ,QAAQ,EAAE,SAAS;YACnB,MAAM,EAAE,SAA4D;SACpE;KACD,CAAC;AACH,CAAC;AApBD,sDAoBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IAudience } from \"@fluidframework/container-definitions\";\nimport type { IEmitter } from \"@fluidframework/core-interfaces/internal\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\n\nimport type { ClientConnectionId } from \"./baseTypes.js\";\nimport type { InternalTypes } from \"./exposedInternalTypes.js\";\nimport type {\n\tClientSessionId,\n\tIPresence,\n\tISessionClient,\n\tPresenceEvents,\n} from \"./presence.js\";\nimport { SessionClientStatus } from \"./presence.js\";\nimport type { PresenceStatesInternal } from \"./presenceStates.js\";\nimport type { PresenceStates, PresenceStatesSchema } from \"./types.js\";\n\n/**\n * The system workspace's datastore structure.\n *\n * @internal\n */\nexport interface SystemWorkspaceDatastore {\n\tclientToSessionId: {\n\t\t[ConnectionId: ClientConnectionId]: InternalTypes.ValueRequiredState<ClientSessionId>;\n\t};\n}\n\nclass SessionClient implements ISessionClient {\n\t/**\n\t * Order is used to track the most recent client connection\n\t * during a session.\n\t */\n\tpublic order: number = 0;\n\n\tprivate connectionStatus: SessionClientStatus;\n\n\tpublic constructor(\n\t\tpublic readonly sessionId: ClientSessionId,\n\t\tprivate connectionId: ClientConnectionId | undefined = undefined,\n\t) {\n\t\tthis.connectionStatus =\n\t\t\tconnectionId === undefined\n\t\t\t\t? SessionClientStatus.Disconnected\n\t\t\t\t: SessionClientStatus.Connected;\n\t}\n\n\tpublic getConnectionId(): ClientConnectionId {\n\t\tif (this.connectionId === undefined) {\n\t\t\tthrow new Error(\"Client has never been connected\");\n\t\t}\n\t\treturn this.connectionId;\n\t}\n\n\tpublic getConnectionStatus(): SessionClientStatus {\n\t\treturn this.connectionStatus;\n\t}\n\n\tpublic setConnectionId(connectionId: ClientConnectionId): void {\n\t\tthis.connectionId = connectionId;\n\t\tthis.connectionStatus = SessionClientStatus.Connected;\n\t}\n\n\tpublic setDisconnected(): void {\n\t\tthis.connectionStatus = SessionClientStatus.Disconnected;\n\t}\n}\n\n/**\n * @internal\n */\nexport interface SystemWorkspace\n\t// Portion of IPresence that is handled by SystemWorkspace along with\n\t// responsiblity for emitting \"attendeeJoined\" events.\n\textends Pick<IPresence, \"getAttendees\" | \"getAttendee\" | \"getMyself\"> {\n\t/**\n\t * Must be called when the current client acquires a new connection.\n\t *\n\t * @param clientConnectionId - The new client connection ID.\n\t */\n\tonConnectionAdded(clientConnectionId: ClientConnectionId): void;\n\n\t/**\n\t * Removes the client connection ID from the system workspace.\n\t *\n\t * @param clientConnectionId - The client connection ID to remove.\n\t */\n\tremoveClientConnectionId(clientConnectionId: ClientConnectionId): void;\n}\n\nclass SystemWorkspaceImpl implements PresenceStatesInternal, SystemWorkspace {\n\tprivate readonly selfAttendee: SessionClient;\n\t/**\n\t * `attendees` is this client's understanding of the attendees in the\n\t * session. The map covers entries for both session ids and connection\n\t * ids, which are never expected to collide, but if they did for same\n\t * client that would be fine.\n\t * An entry is for session ID if the value's `sessionId` matches the key.\n\t */\n\tprivate readonly attendees = new Map<ClientConnectionId | ClientSessionId, SessionClient>();\n\n\tpublic constructor(\n\t\tclientSessionId: ClientSessionId,\n\t\tprivate readonly datastore: SystemWorkspaceDatastore,\n\t\tprivate readonly events: IEmitter<\n\t\t\tPick<PresenceEvents, \"attendeeJoined\" | \"attendeeDisconnected\">\n\t\t>,\n\t\tprivate readonly audience: IAudience,\n\t) {\n\t\tthis.selfAttendee = new SessionClient(clientSessionId);\n\t\tthis.attendees.set(clientSessionId, this.selfAttendee);\n\t}\n\n\tpublic ensureContent<TSchemaAdditional extends PresenceStatesSchema>(\n\t\t_content: TSchemaAdditional,\n\t): never {\n\t\tthrow new Error(\"Method not implemented.\");\n\t}\n\n\tpublic processUpdate(\n\t\t_received: number,\n\t\t_timeModifier: number,\n\t\tremoteDatastore: {\n\t\t\tclientToSessionId: {\n\t\t\t\t[\n\t\t\t\t\tConnectionId: ClientConnectionId\n\t\t\t\t]: InternalTypes.ValueRequiredState<ClientSessionId> & {\n\t\t\t\t\tignoreUnmonitored?: true;\n\t\t\t\t};\n\t\t\t};\n\t\t},\n\t\tsenderConnectionId: ClientConnectionId,\n\t): void {\n\t\tconst postUpdateActions: (() => void)[] = [];\n\t\tconst audienceMembers = this.audience.getMembers();\n\t\tconst connectedAttendees = new Set<SessionClient>();\n\t\tfor (const [clientConnectionId, value] of Object.entries(\n\t\t\tremoteDatastore.clientToSessionId,\n\t\t)) {\n\t\t\tconst clientSessionId = value.value;\n\t\t\tconst { attendee, isNew } = this.ensureAttendee(\n\t\t\t\tclientSessionId,\n\t\t\t\tclientConnectionId,\n\t\t\t\t/* order */ value.rev,\n\t\t\t);\n\n\t\t\t// Check new attendee against audience to see if they're currently connected\n\t\t\tconst isAttendeeConnected = audienceMembers.has(clientConnectionId);\n\n\t\t\tif (isAttendeeConnected) {\n\t\t\t\tconnectedAttendees.add(attendee);\n\t\t\t\tif (attendee.getConnectionStatus() === SessionClientStatus.Disconnected) {\n\t\t\t\t\tattendee.setConnectionId(clientConnectionId);\n\t\t\t\t}\n\t\t\t\tif (isNew) {\n\t\t\t\t\t// If the attendee is both new and in audience (i.e. currently connected), emit an attendeeJoined event.\n\t\t\t\t\tpostUpdateActions.push(() => this.events.emit(\"attendeeJoined\", attendee));\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// If the attendee is not in the audience, they are considered disconnected.\n\t\t\tif (!connectedAttendees.has(attendee)) {\n\t\t\t\tattendee.setDisconnected();\n\t\t\t}\n\n\t\t\tconst knownSessionId: InternalTypes.ValueRequiredState<ClientSessionId> | undefined =\n\t\t\t\tthis.datastore.clientToSessionId[clientConnectionId];\n\t\t\tif (knownSessionId === undefined) {\n\t\t\t\tthis.datastore.clientToSessionId[clientConnectionId] = value;\n\t\t\t} else {\n\t\t\t\tassert(knownSessionId.value === value.value, 0xa5a /* Mismatched SessionId */);\n\t\t\t}\n\t\t}\n\n\t\t// TODO: reorganize processUpdate and caller to process actions after all updates are processed.\n\t\tfor (const action of postUpdateActions) {\n\t\t\taction();\n\t\t}\n\t}\n\n\tpublic onConnectionAdded(clientConnectionId: ClientConnectionId): void {\n\t\tthis.datastore.clientToSessionId[clientConnectionId] = {\n\t\t\trev: this.selfAttendee.order++,\n\t\t\ttimestamp: Date.now(),\n\t\t\tvalue: this.selfAttendee.sessionId,\n\t\t};\n\n\t\tthis.selfAttendee.setConnectionId(clientConnectionId);\n\t\tthis.attendees.set(clientConnectionId, this.selfAttendee);\n\t}\n\n\tpublic removeClientConnectionId(clientConnectionId: ClientConnectionId): void {\n\t\tconst attendee = this.attendees.get(clientConnectionId);\n\t\tif (!attendee) {\n\t\t\treturn;\n\t\t}\n\n\t\t// If the last known connectionID is different from the connection ID being removed, the attendee has reconnected,\n\t\t// therefore we should not change the attendee connection status or emit a disconnect event.\n\t\tconst attendeeReconnected = attendee.getConnectionId() !== clientConnectionId;\n\t\tconst connected = attendee.getConnectionStatus() === SessionClientStatus.Connected;\n\t\tif (!attendeeReconnected && connected) {\n\t\t\tattendee.setDisconnected();\n\t\t\tthis.events.emit(\"attendeeDisconnected\", attendee);\n\t\t}\n\t}\n\n\tpublic getAttendees(): ReadonlySet<ISessionClient> {\n\t\treturn new Set(this.attendees.values());\n\t}\n\n\tpublic getAttendee(clientId: ClientConnectionId | ClientSessionId): ISessionClient {\n\t\tconst attendee = this.attendees.get(clientId);\n\t\tif (attendee) {\n\t\t\treturn attendee;\n\t\t}\n\n\t\t// TODO: Restore option to add attendee on demand to handle internal\n\t\t// lookup cases that must come from internal data.\n\t\t// There aren't any resiliency mechanisms in place to handle a missed\n\t\t// ClientJoin right now.\n\t\tthrow new Error(\"Attendee not found\");\n\t}\n\n\tpublic getMyself(): ISessionClient {\n\t\treturn this.selfAttendee;\n\t}\n\n\t/**\n\t * Make sure the given client session and connection ID pair are represented\n\t * in the attendee map. If not present, SessionClient is created and added\n\t * to map. If present, make sure the current connection ID is updated.\n\t */\n\tprivate ensureAttendee(\n\t\tclientSessionId: ClientSessionId,\n\t\tclientConnectionId: ClientConnectionId,\n\t\torder: number,\n\t): { attendee: SessionClient; isNew: boolean } {\n\t\tlet attendee = this.attendees.get(clientSessionId);\n\t\tlet isNew = false;\n\n\t\tif (attendee === undefined) {\n\t\t\t// New attendee. Create SessionClient and add session ID based\n\t\t\t// entry to map.\n\t\t\tattendee = new SessionClient(clientSessionId, clientConnectionId);\n\t\t\tthis.attendees.set(clientSessionId, attendee);\n\t\t\tisNew = true;\n\t\t} else if (order > attendee.order) {\n\t\t\t// The given association is newer than the one we have.\n\t\t\t// Update the order and current connection ID.\n\t\t\tattendee.order = order;\n\t\t\tattendee.setConnectionId(clientConnectionId);\n\t\t\tisNew = true;\n\t\t}\n\t\t// Always update entry for the connection ID. (Okay if already set.)\n\t\tthis.attendees.set(clientConnectionId, attendee);\n\n\t\treturn { attendee, isNew };\n\t}\n}\n\n/**\n * Instantiates the system workspace.\n *\n * @internal\n */\nexport function createSystemWorkspace(\n\tclientSessionId: ClientSessionId,\n\tdatastore: SystemWorkspaceDatastore,\n\tevents: IEmitter<Pick<PresenceEvents, \"attendeeJoined\">>,\n\taudience: IAudience,\n): {\n\tworkspace: SystemWorkspace;\n\tstatesEntry: {\n\t\tinternal: PresenceStatesInternal;\n\t\tpublic: PresenceStates<PresenceStatesSchema>;\n\t};\n} {\n\tconst workspace = new SystemWorkspaceImpl(clientSessionId, datastore, events, audience);\n\treturn {\n\t\tworkspace,\n\t\tstatesEntry: {\n\t\t\tinternal: workspace,\n\t\t\tpublic: undefined as unknown as PresenceStates<PresenceStatesSchema>,\n\t\t},\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"systemWorkspace.js","sourceRoot":"","sources":["../src/systemWorkspace.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH,kEAA6D;AAU7D,+CAAoD;AAEpD,uDAAiD;AAcjD,MAAM,aAAa;IASlB,YACiB,SAA0B,EACnC,eAA+C,SAAS;QAD/C,cAAS,GAAT,SAAS,CAAiB;QACnC,iBAAY,GAAZ,YAAY,CAA4C;QAVhE;;;WAGG;QACI,UAAK,GAAW,CAAC,CAAC;QAEjB,qBAAgB,GAAwB,iCAAmB,CAAC,YAAY,CAAC;IAK9E,CAAC;IAEG,eAAe;QACrB,IAAI,IAAI,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;YACrC,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;QACpD,CAAC;QACD,OAAO,IAAI,CAAC,YAAY,CAAC;IAC1B,CAAC;IAEM,mBAAmB;QACzB,OAAO,IAAI,CAAC,gBAAgB,CAAC;IAC9B,CAAC;IAEM,YAAY;QAClB,IAAI,CAAC,gBAAgB,GAAG,iCAAmB,CAAC,SAAS,CAAC;IACvD,CAAC;IAEM,eAAe;QACrB,IAAI,CAAC,gBAAgB,GAAG,iCAAmB,CAAC,YAAY,CAAC;IAC1D,CAAC;CACD;AAwBD,MAAM,mBAAmB;IAiBxB,YACC,eAAgC,EACf,SAAmC,EACnC,MAEhB,EACgB,QAAmB;QAJnB,cAAS,GAAT,SAAS,CAA0B;QACnC,WAAM,GAAN,MAAM,CAEtB;QACgB,aAAQ,GAAR,QAAQ,CAAW;QArBrC;;;;;;WAMG;QACc,cAAS,GAAG,IAAI,GAAG,EAAuD,CAAC;QAE5F,8GAA8G;QAC9G,2IAA2I;QAC1H,2BAAsB,GAAG,IAAI,GAAG,EAAiB,CAAC;QAElD,yBAAoB,GAAG,IAAI,8B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,0EAA0E;YAC1E,IAAI,CAAC,sBAAsB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC9C,CAAC;QAED,oEAAoE;QACpE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,kBAAkB,EAAE,QAAQ,CAAC,CAAC;QAEjD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC;IAChC,CAAC;CACD;AAED;;;;GAIG;AACH,SAAgB,qBAAqB,CACpC,eAAgC,EAChC,SAAmC,EACnC,MAAwD,EACxD,QAAmB;IAQnB,MAAM,SAAS,GAAG,IAAI,mBAAmB,CAAC,eAAe,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;IACxF,OAAO;QACN,SAAS;QACT,WAAW,EAAE;YACZ,QAAQ,EAAE,SAAS;YACnB,MAAM,EAAE,SAA4D;SACpE;KACD,CAAC;AACH,CAAC;AApBD,sDAoBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IAudience } from \"@fluidframework/container-definitions\";\nimport type { IEmitter } from \"@fluidframework/core-interfaces/internal\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\n\nimport type { ClientConnectionId } from \"./baseTypes.js\";\nimport type { InternalTypes } from \"./exposedInternalTypes.js\";\nimport type {\n\tClientSessionId,\n\tIPresence,\n\tISessionClient,\n\tPresenceEvents,\n} from \"./presence.js\";\nimport { SessionClientStatus } from \"./presence.js\";\nimport type { PresenceStatesInternal } from \"./presenceStates.js\";\nimport { TimerManager } from \"./timerManager.js\";\nimport type { PresenceStates, PresenceStatesSchema } from \"./types.js\";\n\n/**\n * The system workspace's datastore structure.\n *\n * @internal\n */\nexport interface SystemWorkspaceDatastore {\n\tclientToSessionId: {\n\t\t[ConnectionId: ClientConnectionId]: InternalTypes.ValueRequiredState<ClientSessionId>;\n\t};\n}\n\nclass SessionClient implements ISessionClient {\n\t/**\n\t * Order is used to track the most recent client connection\n\t * during a session.\n\t */\n\tpublic order: number = 0;\n\n\tprivate connectionStatus: SessionClientStatus = SessionClientStatus.Disconnected;\n\n\tpublic constructor(\n\t\tpublic readonly sessionId: ClientSessionId,\n\t\tpublic connectionId: ClientConnectionId | undefined = undefined,\n\t) {}\n\n\tpublic getConnectionId(): ClientConnectionId {\n\t\tif (this.connectionId === undefined) {\n\t\t\tthrow new Error(\"Client has never been connected\");\n\t\t}\n\t\treturn this.connectionId;\n\t}\n\n\tpublic getConnectionStatus(): SessionClientStatus {\n\t\treturn this.connectionStatus;\n\t}\n\n\tpublic setConnected(): void {\n\t\tthis.connectionStatus = SessionClientStatus.Connected;\n\t}\n\n\tpublic setDisconnected(): void {\n\t\tthis.connectionStatus = SessionClientStatus.Disconnected;\n\t}\n}\n\n/**\n * @internal\n */\nexport interface SystemWorkspace\n\t// Portion of IPresence that is handled by SystemWorkspace along with\n\t// responsiblity for emitting \"attendeeJoined\" events.\n\textends Pick<IPresence, \"getAttendees\" | \"getAttendee\" | \"getMyself\"> {\n\t/**\n\t * Must be called when the current client acquires a new connection.\n\t *\n\t * @param clientConnectionId - The new client connection ID.\n\t */\n\tonConnectionAdded(clientConnectionId: ClientConnectionId): void;\n\n\t/**\n\t * Removes the client connection ID from the system workspace.\n\t *\n\t * @param clientConnectionId - The client connection ID to remove.\n\t */\n\tremoveClientConnectionId(clientConnectionId: ClientConnectionId): void;\n}\n\nclass SystemWorkspaceImpl implements PresenceStatesInternal, SystemWorkspace {\n\tprivate readonly selfAttendee: SessionClient;\n\t/**\n\t * `attendees` is this client's understanding of the attendees in the\n\t * session. The map covers entries for both session ids and connection\n\t * ids, which are never expected to collide, but if they did for same\n\t * client that would be fine.\n\t * An entry is for session ID if the value's `sessionId` matches the key.\n\t */\n\tprivate readonly attendees = new Map<ClientConnectionId | ClientSessionId, SessionClient>();\n\n\t// When local client disconnects, we lose the connectivity status updates for remote attendees in the session.\n\t// Upon reconnect, we mark all other attendees connections as stale and update their status to disconnected after 30 seconds of inactivity.\n\tprivate readonly staleConnectionClients = new Set<SessionClient>();\n\n\tprivate readonly staleConnectionTimer = new TimerManager();\n\n\tpublic constructor(\n\t\tclientSessionId: ClientSessionId,\n\t\tprivate readonly datastore: SystemWorkspaceDatastore,\n\t\tprivate readonly events: IEmitter<\n\t\t\tPick<PresenceEvents, \"attendeeJoined\" | \"attendeeDisconnected\">\n\t\t>,\n\t\tprivate readonly audience: IAudience,\n\t) {\n\t\tthis.selfAttendee = new SessionClient(clientSessionId);\n\t\tthis.attendees.set(clientSessionId, this.selfAttendee);\n\t}\n\n\tpublic ensureContent<TSchemaAdditional extends PresenceStatesSchema>(\n\t\t_content: TSchemaAdditional,\n\t): never {\n\t\tthrow new Error(\"Method not implemented.\");\n\t}\n\n\tpublic processUpdate(\n\t\t_received: number,\n\t\t_timeModifier: number,\n\t\tremoteDatastore: {\n\t\t\tclientToSessionId: {\n\t\t\t\t[\n\t\t\t\t\tConnectionId: ClientConnectionId\n\t\t\t\t]: InternalTypes.ValueRequiredState<ClientSessionId> & {\n\t\t\t\t\tignoreUnmonitored?: true;\n\t\t\t\t};\n\t\t\t};\n\t\t},\n\t\tsenderConnectionId: ClientConnectionId,\n\t): void {\n\t\tconst audienceMembers = this.audience.getMembers();\n\t\tconst joiningAttendees = new Set<SessionClient>();\n\t\tfor (const [clientConnectionId, value] of Object.entries(\n\t\t\tremoteDatastore.clientToSessionId,\n\t\t)) {\n\t\t\tconst clientSessionId = value.value;\n\t\t\tconst { attendee, isJoining } = this.ensureAttendee(\n\t\t\t\tclientSessionId,\n\t\t\t\tclientConnectionId,\n\t\t\t\t/* order */ value.rev,\n\t\t\t\t// If the attendee is present in audience OR if the attendee update is from the sending remote client itself,\n\t\t\t\t// then the attendee is considered connected.\n\t\t\t\t/* isConnected */ senderConnectionId === clientConnectionId ||\n\t\t\t\t\taudienceMembers.has(clientConnectionId),\n\t\t\t);\n\t\t\t// If the attendee is joining the session, add them to the list of joining attendees to be announced later.\n\t\t\tif (isJoining) {\n\t\t\t\tjoiningAttendees.add(attendee);\n\t\t\t}\n\n\t\t\tconst knownSessionId: InternalTypes.ValueRequiredState<ClientSessionId> | undefined =\n\t\t\t\tthis.datastore.clientToSessionId[clientConnectionId];\n\t\t\tif (knownSessionId === undefined) {\n\t\t\t\tthis.datastore.clientToSessionId[clientConnectionId] = value;\n\t\t\t} else {\n\t\t\t\tassert(knownSessionId.value === value.value, 0xa5a /* Mismatched SessionId */);\n\t\t\t}\n\t\t}\n\n\t\t// TODO: reorganize processUpdate and caller to process actions after all updates are processed.\n\t\tfor (const announcedAttendee of joiningAttendees) {\n\t\t\tthis.events.emit(\"attendeeJoined\", announcedAttendee);\n\t\t}\n\t}\n\n\tpublic onConnectionAdded(clientConnectionId: ClientConnectionId): void {\n\t\tassert(\n\t\t\tthis.selfAttendee.getConnectionStatus() === SessionClientStatus.Disconnected,\n\t\t\t0xaad /* Local client should be 'Disconnected' before adding new connection. */,\n\t\t);\n\n\t\tthis.datastore.clientToSessionId[clientConnectionId] = {\n\t\t\trev: this.selfAttendee.order++,\n\t\t\ttimestamp: Date.now(),\n\t\t\tvalue: this.selfAttendee.sessionId,\n\t\t};\n\n\t\t// Mark 'Connected' remote attendees connections as stale\n\t\tfor (const staleConnectionClient of this.attendees.values()) {\n\t\t\tif (staleConnectionClient.getConnectionStatus() === SessionClientStatus.Connected) {\n\t\t\t\tthis.staleConnectionClients.add(staleConnectionClient);\n\t\t\t}\n\t\t}\n\n\t\t// Update the self attendee\n\t\tthis.selfAttendee.connectionId = clientConnectionId;\n\t\tthis.selfAttendee.setConnected();\n\t\tthis.attendees.set(clientConnectionId, this.selfAttendee);\n\n\t\tthis.staleConnectionTimer.setTimeout(() => {\n\t\t\tfor (const client of this.staleConnectionClients) {\n\t\t\t\tclient.setDisconnected();\n\t\t\t}\n\t\t\tfor (const client of this.staleConnectionClients) {\n\t\t\t\tthis.events.emit(\"attendeeDisconnected\", client);\n\t\t\t}\n\t\t\tthis.staleConnectionClients.clear();\n\t\t}, 30_000);\n\t}\n\n\tpublic removeClientConnectionId(clientConnectionId: ClientConnectionId): void {\n\t\tconst attendee = this.attendees.get(clientConnectionId);\n\t\tif (!attendee) {\n\t\t\treturn;\n\t\t}\n\n\t\t// If the local connection is being removed, clear the stale connection timer\n\t\tif (attendee === this.selfAttendee) {\n\t\t\tthis.staleConnectionTimer.clearTimeout();\n\t\t}\n\n\t\t// If the last known connectionID is different from the connection ID being removed, the attendee has reconnected,\n\t\t// therefore we should not change the attendee connection status or emit a disconnect event.\n\t\tconst attendeeReconnected = attendee.getConnectionId() !== clientConnectionId;\n\t\tconst connected = attendee.getConnectionStatus() === SessionClientStatus.Connected;\n\t\tif (!attendeeReconnected && connected) {\n\t\t\tattendee.setDisconnected();\n\t\t\tthis.events.emit(\"attendeeDisconnected\", attendee);\n\t\t\tthis.staleConnectionClients.delete(attendee);\n\t\t}\n\t}\n\n\tpublic getAttendees(): ReadonlySet<ISessionClient> {\n\t\treturn new Set(this.attendees.values());\n\t}\n\n\tpublic getAttendee(clientId: ClientConnectionId | ClientSessionId): ISessionClient {\n\t\tconst attendee = this.attendees.get(clientId);\n\t\tif (attendee) {\n\t\t\treturn attendee;\n\t\t}\n\n\t\t// TODO: Restore option to add attendee on demand to handle internal\n\t\t// lookup cases that must come from internal data.\n\t\t// There aren't any resiliency mechanisms in place to handle a missed\n\t\t// ClientJoin right now.\n\t\tthrow new Error(\"Attendee not found\");\n\t}\n\n\tpublic getMyself(): ISessionClient {\n\t\treturn this.selfAttendee;\n\t}\n\n\t/**\n\t * Make sure the given client session and connection ID pair are represented\n\t * in the attendee map. If not present, SessionClient is created and added\n\t * to map. If present, make sure the current connection ID is updated.\n\t */\n\tprivate ensureAttendee(\n\t\tclientSessionId: ClientSessionId,\n\t\tclientConnectionId: ClientConnectionId,\n\t\torder: number,\n\t\tisConnected: boolean,\n\t): { attendee: SessionClient; isJoining: boolean } {\n\t\tlet attendee = this.attendees.get(clientSessionId);\n\t\tlet isJoining = false;\n\n\t\tif (attendee === undefined) {\n\t\t\t// New attendee. Create SessionClient and add session ID based\n\t\t\t// entry to map.\n\t\t\tattendee = new SessionClient(clientSessionId, clientConnectionId);\n\t\t\tthis.attendees.set(clientSessionId, attendee);\n\t\t\tif (isConnected) {\n\t\t\t\tattendee.setConnected();\n\t\t\t\tisJoining = true;\n\t\t\t}\n\t\t} else if (order > attendee.order) {\n\t\t\t// The given association is newer than the one we have.\n\t\t\t// Update the order and current connection ID.\n\t\t\tattendee.order = order;\n\t\t\t// Known attendee is joining the session if they are currently disconnected\n\t\t\tif (attendee.getConnectionStatus() === SessionClientStatus.Disconnected && isConnected) {\n\t\t\t\tattendee.setConnected();\n\t\t\t\tisJoining = true;\n\t\t\t}\n\t\t\tattendee.connectionId = clientConnectionId;\n\t\t}\n\n\t\tif (isConnected) {\n\t\t\t// If the attendee is connected, remove them from the stale connection set\n\t\t\tthis.staleConnectionClients.delete(attendee);\n\t\t}\n\n\t\t// Always update entry for the connection ID. (Okay if already set.)\n\t\tthis.attendees.set(clientConnectionId, attendee);\n\n\t\treturn { attendee, isJoining };\n\t}\n}\n\n/**\n * Instantiates the system workspace.\n *\n * @internal\n */\nexport function createSystemWorkspace(\n\tclientSessionId: ClientSessionId,\n\tdatastore: SystemWorkspaceDatastore,\n\tevents: IEmitter<Pick<PresenceEvents, \"attendeeJoined\">>,\n\taudience: IAudience,\n): {\n\tworkspace: SystemWorkspace;\n\tstatesEntry: {\n\t\tinternal: PresenceStatesInternal;\n\t\tpublic: PresenceStates<PresenceStatesSchema>;\n\t};\n} {\n\tconst workspace = new SystemWorkspaceImpl(clientSessionId, datastore, events, audience);\n\treturn {\n\t\tworkspace,\n\t\tstatesEntry: {\n\t\t\tinternal: workspace,\n\t\t\tpublic: undefined as unknown as PresenceStates<PresenceStatesSchema>,\n\t\t},\n\t};\n}\n"]}
|
|
@@ -46,10 +46,10 @@ export declare namespace InternalTypes {
|
|
|
46
46
|
/**
|
|
47
47
|
* @system
|
|
48
48
|
*/
|
|
49
|
-
interface MapValueState<T> {
|
|
49
|
+
interface MapValueState<T, Keys extends string | number> {
|
|
50
50
|
rev: number;
|
|
51
51
|
items: {
|
|
52
|
-
[name
|
|
52
|
+
[name in Keys]: ValueOptionalState<T>;
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exposedInternalTypes.d.ts","sourceRoot":"","sources":["../src/exposedInternalTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACX,gBAAgB,EAChB,gBAAgB,EAChB,MAAM,mDAAmD,CAAC;AAE3D;;;;;;GAMG;AAEH,yBAAiB,aAAa,CAAC;IAC9B;;OAEG;IACH,UAAiB,kBAAkB;QAClC,GAAG,EAAE,MAAM,CAAC;QACZ,SAAS,EAAE,MAAM,CAAC;KAClB;IAED;;OAEG;IACH,UAAiB,kBAAkB,CAAC,MAAM,CAAE,SAAQ,kBAAkB;QACrE,KAAK,CAAC,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC;KACjC;IAED;;OAEG;IACH,UAAiB,kBAAkB,CAAC,MAAM,CAAE,SAAQ,kBAAkB;QACrE,KAAK,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC;KAChC;IAED;;OAEG;IACH,UAAiB,cAAc,CAAC,CAAC;QAChC,GAAG,EAAE,MAAM,CAAC;QACZ,KAAK,EAAE;YAIN,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,kBAAkB,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC;SACnE,CAAC;KACF;IAED;;OAEG;IACH,KAAY,qBAAqB,CAAC,CAAC,IAAI,kBAAkB,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC;IAEjF;;OAEG;IACH,UAAiB,aAAa,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"exposedInternalTypes.d.ts","sourceRoot":"","sources":["../src/exposedInternalTyp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,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAgB;KAC3C;IAED;;;;;;;;;OASG;IACH,KAAY,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC;IAEnD;;;;OAIG;IACH,KAAY,cAAc,CACzB,IAAI,SAAS,MAAM,EACnB,MAAM,SAAS,qBAAqB,CAAC,GAAG,CAAC,EACzC,QAAQ,IACL;QAAE,YAAY,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAA;KAAE,GAAG,CAAC,CACpD,GAAG,EAAE,IAAI,EACT,eAAe,EAAE,oBAAoB,CAAC,IAAI,EAAE,MAAM,CAAC,KAC/C;QACJ,WAAW,CAAC,EAAE;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,wBAAwB,EAAE,MAAM,GAAG,SAAS,CAAA;SAAE,CAAC;QAC9E,OAAO,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;KAC9B,CAAC,CAAC;IAEH;;OAEG;IACH,UAAiB,gBAAgB;QAChC,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC;KAChE;CACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exposedInternalTypes.js","sourceRoot":"","sources":["../src/exposedInternalTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH;;;;;;GAMG;AACH,2DAA2D;AAC3D,MAAM,KAAW,aAAa,CA2G7B;AA3GD,WAAiB,aAAa;AA2G9B,CAAC,EA3GgB,aAAa,KAAb,aAAa,QA2G7B","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type {\n\tJsonDeserialized,\n\tJsonSerializable,\n} from \"@fluidframework/presence/internal/core-interfaces\";\n\n/**\n * Collection of value types that are not intended to be used/imported\n * directly outside of this package.\n *\n * @alpha\n * @system\n */\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport namespace InternalTypes {\n\t/**\n\t * @system\n\t */\n\texport interface ValueStateMetadata {\n\t\trev: number;\n\t\ttimestamp: number;\n\t}\n\n\t/**\n\t * @system\n\t */\n\texport interface ValueOptionalState<TValue> extends ValueStateMetadata {\n\t\tvalue?: JsonDeserialized<TValue>;\n\t}\n\n\t/**\n\t * @system\n\t */\n\texport interface ValueRequiredState<TValue> extends ValueStateMetadata {\n\t\tvalue: JsonDeserialized<TValue>;\n\t}\n\n\t/**\n\t * @system\n\t */\n\texport interface ValueDirectory<T> {\n\t\trev: number;\n\t\titems: {\n\t\t\t// Caution: any particular item may or may not exist\n\t\t\t// Typescript does not support absent keys without forcing type to also be undefined.\n\t\t\t// See https://github.com/microsoft/TypeScript/issues/42810.\n\t\t\t[name: string | number]: ValueOptionalState<T> | ValueDirectory<T>;\n\t\t};\n\t}\n\n\t/**\n\t * @system\n\t */\n\texport type ValueDirectoryOrState<T> = ValueRequiredState<T> | ValueDirectory<T>;\n\n\t/**\n\t * @system\n\t */\n\texport interface MapValueState<T> {\n\t\trev: number;\n\t\titems: {\n\t\t\t// Caution: any particular item may or may not exist\n\t\t\t// Typescript does not support absent keys without forcing type to also be undefined.\n\t\t\t// See https://github.com/microsoft/TypeScript/issues/42810.\n\t\t\t[name
|
|
1
|
+
{"version":3,"file":"exposedInternalTypes.js","sourceRoot":"","sources":["../src/exposedInternalTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH;;;;;;GAMG;AACH,2DAA2D;AAC3D,MAAM,KAAW,aAAa,CA2G7B;AA3GD,WAAiB,aAAa;AA2G9B,CAAC,EA3GgB,aAAa,KAAb,aAAa,QA2G7B","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type {\n\tJsonDeserialized,\n\tJsonSerializable,\n} from \"@fluidframework/presence/internal/core-interfaces\";\n\n/**\n * Collection of value types that are not intended to be used/imported\n * directly outside of this package.\n *\n * @alpha\n * @system\n */\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport namespace InternalTypes {\n\t/**\n\t * @system\n\t */\n\texport interface ValueStateMetadata {\n\t\trev: number;\n\t\ttimestamp: number;\n\t}\n\n\t/**\n\t * @system\n\t */\n\texport interface ValueOptionalState<TValue> extends ValueStateMetadata {\n\t\tvalue?: JsonDeserialized<TValue>;\n\t}\n\n\t/**\n\t * @system\n\t */\n\texport interface ValueRequiredState<TValue> extends ValueStateMetadata {\n\t\tvalue: JsonDeserialized<TValue>;\n\t}\n\n\t/**\n\t * @system\n\t */\n\texport interface ValueDirectory<T> {\n\t\trev: number;\n\t\titems: {\n\t\t\t// Caution: any particular item may or may not exist\n\t\t\t// Typescript does not support absent keys without forcing type to also be undefined.\n\t\t\t// See https://github.com/microsoft/TypeScript/issues/42810.\n\t\t\t[name: string | number]: ValueOptionalState<T> | ValueDirectory<T>;\n\t\t};\n\t}\n\n\t/**\n\t * @system\n\t */\n\texport type ValueDirectoryOrState<T> = ValueRequiredState<T> | ValueDirectory<T>;\n\n\t/**\n\t * @system\n\t */\n\texport interface MapValueState<T, Keys extends string | number> {\n\t\trev: number;\n\t\titems: {\n\t\t\t// Caution: any particular item may or may not exist\n\t\t\t// Typescript does not support absent keys without forcing type to also be undefined.\n\t\t\t// See https://github.com/microsoft/TypeScript/issues/42810.\n\t\t\t[name in Keys]: ValueOptionalState<T>;\n\t\t};\n\t}\n\n\t/**\n\t * @system\n\t */\n\texport declare class StateDatastoreHandle<TKey, TValue extends ValueDirectoryOrState<any>> {\n\t\tprivate readonly StateDatastoreHandle: StateDatastoreHandle<TKey, TValue>;\n\t}\n\n\t/**\n\t * Brand to ensure state values internal type safety without revealing\n\t * internals that are subject to change.\n\t *\n\t * @system\n\t */\n\texport declare class StateValueBrand<T> {\n\t\tprivate readonly StateValue: StateValue<T>;\n\t}\n\n\t/**\n\t * This type provides no additional functionality over the type it wraps.\n\t * It is used to ensure type safety within package.\n\t * Users may find it convenient to just use the type it wraps directly.\n\t *\n\t * @privateRemarks\n\t * Checkout filtering omitting unknown from T (`Omit<T,unknown> &`).\n\t *\n\t * @system\n\t */\n\texport type StateValue<T> = T & StateValueBrand<T>;\n\n\t/**\n\t * Package internal function declaration for value manager instantiation.\n\t *\n\t * @system\n\t */\n\texport type ManagerFactory<\n\t\tTKey extends string,\n\t\tTValue extends ValueDirectoryOrState<any>,\n\t\tTManager,\n\t> = { instanceBase: new (...args: any[]) => any } & ((\n\t\tkey: TKey,\n\t\tdatastoreHandle: StateDatastoreHandle<TKey, TValue>,\n\t) => {\n\t\tinitialData?: { value: TValue; allowableUpdateLatencyMs: number | undefined };\n\t\tmanager: StateValue<TManager>;\n\t});\n\n\t/**\n\t * @system\n\t */\n\texport interface NotificationType {\n\t\tname: string;\n\t\targs: (JsonSerializable<unknown> & JsonDeserialized<unknown>)[];\n\t}\n}\n"]}
|
package/lib/internalTypes.d.ts
CHANGED
|
@@ -13,12 +13,6 @@ import type { IRuntimeInternal } from "@fluidframework/presence/internal/contain
|
|
|
13
13
|
export interface ClientRecord<TValue extends InternalTypes.ValueDirectoryOrState<unknown>> {
|
|
14
14
|
[ClientSessionId: ClientSessionId]: TValue;
|
|
15
15
|
}
|
|
16
|
-
/**
|
|
17
|
-
* Object.entries retyped to support branded string-based keys.
|
|
18
|
-
*
|
|
19
|
-
* @internal
|
|
20
|
-
*/
|
|
21
|
-
export declare const brandedObjectEntries: <K extends string, T>(o: Record<K, T>) => [K, T][];
|
|
22
16
|
/**
|
|
23
17
|
* This interface is a subset of (IContainerRuntime & IRuntimeInternal) and
|
|
24
18
|
* (IFluidDataStoreRuntime) that is needed by the Presence States.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internalTypes.d.ts","sourceRoot":"","sources":["../src/internalTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE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C,CAAC;AAEjD;;GAEG;AACH,MAAM,WAAW,YAAY,CAC5B,MAAM,EACN,WAAW,SACV,aAAa,CAAC,qBAAqB,CAAC,MAAM,CAAC,GAAG,aAAa,CAAC,qBAAqB,CAAC,MAAM,CAAC;IAG1F,QAAQ,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC;IAC7B,MAAM,CAAC,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,IAAI,CAAC;CAC3E"}
|
package/lib/internalTypes.js
CHANGED
|
@@ -2,10 +2,5 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
* Object.entries retyped to support branded string-based keys.
|
|
7
|
-
*
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
export const brandedObjectEntries = Object.entries;
|
|
5
|
+
export {};
|
|
11
6
|
//# sourceMappingURL=internalTypes.js.map
|
package/lib/internalTypes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internalTypes.js","sourceRoot":"","sources":["../src/internalTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG
|
|
1
|
+
{"version":3,"file":"internalTypes.js","sourceRoot":"","sources":["../src/internalTypes.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 { IContainerRuntime } from \"@fluidframework/container-runtime-definitions/internal\";\nimport type { IFluidDataStoreRuntime } from \"@fluidframework/datastore-definitions/internal\";\n\nimport type { InternalTypes } from \"./exposedInternalTypes.js\";\nimport type { ClientSessionId, ISessionClient } from \"./presence.js\";\n\nimport type { IRuntimeInternal } from \"@fluidframework/presence/internal/container-definitions/internal\";\n\n/**\n * @internal\n */\nexport interface ClientRecord<TValue extends InternalTypes.ValueDirectoryOrState<unknown>> {\n\t// Caution: any particular item may or may not exist\n\t// Typescript does not support absent keys without forcing type to also be undefined.\n\t// See https://github.com/microsoft/TypeScript/issues/42810.\n\t[ClientSessionId: ClientSessionId]: TValue;\n}\n\n/**\n * This interface is a subset of (IContainerRuntime & IRuntimeInternal) and\n * (IFluidDataStoreRuntime) that is needed by the Presence States.\n *\n * @privateRemarks\n * Replace with non-DataStore based interface.\n *\n * @internal\n */\nexport type IEphemeralRuntime = Pick<\n\t(IContainerRuntime & IRuntimeInternal) | IFluidDataStoreRuntime,\n\t\"clientId\" | \"connected\" | \"getAudience\" | \"getQuorum\" | \"off\" | \"on\" | \"submitSignal\"\n> &\n\tPartial<Pick<IFluidDataStoreRuntime, \"logger\">>;\n\n/**\n * @internal\n */\nexport interface ValueManager<\n\tTValue,\n\tTValueState extends\n\t\tInternalTypes.ValueDirectoryOrState<TValue> = InternalTypes.ValueDirectoryOrState<TValue>,\n> {\n\t// Most value managers should provide value - implement Required<ValueManager<...>>\n\treadonly value?: TValueState;\n\tupdate(client: ISessionClient, received: number, value: TValueState): void;\n}\n"]}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Returns union of types of values in a record.
|
|
7
|
+
*/
|
|
8
|
+
export type RecordEntryTypes<T> = T[keyof T];
|
|
9
|
+
type MapNumberIndicesToStrings<T> = {
|
|
10
|
+
[K in keyof T as K extends number ? `${K}` : K]: T[K];
|
|
11
|
+
};
|
|
12
|
+
type KeyValuePairs<T> = {
|
|
13
|
+
[K in keyof MapNumberIndicesToStrings<Required<T>>]: [K, Required<T>[K]];
|
|
14
|
+
}[keyof MapNumberIndicesToStrings<Required<T>>][];
|
|
15
|
+
type RequiredAndNotUndefined<T> = {
|
|
16
|
+
[K in keyof T]-?: Exclude<T[K], undefined>;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Object.entries retyped to preserve known keys and their types.
|
|
20
|
+
*
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export declare const objectEntries: <T>(o: T) => KeyValuePairs<T>;
|
|
24
|
+
/**
|
|
25
|
+
* Object.entries retyped to preserve known keys and their types.
|
|
26
|
+
*
|
|
27
|
+
* @remarks
|
|
28
|
+
* Given `T` should not contain `undefined` values. If it does, use
|
|
29
|
+
* {@link objectEntries} instead. Without `undefined` values, this
|
|
30
|
+
* typing provides best handling of objects with optional properties.
|
|
31
|
+
*
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
export declare const objectEntriesWithoutUndefined: <T>(o: T) => KeyValuePairs<RequiredAndNotUndefined<T>>;
|
|
35
|
+
/**
|
|
36
|
+
* Object.keys retyped to preserve known keys and their types.
|
|
37
|
+
*
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
export declare const objectKeys: <T>(o: T) => (keyof MapNumberIndicesToStrings<T>)[];
|
|
41
|
+
/**
|
|
42
|
+
* Retrieve a value from a record with the given key, or create a new entry if
|
|
43
|
+
* the key is not in the record.
|
|
44
|
+
*
|
|
45
|
+
* @param record - The record to index/update
|
|
46
|
+
* @param key - The key to lookup in the record
|
|
47
|
+
* @param defaultValue - a function which returns a default value. This is
|
|
48
|
+
* called and used to set an initial value for the given key in the record if
|
|
49
|
+
* none exists.
|
|
50
|
+
* @returns either the existing value for the given key, or the newly-created
|
|
51
|
+
* value (the result of `defaultValue`)
|
|
52
|
+
*/
|
|
53
|
+
export declare function getOrCreateRecord<K extends string | number | symbol, V>(record: Record<K, V>, key: K, defaultValue: (key: K) => V): V;
|
|
54
|
+
export {};
|
|
55
|
+
//# sourceMappingURL=internalUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internalUtils.d.ts","sourceRoot":"","sources":["../src/internalUtils.ts"],"names":[],"mappings":"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CAAC,CAKH"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Object.entries retyped to preserve known keys and their types.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export const objectEntries = Object.entries;
|
|
11
|
+
/**
|
|
12
|
+
* Object.entries retyped to preserve known keys and their types.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* Given `T` should not contain `undefined` values. If it does, use
|
|
16
|
+
* {@link objectEntries} instead. Without `undefined` values, this
|
|
17
|
+
* typing provides best handling of objects with optional properties.
|
|
18
|
+
*
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
export const objectEntriesWithoutUndefined = Object.entries;
|
|
22
|
+
/**
|
|
23
|
+
* Object.keys retyped to preserve known keys and their types.
|
|
24
|
+
*
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
export const objectKeys = Object.keys;
|
|
28
|
+
/**
|
|
29
|
+
* Retrieve a value from a record with the given key, or create a new entry if
|
|
30
|
+
* the key is not in the record.
|
|
31
|
+
*
|
|
32
|
+
* @param record - The record to index/update
|
|
33
|
+
* @param key - The key to lookup in the record
|
|
34
|
+
* @param defaultValue - a function which returns a default value. This is
|
|
35
|
+
* called and used to set an initial value for the given key in the record if
|
|
36
|
+
* none exists.
|
|
37
|
+
* @returns either the existing value for the given key, or the newly-created
|
|
38
|
+
* value (the result of `defaultValue`)
|
|
39
|
+
*/
|
|
40
|
+
export function getOrCreateRecord(record, key, defaultValue) {
|
|
41
|
+
if (!(key in record)) {
|
|
42
|
+
record[key] = defaultValue(key);
|
|
43
|
+
}
|
|
44
|
+
return record[key];
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=internalUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internalUtils.js","sourceRoot":"","sources":["../src/internalUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAmBH;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,OAAwC,CAAC;AAE7E;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,MAAM,CAAC,OAEN,CAAC;AAE/C;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,IAA2D,CAAC;AAE7F;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,iBAAiB,CAChC,MAAoB,EACpB,GAAM,EACN,YAA2B;IAE3B,IAAI,CAAC,CAAC,GAAG,IAAI,MAAM,CAAC,EAAE,CAAC;QACtB,MAAM,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;IACD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;AACpB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Returns union of types of values in a record.\n */\nexport type RecordEntryTypes<T> = T[keyof T];\n\ntype MapNumberIndicesToStrings<T> = {\n\t[K in keyof T as K extends number ? `${K}` : K]: T[K];\n};\n\ntype KeyValuePairs<T> = {\n\t[K in keyof MapNumberIndicesToStrings<Required<T>>]: [K, Required<T>[K]];\n}[keyof MapNumberIndicesToStrings<Required<T>>][];\n\ntype RequiredAndNotUndefined<T> = {\n\t[K in keyof T]-?: Exclude<T[K], undefined>;\n};\n\n/**\n * Object.entries retyped to preserve known keys and their types.\n *\n * @internal\n */\nexport const objectEntries = Object.entries as <T>(o: T) => KeyValuePairs<T>;\n\n/**\n * Object.entries retyped to preserve known keys and their types.\n *\n * @remarks\n * Given `T` should not contain `undefined` values. If it does, use\n * {@link objectEntries} instead. Without `undefined` values, this\n * typing provides best handling of objects with optional properties.\n *\n * @internal\n */\nexport const objectEntriesWithoutUndefined = Object.entries as <T>(\n\to: T,\n) => KeyValuePairs<RequiredAndNotUndefined<T>>;\n\n/**\n * Object.keys retyped to preserve known keys and their types.\n *\n * @internal\n */\nexport const objectKeys = Object.keys as <T>(o: T) => (keyof MapNumberIndicesToStrings<T>)[];\n\n/**\n * Retrieve a value from a record with the given key, or create a new entry if\n * the key is not in the record.\n *\n * @param record - The record to index/update\n * @param key - The key to lookup in the record\n * @param defaultValue - a function which returns a default value. This is\n * called and used to set an initial value for the given key in the record if\n * none exists.\n * @returns either the existing value for the given key, or the newly-created\n * value (the result of `defaultValue`)\n */\nexport function getOrCreateRecord<K extends string | number | symbol, V>(\n\trecord: Record<K, V>,\n\tkey: K,\n\tdefaultValue: (key: K) => V,\n): V {\n\tif (!(key in record)) {\n\t\trecord[key] = defaultValue(key);\n\t}\n\treturn record[key];\n}\n"]}
|
|
@@ -178,5 +178,5 @@ export interface LatestMapValueManager<T, Keys extends string | number = string
|
|
|
178
178
|
*/
|
|
179
179
|
export declare function LatestMap<T extends object, Keys extends string | number = string | number, RegistrationKey extends string = string>(initialValues?: {
|
|
180
180
|
[K in Keys]: JsonSerializable<T> & JsonDeserialized<T>;
|
|
181
|
-
}, controls?: BroadcastControlSettings): InternalTypes.ManagerFactory<RegistrationKey, InternalTypes.MapValueState<T>, LatestMapValueManager<T, Keys>>;
|
|
181
|
+
}, controls?: BroadcastControlSettings): InternalTypes.ManagerFactory<RegistrationKey, InternalTypes.MapValueState<T, Keys>, LatestMapValueManager<T, Keys>>;
|
|
182
182
|
//# sourceMappingURL=latestMapValueManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"latestMapValueManager.d.ts","sourceRoot":"","sources":["../src/latestMapValueManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAElE,OAAO,KAAK,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,wBA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@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { createEmitter } from "@fluid-internal/client-utils";
|
|
6
6
|
import { OptionalBroadcastControl } from "./broadcastControls.js";
|
|
7
|
+
import { objectEntries, objectKeys } from "./internalUtils.js";
|
|
7
8
|
import { datastoreFromHandle } from "./stateDatastore.js";
|
|
8
9
|
import { brandIVM } from "./valueManager.js";
|
|
9
10
|
class ValueMapImpl {
|
|
@@ -14,8 +15,13 @@ class ValueMapImpl {
|
|
|
14
15
|
// TODO assert all defined and/or update type.
|
|
15
16
|
this.countDefined = Object.keys(value.items).length;
|
|
16
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Note: caller must ensure key exists in this.value.items.
|
|
20
|
+
*/
|
|
17
21
|
updateItem(key, value) {
|
|
18
22
|
this.value.rev += 1;
|
|
23
|
+
// Caller is required to ensure key exists.
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
19
25
|
const item = this.value.items[key];
|
|
20
26
|
item.rev += 1;
|
|
21
27
|
item.timestamp = Date.now();
|
|
@@ -41,9 +47,8 @@ class ValueMapImpl {
|
|
|
41
47
|
return hasKey;
|
|
42
48
|
}
|
|
43
49
|
forEach(callbackfn, thisArg) {
|
|
44
|
-
for (const [key, item] of
|
|
50
|
+
for (const [key, item] of objectEntries(this.value.items)) {
|
|
45
51
|
if (item.value !== undefined) {
|
|
46
|
-
// TODO: see about typing InternalTypes.MapValueState with K
|
|
47
52
|
callbackfn(item.value, key, this);
|
|
48
53
|
}
|
|
49
54
|
}
|
|
@@ -67,7 +72,7 @@ class ValueMapImpl {
|
|
|
67
72
|
}
|
|
68
73
|
keys() {
|
|
69
74
|
const keys = [];
|
|
70
|
-
for (const [key, item] of
|
|
75
|
+
for (const [key, item] of objectEntries(this.value.items)) {
|
|
71
76
|
if (item.value !== undefined) {
|
|
72
77
|
keys.push(key);
|
|
73
78
|
}
|
|
@@ -90,7 +95,7 @@ class LatestMapValueManagerImpl {
|
|
|
90
95
|
}
|
|
91
96
|
*clientValues() {
|
|
92
97
|
const allKnownStates = this.datastore.knownValues(this.key);
|
|
93
|
-
for (const clientSessionId of
|
|
98
|
+
for (const clientSessionId of objectKeys(allKnownStates.states)) {
|
|
94
99
|
if (clientSessionId !== allKnownStates.self) {
|
|
95
100
|
const client = this.datastore.lookupClient(clientSessionId);
|
|
96
101
|
const items = this.clientValue(client);
|
|
@@ -100,19 +105,19 @@ class LatestMapValueManagerImpl {
|
|
|
100
105
|
}
|
|
101
106
|
clients() {
|
|
102
107
|
const allKnownStates = this.datastore.knownValues(this.key);
|
|
103
|
-
return
|
|
108
|
+
return objectKeys(allKnownStates.states)
|
|
104
109
|
.filter((clientSessionId) => clientSessionId !== allKnownStates.self)
|
|
105
110
|
.map((clientSessionId) => this.datastore.lookupClient(clientSessionId));
|
|
106
111
|
}
|
|
107
112
|
clientValue(client) {
|
|
108
113
|
const allKnownStates = this.datastore.knownValues(this.key);
|
|
109
114
|
const clientSessionId = client.sessionId;
|
|
110
|
-
|
|
115
|
+
const clientStateMap = allKnownStates.states[clientSessionId];
|
|
116
|
+
if (clientStateMap === undefined) {
|
|
111
117
|
throw new Error("No entry for client");
|
|
112
118
|
}
|
|
113
|
-
const clientStateMap = allKnownStates.states[clientSessionId];
|
|
114
119
|
const items = new Map();
|
|
115
|
-
for (const [key, item] of
|
|
120
|
+
for (const [key, item] of objectEntries(clientStateMap.items)) {
|
|
116
121
|
const value = item.value;
|
|
117
122
|
if (value !== undefined) {
|
|
118
123
|
items.set(key, {
|
|
@@ -124,18 +129,22 @@ class LatestMapValueManagerImpl {
|
|
|
124
129
|
return items;
|
|
125
130
|
}
|
|
126
131
|
update(client, _received, value) {
|
|
132
|
+
var _a;
|
|
127
133
|
const allKnownStates = this.datastore.knownValues(this.key);
|
|
128
134
|
const clientSessionId = client.sessionId;
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
135
|
+
const currentState = ((_a = allKnownStates.states)[clientSessionId] ?? (_a[clientSessionId] =
|
|
136
|
+
// New client - prepare new client state directory
|
|
137
|
+
{
|
|
138
|
+
rev: value.rev,
|
|
139
|
+
items: {},
|
|
140
|
+
}));
|
|
134
141
|
// Accumulate individual update keys
|
|
135
142
|
const updatedItemKeys = [];
|
|
136
|
-
for (const [key, item] of
|
|
137
|
-
|
|
138
|
-
|
|
143
|
+
for (const [key, item] of objectEntries(value.items)) {
|
|
144
|
+
// TODO: Key validation needs to be added here.
|
|
145
|
+
const validKey = key;
|
|
146
|
+
if (!(key in currentState.items) || currentState.items[validKey].rev < item.rev) {
|
|
147
|
+
updatedItemKeys.push(validKey);
|
|
139
148
|
}
|
|
140
149
|
}
|
|
141
150
|
if (updatedItemKeys.length === 0) {
|
|
@@ -150,6 +159,7 @@ class LatestMapValueManagerImpl {
|
|
|
150
159
|
items: new Map(),
|
|
151
160
|
};
|
|
152
161
|
for (const key of updatedItemKeys) {
|
|
162
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
153
163
|
const item = value.items[key];
|
|
154
164
|
const hadPriorValue = currentState.items[key]?.value;
|
|
155
165
|
currentState.items[key] = item;
|
|
@@ -185,7 +195,7 @@ export function LatestMap(initialValues, controls) {
|
|
|
185
195
|
const value = { rev: 0, items: {} };
|
|
186
196
|
// LatestMapValueManager takes ownership of values within initialValues.
|
|
187
197
|
if (initialValues !== undefined) {
|
|
188
|
-
for (const key of
|
|
198
|
+
for (const key of objectKeys(initialValues)) {
|
|
189
199
|
value.items[key] = { rev: 0, timestamp, value: initialValues[key] };
|
|
190
200
|
}
|
|
191
201
|
}
|