diff --git a/.vscode/settings.json b/.vscode/settings.json index 6763058..01d2b8d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -11,7 +11,13 @@ }, "gitzone": { "type": "object", - "description": "settings for gitzone" + "description": "settings for gitzone", + "properties": { + "projectType": { + "type": "string", + "enum": ["website", "element", "service", "npm"] + } + } } } } diff --git a/npmextra.json b/npmextra.json index 90d38ff..229baf6 100644 --- a/npmextra.json +++ b/npmextra.json @@ -1,5 +1,6 @@ { "gitzone": { + "projectType": "npm", "module": { "githost": "gitlab.com", "gitscope": "pushrocks", diff --git a/package.json b/package.json index ba74bef..d146ddb 100644 --- a/package.json +++ b/package.json @@ -32,4 +32,4 @@ "npmextra.json", "readme.md" ] -} +} \ No newline at end of file diff --git a/test/test.ts b/test/test.ts index 4380e10..7a8a21b 100644 --- a/test/test.ts +++ b/test/test.ts @@ -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(); diff --git a/ts/index.ts b/ts/index.ts index a037097..472b8a1 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -1 +1 @@ -export * from './smartrule.classes.smartrule'; \ No newline at end of file +export * from './smartrule.classes.smartrule'; diff --git a/ts/smartrule.classes.rule.ts b/ts/smartrule.classes.rule.ts index c0bca7d..cb118ee 100644 --- a/ts/smartrule.classes.rule.ts +++ b/ts/smartrule.classes.rule.ts @@ -12,10 +12,15 @@ export class Rule { public checkFunction: TCheckFunc; public actionFunction: TActionFunc; - constructor(smartRuleRef: SmartRule, priorityArg: number, checkFunctionArg: TCheckFunc, actionFunctionArg: TActionFunc) { + constructor( + smartRuleRef: SmartRule, + priorityArg: number, + checkFunctionArg: TCheckFunc, + actionFunctionArg: TActionFunc + ) { this.smartRuleRef = smartRuleRef; this.priority = priorityArg; this.checkFunction = checkFunctionArg; this.actionFunction = actionFunctionArg; } -} \ No newline at end of file +} diff --git a/ts/smartrule.classes.smartrule.ts b/ts/smartrule.classes.smartrule.ts index f95b74b..4bf1a6d 100644 --- a/ts/smartrule.classes.smartrule.ts +++ b/ts/smartrule.classes.smartrule.ts @@ -6,11 +6,11 @@ export class SmartRule { /** * makes a decision based on the given obect and the given rules - * @param objectArg + * @param objectArg */ public async makeDecision(objectArg: T) { // lets sort the rules - this.rules = this.rules.sort((a,b) => { + this.rules = this.rules.sort((a, b) => { if (a.priority > b.priority) { return 1; } else { @@ -32,39 +32,49 @@ export class SmartRule { 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) => { - if (current.includes('continue') || previous.includes('continue')) { - return 'continue'; - } else { - return 'stop'; + 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; } }; - await runNextBatch(0,0); + await runNextBatch(0, 0); } - public createRule(priorityArg: number, checkFunctionArg: TCheckFunc, actionFunctionArg: TActionFunc) { + public createRule( + priorityArg: number, + checkFunctionArg: TCheckFunc, + actionFunctionArg: TActionFunc + ) { const rule = new Rule(this, priorityArg, checkFunctionArg, actionFunctionArg); this.rules.push(rule); } -} \ No newline at end of file +}