typedrequest/ts/classes.typedtools.ts

13 lines
542 B
TypeScript
Raw Normal View History

2024-05-30 20:41:49 +00:00
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 });
}
}
}