( select: Record<string, any>, targetPath: Array<string>, )
| 1565 | } |
| 1566 | |
| 1567 | function findProjectedIncludePaths( |
| 1568 | select: Record<string, any>, |
| 1569 | targetPath: Array<string>, |
| 1570 | ): Array<ProjectedSourceIncludePath> { |
| 1571 | const resultPaths: Array<ProjectedSourceIncludePath> = [] |
| 1572 | |
| 1573 | const visitSelectObject = ( |
| 1574 | obj: Record<string, any>, |
| 1575 | prefix: Array<string>, |
| 1576 | guards: Array<ConditionalSelectGuard>, |
| 1577 | ) => { |
| 1578 | for (const [key, value] of Object.entries(obj)) { |
| 1579 | if (key.startsWith(`__SPREAD_SENTINEL__`)) { |
| 1580 | visitSpreadSentinel(key, value, prefix, guards) |
| 1581 | continue |
| 1582 | } |
| 1583 | visitSelectValue(value, [...prefix, key], guards) |
| 1584 | } |
| 1585 | } |
| 1586 | |
| 1587 | const visitSpreadSentinel = ( |
| 1588 | key: string, |
| 1589 | value: any, |
| 1590 | path: Array<string>, |
| 1591 | guards: Array<ConditionalSelectGuard>, |
| 1592 | ) => { |
| 1593 | const rest = key.slice(`__SPREAD_SENTINEL__`.length) |
| 1594 | const splitIndex = rest.lastIndexOf(`__`) |
| 1595 | const pathStr = splitIndex >= 0 ? rest.slice(0, splitIndex) : rest |
| 1596 | const isRefExpr = |
| 1597 | value && |
| 1598 | typeof value === `object` && |
| 1599 | `type` in value && |
| 1600 | value.type === `ref` |
| 1601 | const sourcePath = isRefExpr |
| 1602 | ? (value as PropRef).path |
| 1603 | : pathStr.split(`.`).filter(Boolean) |
| 1604 | |
| 1605 | if (pathStartsWith(targetPath, sourcePath)) { |
| 1606 | resultPaths.push({ |
| 1607 | path: [...path, ...targetPath.slice(sourcePath.length)], |
| 1608 | guards, |
| 1609 | }) |
| 1610 | } |
| 1611 | } |
| 1612 | |
| 1613 | const visitSelectValue = ( |
| 1614 | value: any, |
| 1615 | path: Array<string>, |
| 1616 | guards: Array<ConditionalSelectGuard>, |
| 1617 | ) => { |
| 1618 | if (value instanceof PropRef && pathStartsWith(targetPath, value.path)) { |
| 1619 | resultPaths.push({ |
| 1620 | path: [...path, ...targetPath.slice(value.path.length)], |
| 1621 | guards, |
| 1622 | }) |
| 1623 | return |
| 1624 | } |
no test coverage detected