From 731cf5b00afdaafd075dfe3225ba12ba2ed839eb Mon Sep 17 00:00:00 2001 From: Khiet Tam Nguyen Date: Thu, 28 Nov 2024 22:35:19 +1100 Subject: [PATCH 1/2] style: semi-colons and consistent null coalescing operator usage --- src/modules/components/common_components/common.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/components/common_components/common.ts b/src/modules/components/common_components/common.ts index 92b20dbd..e73643aa 100644 --- a/src/modules/components/common_components/common.ts +++ b/src/modules/components/common_components/common.ts @@ -1862,12 +1862,12 @@ export class Common { 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 }; } @@ -1876,7 +1876,7 @@ export class Common { 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); From 184569373c0556f23df0a2c29184f13c22f4b323 Mon Sep 17 00:00:00 2001 From: Khiet Tam Nguyen Date: Thu, 28 Nov 2024 22:36:25 +1100 Subject: [PATCH 2/2] docs: jsdoc added for wrapWhereClauseInParenthesis and mergeWhereClauses --- .../components/common_components/common.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/modules/components/common_components/common.ts b/src/modules/components/common_components/common.ts index e73643aa..4216eb57 100644 --- a/src/modules/components/common_components/common.ts +++ b/src/modules/components/common_components/common.ts @@ -1860,6 +1860,15 @@ 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; @@ -1871,6 +1880,17 @@ export class Common { 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,