Comparing version 4.1.0 to 4.1.1
@@ -63,3 +63,4 @@ 'use strict'; | ||
const lines = internals.flatten(this.criteria, []); | ||
const edges = []; | ||
const lines = internals.flatten(this.criteria, [], edges); | ||
if (!lines.length) { | ||
@@ -112,2 +113,12 @@ return; | ||
this.criteria = (tests.length === 1 ? tests[0] : RethinkDB.and(RethinkDB.args(tests))); | ||
if (edges.length) { | ||
let typeCheck = internals.row(edges[0]).typeOf().eq('OBJECT'); | ||
for (let i = 1; i < edges.length; ++i) { | ||
typeCheck = RethinkDB.and(typeCheck, internals.row(edges[i]).typeOf().eq('OBJECT')); | ||
} | ||
this.criteria = typeCheck.and(this.criteria); | ||
} | ||
} | ||
@@ -117,3 +128,3 @@ }; | ||
internals.flatten = function (criteria, path) { | ||
internals.flatten = function (criteria, path, edges) { | ||
@@ -128,3 +139,4 @@ const keys = Object.keys(criteria); | ||
if (typeof value === 'object') { | ||
lines = lines.concat(internals.flatten(value, location)); | ||
edges.push(location); | ||
lines = lines.concat(internals.flatten(value, location, edges)); | ||
} | ||
@@ -131,0 +143,0 @@ else { |
{ | ||
"name": "penseur", | ||
"description": "Lightweight RethinkDB wrapper", | ||
"version": "4.1.0", | ||
"version": "4.1.1", | ||
"author": "Eran Hammer <eran@hammer.io> (http://hueniverse.com)", | ||
@@ -6,0 +6,0 @@ "repository": "git://github.com/hueniverse/penseur", |
@@ -388,2 +388,46 @@ 'use strict'; | ||
}); | ||
it('handles query into nested object where item is not an object', (done) => { | ||
const db = new Penseur.Db('penseurtest'); | ||
db.establish(['test'], (err) => { | ||
expect(err).to.not.exist(); | ||
db.test.insert([{ id: 1, a: 1, b: false }, { id: 2, a: 2, b: { c: 1 } }, { id: 3, a: 1, b: { c: 1 } }], (err, keys) => { | ||
expect(err).to.not.exist(); | ||
db.test.query({ a: 1, b: { c: 1 } }, (err, result) => { | ||
expect(err).to.not.exist(); | ||
expect(result).to.deep.equal([{ id: 3, a: 1, b: { c: 1 } }]); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
it('handles query into double nested object where item is not an object', (done) => { | ||
const db = new Penseur.Db('penseurtest'); | ||
db.establish(['test'], (err) => { | ||
expect(err).to.not.exist(); | ||
db.test.insert([ | ||
{ id: 1, a: 1, b: false }, | ||
{ id: 2, a: 2, b: { c: { d: 4 } } }, | ||
{ id: 3, a: 1, b: { c: 1 } } | ||
], (err, keys) => { | ||
expect(err).to.not.exist(); | ||
db.test.query({ b: { c: { d: 4 } } }, (err, result) => { | ||
expect(err).to.not.exist(); | ||
expect(result).to.deep.equal([{ id: 2, a: 2, b: { c: { d: 4 } } }]); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
@@ -390,0 +434,0 @@ |
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
100402
2371