@fluidframework/container-loader 2.0.0-dev-rc.5.0.0.268409 → 2.0.0-dev-rc.5.0.0.270987
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/api-report/container-loader.alpha.api.md +59 -4
- package/api-report/container-loader.beta.api.md +7 -3
- package/api-report/container-loader.public.api.md +7 -3
- package/biome.jsonc +4 -0
- package/dist/audience.js +2 -1
- package/dist/audience.js.map +1 -1
- package/dist/catchUpMonitor.js +11 -8
- package/dist/catchUpMonitor.js.map +1 -1
- package/dist/connectionManager.d.ts +2 -2
- package/dist/connectionManager.d.ts.map +1 -1
- package/dist/connectionManager.js +91 -63
- package/dist/connectionManager.js.map +1 -1
- package/dist/connectionStateHandler.js +35 -11
- package/dist/connectionStateHandler.js.map +1 -1
- package/dist/container.d.ts +3 -2
- package/dist/container.d.ts.map +1 -1
- package/dist/container.js +162 -126
- package/dist/container.js.map +1 -1
- package/dist/containerContext.d.ts +2 -2
- package/dist/containerContext.d.ts.map +1 -1
- package/dist/containerContext.js +34 -8
- package/dist/containerContext.js.map +1 -1
- package/dist/containerStorageAdapter.js +17 -9
- package/dist/containerStorageAdapter.js.map +1 -1
- package/dist/contracts.d.ts +2 -2
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js.map +1 -1
- package/dist/debugLogger.js +2 -0
- package/dist/debugLogger.js.map +1 -1
- package/dist/deltaManager.d.ts +2 -2
- package/dist/deltaManager.d.ts.map +1 -1
- package/dist/deltaManager.js +48 -35
- package/dist/deltaManager.js.map +1 -1
- package/dist/deltaQueue.js +14 -7
- package/dist/deltaQueue.js.map +1 -1
- package/dist/error.js +5 -4
- package/dist/error.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/legacy.d.ts +5 -0
- package/dist/loader.js +5 -1
- package/dist/loader.js.map +1 -1
- package/dist/noopHeuristic.d.ts +1 -1
- package/dist/noopHeuristic.d.ts.map +1 -1
- package/dist/noopHeuristic.js +3 -1
- package/dist/noopHeuristic.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/protocol/index.d.ts +7 -0
- package/dist/protocol/index.d.ts.map +1 -0
- package/dist/protocol/index.js +12 -0
- package/dist/protocol/index.js.map +1 -0
- package/dist/protocol/protocol.d.ts +52 -0
- package/dist/protocol/protocol.d.ts.map +1 -0
- package/dist/protocol/protocol.js +115 -0
- package/dist/protocol/protocol.js.map +1 -0
- package/dist/protocol/quorum.d.ts +185 -0
- package/dist/protocol/quorum.d.ts.map +1 -0
- package/dist/protocol/quorum.js +440 -0
- package/dist/protocol/quorum.js.map +1 -0
- package/dist/protocol.d.ts +2 -3
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +4 -2
- package/dist/protocol.js.map +1 -1
- package/dist/protocolTreeDocumentStorageService.d.ts +7 -7
- package/dist/protocolTreeDocumentStorageService.d.ts.map +1 -1
- package/dist/protocolTreeDocumentStorageService.js +16 -7
- package/dist/protocolTreeDocumentStorageService.js.map +1 -1
- package/dist/retriableDocumentStorageService.js +4 -1
- package/dist/retriableDocumentStorageService.js.map +1 -1
- package/dist/serializedStateManager.d.ts +5 -3
- package/dist/serializedStateManager.d.ts.map +1 -1
- package/dist/serializedStateManager.js +26 -5
- package/dist/serializedStateManager.js.map +1 -1
- package/lib/audience.js +2 -1
- package/lib/audience.js.map +1 -1
- package/lib/catchUpMonitor.js +11 -8
- package/lib/catchUpMonitor.js.map +1 -1
- package/lib/connectionManager.d.ts +2 -2
- package/lib/connectionManager.d.ts.map +1 -1
- package/lib/connectionManager.js +91 -63
- package/lib/connectionManager.js.map +1 -1
- package/lib/connectionStateHandler.js +35 -11
- package/lib/connectionStateHandler.js.map +1 -1
- package/lib/container.d.ts +3 -2
- package/lib/container.d.ts.map +1 -1
- package/lib/container.js +162 -126
- package/lib/container.js.map +1 -1
- package/lib/containerContext.d.ts +2 -2
- package/lib/containerContext.d.ts.map +1 -1
- package/lib/containerContext.js +34 -8
- package/lib/containerContext.js.map +1 -1
- package/lib/containerStorageAdapter.js +17 -9
- package/lib/containerStorageAdapter.js.map +1 -1
- package/lib/contracts.d.ts +2 -2
- package/lib/contracts.d.ts.map +1 -1
- package/lib/contracts.js.map +1 -1
- package/lib/debugLogger.js +2 -0
- package/lib/debugLogger.js.map +1 -1
- package/lib/deltaManager.d.ts +2 -2
- package/lib/deltaManager.d.ts.map +1 -1
- package/lib/deltaManager.js +48 -35
- package/lib/deltaManager.js.map +1 -1
- package/lib/deltaQueue.js +14 -7
- package/lib/deltaQueue.js.map +1 -1
- package/lib/error.js +5 -4
- package/lib/error.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/legacy.d.ts +5 -0
- package/lib/loader.js +5 -1
- package/lib/loader.js.map +1 -1
- package/lib/noopHeuristic.d.ts +1 -1
- package/lib/noopHeuristic.d.ts.map +1 -1
- package/lib/noopHeuristic.js +3 -1
- package/lib/noopHeuristic.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/protocol/index.d.ts +7 -0
- package/lib/protocol/index.d.ts.map +1 -0
- package/lib/protocol/index.js +7 -0
- package/lib/protocol/index.js.map +1 -0
- package/lib/protocol/protocol.d.ts +52 -0
- package/lib/protocol/protocol.d.ts.map +1 -0
- package/lib/protocol/protocol.js +111 -0
- package/lib/protocol/protocol.js.map +1 -0
- package/lib/protocol/quorum.d.ts +185 -0
- package/lib/protocol/quorum.d.ts.map +1 -0
- package/lib/protocol/quorum.js +431 -0
- package/lib/protocol/quorum.js.map +1 -0
- package/lib/protocol.d.ts +2 -3
- package/lib/protocol.d.ts.map +1 -1
- package/lib/protocol.js +3 -1
- package/lib/protocol.js.map +1 -1
- package/lib/protocolTreeDocumentStorageService.d.ts +7 -7
- package/lib/protocolTreeDocumentStorageService.d.ts.map +1 -1
- package/lib/protocolTreeDocumentStorageService.js +16 -7
- package/lib/protocolTreeDocumentStorageService.js.map +1 -1
- package/lib/retriableDocumentStorageService.js +4 -1
- package/lib/retriableDocumentStorageService.js.map +1 -1
- package/lib/serializedStateManager.d.ts +5 -3
- package/lib/serializedStateManager.d.ts.map +1 -1
- package/lib/serializedStateManager.js +26 -5
- package/lib/serializedStateManager.js.map +1 -1
- package/package.json +19 -14
- package/src/catchUpMonitor.ts +1 -1
- package/src/connectionManager.ts +3 -7
- package/src/container.ts +16 -9
- package/src/containerContext.ts +2 -5
- package/src/contracts.ts +3 -6
- package/src/deltaManager.ts +3 -5
- package/src/index.ts +7 -0
- package/src/noopHeuristic.ts +1 -1
- package/src/packageVersion.ts +1 -1
- package/src/protocol/README.md +10 -0
- package/src/protocol/index.ts +16 -0
- package/src/protocol/protocol.ts +185 -0
- package/src/protocol/quorum.ts +584 -0
- package/src/protocol.ts +4 -6
- package/src/protocolTreeDocumentStorageService.ts +16 -8
- package/src/serializedStateManager.ts +25 -4
- package/tsconfig.json +2 -0
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.Quorum = exports.QuorumProposals = exports.QuorumClients = void 0;
|
|
11
|
+
const client_utils_1 = require("@fluid-internal/client-utils");
|
|
12
|
+
const internal_1 = require("@fluidframework/core-utils/internal");
|
|
13
|
+
const events_pkg_1 = __importDefault(require("events_pkg"));
|
|
14
|
+
const { EventEmitter } = events_pkg_1.default;
|
|
15
|
+
/**
|
|
16
|
+
* Structure for tracking proposals that have been sequenced but not approved yet.
|
|
17
|
+
*/
|
|
18
|
+
class PendingProposal {
|
|
19
|
+
sequenceNumber;
|
|
20
|
+
key;
|
|
21
|
+
value;
|
|
22
|
+
local;
|
|
23
|
+
constructor(sequenceNumber, key, value, local) {
|
|
24
|
+
this.sequenceNumber = sequenceNumber;
|
|
25
|
+
this.key = key;
|
|
26
|
+
this.value = value;
|
|
27
|
+
this.local = local;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The QuorumClients is used to track members joining and leaving the collaboration session.
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
class QuorumClients extends client_utils_1.TypedEventEmitter {
|
|
35
|
+
members;
|
|
36
|
+
isDisposed = false;
|
|
37
|
+
get disposed() {
|
|
38
|
+
return this.isDisposed;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Cached snapshot state, to avoid unnecessary deep clones on repeated snapshot calls.
|
|
42
|
+
* Cleared immediately (set to undefined) when the cache becomes invalid.
|
|
43
|
+
*/
|
|
44
|
+
snapshotCache;
|
|
45
|
+
constructor(snapshot) {
|
|
46
|
+
super();
|
|
47
|
+
this.members = new Map(snapshot);
|
|
48
|
+
this.snapshotCache = snapshot;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Snapshots the current state of the QuorumClients
|
|
52
|
+
* @returns a snapshot of the clients in the quorum
|
|
53
|
+
*/
|
|
54
|
+
snapshot() {
|
|
55
|
+
this.snapshotCache ??= Array.from(this.members);
|
|
56
|
+
return this.snapshotCache;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Adds a new client to the quorum
|
|
60
|
+
*/
|
|
61
|
+
addMember(clientId, details) {
|
|
62
|
+
(0, internal_1.assert)(!!clientId, "clientId has to be non-empty string");
|
|
63
|
+
(0, internal_1.assert)(!this.members.has(clientId), "clientId not found");
|
|
64
|
+
this.members.set(clientId, details);
|
|
65
|
+
this.emit("addMember", clientId, details);
|
|
66
|
+
// clear the cache
|
|
67
|
+
this.snapshotCache = undefined;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Removes a client from the quorum
|
|
71
|
+
*/
|
|
72
|
+
removeMember(clientId) {
|
|
73
|
+
(0, internal_1.assert)(!!clientId, "clientId has to be non-empty string");
|
|
74
|
+
(0, internal_1.assert)(this.members.has(clientId), "clientId not found");
|
|
75
|
+
this.members.delete(clientId);
|
|
76
|
+
this.emit("removeMember", clientId);
|
|
77
|
+
// clear the cache
|
|
78
|
+
this.snapshotCache = undefined;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Retrieves all the members in the quorum
|
|
82
|
+
*/
|
|
83
|
+
getMembers() {
|
|
84
|
+
return new Map(this.members);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Retrieves a specific member of the quorum
|
|
88
|
+
*/
|
|
89
|
+
getMember(clientId) {
|
|
90
|
+
return this.members.get(clientId);
|
|
91
|
+
}
|
|
92
|
+
dispose() {
|
|
93
|
+
this.isDisposed = true;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.QuorumClients = QuorumClients;
|
|
97
|
+
/**
|
|
98
|
+
* The QuorumProposals holds a key/value store. Proposed values become finalized in the store once all connected
|
|
99
|
+
* clients have seen the proposal.
|
|
100
|
+
* @internal
|
|
101
|
+
*/
|
|
102
|
+
class QuorumProposals extends client_utils_1.TypedEventEmitter {
|
|
103
|
+
sendProposal;
|
|
104
|
+
proposals;
|
|
105
|
+
values;
|
|
106
|
+
isDisposed = false;
|
|
107
|
+
get disposed() {
|
|
108
|
+
return this.isDisposed;
|
|
109
|
+
}
|
|
110
|
+
// Event emitter for changes to the environment that affect pending proposal promises.
|
|
111
|
+
stateEvents = new EventEmitter();
|
|
112
|
+
/**
|
|
113
|
+
* Cached snapshot state, to avoid unnecessary deep clones on repeated snapshot calls.
|
|
114
|
+
* Cleared immediately (set to undefined) when the cache becomes invalid.
|
|
115
|
+
*/
|
|
116
|
+
proposalsSnapshotCache;
|
|
117
|
+
valuesSnapshotCache;
|
|
118
|
+
constructor(snapshot, sendProposal) {
|
|
119
|
+
super();
|
|
120
|
+
this.sendProposal = sendProposal;
|
|
121
|
+
this.proposals = new Map(snapshot.proposals.map(([, proposal]) => {
|
|
122
|
+
return [
|
|
123
|
+
proposal.sequenceNumber,
|
|
124
|
+
new PendingProposal(proposal.sequenceNumber, proposal.key, proposal.value, false),
|
|
125
|
+
];
|
|
126
|
+
}));
|
|
127
|
+
this.values = new Map(snapshot.values);
|
|
128
|
+
this.proposalsSnapshotCache = snapshot.proposals;
|
|
129
|
+
this.valuesSnapshotCache = snapshot.values;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Snapshots the current state of the QuorumProposals
|
|
133
|
+
* @returns arrays of proposals and values
|
|
134
|
+
*/
|
|
135
|
+
snapshot() {
|
|
136
|
+
this.proposalsSnapshotCache ??= Array.from(this.proposals).map(([sequenceNumber, proposal]) => [
|
|
137
|
+
sequenceNumber,
|
|
138
|
+
{ sequenceNumber, key: proposal.key, value: proposal.value },
|
|
139
|
+
[], // rejections, which has been removed
|
|
140
|
+
]);
|
|
141
|
+
this.valuesSnapshotCache ??= Array.from(this.values);
|
|
142
|
+
return {
|
|
143
|
+
proposals: this.proposalsSnapshotCache,
|
|
144
|
+
values: this.valuesSnapshotCache,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Returns whether the quorum has achieved a consensus for the given key.
|
|
149
|
+
*/
|
|
150
|
+
has(key) {
|
|
151
|
+
return this.values.has(key);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Returns the consensus value for the given key
|
|
155
|
+
*/
|
|
156
|
+
get(key) {
|
|
157
|
+
return this.values.get(key)?.value;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Returns additional data about the approved consensus value
|
|
161
|
+
* @deprecated Removed in recent protocol-definitions. Use get() instead.
|
|
162
|
+
*/
|
|
163
|
+
getApprovalData(key) {
|
|
164
|
+
return this.values.get(key);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Proposes a new value. Returns a promise that will either:
|
|
168
|
+
* - Resolve when the proposal is accepted
|
|
169
|
+
* - Reject if the proposal fails to send or if the QuorumProposals is disposed
|
|
170
|
+
*/
|
|
171
|
+
async propose(key, value) {
|
|
172
|
+
const clientSequenceNumber = this.sendProposal(key, value);
|
|
173
|
+
if (clientSequenceNumber < 0) {
|
|
174
|
+
this.emit("error", { eventName: "ProposalInDisconnectedState", key });
|
|
175
|
+
throw new Error("Can't propose in disconnected state");
|
|
176
|
+
}
|
|
177
|
+
return new Promise((resolve, reject) => {
|
|
178
|
+
// The sequence number that our proposal was assigned and went pending.
|
|
179
|
+
// If undefined, then it's not sequenced yet.
|
|
180
|
+
let thisProposalSequenceNumber;
|
|
181
|
+
// A proposal goes through two phases before this promise resolves:
|
|
182
|
+
// 1. Sequencing - waiting for the proposal to be ack'd by the server.
|
|
183
|
+
// 2. Approval - waiting for the proposal to be approved by connected clients.
|
|
184
|
+
const localProposalSequencedHandler = (sequencedCSN, sequenceNumber) => {
|
|
185
|
+
if (sequencedCSN === clientSequenceNumber) {
|
|
186
|
+
thisProposalSequenceNumber = sequenceNumber;
|
|
187
|
+
this.stateEvents.off("localProposalSequenced", localProposalSequencedHandler);
|
|
188
|
+
this.stateEvents.off("disconnected", disconnectedHandler);
|
|
189
|
+
this.stateEvents.on("localProposalApproved", localProposalApprovedHandler);
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
const localProposalApprovedHandler = (sequenceNumber) => {
|
|
193
|
+
// Proposals can be uniquely identified by the sequenceNumber they were assigned.
|
|
194
|
+
if (sequenceNumber === thisProposalSequenceNumber) {
|
|
195
|
+
resolve();
|
|
196
|
+
removeListeners();
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
// There are two error flows we consider: disconnect and disposal.
|
|
200
|
+
// If we get disconnected before the proposal is sequenced, it has one of two possible futures:
|
|
201
|
+
// 1. We reconnect and see the proposal was sequenced in the meantime.
|
|
202
|
+
// -> The promise can still resolve, once it is approved.
|
|
203
|
+
// 2. We reconnect and see the proposal was not sequenced in the meantime, so it will never sequence.
|
|
204
|
+
// -> The promise rejects.
|
|
205
|
+
const disconnectedHandler = () => {
|
|
206
|
+
// If we haven't seen the ack by the time we disconnect, we hope to see it by the time we reconnect.
|
|
207
|
+
if (thisProposalSequenceNumber === undefined) {
|
|
208
|
+
this.stateEvents.once("connected", () => {
|
|
209
|
+
// If we don't see the ack by the time reconnection finishes, it failed to send.
|
|
210
|
+
if (thisProposalSequenceNumber === undefined) {
|
|
211
|
+
reject(new Error("Client disconnected without successfully sending proposal"));
|
|
212
|
+
removeListeners();
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
// If the QuorumProposals is disposed of, we assume something catastrophic has happened
|
|
218
|
+
// All outstanding proposals are considered rejected.
|
|
219
|
+
const disposedHandler = () => {
|
|
220
|
+
reject(new Error("QuorumProposals was disposed"));
|
|
221
|
+
removeListeners();
|
|
222
|
+
};
|
|
223
|
+
// Convenience function to clean up our listeners.
|
|
224
|
+
const removeListeners = () => {
|
|
225
|
+
this.stateEvents.off("localProposalSequenced", localProposalSequencedHandler);
|
|
226
|
+
this.stateEvents.off("localProposalApproved", localProposalApprovedHandler);
|
|
227
|
+
this.stateEvents.off("disconnected", disconnectedHandler);
|
|
228
|
+
this.stateEvents.off("disposed", disposedHandler);
|
|
229
|
+
};
|
|
230
|
+
this.stateEvents.on("localProposalSequenced", localProposalSequencedHandler);
|
|
231
|
+
this.stateEvents.on("disconnected", disconnectedHandler);
|
|
232
|
+
this.stateEvents.on("disposed", disposedHandler);
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Begins tracking a new proposal
|
|
237
|
+
*/
|
|
238
|
+
addProposal(key, value, sequenceNumber, local, clientSequenceNumber) {
|
|
239
|
+
(0, internal_1.assert)(!this.proposals.has(sequenceNumber), "sequenceNumber not found");
|
|
240
|
+
const proposal = new PendingProposal(sequenceNumber, key, value, local);
|
|
241
|
+
this.proposals.set(sequenceNumber, proposal);
|
|
242
|
+
// Legacy event, from rejection support. May still have some use for clients to learn that a proposal is
|
|
243
|
+
// likely to be approved soon.
|
|
244
|
+
this.emit("addProposal", proposal);
|
|
245
|
+
if (local) {
|
|
246
|
+
this.stateEvents.emit("localProposalSequenced", clientSequenceNumber, sequenceNumber);
|
|
247
|
+
}
|
|
248
|
+
// clear the proposal cache
|
|
249
|
+
this.proposalsSnapshotCache = undefined;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Updates the minimum sequence number. If the MSN advances past the sequence number for any proposal then it
|
|
253
|
+
* becomes an approved value.
|
|
254
|
+
*/
|
|
255
|
+
updateMinimumSequenceNumber(message) {
|
|
256
|
+
const msn = message.minimumSequenceNumber;
|
|
257
|
+
// Accept proposals proposals whose sequenceNumber is <= the minimumSequenceNumber
|
|
258
|
+
// Return a sorted list of approved proposals. We sort so that we apply them in their sequence number order
|
|
259
|
+
// TODO this can be optimized if necessary to avoid the linear search+sort
|
|
260
|
+
const completed = [];
|
|
261
|
+
for (const [sequenceNumber, proposal] of this.proposals) {
|
|
262
|
+
if (sequenceNumber <= msn) {
|
|
263
|
+
completed.push(proposal);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
completed.sort((a, b) => a.sequenceNumber - b.sequenceNumber);
|
|
267
|
+
for (const proposal of completed) {
|
|
268
|
+
const committedProposal = {
|
|
269
|
+
approvalSequenceNumber: message.sequenceNumber,
|
|
270
|
+
// No longer used. We still stamp a -1 for compat with older versions of the quorum.
|
|
271
|
+
// Can be removed after 0.1035 and higher is ubiquitous.
|
|
272
|
+
commitSequenceNumber: -1,
|
|
273
|
+
key: proposal.key,
|
|
274
|
+
sequenceNumber: proposal.sequenceNumber,
|
|
275
|
+
value: proposal.value,
|
|
276
|
+
};
|
|
277
|
+
this.values.set(committedProposal.key, committedProposal);
|
|
278
|
+
// clear the values cache
|
|
279
|
+
this.valuesSnapshotCache = undefined;
|
|
280
|
+
// check if there are multiple proposals with matching keys
|
|
281
|
+
let proposalSettled = false;
|
|
282
|
+
let proposalKeySeen = false;
|
|
283
|
+
for (const [, p] of this.proposals) {
|
|
284
|
+
if (p.key === committedProposal.key) {
|
|
285
|
+
if (!proposalKeySeen) {
|
|
286
|
+
// set proposalSettled to true if the proposal key match is unique thus far
|
|
287
|
+
proposalSettled = true;
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
// set proposalSettled to false if matching proposal key is not unique
|
|
291
|
+
proposalSettled = false;
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
proposalKeySeen = true;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
this.emit("approveProposal", committedProposal.sequenceNumber, committedProposal.key, committedProposal.value, committedProposal.approvalSequenceNumber);
|
|
298
|
+
// emit approveProposalComplete when all pending proposals are processed
|
|
299
|
+
if (proposalSettled) {
|
|
300
|
+
this.emit("approveProposalComplete", committedProposal.sequenceNumber, committedProposal.key, committedProposal.value, committedProposal.approvalSequenceNumber);
|
|
301
|
+
}
|
|
302
|
+
this.proposals.delete(proposal.sequenceNumber);
|
|
303
|
+
// clear the proposals cache
|
|
304
|
+
this.proposalsSnapshotCache = undefined;
|
|
305
|
+
if (proposal.local) {
|
|
306
|
+
this.stateEvents.emit("localProposalApproved", proposal.sequenceNumber);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
setConnectionState(connected) {
|
|
311
|
+
if (connected) {
|
|
312
|
+
this.stateEvents.emit("connected");
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
this.stateEvents.emit("disconnected");
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
dispose() {
|
|
319
|
+
this.isDisposed = true;
|
|
320
|
+
this.stateEvents.emit("disposed");
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
exports.QuorumProposals = QuorumProposals;
|
|
324
|
+
/**
|
|
325
|
+
* A quorum represents all clients currently within the collaboration window. As well as the values
|
|
326
|
+
* they have agreed upon and any pending proposals.
|
|
327
|
+
* @internal
|
|
328
|
+
*/
|
|
329
|
+
class Quorum extends client_utils_1.TypedEventEmitter {
|
|
330
|
+
quorumClients;
|
|
331
|
+
quorumProposals;
|
|
332
|
+
isDisposed = false;
|
|
333
|
+
get disposed() {
|
|
334
|
+
return this.isDisposed;
|
|
335
|
+
}
|
|
336
|
+
constructor(members, proposals, values, sendProposal) {
|
|
337
|
+
super();
|
|
338
|
+
this.quorumClients = new QuorumClients(members);
|
|
339
|
+
this.quorumClients.on("addMember", (clientId, details) => {
|
|
340
|
+
this.emit("addMember", clientId, details);
|
|
341
|
+
});
|
|
342
|
+
this.quorumClients.on("removeMember", (clientId) => {
|
|
343
|
+
this.emit("removeMember", clientId);
|
|
344
|
+
});
|
|
345
|
+
this.quorumProposals = new QuorumProposals({ proposals, values }, sendProposal);
|
|
346
|
+
this.quorumProposals.on("addProposal", (proposal) => {
|
|
347
|
+
this.emit("addProposal", proposal);
|
|
348
|
+
});
|
|
349
|
+
this.quorumProposals.on("approveProposal", (sequenceNumber, key, value, approvalSequenceNumber) => {
|
|
350
|
+
this.emit("approveProposal", sequenceNumber, key, value, approvalSequenceNumber);
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
close() {
|
|
354
|
+
this.removeAllListeners();
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Snapshots the entire quorum
|
|
358
|
+
* @returns a quorum snapshot
|
|
359
|
+
*/
|
|
360
|
+
snapshot() {
|
|
361
|
+
const members = this.quorumClients.snapshot();
|
|
362
|
+
const { proposals, values } = this.quorumProposals.snapshot();
|
|
363
|
+
return {
|
|
364
|
+
members,
|
|
365
|
+
proposals,
|
|
366
|
+
values,
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Returns whether the quorum has achieved a consensus for the given key.
|
|
371
|
+
*/
|
|
372
|
+
has(key) {
|
|
373
|
+
return this.quorumProposals.has(key);
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Returns the consensus value for the given key
|
|
377
|
+
*/
|
|
378
|
+
get(key) {
|
|
379
|
+
return this.quorumProposals.get(key);
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Returns additional data about the approved consensus value
|
|
383
|
+
* @deprecated Removed in recent protocol-definitions. Use get() instead.
|
|
384
|
+
*/
|
|
385
|
+
getApprovalData(key) {
|
|
386
|
+
return this.quorumProposals.getApprovalData(key);
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Adds a new client to the quorum
|
|
390
|
+
*/
|
|
391
|
+
addMember(clientId, details) {
|
|
392
|
+
this.quorumClients.addMember(clientId, details);
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Removes a client from the quorum
|
|
396
|
+
*/
|
|
397
|
+
removeMember(clientId) {
|
|
398
|
+
this.quorumClients.removeMember(clientId);
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Retrieves all the members in the quorum
|
|
402
|
+
*/
|
|
403
|
+
getMembers() {
|
|
404
|
+
return this.quorumClients.getMembers();
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Retrieves a specific member of the quorum
|
|
408
|
+
*/
|
|
409
|
+
getMember(clientId) {
|
|
410
|
+
return this.quorumClients.getMember(clientId);
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Proposes a new value. Returns a promise that will resolve when the proposal is either accepted, or reject if
|
|
414
|
+
* the proposal fails to send.
|
|
415
|
+
*/
|
|
416
|
+
async propose(key, value) {
|
|
417
|
+
return this.quorumProposals.propose(key, value);
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Begins tracking a new proposal
|
|
421
|
+
*/
|
|
422
|
+
addProposal(key, value, sequenceNumber, local, clientSequenceNumber) {
|
|
423
|
+
return this.quorumProposals.addProposal(key, value, sequenceNumber, local, clientSequenceNumber);
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Updates the minimum sequence number. If the MSN advances past the sequence number for any proposal then it
|
|
427
|
+
* becomes an approved value.
|
|
428
|
+
*/
|
|
429
|
+
updateMinimumSequenceNumber(message) {
|
|
430
|
+
this.quorumProposals.updateMinimumSequenceNumber(message);
|
|
431
|
+
}
|
|
432
|
+
setConnectionState(connected, clientId) {
|
|
433
|
+
this.quorumProposals.setConnectionState(connected);
|
|
434
|
+
}
|
|
435
|
+
dispose() {
|
|
436
|
+
throw new Error("Not implemented.");
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
exports.Quorum = Quorum;
|
|
440
|
+
//# sourceMappingURL=quorum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quorum.js","sourceRoot":"","sources":["../../src/protocol/quorum.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,+DAAiE;AACjE,kEAA6D;AAS7D,4DAAoC;AACpC,MAAM,EAAE,YAAY,EAAE,GAAG,oBAAU,CAAC;AAEpC;;GAEG;AACH,MAAM,eAAe;IAEH;IACA;IACA;IACA;IAJjB,YACiB,cAAsB,EACtB,GAAW,EACX,KAAU,EACV,KAAc;QAHd,mBAAc,GAAd,cAAc,CAAQ;QACtB,QAAG,GAAH,GAAG,CAAQ;QACX,UAAK,GAAL,KAAK,CAAK;QACV,UAAK,GAAL,KAAK,CAAS;IAC5B,CAAC;CACJ;AA4BD;;;GAGG;AACH,MAAa,aACZ,SAAQ,gCAAuC;IAG9B,OAAO,CAAgC;IAChD,UAAU,GAAY,KAAK,CAAC;IACpC,IAAW,QAAQ;QAClB,OAAO,IAAI,CAAC,UAAU,CAAC;IACxB,CAAC;IAED;;;OAGG;IACK,aAAa,CAAoC;IAEzD,YA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C,SAAS,CAAC,QAAQ,CAAC,CAAC;IAC/C,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,OAAO,CAAC,GAAW,EAAE,KAAU;QAC3C,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACjD,CAAC;IAED;;OAEG;IACI,WAAW,CACjB,GAAW,EACX,KAAU,EACV,cAAsB,EACtB,KAAc,EACd,oBAA4B;QAE5B,OAAO,IAAI,CAAC,eAAe,CAAC,WAAW,CACtC,GAAG,EACH,KAAK,EACL,cAAc,EACd,KAAK,EACL,oBAAoB,CACpB,CAAC;IACH,CAAC;IAED;;;OAGG;IACI,2BAA2B,CAAC,OAAkC;QACpE,IAAI,CAAC,eAAe,CAAC,2BAA2B,CAAC,OAAO,CAAC,CAAC;IAC3D,CAAC;IAEM,kBAAkB,CAAC,SAAkB,EAAE,QAAiB;QAC9D,IAAI,CAAC,eAAe,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;IAEM,OAAO;QACb,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACrC,CAAC;CACD;AAlJD,wBAkJC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { IQuorumClients, ISequencedClient } from \"@fluidframework/driver-definitions\";\nimport {\n\tISequencedDocumentMessage,\n\tICommittedProposal,\n\tIQuorum,\n\tIQuorumProposals,\n\tISequencedProposal,\n} from \"@fluidframework/driver-definitions/internal\";\nimport events_pkg from \"events_pkg\";\nconst { EventEmitter } = events_pkg;\n\n/**\n * Structure for tracking proposals that have been sequenced but not approved yet.\n */\nclass PendingProposal implements ISequencedProposal {\n\tconstructor(\n\t\tpublic readonly sequenceNumber: number,\n\t\tpublic readonly key: string,\n\t\tpublic readonly value: any,\n\t\tpublic readonly local: boolean,\n\t) {}\n}\n\n/**\n * Snapshot format for a QuorumClients\n * @alpha\n */\nexport type QuorumClientsSnapshot = [string, ISequencedClient][];\n\n/**\n * Snapshot format for a QuorumProposals\n * @alpha\n */\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport type QuorumProposalsSnapshot = {\n\tproposals: [number, ISequencedProposal, string[]][];\n\tvalues: [string, ICommittedProposal][];\n};\n\n/**\n * Snapshot format for a Quorum\n * @alpha\n */\nexport interface IQuorumSnapshot {\n\tmembers: QuorumClientsSnapshot;\n\tproposals: QuorumProposalsSnapshot[\"proposals\"];\n\tvalues: QuorumProposalsSnapshot[\"values\"];\n}\n\n/**\n * The QuorumClients is used to track members joining and leaving the collaboration session.\n * @internal\n */\nexport class QuorumClients\n\textends TypedEventEmitter<IQuorumClients[\"on\"]>\n\timplements IQuorumClients\n{\n\tprivate readonly members: Map<string, ISequencedClient>;\n\tprivate isDisposed: boolean = false;\n\tpublic get disposed() {\n\t\treturn this.isDisposed;\n\t}\n\n\t/**\n\t * Cached snapshot state, to avoid unnecessary deep clones on repeated snapshot calls.\n\t * Cleared immediately (set to undefined) when the cache becomes invalid.\n\t */\n\tprivate snapshotCache: QuorumClientsSnapshot | undefined;\n\n\tconstructor(snapshot: QuorumClientsSnapshot) {\n\t\tsuper();\n\n\t\tthis.members = new Map(snapshot);\n\t\tthis.snapshotCache = snapshot;\n\t}\n\n\t/**\n\t * Snapshots the current state of the QuorumClients\n\t * @returns a snapshot of the clients in the quorum\n\t */\n\tpublic snapshot(): QuorumClientsSnapshot {\n\t\tthis.snapshotCache ??= Array.from(this.members);\n\n\t\treturn this.snapshotCache;\n\t}\n\n\t/**\n\t * Adds a new client to the quorum\n\t */\n\tpublic addMember(clientId: string, details: ISequencedClient) {\n\t\tassert(!!clientId, \"clientId has to be non-empty string\");\n\t\tassert(!this.members.has(clientId), \"clientId not found\");\n\t\tthis.members.set(clientId, details);\n\t\tthis.emit(\"addMember\", clientId, details);\n\n\t\t// clear the cache\n\t\tthis.snapshotCache = undefined;\n\t}\n\n\t/**\n\t * Removes a client from the quorum\n\t */\n\tpublic removeMember(clientId: string) {\n\t\tassert(!!clientId, \"clientId has to be non-empty string\");\n\t\tassert(this.members.has(clientId), \"clientId not found\");\n\t\tthis.members.delete(clientId);\n\t\tthis.emit(\"removeMember\", clientId);\n\n\t\t// clear the cache\n\t\tthis.snapshotCache = undefined;\n\t}\n\n\t/**\n\t * Retrieves all the members in the quorum\n\t */\n\tpublic getMembers(): Map<string, ISequencedClient> {\n\t\treturn new Map(this.members);\n\t}\n\n\t/**\n\t * Retrieves a specific member of the quorum\n\t */\n\tpublic getMember(clientId: string): ISequencedClient | undefined {\n\t\treturn this.members.get(clientId);\n\t}\n\n\tpublic dispose(): void {\n\t\tthis.isDisposed = true;\n\t}\n}\n\n/**\n * The QuorumProposals holds a key/value store. Proposed values become finalized in the store once all connected\n * clients have seen the proposal.\n * @internal\n */\nexport class QuorumProposals\n\textends TypedEventEmitter<IQuorumProposals[\"on\"]>\n\timplements IQuorumProposals\n{\n\tprivate readonly proposals: Map<number, PendingProposal>;\n\tprivate readonly values: Map<string, ICommittedProposal>;\n\tprivate isDisposed: boolean = false;\n\tpublic get disposed() {\n\t\treturn this.isDisposed;\n\t}\n\n\t// Event emitter for changes to the environment that affect pending proposal promises.\n\tprivate readonly stateEvents = new EventEmitter();\n\n\t/**\n\t * Cached snapshot state, to avoid unnecessary deep clones on repeated snapshot calls.\n\t * Cleared immediately (set to undefined) when the cache becomes invalid.\n\t */\n\tprivate proposalsSnapshotCache: QuorumProposalsSnapshot[\"proposals\"] | undefined;\n\tprivate valuesSnapshotCache: QuorumProposalsSnapshot[\"values\"] | undefined;\n\n\tconstructor(\n\t\tsnapshot: QuorumProposalsSnapshot,\n\t\tprivate readonly sendProposal: (key: string, value: any) => number,\n\t) {\n\t\tsuper();\n\n\t\tthis.proposals = new Map(\n\t\t\tsnapshot.proposals.map(([, proposal]) => {\n\t\t\t\treturn [\n\t\t\t\t\tproposal.sequenceNumber,\n\t\t\t\t\tnew PendingProposal(\n\t\t\t\t\t\tproposal.sequenceNumber,\n\t\t\t\t\t\tproposal.key,\n\t\t\t\t\t\tproposal.value,\n\t\t\t\t\t\tfalse, // local\n\t\t\t\t\t),\n\t\t\t\t] as [number, PendingProposal];\n\t\t\t}),\n\t\t);\n\t\tthis.values = new Map(snapshot.values);\n\t\tthis.proposalsSnapshotCache = snapshot.proposals;\n\t\tthis.valuesSnapshotCache = snapshot.values;\n\t}\n\n\t/**\n\t * Snapshots the current state of the QuorumProposals\n\t * @returns arrays of proposals and values\n\t */\n\tpublic snapshot(): QuorumProposalsSnapshot {\n\t\tthis.proposalsSnapshotCache ??= Array.from(this.proposals).map(\n\t\t\t([sequenceNumber, proposal]) => [\n\t\t\t\tsequenceNumber,\n\t\t\t\t{ sequenceNumber, key: proposal.key, value: proposal.value },\n\t\t\t\t[], // rejections, which has been removed\n\t\t\t],\n\t\t);\n\t\tthis.valuesSnapshotCache ??= Array.from(this.values);\n\n\t\treturn {\n\t\t\tproposals: this.proposalsSnapshotCache,\n\t\t\tvalues: this.valuesSnapshotCache,\n\t\t};\n\t}\n\n\t/**\n\t * Returns whether the quorum has achieved a consensus for the given key.\n\t */\n\tpublic has(key: string): boolean {\n\t\treturn this.values.has(key);\n\t}\n\n\t/**\n\t * Returns the consensus value for the given key\n\t */\n\tpublic get(key: string): any {\n\t\treturn this.values.get(key)?.value;\n\t}\n\n\t/**\n\t * Returns additional data about the approved consensus value\n\t * @deprecated Removed in recent protocol-definitions. Use get() instead.\n\t */\n\tpublic getApprovalData(key: string): ICommittedProposal | undefined {\n\t\treturn this.values.get(key);\n\t}\n\n\t/**\n\t * Proposes a new value. Returns a promise that will either:\n\t * - Resolve when the proposal is accepted\n\t * - Reject if the proposal fails to send or if the QuorumProposals is disposed\n\t */\n\tpublic async propose(key: string, value: any): Promise<void> {\n\t\tconst clientSequenceNumber = this.sendProposal(key, value);\n\t\tif (clientSequenceNumber < 0) {\n\t\t\tthis.emit(\"error\", { eventName: \"ProposalInDisconnectedState\", key });\n\t\t\tthrow new Error(\"Can't propose in disconnected state\");\n\t\t}\n\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\t// The sequence number that our proposal was assigned and went pending.\n\t\t\t// If undefined, then it's not sequenced yet.\n\t\t\tlet thisProposalSequenceNumber: number | undefined;\n\n\t\t\t// A proposal goes through two phases before this promise resolves:\n\t\t\t// 1. Sequencing - waiting for the proposal to be ack'd by the server.\n\t\t\t// 2. Approval - waiting for the proposal to be approved by connected clients.\n\t\t\tconst localProposalSequencedHandler = (\n\t\t\t\tsequencedCSN: number,\n\t\t\t\tsequenceNumber: number,\n\t\t\t) => {\n\t\t\t\tif (sequencedCSN === clientSequenceNumber) {\n\t\t\t\t\tthisProposalSequenceNumber = sequenceNumber;\n\t\t\t\t\tthis.stateEvents.off(\"localProposalSequenced\", localProposalSequencedHandler);\n\t\t\t\t\tthis.stateEvents.off(\"disconnected\", disconnectedHandler);\n\t\t\t\t\tthis.stateEvents.on(\"localProposalApproved\", localProposalApprovedHandler);\n\t\t\t\t}\n\t\t\t};\n\t\t\tconst localProposalApprovedHandler = (sequenceNumber: number) => {\n\t\t\t\t// Proposals can be uniquely identified by the sequenceNumber they were assigned.\n\t\t\t\tif (sequenceNumber === thisProposalSequenceNumber) {\n\t\t\t\t\tresolve();\n\t\t\t\t\tremoveListeners();\n\t\t\t\t}\n\t\t\t};\n\n\t\t\t// There are two error flows we consider: disconnect and disposal.\n\t\t\t// If we get disconnected before the proposal is sequenced, it has one of two possible futures:\n\t\t\t// 1. We reconnect and see the proposal was sequenced in the meantime.\n\t\t\t// -> The promise can still resolve, once it is approved.\n\t\t\t// 2. We reconnect and see the proposal was not sequenced in the meantime, so it will never sequence.\n\t\t\t// -> The promise rejects.\n\t\t\tconst disconnectedHandler = () => {\n\t\t\t\t// If we haven't seen the ack by the time we disconnect, we hope to see it by the time we reconnect.\n\t\t\t\tif (thisProposalSequenceNumber === undefined) {\n\t\t\t\t\tthis.stateEvents.once(\"connected\", () => {\n\t\t\t\t\t\t// If we don't see the ack by the time reconnection finishes, it failed to send.\n\t\t\t\t\t\tif (thisProposalSequenceNumber === undefined) {\n\t\t\t\t\t\t\treject(\n\t\t\t\t\t\t\t\tnew Error(\n\t\t\t\t\t\t\t\t\t\"Client disconnected without successfully sending proposal\",\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tremoveListeners();\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t};\n\t\t\t// If the QuorumProposals is disposed of, we assume something catastrophic has happened\n\t\t\t// All outstanding proposals are considered rejected.\n\t\t\tconst disposedHandler = () => {\n\t\t\t\treject(new Error(\"QuorumProposals was disposed\"));\n\t\t\t\tremoveListeners();\n\t\t\t};\n\t\t\t// Convenience function to clean up our listeners.\n\t\t\tconst removeListeners = () => {\n\t\t\t\tthis.stateEvents.off(\"localProposalSequenced\", localProposalSequencedHandler);\n\t\t\t\tthis.stateEvents.off(\"localProposalApproved\", localProposalApprovedHandler);\n\t\t\t\tthis.stateEvents.off(\"disconnected\", disconnectedHandler);\n\t\t\t\tthis.stateEvents.off(\"disposed\", disposedHandler);\n\t\t\t};\n\t\t\tthis.stateEvents.on(\"localProposalSequenced\", localProposalSequencedHandler);\n\t\t\tthis.stateEvents.on(\"disconnected\", disconnectedHandler);\n\t\t\tthis.stateEvents.on(\"disposed\", disposedHandler);\n\t\t});\n\t}\n\n\t/**\n\t * Begins tracking a new proposal\n\t */\n\tpublic addProposal(\n\t\tkey: string,\n\t\tvalue: any,\n\t\tsequenceNumber: number,\n\t\tlocal: boolean,\n\t\tclientSequenceNumber: number,\n\t) {\n\t\tassert(!this.proposals.has(sequenceNumber), \"sequenceNumber not found\");\n\n\t\tconst proposal = new PendingProposal(sequenceNumber, key, value, local);\n\t\tthis.proposals.set(sequenceNumber, proposal);\n\n\t\t// Legacy event, from rejection support. May still have some use for clients to learn that a proposal is\n\t\t// likely to be approved soon.\n\t\tthis.emit(\"addProposal\", proposal);\n\n\t\tif (local) {\n\t\t\tthis.stateEvents.emit(\"localProposalSequenced\", clientSequenceNumber, sequenceNumber);\n\t\t}\n\n\t\t// clear the proposal cache\n\t\tthis.proposalsSnapshotCache = undefined;\n\t}\n\n\t/**\n\t * Updates the minimum sequence number. If the MSN advances past the sequence number for any proposal then it\n\t * becomes an approved value.\n\t */\n\tpublic updateMinimumSequenceNumber(message: ISequencedDocumentMessage): void {\n\t\tconst msn = message.minimumSequenceNumber;\n\n\t\t// Accept proposals proposals whose sequenceNumber is <= the minimumSequenceNumber\n\n\t\t// Return a sorted list of approved proposals. We sort so that we apply them in their sequence number order\n\t\t// TODO this can be optimized if necessary to avoid the linear search+sort\n\t\tconst completed: PendingProposal[] = [];\n\t\tfor (const [sequenceNumber, proposal] of this.proposals) {\n\t\t\tif (sequenceNumber <= msn) {\n\t\t\t\tcompleted.push(proposal);\n\t\t\t}\n\t\t}\n\t\tcompleted.sort((a, b) => a.sequenceNumber - b.sequenceNumber);\n\n\t\tfor (const proposal of completed) {\n\t\t\tconst committedProposal: ICommittedProposal = {\n\t\t\t\tapprovalSequenceNumber: message.sequenceNumber,\n\t\t\t\t// No longer used. We still stamp a -1 for compat with older versions of the quorum.\n\t\t\t\t// Can be removed after 0.1035 and higher is ubiquitous.\n\t\t\t\tcommitSequenceNumber: -1,\n\t\t\t\tkey: proposal.key,\n\t\t\t\tsequenceNumber: proposal.sequenceNumber,\n\t\t\t\tvalue: proposal.value,\n\t\t\t};\n\n\t\t\tthis.values.set(committedProposal.key, committedProposal);\n\n\t\t\t// clear the values cache\n\t\t\tthis.valuesSnapshotCache = undefined;\n\n\t\t\t// check if there are multiple proposals with matching keys\n\t\t\tlet proposalSettled = false;\n\t\t\tlet proposalKeySeen = false;\n\t\t\tfor (const [, p] of this.proposals) {\n\t\t\t\tif (p.key === committedProposal.key) {\n\t\t\t\t\tif (!proposalKeySeen) {\n\t\t\t\t\t\t// set proposalSettled to true if the proposal key match is unique thus far\n\t\t\t\t\t\tproposalSettled = true;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// set proposalSettled to false if matching proposal key is not unique\n\t\t\t\t\t\tproposalSettled = false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tproposalKeySeen = true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.emit(\n\t\t\t\t\"approveProposal\",\n\t\t\t\tcommittedProposal.sequenceNumber,\n\t\t\t\tcommittedProposal.key,\n\t\t\t\tcommittedProposal.value,\n\t\t\t\tcommittedProposal.approvalSequenceNumber,\n\t\t\t);\n\n\t\t\t// emit approveProposalComplete when all pending proposals are processed\n\t\t\tif (proposalSettled) {\n\t\t\t\tthis.emit(\n\t\t\t\t\t\"approveProposalComplete\",\n\t\t\t\t\tcommittedProposal.sequenceNumber,\n\t\t\t\t\tcommittedProposal.key,\n\t\t\t\t\tcommittedProposal.value,\n\t\t\t\t\tcommittedProposal.approvalSequenceNumber,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tthis.proposals.delete(proposal.sequenceNumber);\n\n\t\t\t// clear the proposals cache\n\t\t\tthis.proposalsSnapshotCache = undefined;\n\t\t\tif (proposal.local) {\n\t\t\t\tthis.stateEvents.emit(\"localProposalApproved\", proposal.sequenceNumber);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic setConnectionState(connected: boolean) {\n\t\tif (connected) {\n\t\t\tthis.stateEvents.emit(\"connected\");\n\t\t} else {\n\t\t\tthis.stateEvents.emit(\"disconnected\");\n\t\t}\n\t}\n\n\tpublic dispose(): void {\n\t\tthis.isDisposed = true;\n\t\tthis.stateEvents.emit(\"disposed\");\n\t}\n}\n\n/**\n * A quorum represents all clients currently within the collaboration window. As well as the values\n * they have agreed upon and any pending proposals.\n * @internal\n */\nexport class Quorum extends TypedEventEmitter<IQuorum[\"on\"]> implements IQuorum {\n\tprivate readonly quorumClients: QuorumClients;\n\tprivate readonly quorumProposals: QuorumProposals;\n\tprivate readonly isDisposed: boolean = false;\n\tpublic get disposed() {\n\t\treturn this.isDisposed;\n\t}\n\n\tconstructor(\n\t\tmembers: QuorumClientsSnapshot,\n\t\tproposals: QuorumProposalsSnapshot[\"proposals\"],\n\t\tvalues: QuorumProposalsSnapshot[\"values\"],\n\t\tsendProposal: (key: string, value: any) => number,\n\t) {\n\t\tsuper();\n\n\t\tthis.quorumClients = new QuorumClients(members);\n\t\tthis.quorumClients.on(\"addMember\", (clientId: string, details: ISequencedClient) => {\n\t\t\tthis.emit(\"addMember\", clientId, details);\n\t\t});\n\t\tthis.quorumClients.on(\"removeMember\", (clientId: string) => {\n\t\t\tthis.emit(\"removeMember\", clientId);\n\t\t});\n\n\t\tthis.quorumProposals = new QuorumProposals({ proposals, values }, sendProposal);\n\t\tthis.quorumProposals.on(\"addProposal\", (proposal: ISequencedProposal) => {\n\t\t\tthis.emit(\"addProposal\", proposal);\n\t\t});\n\t\tthis.quorumProposals.on(\n\t\t\t\"approveProposal\",\n\t\t\t(sequenceNumber: number, key: string, value: any, approvalSequenceNumber: number) => {\n\t\t\t\tthis.emit(\"approveProposal\", sequenceNumber, key, value, approvalSequenceNumber);\n\t\t\t},\n\t\t);\n\t}\n\n\tpublic close() {\n\t\tthis.removeAllListeners();\n\t}\n\n\t/**\n\t * Snapshots the entire quorum\n\t * @returns a quorum snapshot\n\t */\n\tpublic snapshot(): IQuorumSnapshot {\n\t\tconst members = this.quorumClients.snapshot();\n\t\tconst { proposals, values } = this.quorumProposals.snapshot();\n\t\treturn {\n\t\t\tmembers,\n\t\t\tproposals,\n\t\t\tvalues,\n\t\t};\n\t}\n\n\t/**\n\t * Returns whether the quorum has achieved a consensus for the given key.\n\t */\n\tpublic has(key: string): boolean {\n\t\treturn this.quorumProposals.has(key);\n\t}\n\n\t/**\n\t * Returns the consensus value for the given key\n\t */\n\tpublic get(key: string): any {\n\t\treturn this.quorumProposals.get(key);\n\t}\n\n\t/**\n\t * Returns additional data about the approved consensus value\n\t * @deprecated Removed in recent protocol-definitions. Use get() instead.\n\t */\n\tpublic getApprovalData(key: string): ICommittedProposal | undefined {\n\t\treturn this.quorumProposals.getApprovalData(key);\n\t}\n\n\t/**\n\t * Adds a new client to the quorum\n\t */\n\tpublic addMember(clientId: string, details: ISequencedClient) {\n\t\tthis.quorumClients.addMember(clientId, details);\n\t}\n\n\t/**\n\t * Removes a client from the quorum\n\t */\n\tpublic removeMember(clientId: string) {\n\t\tthis.quorumClients.removeMember(clientId);\n\t}\n\n\t/**\n\t * Retrieves all the members in the quorum\n\t */\n\tpublic getMembers(): Map<string, ISequencedClient> {\n\t\treturn this.quorumClients.getMembers();\n\t}\n\n\t/**\n\t * Retrieves a specific member of the quorum\n\t */\n\tpublic getMember(clientId: string): ISequencedClient | undefined {\n\t\treturn this.quorumClients.getMember(clientId);\n\t}\n\n\t/**\n\t * Proposes a new value. Returns a promise that will resolve when the proposal is either accepted, or reject if\n\t * the proposal fails to send.\n\t */\n\tpublic async propose(key: string, value: any): Promise<void> {\n\t\treturn this.quorumProposals.propose(key, value);\n\t}\n\n\t/**\n\t * Begins tracking a new proposal\n\t */\n\tpublic addProposal(\n\t\tkey: string,\n\t\tvalue: any,\n\t\tsequenceNumber: number,\n\t\tlocal: boolean,\n\t\tclientSequenceNumber: number,\n\t) {\n\t\treturn this.quorumProposals.addProposal(\n\t\t\tkey,\n\t\t\tvalue,\n\t\t\tsequenceNumber,\n\t\t\tlocal,\n\t\t\tclientSequenceNumber,\n\t\t);\n\t}\n\n\t/**\n\t * Updates the minimum sequence number. If the MSN advances past the sequence number for any proposal then it\n\t * becomes an approved value.\n\t */\n\tpublic updateMinimumSequenceNumber(message: ISequencedDocumentMessage): void {\n\t\tthis.quorumProposals.updateMinimumSequenceNumber(message);\n\t}\n\n\tpublic setConnectionState(connected: boolean, clientId?: string) {\n\t\tthis.quorumProposals.setConnectionState(connected);\n\t}\n\n\tpublic dispose(): void {\n\t\tthrow new Error(\"Not implemented.\");\n\t}\n}\n"]}
|
package/dist/protocol.d.ts
CHANGED
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
import { IAudienceOwner } from "@fluidframework/container-definitions/internal";
|
|
6
|
-
import { ISequencedDocumentMessage, ISignalMessage } from "@fluidframework/driver-definitions";
|
|
7
|
-
import {
|
|
8
|
-
import { IProtocolHandler as IBaseProtocolHandler, IQuorumSnapshot, ProtocolOpHandler } from "@fluidframework/protocol-base";
|
|
6
|
+
import { IDocumentAttributes, IProcessMessageResult, ISequencedDocumentMessage, ISignalMessage } from "@fluidframework/driver-definitions/internal";
|
|
7
|
+
import { IBaseProtocolHandler, IQuorumSnapshot, ProtocolOpHandler } from "./protocol/index.js";
|
|
9
8
|
export declare enum SignalType {
|
|
10
9
|
ClientJoin = "join",// same value as MessageType.ClientJoin,
|
|
11
10
|
ClientLeave = "leave",// same value as MessageType.ClientLeave,
|
package/dist/protocol.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,gDAAgD,CAAC;AAChF,OAAO,
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,gDAAgD,CAAC;AAChF,OAAO,EACN,mBAAmB,EACnB,qBAAqB,EAGrB,yBAAyB,EACzB,cAAc,EACd,MAAM,6CAA6C,CAAC;AAGrD,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAG/F,oBAAY,UAAU;IACrB,UAAU,SAAS,CAAE,wCAAwC;IAC7D,WAAW,UAAU,CAAE,yCAAyC;IAChE,KAAK,UAAU;CACf;AAED;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG,CACpC,UAAU,EAAE,mBAAmB,EAC/B,QAAQ,EAAE,eAAe,EACzB,YAAY,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,MAAM,KAC7C,gBAAgB,CAAC;AAEtB;;GAEG;AACH,MAAM,WAAW,gBAAiB,SAAQ,oBAAoB;IAC7D,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,aAAa,CAAC,OAAO,EAAE,cAAc,OAAE;CACvC;AAED,qBAAa,eAAgB,SAAQ,iBAAkB,YAAW,gBAAgB;aAKhE,QAAQ,EAAE,cAAc;IACxC,OAAO,CAAC,QAAQ,CAAC,oBAAoB;gBAJrC,UAAU,EAAE,mBAAmB,EAC/B,cAAc,EAAE,eAAe,EAC/B,YAAY,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,MAAM,EACjC,QAAQ,EAAE,cAAc,EACvB,oBAAoB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO;IAyB9D,cAAc,CACpB,OAAO,EAAE,yBAAyB,EAClC,KAAK,EAAE,OAAO,GACZ,qBAAqB;IAuBjB,aAAa,CAAC,OAAO,EAAE,cAAc;CAgC5C;AAED;;;;GAIG;AACH,wBAAgB,kCAAkC,CAAC,OAAO,EAAE,cAAc,WAWzE"}
|
package/dist/protocol.js
CHANGED
|
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
exports.protocolHandlerShouldProcessSignal = exports.ProtocolHandler = exports.SignalType = void 0;
|
|
8
8
|
const internal_1 = require("@fluidframework/driver-definitions/internal");
|
|
9
9
|
const internal_2 = require("@fluidframework/driver-utils/internal");
|
|
10
|
-
const
|
|
10
|
+
const index_js_1 = require("./protocol/index.js");
|
|
11
11
|
// ADO: #1986: Start using enum from protocol-base.
|
|
12
12
|
var SignalType;
|
|
13
13
|
(function (SignalType) {
|
|
@@ -15,7 +15,9 @@ var SignalType;
|
|
|
15
15
|
SignalType["ClientLeave"] = "leave";
|
|
16
16
|
SignalType["Clear"] = "clear";
|
|
17
17
|
})(SignalType || (exports.SignalType = SignalType = {}));
|
|
18
|
-
class ProtocolHandler extends
|
|
18
|
+
class ProtocolHandler extends index_js_1.ProtocolOpHandler {
|
|
19
|
+
audience;
|
|
20
|
+
shouldClientHaveLeft;
|
|
19
21
|
constructor(attributes, quorumSnapshot, sendProposal, audience, shouldClientHaveLeft) {
|
|
20
22
|
super(attributes.minimumSequenceNumber, attributes.sequenceNumber, quorumSnapshot.members, quorumSnapshot.proposals, quorumSnapshot.values, sendProposal);
|
|
21
23
|
this.audience = audience;
|
package/dist/protocol.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,0EAOqD;AACrD,oEAAgF;AAEhF,kDAA+F;AAE/F,mDAAmD;AACnD,IAAY,UAIX;AAJD,WAAY,UAAU;IACrB,iCAAmB,CAAA;IACnB,mCAAqB,CAAA;IACrB,6BAAe,CAAA;AAChB,CAAC,EAJW,UAAU,0BAAV,UAAU,QAIrB;AAoBD,MAAa,eAAgB,SAAQ,4BAAiB;IAKpC;IACC;IALlB,YACC,UAA+B,EAC/B,cAA+B,EAC/B,YAAiD,EACjC,QAAwB,EACvB,oBAAmD;QAEpE,KAAK,CACJ,UAAU,CAAC,qBAAqB,EAChC,UAAU,CAAC,cAAc,EACzB,cAAc,CAAC,OAAO,EACtB,cAAc,CAAC,SAAS,EACxB,cAAc,CAAC,MAAM,EACrB,YAAY,CACZ,CAAC;QAVc,aAAQ,GAAR,QAAQ,CAAgB;QACvB,yBAAoB,GAApB,oBAAoB,CAA+B;QAWpE,KA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IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;gBAC1C,CAAC;gBACD,MAAM;YACP,CAAC;YACD;gBACC,MAAM;QACR,CAAC;IACF,CAAC;CACD;AAzFD,0CAyFC;AAED;;;;GAIG;AACH,SAAgB,kCAAkC,CAAC,OAAuB;IACzE,gCAAgC;IAChC,IAAI,OAAO,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;QAC/B,MAAM,YAAY,GAAG,OAAO,CAAC,OAA6C,CAAC;QAC3E,OAAO,CACN,YAAY,CAAC,IAAI,KAAK,UAAU,CAAC,KAAK;YACtC,YAAY,CAAC,IAAI,KAAK,UAAU,CAAC,UAAU;YAC3C,YAAY,CAAC,IAAI,KAAK,UAAU,CAAC,WAAW,CAC5C,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAXD,gFAWC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IAudienceOwner } from \"@fluidframework/container-definitions/internal\";\nimport {\n\tIDocumentAttributes,\n\tIProcessMessageResult,\n\tISignalClient,\n\tMessageType,\n\tISequencedDocumentMessage,\n\tISignalMessage,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { canBeCoalescedByService } from \"@fluidframework/driver-utils/internal\";\n\nimport { IBaseProtocolHandler, IQuorumSnapshot, ProtocolOpHandler } from \"./protocol/index.js\";\n\n// ADO: #1986: Start using enum from protocol-base.\nexport enum SignalType {\n\tClientJoin = \"join\", // same value as MessageType.ClientJoin,\n\tClientLeave = \"leave\", // same value as MessageType.ClientLeave,\n\tClear = \"clear\", // used only by client for synthetic signals\n}\n\n/**\n * Function to be used for creating a protocol handler.\n * @alpha\n */\nexport type ProtocolHandlerBuilder = (\n\tattributes: IDocumentAttributes,\n\tsnapshot: IQuorumSnapshot,\n\tsendProposal: (key: string, value: any) => number,\n) => IProtocolHandler;\n\n/**\n * @alpha\n */\nexport interface IProtocolHandler extends IBaseProtocolHandler {\n\treadonly audience: IAudienceOwner;\n\tprocessSignal(message: ISignalMessage);\n}\n\nexport class ProtocolHandler extends ProtocolOpHandler implements IProtocolHandler {\n\tconstructor(\n\t\tattributes: IDocumentAttributes,\n\t\tquorumSnapshot: IQuorumSnapshot,\n\t\tsendProposal: (key: string, value: any) => number,\n\t\tpublic readonly audience: IAudienceOwner,\n\t\tprivate readonly shouldClientHaveLeft: (clientId: string) => boolean,\n\t) {\n\t\tsuper(\n\t\t\tattributes.minimumSequenceNumber,\n\t\t\tattributes.sequenceNumber,\n\t\t\tquorumSnapshot.members,\n\t\t\tquorumSnapshot.proposals,\n\t\t\tquorumSnapshot.values,\n\t\t\tsendProposal,\n\t\t);\n\n\t\tfor (const [clientId, member] of this.quorum.getMembers()) {\n\t\t\taudience.addMember(clientId, member.client);\n\t\t}\n\n\t\t// Join / leave signals are ignored for \"write\" clients in favor of join / leave ops\n\t\tthis.quorum.on(\"addMember\", (clientId, details) =>\n\t\t\taudience.addMember(clientId, details.client),\n\t\t);\n\t\tthis.quorum.on(\"removeMember\", (clientId) => audience.removeMember(clientId));\n\t\tfor (const [clientId, details] of this.quorum.getMembers()) {\n\t\t\tthis.audience.addMember(clientId, details.client);\n\t\t}\n\t}\n\n\tpublic processMessage(\n\t\tmessage: ISequencedDocumentMessage,\n\t\tlocal: boolean,\n\t): IProcessMessageResult {\n\t\t// Check and report if we're getting messages from a clientId that we previously\n\t\t// flagged as shouldHaveLeft, or from a client that's not in the quorum but should be\n\t\tif (message.clientId != null) {\n\t\t\tconst client = this.quorum.getMember(message.clientId);\n\n\t\t\tif (client === undefined && message.type !== MessageType.ClientJoin) {\n\t\t\t\t// pre-0.58 error message: messageClientIdMissingFromQuorum\n\t\t\t\tthrow new Error(\"Remote message's clientId is missing from the quorum\");\n\t\t\t}\n\n\t\t\t// Here checking canBeCoalescedByService is used as an approximation of \"is benign to process despite being unexpected\".\n\t\t\t// It's still not good to see these messages from unexpected clientIds, but since they don't harm the integrity of the\n\t\t\t// document we don't need to blow up aggressively.\n\t\t\tif (this.shouldClientHaveLeft(message.clientId) && !canBeCoalescedByService(message)) {\n\t\t\t\t// pre-0.58 error message: messageClientIdShouldHaveLeft\n\t\t\t\tthrow new Error(\"Remote message's clientId already should have left\");\n\t\t\t}\n\t\t}\n\n\t\treturn super.processMessage(message, local);\n\t}\n\n\tpublic processSignal(message: ISignalMessage) {\n\t\tconst innerContent = message.content as { content: any; type: string };\n\t\tswitch (innerContent.type) {\n\t\t\tcase SignalType.Clear: {\n\t\t\t\tconst members = this.audience.getMembers();\n\t\t\t\tfor (const [clientId, client] of members) {\n\t\t\t\t\tif (client.mode === \"read\") {\n\t\t\t\t\t\tthis.audience.removeMember(clientId);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SignalType.ClientJoin: {\n\t\t\t\tconst newClient = innerContent.content as ISignalClient;\n\t\t\t\t// Ignore write clients - quorum will control such clients.\n\t\t\t\tif (newClient.client.mode === \"read\") {\n\t\t\t\t\tthis.audience.addMember(newClient.clientId, newClient.client);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SignalType.ClientLeave: {\n\t\t\t\tconst leftClientId = innerContent.content as string;\n\t\t\t\t// Ignore write clients - quorum will control such clients.\n\t\t\t\tif (this.audience.getMember(leftClientId)?.mode === \"read\") {\n\t\t\t\t\tthis.audience.removeMember(leftClientId);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n\n/**\n * Function to check whether the protocol handler should process the Signal.\n * The protocol handler should strictly handle only ClientJoin, ClientLeave\n * and Clear signal types.\n */\nexport function protocolHandlerShouldProcessSignal(message: ISignalMessage) {\n\t// Signal originates from server\n\tif (message.clientId === null) {\n\t\tconst innerContent = message.content as { content: unknown; type: string };\n\t\treturn (\n\t\t\tinnerContent.type === SignalType.Clear ||\n\t\t\tinnerContent.type === SignalType.ClientJoin ||\n\t\t\tinnerContent.type === SignalType.ClientLeave\n\t\t);\n\t}\n\treturn false;\n}\n"]}
|
|
@@ -15,13 +15,13 @@ export declare class ProtocolTreeStorageService implements IDocumentStorageServi
|
|
|
15
15
|
constructor(internalStorageService: IDocumentStorageService & IDisposable, addProtocolSummaryIfMissing: (summaryTree: ISummaryTree) => ISummaryTree);
|
|
16
16
|
get policies(): import("@fluidframework/driver-definitions/internal").IDocumentStorageServicePolicies | undefined;
|
|
17
17
|
get disposed(): boolean;
|
|
18
|
-
getSnapshotTree:
|
|
19
|
-
getSnapshot:
|
|
20
|
-
getVersions:
|
|
21
|
-
createBlob:
|
|
22
|
-
readBlob:
|
|
23
|
-
downloadSummary:
|
|
24
|
-
dispose:
|
|
18
|
+
getSnapshotTree: IDocumentStorageService["getSnapshotTree"];
|
|
19
|
+
getSnapshot: IDocumentStorageService["getSnapshot"];
|
|
20
|
+
getVersions: IDocumentStorageService["getVersions"];
|
|
21
|
+
createBlob: IDocumentStorageService["createBlob"];
|
|
22
|
+
readBlob: IDocumentStorageService["readBlob"];
|
|
23
|
+
downloadSummary: IDocumentStorageService["downloadSummary"];
|
|
24
|
+
dispose: IDisposable["dispose"];
|
|
25
25
|
uploadSummaryWithContext(summary: ISummaryTree, context: ISummaryContext): Promise<string>;
|
|
26
26
|
}
|
|
27
27
|
//# sourceMappingURL=protocolTreeDocumentStorageService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocolTreeDocumentStorageService.d.ts","sourceRoot":"","sources":["../src/protocolTreeDocumentStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EACN,uBAAuB,EACvB,eAAe,EACf,MAAM,6CAA6C,CAAC;AAErD;;;GAGG;AACH,qBAAa,0BAA2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