fix(core): update
This commit is contained in:
parent
17287a9ba3
commit
1493848dc8
8
.vscode/settings.json
vendored
8
.vscode/settings.json
vendored
@ -11,7 +11,13 @@
|
|||||||
},
|
},
|
||||||
"gitzone": {
|
"gitzone": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"description": "settings for gitzone"
|
"description": "settings for gitzone",
|
||||||
|
"properties": {
|
||||||
|
"projectType": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["website", "element", "service", "npm"]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"gitzone": {
|
"gitzone": {
|
||||||
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "pushrocks",
|
||||||
|
@ -27,7 +27,7 @@ tap.test('make a decision based on an object', async () => {
|
|||||||
testSmartruleInstance.makeDecision({
|
testSmartruleInstance.makeDecision({
|
||||||
id: '123456',
|
id: '123456',
|
||||||
body: 'hello, there. This is a cool message!'
|
body: 'hello, there. This is a cool message!'
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
@ -12,7 +12,12 @@ export class Rule<T> {
|
|||||||
public checkFunction: TCheckFunc<T>;
|
public checkFunction: TCheckFunc<T>;
|
||||||
public actionFunction: TActionFunc;
|
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.smartRuleRef = smartRuleRef;
|
||||||
this.priority = priorityArg;
|
this.priority = priorityArg;
|
||||||
this.checkFunction = checkFunctionArg;
|
this.checkFunction = checkFunctionArg;
|
||||||
|
@ -10,7 +10,7 @@ export class SmartRule<T> {
|
|||||||
*/
|
*/
|
||||||
public async makeDecision(objectArg: T) {
|
public async makeDecision(objectArg: T) {
|
||||||
// lets sort the rules
|
// lets sort the rules
|
||||||
this.rules = this.rules.sort((a,b) => {
|
this.rules = this.rules.sort((a, b) => {
|
||||||
if (a.priority > b.priority) {
|
if (a.priority > b.priority) {
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
@ -32,38 +32,48 @@ export class SmartRule<T> {
|
|||||||
const outcomes: TTreeActionResult[] = [];
|
const outcomes: TTreeActionResult[] = [];
|
||||||
for (const rule of nextBatch) {
|
for (const rule of nextBatch) {
|
||||||
const checkResult = await rule.checkFunction(objectArg);
|
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
|
await rule.actionFunction(objectArg); // here the action function is run
|
||||||
}
|
}
|
||||||
outcomes.push(checkResult);
|
outcomes.push(checkResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outcomes.length > 0) {
|
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')) {
|
if (current.includes('continue') || previous.includes('continue')) {
|
||||||
return 'continue';
|
return 'continue';
|
||||||
} else {
|
} else {
|
||||||
return 'stop';
|
return 'stop';
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
);
|
||||||
if (finalOutcomeOfBatch === 'stop') {
|
if (finalOutcomeOfBatch === 'stop') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (runRulesAmount < this.rules.length) {
|
if (runRulesAmount < this.rules.length) {
|
||||||
await runNextBatch((startPriority + 1), runRulesAmount);
|
await runNextBatch(startPriority + 1, runRulesAmount);
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
await runNextBatch(0,0);
|
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);
|
const rule = new Rule<T>(this, priorityArg, checkFunctionArg, actionFunctionArg);
|
||||||
this.rules.push(rule);
|
this.rules.push(rule);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user