<commit_before>
module.exports = SearchSupport;

function SearchSupport () {
    var self = this;

    function getOnlySingleResult (result) {
        if (!result || result.length === 0) {
            throw new Error("Can't resolve any template");
        }

        if (result.length > 1) {
            throw new Error("Please specify more concrete search criteria");
        }

        return result[0];
    }

    function arrayToCompositeCriteria(array) {
        var emptyObject = { };

        return array
            .reduce(function (memo, item) {
                return { or: [memo, self._toCriteriaObject(item)] };
            }, emptyObject);
    }

    self.findSingle = function (criteria) {
        return self.find(criteria).then(getOnlySingleResult);
    };

    self._toCriteriaObject = function (args) {
        var argsArray = Array.prototype.slice.call(args);

        if (argsArray.length > 1) {
            console.log(argsArray);
            return arrayToCompositeCriteria(argsArray);
        } else if (argsArray.length === 1) {
            if (argsArray[0] instanceof Object) {
                return argsArray[0];
            } else {
                throw new Error('Criteria[' + argsArray[0] + '] must be an object');
            }
        } else {
            return { };
        }
    };

}<commit_msg> #65 Design, Development and Prototyping of SDK architecture<commit_after>
module.exports = SearchSupport;

function SearchSupport () {
    var self = this;

    function getOnlySingleResult (result) {
        if (!result || result.length === 0) {
            throw new Error("Can't resolve any template");
        }

        if (result.length > 1) {
            throw new Error("Please specify more concrete search criteria");
        }

        return result[0];
    }

    function arrayToCompositeCriteria(array) {
        var emptyObject = { };

        return array
            .reduce(function (memo, item) {
                return { or: [memo, singleItemToCriteria(item)] };
            }, emptyObject);
    }

    function singleItemToCriteria(curItem) {
        if (curItem instanceof Object) {
            return curItem;
        } else if (curItem instanceof Array) {
            return arrayToCompositeCriteria(curItem);
        } else {
            throw new Error('Criteria[' + curItem + '] must be an object');
        }
    }

    self.findSingle = function (criteria) {
        return self.find(criteria).then(getOnlySingleResult);
    };

    self._toCriteriaObject = function (args) {
        var argsArray = Array.prototype.slice.call(args);

        if (argsArray.length > 1) {
            return arrayToCompositeCriteria(argsArray);
        } else if (argsArray.length === 1) {
            return singleItemToCriteria(argsArray[0]);
        } else {
            return { };
        }
    };

}
{'fraction_non_alphanumeric': 0.10982456140350877, 'fraction_numerical': 0.005614035087719298, 'mean_word_length': 1.9697916666666666, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5980945', 'n_tokens_mistral': 780, 'n_tokens_neox': 743, 'n_words': 190}