jurisv/nodejs.extdirect — pull request #17 by jorisa (2014-02-01 17:20:29+00:00)
Title: Add option for standard node callback convention (err, result)

This pull request is more to show my point, maybe you did not implement it this way for a reason.

I see that you have a way to intentionally send back exceptions:
```javascript
if(err){
callback(null, 'exception', err);
}else{
callback({
success: true,
data: rows,
total: rowsTotal[0].totals
});
}
```

But this is not really in line with the standard node callback(err, results) convention. Why not do:
```javascript
if(err){
callback(err);
}else{
callback(null, {
data: rows,
total: rowsTotal[0].totals
});
}
```

This way you might be able to pass the callback to a lot of standard functions directly.
And maybe even automatically set success:true if error is null?

To use this, do:
```javascript
var directCfg = {
namespace: "ExtRemote",
apiName: "REMOTING_API",
apiPath: "/directapi",
classPath: "/direct",
classPrefix: "DX",
relativeUrl: true,
appendRequestResponseObjects: true,
conventionalCallbackFormat: true,
autoSetSuccess: true
};

// Now you can do:
// [...]
read: function(params, callback, sessionID, request, response) {
models.Foo.findAll({raw: true}).complete(callback);
}
// Instead off
read: function(params, callback, sessionID, request, response) {
models.Foo.findAll({raw: true}).complete(function(err,results) {
callback(results);
});
}
// [...]
```