pouchdb-selector-core
Advanced tools
Comparing version 7.3.1 to 8.0.0
@@ -271,11 +271,10 @@ import { clone } from 'pouchdb-utils'; | ||
var result = clone(input); | ||
var wasAnded = false; | ||
//#7458: if $and is present in selector (at any level) merge nested $and | ||
if (isAndInSelector(result, false)) { | ||
result = mergeAndedSelectorsNested(result); | ||
if ('$and' in result) { | ||
result = mergeAndedSelectors(result['$and']); | ||
} | ||
wasAnded = true; | ||
//#7458: if $and is present in selector (at any level) merge nested $and | ||
if (isAndInSelector(result, false)) { | ||
result = mergeAndedSelectorsNested(result); | ||
if ('$and' in result) { | ||
result = mergeAndedSelectors(result['$and']); | ||
} | ||
} | ||
@@ -313,11 +312,2 @@ ['$or', '$nor'].forEach(function (orOrNor) { | ||
matcher = {$eq: matcher}; | ||
} else if (!wasAnded) { | ||
// These values must be placed in an array because these operators can be used multiple times on the same field | ||
// when $and is used, mergeAndedSelectors takes care of putting them into arrays, otherwise it's done here: | ||
if ('$ne' in matcher) { | ||
matcher.$ne = [matcher.$ne]; | ||
} | ||
if ('$regex' in matcher) { | ||
matcher.$regex = [matcher.$regex]; | ||
} | ||
} | ||
@@ -327,5 +317,31 @@ result[field] = matcher; | ||
normalizeArrayOperators(result); | ||
return result; | ||
} | ||
// | ||
// The $ne and $regex values must be placed in an array because these operators can be used multiple times on the same field. | ||
// When $and is used, mergeAndedSelectors takes care of putting some of them into arrays, otherwise it's done here. | ||
// | ||
function normalizeArrayOperators(selector) { | ||
Object.keys(selector).forEach(function (field) { | ||
var matcher = selector[field]; | ||
if (Array.isArray(matcher)) { | ||
matcher.forEach(function (matcherItem) { | ||
if (matcherItem && typeof matcherItem === 'object') { | ||
normalizeArrayOperators(matcherItem); | ||
} | ||
}); | ||
} else if (field === '$ne') { | ||
selector.$ne = [matcher]; | ||
} else if (field === '$regex') { | ||
selector.$regex = [matcher]; | ||
} else if (matcher && typeof matcher === 'object') { | ||
normalizeArrayOperators(matcher); | ||
} | ||
}); | ||
} | ||
// create a comparator based on the sort object | ||
@@ -332,0 +348,0 @@ function createFieldSorter(sort) { |
@@ -275,11 +275,10 @@ 'use strict'; | ||
var result = pouchdbUtils.clone(input); | ||
var wasAnded = false; | ||
//#7458: if $and is present in selector (at any level) merge nested $and | ||
if (isAndInSelector(result, false)) { | ||
result = mergeAndedSelectorsNested(result); | ||
if ('$and' in result) { | ||
result = mergeAndedSelectors(result['$and']); | ||
} | ||
wasAnded = true; | ||
//#7458: if $and is present in selector (at any level) merge nested $and | ||
if (isAndInSelector(result, false)) { | ||
result = mergeAndedSelectorsNested(result); | ||
if ('$and' in result) { | ||
result = mergeAndedSelectors(result['$and']); | ||
} | ||
} | ||
@@ -317,11 +316,2 @@ ['$or', '$nor'].forEach(function (orOrNor) { | ||
matcher = {$eq: matcher}; | ||
} else if (!wasAnded) { | ||
// These values must be placed in an array because these operators can be used multiple times on the same field | ||
// when $and is used, mergeAndedSelectors takes care of putting them into arrays, otherwise it's done here: | ||
if ('$ne' in matcher) { | ||
matcher.$ne = [matcher.$ne]; | ||
} | ||
if ('$regex' in matcher) { | ||
matcher.$regex = [matcher.$regex]; | ||
} | ||
} | ||
@@ -331,5 +321,31 @@ result[field] = matcher; | ||
normalizeArrayOperators(result); | ||
return result; | ||
} | ||
// | ||
// The $ne and $regex values must be placed in an array because these operators can be used multiple times on the same field. | ||
// When $and is used, mergeAndedSelectors takes care of putting some of them into arrays, otherwise it's done here. | ||
// | ||
function normalizeArrayOperators(selector) { | ||
Object.keys(selector).forEach(function (field) { | ||
var matcher = selector[field]; | ||
if (Array.isArray(matcher)) { | ||
matcher.forEach(function (matcherItem) { | ||
if (matcherItem && typeof matcherItem === 'object') { | ||
normalizeArrayOperators(matcherItem); | ||
} | ||
}); | ||
} else if (field === '$ne') { | ||
selector.$ne = [matcher]; | ||
} else if (field === '$regex') { | ||
selector.$regex = [matcher]; | ||
} else if (matcher && typeof matcher === 'object') { | ||
normalizeArrayOperators(matcher); | ||
} | ||
}); | ||
} | ||
// create a comparator based on the sort object | ||
@@ -336,0 +352,0 @@ function createFieldSorter(sort) { |
{ | ||
"name": "pouchdb-selector-core", | ||
"version": "7.3.1", | ||
"version": "8.0.0", | ||
"description": "PouchDB's core selector code", | ||
@@ -16,4 +16,4 @@ "main": "./lib/index.js", | ||
"dependencies": { | ||
"pouchdb-collate": "7.3.1", | ||
"pouchdb-utils": "7.3.1" | ||
"pouchdb-collate": "8.0.0", | ||
"pouchdb-utils": "8.0.0" | ||
}, | ||
@@ -20,0 +20,0 @@ "module": "./lib/index.es.js", |
53922
1167
+ Addedpouchdb-binary-utils@8.0.0(transitive)
+ Addedpouchdb-collate@8.0.0(transitive)
+ Addedpouchdb-collections@8.0.0(transitive)
+ Addedpouchdb-errors@8.0.0(transitive)
+ Addedpouchdb-md5@8.0.0(transitive)
+ Addedpouchdb-utils@8.0.0(transitive)
- Removedargsarray@0.0.1(transitive)
- Removedinherits@2.0.4(transitive)
- Removedpouchdb-binary-utils@7.3.1(transitive)
- Removedpouchdb-collate@7.3.1(transitive)
- Removedpouchdb-collections@7.3.1(transitive)
- Removedpouchdb-errors@7.3.1(transitive)
- Removedpouchdb-md5@7.3.1(transitive)
- Removedpouchdb-utils@7.3.1(transitive)
Updatedpouchdb-collate@8.0.0
Updatedpouchdb-utils@8.0.0