@berish/rfp
Version:
Binary secure transport organization protocol for peer communication using function fingerprints
46 lines • 2.45 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.functionToFunctionPrintPlugin = exports.SYMBOL_SERBER_CHUNK_REPLY_PATH = exports.SYMBOL_SERBER_DEFERRED_LIST = void 0;
const serber_1 = require("@berish/serber");
const utils_1 = require("./utils");
const abstract_1 = require("../abstract");
const network_1 = require("./network");
const network_2 = require("./network");
exports.SYMBOL_SERBER_DEFERRED_LIST = Symbol('serberDeferredList');
exports.SYMBOL_SERBER_CHUNK_REPLY_PATH = Symbol('serberChunkPath');
exports.functionToFunctionPrintPlugin = {
isForSerialize: (obj) => abstract_1.getType(obj) === 'function',
isForDeserialize: (obj) => abstract_1.getType(obj) === 'printFunction',
isAlreadySerialized: (obj) => exports.functionToFunctionPrintPlugin.isForDeserialize(obj),
isAlreadyDeserialized: (obj) => exports.functionToFunctionPrintPlugin.isForSerialize(obj),
serialize: (obj, options) => {
const replyPath = options[exports.SYMBOL_SERBER_CHUNK_REPLY_PATH];
const peer = options[abstract_1.SYMBOL_SERBER_PEER];
const deferredList = options[exports.SYMBOL_SERBER_DEFERRED_LIST];
const thisArg = options[serber_1.SERBER_PARENT_OBJECT_SYMBOL];
const key = options[serber_1.SERBER_KEY_SYMBOL];
const print = Object.assign(Object.assign({}, abstract_1.createPrint(abstract_1.PrintTypeEnum.printFunction)), { printId: utils_1.generatePrintId(), name: utils_1.getPrintName(obj, key, replyPath), args: utils_1.getPrintArguments(obj) });
if (deferredList) {
network_1.deferredReceivePrintFunction(print, obj, peer, deferredList, thisArg);
}
else {
network_1.startReceivePrintFunction(print, obj, peer, thisArg);
}
return print;
},
deserialize: (print, params) => {
const peer = params[abstract_1.SYMBOL_SERBER_PEER];
const withSend = (...args) => {
const aside = utils_1.getAsideFromLocalFunction(withSend);
return network_2.executeRemoteFunction(peer, print, aside, args);
};
Object.defineProperty(withSend, 'name', { value: print.name });
Object.defineProperty(withSend, 'toString', {
value: function () {
return `function ${print.name || ''}(${print.args.join(',')}) { [rfp code] }`;
},
});
return withSend;
},
};
//# sourceMappingURL=plugin.js.map