From 5ad3b0b42072f0df6c1a839391d27853460ca02e Mon Sep 17 00:00:00 2001 From: Thodoris Greasidis Date: Mon, 29 Apr 2019 23:20:20 +0300 Subject: [PATCH 1/4] Drop bower support --- README.md | 4 +--- bower.json | 23 ----------------------- 2 files changed, 1 insertion(+), 26 deletions(-) delete mode 100644 bower.json diff --git a/README.md b/README.md index 80cbcd5..1ab0159 100644 --- a/README.md +++ b/README.md @@ -14,9 +14,7 @@ SQLite driver for [Cordova](https://cordova.apache.org/) apps using [localForage ## Install Dependencies * install Cordova-sqlite-storage plugin `cordova plugin add https://github.com/litehelpers/Cordova-sqlite-storage.git` -* install localForage-cordovaSQLiteDriver - * via npm with: `npm i --save localforage localforage-cordovasqlitedriver` (ionic 2 users might prefer ths one) - * via bower with: `bower install --save localforage localForage-cordovaSQLiteDriver` +* install localForage-cordovaSQLiteDriver via npm with: `npm i --save localforage localforage-cordovasqlitedriver` (ionic 2 users might prefer ths one) #### Cordova-sqlcipher-adapter support install the plugin by diff --git a/bower.json b/bower.json deleted file mode 100644 index 9bd2a8a..0000000 --- a/bower.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "localforage-cordovasqlitedriver", - "version": "1.7.0", - "main": [ - "dist/localforage-cordovasqlitedriver.js" - ], - "ignore": [ - ".travis.yml", - "CONTRIBUTING.md", - "config.rb", - "Gemfile", - "Gemfile.lock", - "Rakefile", - "LICENSE", - "docs*", - "examples*", - "test*", - "site*" - ], - "dependencies": { - "localforage": "^1.5.0" - } -} From 7f291da15715394f5ea8ba94efbaaae5ba930598 Mon Sep 17 00:00:00 2001 From: Thodoris Greasidis Date: Mon, 29 Apr 2019 23:27:51 +0300 Subject: [PATCH 2/4] Remove the dist folder from the repo --- .gitignore | 2 +- .npmignore | 10 ++ dist/localforage-cordovasqlitedriver.es6.js | 160 ------------------- dist/localforage-cordovasqlitedriver.js | 168 -------------------- 4 files changed, 11 insertions(+), 329 deletions(-) create mode 100644 .npmignore delete mode 100644 dist/localforage-cordovasqlitedriver.es6.js delete mode 100644 dist/localforage-cordovasqlitedriver.js diff --git a/.gitignore b/.gitignore index 0f1e467..ff4d57d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ build bower_components node_modules -components +dist # Logs + Sauce Labs Tests *.log diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..1549c54 --- /dev/null +++ b/.npmignore @@ -0,0 +1,10 @@ +.babelrc +.eslintrc +.jscsrc +.jshintrc +.travis.yml +build/ +rollup.config.es6.js +rollup.config.js +rollup.config.test.js +rollup.config.umd.js diff --git a/dist/localforage-cordovasqlitedriver.es6.js b/dist/localforage-cordovasqlitedriver.es6.js deleted file mode 100644 index c942a13..0000000 --- a/dist/localforage-cordovasqlitedriver.es6.js +++ /dev/null @@ -1,160 +0,0 @@ -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); - 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); - } -}); - -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.'); - } - }); -} - -/* - * 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 - }; - - 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, - key: dbInfo.dbKey, - 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); - }); - }); - }); - }); - - var serializerPromise = getSerializerPromise(self); - var webSqlDriverPromise = getWebSqlDriverPromise(self); - - 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; - }); - } -}; - -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); - }); - }; - } - - for (var i = 0, len = LibraryMethods.length; i < len; i++) { - wireUpDriverMethod(driver, LibraryMethods[i]); - } -} - -wireUpDriverMethods(cordovaSQLiteDriver); - -export default cordovaSQLiteDriver; diff --git a/dist/localforage-cordovasqlitedriver.js b/dist/localforage-cordovasqlitedriver.js deleted file mode 100644 index 73182c2..0000000 --- a/dist/localforage-cordovasqlitedriver.js +++ /dev/null @@ -1,168 +0,0 @@ -(function (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : - typeof define === 'function' && define.amd ? define(factory) : - (global.cordovaSQLiteDriver = factory()); -}(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(); - 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); - 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); - } -}); - -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.'); - } - }); -} - -/* - * 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 - }; - - 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, - key: dbInfo.dbKey, - 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); - }); - }); - }); - }); - - var serializerPromise = getSerializerPromise(self); - var webSqlDriverPromise = getWebSqlDriverPromise(self); - - 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; - }); - } -}; - -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); - }); - }; - } - - for (var i = 0, len = LibraryMethods.length; i < len; i++) { - wireUpDriverMethod(driver, LibraryMethods[i]); - } -} - -wireUpDriverMethods(cordovaSQLiteDriver); - -return cordovaSQLiteDriver; - -}))); From 476c4fe78ed792c84427ba1730fd52c57bcbf907 Mon Sep 17 00:00:00 2001 From: Thodoris Greasidis Date: Mon, 29 Apr 2019 23:23:34 +0300 Subject: [PATCH 3/4] Use a prepare script instead of a prepublish --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b42f419..8384438 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,9 @@ "prebuild": "eslint lib test", "build": "rollup -c rollup.config.umd.js && rollup -c rollup.config.es6.js", "pretest": "rollup -c rollup.config.test.js", - "test": "mocha build/test-bundle.js", - "prepublish": "npm run build && npm test" + "test:only": "mocha build/test-bundle.js", + "test": "npm run build && npm run test:only", + "prepare": "npm run build" }, "repository": { "type": "git", From 7a4ac27176efbab130fc88a47413744186be0b50 Mon Sep 17 00:00:00 2001 From: Thodoris Greasidis Date: Sat, 18 May 2019 23:14:40 +0300 Subject: [PATCH 4/4] Add dropInstance method Resolves #30 --- lib/localforage-cordovasqlitedriver.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/localforage-cordovasqlitedriver.js b/lib/localforage-cordovasqlitedriver.js index 1481e81..db6d26e 100644 --- a/lib/localforage-cordovasqlitedriver.js +++ b/lib/localforage-cordovasqlitedriver.js @@ -98,7 +98,8 @@ function wireUpDriverMethods(driver) { 'keys', 'length', 'removeItem', - 'setItem' + 'setItem', + 'dropInstance' ]; function wireUpDriverMethod(driver, methodName) {