import * as plugins from './smartguard.plugins.js'; import { Guard, type TGuardFunction } from './smartguard.classes.guard.js'; /** * Extended GuardSet that inherits from Guard * and provides additional functionalities. */ export class GuardSet extends Guard { public guards: Array>; constructor(guardArray: Array> = []) { super(async (dataArg: T) => { return this.allGuardsPass(dataArg); }) this.guards = guardArray; } /** * executes all guards in all guardSets against a data argument * @param dataArg */ public async executeAllGuardsWithData(dataArg: T) { const resultPromises: Array> = []; for (const guard of this.guards) { const guardResultPromise = guard.executeGuardWithData(dataArg); resultPromises.push(guardResultPromise); } const results = await Promise.all(resultPromises); return results; } /** * checks if all guards pass * @param dataArg */ public async allGuardsPass(dataArg: T): Promise { const results = await this.executeAllGuardsWithData(dataArg); return results.every(result => result); } /** * checks if any guard passes * @param dataArg */ public async anyGuardsPass(dataArg: T): Promise { const results = await this.executeAllGuardsWithData(dataArg); return results.some(result => result); } }