Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use localforage v1.5 & drop @types #19

Merged
merged 5 commits into from
Feb 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"presets": [ "es2015-rollup" ]
"presets": [ "es2015" ]
}
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ SQLite driver for [Cordova](https://cordova.apache.org/) apps using [localForage

* [Cordova](https://cordova.apache.org/)/[ionic](http://ionicframework.com/)
* [Cordova SQLite storage plugin](https://github.com/litehelpers/Cordova-sqlite-storage/) or [Cordova SQLite Plugin 2](https://github.com/nolanlawson/cordova-plugin-sqlite-2)
* [localForage](https://github.com/mozilla/localForage) v1.4.0+
* for earlier versions of localforage, please use the v1.2.x releases
* [localForage](https://github.com/mozilla/localForage) v1.5.0+
* for localforage 1.4.x, please use the v1.5.0 release of this package
* for even older versions of localforage, please use the v1.2.x releases


## Install Dependencies

Expand Down
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "localforage-cordovasqlitedriver",
"version": "1.5.0",
"version": "1.6.0",
"main": [
"dist/localforage-cordovasqlitedriver.js"
],
Expand All @@ -18,6 +18,6 @@
"site*"
],
"dependencies": {
"localforage": "^1.4.0"
"localforage": "^1.5.0"
}
}
13 changes: 12 additions & 1 deletion dist/localforage-cordovasqlitedriver.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ function getOpenDatabasePromise() {
});
}

/*
* Includes code from:
*
* localForage - websql driver
* https://github.com/mozilla/localforage
*
* Copyright (c) 2015 Mozilla
* Licensed under Apache 2.0 license.
*
*/
// import localforage from 'localforage';
// // If cordova is not present, we can stop now.
// if (!globalObject.cordova) {
// return;
Expand Down Expand Up @@ -145,4 +156,4 @@ function wireUpDriverMethods(driver) {

wireUpDriverMethods(cordovaSQLiteDriver);

export default cordovaSQLiteDriver;
export default cordovaSQLiteDriver;
253 changes: 132 additions & 121 deletions dist/localforage-cordovasqlitedriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,155 +2,166 @@
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.cordovaSQLiteDriver = factory());
}(this, function () { 'use strict';
}(this, (function () { 'use strict';

function getSerializerPromise(localForageInstance) {
if (getSerializerPromise.result) {
return getSerializerPromise.result;
}
if (!localForageInstance || typeof localForageInstance.getSerializer !== 'function') {
return Promise.reject(new Error('localforage.getSerializer() was not available! ' + 'localforage v1.4+ is required!'));
}
getSerializerPromise.result = localForageInstance.getSerializer();
function getSerializerPromise(localForageInstance) {
if (getSerializerPromise.result) {
return getSerializerPromise.result;
}
if (!localForageInstance || typeof localForageInstance.getSerializer !== 'function') {
return Promise.reject(new Error('localforage.getSerializer() was not available! ' + 'localforage v1.4+ is required!'));
}
getSerializerPromise.result = localForageInstance.getSerializer();
return getSerializerPromise.result;
}

function getDriverPromise(localForageInstance, driverName) {
getDriverPromise.result = getDriverPromise.result || {};
if (getDriverPromise.result[driverName]) {
return getDriverPromise.result[driverName];
}
if (!localForageInstance || typeof localForageInstance.getDriver !== 'function') {
return Promise.reject(new Error('localforage.getDriver() was not available! ' + 'localforage v1.4+ is required!'));
}
getDriverPromise.result[driverName] = localForageInstance.getDriver(driverName);
function getDriverPromise(localForageInstance, driverName) {
getDriverPromise.result = getDriverPromise.result || {};
if (getDriverPromise.result[driverName]) {
return getDriverPromise.result[driverName];
}

function getWebSqlDriverPromise(localForageInstance) {
return getDriverPromise(localForageInstance, localForageInstance.WEBSQL);
if (!localForageInstance || typeof localForageInstance.getDriver !== 'function') {
return Promise.reject(new Error('localforage.getDriver() was not available! ' + 'localforage v1.4+ is required!'));
}
getDriverPromise.result[driverName] = localForageInstance.getDriver(driverName);
return getDriverPromise.result[driverName];
}

function getWebSqlDriverPromise(localForageInstance) {
return getDriverPromise(localForageInstance, localForageInstance.WEBSQL);
}

/* global document, sqlitePlugin */
// we can't import this, since it gets defined later
// import sqlitePlugin from 'sqlitePlugin';

var deviceReady = new Promise(function (resolve, reject) {
if (typeof sqlitePlugin !== 'undefined') {
resolve();
} else if (typeof cordova === 'undefined') {
reject(new Error('cordova is not defined.'));
} else {
// Wait for Cordova to load
document.addEventListener("deviceready", function () {
return resolve();
}, false);
}
});

/* global document, sqlitePlugin */
// we can't import this, since it gets defined later
// import sqlitePlugin from 'sqlitePlugin';
var deviceReadyDone = deviceReady.catch(function () {
return Promise.resolve();
});

var deviceReady = new Promise(function (resolve, reject) {
if (typeof sqlitePlugin !== 'undefined') {
resolve();
} else if (typeof cordova === 'undefined') {
reject(new Error('cordova is not defined.'));
function getOpenDatabasePromise() {
return deviceReadyDone.then(function () {
if (typeof sqlitePlugin !== 'undefined' && typeof sqlitePlugin.openDatabase === 'function') {
return sqlitePlugin.openDatabase;
} else {
// Wait for Cordova to load
document.addEventListener("deviceready", function () {
return resolve();
}, false);
throw new Error('SQLite plugin is not present.');
}
});
}

/*
* Includes code from:
*
* localForage - websql driver
* https://github.com/mozilla/localforage
*
* Copyright (c) 2015 Mozilla
* Licensed under Apache 2.0 license.
*
*/
// import localforage from 'localforage';
// // If cordova is not present, we can stop now.
// if (!globalObject.cordova) {
// return;
// }

// Open the cordova sqlite plugin database (automatically creates one if one didn't
// previously exist), using any options set in the config.
function _initStorage(options) {
var self = this;
var dbInfo = {
db: null
};

var deviceReadyDone = deviceReady.catch(function () {
return Promise.resolve();
});

function getOpenDatabasePromise() {
return deviceReadyDone.then(function () {
if (typeof sqlitePlugin !== 'undefined' && typeof sqlitePlugin.openDatabase === 'function') {
return sqlitePlugin.openDatabase;
} else {
throw new Error('SQLite plugin is not present.');
}
});
if (options) {
for (var i in options) {
dbInfo[i] = typeof options[i] !== 'string' ? options[i].toString() : options[i];
}
}

// // If cordova is not present, we can stop now.
// if (!globalObject.cordova) {
// return;
// }

// Open the cordova sqlite plugin database (automatically creates one if one didn't
// previously exist), using any options set in the config.
function _initStorage(options) {
var self = this;
var dbInfo = {
db: null
};

if (options) {
for (var i in options) {
dbInfo[i] = typeof options[i] !== 'string' ? options[i].toString() : options[i];
var dbInfoPromise = getOpenDatabasePromise().then(function (openDatabase) {
return new Promise(function (resolve, reject) {
// Open the database; the openDatabase API will automatically
// create it for us if it doesn't exist.
try {
dbInfo.location = dbInfo.location || 'default';
dbInfo.db = openDatabase({
name: dbInfo.name,
version: String(dbInfo.version),
description: dbInfo.description,
size: dbInfo.size,
location: dbInfo.location
});
} catch (e) {
reject(e);
}
}

var dbInfoPromise = getOpenDatabasePromise().then(function (openDatabase) {
return new Promise(function (resolve, reject) {
// Open the database; the openDatabase API will automatically
// create it for us if it doesn't exist.
try {
dbInfo.location = dbInfo.location || 'default';
dbInfo.db = openDatabase({
name: dbInfo.name,
version: String(dbInfo.version),
description: dbInfo.description,
size: dbInfo.size,
location: dbInfo.location
});
} catch (e) {
reject(e);
}

// Create our key/value table if it doesn't exist.
dbInfo.db.transaction(function (t) {
t.executeSql('CREATE TABLE IF NOT EXISTS ' + dbInfo.storeName + ' (id INTEGER PRIMARY KEY, key unique, value)', [], function () {
self._dbInfo = dbInfo;
resolve();
}, function (t, error) {
reject(error);
});
// Create our key/value table if it doesn't exist.
dbInfo.db.transaction(function (t) {
t.executeSql('CREATE TABLE IF NOT EXISTS ' + dbInfo.storeName + ' (id INTEGER PRIMARY KEY, key unique, value)', [], function () {
self._dbInfo = dbInfo;
resolve();
}, function (t, error) {
reject(error);
});
});
});
});

var serializerPromise = getSerializerPromise(self);
var webSqlDriverPromise = getWebSqlDriverPromise(self);
var serializerPromise = getSerializerPromise(self);
var webSqlDriverPromise = getWebSqlDriverPromise(self);

return Promise.all([serializerPromise, webSqlDriverPromise, dbInfoPromise]).then(function (results) {
dbInfo.serializer = results[0];
return dbInfoPromise;
return Promise.all([serializerPromise, webSqlDriverPromise, dbInfoPromise]).then(function (results) {
dbInfo.serializer = results[0];
return dbInfoPromise;
});
}

var cordovaSQLiteDriver = {
_driver: 'cordovaSQLiteDriver',
_initStorage: _initStorage,
_support: function _support() {
return getOpenDatabasePromise().then(function (openDatabase) {
return !!openDatabase;
}).catch(function () {
return false;
});
}
};

var cordovaSQLiteDriver = {
_driver: 'cordovaSQLiteDriver',
_initStorage: _initStorage,
_support: function _support() {
return getOpenDatabasePromise().then(function (openDatabase) {
return !!openDatabase;
}).catch(function () {
return false;
});
}
};

function wireUpDriverMethods(driver) {
var LibraryMethods = ['clear', 'getItem', 'iterate', 'key', 'keys', 'length', 'removeItem', 'setItem'];
function wireUpDriverMethods(driver) {
var LibraryMethods = ['clear', 'getItem', 'iterate', 'key', 'keys', 'length', 'removeItem', 'setItem'];

function wireUpDriverMethod(driver, methodName) {
driver[methodName] = function () {
var localForageInstance = this;
var args = arguments;
return getWebSqlDriverPromise(localForageInstance).then(function (webSqlDriver) {
return webSqlDriver[methodName].apply(localForageInstance, args);
});
};
}
function wireUpDriverMethod(driver, methodName) {
driver[methodName] = function () {
var localForageInstance = this;
var args = arguments;
return getWebSqlDriverPromise(localForageInstance).then(function (webSqlDriver) {
return webSqlDriver[methodName].apply(localForageInstance, args);
});
};
}

for (var i = 0, len = LibraryMethods.length; i < len; i++) {
wireUpDriverMethod(driver, LibraryMethods[i]);
}
for (var i = 0, len = LibraryMethods.length; i < len; i++) {
wireUpDriverMethod(driver, LibraryMethods[i]);
}
}

wireUpDriverMethods(cordovaSQLiteDriver);
wireUpDriverMethods(cordovaSQLiteDriver);

return cordovaSQLiteDriver;
return cordovaSQLiteDriver;

}));
})));
18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "localforage-cordovasqlitedriver",
"version": "1.5.0",
"version": "1.6.0",
"description": "SQLite driver for Cordova apps using localForage.",
"homepage": "https://github.com/thgreasi/localForage-cordovaSQLiteDriver",
"main": "dist/localforage-cordovasqlitedriver.js",
Expand Down Expand Up @@ -29,18 +29,20 @@
"url": "http://github.com/thgreasi/localForage-cordovaSQLiteDriver/issues"
},
"devDependencies": {
"babel-eslint": "^6.0.4",
"babel-preset-es2015-rollup": "^1.1.1",
"babel-eslint": "^7.1.1",
"babel-plugin-external-helpers": "^6.18.0",
"babel-preset-es2015": "^6.18.0",
"babel-register": "^6.18.0",
"babelrc-rollup": "^3.0.0",
"eslint": "^2.8.0",
"mocha": "^2.4.5",
"requirejs": "^2.2.0",
"rollup": "^0.26.1",
"rollup-plugin-babel": "^2.4.0",
"rollup-plugin-multi-entry": "^1.2.0",
"rollup": "^0.37.0",
"rollup-plugin-babel": "^2.7.1",
"rollup-plugin-multi-entry": "^2.0.1",
"source-map-support": "^0.4.0"
},
"dependencies": {
"@types/localforage": "0.0.30",
"localforage": ">=1.4.0"
"localforage": ">=1.5.0"
}
}
3 changes: 2 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import babel from 'rollup-plugin-babel';
import babelrc from 'babelrc-rollup';

export default {
entry: 'lib/localforage-cordovasqlitedriver.js',
// sourceMap: true,
plugins: [babel()]
plugins: [babel(babelrc())]
};
Loading