( whereClause: BasicExpression<boolean>, collectionAlias: string, )
| 19 | * // Output: ref with path ['id'] |
| 20 | */ |
| 21 | export function normalizeExpressionPaths( |
| 22 | whereClause: BasicExpression<boolean>, |
| 23 | collectionAlias: string, |
| 24 | ): BasicExpression<boolean> { |
| 25 | const tpe = whereClause.type |
| 26 | if (tpe === `val`) { |
| 27 | return new Value(whereClause.value) |
| 28 | } else if (tpe === `ref`) { |
| 29 | const path = whereClause.path |
| 30 | if (Array.isArray(path)) { |
| 31 | if (path[0] === collectionAlias && path.length > 1) { |
| 32 | // Remove the table alias from the path for single-collection queries |
| 33 | return new PropRef(path.slice(1)) |
| 34 | } else if (path.length === 1 && path[0] !== undefined) { |
| 35 | // Single field reference |
| 36 | return new PropRef([path[0]]) |
| 37 | } |
| 38 | } |
| 39 | // Fallback for non-array paths |
| 40 | return new PropRef(Array.isArray(path) ? path : [String(path)]) |
| 41 | } else { |
| 42 | // Recursively convert all arguments |
| 43 | const args: Array<BasicExpression> = [] |
| 44 | for (const arg of whereClause.args) { |
| 45 | const convertedArg = normalizeExpressionPaths( |
| 46 | arg as BasicExpression<boolean>, |
| 47 | collectionAlias, |
| 48 | ) |
| 49 | args.push(convertedArg) |
| 50 | } |
| 51 | return new Func(whereClause.name, args) |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | export function normalizeOrderByPaths( |
| 56 | orderBy: OrderBy, |
no outgoing calls
no test coverage detected