| 3120 | } |
| 3121 | |
| 3122 | function resolveOrderKey( |
| 3123 | order: OrderItem, |
| 3124 | aliasMap: Map<string, AliasInfo>, |
| 3125 | useAliasDirectly: boolean, |
| 3126 | ): string | undefined { |
| 3127 | if (order.alias) { |
| 3128 | if (useAliasDirectly) { |
| 3129 | // WITH ORDER BY: use alias directly since path has it bound after projection |
| 3130 | return order.alias; |
| 3131 | } |
| 3132 | |
| 3133 | // RETURN ORDER BY: look up source property/variable |
| 3134 | const aliasInfo = aliasMap.get(order.alias); |
| 3135 | if (aliasInfo?.property) { |
| 3136 | return aliasInfo.property; |
| 3137 | } |
| 3138 | if (aliasInfo) { |
| 3139 | return aliasInfo.variable; |
| 3140 | } |
| 3141 | return order.alias; |
| 3142 | } |
| 3143 | |
| 3144 | // ORDER BY variable.property - use property as key |
| 3145 | return order.property; |
| 3146 | } |
| 3147 | |
| 3148 | function resolveReturnOrderExpression( |
| 3149 | expression: Exclude<OrderItem["expression"], undefined>, |