nodee-model
Advanced tools
Comparing version 0.8.10 to 0.9.0
@@ -46,3 +46,3 @@ 'use strict'; | ||
// don't listen to messages from other modules | ||
if(msg.module!=='enterprise-cache') return; | ||
if(msg.module!=='nodee-cache') return; | ||
@@ -60,3 +60,3 @@ if(msg.cmd === 'clear_cache_key') { | ||
if(!value) process.send({ | ||
module:'enterprise-cache', | ||
module:'nodee-cache', | ||
cmd: 'clear_cache_key', | ||
@@ -67,3 +67,3 @@ key:key, | ||
else process.send({ | ||
module:'enterprise-cache', | ||
module:'nodee-cache', | ||
cmd: 'update_cache_key', | ||
@@ -70,0 +70,0 @@ key:key, |
@@ -42,3 +42,3 @@ 'use strict'; | ||
cache:{ | ||
keyPrefix:'enterprise-model', | ||
keyPrefix:'nodee-model', | ||
createKey: createCacheKey | ||
@@ -45,0 +45,0 @@ //duration: 3000, // duration (undefined or zero means no expiration) |
@@ -90,3 +90,2 @@ 'use strict'; | ||
maxRetries: 3, // if connection fail, retry 3-times | ||
retryTimeout: 1000, // miliseconds between repeated requests | ||
hasCount: true, // if responses contains count | ||
@@ -99,3 +98,3 @@ autoPaging: true, // will auto request next page if query.limit not reached | ||
cache:{ | ||
keyPrefix:'enterprise-model-elasticsearch', | ||
keyPrefix:'nodee-model-elasticsearch', | ||
// createKey: createCacheKey - using createKey defined in DataSource | ||
@@ -102,0 +101,0 @@ // duration: 3000, // duration (undefined or zero means no expiration) |
@@ -58,3 +58,3 @@ 'use strict'; | ||
cache:{ | ||
keyPrefix:'enterprise-model-filesystem', | ||
keyPrefix:'nodee-model-filesystem', | ||
// createKey: createCacheKey - using createKey defined in DataSource | ||
@@ -61,0 +61,0 @@ // duration: 3000, // duration (undefined or zero means no expiration) |
@@ -50,3 +50,3 @@ 'use strict'; | ||
cache:{ | ||
keyPrefix:'enterprise-model-jsonfile', | ||
keyPrefix:'nodee-model-jsonfile', | ||
// createKey: createCacheKey - using createKey defined in DataSource | ||
@@ -53,0 +53,0 @@ // duration: 3000, // duration (undefined or zero means no expiration) |
@@ -40,3 +40,3 @@ 'use strict'; | ||
cache:{ | ||
keyPrefix:'enterprise-model-memory', | ||
keyPrefix:'nodee-model-memory', | ||
// createKey: createCacheKey - using createKey defined in DataSource | ||
@@ -43,0 +43,0 @@ // duration: 3000, // duration (undefined or zero means no expiration) |
@@ -52,3 +52,3 @@ 'use strict'; | ||
cache:{ | ||
keyPrefix:'enterprise-model-mongo', | ||
keyPrefix:'nodee-model-mongo', | ||
// createKey: createCacheKey - using createKey defined in DataSource | ||
@@ -55,0 +55,0 @@ // duration: 3000, // duration (undefined or zero means no expiration) |
@@ -56,4 +56,4 @@ 'use strict'; | ||
method:'POST', | ||
// TODO: implement multipart | ||
// multipart:{ data:{ name:'data[image][file]', isFile:true }, product_id:'product[id]' } - multipart not implemented | ||
// method:'UPLOAD', | ||
// files:['image'] - data properties as files, they can be specified in data also { image:{ path:'mypicture.png', name:'optional file name' } } | ||
}, | ||
@@ -80,3 +80,2 @@ update:{ url:'/{id}', method:'PUT' }, | ||
maxRetries: 3, // if connection fail, retry 3-times | ||
retryTimeout: 1000, // miliseconds between repeated requests | ||
hasCount: true, // if responses contains count | ||
@@ -89,3 +88,3 @@ autoPaging: true, // will auto request next page if query.limit not reached | ||
cache:{ | ||
keyPrefix:'enterprise-model-rest', | ||
keyPrefix:'nodee-model-rest', | ||
// createKey: createCacheKey - using createKey defined in DataSource | ||
@@ -199,4 +198,16 @@ // duration: 3000, // duration (undefined or zero means no expiration) | ||
var req = request(method, url).set(headers).query(query); | ||
if(body) req.send(body); | ||
if(body && ['POST-MULTIPART','UPLOAD'].indexOf(req.method) > -1) { | ||
var fileKeys = (defaults.connection[ defaults.connection.command ]||{}).files || []; | ||
for(var key in body){ | ||
if(key && body.hasOwnProperty(key)){ | ||
if(body[key] && (fileKeys.indexOf(key) > -1 || body[key].path)){ | ||
req.attach(key, body[key].path || body[key], body[key].name); | ||
} | ||
else req.field(key, JSON.stringify(body[key])); | ||
} | ||
} | ||
} | ||
else if(body) req.send(body); | ||
return req; | ||
@@ -289,2 +300,9 @@ }); | ||
// auth before request send | ||
Rest.addMethod('authRequest', function(ModelCnst, parseMode, defaults, reqData, done){ // done(err) | ||
// do something to authorize: oauth, cookie auth, etc... | ||
done(); | ||
}); | ||
// helper - repeat | ||
@@ -296,21 +314,16 @@ Rest.addMethod('execRequest', execRequest); // store reference for use by inherited models | ||
eReq(defaults); | ||
if(ModelCnst.authRequest) ModelCnst.authRequest(ModelCnst, parseMode, defaults, reqData, function(err){ | ||
if(err) done(new Error('RestDataSource: Authorization failed').cause(err)); | ||
else eReq(defaults); | ||
}); | ||
else eReq(defaults); | ||
function eReq(defaults, requestRepeats){ | ||
var request = ModelCnst.buildRequest(defaults, reqData); | ||
if(['POST-MULTIPART','UPLOAD'].indexOf(request.method) > -1) request.method = 'POST'; | ||
request | ||
.retry(maxRetries) | ||
.end(function(err, res){ | ||
if(err){ | ||
requestRepeats = requestRepeats || 1; | ||
requestRepeats++; | ||
// if not last try, try again | ||
if(requestRepeats <= maxRetries) setTimeout(function(){ | ||
eReq(defaults, requestRepeats); | ||
}, retryTimeout); // try again after 1,5 sec | ||
// this is last try, | ||
else done(new Error('RestDataSource: Max repeated requests reached').cause(err)); | ||
} | ||
else if(!res) done(new Error('RestDataSource: No response')); // connection error | ||
if(!res) done(new Error('RestDataSource: Request failed').cause(err)); | ||
else if(res.statusType === 5){ // server error | ||
@@ -317,0 +330,0 @@ done(res.error, ModelCnst.parseError(defaults, res.status, res.body)); |
{ | ||
"name": "nodee-model", | ||
"preferGlobal": false, | ||
"version": "0.8.10", | ||
"version": "0.9.0", | ||
"author": "NODEE - Matus Szabo <matus@nodee.io>", | ||
@@ -6,0 +6,0 @@ "description": "Advanced, database agnostic ODM", |
Sorry, the diff of this file is not supported yet
225268
4905