fix(core): update

This commit is contained in:
Philipp Kunz 2020-01-24 07:11:25 +00:00
parent 17287a9ba3
commit 1493848dc8
7 changed files with 42 additions and 20 deletions

View File

@ -11,7 +11,13 @@
},
"gitzone": {
"type": "object",
"description": "settings for gitzone"
"description": "settings for gitzone",
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm"]
}
}
}
}
}

View File

@ -1,5 +1,6 @@
{
"gitzone": {
"projectType": "npm",
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",

View File

@ -27,7 +27,7 @@ tap.test('make a decision based on an object', async () => {
testSmartruleInstance.makeDecision({
id: '123456',
body: 'hello, there. This is a cool message!'
})
});
});
tap.start();

View File

@ -12,7 +12,12 @@ export class Rule<T> {
public checkFunction: TCheckFunc<T>;
public actionFunction: TActionFunc;
constructor(smartRuleRef: SmartRule<T>, priorityArg: number, checkFunctionArg: TCheckFunc<T>, actionFunctionArg: TActionFunc) {
constructor(
smartRuleRef: SmartRule<T>,
priorityArg: number,
checkFunctionArg: TCheckFunc<T>,
actionFunctionArg: TActionFunc
) {
this.smartRuleRef = smartRuleRef;
this.priority = priorityArg;
this.checkFunction = checkFunctionArg;

View File

@ -32,29 +32,35 @@ export class SmartRule<T> {
const outcomes: TTreeActionResult[] = [];
for (const rule of nextBatch) {
const checkResult = await rule.checkFunction(objectArg);
checkResult ? null : console.log('WARNING!!! Please make sure your rule always returns a statement of how to continue!');
checkResult
? null
: console.log(
'WARNING!!! Please make sure your rule always returns a statement of how to continue!'
);
if (checkResult.startsWith("apply")) {
if (checkResult.startsWith('apply')) {
await rule.actionFunction(objectArg); // here the action function is run
}
outcomes.push(checkResult);
}
if (outcomes.length > 0) {
const finalOutcomeOfBatch: TTreeActionResult = outcomes.reduce((previous, current, index, array) => {
const finalOutcomeOfBatch: TTreeActionResult = outcomes.reduce(
(previous, current, index, array) => {
if (current.includes('continue') || previous.includes('continue')) {
return 'continue';
} else {
return 'stop';
}
});
}
);
if (finalOutcomeOfBatch === 'stop') {
return;
}
}
if (runRulesAmount < this.rules.length) {
await runNextBatch((startPriority + 1), runRulesAmount);
await runNextBatch(startPriority + 1, runRulesAmount);
} else {
return;
}
@ -63,7 +69,11 @@ export class SmartRule<T> {
await runNextBatch(0, 0);
}
public createRule(priorityArg: number, checkFunctionArg: TCheckFunc<T>, actionFunctionArg: TActionFunc) {
public createRule(
priorityArg: number,
checkFunctionArg: TCheckFunc<T>,
actionFunctionArg: TActionFunc
) {
const rule = new Rule<T>(this, priorityArg, checkFunctionArg, actionFunctionArg);
this.rules.push(rule);
}