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 , public readonly code , public readonly documentationUrls , public readonly level ? ) { super ( name ) ; if ( ! code ) { throw new Error ( `undefined code (script: ${ name })` ) ; } validateLevel ( level ) ; } public canRevert ( ) { return Boolean ( this . code . revert ) ; } } function validateLevel ( level ? ) { if ( level !== undefined && ! ( level in RecommendationLevel ) ) { throw new Error ( `invalid level: ${ level }` ) ; } }