13 lines
542 B
TypeScript
13 lines
542 B
TypeScript
|
import { TypedResponseError } from './classes.typedresponseerror.js';
|
||
|
import * as plugins from './plugins.js';
|
||
|
|
||
|
export class TypedTools {
|
||
|
public async passGuards<T = any>(guardsArg: plugins.smartguard.Guard<T>[], dataArg: T) {
|
||
|
const guardSet = new plugins.smartguard.GuardSet<T>(guardsArg);
|
||
|
const guardResult = await guardSet.allGuardsPass(dataArg);
|
||
|
if (!guardResult) {
|
||
|
const failedHint = await guardSet.getFailedHint(dataArg);
|
||
|
throw new TypedResponseError(`guard failed: ${failedHint}`, { failedHint });
|
||
|
}
|
||
|
}
|
||
|
}
|