typedrequest/ts/classes.typedtools.ts
2024-05-30 22:41:49 +02:00

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 });
}
}
}