<commit_before>M.wrap('github/jillix/bind-filter/dev/find.js', function (require, module, exports) {
var currentFilters = {};

function queryBuilder (filters) {
    var self = this;
    var query = {};
    var fieldsInQuery = {};

    for (filter in filters) {
        if (!filters.hasOwnProperty(filter)) continue;

        if (!filters[filter].disabled && self.config.operators[filters[filter].operator]) {
            
            var expression = {};
            var values = filters[filter];
            var value = values.value;
            var operator = self.config.operators[values.operator];
            
            
            // handle operators
            if (operator[0]) {
                expression[values.field] = {};
                expression[values.field][operator[0]] = value;
            } else {
                expression[values.field] = value;
            }
            
            // handle or
            if (fieldsInQuery[values.field]) {
                if (operator[0] === '') {
                    // create or array and move the existing expression to the array
                    if (!query.$or) {
                        query.$or = [{}];
                        query.$or[0][values.field] = query[values.field];
                        delete query[values.field];
                    }
                    query.$or.push(expression);
                } else {
                    query[values.field][operator[0]] = value;
                }
            } else {
                query[values.field] = expression[values.field];
            }
            
            fieldsInQuery[values.field] = 1;
        }
    }
    return {
        t: self.template,
        q: query,
        o: self.options
    };
}

function find (all) {
    var self = this;
    
    if (!self.template) {
        return self.emit('result', new Error('NO_TEMPLATE_SELECTED'));
    }
    
    if (self.crudFindBusy) {
        return self.emit('result', new Error('FILTER_IS_BUSY'));
    }
    
    self.crudFindBusy = true;
    
    // build queries
    self.query = all ? {} : queryBuilder.call(self, self.filters);
    
    if (!self.query) {
        
        if (self.wasEmpty) {
            self.crudFindBusy = false;
            return self.emit('result', new Error('NO_FILTERS_SELECTED'));
        }
        
        self.wasEmpty = true;
        self.query = {};
    } else {
        self.wasEmpty = false;
    }
    
    // get data with crud module
    return self.emit('find', self.query, function (err, data, xhr) {
        self.crudFindBusy = false;
        var count = xhr.getResponseHeader('X-Mono-CRUD-Count');
        self.emit('result', err, data, count);
    });
}

module.exports = find;


return module; });
<commit_msg>Handle error.<commit_after>M.wrap('github/jillix/bind-filter/dev/find.js', function (require, module, exports) {
var currentFilters = {};

function queryBuilder (filters) {
    var self = this;
    var query = {};
    var fieldsInQuery = {};

    for (filter in filters) {
        if (!filters.hasOwnProperty(filter)) continue;

        if (!filters[filter].disabled && self.config.operators[filters[filter].operator]) {
            
            var expression = {};
            var values = filters[filter];
            var value = values.value;
            var operator = self.config.operators[values.operator];
            
            
            // handle operators
            if (operator[0]) {
                expression[values.field] = {};
                expression[values.field][operator[0]] = value;
            } else {
                expression[values.field] = value;
            }
            
            // handle or
            if (fieldsInQuery[values.field]) {
                if (operator[0] === '') {
                    // create or array and move the existing expression to the array
                    if (!query.$or) {
                        query.$or = [{}];
                        query.$or[0][values.field] = query[values.field];
                        delete query[values.field];
                    }
                    query.$or.push(expression);
                } else {
                    query[values.field][operator[0]] = value;
                }
            } else {
                query[values.field] = expression[values.field];
            }
            
            fieldsInQuery[values.field] = 1;
        }
    }
    return {
        t: self.template,
        q: query,
        o: self.options
    };
}

function find (all) {
    var self = this;
    
    if (!self.template) {
        return self.emit('result', new Error('NO_TEMPLATE_SELECTED'));
    }
    
    if (self.crudFindBusy) {
        return self.emit('result', new Error('FILTER_IS_BUSY'));
    }
    
    self.crudFindBusy = true;
    
    // build queries
    self.query = all ? {} : queryBuilder.call(self, self.filters);
    
    if (!self.query) {
        
        if (self.wasEmpty) {
            self.crudFindBusy = false;
            return self.emit('result', new Error('NO_FILTERS_SELECTED'));
        }
        
        self.wasEmpty = true;
        self.query = {};
    } else {
        self.wasEmpty = false;
    }
    
    // get data with crud module
    return self.emit('find', self.query, function (err, data, xhr) {
        if (err) { return console.error(err.message || err); }        
        self.crudFindBusy = false;
        var count = xhr.getResponseHeader('X-Mono-CRUD-Count');
        self.emit('result', err, data, count);
    });
}

module.exports = find;


return module; });

{'fraction_non_alphanumeric': 0.12744570095135524, 'fraction_numerical': 0.002154011847065159, 'mean_word_length': 1.4975347377857462, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2023252', 'n_tokens_mistral': 1556, 'n_tokens_neox': 1521, 'n_words': 316}