( obj: Select, )
| 871 | } |
| 872 | |
| 873 | function compileGroupedSelectObject( |
| 874 | obj: Select, |
| 875 | ): (row: NamespacedRow) => Record<string, any> { |
| 876 | const entries = Object.entries(obj).map(([key, value]) => { |
| 877 | if (key.startsWith(`__SPREAD_SENTINEL__`)) { |
| 878 | const rest = key.slice(`__SPREAD_SENTINEL__`.length) |
| 879 | const splitIndex = rest.lastIndexOf(`__`) |
| 880 | const pathStr = splitIndex >= 0 ? rest.slice(0, splitIndex) : rest |
| 881 | const isRefExpr = |
| 882 | typeof value === `object` && `type` in value && value.type === `ref` |
| 883 | const expression = isRefExpr |
| 884 | ? (value as BasicExpression) |
| 885 | : (new PropRef(pathStr.split(`.`)) as BasicExpression) |
| 886 | |
| 887 | return { |
| 888 | key, |
| 889 | spread: true, |
| 890 | value: compileExpression(expression), |
| 891 | } |
| 892 | } |
| 893 | |
| 894 | return { |
| 895 | key, |
| 896 | spread: false, |
| 897 | value: compileGroupedSelectValue(value as SelectValueExpression), |
| 898 | } |
| 899 | }) |
| 900 | |
| 901 | return (row) => { |
| 902 | const result: Record<string, any> = {} |
| 903 | for (const entry of entries) { |
| 904 | const value = entry.value(row) |
| 905 | if (entry.spread) { |
| 906 | if (value && typeof value === `object`) { |
| 907 | Object.assign(result, value) |
| 908 | } |
| 909 | } else { |
| 910 | result[entry.key] = value |
| 911 | } |
| 912 | } |
| 913 | return result |
| 914 | } |
| 915 | } |
| 916 | |
| 917 | function compileGroupedConditionalSelect( |
| 918 | conditional: ConditionalSelect, |
no test coverage detected