import type { PlanTable, QueryPlan, ScriptPlan, SimlifiedPlanOperatorOtherParams, SimplifiedNode, } from '../../../types/api/query'; import type {IQueryResult, QueryAction, StatisticsMode} from '../../../types/store/query'; export type QueryExecutionStatusType = 'loading' | 'completed' | 'failed' | 'stopped' | 'aborted'; export interface RawQueryInHistory { queryId: string; operationId?: string; realQueryId?: string; queryText: string; syntax?: string; startTime?: number; endTime?: string | number; durationUs?: string | number; status?: string; } export interface QueryInHistory extends RawQueryInHistory { status?: QueryExecutionStatusType; } export interface Link { from: string; to: string; } export interface Metric { name: string; value: string; theme?: 'warning' | 'danger'; } export interface GraphNode { name: string; status?: string; meta?: string; group?: string; data?: TData; metrics?: Metric[]; } export interface ExplainPlanNodeData { id?: number; type: 'query' | 'result' | 'stage' | 'connection' | 'materialize'; name?: string; operators?: string[]; tables?: string[]; cte?: string; stats?: TopologyNodeDataStats[]; } export interface TopologyNodeDataStatsItem { name: string; value: string | number; } export interface TopologyNodeDataStatsSection { name: string; items: TopologyNodeDataStatsItem[]; } export interface TopologyNodeDataStats { group: string; stats: TopologyNodeDataStatsSection[] | TopologyNodeDataStatsItem[]; } export interface PreparedPlan { links?: Link[]; nodes?: GraphNode[]; tables?: PlanTable[]; version?: string; pristine?: QueryPlan | ScriptPlan; DurationUs?: string | number; } interface SimplifiedPlan { plan?: SimplifiedPlanItem[]; pristine?: SimplifiedNode; } export interface SimplifiedPlanItem { parentId?: string; name: string; operationParams: SimlifiedPlanOperatorOtherParams; aCpu?: number; aRows?: number; eCost?: string; eRows?: string; eSize?: string; children?: SimplifiedPlanItem[]; } export interface PreparedQueryData extends IQueryResult { preparedPlan?: PreparedPlan; simplifiedPlan?: SimplifiedPlan; } export type StreamingStatus = 'preparing' | 'running' | 'fetching'; export interface QuerySourcePosition { lineNumber: number; column: number; preparedQueryPrefixLineCount?: number; } export interface QueryResult { executionId: string; type: QueryAction; statisticsMode?: StatisticsMode; data?: PreparedQueryData; error?: unknown; queryId: string; operationId?: string; startTime?: number; endTime?: number; isLoading: boolean; streamingStatus?: StreamingStatus; sourcePosition?: QuerySourcePosition; } export interface QueryTabState { id: string; title: string; /** * True only when the user explicitly renamed the tab via UI. * Used for UX decisions (e.g. prefilling "Save as" name). */ isTitleUserDefined?: boolean; input: string; /** * The "clean" baseline input used to compute isDirty. * undefined = unknown baseline (e.g. tab loaded as dirty from persistence) — stays dirty until explicit reset. */ savedInput?: string; isDirty: boolean; isTouched?: boolean; createdAt: number; updatedAt: number; lastExecutedQueryText?: string; result?: QueryResult; /** * Snippet text to be inserted into the editor after the tab model is switched. * Used when creating a new tab from templates (schema actions, New SQL). * Cleared after insertion by the editor component. */ pendingSnippet?: string; /** * Name of the saved query currently bound to this tab. * Used in multi-tab mode to decide between "Save" and "Edit query". */ savedQueryName?: string; } export interface QueryState { activeTabId?: string; tabsOrder: string[]; tabsById: Record; newTabCounter: number; historyFilter?: string; historyCurrentQueryId?: string; tenantPath?: string; selectedResultTab?: Partial>; } export interface QueryStats { startTime?: number; durationUs?: string | number; endTime?: string | number; status?: QueryExecutionStatusType; operationId?: string; }