falkordb
Version:
A FalkorDB javascript library
27 lines (26 loc) • 903 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformArguments = transformArguments;
function transformArguments(name, script, replace = false) {
const args = ['GRAPH.UDF', 'LOAD'];
if (replace) {
args.push('REPLACE');
}
args.push(name);
// If script is a function, convert it to string and add falkor.register() call
let scriptStr;
if (typeof script === 'function') {
const functionStr = script.toString();
const functionName = script.name;
if (!functionName) {
throw new Error('Function must have a name to be registered as a UDF');
}
// Add the function definition and register call
scriptStr = `${functionStr}\nfalkor.register("${functionName}", ${functionName});`;
}
else {
scriptStr = script;
}
args.push(scriptStr);
return args;
}