(
paths: readonly TraversalPath<any, any, any>[],
items: readonly WithItemConfig[],
context?: QueryContext,
)
| 6897 | } |
| 6898 | |
| 6899 | protected computeAggregates( |
| 6900 | paths: readonly TraversalPath<any, any, any>[], |
| 6901 | items: readonly WithItemConfig[], |
| 6902 | context?: QueryContext, |
| 6903 | ): { firstValue: any; bindings: [string, any][] } { |
| 6904 | const bindings: [string, any][] = []; |
| 6905 | let firstValue: any = null; |
| 6906 | let isFirst = true; |
| 6907 | |
| 6908 | for (const item of items) { |
| 6909 | let value: any; |
| 6910 | |
| 6911 | switch (item.type) { |
| 6912 | case "variable": { |
| 6913 | // For non-aggregate items in an aggregate context, use the first path's value |
| 6914 | const pathNode = paths[0]?.get(item.sourceVariable); |
| 6915 | value = pathNode?.value ?? null; |
| 6916 | break; |
| 6917 | } |
| 6918 | case "property": { |
| 6919 | const pathNode = paths[0]?.get(item.sourceVariable); |
| 6920 | value = pathNode?.property(item.property as never) ?? null; |
| 6921 | break; |
| 6922 | } |
| 6923 | case "aggregate": { |
| 6924 | value = this.computeSingleAggregate(paths, item); |
| 6925 | break; |
| 6926 | } |
| 6927 | case "functionCall": { |
| 6928 | // Evaluate function call using first path |
| 6929 | const firstPath = paths[0]; |
| 6930 | if (firstPath) { |
| 6931 | const resolvedArgs = item.args.map((arg) => |
| 6932 | resolveConditionValue(firstPath, arg, context), |
| 6933 | ); |
| 6934 | value = evaluateFunction(item.functionName, resolvedArgs, firstPath, item.distinct); |
| 6935 | } else { |
| 6936 | value = null; |
| 6937 | } |
| 6938 | break; |
| 6939 | } |
| 6940 | case "expression": { |
| 6941 | // Evaluate arbitrary expression using first path |
| 6942 | const firstPath = paths[0]; |
| 6943 | value = firstPath ? resolveConditionValue(firstPath, item.value, context) : null; |
| 6944 | break; |
| 6945 | } |
| 6946 | } |
| 6947 | |
| 6948 | if (isFirst) { |
| 6949 | firstValue = value; |
| 6950 | isFirst = false; |
| 6951 | } |
| 6952 | bindings.push([item.alias, value]); |
| 6953 | } |
| 6954 | |
| 6955 | return { firstValue, bindings }; |
| 6956 | } |
no test coverage detected