import {ZodType} from "zod"; import FlaggerConstraintInterface from "./FlaggerConstraintInterface"; export default class FlaggerConstraint { #config: FlaggerConstraintConfigType | Record; constructor(config: Record = {}, configSchema: ZodType | null = null) { if (config instanceof ZodType) { this.#config = configSchema!.parse(config); } this.#config = config; } public async checkIfShouldBeActivated(): Promise { if (typeof (this as typeof this & FlaggerConstraintInterface).canBeActivated !== 'function') { throw new Error('Flagger activator must implement FlaggerConstraintInterface'); } return (this as typeof this & FlaggerConstraintInterface).canBeActivated(); } protected get config(): FlaggerConstraintConfigType | Record { return this.#config; } }