drizzle-cube
Version:
Drizzle ORM-first semantic layer with Cube.js compatibility. Type-safe analytics and dashboards with SQL injection protection.
104 lines (103 loc) • 3.43 kB
TypeScript
import { MetricItem, BreakdownItem, FieldOption, FieldType, RecentFieldsStorage } from './types';
import { MetaResponse, MetaField } from '../../shared/types';
import { CubeQuery, Filter } from '../../types';
/**
* Generate a unique ID for items
*/
export declare function generateId(): string;
/**
* Generate letter label for metrics (A, B, C, ..., AA, AB, ...)
*/
export declare function generateMetricLabel(index: number): string;
/**
* Convert metrics and breakdowns to CubeQuery format
*/
export declare function buildCubeQuery(metrics: MetricItem[], breakdowns: BreakdownItem[], filters: Filter[]): CubeQuery;
/**
* Check if a query has any content
*/
export declare function hasQueryContent(metrics: MetricItem[], breakdowns: BreakdownItem[], filters: Filter[]): boolean;
/**
* Get cube name from a field name (e.g., "Employees.count" -> "Employees")
*/
export declare function getCubeNameFromField(fieldName: string): string;
/**
* Get field short name from full name (e.g., "Employees.count" -> "count")
*/
export declare function getFieldShortName(fieldName: string): string;
/**
* Find field metadata from schema
*/
export declare function findFieldInSchema(fieldName: string, schema: MetaResponse | null): {
field: MetaField;
cubeName: string;
fieldType: FieldType;
} | null;
/**
* Get display title for a field
*/
export declare function getFieldTitle(fieldName: string, schema: MetaResponse | null): string;
/**
* Determine field type from metadata
*/
export declare function getFieldType(field: MetaField): FieldType;
/**
* Convert schema to flat list of field options
*/
export declare function schemaToFieldOptions(schema: MetaResponse | null, mode: 'metrics' | 'breakdown' | 'filter'): FieldOption[];
/**
* Filter field options by search term
*/
export declare function filterFieldOptions(options: FieldOption[], searchTerm: string, selectedCube?: string | null): FieldOption[];
/**
* Group field options by cube
*/
export declare function groupFieldsByCube(options: FieldOption[]): Map<string, FieldOption[]>;
/**
* Get recent fields from localStorage
*/
export declare function getRecentFields(): RecentFieldsStorage;
/**
* Add a field to recent fields
*/
export declare function addRecentField(fieldName: string, mode: 'metrics' | 'breakdowns'): void;
/**
* Get recent field options from schema
*/
export declare function getRecentFieldOptions(schema: MetaResponse | null, mode: 'metrics' | 'breakdown' | 'filter', recentFieldNames: string[]): FieldOption[];
/**
* Get list of cube names from schema
*/
export declare function getCubeNames(schema: MetaResponse | null): string[];
/**
* Get cube title by name
*/
export declare function getCubeTitle(cubeName: string, schema: MetaResponse | null): string;
/**
* Save state to localStorage
*/
export declare function saveStateToStorage(state: {
metrics: MetricItem[];
breakdowns: BreakdownItem[];
filters: Filter[];
chartType: string;
chartConfig: object;
displayConfig: object;
activeView: string;
}): void;
/**
* Load state from localStorage
*/
export declare function loadStateFromStorage(): {
metrics: MetricItem[];
breakdowns: BreakdownItem[];
filters: Filter[];
chartType: string;
chartConfig: object;
displayConfig: object;
activeView: string;
} | null;
/**
* Clear state from localStorage
*/
export declare function clearStateFromStorage(): void;