nodee-model
Advanced tools
Comparing version 0.9.10 to 0.9.11
@@ -28,2 +28,10 @@ 'use strict'; | ||
// auth, if no username, it will not be used | ||
auth:{ | ||
username:'', | ||
password:'' | ||
}, | ||
timeout: false, // by default there is no timeout, you can set it as number in ms | ||
// default headers for every request | ||
@@ -200,2 +208,6 @@ headers:{ 'Content-Type': 'application/json' }, | ||
var req = request(method, url).set(headers).query(query); | ||
if(defaults.connection.auth && defaults.connection.auth.username) { | ||
req.auth(defaults.connection.auth.username, defaults.connection.auth.password); | ||
} | ||
if(defaults.connection.timeout) req.timeout(defaults.connection.timeout); | ||
@@ -324,2 +336,3 @@ if(body && ['POST-MULTIPART','UPLOAD'].indexOf(req.method) > -1) { | ||
if(!res) done(new Error((ModelCnst._name||'RestDataSource')+': Request failed "' +request.url+ '"').cause(err)); | ||
else if(parseMode === 'raw') done(null, res); | ||
else if(res.statusType === 5){ // server error | ||
@@ -329,4 +342,4 @@ done(res.error, ModelCnst.parseError(defaults, res.status, res.body)); | ||
else if(res.status === 404){ // client error | ||
if(['single','one','resource'].indexOf(parseMode) !== -1) done(null, null, 0); | ||
else if(['multiple','list','resourceList','all'].indexOf(parseMode) !== -1) done(null, [], 0); | ||
if(['single','one','resource'].indexOf(parseMode) > -1) done(null, null, 0); | ||
else if(['multiple','list','resourceList','all'].indexOf(parseMode) > -1) done(null, [], 0); | ||
else done(null, null, 0); | ||
@@ -432,3 +445,3 @@ } | ||
*/ | ||
Rest.Collection.addMethod('exec', { cacheable:true, fetch:false }, function(command, args, cb){ // cb(err, count) | ||
Rest.Collection.addMethod('exec', { cacheable:true, fetch:false }, function(command, parseMode, reqQuery, reqData, cb){ // cb(err, count) | ||
var query = this, | ||
@@ -438,2 +451,24 @@ defaults = this._defaults, | ||
if(arguments.length === 4){ | ||
cb = arguments[3]; | ||
reqData = arguments[2]; | ||
reqQuery = arguments[1]; | ||
parseMode = null; | ||
} | ||
else if(arguments.length === 3){ | ||
cb = arguments[2]; | ||
reqData = arguments[1]; | ||
reqQuery = {}; | ||
parseMode = null; | ||
} | ||
else if(arguments.length === 2){ | ||
cb = arguments[1]; | ||
reqData = {}; | ||
reqQuery = {}; | ||
parseMode = null; | ||
} | ||
if(typeof cb !== 'function') throw new Error('Wrong arguments'); | ||
defaults.query = reqQuery; | ||
// set command, to use to build request | ||
@@ -443,3 +478,3 @@ defaults.connection.command = command; | ||
// exec request, but don't parse result | ||
execRequest(ModelCnst, null, defaults, args, function(err, resData, count){ | ||
execRequest(ModelCnst, parseMode, defaults, reqData, function(err, resData, count){ | ||
if(err && resData) cb(new Error((ModelCnst._name||'RestDataSource')+' exec: EXECFAIL').details({ code:'EXECFAIL', cause:err })); | ||
@@ -446,0 +481,0 @@ else if(err) cb(new Error((ModelCnst._name||'RestDataSource')+' exec: CONNFAIL').details({ code:'CONNFAIL', cause:err })); |
{ | ||
"name": "nodee-model", | ||
"preferGlobal": false, | ||
"version": "0.9.10", | ||
"version": "0.9.11", | ||
"author": "NODEE - Matus Szabo <matus@nodee.io>", | ||
@@ -6,0 +6,0 @@ "description": "Advanced, database agnostic ODM", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
237234
5045