smartguard/ts/index.ts

20 lines
663 B
TypeScript
Raw Normal View History

2022-03-21 20:53:46 +00:00
import * as plugins from './smartguard.plugins.js';
2024-08-25 16:03:37 +00:00
import { Guard } from './classes.guard.js';
export * from './classes.guarderror.js';
export * from './classes.guard.js';
export * from './classes.guardset.js';
2019-06-18 12:51:13 +00:00
2024-08-25 16:03:37 +00:00
import { GuardSet } from './classes.guardset.js';
import { GuardError } from './classes.guarderror.js';
2024-05-30 14:57:18 +00:00
export const passGuardsOrReject = async <T>(dataArg: T, guards: Array<Guard<T>>) => {
2019-08-07 14:31:53 +00:00
const guardSet = new GuardSet<T>(guards);
2024-05-30 14:57:18 +00:00
const result = await guardSet.allGuardsPass(dataArg);
if (!result) {
2024-08-25 16:03:37 +00:00
const failedHint = await guardSet.getFailedHint(dataArg);
throw new GuardError(`Guards failed:
${failedHint}
`);
2019-08-07 14:31:53 +00:00
}
2024-05-30 14:57:18 +00:00
return ;
2019-08-07 14:34:34 +00:00
};