mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	This commit prepares the frontend code to be consumed by webpack. It is a hack: In theory, modules should be declaring and importing the modules they depend on and the globals they expose directly. However, that requires significant per-module work, which we don't really want to block moving our toolchain to webpack on. So we expose the modules by setting window.varName = varName; as needed in the js files.
		
			
				
	
	
		
			68 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			68 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
var schema = (function () {
 | 
						|
 | 
						|
var exports = {};
 | 
						|
 | 
						|
/*
 | 
						|
 | 
						|
These runtime schema validators are defensive and
 | 
						|
should always succeed, so we don't necessarily want
 | 
						|
to translate these.  These are very similar to server
 | 
						|
side validators in zerver/lib/validator.py.
 | 
						|
 | 
						|
*/
 | 
						|
 | 
						|
exports.check_string = function (var_name, val) {
 | 
						|
    if (!_.isString(val)) {
 | 
						|
        return var_name + ' is not a string';
 | 
						|
    }
 | 
						|
};
 | 
						|
 | 
						|
exports.check_record = function (var_name, val, fields) {
 | 
						|
    if (!_.isObject(val)) {
 | 
						|
        return var_name + ' is not a record';
 | 
						|
    }
 | 
						|
 | 
						|
    var field_results = _.map(fields, function (f, field_name) {
 | 
						|
        if (val[field_name] === undefined) {
 | 
						|
            return field_name + ' is missing';
 | 
						|
        }
 | 
						|
        return f(field_name, val[field_name]);
 | 
						|
    });
 | 
						|
 | 
						|
    var msg = _.filter(field_results).sort().join(', ');
 | 
						|
 | 
						|
    if (msg) {
 | 
						|
        return 'in ' + var_name + ' ' + msg;
 | 
						|
    }
 | 
						|
};
 | 
						|
 | 
						|
exports.check_array = function (var_name, val, checker) {
 | 
						|
    if (!_.isArray(val)) {
 | 
						|
        return var_name + ' is not an array';
 | 
						|
    }
 | 
						|
 | 
						|
    var msg;
 | 
						|
 | 
						|
    _.find(val, function (item) {
 | 
						|
        var res = checker('item', item);
 | 
						|
 | 
						|
        if (res) {
 | 
						|
            msg = res;
 | 
						|
            return msg;
 | 
						|
        }
 | 
						|
    });
 | 
						|
 | 
						|
    if (msg) {
 | 
						|
        return 'in ' + var_name + ' we found an item where ' + msg;
 | 
						|
    }
 | 
						|
};
 | 
						|
 | 
						|
return exports;
 | 
						|
 | 
						|
}());
 | 
						|
if (typeof module !== 'undefined') {
 | 
						|
    module.exports = schema;
 | 
						|
}
 | 
						|
 | 
						|
window.schema = schema;
 |