<commit_before>var jsHyphen = angular.module('jsHyphen', []);

(function () {

    //var publicApi = {};
    //jsHyphen.value('jsHyphen', publicApi);

    jsHyphen.provider("Hyphen", [function () {
        var provider = {};
        provider.initialize = function () {

        }
        provider.$get = ['$http', '$q', 'HyphenIndexDb', 'ModelsAbstractFactory', 'BasicModel', 'HyphenIndexDb', '$injector', function ($http, $q, HyphenIndexDb, ModelsAbstractFactory, BasicModel, HyphenIndexDb, $injector) {
            var service = {};
            var listOfenqueueList = [];
            var hyphenConfiguration;
            var hyphenIndexDb;
            var stores = [];
            var startEvent;

            service.registerStartEvent = function (event) {
                startEvent = event;
            };

            service.initialize = function (configuration) {
                var self = this;
                hyphenConfiguration = configuration;

                configuration.model.forEach(function (entity) {
                    service[entity.model] = new BasicModel(entity, configuration);
                    stores.push({name: entity.model, key: entity.key});
                });

                hyphenIndexDb = new HyphenIndexDb(configuration.dbName, configuration.dbVersion, stores);
                HyphenIndexDb.upgradeEvent(function (event) {
                    //HyphenIndexDb.clearStores(stores, stores);
                    //return;
                    _(stores).each(function (st) {

                        if (!_(event.target.transaction.db.objectStoreNames).contains(st.name)) {
                            HyphenIndexDb.createStore(st.name, st.key);
                        } else {
                            console.log("Store " + st + "already exist and will be not creatd again");
                        }
                    })
                });

                HyphenIndexDb.openEvent(function (event) {
                    var readPromises = [];
                    _(event.target.result.objectStoreNames).each(function (store) {
                        var indexReadPromise = HyphenIndexDb.getStoreData(store);
                        readPromises.push(indexReadPromise);
                    });

                    $q.all(readPromises).then(function (result) {
                        var syncQue = [];
                        _(result).each(function (dbData) {
                            var entityModel;
                            try {
                                entityModel = $injector.get(dbData.model);
                            } catch (e) {
                                entityModel = $injector.get('DefaultModel');
                            }

                            if (!entityModel.synchronize)
                                throw Error("Not defined synchronise method for model " + dbData.store);

                            syncQue.push(entityModel.synchronize(dbData.data));
                        })

                        $q.all(syncQue).then(function (result) {
                            _(event.target.result.objectStoreNames).each(function (store) {
                                HyphenIndexDb.clear(store);
                            });
                            if (startEvent)
                                startEvent();
                            loadData();
                            console.log("Load data and start app");
                        });
                    }, function(r){
                        alert();
                    }).catch(function(ex){
                        console.log("ghgh");
                    });
                });

            };

            window.addEventListener('online', function () {
                var stores = HyphenIndexDb.getStores();
                var readPromises = [];
                _(stores).each(function (store) {
                    var indexReadPromise = HyphenIndexDb.getStoreData(store);
                    readPromises.push(indexReadPromise);
                });

                $q.all(readPromises).then(function (result) {
                    var syncQue = [];
                    _(result).each(function (dbData) {
                        var entityModel = $injector.get(dbData.model);
                        if (!entityModel.synchronize)
                            throw Error("Not defined synchronise method for model " + dbData.store);

                        syncQue.push(entityModel.synchronize(dbData.data));
                    });

                    $q.all(syncQue).then(function (result) {
                        console.log("Sync finished");
                    });
                    console.log("open");
                });
                console.log("Is online");
            });

            window.addEventListener('offline', function () {
                console.log("is offline");
            });

            var loadData = function () {
                _(listOfenqueueList).each(function (enqueueList) {
                    _(enqueueList).each(function (data) {
                        var method = data.method;
                        var params = data.params;
                        method.data = data.data;
                        method.call(params).then(function (data) {
                            self.defer.resolve(data);
                        }, function (reason) {
                            self.defer.reject(reason);
                        });
                    });
                })
            }

            service.enqueue = function (enqueueList) {
                self.defer = $q.defer();
                listOfenqueueList.push(enqueueList);
                return self.defer.promise;
            }

            return service;
        }];
        return provider;
    }]);

    jsHyphen.factory("HyphenDataStore", ['HyphenDataModel', function (HyphenDataModel) {
        var HyphenDataStore = function (store, entityModel) {
            HyphenDataStore.prototype.stores[store] = new HyphenDataModel(entityModel, store);
        }

        HyphenDataStore.prototype.stores = {};

        HyphenDataStore.saveResult = function (data, store, options) {
            if (options.processResponse != false) {
                if (options.responseHandler) {
                    options.responseHandler(data, HyphenDataStore.prototype.stores);

                } else {
                    if (options.method == "delete" || options.action == "delete") {
                        if (navigator.onLine && !window.hjom) {
                            HyphenDataStore.prototype.stores[store].removeDataOnline(data);
                        }
                        else {
                            HyphenDataStore.prototype.stores[store].removeDataOffline(data);
                        }
                    }<commit_msg>-initialization flag<commit_after>var jsHyphen = angular.module('jsHyphen', []);

(function () {

    //var publicApi = {};
    //jsHyphen.value('jsHyphen', publicApi);

    jsHyphen.provider("Hyphen", [function () {
        var provider = {};
        provider.initialize = function () {

        }
        provider.$get = ['$http', '$q', 'HyphenIndexDb', 'ModelsAbstractFactory', 'BasicModel', 'HyphenIndexDb', '$injector', function ($http, $q, HyphenIndexDb, ModelsAbstractFactory, BasicModel, HyphenIndexDb, $injector) {
            var service = {};
            var listOfenqueueList = [];
            var hyphenConfiguration;
            var hyphenIndexDb;
            var stores = [];
            var startEvent;

            service.registerStartEvent = function (event) {
                startEvent = event;
            };

            service.initialize = function (configuration) {
                var self = this;
                hyphenConfiguration = configuration;

                configuration.model.forEach(function (entity) {
                    service[entity.model] = new BasicModel(entity, configuration);
                    stores.push({name: entity.model, key: entity.key});
                });

                hyphenIndexDb = new HyphenIndexDb(configuration.dbName, configuration.dbVersion, stores);
                HyphenIndexDb.upgradeEvent(function (event) {
                    //HyphenIndexDb.clearStores(stores, stores);
                    //return;
                    _(stores).each(function (st) {

                        if (!_(event.target.transaction.db.objectStoreNames).contains(st.name)) {
                            HyphenIndexDb.createStore(st.name, st.key);
                        } else {
                            console.log("Store " + st + "already exist and will be not creatd again");
                        }
                    })
                });

                HyphenIndexDb.openEvent(function (event) {
                    HyphenIndexDb.initialized=true;
                    var readPromises = [];
                    _(event.target.result.objectStoreNames).each(function (store) {
                        var indexReadPromise = HyphenIndexDb.getStoreData(store);
                        readPromises.push(indexReadPromise);
                    });

                    $q.all(readPromises).then(function (result) {
                        var syncQue = [];
                        _(result).each(function (dbData) {
                            var entityModel;
                            try {
                                entityModel = $injector.get(dbData.model);
                            } catch (e) {
                                entityModel = $injector.get('DefaultModel');
                            }

                            if (!entityModel.synchronize)
                                throw Error("Not defined synchronise method for model " + dbData.store);

                            syncQue.push(entityModel.synchronize(dbData.data));
                        })

                        $q.all(syncQue).then(function (result) {
                            _(event.target.result.objectStoreNames).each(function (store) {
                                HyphenIndexDb.clear(store);
                            });
                            if (startEvent)
                                startEvent();
                            loadData();
                            console.log("Load data and start app");
                        });
                    }, function(r){
                        alert();
                    }).catch(function(ex){
                        console.log("ghgh");
                    });
                });

            };

            window.addEventListener('online', function () {
                var stores = HyphenIndexDb.getStores();
                var readPromises = [];
                _(stores).each(function (store) {
                    var indexReadPromise = HyphenIndexDb.getStoreData(store);
                    readPromises.push(indexReadPromise);
                });

                $q.all(readPromises).then(function (result) {
                    var syncQue = [];
                    _(result).each(function (dbData) {
                        var entityModel = $injector.get(dbData.model);
                        if (!entityModel.synchronize)
                            throw Error("Not defined synchronise method for model " + dbData.store);

                        syncQue.push(entityModel.synchronize(dbData.data));
                    });

                    $q.all(syncQue).then(function (result) {
                        console.log("Sync finished");
                    });
                    console.log("open");
                });
                console.log("Is online");
            });

            window.addEventListener('offline', function () {
                console.log("is offline");
            });

            var loadData = function () {
                _(listOfenqueueList).each(function (enqueueList) {
                    _(enqueueList).each(function (data) {
                        var method = data.method;
                        var params = data.params;
                        method.data = data.data;
                        method.call(params).then(function (data) {
                            self.defer.resolve(data);
                        }, function (reason) {
                            self.defer.reject(reason);
                        });
                    });
                })
            }

            service.enqueue = function (enqueueList) {
                listOfenqueueList=[];
                self.defer = $q.defer();
                listOfenqueueList.push(enqueueList);
                if(HyphenIndexDb.initialized)
                    loadData();
                return self.defer.promise;
            }

            return service;
        }];
        return provider;
    }]);

    jsHyphen.factory("HyphenDataStore", ['HyphenDataModel', function (HyphenDataModel) {
        var HyphenDataStore = function (store, entityModel) {
            HyphenDataStore.prototype.stores[store] = new HyphenDataModel(entityModel, store);
        }

        HyphenDataStore.prototype.stores = {};

        HyphenDataStore.saveResult = function (data, store, options) {
            if (options.processResponse != false) {
                if (options.responseHandler) {
                    options.responseHandler(data, HyphenDataStore.prototype.stores);

                } else {
                    if (options.method == "delete" || options.action == "delete") {
                        if (navigator.onLine && !window.hjom) {
                            HyphenDataStore.prototype.stores[store].removeDataOnline(data);
                        }
                        else {
                            HyphenDataStore.prototype.stores[store].removeDataOffline(data);
                        }
                    }
{'fraction_non_alphanumeric': 0.10427633951106945, 'fraction_numerical': 0.0, 'mean_word_length': 1.199524187153053, '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': '6463979', 'n_tokens_mistral': 3354, 'n_tokens_neox': 3057, 'n_words': 527}