| 12345678910111213141516171819202122232425262728293031 |
- import type {AssertRule} from "~/types/interfaces";
- import { MaxAssert } from './MaxAssert';
- import { NullableAssert } from './NullableAssert';
- import { TypeAssert } from './TypeAssert';
- export class AssertRuleRegistry {
- private rules: AssertRule[] = [];
- constructor() {
- this.rules = [
- new MaxAssert(),
- new NullableAssert(),
- new TypeAssert(),
- ];
- }
- getValidators(asserts: Record<string, any>): ((value: any) => true | string)[] {
- const allRules: ((value: any) => true | string)[] = [];
- for (const key in asserts) {
- const criteria = asserts[key];
- const rule = this.rules.find(r => r.supports(key));
- if (rule) {
- allRules.push(rule.createRule(criteria));
- }
- }
- return allRules;
- }
- }
|