drizzle-cube
Version:
Drizzle ORM-first semantic layer with Cube.js compatibility. Type-safe analytics and dashboards with SQL injection protection.
217 lines (216 loc) • 7.13 kB
TypeScript
import { CubeQuery, FilterOperator, Filter, SimpleFilter, GroupFilter } from '../../types';
export interface MetaField {
name: string;
title: string;
shortTitle: string;
type: string;
description?: string;
}
export interface MetaCube {
name: string;
title: string;
description: string;
measures: MetaField[];
dimensions: MetaField[];
segments: MetaField[];
}
export interface MetaResponse {
cubes: MetaCube[];
}
export type ValidationStatus = 'idle' | 'validating' | 'valid' | 'invalid';
export type ExecutionStatus = 'idle' | 'loading' | 'success' | 'error';
export type SchemaStatus = 'idle' | 'loading' | 'success' | 'error';
export interface QueryBuilderState {
query: CubeQuery;
schema: MetaResponse | null;
schemaStatus: SchemaStatus;
schemaError: string | null;
validationStatus: ValidationStatus;
validationError: string | null;
validationSql: {
sql: string[];
params: any[];
} | null;
executionStatus: ExecutionStatus;
executionResults: any[] | null;
executionError: string | null;
totalRowCount: number | null;
totalRowCountStatus: 'idle' | 'loading' | 'success' | 'error';
}
export interface ValidationResult {
valid?: boolean;
error?: string;
query?: CubeQuery;
sql?: {
sql: string[];
params: any[];
};
queryType?: string;
normalizedQueries?: any[];
queryOrder?: string[];
transformedQueries?: any[];
pivotQuery?: any;
complexity?: string;
cubesUsed?: string[];
joinType?: string;
}
export interface ApiConfig {
baseApiUrl: string;
apiToken: string;
}
export interface QueryBuilderProps {
className?: string;
initialQuery?: CubeQuery;
disableLocalStorage?: boolean;
hideSettings?: boolean;
}
export interface QueryBuilderRef {
getCurrentQuery: () => CubeQuery;
getValidationState: () => {
status: ValidationStatus;
result?: ValidationResult;
};
getValidationResult: () => ValidationResult | null;
}
export interface CubeMetaExplorerProps {
schema: MetaResponse | null;
schemaStatus: SchemaStatus;
schemaError: string | null;
selectedFields: {
measures: string[];
dimensions: string[];
timeDimensions: string[];
};
onFieldSelect: (fieldName: string, fieldType: 'measures' | 'dimensions' | 'timeDimensions') => void;
onFieldDeselect: (fieldName: string, fieldType: 'measures' | 'dimensions' | 'timeDimensions') => void;
onRetrySchema?: () => void;
onOpenSettings?: () => void;
onExpandSchema?: (expanded: boolean) => void;
onViewTypeChange?: (viewType: 'tree' | 'diagram') => void;
isExpanded?: boolean;
}
export interface QueryPanelProps {
query: CubeQuery;
schema: MetaResponse | null;
validationStatus: ValidationStatus;
validationError: string | null;
validationSql: {
sql: string[];
params: any[];
} | null;
onValidate: () => void;
onExecute: () => void;
onRemoveField: (fieldName: string, fieldType: 'measures' | 'dimensions' | 'timeDimensions') => void;
onTimeDimensionGranularityChange: (dimensionName: string, granularity: string) => void;
onFiltersChange: (filters: Filter[]) => void;
onDateRangeChange: (timeDimension: string, dateRange: string | string[]) => void;
onDateRangeRemove: (timeDimension: string) => void;
onOrderChange: (fieldName: string, direction: 'asc' | 'desc' | null) => void;
onClearQuery?: () => void;
showSettings?: boolean;
onSettingsClick?: () => void;
onAIAssistantClick?: () => void;
onSchemaClick?: () => void;
}
export interface ResultsPanelProps {
executionStatus: ExecutionStatus;
executionResults: any[] | null;
executionError: string | null;
query: CubeQuery;
displayLimit?: number;
onDisplayLimitChange?: (limit: number) => void;
totalRowCount?: number | null;
totalRowCountStatus?: 'idle' | 'loading' | 'success' | 'error';
}
export declare const TIME_GRANULARITIES: readonly [{
readonly value: "hour";
readonly label: "Hour";
}, {
readonly value: "day";
readonly label: "Day";
}, {
readonly value: "week";
readonly label: "Week";
}, {
readonly value: "month";
readonly label: "Month";
}, {
readonly value: "quarter";
readonly label: "Quarter";
}, {
readonly value: "year";
readonly label: "Year";
}];
export type TimeGranularity = typeof TIME_GRANULARITIES[number]['value'];
export interface FilterOperatorMeta {
label: string;
description: string;
requiresValues: boolean;
supportsMultipleValues: boolean;
valueType: 'string' | 'number' | 'date' | 'boolean' | 'any';
fieldTypes: string[];
}
export declare const FILTER_OPERATORS: Record<FilterOperator, FilterOperatorMeta>;
export interface FilterBuilderProps {
filters: Filter[];
schema: MetaResponse | null;
query: CubeQuery;
onFiltersChange: (filters: Filter[]) => void;
hideFieldSelector?: boolean;
}
export interface FilterItemProps {
filter: SimpleFilter;
index: number;
onFilterChange: (index: number, filter: SimpleFilter) => void;
onFilterRemove: (index: number) => void;
schema: MetaResponse | null;
query: CubeQuery;
hideFieldSelector?: boolean;
hideOperatorSelector?: boolean;
hideRemoveButton?: boolean;
}
export interface FilterGroupProps {
group: GroupFilter;
index: number;
onGroupChange: (index: number, group: GroupFilter) => void;
onGroupChangeWithUnwrap?: (index: number, group: GroupFilter) => void;
onGroupRemove: (index: number) => void;
schema: MetaResponse | null;
query: CubeQuery;
depth: number;
}
export interface FilterValueSelectorProps {
fieldName: string;
operator: FilterOperator;
values: any[];
onValuesChange: (values: any[]) => void;
schema: MetaResponse | null;
}
export type DateRangeType = 'custom' | 'today' | 'yesterday' | 'this_week' | 'this_month' | 'this_quarter' | 'this_year' | 'last_7_days' | 'last_30_days' | 'last_week' | 'last_month' | 'last_quarter' | 'last_year' | 'last_12_months' | 'last_n_days' | 'last_n_weeks' | 'last_n_months' | 'last_n_quarters' | 'last_n_years';
export interface DateRangeOption {
value: DateRangeType;
label: string;
}
export declare const DATE_RANGE_OPTIONS: DateRangeOption[];
export interface DateRangeFilter {
id: string;
timeDimension: string;
rangeType: DateRangeType;
startDate?: string;
endDate?: string;
}
export interface DateRangeSelectorProps {
timeDimensions: string[];
onDateRangeChange: (timeDimension: string, dateRange: string | string[]) => void;
onDateRangeRemove: (timeDimension: string) => void;
currentDateRanges: Record<string, string | string[]>;
}
export interface DateRangeFilterProps {
timeDimensions: Array<{
dimension: string;
granularity?: string;
dateRange?: string | string[];
}>;
onDateRangeChange: (timeDimension: string, dateRange: string | string[]) => void;
onDateRangeRemove: (timeDimension: string) => void;
}