UNPKG

drizzle-cube

Version:

Drizzle ORM-first semantic layer with Cube.js compatibility. Type-safe analytics and dashboards with SQL injection protection.

144 lines (143 loc) 4.11 kB
import { CubeQuery, FilterOperator } from '../types'; export interface MetaField { name: string; title: string; shortTitle: string; type: string; description?: string; } export interface MetaCubeRelationship { targetCube: string; relationship: 'belongsTo' | 'hasOne' | 'hasMany' | 'belongsToMany'; joinFields?: Array<{ sourceField: string; targetField: string; }>; } export interface MetaCube { name: string; title: string; description: string; measures: MetaField[]; dimensions: MetaField[]; segments: MetaField[]; relationships?: MetaCubeRelationship[]; } export interface MetaResponse { cubes: MetaCube[]; } export type PrimaryCubeSelectionReason = 'most_dimensions' | 'most_connected' | 'alphabetical_fallback' | 'single_cube'; export interface PrimaryCubeCandidate { cubeName: string; dimensionCount: number; joinCount: number; canReachAll: boolean; } export interface PrimaryCubeAnalysis { selectedCube: string; reason: PrimaryCubeSelectionReason; explanation: string; candidates?: PrimaryCubeCandidate[]; } export interface JoinPathStep { fromCube: string; toCube: string; relationship: 'belongsTo' | 'hasOne' | 'hasMany' | 'belongsToMany'; joinType: 'inner' | 'left' | 'right' | 'full'; joinColumns: Array<{ sourceColumn: string; targetColumn: string; }>; junctionTable?: { tableName: string; sourceColumns: string[]; targetColumns: string[]; }; } export interface JoinPathAnalysis { targetCube: string; pathFound: boolean; path?: JoinPathStep[]; pathLength?: number; error?: string; visitedCubes?: string[]; } export interface PreAggregationAnalysis { cubeName: string; cteAlias: string; reason: string; measures: string[]; joinKeys: Array<{ sourceColumn: string; targetColumn: string; }>; } export interface QuerySummary { queryType: 'single_cube' | 'multi_cube_join' | 'multi_cube_cte'; joinCount: number; cteCount: number; hasPreAggregation: boolean; } export interface QueryAnalysis { timestamp: string; cubeCount: number; cubesInvolved: string[]; primaryCube: PrimaryCubeAnalysis; joinPaths: JoinPathAnalysis[]; preAggregations: PreAggregationAnalysis[]; querySummary: QuerySummary; warnings?: string[]; } 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; analysis?: QueryAnalysis; } 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 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 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'];