20 lines
483 B
TypeScript
20 lines
483 B
TypeScript
import * as plugins from './smartguard.plugins.js';
|
|
|
|
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 exec(dataArg: T) {
|
|
const result = await this.guardFunction(dataArg);
|
|
return result;
|
|
}
|
|
}
|