<commit_before>var env = process.env;
var fs = require('fs');
var cache = require(env.Z_PATH_CACHE + 'cache');

// crate caches
var pojoStores = cache.pojo('stores');
var compStores = cache.comp('stores');

// read available store adapters to adapter cache
var adapatersPath = __dirname + '/adapters/';
var adapters = fs.readdirSync(adapatersPath);

// save adapter paths in adapter cache
for (var i = 0; i < adapters.length; ++i) {
    adapters[adapters[i]] = adapatersPath + adapters[i] + '/' + adapters[i] + '.js';
}

module.exports = factory;

// fetch a store config from the system store
function factory (name, role, callback) {

    // get connected store from cache
    var store = pojoStores.get(name, role);

    if (store === 0) {
        return callback(new Error('Store ' + name + ' not found.'));
    }

    if (store) {
        return callback(null, store);
    }

    // set store config from composition files (this checks the cache internall)
    compStores.set(name, role, function (err, store) {

        if (err || !store) {
            return callback(err || new Error('Store ' + name + ' not found.'));
        }

        // check if adpater exists
        if (!adapters[store.adapter]) {
            return callback('Store: adapter "' + store.adapter + '" not found.');
        }

        // require adapter
        if (typeof adapters[store.adapter] === 'string') {
            adapters[store.adapter] = require(adapters[store.adapter]);
        }

        // connect to store
        adapters[store.adapter](env.Z_USER, env.Z_KEY, store.config, function (err, store) {

            if (err) {
                return callback(err);
            }

            // save store in cache
            pojoStores.set(name, store);

            callback(err, store);
        });
    });
}<commit_msg>save composition roles on store object<commit_after>var env = process.env;
var fs = require('fs');
var cache = require(env.Z_PATH_CACHE + 'cache');

// crate caches
var pojoStores = cache.pojo('stores');
var compStores = cache.comp('stores');

// read available store adapters to adapter cache
var adapatersPath = __dirname + '/adapters/';
var adapters = fs.readdirSync(adapatersPath);

// save adapter paths in adapter cache
for (var i = 0; i < adapters.length; ++i) {
    adapters[adapters[i]] = adapatersPath + adapters[i] + '/' + adapters[i] + '.js';
}

module.exports = factory;

// fetch a store config from the system store
function factory (name, role, callback) {

    // get connected store from cache
    var store = pojoStores.get(name, role);

    if (store === 0) {
        return callback(new Error('Store ' + name + ' not found.'));
    }

    if (store) {
        return callback(null, store);
    }

    // set store config from composition files (this checks the cache internall)
    compStores.set(name, role, function (err, comp_store) {

        if (err || !comp_store) {
            return callback(err || new Error('Store ' + name + ' not found.'));
        }

        // check if adpater exists
        if (!adapters[comp_store.adapter]) {
            return callback('Store: adapter "' + comp_store.adapter + '" not found.');
        }

        // require adapter
        if (typeof adapters[comp_store.adapter] === 'string') {
            adapters[comp_store.adapter] = require(adapters[comp_store.adapter]);
        }

        // connect to store
        adapters[comp_store.adapter](env.Z_USER, env.Z_KEY, comp_store.config, function (err, store) {

            if (err) {
                return callback(err);
            }

            // save roles on store
            store._roles = comp_store.roles;

            // save store in cache
            pojoStores.set(name, store);

            callback(err, store);
        });
    });
}
{'fraction_non_alphanumeric': 0.13368560105680316, 'fraction_numerical': 0.0010568031704095112, 'mean_word_length': 2.383378016085791, 'pattern_counts': {'":': 0, '<': 5, '<?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': '771621', 'n_tokens_mistral': 1168, 'n_tokens_neox': 1103, 'n_words': 321}