smartguard/ts/smartguard.classes.guardset.ts

24 lines
684 B
TypeScript

import * as plugins from './smartguard.plugins.js';
import { Guard } from './smartguard.classes.guard.js';
/**
* a guardSet is a set of guards that need to be fulfilled
*/
export class GuardSet<T> {
public guards: Array<Guard<T>>;
public passed: boolean;
constructor(guardsArrayArg: Array<Guard<T>>) {
this.guards = guardsArrayArg;
}
public async executeGuardsWithData(dataArg: T) {
const resultPromises: Array<Promise<boolean>> = [];
for (const guard of this.guards) {
const resultPromise = guard.executeGuardWithData(dataArg);
resultPromises.push(resultPromise);
}
const results = Promise.all(resultPromises);
return results;
}
}