import { NamedEntity } from './types'; /** * Environment parameter representing a key-value configuration pair */ export class EnvParam implements NamedEntity { constructor( public id?: number, public name?: string, public value?: string, public isChanged: boolean = false ) {} /** * Marks the parameter as changed (backward compatibility) */ public Changed(changed: boolean = true): EnvParam { return this.markChanged(changed); } /** * Marks the parameter as changed */ public markChanged(changed: boolean = true): EnvParam { return new EnvParam(this.id, this.name, this.value, changed); } /** * Creates a copy of this parameter with updated values */ public update(updates: Partial): EnvParam { return new EnvParam( updates.id ?? this.id, updates.name ?? this.name, updates.value ?? this.value, updates.isChanged ?? this.isChanged ); } /** * Sanitizes HTML special characters (instance method for backward compatibility) */ public sanitize(value?: string): string { const v = value ?? this.value ?? ''; return EnvParam.sanitize(v); } /** * Sanitizes HTML special characters (static method) */ public static sanitize(value: string): string { return value .replace(/&/g, '&') .replace(//g, '>') .replace(/"/g, '"') .replace(/'/g, '''); } /** * Humanizes the value (backward compatibility) */ public humanize(value?: string): string { return value ?? this.value ?? ''; } /** * Validates that the parameter has required fields */ public isValid(): boolean { return !!(this.name && this.name.trim() !== ''); } }