function _class_call_check(instance, Constructor) {
    if (!(instance instanceof Constructor)) {
        throw new TypeError("Cannot call a class as a function");
    }
}
function _defineProperties(target, props) {
    for(var i = 0; i < props.length; i++){
        var descriptor = props[i];
        descriptor.enumerable = descriptor.enumerable || false;
        descriptor.configurable = true;
        if ("value" in descriptor) descriptor.writable = true;
        Object.defineProperty(target, descriptor.key, descriptor);
    }
}
function _create_class(Constructor, protoProps, staticProps) {
    if (protoProps) _defineProperties(Constructor.prototype, protoProps);
    if (staticProps) _defineProperties(Constructor, staticProps);
    return Constructor;
}
function _define_property(obj, key, value) {
    if (key in obj) {
        Object.defineProperty(obj, key, {
            value: value,
            enumerable: true,
            configurable: true,
            writable: true
        });
    } else {
        obj[key] = value;
    }
    return obj;
}
import Ajv from "ajv";
import addFormats from "ajv-formats";
import lowcodeSchema from "./schema.definition.json";
export var SchemaValidator = /*#__PURE__*/ function() {
    "use strict";
    function SchemaValidator() {
        _class_call_check(this, SchemaValidator);
        _define_property(this, "ajv", void 0);
        this.ajv = new Ajv({
            allErrors: true,
            verbose: true,
            strict: false
        });
        addFormats(this.ajv);
    }
    _create_class(SchemaValidator, [
        {
            /**
   * 验证JSON数据是否符合低代码组件规范
   * @param data 要验证的JSON数据
   * @returns 验证结果对象
   */ key: "validate",
            value: function validate(data) {
                var validate = this.ajv.compile(lowcodeSchema);
                var valid = validate(data);
                if (!valid) {
                    var errors = (validate.errors || []).map(function(error) {
                        return {
                            path: error.instancePath,
                            message: error.message || '未知错误'
                        };
                    });
                    return {
                        valid: false,
                        errors: errors
                    };
                }
                return {
                    valid: true,
                    errors: []
                };
            }
        }
    ]);
    return SchemaValidator;
}();
// 导出单例实例
export var mdDataSchemaValidator = new SchemaValidator();
