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

Add support for promises #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
```


Expand All @@ -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).
15 changes: 13 additions & 2 deletions devless.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use strict";

const axios = require("axios");
const promisify = require('./helper')

function Devless(url, token) {
//CRUD
Expand Down Expand Up @@ -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 = "";
Expand All @@ -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 = {
Expand Down Expand Up @@ -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({
Expand All @@ -103,6 +110,7 @@ function Devless(url, token) {
});
};

this.asyncDeleteData = promisify(this.deleteData)

//Authentication

Expand All @@ -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({
Expand All @@ -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;
11 changes: 11 additions & 0 deletions helper.js
Original file line number Diff line number Diff line change
@@ -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;
43 changes: 43 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.