Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Low Priority] Fixed style + Added JSDoc for introduced sourceRecordsFilter helper functions #937

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions src/modules/components/common_components/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1860,23 +1860,43 @@ export class Common {
return new Promise(resolve => setTimeout(resolve, time));
}

/**
* Wraps the given `WhereClause` in parentheses - useful for merging.
*
* @param {WhereClause} clause - The `WhereClause` to be wrapped.
* @returns {{beginClause: WhereClause, endClause: WhereClause}} An object
* containing the `beginClause` (the wrapped version of the input
* `clause`) and the `endClause` (the last clause where the right
* side of the expression ends with a close parenthesis).
*/
private static wrapWhereClauseInParenthesis(clause: WhereClause): { beginClause: WhereClause, endClause: WhereClause } {
const clone = JSON.parse(JSON.stringify(clause)) as WhereClause;
clone.left.openParen = (clone.left.openParen ?? 0) + 1
clone.left.openParen = (clone.left.openParen ?? 0) + 1;
let current = clone;
while (current.right) {
current = current.right;
}
current.left.closeParen = (current.left.closeParen || 0) + 1
current.left.closeParen = (current.left.closeParen ?? 0) + 1;
return { beginClause: clone, endClause: current };
}

/**
* Merges two `WhereClause` objects into a single clause, joining them with
* a logical operator (defaults AND).
*
* @param {WhereClause} [where1] - First clause to merge
* @param {WhereClause} [where2] - Second clause to merge
* @param {LogicalOperator} [operator='AND'] - Operator for joing clauses
*
* @returns {WhereClause|undefined} A new `WhereClause` that represents the
* merged expression, or `undefined` if neither clauses were provided.
*/
static mergeWhereClauses(
where1?: WhereClause,
where2?: WhereClause,
operator: LogicalOperator = 'AND',
): WhereClause | undefined {
if (!where1 || !where2) return where1 || where2;
if (!where1 || !where2) return where1 ?? where2;

const { beginClause: wrappedWhere1, endClause: endClause1 } = Common.wrapWhereClauseInParenthesis(where1);
const { beginClause: wrappedWhere2 } = Common.wrapWhereClauseInParenthesis(where2);
Expand Down