smartguard/ts/index.ts

20 lines
663 B
TypeScript

import * as plugins from './smartguard.plugins.js';
import { Guard } from './classes.guard.js';
export * from './classes.guarderror.js';
export * from './classes.guard.js';
export * from './classes.guardset.js';
import { GuardSet } from './classes.guardset.js';
import { GuardError } from './classes.guarderror.js';
export const passGuardsOrReject = async <T>(dataArg: T, guards: Array<Guard<T>>) => {
const guardSet = new GuardSet<T>(guards);
const result = await guardSet.allGuardsPass(dataArg);
if (!result) {
const failedHint = await guardSet.getFailedHint(dataArg);
throw new GuardError(`Guards failed:
${failedHint}
`);
}
return ;
};