core/MetaModelManager.js
function validateMetaType(name, metaType) {
        assert(_.isObject(metaType), ERR_METATYPE_OBJECT, { name: name });
        assert(metaType.name, ERR_REQUIRE_FIELD, { metaType: metaType, field: "name" });
        assert(metaType.kind === "enum" || metaType.kind === "class", ERR_METATYPE_KIND, { metaType: metaType });

        // Enum MetaType
        if (metaType.kind === "enum") {
            var lits = metaType.literals;
            assert(Array.isArray(lits) && lits.length > 0, ERR_ENUM_HAS_LITERALS, { metaType: metaType });

            // Check duplicated literal
            _.each(lits, function (lit1) {
                var len = _.filter(lits, function (lit2) { return lit2 === lit1; }).length;
                assert(len === 1, ERR_DUPLICATED_LITERAL, { metaType: metaType, literal: lit1 });
            });
        }

        // Class MetaType
        if (metaType.kind === "class") {

            // Check .super
            if (metaType.super) {
                assert(metaType.super && _global.meta[metaType.super], ERR_TYPE_NOT_FOUND, { metaType: metaType, type: metaType.super, field: "super" });
            }

            // Check Attributes
            if (metaType.attributes) {
                assert(Array.isArray(metaType.attributes), ERR_FIELD_TYPE, { metaType: metaType, field: "attributes", type: "Array" });
                _.each(metaType.attributes, function (attribute) {

                    // check 'name'
                    assert(attribute.name, ERR_UNNAMED_ATTRIBUTE, { metaType: metaType });

                    // Check 'kind'
                    assert(_.contains(["prim", "enum", "var", "ref", "refs", "obj", "objs", "custom"], attribute.kind), ERR_ATTRIBUTE_KIND, { metaType: metaType, attribute: attribute });

                    // Check 'type'
                    if (attribute.kind === "prim") {
                        assert(_.contains(["Integer", "String", "Boolean", "Real"], attribute.type), ERR_ATTRIBUTE_PRIM_TYPE, { metaType: metaType, attribute: attribute });
                    } else if (attribute.kind !== "custom") {
                        assert(_global.meta[attribute.type], ERR_TYPE_NOT_FOUND, { metaType: metaType, type: attribute.type, field: attribute.name + ".type" });
                    }

                    // Check duplicated attribute in all inherited attributes
                    var len = _.filter(getMetaAttributes(metaType.name), function (attr) { return attr.name === attribute.name; }).length;
                    assert(len === 1, ERR_DUPLICATED_ATTRIBUTE, { metaType: metaType, attribute: attribute });
                });
            }
        }
    }
function validateMetaType(name, metaType) {
        assert(_.isObject(metaType), ERR_METATYPE_OBJECT, { name: name });
        assert(metaType.name, ERR_REQUIRE_FIELD, { metaType: metaType, field: "name" });
        assert(metaType.kind === "enum" || metaType.kind === "class", ERR_METATYPE_KIND, { metaType: metaType });

        // Enum MetaType
        if (metaType.kind === "enum") {
            var lits = metaType.literals;
            assert(Array.isArray(lits) && lits.length > 0, ERR_ENUM_HAS_LITERALS, { metaType: metaType });

            // Check duplicated literal
            _.each(lits, function (lit1) {
                var len = _.filter(lits, function (lit2) { return lit2 === lit1; }).length;
                assert(len === 1, ERR_DUPLICATED_LITERAL, { metaType: metaType, literal: lit1 });
            });
        }

        // Class MetaType
        if (metaType.kind === "class") {

            // Check .super
            if (metaType.super) {
                assert(metaType.super && _global.meta[metaType.super], ERR_TYPE_NOT_FOUND, { metaType: metaType, type: metaType.super, field: "super" });
            }

            // Check Attributes
            if (metaType.attributes) {
                assert(Array.isArray(metaType.attributes), ERR_FIELD_TYPE, { metaType: metaType, field: "attributes", type: "Array" });
                _.each(metaType.attributes, function (attribute) {

                    // check 'name'
                    assert(attribute.name, ERR_UNNAMED_ATTRIBUTE, { metaType: metaType });

                    // Check 'kind'
                    assert(_.contains(["prim", "enum", "var", "ref", "refs", "obj", "objs", "custom"], attribute.kind), ERR_ATTRIBUTE_KIND, { metaType: metaType, attribute: attribute });

                    // Check 'type'
                    if (attribute.kind === "prim") {
                        assert(_.contains(["Integer", "String", "Boolean", "Real"], attribute.type), ERR_ATTRIBUTE_PRIM_TYPE, { metaType: metaType, attribute: attribute });
                    } else if (attribute.kind !== "custom") {
                        assert(_global.meta[attribute.type], ERR_TYPE_NOT_FOUND, { metaType: metaType, type: attribute.type, field: attribute.name + ".type" });
                    }

                    // Check duplicated attribute in all inherited attributes
                    var len = _.filter(getMetaAttributes(metaType.name), function (attr) { return attr.name === attribute.name; }).length;
                    assert(len === 1, ERR_DUPLICATED_ATTRIBUTE, { metaType: metaType, attribute: attribute });
                });
            }
        }
    }
