Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = async function runAction (ctx, domain, id, args, setting) {
var returns = []
if (domain) {
var modAction = await ctx.modules.get(ctx, domain, id)
if (!ktypes.isAction(modAction)) {
throw new Error('`' + domain + ':' + id + '` is not an action')
}
returns = await modAction(ctx, args)
} else if (id === 'noop') {
returns = []// returns nothing
} else if (ctx.scope.has(id)) {
var definedAction = ctx.scope.get(id)
if (!ktypes.isAction(definedAction)) {
throw new Error('`' + id + '` is not defined as an action')
}
returns = await definedAction(ctx, args)
} else if (id === 'send_directive' || id === 'sendDirective') {
returns = await sendDirective(ctx, args)
} else {
throw new Error('`' + id + '` is not defined')
}
_.each(setting, function (id, i) {
var val = returns[i]
if (val === void 0 || _.isNaN(val)) {
val = null
}
ctx.scope.set(id, val)
})
}
module.exports = async function runAction (ctx, domain, id, args, setting) {
var returns = []
if (domain) {
var modAction = await ctx.modules.get(ctx, domain, id)
if (!ktypes.isAction(modAction)) {
throw new Error('`' + domain + ':' + id + '` is not an action')
}
returns = await modAction(ctx, args)
} else if (id === 'noop') {
returns = []// returns nothing
} else if (ctx.scope.has(id)) {
var definedAction = ctx.scope.get(id)
if (!ktypes.isAction(definedAction)) {
throw new Error('`' + id + '` is not defined as an action')
}
returns = await definedAction(ctx, args)
} else if (id === 'send_directive' || id === 'sendDirective') {
returns = await sendDirective(ctx, args)
} else {
throw new Error('`' + id + '` is not defined')
}
module.exports = cocb.wrap(function*(ctx, domain, id, args, setting){
var returns = [];
if(domain){
returns = yield ctx.modules.action(ctx, domain, id, args);
}else if(id === "noop"){
returns = [];//returns nothing
}else if(ctx.scope.has(id)){
var definedAction = ctx.scope.get(id);
if( ! ktypes.isAction(definedAction)){
throw new Error("`" + id + "` is not defined as an action");
}
returns = yield definedAction(ctx, args);
}else if(id === "send_directive" || id === "sendDirective"){
returns = [
//returns only one value
yield send_directive(ctx, args)
];
}else{
throw new Error("`" + id + "` is not defined");
}
_.each(setting, function(id, i){
var val = returns[i];
if(val === void 0 || _.isNaN(val)){
val = null;
}
var applyFn = cocb.wrap(function*(fn, ctx, args){
if(ktypes.isAction(fn)){
throw new Error("actions can only be called in the rule action block");
}
if( ! ktypes.isFunction(fn)){
throw new Error("Not a function");
}
return yield fn(ctx, args);
});
var applyFn = cocb.wrap(function*(fn, ctx, args){
if(ktypes.isAction(fn)){
throw new Error("actions can only be called in the rule action block");
}
if( ! ktypes.isFunction(fn)){
throw new Error("Not a function");
}
return yield fn(ctx, args);
});