MCPcopy Create free account
hub / github.com/CommE2E/comm / convertClientIDsToServerIDs

Function convertClientIDsToServerIDs

lib/utils/conversion-utils.js:35–63  ·  view source on GitHub ↗
(
  serverPrefixID: string,
  outputValidator: TType<T>,
  data: T,
)

Source from the content-addressed store, hash-verified

33}
34
35function convertClientIDsToServerIDs<T>(
36 serverPrefixID: string,
37 outputValidator: TType<T>,
38 data: T,
39): T {
40 const prefix = serverPrefixID + '|';
41 const conversionFunction = (id: string) => {
42 if (id.startsWith(prefix)) {
43 return id.substr(prefix.length);
44 }
45
46 const pendingIDContents = parsePendingThreadID(id);
47 if (!pendingIDContents) {
48 throw new Error('invalid_client_id_prefix');
49 }
50
51 if (!pendingIDContents.sourceMessageID) {
52 return id;
53 }
54
55 return getPendingThreadID(
56 pendingIDContents.threadType,
57 pendingIDContents.memberIDs,
58 pendingIDContents.sourceMessageID.substr(prefix.length),
59 );
60 };
61
62 return convertObject(outputValidator, data, [tID], conversionFunction);
63}
64
65function extractUserIDsFromPayload<T>(
66 outputValidator: TType<T>,

Callers 2

validateInputFunction · 0.90

Calls 1

convertObjectFunction · 0.85

Tested by

no test coverage detected