mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 20:37:21 +00:00
feat: enhance query handling by ignoring undefined values
- Updated query conversion logic to skip undefined values, improving robustness. - Added tests to validate that undefined values are correctly ignored in query specifications.
This commit is contained in:
@@ -55,7 +55,7 @@ function getExpression<Exps extends Expressions>(
|
||||
}
|
||||
|
||||
type LiteralExpressionCondition<Exps extends Expressions> = {
|
||||
[key: string]: Primitive | ExpressionCondition<Exps>;
|
||||
[key: string]: undefined | Primitive | ExpressionCondition<Exps>;
|
||||
};
|
||||
|
||||
const OperandOr = "$or" as const;
|
||||
@@ -96,6 +96,11 @@ function _convert<Exps extends Expressions>(
|
||||
}
|
||||
|
||||
for (const [key, value] of Object.entries($query)) {
|
||||
// skip undefined values
|
||||
if (value === undefined) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// if $or, convert each value
|
||||
if (key === "$or") {
|
||||
invariant(isPlainObject(value), "$or must be an object");
|
||||
@@ -171,6 +176,8 @@ function _build<Exps extends Expressions>(
|
||||
|
||||
// check $and
|
||||
for (const [key, value] of Object.entries($and)) {
|
||||
if (value === undefined) continue;
|
||||
|
||||
for (const [$op, $v] of Object.entries(value)) {
|
||||
const objValue = options.value_is_kv ? key : getPath(options.object, key);
|
||||
result.$and.push(__validate($op, $v, objValue, [key]));
|
||||
|
||||
Reference in New Issue
Block a user