@diullei/codeguardian
Version:
Open-source developer tool to validate and enforce architectural rules, especially for AI-generated code
39 lines • 1.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RuleFactory = void 0;
const yaml_1 = require("yaml");
class RuleFactory {
builders = new Map();
ruleIdCounter = 0;
register(type, builder) {
this.builders.set(type, builder);
}
create(config) {
const builder = this.builders.get(config.type);
if (!builder) {
throw new Error(`Unknown rule type: ${config.type}`);
}
return builder.build(config, this);
}
loadFromYAML(yaml) {
const config = (0, yaml_1.parse)(yaml);
let ruleConfig;
if (config.rule) {
ruleConfig = config.rule;
ruleConfig.id = config.id || this.generateRuleId();
}
else if (config.type) {
ruleConfig = config;
ruleConfig.id = config.id || this.generateRuleId();
}
else {
throw new Error('Invalid configuration: missing "type" property');
}
return this.create(ruleConfig);
}
generateRuleId() {
return `rule_${++this.ruleIdCounter}`;
}
}
exports.RuleFactory = RuleFactory;
//# sourceMappingURL=RuleFactory.js.map