<commit_before>/*
 * gstorage
 * https://github.com/goliatone/gstorage
 * Created with gbase.
 * Copyright (c) 2014 goliatone
 * Licensed under the MIT license.
 */
/* jshint strict: false, plusplus: true */
/*global define: false, require: false, module: false, exports: false */
(function(root, name, deps, factory) {
    "use strict";
    // Node
    if (typeof deps === 'function') {
        factory = deps;
        deps = [];
    }

    if (typeof exports === 'object') {
        module.exports = factory.apply(root, deps.map(require));
    } else if (typeof define === 'function' && 'amd' in define) {
        //require js, here we assume the file is named as the lower
        //case module name.
        define(name.toLowerCase(), deps, factory);
    } else {
        // Browser
        var d, i = 0,
            global = root,
            old = global[name],
            mod;
        while ((d = deps[i]) !== undefined) deps[i++] = root[d];
        global[name] = mod = factory.apply(global, deps);
        //Export no 'conflict module', aliases the module.
        mod.noConflict = function() {
            global[name] = old;
            return mod;
        };
    }
}(this, 'gstorage', ['extend'], function(extend) {

    /**
     * Extend method.
     * @param  {Object} target Source object
     * @return {Object}        Resulting object from
     *                         meging target to params.
     */
    var _extend = extend;

    /**
     * Shim console, make sure that if no console
     * available calls do not generate errors.
     * @return {Object} Console shim.
     */
    var _shimConsole = function(con) {

        if (con) return con;

        con = {};
        var empty = {},
            noop = function() {},
            properties = 'memory'.split(','),
            methods = ('assert,clear,count,debug,dir,dirxml,error,exception,group,' +
                'groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,' +
                'table,time,timeEnd,timeStamp,trace,warn').split(','),
            prop,
            method;

        while (method = methods.pop()) con[method] = noop;
        while (prop = properties.pop()) con[prop] = empty;

        return con;
    };



    ///////////////////////////////////////////////////
    // CONSTRUCTOR
    ///////////////////////////////////////////////////

    var options = {
        hashLength: 32,
        storeKey: '_GST_',
        storeID: '_gstore_default_',
        autoinitialize: true,
        buildDefaultStore: function() {
            //Use NullStore
            return new WebSQLStore();
        },
        makeStoreId: function() {
            return this.storeKey + window.location.hostname;
        }

        //store config
        // storeName: '',
        // storeTable: '',
        // storeVersion: ''

    };

    /**
     * GStorage constructor
     *
     * @param  {object} config Configuration object.
     */
    var GStorage = function(config) {
        config = config || {};

        config = _extend({}, this.constructor.DEFAULTS, config);

        if (config.autoinitialize) this.init(config);
    };

    GStorage.name = GStorage.prototype.name = 'GStorage';

    GStorage.VERSION = '0.0.0';

    /**
     * Make default options available so we
     * can override.
     */
    GStorage.DEFAULTS = options;

    GStorage.use = function(ext) {
        _extend(GStorage.prototype, ext);
    };

    ///////////////////////////////////////////////////
    // PRIVATE METHODS
    ///////////////////////////////////////////////////

    GStorage.prototype.init = function(config) {
        if (this.initialized) return this.logger.warn('Already initialized');
        this.initialized = true;

        console.log('GStorage: Init!');
        _extend(this, config);

        //TODO: Use promises!!!!!!
        this.store = this.buildDefaultStore();
        this.store.onError = this.onError.bind(this);
        this.store.onSuccess = this.onSuccess.bind(this);
        this.store.onConnected = this.onConnected.bind(this);

        return this;
    };

    GStorage.prototype.onError = function(e) {
        this.logger.error(e);
    };

    GStorage.prototype.onConnected = function(e) {
        this.logger.info('On connected', e, this);
        this.emit('connected');
    };

    GStorage.prototype.onSuccess = function(e) {
        this.logger.info('On success', e, this);
        this.emit('success');
    };

    ////////////////////////////////////////////
    /// DATA ACCESSSOR MEHTODS
    ///
    ////////////////////////////////////////////
    GStorage.prototype.get = function(key, def) {
        return this.store.get(key, def);
    };

    GStorage.prototype.set = function(key, value) {
        var old = this.store.get(key, null);

        this.store.set(key, value);

        //TODO: We should formalize bindable model
        //change event payload
        this.emit('change', {
            key: key,
            old: old,
            value: value
        });
        return this;
    };

    GStorage.prototype.del = function(key) {
        var old = this.store.get(key, null);

        this.store.del(key);

        this.emit('change', {
            key: key,
            old: old,
            value: null
        });

        return this;
    };

    //TODO: This might now make sense
    GStorage.prototype.has = function(key) {
        return this.store.has(key);
    };

    GStorage.prototype.key = function(key) {
        //TODO: Do we want to transform key?
        return key;
    };

    ////////////////////////////////////////////
    /// STORE DELEGATE METHODS
    ///
    ////////////////////////////////////////////
    GStorage.prototype.maxSize = function() {<commit_msg>SRC: GStorage working out API.<commit_after>/*
 * gstorage
 * https://github.com/goliatone/gstorage
 * Created with gbase.
 * Copyright (c) 2014 goliatone
 * Licensed under the MIT license.
 */
/* jshint strict: false, plusplus: true */
/*global define: false, require: false, module: false, exports: false */
(function(root, name, deps, factory) {
    "use strict";
    // Node
    if (typeof deps === 'function') {
        factory = deps;
        deps = [];
    }

    if (typeof exports === 'object') {
        module.exports = factory.apply(root, deps.map(require));
    } else if (typeof define === 'function' && 'amd' in define) {
        //require js, here we assume the file is named as the lower
        //case module name.
        define(name.toLowerCase(), deps, factory);
    } else {
        // Browser
        var d, i = 0,
            global = root,
            old = global[name],
            mod;
        while ((d = deps[i]) !== undefined) deps[i++] = root[d];
        global[name] = mod = factory.apply(global, deps);
        //Export no 'conflict module', aliases the module.
        mod.noConflict = function() {
            global[name] = old;
            return mod;
        };
    }
}(this, 'gstorage', ['extend'], function(extend) {

    /**
     * Extend method.
     * @param  {Object} target Source object
     * @return {Object}        Resulting object from
     *                         meging target to params.
     */
    var _extend = extend;

    /**
     * Shim console, make sure that if no console
     * available calls do not generate errors.
     * @return {Object} Console shim.
     */
    var _shimConsole = function(con) {

        if (con) return con;

        con = {};
        var empty = {},
            noop = function() {},
            properties = 'memory'.split(','),
            methods = ('assert,clear,count,debug,dir,dirxml,error,exception,group,' +
                'groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,' +
                'table,time,timeEnd,timeStamp,trace,warn').split(','),
            prop,
            method;

        while (method = methods.pop()) con[method] = noop;
        while (prop = properties.pop()) con[prop] = empty;

        return con;
    };



    ///////////////////////////////////////////////////
    // CONSTRUCTOR
    ///////////////////////////////////////////////////

    var options = {
        hashLength: 32,
        storeKey: '_GST_',
        storeID: '_gstore_default_',
        autoinitialize: true,
        buildDefaultStore: function() {
            //Use NullStore
            return new WebSQLStore();
        },
        makeStoreId: function() {
            return this.storeKey + window.location.hostname;
        }

        //store config
        // storeName: '',
        // storeTable: '',
        // storeVersion: ''

    };

    /**
     * GStorage constructor
     *
     * @param  {object} config Configuration object.
     */
    var GStorage = function(config) {
        config = config || {};

        config = _extend({}, this.constructor.DEFAULTS, config);

        if (config.autoinitialize) this.init(config);
    };

    GStorage.name = GStorage.prototype.name = 'GStorage';

    GStorage.VERSION = '0.0.0';

    /**
     * Make default options available so we
     * can override.
     */
    GStorage.DEFAULTS = options;

    GStorage.use = function(ext) {
        _extend(GStorage.prototype, ext);
    };

    ///////////////////////////////////////////////////
    // PRIVATE METHODS
    ///////////////////////////////////////////////////

    GStorage.prototype.init = function(config) {
        if (this.initialized) return this.logger.warn('Already initialized');
        this.initialized = true;

        console.log('GStorage: Init!');
        _extend(this, config);

        //TODO: Use promises!!!!!!
        this.store = this.buildDefaultStore();
        this.store.onError = this.onError.bind(this);
        this.store.onSuccess = this.onSuccess.bind(this);
        this.store.onConnected = this.onConnected.bind(this);

        return this;
    };

    GStorage.prototype.onError = function(e) {
        this.logger.error(e);
    };

    GStorage.prototype.onConnected = function(e) {
        this.logger.info('On connected', e, this);
        this.emit('connected');
    };

    GStorage.prototype.onSuccess = function(e) {
        this.logger.info('On success', e, this);
        this.emit('success', e);
    };

    ////////////////////////////////////////////
    /// DATA ACCESSSOR MEHTODS
    ///
    ////////////////////////////////////////////
    GStorage.prototype.get = function(key, def) {
        this.store.get(key, def);
        return this;
    };

    GStorage.prototype.set = function(key, value) {
        var old = this.store.get(key, null);

        this.store.set(key, value);

        //TODO: We should formalize bindable model
        //change event payload
        this.emit('change', {
            key: key,
            value: value
        });
        return this;
    };

    GStorage.prototype.del = function(key) {

        this.store.del(key).once('success', function() {
            this.emit('change', {
                key: key,
                action: 'delete',
                value: value
            });
        });
        return this;
    };

    //TODO: This might now make sense
    GStorage.prototype.has = function(key) {
        return this.store.has(key);
    };

    GStorage.prototype.key = function(key) {
        //TODO: Do we want to transform key?
        return key;
    };

    ////////////////////////////////////////////
    /// STORE DELEGATE METHODS
    ///
    ////////////////////////////////////////////
    GStorage.prototype.maxSize = function() {
{'fraction_non_alphanumeric': 0.19257520431229352, 'fraction_numerical': 0.001738828029907842, 'mean_word_length': 1.544348595443486, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '1017243', 'n_tokens_mistral': 3218, 'n_tokens_neox': 3102, 'n_words': 745}