2022-03-21 20:53:46 +00:00
|
|
|
import * as plugins from './smartguard.plugins.js';
|
2019-08-07 14:31:53 +00:00
|
|
|
|
|
|
|
export type TGuardFunction<T> = (dataArg: T) => Promise<boolean>;
|
|
|
|
|
|
|
|
export class Guard<T> {
|
2019-08-07 14:34:34 +00:00
|
|
|
private guardFunction: TGuardFunction<T>;
|
2019-08-07 14:31:53 +00:00
|
|
|
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;
|
|
|
|
}
|
2019-08-07 14:34:34 +00:00
|
|
|
}
|