add support for different recommendation levels: strict and standard

This commit is contained in:
undergroundwires
2020-10-19 14:51:42 +01:00
parent 978bab0b81
commit 14be3017c5
20 changed files with 954 additions and 654 deletions

View File

@@ -1,5 +1,6 @@
import { BaseEntity } from '@/infrastructure/Entity/BaseEntity';
import { IScript } from './IScript';
import { RecommendationLevel } from './RecommendationLevel';
export class Script extends BaseEntity<string> implements IScript {
constructor(
@@ -7,9 +8,10 @@ export class Script extends BaseEntity<string> implements IScript {
public readonly code: string,
public readonly revertCode: string,
public readonly documentationUrls: ReadonlyArray<string>,
public readonly isRecommended: boolean) {
public readonly level?: RecommendationLevel) {
super(name);
validateCode(name, code);
validateLevel(level);
if (revertCode) {
validateCode(name, revertCode);
if (code === revertCode) {
@@ -22,6 +24,12 @@ export class Script extends BaseEntity<string> implements IScript {
}
}
function validateLevel(level?: RecommendationLevel) {
if (level !== undefined && !(level in RecommendationLevel)) {
throw new Error(`invalid level: ${level}`);
}
}
function validateCode(name: string, code: string): void {
if (!code || code.length === 0) {
throw new Error(`Code of ${name} is empty or null`);