Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Push all the complex stages onto the pipeline as-is
while (!itr.done && itr.value.$isComplexStage) {
pipeline.push(...itr.value.pipeline);
if (itr.value.mutator) {
postAggregateMutation.push(itr.value.mutator);
}
itr = iterator.next();
}
}
if (args.search) {
// TODO: Implement configurable search fields for lists
pipeline.push({
$match: {
name: new RegExp(`${escapeRegExp(args.search)}`, 'i'),
},
});
}
if (args.orderBy) {
const [orderField, orderDirection] = args.orderBy.split('_');
pipeline.push({
$sort: {
[orderField]: orderDirection === 'ASC' ? 1 : -1,
},
});
}
if (args.skip < Infinity && args.skip > 0) {
pipeline.push({
$search: value => {
if (!value || (getType(value) === 'String' && !value.trim())) {
return undefined;
}
return {
$match: {
name: new RegExp(`${escapeRegExp(value)}`, 'i'),
},
};
},
[`${this.path}_contains`]: value => ({
[dbPath]: { $regex: new RegExp(escapeRegExp(f(value))) },
}),
[`${this.path}_not_contains`]: value => ({
[`${this.path}_i`]: value => ({ [dbPath]: new RegExp(`^${escapeRegExp(f(value))}$`, 'i') }),
[`${this.path}_not_i`]: value => ({
if (not in args) {
if (caseSensitive) {
conditions.push({ $ne: args[not] });
} else {
const not_rx = new RegExp(`^${esc(args[not])}$`, rx_cs);
conditions.push({ $not: not_rx });
}
}
const contains = `${this.path}_contains`;
if (contains in args) {
const contains_rx = new RegExp(esc(args[contains]), rx_cs);
conditions.push({ $regex: contains_rx });
}
const not_contains = `${this.path}_not_contains`;
if (not_contains in args) {
const not_contains_rx = new RegExp(esc(args[not_contains]), rx_cs);
conditions.push({ $not: not_contains_rx });
}
const starts_with = `${this.path}_starts_with`;
if (starts_with in args) {
const starts_with_rx = new RegExp(`^${esc(args[starts_with])}`, rx_cs);
conditions.push({ $regex: starts_with_rx });
}
const not_starts_with = `${this.path}_not_starts_with`;
if (not_starts_with in args) {
const not_starts_with_rx = new RegExp(
`^${esc(args[not_starts_with])}`,
rx_cs
);
conditions.push({ $not: not_starts_with_rx });
}
const ends_with = `${this.path}_ends_with`;
const rx_cs = caseSensitive ? '' : 'i';
const eq = this.path;
if (eq in args) {
if (caseSensitive) {
conditions.push({ $eq: args[eq] });
} else {
const eq_rx = new RegExp(`^${esc(args[eq])}$`, rx_cs);
conditions.push({ $regex: eq_rx });
}
}
const not = `${this.path}_not`;
if (not in args) {
if (caseSensitive) {
conditions.push({ $ne: args[not] });
} else {
const not_rx = new RegExp(`^${esc(args[not])}$`, rx_cs);
conditions.push({ $not: not_rx });
}
}
const contains = `${this.path}_contains`;
if (contains in args) {
const contains_rx = new RegExp(esc(args[contains]), rx_cs);
conditions.push({ $regex: contains_rx });
}
const not_contains = `${this.path}_not_contains`;
if (not_contains in args) {
const not_contains_rx = new RegExp(esc(args[not_contains]), rx_cs);
conditions.push({ $not: not_contains_rx });
}
const starts_with = `${this.path}_starts_with`;
if (starts_with in args) {
const starts_with_rx = new RegExp(`^${esc(args[starts_with])}`, rx_cs);