| 155 | const aliasesById = new Map<string, Set<string>>() |
| 156 | |
| 157 | function recordAlias(source: any) { |
| 158 | if (!source) return |
| 159 | |
| 160 | if (source.type === `collectionRef`) { |
| 161 | const { id } = source.collection |
| 162 | const existing = aliasesById.get(id) |
| 163 | if (existing) { |
| 164 | existing.add(source.alias) |
| 165 | } else { |
| 166 | aliasesById.set(id, new Set([source.alias])) |
| 167 | } |
| 168 | } else if (source.type === `queryRef`) { |
| 169 | traverse(source.query) |
| 170 | } else if (source.type === `unionFrom`) { |
| 171 | for (const childSource of source.sources) { |
| 172 | recordAlias(childSource) |
| 173 | } |
| 174 | } else if (source.type === `unionAll`) { |
| 175 | for (const branch of source.queries) { |
| 176 | traverse(branch) |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | function traverseSelect(select: any) { |
| 182 | for (const [key, value] of Object.entries(select)) { |