Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added js-min-sourcemap

Also corrected test cases to remove constants in IDBTransaction
  • Loading branch information...
commit 376e14283ccb393af8d57b340dbcfa65fa66bc74 1 parent d490a33
@axemclion authored
View
19 Gruntfile.js
@@ -7,9 +7,6 @@ module.exports = function(grunt) {
saucekey = process.env.saucekey;
}
grunt.initConfig({
- jshint: {
- files: ['grunt.js', 'src/**/*.js', 'test/**/*.js']
- },
concat: {
dist: {
src: srcFiles,
@@ -45,7 +42,6 @@ module.exports = function(grunt) {
all: {
username: 'indexeddbshim',
key: saucekey,
- testname: 'IndexedDBShim',
tags: ['master'],
urls: ['http://127.0.0.1:9999/test/index.html'],
browsers: [{
@@ -59,6 +55,9 @@ module.exports = function(grunt) {
},
jshint: {
+ files: ['grunt.js', 'src/**/*.js', 'test/**/*.js'],
+ },
+ jshint: {
options: {
camelcase: true,
nonew: true,
@@ -106,6 +105,12 @@ module.exports = function(grunt) {
unescape: true,
process: true
}
+ },
+ watch: {
+ dev : {
+ files: ["src/*"],
+ tasks :["jshint", "concat", "jsmin-sourcemap"]
+ }
}
});
@@ -114,11 +119,12 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-jsmin-sourcemap');
+ grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-saucelabs');
- grunt.registerTask('build', ['jshint', 'concat', 'uglify']);
+ grunt.registerTask('build', ['jshint', 'concat', 'jsmin-sourcemap']);
- grunt.registerTask("publish", function() {
+ grunt.registerTask("publish", "Publish to gh-pages", function() {
var done = this.async();
console.log("Running publish action");
var request = require("request");
@@ -153,4 +159,5 @@ module.exports = function(grunt) {
grunt.registerTask('test', testJobs);
grunt.registerTask('default', 'build');
+ grunt.registerTask('dev', ['build', 'connect', 'watch']);
};
View
48 dist/IndexedDBShim.js
@@ -1,7 +1,7 @@
/**
* An initialization file that checks for conditions, removes console.log and warn, etc
*/
-var idbModules = {};
+var idbModules = {};
(function(idbModules){
/**
* A utility method to callback onsuccess, onerror, etc as soon as the calling function's context is over
@@ -71,7 +71,7 @@ var idbModules = {};
"StringList": StringList
};
}(idbModules));
-
+
(function(idbModules){
/**
* A dummy implementation of the Structured Cloning Algorithm
@@ -88,7 +88,7 @@ var idbModules = {};
};
}());
idbModules.Sca = Sca;
-}(idbModules));
+}(idbModules));
(function(idbModules){
/**
* Encodes the keys and values based on their types. This is required to maintain collations
@@ -144,7 +144,7 @@ var idbModules = {};
}());
idbModules.Key = Key;
}(idbModules));
-
+
(function(idbModules, undefined){
// The event interface used for IndexedBD Actions.
var Event = function(type, debug){
@@ -161,6 +161,7 @@ var idbModules = {};
};
idbModules.Event = Event;
}(idbModules));
+
(function(idbModules){
/**
@@ -183,7 +184,7 @@ var idbModules = {};
idbModules.IDBOpenRequest = IDBOpenRequest;
}(idbModules));
-
+
(function(idbModules, undefined){
/**
* The IndexedDB KeyRange object
@@ -217,7 +218,7 @@ var idbModules = {};
idbModules.IDBKeyRange = IDBKeyRange;
}(idbModules));
-
+
(function(idbModules, undefined){
/**
* The IndexedDB Cursor Object
@@ -257,12 +258,12 @@ var idbModules = {};
if (me.__range && (me.__range.lower || me.__range.upper)) {
sql.push("AND");
if (me.__range.lower) {
- sql.push(me.__keyColumnName + (me.__range.lowerOpen ? " >=" : " >") + " ?");
+ sql.push(me.__keyColumnName + (me.__range.lowerOpen ? " >" : " >= ") + " ?");
sqlValues.push(idbModules.Key.encode(me.__range.lower));
}
(me.__range.lower && me.__range.upper) && sql.push("AND");
if (me.__range.upper) {
- sql.push(me.__keyColumnName + (me.__range.upperOpen ? " <= " : " < ") + " ?");
+ sql.push(me.__keyColumnName + (me.__range.upperOpen ? " < " : " <= ") + " ?");
sqlValues.push(idbModules.Key.encode(me.__range.upper));
}
}
@@ -276,6 +277,7 @@ var idbModules = {};
}
sql.push("ORDER BY ", me.__keyColumnName);
sql.push("LIMIT 1 OFFSET " + me.__offset);
+ debugger;
idbModules.DEBUG && console.log(sql.join(" "), sqlValues);
tx.executeSql(sql.join(" "), sqlValues, function(tx, data){
if (data.rows.length === 1) {
@@ -370,19 +372,25 @@ var idbModules = {};
idbModules.IDBCursor = IDBCursor;
}(idbModules));
-
+
(function(idbModules, undefined){
/**
* IDB Index
* http://www.w3.org/TR/IndexedDB/#idl-def-IDBIndex
- * @param {Object} indexName
- * @param {Object} keyPath
- * @param {Object} optionalParameters
- * @param {Object} transaction
+ * @param {Object} name;
+ * @param {Object} objectStore;
*/
function IDBIndex(indexName, idbObjectStore){
- this.indexName = indexName;
- this.__idbObjectStore = this.source = idbObjectStore;
+ this.indexName = this.name = indexName;
+ this.__idbObjectStore = this.objectStore = this.source = idbObjectStore;
+
+ var indexList = idbObjectStore.__storeProps && idbObjectStore.__storeProps.indexList;
+ indexList && (indexList = JSON.parse(indexList));
+
+ this.keyPath = ((indexList && indexList[indexName] && indexList[indexName].keyPath) || indexName);
+ ['multiEntry','unique'].forEach(function(prop){
+ this[prop] = !!indexList && !!indexList[indexName] && !!indexList[indexName].optionalParams && !!indexList[indexName].optionalParams[prop];
+ }, this);
}
IDBIndex.prototype.__createIndex = function(indexName, keyPath, optionalParameters){
@@ -498,7 +506,7 @@ var idbModules = {};
idbModules.IDBIndex = IDBIndex;
}(idbModules));
-
+
(function(idbModules){
/**
@@ -825,7 +833,7 @@ var idbModules = {};
idbModules.IDBObjectStore = IDBObjectStore;
}(idbModules));
-
+
(function(idbModules){
/**
@@ -968,7 +976,7 @@ var idbModules = {};
idbModules.IDBTransaction = IDBTransaction;
}(idbModules));
-
+
(function(idbModules){
/**
@@ -1057,7 +1065,7 @@ var idbModules = {};
idbModules.IDBDatabase = IDBDatabase;
}(idbModules));
-
+
(function(idbModules){
var DEFAULT_DB_SIZE = 4 * 1024 * 1024;
if (!window.openDatabase) {
@@ -1230,7 +1238,7 @@ var idbModules = {};
idbModules.shimIndexedDB = shimIndexedDB;
}(idbModules));
-
+
(function(window, idbModules){
if (typeof window.openDatabase !== "undefined") {
window.shimIndexedDB = idbModules.shimIndexedDB;
View
95 dist/IndexedDBShim.min.js
@@ -1 +1,94 @@
-var idbModules={};(function(e){function t(e,t,n,o){n.target=t,"function"==typeof t[e]&&t[e].apply(t,[n]),"function"==typeof o&&o()}function n(t,n,o){var i=new DOMException.constructor(0,n);throw i.name=t,i.message=n,i.stack=arguments.callee.caller,e.DEBUG&&console.log(t,n,o,i),i}var o=function(){this.length=0,this._items=[]};o.prototype={contains:function(e){return-1!==this._items.indexOf(e)},item:function(e){return this._items[e]},indexOf:function(e){return this._items.indexOf(e)},push:function(e){this._items.push(e),this.length+=1},splice:function(){this._items.splice.apply(this._items,arguments),this.length=this._items.length}},e.util={throwDOMException:n,callback:t,quote:function(e){return"'"+e+"'"},StringList:o}})(idbModules),function(e){var t=function(){return{encode:function(e){return JSON.stringify(e)},decode:function(e){return JSON.parse(e)}}}();e.Sca=t}(idbModules),function(e){var t=["","number","string","boolean","object","undefined"],n=function(){return{encode:function(e){return t.indexOf(typeof e)+"-"+JSON.stringify(e)},decode:function(e){return e===void 0?void 0:JSON.parse(e.substring(2))}}},o={number:n("number"),"boolean":n(),object:n(),string:{encode:function(e){return t.indexOf("string")+"-"+e},decode:function(e){return""+e.substring(2)}},undefined:{encode:function(){return t.indexOf("undefined")+"-undefined"},decode:function(){return void 0}}},i=function(){return{encode:function(e){return o[typeof e].encode(e)},decode:function(e){return o[t[e.substring(0,1)]].decode(e)}}}();e.Key=i}(idbModules),function(e){var t=function(e,t){return{type:e,debug:t,bubbles:!1,cancelable:!1,eventPhase:0,timeStamp:new Date}};e.Event=t}(idbModules),function(e){var t=function(){this.onsuccess=this.onerror=this.result=this.error=this.source=this.transaction=null,this.readyState="pending"},n=function(){this.onblocked=this.onupgradeneeded=null};n.prototype=t,e.IDBRequest=t,e.IDBOpenRequest=n}(idbModules),function(e,t){var n=function(e,t,n,o){this.lower=e,this.upper=t,this.lowerOpen=n,this.upperOpen=o};n.only=function(e){return new n(e,e,!0,!0)},n.lowerBound=function(e,o){return new n(e,t,o,t)},n.upperBound=function(e){return new n(t,e,t,open)},n.bound=function(e,t,o,i){return new n(e,t,o,i)},e.IDBKeyRange=n}(idbModules),function(e,t){function n(n,o,i,r,s,a){this.__range=n,this.source=this.__idbObjectStore=i,this.__req=r,this.key=t,this.direction=o,this.__keyColumnName=s,this.__valueColumnName=a,this.source.transaction.__active||e.util.throwDOMException("TransactionInactiveError - The transaction this IDBObjectStore belongs to is not active."),this.__offset=-1,this.__lastKeyContinued=t,this["continue"]()}n.prototype.__find=function(n,o,i,r){var s=this,a=["SELECT * FROM ",e.util.quote(s.__idbObjectStore.name)],u=[];a.push("WHERE ",s.__keyColumnName," NOT NULL"),s.__range&&(s.__range.lower||s.__range.upper)&&(a.push("AND"),s.__range.lower&&(a.push(s.__keyColumnName+(s.__range.lowerOpen?" >=":" >")+" ?"),u.push(e.Key.encode(s.__range.lower))),s.__range.lower&&s.__range.upper&&a.push("AND"),s.__range.upper&&(a.push(s.__keyColumnName+(s.__range.upperOpen?" <= ":" < ")+" ?"),u.push(e.Key.encode(s.__range.upper)))),n!==t&&(s.__lastKeyContinued=n,s.__offset=0),s.__lastKeyContinued!==t&&(a.push("AND "+s.__keyColumnName+" >= ?"),u.push(e.Key.encode(s.__lastKeyContinued))),a.push("ORDER BY ",s.__keyColumnName),a.push("LIMIT 1 OFFSET "+s.__offset),e.DEBUG&&console.log(a.join(" "),u),o.executeSql(a.join(" "),u,function(n,o){if(1===o.rows.length){var r=e.Key.decode(o.rows.item(0)[s.__keyColumnName]),a="value"===s.__valueColumnName?e.Sca.decode(o.rows.item(0)[s.__valueColumnName]):e.Key.decode(o.rows.item(0)[s.__valueColumnName]);i(r,a)}else e.DEBUG&&console.log("Reached end of cursors"),i(t,t)},function(t,n){e.DEBUG&&console.log("Could not execute Cursor.continue"),r(n)})},n.prototype["continue"]=function(e){var n=this;this.__idbObjectStore.transaction.__addToTransactionQueue(function(o,i,r,s){n.__offset++,n.__find(e,o,function(e,o){n.key=e,n.value=o,r(n.key!==t?n:t,n.__req)},function(e){s(e)})})},n.prototype.advance=function(n){0>=n&&e.util.throwDOMException("Type Error - Count is invalid - 0 or negative",n);var o=this;this.__idbObjectStore.transaction.__addToTransactionQueue(function(e,i,r,s){o.__offset+=n,o.__find(t,e,function(e,n){o.key=e,o.value=n,r(o.key!==t?o:t,o.__req)},function(e){s(e)})})},n.prototype.update=function(n){var o=this;return this.__idbObjectStore.transaction.__addToTransactionQueue(function(i,r,s,a){o.__find(t,i,function(t){var r="UPDATE "+e.util.quote(o.__idbObjectStore.name)+" SET value = ? WHERE key = ?";e.DEBUG&&console.log(r,n,t),i.executeSql(r,[e.Sca.encode(n),e.Key.encode(t)],function(e,n){1===n.rowsAffected?s(t):a("No rowns with key found"+t)},function(e,t){a(t)})},function(e){a(e)})})},n.prototype["delete"]=function(){var n=this;return this.__idbObjectStore.transaction.__addToTransactionQueue(function(o,i,r,s){n.__find(t,o,function(i){var a="DELETE FROM "+e.util.quote(n.__idbObjectStore.name)+" WHERE key = ?";e.DEBUG&&console.log(a,i),o.executeSql(a,[e.Key.encode(i)],function(e,n){1===n.rowsAffected?r(t):s("No rowns with key found"+i)},function(e,t){s(t)})},function(e){s(e)})})},e.IDBCursor=n}(idbModules),function(idbModules,undefined){function IDBIndex(e,t){this.indexName=e,this.__idbObjectStore=this.source=t}IDBIndex.prototype.__createIndex=function(indexName,keyPath,optionalParameters){var me=this,transaction=me.__idbObjectStore.transaction;transaction.__addToTransactionQueue(function(tx,args,success,failure){me.__idbObjectStore.__getStoreProps(tx,function(){function error(){idbModules.util.throwDOMException(0,"Could not create new index",arguments)}2!==transaction.mode&&idbModules.util.throwDOMException(0,"Invalid State error, not a version transaction",me.transaction);var idxList=JSON.parse(me.__idbObjectStore.__storeProps.indexList);idxList[indexName]!==undefined&&idbModules.util.throwDOMException(0,"Index already exists on store",idxList);var columnName=indexName;idxList[indexName]={columnName:columnName,keyPath:keyPath,optionalParams:optionalParameters},me.__idbObjectStore.__storeProps.indexList=JSON.stringify(idxList);var sql=["ALTER TABLE",idbModules.util.quote(me.__idbObjectStore.name),"ADD",columnName,"BLOB"].join(" ");idbModules.DEBUG&&console.log(sql),tx.executeSql(sql,[],function(tx,data){tx.executeSql("SELECT * FROM "+idbModules.util.quote(me.__idbObjectStore.name),[],function(tx,data){(function initIndexForRow(i){if(data.rows.length>i)try{var value=idbModules.Sca.decode(data.rows.item(i).value),indexKey=eval("value['"+keyPath+"']");tx.executeSql("UPDATE "+idbModules.util.quote(me.__idbObjectStore.name)+" set "+columnName+" = ? where key = ?",[idbModules.Key.encode(indexKey),data.rows.item(i).key],function(){initIndexForRow(i+1)},error)}catch(e){initIndexForRow(i+1)}else idbModules.DEBUG&&console.log("Updating the indexes in table",me.__idbObjectStore.__storeProps),tx.executeSql("UPDATE __sys__ set indexList = ? where name = ?",[me.__idbObjectStore.__storeProps.indexList,me.__idbObjectStore.name],function(){me.__idbObjectStore.__setReadyState("createIndex",!0),success(me)},error)})(0)},error)},error)},"createObjectStore")})},IDBIndex.prototype.openCursor=function(e,t){var n=new idbModules.IDBRequest;return new idbModules.IDBCursor(e,t,this.source,n,this.indexName,"value"),n},IDBIndex.prototype.openKeyCursor=function(e,t){var n=new idbModules.IDBRequest;return new idbModules.IDBCursor(e,t,this.source,n,this.indexName,"key"),n},IDBIndex.prototype.__fetchIndexData=function(e,t){var n=this;return n.__idbObjectStore.transaction.__addToTransactionQueue(function(o,i,r,s){var a=["SELECT * FROM ",idbModules.util.quote(n.__idbObjectStore.name)," WHERE",n.indexName,"NOT NULL"],u=[];e!==undefined&&(a.push("AND",n.indexName," = ?"),u.push(idbModules.Key.encode(e))),idbModules.DEBUG&&console.log("Trying to fetch data for Index",a.join(" "),u),o.executeSql(a.join(" "),u,function(e,n){var o;o="count"==typeof t?n.rows.length:0===n.rows.length?undefined:"key"===t?idbModules.Key.decode(n.rows.item(0).key):idbModules.Sca.decode(n.rows.item(0).value),r(o)},s)})},IDBIndex.prototype.get=function(e){return this.__fetchIndexData(e,"value")},IDBIndex.prototype.getKey=function(e){return this.__fetchIndexData(e,"key")},IDBIndex.prototype.count=function(e){return this.__fetchIndexData(e,"count")},idbModules.IDBIndex=IDBIndex}(idbModules),function(idbModules){var IDBObjectStore=function(e,t,n){this.name=e,this.transaction=t,this.__ready={},this.__setReadyState("createObjectStore",n===void 0?!0:n),this.indexNames=new idbModules.util.StringList};IDBObjectStore.prototype.__setReadyState=function(e,t){this.__ready[e]=t},IDBObjectStore.prototype.__waitForReady=function(e,t){var n=!0;if(t!==void 0)n=this.__ready[t]===void 0?!0:this.__ready[t];else for(var o in this.__ready)this.__ready[o]||(n=!1);if(n)e();else{idbModules.DEBUG&&console.log("Waiting for to be ready",t);var i=this;window.setTimeout(function(){i.__waitForReady(e,t)},100)}},IDBObjectStore.prototype.__getStoreProps=function(e,t,n){var o=this;this.__waitForReady(function(){o.__storeProps?(idbModules.DEBUG&&console.log("Store properties - cached",o.__storeProps),t(o.__storeProps)):e.executeSql("SELECT * FROM __sys__ where name = ?",[o.name],function(e,n){1!==n.rows.length?t():(o.__storeProps={name:n.rows.item(0).name,indexList:n.rows.item(0).indexList,autoInc:n.rows.item(0).autoInc,keyPath:n.rows.item(0).keyPath},idbModules.DEBUG&&console.log("Store properties",o.__storeProps),t(o.__storeProps))},function(){t()})},n)},IDBObjectStore.prototype.__deriveKey=function(tx,value,key,callback){function getNextAutoIncKey(){tx.executeSql("SELECT * FROM sqlite_sequence where name like ?",[me.name],function(e,t){1!==t.rows.length?callback(0):callback(t.rows.item(0).seq)},function(e,t){idbModules.util.throwDOMException(0,"Data Error - Could not get the auto increment value for key",t)})}var me=this;me.__getStoreProps(tx,function(props){if(props||idbModules.util.throwDOMException(0,"Data Error - Could not locate defination for this table",props),props.keyPath)if(key!==void 0&&idbModules.util.throwDOMException(0,"Data Error - The object store uses in-line keys and the key parameter was provided",props),value)try{var primaryKey=eval("value['"+props.keyPath+"']");primaryKey?callback(primaryKey):"true"===props.autoInc?getNextAutoIncKey():idbModules.util.throwDOMException(0,"Data Error - Could not eval key from keyPath")}catch(e){idbModules.util.throwDOMException(0,"Data Error - Could not eval key from keyPath",e)}else idbModules.util.throwDOMException(0,"Data Error - KeyPath was specified, but value was not");else key!==void 0?callback(key):"false"===props.autoInc?idbModules.util.throwDOMException(0,"Data Error - The object store uses out-of-line keys and has no key generator and the key parameter was not provided. ",props):getNextAutoIncKey()})},IDBObjectStore.prototype.__insertData=function(tx,value,primaryKey,success,error){var paramMap={};primaryKey!==void 0&&(paramMap.key=idbModules.Key.encode(primaryKey));var indexes=JSON.parse(this.__storeProps.indexList);for(var key in indexes)try{paramMap[indexes[key].columnName]=idbModules.Key.encode(eval("value['"+indexes[key].keyPath+"']"))}catch(e){error(e)}var sqlStart=["INSERT INTO ",idbModules.util.quote(this.name),"("],sqlEnd=[" VALUES ("],sqlValues=[];for(key in paramMap)sqlStart.push(key+","),sqlEnd.push("?,"),sqlValues.push(paramMap[key]);sqlStart.push("value )"),sqlEnd.push("?)"),sqlValues.push(idbModules.Sca.encode(value));var sql=sqlStart.join(" ")+sqlEnd.join(" ");idbModules.DEBUG&&console.log("SQL for adding",sql,sqlValues),tx.executeSql(sql,sqlValues,function(){success(primaryKey)},function(e,t){error(t)})},IDBObjectStore.prototype.add=function(e,t){var n=this;return n.transaction.__addToTransactionQueue(function(o,i,r,s){n.__deriveKey(o,e,t,function(t){n.__insertData(o,e,t,r,s)})})},IDBObjectStore.prototype.put=function(e,t){var n=this;return n.transaction.__addToTransactionQueue(function(o,i,r,s){n.__deriveKey(o,e,t,function(t){var i="DELETE FROM "+idbModules.util.quote(n.name)+" where key = ?";o.executeSql(i,[idbModules.Key.encode(t)],function(o,i){idbModules.DEBUG&&console.log("Did the row with the",t,"exist? ",i.rowsAffected),n.__insertData(o,e,t,r,s)},function(e,t){s(t)})})})},IDBObjectStore.prototype.get=function(e){var t=this;return t.transaction.__addToTransactionQueue(function(n,o,i,r){t.__waitForReady(function(){var o=idbModules.Key.encode(e);idbModules.DEBUG&&console.log("Fetching",t.name,o),n.executeSql("SELECT * FROM "+idbModules.util.quote(t.name)+" where key = ?",[o],function(e,t){idbModules.DEBUG&&console.log("Fetched data",t);try{if(0===t.rows.length)return i();i(idbModules.Sca.decode(t.rows.item(0).value))}catch(n){idbModules.DEBUG&&console.log(n),i(void 0)}},function(e,t){r(t)})})})},IDBObjectStore.prototype["delete"]=function(e){var t=this;return t.transaction.__addToTransactionQueue(function(n,o,i,r){t.__waitForReady(function(){var o=idbModules.Key.encode(e);idbModules.DEBUG&&console.log("Fetching",t.name,o),n.executeSql("DELETE FROM "+idbModules.util.quote(t.name)+" where key = ?",[o],function(e,t){idbModules.DEBUG&&console.log("Deleted from database",t.rowsAffected),i()},function(e,t){r(t)})})})},IDBObjectStore.prototype.clear=function(){var e=this;return e.transaction.__addToTransactionQueue(function(t,n,o,i){e.__waitForReady(function(){t.executeSql("DELETE FROM "+idbModules.util.quote(e.name),[],function(e,t){idbModules.DEBUG&&console.log("Cleared all records from database",t.rowsAffected),o()},function(e,t){i(t)})})})},IDBObjectStore.prototype.count=function(e){var t=this;return t.transaction.__addToTransactionQueue(function(n,o,i,r){t.__waitForReady(function(){var o="SELECT * FROM "+idbModules.util.quote(t.name)+(e!==void 0?" WHERE key = ?":""),s=[];e!==void 0&&s.push(idbModules.Key.encode(e)),n.executeSql(o,s,function(e,t){i(t.rows.length)},function(e,t){r(t)})})})},IDBObjectStore.prototype.openCursor=function(e,t){var n=new idbModules.IDBRequest;return new idbModules.IDBCursor(e,t,this,n,"key","value"),n},IDBObjectStore.prototype.index=function(e){var t=new idbModules.IDBIndex(e,this);return t},IDBObjectStore.prototype.createIndex=function(e,t,n){var o=this;n=n||{},o.__setReadyState("createIndex",!1);var i=new idbModules.IDBIndex(e,o);return o.__waitForReady(function(){i.__createIndex(e,t,n)},"createObjectStore"),o.indexNames.push(e),i},IDBObjectStore.prototype.deleteIndex=function(e){var t=new idbModules.IDBIndex(e,this,!1);return t.__deleteIndex(e),t},idbModules.IDBObjectStore=IDBObjectStore}(idbModules),function(e){var t=0,n=1,o=2,i=function(o,i,r){if("number"==typeof i)this.mode=i,2!==i&&e.DEBUG&&console.log("Mode should be a string, but was specified as ",i);else if("string"==typeof i)switch(i){case"readwrite":this.mode=n;break;case"readonly":this.mode=t;break;default:this.mode=t}this.storeNames="string"==typeof o?[o]:o;for(var s=0;this.storeNames.length>s;s++)r.objectStoreNames.contains(this.storeNames[s])||e.util.throwDOMException(0,"The operation failed because the requested database object could not be found. For example, an object store did not exist but was being opened.",this.storeNames[s]);this.__active=!0,this.__running=!1,this.__requests=[],this.__aborted=!1,this.db=r,this.error=null,this.onabort=this.onerror=this.oncomplete=null};i.prototype.__executeRequests=function(){if(this.__running&&this.mode!==o)return e.DEBUG&&console.log("Looks like the request set is already running",this.mode),void 0;this.__running=!0;var t=this;window.setTimeout(function(){2===t.mode||t.__active||e.util.throwDOMException(0,"A request was placed against a transaction which is currently not active, or which is finished",t.__active),t.db.__db.transaction(function(n){function o(t,n){n&&(s.req=n),s.req.readyState="done",s.req.result=t,delete s.req.error;var o=e.Event("success");e.util.callback("onsuccess",s.req,o),a++,r()}function i(){s.req.readyState="done",s.req.error="DOMError";var t=e.Event("error",arguments);e.util.callback("onerror",s.req,t),a++,r()}function r(){return a>=t.__requests.length?(t.__active=!1,t.__requests=[],void 0):(s=t.__requests[a],s.op(n,s.args,o,i),void 0)}t.__tx=n;var s=null,a=0;try{r()}catch(u){e.DEBUG&&console.log("An exception occured in transaction",arguments),"function"==typeof t.onerror&&t.onerror()}},function(){e.DEBUG&&console.log("An error in transaction",arguments),"function"==typeof t.onerror&&t.onerror()},function(){e.DEBUG&&console.log("Transaction completed",arguments),"function"==typeof t.oncomplete&&t.oncomplete()})},1)},i.prototype.__addToTransactionQueue=function(t,n){this.__active||this.mode===o||e.util.throwDOMException(0,"A request was placed against a transaction which is currently not active, or which is finished.",this.__mode);var i=new e.IDBRequest;return i.source=this.db,this.__requests.push({op:t,args:n,req:i}),this.__executeRequests(),i},i.prototype.objectStore=function(t){return new e.IDBObjectStore(t,this)},i.prototype.abort=function(){!this.__active&&e.util.throwDOMException(0,"A request was placed against a transaction which is currently not active, or which is finished",this.__active)},i.prototype.READ_ONLY=0,i.prototype.READ_WRITE=1,i.prototype.VERSION_CHANGE=2,e.IDBTransaction=i}(idbModules),function(e){var t=function(t,n,o,i){this.__db=t,this.version=o,this.__storeProperties=i,this.objectStoreNames=new e.util.StringList;for(var r=0;i.rows.length>r;r++)this.objectStoreNames.push(i.rows.item(r).name);this.name=n,this.onabort=this.onerror=this.onversionchange=null};t.prototype.createObjectStore=function(t,n){var o=this;n=n||{},n.keyPath=n.keyPath||null;var i=new e.IDBObjectStore(t,o.__versionTransaction,!1),r=o.__versionTransaction;return r.__addToTransactionQueue(function(r,s,a){function u(){e.util.throwDOMException(0,"Could not create new object store",arguments)}o.__versionTransaction||e.util.throwDOMException(0,"Invalid State error",o.transaction);var c=["CREATE TABLE",e.util.quote(t),"(key BLOB",n.autoIncrement?", inc INTEGER PRIMARY KEY AUTOINCREMENT":"PRIMARY KEY",", value BLOB)"].join(" ");e.DEBUG&&console.log(c),r.executeSql(c,[],function(e){e.executeSql("INSERT INTO __sys__ VALUES (?,?,?,?)",[t,n.keyPath,n.autoIncrement?!0:!1,"{}"],function(){i.__setReadyState("createObjectStore",!0),a(i)},u)},u)}),o.objectStoreNames.push(t),i},t.prototype.deleteObjectStore=function(t){var n=function(){e.util.throwDOMException(0,"Could not delete ObjectStore",arguments)},o=this;!o.objectStoreNames.contains(t)&&n("Object Store does not exist"),o.objectStoreNames.splice(o.objectStoreNames.indexOf(t),1);var i=o.__versionTransaction;i.__addToTransactionQueue(function(){o.__versionTransaction||e.util.throwDOMException(0,"Invalid State error",o.transaction),o.__db.transaction(function(o){o.executeSql("SELECT * FROM __sys__ where name = ?",[t],function(o,i){i.rows.length>0&&o.executeSql("DROP TABLE "+e.util.quote(t),[],function(){o.executeSql("DELETE FROM __sys__ WHERE name = ?",[t],function(){},n)},n)})})})},t.prototype.close=function(){},t.prototype.transaction=function(t,n){var o=new e.IDBTransaction(t,n||1,this);return o},e.IDBDatabase=t}(idbModules),function(e){var t=4194304;if(window.openDatabase){var n=window.openDatabase("__sysdb__",1,"System Database",t);n.transaction(function(t){t.executeSql("SELECT * FROM dbVersions",[],function(){},function(){n.transaction(function(t){t.executeSql("CREATE TABLE IF NOT EXISTS dbVersions (name VARCHAR(255), version INT);",[],function(){},function(){e.util.throwDOMException("Could not create table __sysdb__ to save DB versions")})})})},function(){e.DEBUG&&console.log("Error in sysdb transaction - when selecting from dbVersions",arguments)});var o={open:function(o,i){function r(){if(!u){var t=e.Event("error",arguments);a.readyState="done",a.error="DOMError",e.util.callback("onerror",a,t),u=!0}}function s(s){var u=window.openDatabase(o,1,o,t);a.readyState="done",i===void 0&&(i=s||1),(0>=i||s>i)&&e.util.throwDOMException(0,"An attempt was made to open a database using a lower version than the existing version.",i),u.transaction(function(t){t.executeSql("CREATE TABLE IF NOT EXISTS __sys__ (name VARCHAR(255), keyPath VARCHAR(255), autoInc BOOLEAN, indexList BLOB)",[],function(){t.executeSql("SELECT * FROM __sys__",[],function(t,c){var d=e.Event("success");a.source=a.result=new e.IDBDatabase(u,o,i,c),i>s?n.transaction(function(t){t.executeSql("UPDATE dbVersions set version = ? where name = ?",[i,o],function(){var t=e.Event("upgradeneeded");t.oldVersion=s,t.newVersion=i,a.transaction=a.result.__versionTransaction=new e.IDBTransaction([],2,a.source),e.util.callback("onupgradeneeded",a,t,function(){var t=e.Event("success");e.util.callback("onsuccess",a,t)})},r)},r):e.util.callback("onsuccess",a,d)},r)},r)},r)}var a=new e.IDBOpenRequest,u=!1;return n.transaction(function(e){e.executeSql("SELECT * FROM dbVersions where name = ?",[o],function(e,t){0===t.rows.length?e.executeSql("INSERT INTO dbVersions VALUES (?,?)",[o,i||1],function(){s(0)},r):s(t.rows.item(0).version)},r)},r),a},deleteDatabase:function(o){function i(t){if(!a){s.readyState="done",s.error="DOMError";var n=e.Event("error");n.message=t,n.debug=arguments,e.util.callback("onerror",s,n),a=!0}}function r(){n.transaction(function(t){t.executeSql("DELETE FROM dbVersions where name = ? ",[o],function(){s.result=void 0;var t=e.Event("success");t.newVersion=null,t.oldVersion=u,e.util.callback("onsuccess",s,t)},i)},i)}var s=new e.IDBOpenRequest,a=!1,u=null;return n.transaction(function(n){n.executeSql("SELECT * FROM dbVersions where name = ?",[o],function(n,a){if(0===a.rows.length){s.result=void 0;var c=e.Event("success");return c.newVersion=null,c.oldVersion=u,e.util.callback("onsuccess",s,c),void 0}u=a.rows.item(0).version;var d=window.openDatabase(o,1,o,t);d.transaction(function(t){t.executeSql("SELECT * FROM __sys__",[],function(t,n){var o=n.rows;(function s(n){n>=o.length?t.executeSql("DROP TABLE __sys__",[],function(){r()},i):t.executeSql("DROP TABLE "+e.util.quote(o.item(n).name),[],function(){s(n+1)},function(){s(n+1)})})(0)},function(){r()})},i)})},i),s},cmp:function(t,n){return e.Key.encode(t)>e.Key.encode(n)?1:t===n?0:-1}};e.shimIndexedDB=o}}(idbModules),function(e,t){e.openDatabase!==void 0&&(e.shimIndexedDB=t.shimIndexedDB,e.shimIndexedDB&&(e.shimIndexedDB.__useShim=function(){e.indexedDB=t.shimIndexedDB,e.IDBDatabase=t.IDBDatabase,e.IDBTransaction=t.IDBTransaction,e.IDBCursor=t.IDBCursor,e.IDBKeyRange=t.IDBKeyRange},e.shimIndexedDB.__debug=function(e){t.DEBUG=e})),e.indexedDB=e.indexedDB||e.webkitIndexedDB||e.mozIndexedDB||e.oIndexedDB||e.msIndexedDB,e.indexedDB===void 0&&e.openDatabase!==void 0?e.shimIndexedDB.__useShim():(e.IDBDatabase=e.IDBDatabase||e.webkitIDBDatabase,e.IDBTransaction=e.IDBTransaction||e.webkitIDBTransaction,e.IDBCursor=e.IDBCursor||e.webkitIDBCursor,e.IDBKeyRange=e.IDBKeyRange||e.webkitIDBKeyRange,e.IDBTransaction||(e.IDBTransaction={}),e.IDBTransaction.READ_ONLY=e.IDBTransaction.READ_ONLY||"readonly",e.IDBTransaction.READ_WRITE=e.IDBTransaction.READ_WRITE||"readwrite")}(window,idbModules);
+
+var idbModules={};
+(function(idbModules){function callback(fn,context,event,func){event.target=context;(typeof context[fn]==="function")&&context[fn].apply(context,[event]);(typeof func==="function")&&func();}
+function throwDOMException(name,message,error){var e=new DOMException.constructor(0,message);e.name=name;e.message=message;e.stack=arguments.callee.caller;idbModules.DEBUG&&console.log(name,message,error,e);throw e;}
+var StringList=function(){this.length=0;this._items=[];};StringList.prototype={contains:function(str){return-1!==this._items.indexOf(str);},item:function(key){return this._items[key];},indexOf:function(str){return this._items.indexOf(str);},push:function(item){this._items.push(item);this.length+=1;},splice:function(){this._items.splice.apply(this._items,arguments);this.length=this._items.length;}};idbModules.util={"throwDOMException":throwDOMException,"callback":callback,"quote":function(arg){return"'"+arg+"'";},"StringList":StringList};}(idbModules));
+(function(idbModules){var Sca=(function(){return{"encode":function(val){return JSON.stringify(val);},"decode":function(val){return JSON.parse(val);}};}());idbModules.Sca=Sca;}(idbModules));
+(function(idbModules){var collations=["","number","string","boolean","object","undefined"];var getGenericEncoder=function(){return{"encode":function(key){return collations.indexOf(typeof key)+"-"+JSON.stringify(key);},"decode":function(key){if(typeof key==="undefined"){return undefined;}
+else{return JSON.parse(key.substring(2));}}};};var types={"number":getGenericEncoder("number"),"boolean":getGenericEncoder(),"object":getGenericEncoder(),"string":{"encode":function(key){return collations.indexOf("string")+"-"+key;},"decode":function(key){return""+key.substring(2);}},"undefined":{"encode":function(key){return collations.indexOf("undefined")+"-undefined";},"decode":function(key){return undefined;}}};var Key=(function(){return{encode:function(key){return types[typeof key].encode(key);},decode:function(key){return types[collations[key.substring(0,1)]].decode(key);}};}());idbModules.Key=Key;}(idbModules));
+(function(idbModules,undefined){var Event=function(type,debug){return{"type":type,debug:debug,bubbles:false,cancelable:false,eventPhase:0,timeStamp:new Date()};};idbModules.Event=Event;}(idbModules));
+(function(idbModules){var IDBRequest=function(){this.onsuccess=this.onerror=this.result=this.error=this.source=this.transaction=null;this.readyState="pending";};var IDBOpenRequest=function(){this.onblocked=this.onupgradeneeded=null;};IDBOpenRequest.prototype=IDBRequest;idbModules.IDBRequest=IDBRequest;idbModules.IDBOpenRequest=IDBOpenRequest;}(idbModules));
+(function(idbModules,undefined){var IDBKeyRange=function(lower,upper,lowerOpen,upperOpen){this.lower=lower;this.upper=upper;this.lowerOpen=lowerOpen;this.upperOpen=upperOpen;};IDBKeyRange.only=function(value){return new IDBKeyRange(value,value,true,true);};IDBKeyRange.lowerBound=function(value,open){return new IDBKeyRange(value,undefined,open,undefined);};IDBKeyRange.upperBound=function(value){return new IDBKeyRange(undefined,value,undefined,open);};IDBKeyRange.bound=function(lower,upper,lowerOpen,upperOpen){return new IDBKeyRange(lower,upper,lowerOpen,upperOpen);};idbModules.IDBKeyRange=IDBKeyRange;}(idbModules));
+(function(idbModules,undefined){function IDBCursor(range,direction,idbObjectStore,cursorRequest,keyColumnName,valueColumnName){this.__range=range;this.source=this.__idbObjectStore=idbObjectStore;this.__req=cursorRequest;this.key=undefined;this.direction=direction;this.__keyColumnName=keyColumnName;this.__valueColumnName=valueColumnName;if(!this.source.transaction.__active){idbModules.util.throwDOMException("TransactionInactiveError - The transaction this IDBObjectStore belongs to is not active.");}
+this.__offset=-1;this.__lastKeyContinued=undefined;this["continue"]();}
+IDBCursor.prototype.__find=function(key,tx,success,error){var me=this;var sql=["SELECT * FROM ",idbModules.util.quote(me.__idbObjectStore.name)];var sqlValues=[];sql.push("WHERE ",me.__keyColumnName," NOT NULL");if(me.__range&&(me.__range.lower||me.__range.upper)){sql.push("AND");if(me.__range.lower){sql.push(me.__keyColumnName+(me.__range.lowerOpen?" >":" >= ")+" ?");sqlValues.push(idbModules.Key.encode(me.__range.lower));}
+(me.__range.lower&&me.__range.upper)&&sql.push("AND");if(me.__range.upper){sql.push(me.__keyColumnName+(me.__range.upperOpen?" < ":" <= ")+" ?");sqlValues.push(idbModules.Key.encode(me.__range.upper));}}
+if(typeof key!=="undefined"){me.__lastKeyContinued=key;me.__offset=0;}
+if(me.__lastKeyContinued!==undefined){sql.push("AND "+me.__keyColumnName+" >= ?");sqlValues.push(idbModules.Key.encode(me.__lastKeyContinued));}
+sql.push("ORDER BY ",me.__keyColumnName);sql.push("LIMIT 1 OFFSET "+me.__offset);debugger;idbModules.DEBUG&&console.log(sql.join(" "),sqlValues);tx.executeSql(sql.join(" "),sqlValues,function(tx,data){if(data.rows.length===1){var key=idbModules.Key.decode(data.rows.item(0)[me.__keyColumnName]);var val=me.__valueColumnName==="value"?idbModules.Sca.decode(data.rows.item(0)[me.__valueColumnName]):idbModules.Key.decode(data.rows.item(0)[me.__valueColumnName]);success(key,val);}
+else{idbModules.DEBUG&&console.log("Reached end of cursors");success(undefined,undefined);}},function(tx,data){idbModules.DEBUG&&console.log("Could not execute Cursor.continue");error(data);});};IDBCursor.prototype["continue"]=function(key){var me=this;this.__idbObjectStore.transaction.__addToTransactionQueue(function(tx,args,success,error){me.__offset++;me.__find(key,tx,function(key,val){me.key=key;me.value=val;success(typeof me.key!=="undefined"?me:undefined,me.__req);},function(data){error(data);});});};IDBCursor.prototype.advance=function(count){if(count<=0){idbModules.util.throwDOMException("Type Error - Count is invalid - 0 or negative",count);}
+var me=this;this.__idbObjectStore.transaction.__addToTransactionQueue(function(tx,args,success,error){me.__offset+=count;me.__find(undefined,tx,function(key,value){me.key=key;me.value=value;success(typeof me.key!=="undefined"?me:undefined,me.__req);},function(data){error(data);});});};IDBCursor.prototype.update=function(valueToUpdate){var me=this;return this.__idbObjectStore.transaction.__addToTransactionQueue(function(tx,args,success,error){me.__find(undefined,tx,function(key,value){var sql="UPDATE "+idbModules.util.quote(me.__idbObjectStore.name)+" SET value = ? WHERE key = ?";idbModules.DEBUG&&console.log(sql,valueToUpdate,key);tx.executeSql(sql,[idbModules.Sca.encode(valueToUpdate),idbModules.Key.encode(key)],function(tx,data){if(data.rowsAffected===1){success(key);}
+else{error("No rowns with key found"+key);}},function(tx,data){error(data);});},function(data){error(data);});});};IDBCursor.prototype["delete"]=function(){var me=this;return this.__idbObjectStore.transaction.__addToTransactionQueue(function(tx,args,success,error){me.__find(undefined,tx,function(key,value){var sql="DELETE FROM "+idbModules.util.quote(me.__idbObjectStore.name)+" WHERE key = ?";idbModules.DEBUG&&console.log(sql,key);tx.executeSql(sql,[idbModules.Key.encode(key)],function(tx,data){if(data.rowsAffected===1){success(undefined);}
+else{error("No rowns with key found"+key);}},function(tx,data){error(data);});},function(data){error(data);});});};idbModules.IDBCursor=IDBCursor;}(idbModules));
+(function(idbModules,undefined){function IDBIndex(indexName,idbObjectStore){this.indexName=this.name=indexName;this.__idbObjectStore=this.objectStore=this.source=idbObjectStore;var indexList=idbObjectStore.__storeProps&&idbObjectStore.__storeProps.indexList;indexList&&(indexList=JSON.parse(indexList));this.keyPath=((indexList&&indexList[indexName]&&indexList[indexName].keyPath)||indexName);['multiEntry','unique'].forEach(function(prop){this[prop]=!!indexList&&!!indexList[indexName]&&!!indexList[indexName].optionalParams&&!!indexList[indexName].optionalParams[prop];},this);}
+IDBIndex.prototype.__createIndex=function(indexName,keyPath,optionalParameters){var me=this;var transaction=me.__idbObjectStore.transaction;transaction.__addToTransactionQueue(function(tx,args,success,failure){me.__idbObjectStore.__getStoreProps(tx,function(){function error(){idbModules.util.throwDOMException(0,"Could not create new index",arguments);}
+if(transaction.mode!==2){idbModules.util.throwDOMException(0,"Invalid State error, not a version transaction",me.transaction);}
+var idxList=JSON.parse(me.__idbObjectStore.__storeProps.indexList);if(typeof idxList[indexName]!=="undefined"){idbModules.util.throwDOMException(0,"Index already exists on store",idxList);}
+var columnName=indexName;idxList[indexName]={"columnName":columnName,"keyPath":keyPath,"optionalParams":optionalParameters};me.__idbObjectStore.__storeProps.indexList=JSON.stringify(idxList);var sql=["ALTER TABLE",idbModules.util.quote(me.__idbObjectStore.name),"ADD",columnName,"BLOB"].join(" ");idbModules.DEBUG&&console.log(sql);tx.executeSql(sql,[],function(tx,data){tx.executeSql("SELECT * FROM "+idbModules.util.quote(me.__idbObjectStore.name),[],function(tx,data){(function initIndexForRow(i){if(i<data.rows.length){try{var value=idbModules.Sca.decode(data.rows.item(i).value);var indexKey=eval("value['"+keyPath+"']");tx.executeSql("UPDATE "+idbModules.util.quote(me.__idbObjectStore.name)+" set "+columnName+" = ? where key = ?",[idbModules.Key.encode(indexKey),data.rows.item(i).key],function(tx,data){initIndexForRow(i+1);},error);}
+catch(e){initIndexForRow(i+1);}}
+else{idbModules.DEBUG&&console.log("Updating the indexes in table",me.__idbObjectStore.__storeProps);tx.executeSql("UPDATE __sys__ set indexList = ? where name = ?",[me.__idbObjectStore.__storeProps.indexList,me.__idbObjectStore.name],function(){me.__idbObjectStore.__setReadyState("createIndex",true);success(me);},error);}}(0));},error);},error);},"createObjectStore");});};IDBIndex.prototype.openCursor=function(range,direction){var cursorRequest=new idbModules.IDBRequest();var cursor=new idbModules.IDBCursor(range,direction,this.source,cursorRequest,this.indexName,"value");return cursorRequest;};IDBIndex.prototype.openKeyCursor=function(range,direction){var cursorRequest=new idbModules.IDBRequest();var cursor=new idbModules.IDBCursor(range,direction,this.source,cursorRequest,this.indexName,"key");return cursorRequest;};IDBIndex.prototype.__fetchIndexData=function(key,opType){var me=this;return me.__idbObjectStore.transaction.__addToTransactionQueue(function(tx,args,success,error){var sql=["SELECT * FROM ",idbModules.util.quote(me.__idbObjectStore.name)," WHERE",me.indexName,"NOT NULL"];var sqlValues=[];if(typeof key!=="undefined"){sql.push("AND",me.indexName," = ?");sqlValues.push(idbModules.Key.encode(key));}
+idbModules.DEBUG&&console.log("Trying to fetch data for Index",sql.join(" "),sqlValues);tx.executeSql(sql.join(" "),sqlValues,function(tx,data){var d;if(typeof opType==="count"){d=data.rows.length;}
+else
+if(data.rows.length===0){d=undefined;}
+else
+if(opType==="key"){d=idbModules.Key.decode(data.rows.item(0).key);}
+else{d=idbModules.Sca.decode(data.rows.item(0).value);}
+success(d);},error);});};IDBIndex.prototype.get=function(key){return this.__fetchIndexData(key,"value");};IDBIndex.prototype.getKey=function(key){return this.__fetchIndexData(key,"key");};IDBIndex.prototype.count=function(key){return this.__fetchIndexData(key,"count");};idbModules.IDBIndex=IDBIndex;}(idbModules));
+(function(idbModules){var IDBObjectStore=function(name,idbTransaction,ready){this.name=name;this.transaction=idbTransaction;this.__ready={};this.__setReadyState("createObjectStore",typeof ready==="undefined"?true:ready);this.indexNames=new idbModules.util.StringList();};IDBObjectStore.prototype.__setReadyState=function(key,val){this.__ready[key]=val;};IDBObjectStore.prototype.__waitForReady=function(callback,key){var ready=true;if(typeof key!=="undefined"){ready=(typeof this.__ready[key]==="undefined")?true:this.__ready[key];}
+else{for(var x in this.__ready){if(!this.__ready[x]){ready=false;}}}
+if(ready){callback();}
+else{idbModules.DEBUG&&console.log("Waiting for to be ready",key);var me=this;window.setTimeout(function(){me.__waitForReady(callback,key);},100);}};IDBObjectStore.prototype.__getStoreProps=function(tx,callback,waitOnProperty){var me=this;this.__waitForReady(function(){if(me.__storeProps){idbModules.DEBUG&&console.log("Store properties - cached",me.__storeProps);callback(me.__storeProps);}
+else{tx.executeSql("SELECT * FROM __sys__ where name = ?",[me.name],function(tx,data){if(data.rows.length!==1){callback();}
+else{me.__storeProps={"name":data.rows.item(0).name,"indexList":data.rows.item(0).indexList,"autoInc":data.rows.item(0).autoInc,"keyPath":data.rows.item(0).keyPath};idbModules.DEBUG&&console.log("Store properties",me.__storeProps);callback(me.__storeProps);}},function(){callback();});}},waitOnProperty);};IDBObjectStore.prototype.__deriveKey=function(tx,value,key,callback){function getNextAutoIncKey(){tx.executeSql("SELECT * FROM sqlite_sequence where name like ?",[me.name],function(tx,data){if(data.rows.length!==1){callback(0);}
+else{callback(data.rows.item(0).seq);}},function(tx,error){idbModules.util.throwDOMException(0,"Data Error - Could not get the auto increment value for key",error);});}
+var me=this;me.__getStoreProps(tx,function(props){if(!props){idbModules.util.throwDOMException(0,"Data Error - Could not locate defination for this table",props);}
+if(props.keyPath){if(typeof key!=="undefined"){idbModules.util.throwDOMException(0,"Data Error - The object store uses in-line keys and the key parameter was provided",props);}
+if(value){try{var primaryKey=eval("value['"+props.keyPath+"']");if(!primaryKey){if(props.autoInc==="true"){getNextAutoIncKey();}
+else{idbModules.util.throwDOMException(0,"Data Error - Could not eval key from keyPath");}}
+else{callback(primaryKey);}}
+catch(e){idbModules.util.throwDOMException(0,"Data Error - Could not eval key from keyPath",e);}}
+else{idbModules.util.throwDOMException(0,"Data Error - KeyPath was specified, but value was not");}}
+else{if(typeof key!=="undefined"){callback(key);}
+else{if(props.autoInc==="false"){idbModules.util.throwDOMException(0,"Data Error - The object store uses out-of-line keys and has no key generator and the key parameter was not provided. ",props);}
+else{getNextAutoIncKey();}}}});};IDBObjectStore.prototype.__insertData=function(tx,value,primaryKey,success,error){var paramMap={};if(typeof primaryKey!=="undefined"){paramMap.key=idbModules.Key.encode(primaryKey);}
+var indexes=JSON.parse(this.__storeProps.indexList);for(var key in indexes){try{paramMap[indexes[key].columnName]=idbModules.Key.encode(eval("value['"+indexes[key].keyPath+"']"));}
+catch(e){error(e);}}
+var sqlStart=["INSERT INTO ",idbModules.util.quote(this.name),"("];var sqlEnd=[" VALUES ("];var sqlValues=[];for(key in paramMap){sqlStart.push(key+",");sqlEnd.push("?,");sqlValues.push(paramMap[key]);}
+sqlStart.push("value )");sqlEnd.push("?)");sqlValues.push(idbModules.Sca.encode(value));var sql=sqlStart.join(" ")+sqlEnd.join(" ");idbModules.DEBUG&&console.log("SQL for adding",sql,sqlValues);tx.executeSql(sql,sqlValues,function(tx,data){success(primaryKey);},function(tx,err){error(err);});};IDBObjectStore.prototype.add=function(value,key){var me=this;return me.transaction.__addToTransactionQueue(function(tx,args,success,error){me.__deriveKey(tx,value,key,function(primaryKey){me.__insertData(tx,value,primaryKey,success,error);});});};IDBObjectStore.prototype.put=function(value,key){var me=this;return me.transaction.__addToTransactionQueue(function(tx,args,success,error){me.__deriveKey(tx,value,key,function(primaryKey){var sql="DELETE FROM "+idbModules.util.quote(me.name)+" where key = ?";tx.executeSql(sql,[idbModules.Key.encode(primaryKey)],function(tx,data){idbModules.DEBUG&&console.log("Did the row with the",primaryKey,"exist? ",data.rowsAffected);me.__insertData(tx,value,primaryKey,success,error);},function(tx,err){error(err);});});});};IDBObjectStore.prototype.get=function(key){var me=this;return me.transaction.__addToTransactionQueue(function(tx,args,success,error){me.__waitForReady(function(){var primaryKey=idbModules.Key.encode(key);idbModules.DEBUG&&console.log("Fetching",me.name,primaryKey);tx.executeSql("SELECT * FROM "+idbModules.util.quote(me.name)+" where key = ?",[primaryKey],function(tx,data){idbModules.DEBUG&&console.log("Fetched data",data);try{if(0===data.rows.length){return success();}
+success(idbModules.Sca.decode(data.rows.item(0).value));}
+catch(e){idbModules.DEBUG&&console.log(e);success(undefined);}},function(tx,err){error(err);});});});};IDBObjectStore.prototype["delete"]=function(key){var me=this;return me.transaction.__addToTransactionQueue(function(tx,args,success,error){me.__waitForReady(function(){var primaryKey=idbModules.Key.encode(key);idbModules.DEBUG&&console.log("Fetching",me.name,primaryKey);tx.executeSql("DELETE FROM "+idbModules.util.quote(me.name)+" where key = ?",[primaryKey],function(tx,data){idbModules.DEBUG&&console.log("Deleted from database",data.rowsAffected);success();},function(tx,err){error(err);});});});};IDBObjectStore.prototype.clear=function(){var me=this;return me.transaction.__addToTransactionQueue(function(tx,args,success,error){me.__waitForReady(function(){tx.executeSql("DELETE FROM "+idbModules.util.quote(me.name),[],function(tx,data){idbModules.DEBUG&&console.log("Cleared all records from database",data.rowsAffected);success();},function(tx,err){error(err);});});});};IDBObjectStore.prototype.count=function(key){var me=this;return me.transaction.__addToTransactionQueue(function(tx,args,success,error){me.__waitForReady(function(){var sql="SELECT * FROM "+idbModules.util.quote(me.name)+((typeof key!=="undefined")?" WHERE key = ?":"");var sqlValues=[];(typeof key!=="undefined")&&sqlValues.push(idbModules.Key.encode(key));tx.executeSql(sql,sqlValues,function(tx,data){success(data.rows.length);},function(tx,err){error(err);});});});};IDBObjectStore.prototype.openCursor=function(range,direction){var cursorRequest=new idbModules.IDBRequest();var cursor=new idbModules.IDBCursor(range,direction,this,cursorRequest,"key","value");return cursorRequest;};IDBObjectStore.prototype.index=function(indexName){var index=new idbModules.IDBIndex(indexName,this);return index;};IDBObjectStore.prototype.createIndex=function(indexName,keyPath,optionalParameters){var me=this;optionalParameters=optionalParameters||{};me.__setReadyState("createIndex",false);var result=new idbModules.IDBIndex(indexName,me);me.__waitForReady(function(){result.__createIndex(indexName,keyPath,optionalParameters);},"createObjectStore");me.indexNames.push(indexName);return result;};IDBObjectStore.prototype.deleteIndex=function(indexName){var result=new idbModules.IDBIndex(indexName,this,false);result.__deleteIndex(indexName);return result;};idbModules.IDBObjectStore=IDBObjectStore;}(idbModules));
+(function(idbModules){var READ=0;var READ_WRITE=1;var VERSION_TRANSACTION=2;var IDBTransaction=function(storeNames,mode,db){if(typeof mode==="number"){this.mode=mode;(mode!==2)&&idbModules.DEBUG&&console.log("Mode should be a string, but was specified as ",mode);}
+else
+if(typeof mode==="string"){switch(mode){case"readwrite":this.mode=READ_WRITE;break;case"readonly":this.mode=READ;break;default:this.mode=READ;break;}}
+this.storeNames=typeof storeNames==="string"?[storeNames]:storeNames;for(var i=0;i<this.storeNames.length;i++){if(!db.objectStoreNames.contains(this.storeNames[i])){idbModules.util.throwDOMException(0,"The operation failed because the requested database object could not be found. For example, an object store did not exist but was being opened.",this.storeNames[i]);}}
+this.__active=true;this.__running=false;this.__requests=[];this.__aborted=false;this.db=db;this.error=null;this.onabort=this.onerror=this.oncomplete=null;var me=this;};IDBTransaction.prototype.__executeRequests=function(){if(this.__running&&this.mode!==VERSION_TRANSACTION){idbModules.DEBUG&&console.log("Looks like the request set is already running",this.mode);return;}
+this.__running=true;var me=this;window.setTimeout(function(){if(me.mode!==2&&!me.__active){idbModules.util.throwDOMException(0,"A request was placed against a transaction which is currently not active, or which is finished",me.__active);}
+me.db.__db.transaction(function(tx){me.__tx=tx;var q=null,i=0;function success(result,req){if(req){q.req=req;}
+q.req.readyState="done";q.req.result=result;delete q.req.error;var e=idbModules.Event("success");idbModules.util.callback("onsuccess",q.req,e);i++;executeRequest();}
+function error(errorVal){q.req.readyState="done";q.req.error="DOMError";var e=idbModules.Event("error",arguments);idbModules.util.callback("onerror",q.req,e);i++;executeRequest();}
+try{function executeRequest(){if(i>=me.__requests.length){me.__active=false;me.__requests=[];return;}
+q=me.__requests[i];q.op(tx,q.args,success,error);}
+executeRequest();}
+catch(e){idbModules.DEBUG&&console.log("An exception occured in transaction",arguments);typeof me.onerror==="function"&&me.onerror();}},function(){idbModules.DEBUG&&console.log("An error in transaction",arguments);typeof me.onerror==="function"&&me.onerror();},function(){idbModules.DEBUG&&console.log("Transaction completed",arguments);typeof me.oncomplete==="function"&&me.oncomplete();});},1);};IDBTransaction.prototype.__addToTransactionQueue=function(callback,args){if(!this.__active&&this.mode!==VERSION_TRANSACTION){idbModules.util.throwDOMException(0,"A request was placed against a transaction which is currently not active, or which is finished.",this.__mode);}
+var request=new idbModules.IDBRequest();request.source=this.db;this.__requests.push({"op":callback,"args":args,"req":request});this.__executeRequests();return request;};IDBTransaction.prototype.objectStore=function(objectStoreName){return new idbModules.IDBObjectStore(objectStoreName,this);};IDBTransaction.prototype.abort=function(){!this.__active&&idbModules.util.throwDOMException(0,"A request was placed against a transaction which is currently not active, or which is finished",this.__active);};IDBTransaction.prototype.READ_ONLY=0;IDBTransaction.prototype.READ_WRITE=1;IDBTransaction.prototype.VERSION_CHANGE=2;idbModules.IDBTransaction=IDBTransaction;}(idbModules));
+(function(idbModules){var IDBDatabase=function(db,name,version,storeProperties){this.__db=db;this.version=version;this.__storeProperties=storeProperties;this.objectStoreNames=new idbModules.util.StringList();for(var i=0;i<storeProperties.rows.length;i++){this.objectStoreNames.push(storeProperties.rows.item(i).name);}
+this.name=name;this.onabort=this.onerror=this.onversionchange=null;};IDBDatabase.prototype.createObjectStore=function(storeName,createOptions){var me=this;createOptions=createOptions||{};createOptions.keyPath=createOptions.keyPath||null;var result=new idbModules.IDBObjectStore(storeName,me.__versionTransaction,false);var transaction=me.__versionTransaction;transaction.__addToTransactionQueue(function(tx,args,success,failure){function error(){idbModules.util.throwDOMException(0,"Could not create new object store",arguments);}
+if(!me.__versionTransaction){idbModules.util.throwDOMException(0,"Invalid State error",me.transaction);}
+var sql=["CREATE TABLE",idbModules.util.quote(storeName),"(key BLOB",createOptions.autoIncrement?", inc INTEGER PRIMARY KEY AUTOINCREMENT":"PRIMARY KEY",", value BLOB)"].join(" ");idbModules.DEBUG&&console.log(sql);tx.executeSql(sql,[],function(tx,data){tx.executeSql("INSERT INTO __sys__ VALUES (?,?,?,?)",[storeName,createOptions.keyPath,createOptions.autoIncrement?true:false,"{}"],function(){result.__setReadyState("createObjectStore",true);success(result);},error);},error);});me.objectStoreNames.push(storeName);return result;};IDBDatabase.prototype.deleteObjectStore=function(storeName){var error=function(){idbModules.util.throwDOMException(0,"Could not delete ObjectStore",arguments);};var me=this;!me.objectStoreNames.contains(storeName)&&error("Object Store does not exist");me.objectStoreNames.splice(me.objectStoreNames.indexOf(storeName),1);var transaction=me.__versionTransaction;transaction.__addToTransactionQueue(function(tx,args,success,failure){if(!me.__versionTransaction){idbModules.util.throwDOMException(0,"Invalid State error",me.transaction);}
+me.__db.transaction(function(tx){tx.executeSql("SELECT * FROM __sys__ where name = ?",[storeName],function(tx,data){if(data.rows.length>0){tx.executeSql("DROP TABLE "+idbModules.util.quote(storeName),[],function(){tx.executeSql("DELETE FROM __sys__ WHERE name = ?",[storeName],function(){},error);},error);}});});});};IDBDatabase.prototype.close=function(){};IDBDatabase.prototype.transaction=function(storeNames,mode){var transaction=new idbModules.IDBTransaction(storeNames,mode||1,this);return transaction;};idbModules.IDBDatabase=IDBDatabase;}(idbModules));
+(function(idbModules){var DEFAULT_DB_SIZE=4*1024*1024;if(!window.openDatabase){return;}
+var sysdb=window.openDatabase("__sysdb__",1,"System Database",DEFAULT_DB_SIZE);sysdb.transaction(function(tx){tx.executeSql("SELECT * FROM dbVersions",[],function(t,data){},function(){sysdb.transaction(function(tx){tx.executeSql("CREATE TABLE IF NOT EXISTS dbVersions (name VARCHAR(255), version INT);",[],function(){},function(){idbModules.util.throwDOMException("Could not create table __sysdb__ to save DB versions");});});});},function(){idbModules.DEBUG&&console.log("Error in sysdb transaction - when selecting from dbVersions",arguments);});var shimIndexedDB={open:function(name,version){var req=new idbModules.IDBOpenRequest();var calledDbCreateError=false;function dbCreateError(){if(calledDbCreateError){return;}
+var e=idbModules.Event("error",arguments);req.readyState="done";req.error="DOMError";idbModules.util.callback("onerror",req,e);calledDbCreateError=true;}
+function openDB(oldVersion){var db=window.openDatabase(name,1,name,DEFAULT_DB_SIZE);req.readyState="done";if(typeof version==="undefined"){version=oldVersion||1;}
+if(version<=0||oldVersion>version){idbModules.util.throwDOMException(0,"An attempt was made to open a database using a lower version than the existing version.",version);}
+db.transaction(function(tx){tx.executeSql("CREATE TABLE IF NOT EXISTS __sys__ (name VARCHAR(255), keyPath VARCHAR(255), autoInc BOOLEAN, indexList BLOB)",[],function(){tx.executeSql("SELECT * FROM __sys__",[],function(tx,data){var e=idbModules.Event("success");req.source=req.result=new idbModules.IDBDatabase(db,name,version,data);if(oldVersion<version){sysdb.transaction(function(systx){systx.executeSql("UPDATE dbVersions set version = ? where name = ?",[version,name],function(){var e=idbModules.Event("upgradeneeded");e.oldVersion=oldVersion;e.newVersion=version;req.transaction=req.result.__versionTransaction=new idbModules.IDBTransaction([],2,req.source);idbModules.util.callback("onupgradeneeded",req,e,function(){var e=idbModules.Event("success");idbModules.util.callback("onsuccess",req,e);});},dbCreateError);},dbCreateError);}else{idbModules.util.callback("onsuccess",req,e);}},dbCreateError);},dbCreateError);},dbCreateError);}
+sysdb.transaction(function(tx){tx.executeSql("SELECT * FROM dbVersions where name = ?",[name],function(tx,data){if(data.rows.length===0){tx.executeSql("INSERT INTO dbVersions VALUES (?,?)",[name,version||1],function(){openDB(0);},dbCreateError);}else{openDB(data.rows.item(0).version);}},dbCreateError);},dbCreateError);return req;},"deleteDatabase":function(name){var req=new idbModules.IDBOpenRequest();var calledDBError=false;function dbError(msg){if(calledDBError){return;}
+req.readyState="done";req.error="DOMError";var e=idbModules.Event("error");e.message=msg;e.debug=arguments;idbModules.util.callback("onerror",req,e);calledDBError=true;}
+var version=null;function deleteFromDbVersions(){sysdb.transaction(function(systx){systx.executeSql("DELETE FROM dbVersions where name = ? ",[name],function(){req.result=undefined;var e=idbModules.Event("success");e.newVersion=null;e.oldVersion=version;idbModules.util.callback("onsuccess",req,e);},dbError);},dbError);}
+sysdb.transaction(function(systx){systx.executeSql("SELECT * FROM dbVersions where name = ?",[name],function(tx,data){if(data.rows.length===0){req.result=undefined;var e=idbModules.Event("success");e.newVersion=null;e.oldVersion=version;idbModules.util.callback("onsuccess",req,e);return;}
+version=data.rows.item(0).version;var db=window.openDatabase(name,1,name,DEFAULT_DB_SIZE);db.transaction(function(tx){tx.executeSql("SELECT * FROM __sys__",[],function(tx,data){var tables=data.rows;(function deleteTables(i){if(i>=tables.length){tx.executeSql("DROP TABLE __sys__",[],function(){deleteFromDbVersions();},dbError);}else{tx.executeSql("DROP TABLE "+idbModules.util.quote(tables.item(i).name),[],function(){deleteTables(i+1);},function(){deleteTables(i+1);});}}(0));},function(e){deleteFromDbVersions();});},dbError);});},dbError);return req;},"cmp":function(key1,key2){return idbModules.Key.encode(key1)>idbModules.Key.encode(key2)?1:key1===key2?0:-1;}};idbModules.shimIndexedDB=shimIndexedDB;}(idbModules));
+(function(window,idbModules){if(typeof window.openDatabase!=="undefined"){window.shimIndexedDB=idbModules.shimIndexedDB;if(window.shimIndexedDB){window.shimIndexedDB.__useShim=function(){window.indexedDB=idbModules.shimIndexedDB;window.IDBDatabase=idbModules.IDBDatabase;window.IDBTransaction=idbModules.IDBTransaction;window.IDBCursor=idbModules.IDBCursor;window.IDBKeyRange=idbModules.IDBKeyRange;};window.shimIndexedDB.__debug=function(val){idbModules.DEBUG=val;};}}
+window.indexedDB=window.indexedDB||window.webkitIndexedDB||window.mozIndexedDB||window.oIndexedDB||window.msIndexedDB;if(typeof window.indexedDB==="undefined"&&typeof window.openDatabase!=="undefined"){window.shimIndexedDB.__useShim();}
+else{window.IDBDatabase=window.IDBDatabase||window.webkitIDBDatabase;window.IDBTransaction=window.IDBTransaction||window.webkitIDBTransaction;window.IDBCursor=window.IDBCursor||window.webkitIDBCursor;window.IDBKeyRange=window.IDBKeyRange||window.webkitIDBKeyRange;if(!window.IDBTransaction){window.IDBTransaction={};}
+window.IDBTransaction.READ_ONLY=window.IDBTransaction.READ_ONLY||"readonly";window.IDBTransaction.READ_WRITE=window.IDBTransaction.READ_WRITE||"readwrite";}}(window,idbModules));
+//@ sourceMappingURL=IndexedDBShim.min.js.map
View
2  dist/IndexedDBShim.min.js.map
1 addition, 1 deletion not shown
View
3  package.json
@@ -29,7 +29,8 @@
"grunt-contrib-connect": "~0.1.2",
"grunt-saucelabs": "~3.0.0",
"grunt-contrib-jshint": "~0.1.1",
- "grunt-jsmin-sourcemap": "~1.6.0"
+ "grunt-jsmin-sourcemap": "~1.7.0",
+ "grunt-contrib-watch": "~0.3.1"
},
"bundleDependencies": [],
"license": "MIT",
View
2  src/Event.js
@@ -13,4 +13,4 @@
};
};
idbModules.Event = Event;
-}(idbModules));
+}(idbModules));
View
1  src/IDBCursor.js
@@ -56,6 +56,7 @@
}
sql.push("ORDER BY ", me.__keyColumnName);
sql.push("LIMIT 1 OFFSET " + me.__offset);
+ debugger;
idbModules.DEBUG && console.log(sql.join(" "), sqlValues);
tx.executeSql(sql.join(" "), sqlValues, function(tx, data){
if (data.rows.length === 1) {
View
2  test/CursorTests.js
@@ -4,7 +4,7 @@ function openObjectStore(name, storeName, callback){
dbOpenRequest.onsuccess = function(e){
_("Database opened successfully");
var db = dbOpenRequest.result;
- var transaction = db.transaction([DB.OBJECT_STORE_1, DB.OBJECT_STORE_2], IDBTransaction.READ_WRITE);
+ var transaction = db.transaction([DB.OBJECT_STORE_1, DB.OBJECT_STORE_2], "readwrite");
var objectStore = transaction.objectStore(DB.OBJECT_STORE_1);
callback(objectStore);
};
View
2  test/IndexTests.js
@@ -43,7 +43,7 @@ function openObjectStore(name, storeName, callback){
dbOpenRequest.onsuccess = function(e){
_("Database opened successfully");
var db = dbOpenRequest.result;
- var transaction = db.transaction([DB.OBJECT_STORE_1, DB.OBJECT_STORE_2], IDBTransaction.READ_WRITE);
+ var transaction = db.transaction([DB.OBJECT_STORE_1, DB.OBJECT_STORE_2], "readwrite");
var objectStore = transaction.objectStore(DB.OBJECT_STORE_1);
callback(objectStore);
};
View
4 test/ObjectStoreCrudTests.js
@@ -5,7 +5,7 @@ function onObjectStoreOpen(name, storeName, callback){
_("Database opened successfully");
ok(true, "Database Opened successfully");
var db = dbOpenRequest.result;
- var transaction = db.transaction([DB.OBJECT_STORE_1, DB.OBJECT_STORE_2, DB.OBJECT_STORE_3, DB.OBJECT_STORE_4], IDBTransaction.READ_WRITE);
+ var transaction = db.transaction([DB.OBJECT_STORE_1, DB.OBJECT_STORE_2, DB.OBJECT_STORE_3, DB.OBJECT_STORE_4], "readwrite");
var objectStore = transaction.objectStore(storeName);
callback(objectStore);
};
@@ -222,7 +222,7 @@ queuedAsyncTest("Lots of data Added to objectStore1", function(){
_("Database opened successfully");
ok(true, "Database Opened successfully");
var db = dbOpenRequest.result;
- var transaction = db.transaction([DB.OBJECT_STORE_1], IDBTransaction.READ_WRITE);
+ var transaction = db.transaction([DB.OBJECT_STORE_1], "readwrite");
var objectStore = transaction.objectStore(DB.OBJECT_STORE_1);
var counter = 0, max = 15;
var success = function(){
View
3  test/index.html
@@ -37,7 +37,7 @@
</script>
<script type = "text/javascript" src= "sampleData.js">
</script>
- <script type = "text/javascript" src= "../dist/IndexedDBShim.js">
+ <script type = "text/javascript" src= "../dist/IndexedDBShim.min.js">
</script>
<script type = "text/javascript">
function startTests(){
@@ -46,6 +46,7 @@
}
else {
window.indexedDB = window.shimIndexedDB;
+ window.shimIndexedDB.__useShim();
window.shimIndexedDB.__debug(true);
console.log("Starting Tests with shimIndexedDB");
}
Please sign in to comment.
Something went wrong with that request. Please try again.