diff --git a/README.md b/README.md index d4e3333..a1efe98 100644 --- a/README.md +++ b/README.md @@ -31,21 +31,25 @@ And you can now have access to all the methods exposed by the module. They inclu **Query (read) data from table** ```javascript dv.queryData(serviceName, tableName, queryParams, callback); +dv.asyncQueryData(serviceName, tableName, queryParams); ``` **Add data to table** ```javascript dv.addData(serviceName, tableName, data, callback); +dv.asyncAddData(serviceName, tableName, data); ``` **Update data in table** ```javascript dv.updateData(serviceName, tableName, identifierField, identifierValue, data, callback); +dv.asyncUpdateData(serviceName, tableName, identifierField, identifierValue, data); ``` **Delete data from table** ```javascript dv.deleteData(serviceName, tableName, identifierField, identifierValue, callback); +dv.asyncDeleteData(serviceName, tableName, identifierField, identifierValue); ``` @@ -55,12 +59,14 @@ For *action*s including **signup** and **login**. ```javascript dv.authenticate(action, params, callback); +dv.asyncAuthenticate(action, params); ``` ### RPC ```javascript dv.rpc(serviceName, action, params, callback); +dv.asyncRPC(serviceName, action, params); ``` Note: This readme is a *WIP*. For more info on parameter definitions, etc, see the [DevLess Documentation](https://devless.gitbooks.io/devless-docs-1-3-0/http_api.html). diff --git a/devless.js b/devless.js index 65a8710..b1d1425 100644 --- a/devless.js +++ b/devless.js @@ -1,6 +1,7 @@ "use strict"; const axios = require("axios"); +const promisify = require('./helper') function Devless(url, token) { //CRUD @@ -28,6 +29,8 @@ function Devless(url, token) { }); }; + this.asyncAddData = promisify(this.addData) + //Query data from service table this.queryData = function (serviceName, tableName, params, callback) { let queryParams = ""; @@ -50,6 +53,8 @@ function Devless(url, token) { }); }; + this.asyncQueryData = promisify(this.queryData) + //Update data in service table this.updateData = function (serviceName, tableName, identifierField, identifierValue, data, callback) { let config = { @@ -78,6 +83,8 @@ function Devless(url, token) { }); }; + this.asyncUpdateData = promisify(this.updateData) + //Delete data in service table this.deleteData = function (serviceName, tableName, identifierField, identifierValue, callback) { axios({ @@ -103,6 +110,7 @@ function Devless(url, token) { }); }; + this.asyncDeleteData = promisify(this.deleteData) //Authentication @@ -128,8 +136,9 @@ function Devless(url, token) { }); }; - //General RPC call + this.asyncAuthenticate = promisify(this.authenticate) + //General RPC call //RPC call this.rpc = function (serviceName, action, params, callback) { axios({ @@ -148,9 +157,11 @@ function Devless(url, token) { callback(response.data); }) .catch(function (error) { - console.log(error); + callback(error) }); }; + + this.asyncRPC = promisify(this.rpc) } module.exports = Devless; \ No newline at end of file diff --git a/helper.js b/helper.js new file mode 100644 index 0000000..9fe3533 --- /dev/null +++ b/helper.js @@ -0,0 +1,11 @@ +"use strict" + +function promisify(fn) { + return function () { + return new Promise((resolve, reject) => { + return fn(...Array.from(arguments), response => resolve(response)); + }); + }; +} + +module.exports = promisify; diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..f5964e8 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,43 @@ +{ + "name": "devless-sdk", + "version": "0.0.1-alpha.1", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "axios": { + "version": "0.18.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.18.1.tgz", + "integrity": "sha512-0BfJq4NSfQXd+SkFdrvFbG7addhYSBA2mQwISr46pD6E5iqkWg02RAs8vyTT/j0RTnoYmeXauBuSv1qKwR179g==", + "requires": { + "follow-redirects": "1.5.10", + "is-buffer": "^2.0.2" + } + }, + "debug": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", + "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", + "requires": { + "ms": "2.0.0" + } + }, + "follow-redirects": { + "version": "1.5.10", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz", + "integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==", + "requires": { + "debug": "=3.1.0" + } + }, + "is-buffer": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.3.tgz", + "integrity": "sha512-U15Q7MXTuZlrbymiz95PJpZxu8IlipAp4dtS3wOdgPXx3mqBnslrWU14kxfHB+Py/+2PVKSr37dMAgM2A4uArw==" + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + } + } +}