import { AnalysisParams } from "../analysis-types.mjs"; import { FileSet } from "../source/source-types.mjs"; import { Analyzer, BuildContext, RequiredCapability, SqlExtraQuery } from "./types.mjs"; import { BuilderState } from "gscdump/query"; interface SqlPlanSpec { sql: string; params: unknown[]; current: FileSet; previous?: FileSet; extraFiles?: Record; extraQueries?: SqlExtraQuery[]; } interface ReduceCtx { /** Extra SQL-query results keyed by `SqlExtraQuery.name` (SQL path only). */ extras?: Record; } type Reducer = (rows: InputRow[] | Record, params: Params, ctx: ReduceCtx) => { results: Result; meta?: Record; }; interface DefineAnalyzerOptions { id: string; /** * Shared reducer used by both SQL and row paths. Use this when the * post-aggregation row count is small and filter/sort/derive can live in * one place. Mutually exclusive with `reduceSql` / `reduceRows`. */ reduce?: Reducer; /** SQL-only reducer. Required when `buildSql` is set without `reduce`. */ reduceSql?: Reducer; /** Row-only reducer. Required when `buildRows` is set without `reduce`. */ reduceRows?: Reducer; /** SQL plan builder. Omit if the analyzer has no SQL path. */ buildSql?: (params: Params, ctx: BuildContext) => SqlPlanSpec; /** Row plan builder. Omit if the analyzer has no row path. */ buildRows?: (params: Params, ctx: BuildContext) => Record; /** Capabilities required by the SQL plan. Defaults to `['executeSql', 'fileSets']`. */ sqlRequires?: readonly RequiredCapability[]; /** Capabilities required by the row plan. Defaults to `[]`. */ rowsRequires?: readonly RequiredCapability[]; } interface DefinedAnalyzer { id: string; sql?: Analyzer; rows?: Analyzer; } declare function defineAnalyzer(opts: DefineAnalyzerOptions): DefinedAnalyzer; export { DefineAnalyzerOptions, DefinedAnalyzer, ReduceCtx, Reducer, SqlPlanSpec, defineAnalyzer };