
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
@coyotte508/mongo-query
Advanced tools
Typescript utilities to manipulate the MongoDB query language.
Get it with npm add @coyotte508/mongo-query.
function simplifyFilter<T>(filter: Filter<T>): Filter<T>;
The result of parseFilter can be verbose, with many logical groupings. simplifyFilter aims to simplify the filter so it becomes less verbose.
For example, simplifyFilter({$and: [{}, {x: 1}, {y: 2}]} becomes:
{x: 1, y: 2}
function inverseFilter<T>(filter: Filter<T>): Filter<T>;
This inverts a filter. For example, inverseFilter({a: {$in: [1, 2]}}) will become {a: {$nin: [1, 2]}}.
It tries to stay simple but not every inversion is implemented. In which case, $not is used.
/**
* @param filter Human-readable boolean filter, eg !(A&&(!B)&&(C||D))
* @param replace A map or replacement function to replace keys by mongodb filters
* @returns A mongodb filter
*/
function parseFilter(filter: string): SearchGroupJson<string>;
function parseFilter<T>(filter: string, replace: Map<string, Filter<T>> | ((key: string) => Filter<T>)): Filter<T>;
This converts a human-readable boolean filter into a MongoDB filter.
filter can make use of the following operators: ! (NOT), || (OR) and && (AND), and parenthesis.
replace is a map or function used to replace A, B, ... by real mongodb expressions.
For example, it can be:
function replace(expr: `${key}:${val}`) {
const [key, val] = expr.split(":");
return { key: { $in: val.split(",") } };
}
or:
replace = new Map([
["A", {user: 'somebody'}],
["B", {createdAt: {$lt: 'somedate'}}],
["C", someOtherCondition],
...
])
The return value is a mongodb filter, with a combination of $and, $or and $nor.
For example, parseFilter("!(A&&(!B)&&(C||D))") will return:
{"$and":[{"$nor":[{"$and":["A",{"$and":[{"$nor":["B"]}]},{"$or":["C","D"]}]}]}]}
The output is verbose, so use it in conjunction with simplifyFilter.
An internal representation of the boolean combination of filters. It is used by parseFilter, which is just a wrapper around new SearchGroup(string).toJSON().
Similar to an AST, it can be manipulated and transformed, or analyzed.
FAQs
Utils to manipulate MongoDB's query language
The npm package @coyotte508/mongo-query receives a total of 50 weekly downloads. As such, @coyotte508/mongo-query popularity was classified as not popular.
We found that @coyotte508/mongo-query demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.

Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.

Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.