* Helper function to process select objects and build operations array
( prefixPath: Array<string>, obj: any, ops: Array<SelectOp>, )
| 293 | * Helper function to process select objects and build operations array |
| 294 | */ |
| 295 | function addFromObject( |
| 296 | prefixPath: Array<string>, |
| 297 | obj: any, |
| 298 | ops: Array<SelectOp>, |
| 299 | ) { |
| 300 | for (const [key, value] of Object.entries(obj)) { |
| 301 | if (!key.startsWith(`__SPREAD_SENTINEL__`)) { |
| 302 | assertSafeAliasSegments(key.split(`.`)) |
| 303 | } |
| 304 | if (key.startsWith(`__SPREAD_SENTINEL__`)) { |
| 305 | const rest = key.slice(`__SPREAD_SENTINEL__`.length) |
| 306 | const splitIndex = rest.lastIndexOf(`__`) |
| 307 | const pathStr = splitIndex >= 0 ? rest.slice(0, splitIndex) : rest |
| 308 | const isRefExpr = |
| 309 | value && |
| 310 | typeof value === `object` && |
| 311 | `type` in (value as any) && |
| 312 | (value as any).type === `ref` |
| 313 | if (pathStr.includes(`.`) || isRefExpr) { |
| 314 | // Merge into the current destination (prefixPath) from the referenced source path |
| 315 | const targetPath = [...prefixPath] |
| 316 | const expr = isRefExpr |
| 317 | ? (value as BasicExpression) |
| 318 | : (new PropRef(pathStr.split(`.`)) as BasicExpression) |
| 319 | const compiled = compileExpression(expr) |
| 320 | ops.push({ kind: `merge`, targetPath, source: compiled }) |
| 321 | } else { |
| 322 | // Table-level: pathStr is the alias; merge from namespaced row at the current prefix |
| 323 | const tableAlias = pathStr |
| 324 | const targetPath = [...prefixPath] |
| 325 | ops.push({ |
| 326 | kind: `merge`, |
| 327 | targetPath, |
| 328 | source: (row) => (row as any)[tableAlias], |
| 329 | }) |
| 330 | } |
| 331 | continue |
| 332 | } |
| 333 | |
| 334 | const expression = value as any |
| 335 | if (isConditionalSelectValue(expression)) { |
| 336 | if (containsAggregate(expression)) { |
| 337 | ops.push({ |
| 338 | kind: `field`, |
| 339 | alias: [...prefixPath, key].join(`.`), |
| 340 | compiled: () => null, |
| 341 | }) |
| 342 | continue |
| 343 | } |
| 344 | |
| 345 | ops.push({ |
| 346 | kind: `field`, |
| 347 | alias: [...prefixPath, key].join(`.`), |
| 348 | compiled: compileConditionalSelect(expression), |
| 349 | }) |
| 350 | continue |
| 351 | } |
| 352 |
no test coverage detected
searching dependent graphs…