RpcMessage.js
1.5 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
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function createRpcMessage(procedure, id, type, payload, source) {
return {
rpc: true,
type,
id,
procedure,
payload,
source,
};
}
exports.createRpcMessage = createRpcMessage;
function createRpcCall(procedure, index, payload) {
return createRpcMessage(procedure, index, 'call', payload);
}
exports.createRpcCall = createRpcCall;
function createRpcReturn(procedure, index, payload) {
return createRpcMessage(procedure, index, 'return', payload);
}
exports.createRpcReturn = createRpcReturn;
function createRpcThrow(procedure, index, payload) {
return createRpcMessage(procedure, index, 'throw', payload);
}
exports.createRpcThrow = createRpcThrow;
function isRpcMessage(candidate) {
return !!(typeof candidate === 'object' && candidate && candidate.rpc);
}
exports.isRpcMessage = isRpcMessage;
function isRpcCallMessage(candidate) {
return isRpcMessage(candidate) && candidate.type === 'call';
}
exports.isRpcCallMessage = isRpcCallMessage;
function isRpcReturnMessage(candidate) {
return isRpcMessage(candidate) && candidate.type === 'return';
}
exports.isRpcReturnMessage = isRpcReturnMessage;
function isRpcThrowMessage(candidate) {
return isRpcMessage(candidate) && candidate.type === 'throw';
}
exports.isRpcThrowMessage = isRpcThrowMessage;
function getRpcMessageKey(message) {
return `${message.procedure}_${message.id}`;
}
exports.getRpcMessageKey = getRpcMessageKey;