add module validator

This commit is contained in:
Bowen Tan 2021-12-15 15:43:18 +08:00
parent c56de04500
commit 50614ab04a

View File

@ -42,4 +42,33 @@ class ComponentPropertyValidatorRule implements ComponentValidatorRule {
return results;
}
}
export const ComponentRules = [new ComponentPropertyValidatorRule()];
class ModuleValidatorRule implements ComponentValidatorRule {
kind: 'component' = 'component';
validate({ component, registry }: ComponentValidateContext): ValidateErrorResult[] {
if (component.type !== 'core/v1/moduleContainer') {
return [];
}
const results: ValidateErrorResult[] = [];
let moduleSpec
try {
moduleSpec = registry.getModuleByType(component.properties.type as string);
} catch (err) {
moduleSpec = undefined
}
if (!moduleSpec) {
results.push({
message: `Module is not registered: ${component.properties.type}.`,
componentId: component.id,
property: '/type',
});
}
return results;
}
}
export const ComponentRules = [
new ComponentPropertyValidatorRule(),
new ModuleValidatorRule(),
];