{"version":3,"file":"find-aggregate.cjs","names":["Aggregate","Func","ConditionalSelect","isExpressionLike"],"sources":["../../../../src/query/compiler/find-aggregate.ts"],"sourcesContent":["import { Aggregate, ConditionalSelect, Func, isExpressionLike } from '../ir.js'\n\n/**\n * Returns the first aggregate in a select, having, or orderBy value. It does\n * not enter include subqueries, which compile with their own aggregates.\n * A plain object is a nested select; its fields may use any names.\n */\nexport function findAggregate(value: unknown): Aggregate | undefined {\n  if (value === null || typeof value !== `object`) return undefined\n  if (Array.isArray(value)) {\n    for (const item of value) {\n      const aggregate = findAggregate(item)\n      if (aggregate) return aggregate\n    }\n    return undefined\n  }\n  if (value instanceof Aggregate) return value\n  if (value instanceof Func) return findAggregate(value.args)\n  if (value instanceof ConditionalSelect)\n    return findAggregate([value.branches, value.defaultValue])\n  if (isExpressionLike(value)) return undefined\n  return findAggregate(Object.values(value))\n}\n"],"mappings":";AAOA,SAAgB,cAAc,OAAuC;CACnE,IAAI,UAAU,QAAQ,OAAO,UAAU,UAAU,OAAO,KAAA;CACxD,IAAI,MAAM,QAAQ,KAAK,GAAG;EACxB,KAAA,MAAW,QAAQ,OAAO;GACxB,MAAM,YAAY,cAAc,IAAI;GACpC,IAAI,WAAW,OAAO;EACxB;EACA;CACF;CACA,IAAI,iBAAiBA,WAAAA,WAAW,OAAO;CACvC,IAAI,iBAAiBC,WAAAA,MAAM,OAAO,cAAc,MAAM,IAAI;CAC1D,IAAI,iBAAiBC,WAAAA,mBACnB,OAAO,cAAc,CAAC,MAAM,UAAU,MAAM,YAAY,CAAC;CAC3D,IAAIC,WAAAA,iBAAiB,KAAK,GAAG,OAAO,KAAA;CACpC,OAAO,cAAc,OAAO,OAAO,KAAK,CAAC;AAC3C"}