pico-engine-core
Advanced tools
Comparing version 0.26.0 to 0.27.0
{ | ||
"name": "pico-engine-core", | ||
"version": "0.26.0", | ||
"version": "0.27.0", | ||
"description": "The core javascript api for the pico-engine. (no http, logging, process management etc...)", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -10,4 +10,9 @@ module.exports = function(core){ | ||
}); | ||
} | ||
}, | ||
del: function(ctx, id, callback){ | ||
core.db.removeAppVar(ctx.rid, id, function(err){ | ||
callback(err); | ||
}); | ||
}, | ||
}; | ||
}; |
@@ -10,4 +10,9 @@ module.exports = function(core){ | ||
}); | ||
} | ||
}, | ||
del: function(ctx, id, callback){ | ||
core.db.removeEntVar(ctx.pico_id, ctx.rid, id, function(err){ | ||
callback(err); | ||
}); | ||
}, | ||
}; | ||
}; |
@@ -38,11 +38,2 @@ var _ = require("lodash"); | ||
raise: mkKRLfn([ | ||
"domain", | ||
"type", | ||
"attributes", | ||
"for_rid", | ||
], function(args, ctx, callback){ | ||
ctx.raiseEvent(args, callback); | ||
}), | ||
//TODO this is technically a RuleAction | ||
@@ -49,0 +40,0 @@ //TODO should this rather return info for event to be signaled? |
@@ -50,4 +50,16 @@ var _ = require("lodash"); | ||
callback(new Error("Not defined `" + domain + ":" + id + "`")); | ||
}) | ||
}), | ||
del: cocb.toYieldable(function(ctx, domain, id, callback){ | ||
if(!_.has(modules, domain)){ | ||
callback(new Error("Module not defined `" + domain + ":" + id + "`")); | ||
return; | ||
} | ||
if(!_.has(modules[domain], "del")){ | ||
callback(new Error("Cannot clear/delete to `" + domain + ":*`")); | ||
return; | ||
} | ||
modules[domain].del(ctx, id, callback); | ||
return; | ||
}), | ||
}; | ||
}; |
@@ -86,8 +86,11 @@ var _ = require("lodash"); | ||
ctx = core.mkCTX({ | ||
event: ctx.event, | ||
pico_id: ctx.pico_id, | ||
raiseEvent: ctx.raiseEvent, | ||
rid: rule.rid, | ||
rule_name: rule.name, | ||
scope: rule.scope, | ||
pico_id: ctx.pico_id, | ||
event: ctx.event, | ||
raiseEvent: ctx.raiseEvent, | ||
raiseError: ctx.raiseError, | ||
stopRulesetExecution: ctx.stopRulesetExecution, | ||
}); | ||
@@ -142,3 +145,7 @@ | ||
pico_id: ctx.pico_id, | ||
raiseEvent: function(revent, callback){ | ||
stopRulesetExecution: function(){ | ||
ctx.emit("debug", "`last` control statement is stopping ruleset execution"); | ||
schedule = []; | ||
}, | ||
raiseEvent: cocb.toYieldable(function(revent, callback){ | ||
//shape the revent like a normal event | ||
@@ -159,5 +166,27 @@ var event = { | ||
raiseEvent: ctx.raiseEvent, | ||
raiseError: ctx.raiseError, | ||
stopRulesetExecution: ctx.stopRulesetExecution, | ||
}); | ||
raise_ctx.emit("debug", "adding raised event to schedule: " + revent.domain + "/" + revent.type); | ||
scheduleEventRAW(raise_ctx, callback); | ||
}), | ||
raiseError: function*(ctx, level, msg){ | ||
//Because one error often cascades into others, | ||
//limit the number of errors from a single event to just one | ||
schedule = []; | ||
return yield ctx.raiseEvent({ | ||
domain: "system", | ||
type: "error", | ||
attributes: { | ||
level: level, | ||
msg: msg, | ||
error_rid: ctx.rid, | ||
rule_name: ctx.rule_name, | ||
genus: "user", | ||
//species: ??, | ||
}, | ||
//for_rid: ctx.rid, | ||
}); | ||
} | ||
@@ -164,0 +193,0 @@ }); |
@@ -17,3 +17,8 @@ var _ = require("lodash"); | ||
var expected = _.cloneDeep(keys).sort().join(","); | ||
var actual = _.pullAll(_.keys(ctx), std_ctx_keys).sort().join(","); | ||
var actual = _.pullAll(_.map(ctx, function(v, k){ | ||
if(v === void 0 || v === null || _.isNaN(v)){ | ||
throw new Error("Invalid ctx." + k + " is not defined"); | ||
} | ||
return k; | ||
}), std_ctx_keys).sort().join(","); | ||
@@ -38,5 +43,10 @@ if(actual !== expected){ | ||
} | ||
if(_.has(ctx, "event")){ | ||
if(_.has(ctx, "event") && !_.has(ctx, "raiseEvent")){//event durring select/eval event exp | ||
assertCTX_keys(ctx, [ | ||
"event", | ||
"pico_id", | ||
"rule_name", | ||
]); | ||
}else if(_.has(ctx, "event")){//event durring rule body | ||
assertCTX_keys(_.omit(ctx, [ | ||
"raiseEvent",//not during select/eval event exp | ||
"foreach_is_final",//only when doing foreach | ||
@@ -47,2 +57,6 @@ ]), [ | ||
"rule_name", | ||
"raiseEvent", | ||
"raiseError", | ||
"stopRulesetExecution", | ||
]); | ||
@@ -49,0 +63,0 @@ }else if(_.has(ctx, "query")){ |
Sorry, the diff of this file is too big to display
171431
4575