lib/misc/factories_schema_helpers.js
/**
 * check correctness of option fields against scheme
 *
 * @method  check_options_correctness_against_schema
 *
 */
check correctness of option fields against scheme
@method  check_options_correctness_against_schema
check correctness of option fields against scheme @method check_options_correctness_against_schema
function check_options_correctness_against_schema(obj, schema, options) {
    if (!exports.doDebug) {
        return ; 
    }
    if (!_.isObject(options)) {
        var message = " Invalid options specified while trying to construct a ".red.bold + " " + schema.name.yellow;
        message += " expecting a ".red.bold + " Object ".yellow;
        message += " and got a ".red.bold + (typeof options).yellow + " instead ".red.bold;
        console.log(" Schema  = ", schema);
        console.log(" options = ", options);
        throw new Error(message);
    }
    if (options instanceof obj.constructor) {
        return true;
    }
    var possible_fields = obj.constructor.possibleFields;
    var current_fields = Object.keys(options);
    var invalid_options_fields = _.difference(current_fields, possible_fields);
    if (invalid_options_fields.length > 0) {
        console.log("expected schema", schema.name);
        console.log("schema", schema);
        console.log("possible_fields", possible_fields);
        require("lib/misc/utils").display_trace_from_this_projet_only();
        console.log("invalid_options_fields= ", invalid_options_fields);
    }
    if (invalid_options_fields.length !== 0) {
        throw new Error(" invalid field found in option :" + JSON.stringify(invalid_options_fields));
    }
    return true;
}
function check_options_correctness_against_schema ( obj , schema , options ) { if ( ! exports . doDebug ) { return ; } if ( ! _ . isObject ( options ) ) { var message = " Invalid options specified while trying to construct a " . red . bold + " " + schema . name . yellow ; message += " expecting a " . red . bold + " Object " . yellow ; message += " and got a " . red . bold + ( typeof options ) . yellow + " instead " . red . bold ; console . log ( " Schema  = " , schema ) ; console . log ( " options = " , options ) ; throw new Error ( message ) ; } if ( options instanceof obj . constructor ) { return true ; } var possible_fields = obj . constructor . possibleFields ; var current_fields = Object . keys ( options ) ; var invalid_options_fields = _ . difference ( current_fields , possible_fields ) ; if ( invalid_options_fields . length > 0 ) { console . log ( "expected schema" , schema . name ) ; console . log ( "schema" , schema ) ; console . log ( "possible_fields" , possible_fields ) ; require ( "lib/misc/utils" ) . display_trace_from_this_projet_only ( ) ; console . log ( "invalid_options_fields= " , invalid_options_fields ) ; } if ( invalid_options_fields . length !== 0 ) { throw new Error ( " invalid field found in option :" + JSON . stringify ( invalid_options_fields ) ) ; } return true ; }
check correctness of option fields against scheme
 @method  check_options_correctness_against_schema
check correctness of option fields against scheme @method check_options_correctness_against_schema
// ignoring set // istanbul ignore next // istanbul ignore next // extract the possible fields from the schema. // extracts the fields exposed by the option object // get a list of field that are in the 'options' object but not in schema /* istanbul ignore next */