drizzle-cube
Version:
Drizzle ORM-first semantic layer with Cube.js compatibility. Type-safe analytics and dashboards with SQL injection protection.
154 lines (153 loc) • 4.46 kB
TypeScript
import { ColorPalette } from './utils/colorPalettes';
export type { CubeMeta, CubeMetaCube, CubeMetaField, CubeMetaRelationship, FieldLabelMap } from './hooks/useCubeMeta';
export type { ColorPalette } from './utils/colorPalettes';
export type ChartType = 'line' | 'bar' | 'pie' | 'table' | 'area' | 'scatter' | 'radar' | 'radialBar' | 'treemap' | 'bubble' | 'activityGrid' | 'kpiNumber' | 'kpiDelta' | 'kpiText' | 'markdown';
export interface ChartAxisConfig {
xAxis?: string[];
yAxis?: string[];
series?: string[];
sizeField?: string;
colorField?: string;
dateField?: string[];
valueField?: string[];
x?: string;
y?: string[];
}
export interface ChartDisplayConfig {
showLegend?: boolean;
showGrid?: boolean;
showTooltip?: boolean;
colors?: string[];
orientation?: 'horizontal' | 'vertical';
stacked?: boolean;
hideHeader?: boolean;
minBubbleSize?: number;
maxBubbleSize?: number;
bubbleOpacity?: number;
showLabels?: boolean;
colorIntensity?: 'low' | 'medium' | 'high';
target?: string;
template?: string;
prefix?: string;
suffix?: string;
decimals?: number;
valueColor?: string;
valueColorIndex?: number;
positiveColorIndex?: number;
negativeColorIndex?: number;
showHistogram?: boolean;
content?: string;
accentColorIndex?: number;
fontSize?: 'small' | 'medium' | 'large';
alignment?: 'left' | 'center' | 'right';
}
export interface PortletConfig {
id: string;
title: string;
query: string;
chartType: ChartType;
chartConfig?: ChartAxisConfig;
displayConfig?: ChartDisplayConfig;
w: number;
h: number;
x: number;
y: number;
}
export interface DashboardConfig {
portlets: PortletConfig[];
layouts?: {
[key: string]: any;
};
colorPalette?: string;
}
export type FilterOperator = 'equals' | 'notEquals' | 'contains' | 'notContains' | 'startsWith' | 'notStartsWith' | 'endsWith' | 'notEndsWith' | 'like' | 'notLike' | 'ilike' | 'gt' | 'gte' | 'lt' | 'lte' | 'between' | 'notBetween' | 'in' | 'notIn' | 'set' | 'notSet' | 'isEmpty' | 'isNotEmpty' | 'inDateRange' | 'beforeDate' | 'afterDate' | 'regex' | 'notRegex';
export interface SimpleFilter {
member: string;
operator: FilterOperator;
values: any[];
}
export interface GroupFilter {
type: 'and' | 'or';
filters: Filter[];
}
export type Filter = SimpleFilter | GroupFilter;
export interface CubeQuery {
measures?: string[];
dimensions?: string[];
timeDimensions?: Array<{
dimension: string;
granularity?: string;
dateRange?: string[] | string;
}>;
filters?: Filter[];
order?: {
[key: string]: 'asc' | 'desc';
};
limit?: number;
offset?: number;
segments?: string[];
}
export interface CubeQueryOptions {
skip?: boolean;
resetResultSetOnChange?: boolean;
subscribe?: boolean;
}
export interface CubeApiOptions {
apiUrl?: string;
token?: string;
headers?: Record<string, string>;
}
export interface CubeResultSet {
rawData(): any[];
tablePivot(): any[];
series(): any[];
annotation(): any;
loadResponse?: any;
}
export interface AnalyticsPortletProps {
query: string;
chartType: ChartType;
chartConfig?: ChartAxisConfig;
displayConfig?: ChartDisplayConfig;
height?: string | number;
title?: string;
colorPalette?: ColorPalette;
onDebugDataReady?: (debugData: {
chartConfig: ChartAxisConfig;
displayConfig: ChartDisplayConfig;
queryObject: any;
data: any[];
chartType: ChartType;
}) => void;
}
export interface AnalyticsDashboardProps {
config: DashboardConfig;
editable?: boolean;
onConfigChange?: (config: DashboardConfig) => void;
onSave?: (config: DashboardConfig) => Promise<void> | void;
onDirtyStateChange?: (isDirty: boolean) => void;
}
export interface ChartProps {
data: any[];
chartConfig?: ChartAxisConfig;
displayConfig?: ChartDisplayConfig;
queryObject?: CubeQuery;
height?: string | number;
colorPalette?: ColorPalette;
}
export interface FeaturesConfig {
enableAI?: boolean;
aiEndpoint?: string;
}
export interface GridLayout {
i: string;
x: number;
y: number;
w: number;
h: number;
minW?: number;
minH?: number;
}
export interface ResponsiveLayout {
[breakpoint: string]: GridLayout[];
}