<commit_before>(function ( window ) {
    'use strict';
    var indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.oIndexedDB || window.msIndexedDB,
        IDBDatabase = window.IDBDatabase || window.webkitIDBDatabase,
        IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange,
        transactionModes = {
            readonly: 'readonly',
            readwrite: 'readwrite'
        };
        
    var hasOwn = Object.prototype.hasOwnProperty;

    var oldApi = !!IDBDatabase.prototype.setVersion;

    if ( !indexedDB ) {
        throw 'IndexedDB required';
    }

    var CallbackList = function () {
        var state,
            list = [];

        var exec = function ( context , args ) {
            if ( list ) {
                args = args || [];
                state = state || [ context , args ];

                for ( var i = 0 , il = list.length ; i < il ; i++ ) {
                    list[ i ].apply( state[ 0 ] , state[ 1 ] );
                }

                list = [];
            }
        };

        this.add = function () {
            for ( var i = 0 , il = arguments.length ; i < il ; i ++ ) {
                list.push( arguments[ i ] );
            }

            if ( state ) {
                exec();
            }

            return this;
        };

        this.execute = function () {
            exec( this , arguments );
            return this;
        };
    };

    var Promise = function () {
        var doneList = new CallbackList(),
            failedList = new CallbackList(),
            progressList = new CallbackList(),
            state = 'progress';

        this.done = doneList.add;
        this.fail = failedList.add;
        this.progress = progressList.add;
        this.resolve = doneList.execute;
        this.reject = failedList.execute;
        this.notify = progressList.execute;

        this.then = function ( doneHandler , failedHandler , progressHandler ) {
            return this.done( doneHandler ).fail( failedHandler ).progress( progressHandler );
        };

        this.done( function () { 
            state = 'resolved';
        }).fail( function () {
            state = 'rejected';
        });
    };

    var Server = function ( db , name ) {
        var that = this,
            closed = false;
        
        this.add = function( table , records ) {
            if ( closed ) {
                throw 'Database has been closed';
            }
            var transaction = db.transaction( table , transactionModes.readwrite ),
                store = transaction.objectStore( table ),
                promise = new Promise();
            
            if ( records.constructor !== Array ) {
                records = [ records ];
            }
            
            records.forEach( function ( record ) {
                var req = store.add( record );
                req.onsuccess = function ( e ) {
                    var target = e.target;
                    record[ target.source.keyPath ] = target.result;
                    promise.notify();
                };
            } );
            
            transaction.oncomplete = function () {
                promise.resolve( records , that );
            };
            transaction.onerror = function ( e ) {
                promise.reject( records , e );
            };
            transaction.onabort = function ( e ) {
                promise.reject( records , e );
            };
            return promise;
        };
        
        this.remove = function ( table , key ) {
            if ( closed ) {
                throw 'Database has been closed';
            }
            var transaction = db.transaction( table , transactionModes.readwrite ),
                store = transaction.objectStore( table ),
                promise = new Promise();
            
            var req = store.delete( key );
            req.onsuccess = function ( e ) {
                promise.resolve( key );
            };
            req.onerror = function ( e ) {
                promise.reject( e );
            };
            return promise;
        };
        
        this.query = function ( table ) {
            if ( closed ) {
                throw 'Database has been closed';
            }
            return new Query( table , db );
        };
        
        this.close = function ( ) {
            if ( closed ) {
                throw 'Database has been closed';
            }
            db.close();
            closed = true;
            delete dbCache[ name ];
        };

        this.get = function ( table , id ) {
            if ( closed ) {
                throw 'Database has been closed';
            }
            var transaction = db.transaction( table ),
                store = transaction.objectStore( table ),
                promise = new Promise();

            var req = store.get( id );
            req.onsuccess = function ( e ) {
                promise.resolve( e.target.result );
            };
            req.onerror = function ( e ) {
                promise.reject( e );
            };
            return promise;
        };

        this.index = function ( table , index ) {
            if ( closed ) {
                throw 'Database has been closed';
            }
            return new IndexQuery( table , index , db );
        };

        for ( var i = 0 , il = db.objectStoreNames.length ; i < il ; i++ ) {
            (function ( storeName ) {
                that[ storeName ] = { };
                for ( var i in that ) {
                    if ( !hasOwn.call( that , i ) || i === 'close' ) {
                        continue;
                    }
                    that[ storeName ][ i ] = (function ( i ) {
                        return function () {
                            var args = [ storeName ].concat( [].slice.call( arguments , 0 ) );
                            return that[ i ].apply( that , args );
                        };
                    })( i );
                }
            })( db.objectStoreNames[ i ] );
        }
    };

    var IndexQuery = function ( table , indexName , db ) {
        var that = this;
        var runQuery = function ( type, args , cursorType ) {
            var transaction = db.transaction( table ),
                store = transaction.objectStore( table ),
                index = store.index( indexName ),<commit_msg>reorganising arguments<commit_after>(function ( window ) {
    'use strict';
    var indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.oIndexedDB || window.msIndexedDB,
        IDBDatabase = window.IDBDatabase || window.webkitIDBDatabase,
        IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange,
        transactionModes = {
            readonly: 'readonly',
            readwrite: 'readwrite'
        };
        
    var hasOwn = Object.prototype.hasOwnProperty;

    var oldApi = !!IDBDatabase.prototype.setVersion;

    if ( !indexedDB ) {
        throw 'IndexedDB required';
    }

    var CallbackList = function () {
        var state,
            list = [];

        var exec = function ( context , args ) {
            if ( list ) {
                args = args || [];
                state = state || [ context , args ];

                for ( var i = 0 , il = list.length ; i < il ; i++ ) {
                    list[ i ].apply( state[ 0 ] , state[ 1 ] );
                }

                list = [];
            }
        };

        this.add = function () {
            for ( var i = 0 , il = arguments.length ; i < il ; i ++ ) {
                list.push( arguments[ i ] );
            }

            if ( state ) {
                exec();
            }

            return this;
        };

        this.execute = function () {
            exec( this , arguments );
            return this;
        };
    };

    var Promise = function () {
        var doneList = new CallbackList(),
            failedList = new CallbackList(),
            progressList = new CallbackList(),
            state = 'progress';

        this.done = doneList.add;
        this.fail = failedList.add;
        this.progress = progressList.add;
        this.resolve = doneList.execute;
        this.reject = failedList.execute;
        this.notify = progressList.execute;

        this.then = function ( doneHandler , failedHandler , progressHandler ) {
            return this.done( doneHandler ).fail( failedHandler ).progress( progressHandler );
        };

        this.done( function () { 
            state = 'resolved';
        }).fail( function () {
            state = 'rejected';
        });
    };

    var Server = function ( db , name ) {
        var that = this,
            closed = false;
        
        this.add = function( table , records ) {
            if ( closed ) {
                throw 'Database has been closed';
            }
            var transaction = db.transaction( table , transactionModes.readwrite ),
                store = transaction.objectStore( table ),
                promise = new Promise();
            
            if ( records.constructor !== Array ) {
                records = [ records ];
            }
            
            records.forEach( function ( record ) {
                var req = store.add( record );
                req.onsuccess = function ( e ) {
                    var target = e.target;
                    record[ target.source.keyPath ] = target.result;
                    promise.notify();
                };
            } );
            
            transaction.oncomplete = function () {
                promise.resolve( records , that );
            };
            transaction.onerror = function ( e ) {
                promise.reject( records , e );
            };
            transaction.onabort = function ( e ) {
                promise.reject( records , e );
            };
            return promise;
        };
        
        this.remove = function ( table , key ) {
            if ( closed ) {
                throw 'Database has been closed';
            }
            var transaction = db.transaction( table , transactionModes.readwrite ),
                store = transaction.objectStore( table ),
                promise = new Promise();
            
            var req = store.delete( key );
            req.onsuccess = function ( e ) {
                promise.resolve( key );
            };
            req.onerror = function ( e ) {
                promise.reject( e );
            };
            return promise;
        };
        
        this.query = function ( table ) {
            if ( closed ) {
                throw 'Database has been closed';
            }
            return new Query( table , db );
        };
        
        this.close = function ( ) {
            if ( closed ) {
                throw 'Database has been closed';
            }
            db.close();
            closed = true;
            delete dbCache[ name ];
        };

        this.get = function ( table , id ) {
            if ( closed ) {
                throw 'Database has been closed';
            }
            var transaction = db.transaction( table ),
                store = transaction.objectStore( table ),
                promise = new Promise();

            var req = store.get( id );
            req.onsuccess = function ( e ) {
                promise.resolve( e.target.result );
            };
            req.onerror = function ( e ) {
                promise.reject( e );
            };
            return promise;
        };

        this.index = function ( table , index ) {
            if ( closed ) {
                throw 'Database has been closed';
            }
            return new IndexQuery( table , db , index );
        };

        for ( var i = 0 , il = db.objectStoreNames.length ; i < il ; i++ ) {
            (function ( storeName ) {
                that[ storeName ] = { };
                for ( var i in that ) {
                    if ( !hasOwn.call( that , i ) || i === 'close' ) {
                        continue;
                    }
                    that[ storeName ][ i ] = (function ( i ) {
                        return function () {
                            var args = [ storeName ].concat( [].slice.call( arguments , 0 ) );
                            return that[ i ].apply( that , args );
                        };
                    })( i );
                }
            })( db.objectStoreNames[ i ] );
        }
    };

    var IndexQuery = function ( table , db , indexName ) {
        var that = this;
        var runQuery = function ( type, args , cursorType ) {
            var transaction = db.transaction( table ),
                store = transaction.objectStore( table ),
                index = store.index( indexName ),
{'fraction_non_alphanumeric': 0.10739614994934144, 'fraction_numerical': 0.0009352349777881693, 'mean_word_length': 1.1595422416694716, 'pattern_counts': {'":': 0, '<': 9, '<?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': '698362', 'n_tokens_mistral': 3202, 'n_tokens_neox': 3075, 'n_words': 821}