19 lines
496 B
TypeScript
19 lines
496 B
TypeScript
import * as plugins from './smartguard.plugins';
|
|
|
|
export type TGuardFunction<T> = (dataArg: T) => Promise<boolean>;
|
|
|
|
export class Guard<T> {
|
|
private guardFunction: TGuardFunction<T>;
|
|
constructor(guardFunctionArg: TGuardFunction<T>) {
|
|
this.guardFunction = guardFunctionArg;
|
|
}
|
|
|
|
/**
|
|
* executes the guard against a data argument;
|
|
* @param dataArg
|
|
*/
|
|
public async executeGuardWithData(dataArg: T) {
|
|
const result = await this.guardFunction(dataArg);
|
|
return result;
|
|
}
|
|
} |