function validateMetaType ( name , metaType ) { assert ( _ . isObject ( metaType ) , ERR_METATYPE_OBJECT , { name : name } ) ; assert ( metaType . name , ERR_REQUIRE_FIELD , { metaType : metaType , field : "name" } ) ; assert ( metaType . kind === "enum" || metaType . kind === "class" , ERR_METATYPE_KIND , { metaType : metaType } ) ; // Enum MetaType if ( metaType . kind === "enum" ) { var lits = metaType . literals ; assert ( Array . isArray ( lits ) && lits . length > 0 , ERR_ENUM_HAS_LITERALS , { metaType : metaType } ) ; // Check duplicated literal _ . each ( lits , function ( lit1 ) { var len = _ . filter ( lits , function ( lit2 ) { return lit2 === lit1 ; } ) . length ; assert ( len === 1 , ERR_DUPLICATED_LITERAL , { metaType : metaType , literal : lit1 } ) ; } ) ; } // Class MetaType if ( metaType . kind === "class" ) { // Check .super if ( metaType . super ) { assert ( metaType . super && _global . meta [ metaType . super ] , ERR_TYPE_NOT_FOUND , { metaType : metaType , type : metaType . super , field : "super" } ) ; } // Check Attributes if ( metaType . attributes ) { assert ( Array . isArray ( metaType . attributes ) , ERR_FIELD_TYPE , { metaType : metaType , field : "attributes" , type : "Array" } ) ; _ . each ( metaType . attributes , function ( attribute ) { // check 'name' assert ( attribute . name , ERR_UNNAMED_ATTRIBUTE , { metaType : metaType } ) ; // Check 'kind' assert ( _ . contains ( [ "prim" , "enum" , "var" , "ref" , "refs" , "obj" , "objs" , "custom" ] , attribute . kind ) , ERR_ATTRIBUTE_KIND , { metaType : metaType , attribute : attribute } ) ; // Check 'type' if ( attribute . kind === "prim" ) { assert ( _ . contains ( [ "Integer" , "String" , "Boolean" , "Real" ] , attribute . type ) , ERR_ATTRIBUTE_PRIM_TYPE , { metaType : metaType , attribute : attribute } ) ; } else if ( attribute . kind !== "custom" ) { assert ( _global . meta [ attribute . type ] , ERR_TYPE_NOT_FOUND , { metaType : metaType , type : attribute . type , field : attribute . name + ".type" } ) ; } // Check duplicated attribute in all inherited attributes var len = _ . filter ( getMetaAttributes ( metaType . name ) , function ( attr ) { return attr . name === attribute . name ; } ) . length ; assert ( len === 1 , ERR_DUPLICATED_ATTRIBUTE , { metaType : metaType , attribute : attribute } ) ; } ) ; } } }
Validate MetaType Definition
@param {Object} metaType
Validate MetaType Definition