nodee-model
Advanced tools
Comparing version 0.9.12 to 0.9.13
@@ -27,2 +27,3 @@ 'use strict'; | ||
connection:{ | ||
debugRequest: false, // debug requests, only for dev | ||
baseUrl:'http://localhost:9200', | ||
@@ -143,3 +144,3 @@ index: '', // elasticsearch index | ||
ElasticSearch.buildQuery = function(defaults, reqData) { | ||
var elasticQuery = {}, filter = {}; | ||
var elasticQuery = {}, filter = {}, filterTerm, filterTerms; | ||
@@ -150,9 +151,18 @@ // defaults.query represents ElasticSearch filter by default, to ensure compatibility with "DataSource", e.g. optimisticLock queries, etc.. | ||
if(key[0] !== '$'){ | ||
filter.bool = filter.bool || {}; | ||
filter.bool.must = filter.bool.must || []; | ||
if(Array.isArray(defaults.query[key])){ | ||
filter.terms = filter.terms || {}; | ||
filter.terms[key] = defaults.query[key]; | ||
filterTerms = {}; | ||
filterTerms[key] = defaults.query[key]; | ||
filter.bool.must.push({ | ||
terms: filterTerms | ||
}); | ||
} | ||
else { | ||
filter.term = filter.term || {}; | ||
filter.term[key] = defaults.query[key]; | ||
filterTerm = {}; | ||
filterTerm[key] = defaults.query[key]; | ||
filter.bool.must.push({ | ||
term: filterTerm | ||
}); | ||
} | ||
@@ -246,2 +256,12 @@ } | ||
if(defaults.connection.debugRequest === true) { | ||
console.warn('\nRestDataSource request url: ' + url); | ||
console.warn('RestDataSource request method: ' + method); | ||
console.warn('RestDataSource request headers: ' + JSON.stringify(headers, null, 4)); | ||
console.warn('RestDataSource request query: ' + JSON.stringify(query, null, 4)); | ||
console.warn('RestDataSource request body: ' + JSON.stringify(body, null, 4)); | ||
} | ||
if(typeof defaults.connection.debugRequest === 'function') defaults.connection.debugRequest(req); | ||
return req; | ||
@@ -292,3 +312,9 @@ }; | ||
.end(function(err, res){ | ||
if(!res || (res.status!==200 && res.status!==400) || ((res.body||{}).error && (res.body||{}).error.indexOf('IndexAlreadyExistsException')===-1)){ | ||
var errorMsg = ((res.body||{}).error||{}).reason || (res.body||{}).error; | ||
if(!res || | ||
(res.status!==200 && res.status!==400) || | ||
(errorMsg.indexOf('IndexAlreadyExistsException')===-1 && | ||
errorMsg.indexOf('already exists')===-1)){ | ||
if(numOfFails >= maxNumOfFails) throw new Error((ModelCnst._name||'ElasticSearchDataSource')+': Cannot ensure ElasticSearch index "' +indexUrl+ '" ' +JSON.stringify((err||{}).message)+ ' ' + JSON.stringify(err || (res||{}).body || '')); | ||
@@ -295,0 +321,0 @@ else { |
@@ -91,3 +91,12 @@ 'use strict'; | ||
MongoClient.connect(mongoUrl, function(err, db){ | ||
if(err) callback(new Error('Model datasources mongoConnector: connection failed').cause(err)); | ||
if(err && err.code === 18 && mongoUrl.indexOf('&authSource=') === -1) { | ||
// auth failed, try to check admin database as authSource, if authSource is not defined in options | ||
MongoClient.connect(mongoUrl + '&authSource=admin', function(err, db){ | ||
if(err) callback(new Error('Model datasources mongoConnector: connection failed').cause(err)); | ||
else promise.fulfill(null, db); | ||
}); | ||
} | ||
else if(err) callback(new Error('Model datasources mongoConnector: connection failed').cause(err)); | ||
else promise.fulfill(null, db); | ||
@@ -94,0 +103,0 @@ }); |
@@ -26,2 +26,3 @@ 'use strict'; | ||
connection:{ | ||
debugRequest: false, // debug requests, only for dev | ||
baseUrl:'', // 'http://api.endpoint.com/products', | ||
@@ -208,2 +209,10 @@ | ||
if(defaults.connection.debugRequest === true) { | ||
console.warn('\nRestDataSource request url: ' + url); | ||
console.warn('RestDataSource request method: ' + method); | ||
console.warn('RestDataSource request headers: ' + JSON.stringify(headers, null, 4)); | ||
console.warn('RestDataSource request query: ' + JSON.stringify(query, null, 4)); | ||
console.warn('RestDataSource request body: ' + JSON.stringify(body, null, 4)); | ||
} | ||
var req = request(method, url) | ||
@@ -232,2 +241,4 @@ .timeout(defaults.connection.timeout) | ||
if(typeof defaults.connection.debugRequest === 'function') defaults.connection.debugRequest(req); | ||
return req; | ||
@@ -234,0 +245,0 @@ }); |
{ | ||
"name": "nodee-model", | ||
"preferGlobal": false, | ||
"version": "0.9.12", | ||
"version": "0.9.13", | ||
"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
240506
5105