forked from microsoft/FluidFramework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.ts
More file actions
101 lines (93 loc) · 2.78 KB
/
utils.ts
File metadata and controls
101 lines (93 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*!
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
* Licensed under the MIT License.
*/
import { ProtocolOpHandler } from "@fluidframework/protocol-base";
import type {
IDocumentMessage,
IDocumentSystemMessage,
IProtocolState,
IUser,
} from "@fluidframework/protocol-definitions";
import {
type IProducer,
type IRawOperationMessage,
RawOperationType,
type IScribe,
} from "@fluidframework/server-services-core";
export const initializeProtocol = (protocolState: IProtocolState): ProtocolOpHandler =>
new ProtocolOpHandler(
protocolState.minimumSequenceNumber,
protocolState.sequenceNumber,
protocolState.members,
protocolState.proposals,
protocolState.values,
() => -1,
);
export const sendToDeli = async (
tenantId: string,
documentId: string,
producer: IProducer | undefined,
operation: IDocumentMessage | IDocumentSystemMessage,
): Promise<void> => {
if (!producer) {
throw new Error("Invalid producer");
}
const message: IRawOperationMessage = {
clientId: null,
documentId,
operation,
tenantId,
timestamp: Date.now(),
type: RawOperationType,
};
return producer.send([message], tenantId, documentId);
};
export const getClientIds = (protocolState: IProtocolState, clientCount: number): string[] => {
return protocolState.members.slice(0, clientCount).map((member) => member[0]);
};
/**
* Whether to write checkpoint to local db.
* @param noActiveClients - whether there are any active clients
* @param globalCheckpointOnly - whether to always write checkpoints to global db
* @returns whether to write checkpoint to local db
*/
export const isLocalCheckpoint = (
noActiveClients: boolean,
globalCheckpointOnly: boolean,
): boolean => {
return !isGlobalCheckpoint(noActiveClients, globalCheckpointOnly);
};
/**
* Whether to write checkpoint to global db.
* @param noActiveClients - whether there are any active clients
* @param globalCheckpointOnly - whether to always write checkpoints to global db
* @returns whether to write checkpoint to global db
*/
export const isGlobalCheckpoint = (
noActiveClients: boolean,
globalCheckpointOnly: boolean,
): boolean => {
return noActiveClients || globalCheckpointOnly;
};
/**
* Whether the quorum members represented in the checkpoint's protocol state have had their user data scrubbed
* for privacy compliance.
*/
export const isScribeCheckpointQuorumScrubbed = (
checkpoint: string | IScribe | undefined,
): boolean => {
if (!checkpoint) {
return false;
}
const parsedCheckpoint: IScribe =
typeof checkpoint === "string" ? JSON.parse(checkpoint) : checkpoint;
for (const [, sequencedClient] of parsedCheckpoint.protocolState.members) {
const user: IUser = sequencedClient.client.user;
if (!user.id) {
// User information was scrubbed.
return true;
}
}
return false;
};