Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mongodb-query-util

Package Overview
Dependencies
Maintainers
0
Versions
305
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongodb-query-util - npm Package Compare versions

Comparing version 0.0.0-next-7e3e53be10eb2396c2c3f47d0f4bb8b7175d7c31 to 0.0.0-next-80f6ac0b3460eec09e5e7aa7f17b44a732ed5730

1

dist/bson-equal.js

@@ -19,2 +19,3 @@ "use strict";

}
// for all others, use native comparisons
return undefined;

@@ -21,0 +22,0 @@ };

@@ -0,2 +1,8 @@

/**
* returns an array of all distinct values in a field (equality or $in)
*
* @param {Any} field the right-hand side of a document field
* @return {Boolean} array of values for this field
*/
export declare const getDistinctValues: (field?: any) => any;
//# sourceMappingURL=get-distinct-values.d.ts.map

@@ -5,6 +5,14 @@ "use strict";

const lodash_1 = require("lodash");
/**
* returns an array of all distinct values in a field (equality or $in)
*
* @param {Any} field the right-hand side of a document field
* @return {Boolean} array of values for this field
*/
const getDistinctValues = (field) => {
// field not present, return empty array
if (field === undefined) {
return [];
}
// field is object, could be a $in clause or a primitive value
if ((0, lodash_1.isPlainObject)(field)) {

@@ -15,2 +23,3 @@ if ((0, lodash_1.has)(field, '$in')) {

}
// it is not a $in operator, return single value as array
return [field];

@@ -17,0 +26,0 @@ };

@@ -0,1 +1,8 @@

/**
* Determines if a field in the query has a distinct value (equality or $in).
*
* @param {Any} field the right-hand side of a document field
* @param {Any} value the value to check
* @return {Boolean} whether or not value is included in field
*/
export declare const hasDistinctValue: (field: {

@@ -2,0 +9,0 @@ $in: any;

@@ -6,8 +6,18 @@ "use strict";

const bson_equal_1 = require("./bson-equal");
/**
* Determines if a field in the query has a distinct value (equality or $in).
*
* @param {Any} field the right-hand side of a document field
* @param {Any} value the value to check
* @return {Boolean} whether or not value is included in field
*/
const hasDistinctValue = (field, value) => {
// field not present, add primitive value
if (field === undefined) {
return false;
}
// field is object, could be a $in clause or a primitive value
if ((0, lodash_1.isPlainObject)(field)) {
if ((0, lodash_1.has)(field, '$in')) {
// check if $in array contains the value
const inArray = field.$in;

@@ -19,2 +29,3 @@ return (0, lodash_1.some)(inArray, (other) => {

}
// it is not a $in operator, check value directly
return (0, lodash_1.isEqualWith)(field, value, bson_equal_1.bsonEqual);

@@ -21,0 +32,0 @@ };

@@ -0,1 +1,23 @@

/**
* returns whether a value is fully or partially covered by a range,
* specified with $gt(e)/$lt(e). Ranges can be open ended on either side,
* and can also be single equality queries, e.g. {"field": 16}.
*
* @examples
* inValueRange(15, {value: 15, dx: 0}) => 'yes'
* inValueRange({$gte: 15, $lt: 30}, {value: 20, dx: 5}) => 'yes'
* inValueRange({$gte: 15, $lt: 30}, {value: 15, dx: 5}) => 'yes'
* inValueRange(15, {value: 15, dx: 1}) => 'partial'
* inValueRange({$gt: 15, $lt: 30}, {value: 15, dx: 5}) => 'partial'
* inValueRange({$gte: 15, $lt: 30}, {value: 20, dx: 20}) => 'partial'
* inValueRange({$gte: 15, $lt: 30}, {value: 10, dx: 10}) => 'partial'
* inValueRange({$gte: 15, $lt: 30}, {value: 10, dx: 5}) => 'partial'
* inValueRange({$gt: 15, $lt: 30}, {value: 10, dx: 5}) => 'no'
* inValueRange({$gte: 15, $lt: 30}, {value: 10, dx: 4}) => 'no'
*
* @param {Object|number} field the field value (range or number)
* @param {Object} d object with a `value` and `dx` field if
* the value represents a binned range itself
* @return {String} 'yes', 'partial', 'no'
*/
export declare const inValueRange: (field: any, d: {

@@ -2,0 +24,0 @@ value: any;

@@ -6,2 +6,24 @@ "use strict";

const bson_equal_1 = require("./bson-equal");
/**
* returns whether a value is fully or partially covered by a range,
* specified with $gt(e)/$lt(e). Ranges can be open ended on either side,
* and can also be single equality queries, e.g. {"field": 16}.
*
* @examples
* inValueRange(15, {value: 15, dx: 0}) => 'yes'
* inValueRange({$gte: 15, $lt: 30}, {value: 20, dx: 5}) => 'yes'
* inValueRange({$gte: 15, $lt: 30}, {value: 15, dx: 5}) => 'yes'
* inValueRange(15, {value: 15, dx: 1}) => 'partial'
* inValueRange({$gt: 15, $lt: 30}, {value: 15, dx: 5}) => 'partial'
* inValueRange({$gte: 15, $lt: 30}, {value: 20, dx: 20}) => 'partial'
* inValueRange({$gte: 15, $lt: 30}, {value: 10, dx: 10}) => 'partial'
* inValueRange({$gte: 15, $lt: 30}, {value: 10, dx: 5}) => 'partial'
* inValueRange({$gt: 15, $lt: 30}, {value: 10, dx: 5}) => 'no'
* inValueRange({$gte: 15, $lt: 30}, {value: 10, dx: 4}) => 'no'
*
* @param {Object|number} field the field value (range or number)
* @param {Object} d object with a `value` and `dx` field if
* the value represents a binned range itself
* @return {String} 'yes', 'partial', 'no'
*/
const inValueRange = (field, d) => {

@@ -31,2 +53,3 @@ const compOperators = {

if (!(0, lodash_1.isPlainObject)(field)) {
// add an equality condition
conditions.push(function (a) {

@@ -41,2 +64,3 @@ return (0, lodash_1.isEqualWith)(a, field, bson_equal_1.bsonEqual);

if (comparator) {
// add comparison condition(s), right-curried with the value of the query
conditions.push((0, lodash_1.curryRight)(comparator)(value));

@@ -48,4 +72,32 @@ edgeCase.push(value);

const dx = (0, lodash_1.get)(d, 'dx', null);
// extract bound(s): if a dx value is set, create a 2-element array of
// upper and lower bound. otherwise create a single value array of the
// original bson type (if available) or the extracted value.
// NOTE: this package is a copy of https://github.com/mongodb-js/mongodb-query-util/tree/main.
// Once we converted the code to typescript, eslint started to complain about the fact
// that the sum is not happening always between numbers.
// From tests, it seems expected for d.value to also be a BSON type, and the sum
// here may not make sense.
// Potentially there could be bugs deriving from it, but tests are passing and
// is not easy to tell what is the original intent here, so we suppress the eslint warning.
//
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
const bounds = dx ? (0, lodash_1.uniq)([d.value, d.value + dx]) : [d.bson || d.value];
/*
* Logic to determine if the query covers the value (or value range)
*
* if all bounds pass all conditions, the value is fully covered in the range (yes)
* if one of two bounds passes all conditions, the value is partially covered (partial)
* if none of the bounds pass all conditions, the value is not covered (no)
*
* Since the upper bound of a bar represents the exclusive bound
* (i.e. lower <= x < upper) we need to use a little hack to adjust for
* the math. This means that if someone adjusts the query bound manually by
* less than 1 millionth of the value, one of the bars may appear half
* selected instead of not/fully selected. The error is purely visual.
*/
const results = (0, lodash_1.map)(bounds, function (bound, i) {
// adjust the upper bound slightly as it represents an exclusive bound
// getting this perfectly right would require a lot more code to check for
// all 4 edge cases.
if (i > 0) {

@@ -64,2 +116,3 @@ bound -= 0.00001 * Math.abs(bound) + 0.00001;

}
// check for edge case where range wraps around query on both ends
if ((0, lodash_1.every)(edgeCase, function (val) {

@@ -66,0 +119,0 @@ return val > bounds[0] && val < bounds[bounds.length - 1];

12

package.json

@@ -16,3 +16,3 @@ {

"homepage": "https://github.com/mongodb-js/compass",
"version": "0.0.0-next-7e3e53be10eb2396c2c3f47d0f4bb8b7175d7c31",
"version": "0.0.0-next-80f6ac0b3460eec09e5e7aa7f17b44a732ed5730",
"repository": {

@@ -54,6 +54,6 @@ "type": "git",

"devDependencies": {
"@mongodb-js/eslint-config-compass": "0.0.0-next-7e3e53be10eb2396c2c3f47d0f4bb8b7175d7c31",
"@mongodb-js/mocha-config-compass": "0.0.0-next-7e3e53be10eb2396c2c3f47d0f4bb8b7175d7c31",
"@mongodb-js/prettier-config-compass": "0.0.0-next-7e3e53be10eb2396c2c3f47d0f4bb8b7175d7c31",
"@mongodb-js/tsconfig-compass": "0.0.0-next-7e3e53be10eb2396c2c3f47d0f4bb8b7175d7c31",
"@mongodb-js/eslint-config-compass": "0.0.0-next-80f6ac0b3460eec09e5e7aa7f17b44a732ed5730",
"@mongodb-js/mocha-config-compass": "0.0.0-next-80f6ac0b3460eec09e5e7aa7f17b44a732ed5730",
"@mongodb-js/prettier-config-compass": "0.0.0-next-80f6ac0b3460eec09e5e7aa7f17b44a732ed5730",
"@mongodb-js/tsconfig-compass": "0.0.0-next-80f6ac0b3460eec09e5e7aa7f17b44a732ed5730",
"@types/chai": "^4.2.21",

@@ -76,3 +76,3 @@ "@types/mocha": "^9.0.0",

},
"gitHead": "7e3e53be10eb2396c2c3f47d0f4bb8b7175d7c31"
"gitHead": "80f6ac0b3460eec09e5e7aa7f17b44a732ed5730"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc