Files
privacy.sexy/src/domain/Script.ts
2020-11-01 18:36:55 +01:00

28 lines
914 B
TypeScript

import { BaseEntity } from '@/infrastructure/Entity/BaseEntity';
import { IScript } from './IScript';
import { RecommendationLevel } from './RecommendationLevel';
import { IScriptCode } from './IScriptCode';
export class Script extends BaseEntity<string> implements IScript {
constructor(
public readonly name: string,
public readonly code: IScriptCode,
public readonly documentationUrls: ReadonlyArray<string>,
public readonly level?: RecommendationLevel) {
super(name);
if (!code) {
throw new Error(`undefined code (script: ${name})`);
}
validateLevel(level);
}
public canRevert(): boolean {
return Boolean(this.code.revert);
}
}
function validateLevel(level?: RecommendationLevel) {
if (level !== undefined && !(level in RecommendationLevel)) {
throw new Error(`invalid level: ${level}`);
}
}