( obj: any, parentAliases: Array<string> = [], fieldName?: string, )
| 974 | } |
| 975 | |
| 976 | function buildNestedSelect( |
| 977 | obj: any, |
| 978 | parentAliases: Array<string> = [], |
| 979 | fieldName?: string, |
| 980 | ): any { |
| 981 | if (obj instanceof BaseQueryBuilder) { |
| 982 | if (!fieldName) { |
| 983 | throw new Error(`Conditional include branch is missing a field name`) |
| 984 | } |
| 985 | return buildIncludesSubquery(obj, fieldName, parentAliases, `collection`) |
| 986 | } |
| 987 | if (obj instanceof ToArrayWrapper) { |
| 988 | if (!(obj.query instanceof BaseQueryBuilder)) { |
| 989 | throw new Error(`toArray() must wrap a subquery builder`) |
| 990 | } |
| 991 | if (!fieldName) { |
| 992 | throw new Error(`Conditional toArray() branch is missing a field name`) |
| 993 | } |
| 994 | return buildIncludesSubquery(obj.query, fieldName, parentAliases, `array`) |
| 995 | } |
| 996 | if (obj instanceof ConcatToArrayWrapper) { |
| 997 | if (!(obj.query instanceof BaseQueryBuilder)) { |
| 998 | throw new Error(`concat(toArray(...)) must wrap a subquery builder`) |
| 999 | } |
| 1000 | if (!fieldName) { |
| 1001 | throw new Error( |
| 1002 | `Conditional concat(toArray(...)) branch is missing a field name`, |
| 1003 | ) |
| 1004 | } |
| 1005 | return buildIncludesSubquery(obj.query, fieldName, parentAliases, `concat`) |
| 1006 | } |
| 1007 | if (obj instanceof CaseWhenWrapper) { |
| 1008 | return buildConditionalSelect(obj, parentAliases, fieldName) |
| 1009 | } |
| 1010 | if (!isPlainObject(obj)) return toExpr(obj) |
| 1011 | const out: Record<string, any> = {} |
| 1012 | for (const [k, v] of Object.entries(obj)) { |
| 1013 | if (typeof k === `string` && k.startsWith(`__SPREAD_SENTINEL__`)) { |
| 1014 | // Preserve sentinel key and its value (value is unimportant at compile time) |
| 1015 | out[k] = v |
| 1016 | continue |
| 1017 | } |
| 1018 | if (v instanceof BaseQueryBuilder) { |
| 1019 | out[k] = buildIncludesSubquery(v, k, parentAliases, `collection`) |
| 1020 | continue |
| 1021 | } |
| 1022 | if (v instanceof ToArrayWrapper) { |
| 1023 | if (!(v.query instanceof BaseQueryBuilder)) { |
| 1024 | throw new Error(`toArray() must wrap a subquery builder`) |
| 1025 | } |
| 1026 | out[k] = buildIncludesSubquery(v.query, k, parentAliases, `array`) |
| 1027 | continue |
| 1028 | } |
| 1029 | if (v instanceof ConcatToArrayWrapper) { |
| 1030 | if (!(v.query instanceof BaseQueryBuilder)) { |
| 1031 | throw new Error(`concat(toArray(...)) must wrap a subquery builder`) |
| 1032 | } |
| 1033 | out[k] = buildIncludesSubquery(v.query, k, parentAliases, `concat`) |
no test coverage detected
searching dependent graphs…