Shared TypeScript library for the Lightdash platform containing common types, utilities, and business logic for analytics workflows
Overall
score
72%
Evaluation — 72%
↑ 1.09xAgent success when using this tile
This document contains types for dashboards, charts, visualization configurations, spaces, and content-as-code functionality.
This module provides the following functionality:
interface Dashboard {
organizationUuid: string;
projectUuid: string;
uuid: string;
name: string;
description?: string;
updatedAt: Date;
tiles: DashboardTile[];
filters: DashboardFilters;
parameters?: DashboardParameters;
tabs?: DashboardTab[];
spaceUuid: string;
views: number;
firstViewedAt: Date | null;
pinnedListUuid: string | null;
pinnedListOrder: number | null;
slug: string;
dashboardVersionId: number;
updatedByUser?: UpdatedByUser;
config?: DashboardConfig;
}
interface DashboardTab {
uuid: string;
name: string;
order: number;
}
interface CreateDashboard {
name: string;
description?: string;
tiles?: DashboardTileTypes[];
filters?: DashboardFilters;
parameters?: DashboardParameters;
spaceUuid?: string;
tags?: string[];
}
interface UpdateDashboard {
name?: string;
description?: string;
tiles?: DashboardTile[];
filters?: DashboardFilters;
tabs?: DashboardTab[];
}
interface DashboardFilters {
dimensions: DashboardFilterRule[];
metrics: DashboardFilterRule[];
tableCalculations: DashboardFilterRule[];
}
interface DashboardAvailableFilters {
dimensions: FilterableDimension[];
metrics: Metric[];
tableCalculations: TableCalculation[];
}
interface DashboardConfig {
isDateZoomDisabled: boolean;
pinnedParameters?: string[];
}
type DashboardParameterValue = {
parameterName: string;
value: ParameterValue;
};
type DashboardParameters = Record<string, DashboardParameterValue>;Additional dashboard-related types, constants, and utility functions:
import {
type DashboardUnversionedFields,
type DashboardVersionedFields,
type UpdateDashboardDetails,
type DuplicateDashboardParams,
type SavedChartsInfoForDashboardAvailableFilters,
type DashboardSqlChartTileProperties,
type ApiCreateDashboardResponse,
type ApiCreateDashboardWithChartsResponse,
type ApiGetDashboardsResponse,
type ApiUpdateDashboardsResponse,
defaultTileSize,
isDashboardUnversionedFields,
isDashboardVersionedFields,
isDuplicateDashboardParams,
isDashboardChartTileType,
isDashboardLoomTileType,
isDashboardMarkdownTileType,
isDashboardSqlChartTileType,
isDashboardUnversionedChartTileType,
getDashboardFilterRulesForTile
} from '@lightdash/common';
/**
* Dashboard fields that don't trigger version creation
*/
type DashboardUnversionedFields = Pick<
CreateDashboard,
'name' | 'description' | 'spaceUuid'
>;
/**
* Dashboard fields that trigger version creation
*/
type DashboardVersionedFields = Pick<
CreateDashboard,
'tiles' | 'filters' | 'parameters' | 'updatedByUser' | 'tabs' | 'config'
>;
/**
* Type for updating basic dashboard details
*/
type UpdateDashboardDetails = Pick<Dashboard, 'name' | 'description'>;
/**
* Parameters for duplicating a dashboard
*/
type DuplicateDashboardParams = {
dashboardName: string;
dashboardDesc: string;
};
/**
* Information about saved charts for dashboard filter computation
*/
type SavedChartsInfoForDashboardAvailableFilters = {
tileUuid: string;
savedChartUuid: string;
}[];
/**
* Properties for SQL chart tiles
*/
type DashboardSqlChartTileProperties = {
type: DashboardTileTypes.SQL_CHART;
properties: {
title?: string;
savedSqlUuid: string | null;
chartName: string;
hideTitle?: boolean;
chartSlug?: string;
lastVersionChartKind?: ChartKind | null;
};
};
/**
* Default tile size dimensions
*/
const defaultTileSize = {
h: 9,
w: 15,
x: 0,
y: 0,
};
/**
* API response for getting list of dashboards
*/
type ApiGetDashboardsResponse = {
status: 'ok';
results: DashboardBasicDetailsWithTileTypes[];
};
/**
* API response for creating a dashboard
*/
type ApiCreateDashboardResponse = {
status: 'ok';
results: Dashboard;
};
/**
* API response for creating a dashboard with charts
*/
type ApiCreateDashboardWithChartsResponse = {
status: 'ok';
results: Dashboard;
};
/**
* API response for updating multiple dashboards
*/
type ApiUpdateDashboardsResponse = {
status: 'ok';
results: Dashboard[];
};
/**
* Type guard to check if update contains unversioned fields
*/
function isDashboardUnversionedFields(
data: UpdateDashboard
): data is DashboardUnversionedFields;
/**
* Type guard to check if update contains versioned fields
*/
function isDashboardVersionedFields(
data: UpdateDashboard
): data is DashboardVersionedFields;
/**
* Type guard to check if params are for duplicating a dashboard
*/
function isDuplicateDashboardParams(
params: DuplicateDashboardParams | CreateDashboard
): params is DuplicateDashboardParams;
/**
* Type guard to check if tile is a chart tile
*/
function isDashboardChartTileType(tile: DashboardTile): tile is DashboardChartTile;
/**
* Type guard to check if tile is a Loom tile
*/
function isDashboardLoomTileType(tile: DashboardTile): tile is DashboardLoomTile;
/**
* Type guard to check if tile is a markdown tile
*/
function isDashboardMarkdownTileType(tile: DashboardTile): tile is DashboardMarkdownTile;
/**
* Type guard to check if tile is a SQL chart tile
*/
function isDashboardSqlChartTileType(tile: DashboardTile): tile is DashboardSqlChartTile;
/**
* Type guard to check if tile is an unversioned chart tile
*/
function isDashboardUnversionedChartTileType(tile: DashboardTile): boolean;
/**
* Get filter rules that apply to a specific dashboard tile
*/
function getDashboardFilterRulesForTile(
tile: DashboardChartTile,
filters: DashboardFilters
): DashboardFilterRule[];enum DashboardTileTypes {
SAVED_CHART = 'saved_chart',
MARKDOWN = 'markdown',
LOOM = 'loom',
SQL_CHART = 'sql_chart',
}
interface DashboardBaseTile {
uuid: string;
type: DashboardTileTypes;
x: number;
y: number;
h: number;
w: number;
tabUuid?: string;
}
interface DashboardChartTile extends DashboardBaseTile {
type: DashboardTileTypes.SAVED_CHART;
properties: {
savedChartUuid: string | null;
chartName?: string;
title?: string;
hideTitle?: boolean;
belongsToDashboard?: boolean;
lastVersionChartKind?: ChartKind | null;
};
}
interface DashboardMarkdownTile extends DashboardBaseTile {
type: DashboardTileTypes.MARKDOWN;
properties: {
title: string;
content: string;
};
}
interface DashboardLoomTile extends DashboardBaseTile {
type: DashboardTileTypes.LOOM;
properties: {
title: string;
url: string;
hideTitle?: boolean;
};
}
interface DashboardSqlChartTile extends DashboardBaseTile {
type: DashboardTileTypes.SQL_CHART;
properties: {
savedSqlUuid: string | null;
chartName?: string;
title?: string;
hideTitle?: boolean;
lastVersionChartKind?: ChartKind | null;
};
}
type DashboardTile =
| DashboardChartTile
| DashboardMarkdownTile
| DashboardLoomTile
| DashboardSqlChartTile;
function isDashboardChartTileType(tile: DashboardTile): tile is DashboardChartTile;
function isDashboardMarkdownTileType(tile: DashboardTile): tile is DashboardMarkdownTile;
function isDashboardLoomTileType(tile: DashboardTile): tile is DashboardLoomTile;
function isDashboardSqlChartTile(tile: DashboardTile): tile is DashboardSqlChartTile;
function hasChartsInDashboard(dashboard: Dashboard): boolean;
function getDefaultChartTileSize(chartKind: ChartKind | null | undefined): { h: number; w: number };enum DashboardSummaryTone {
FRIENDLY = 'friendly',
FORMAL = 'formal',
DIRECT = 'direct',
ENTHUSIASTIC = 'enthusiastic',
}
interface DashboardSummary {
dashboardSummaryUuid: string;
dashboardUuid: string;
dashboardVersionId: number;
context?: string | null;
tone: DashboardSummaryTone;
audiences: string[];
summary: string;
createdAt: Date;
}type DashboardBasicDetailsWithTileTypes = DashboardBasicDetails & {
tileTypes: DashboardTileTypes[];
};interface SavedChart {
uuid: string;
projectUuid: string;
name: string;
description?: string;
tableName: string;
metricQuery: MetricQuery;
chartConfig: ChartConfig;
tableConfig: TableChart;
pivotConfig?: PivotConfig;
updatedAt: Date;
updatedByUser?: UpdatedByUser;
organizationUuid: string;
spaceUuid: string;
spaceName: string;
pinnedListUuid: string | null;
pinnedListOrder: number | null;
dashboardUuid: string | null;
dashboardName: string | null;
slug: string;
views: number;
firstViewedAt: Date | null;
validationErrors?: ValidationError[];
tags?: string[];
}
interface CreateSavedChart {
name: string;
description?: string;
tableName: string;
metricQuery: MetricQuery;
chartConfig: ChartConfig;
tableConfig: TableChart;
pivotConfig?: PivotConfig;
spaceUuid?: string;
dashboardUuid?: string | null;
tags?: string[];
}
interface UpdateSavedChart {
name?: string;
description?: string;
tableName?: string;
metricQuery?: MetricQuery;
chartConfig?: ChartConfig;
tableConfig?: TableChart;
pivotConfig?: PivotConfig;
spaceUuid?: string;
tags?: string[];
}
interface ChartSummary {
uuid: string;
name: string;
description?: string;
spaceUuid: string;
spaceName: string;
pinnedListUuid: string | null;
pinnedListOrder: number | null;
dashboardUuid: string | null;
dashboardName: string | null;
chartType: ChartType;
chartKind: ChartKind;
updatedAt: Date;
updatedByUser?: UpdatedByUser;
validationErrors?: ValidationError[];
views: number;
firstViewedAt: Date | null;
slug: string;
tags?: string[];
}
interface ChartVersion {
chart: SavedChart;
createdAt: Date;
createdBy: UpdatedByUser | null;
versionUuid: string;
}
interface ChartHistory {
history: ChartVersion[];
}enum ChartKind {
LINE = 'line',
HORIZONTAL_BAR = 'horizontal_bar',
VERTICAL_BAR = 'vertical_bar',
SCATTER = 'scatter',
AREA = 'area',
MIXED = 'mixed',
PIE = 'pie',
TABLE = 'table',
BIG_NUMBER = 'big_number',
CUSTOM = 'custom',
FUNNEL = 'funnel',
TREEMAP = 'treemap',
GAUGE = 'gauge',
MAP = 'map',
}
enum ChartType {
CARTESIAN = 'cartesian',
BIG_NUMBER = 'big_number',
TABLE = 'table',
PIE = 'pie',
FUNNEL = 'funnel',
TREEMAP = 'treemap',
GAUGE = 'gauge',
MAP = 'map',
}
type ChartConfig =
| CartesianChartConfig
| PieChartConfig
| BigNumberConfig
| TableChartConfig
| FunnelChartConfig
| TreemapChartConfig
| GaugeChartConfig
| MapChartConfig
| CustomVisConfig;
function isCartesianChartConfig(config: ChartConfig): config is CartesianChartConfig;
function isBigNumberConfig(config: ChartConfig): config is BigNumberConfig;
function isTableChartConfig(config: ChartConfig): config is TableChartConfig;
function isPieChartConfig(config: ChartConfig): config is PieChartConfig;
function getChartType(savedChart: SavedChart): ChartType;
function getChartKind(chartConfig: ChartConfig): ChartKind;Additional chart-related constants, enums, types, and utility functions:
import {
type ApiChartListResponse,
type ApiChartSummaryListResponse,
type ApiCalculateTotalResponse,
type ApiCalculateSubtotalsResponse,
type CalculateTotalFromQuery,
type CalculateSubtotalsFromQuery,
type ChartVersionSummary,
type CompleteCartesianChartLayout,
type CompleteEChartsConfig,
type CreateChart,
type UpdateMultipleChart,
type CartesianSeriesType,
ComparisonDiffTypes,
FunnelChartLegendPosition,
PieChartLegendPositions,
PieChartValueLabels,
PieChartLegendPositionDefault,
PieChartLegendLabelMaxLengthDefault,
PieChartTooltipLabelMaxLength,
getCustomLabelsFromTableConfig,
isChartTile,
isSemanticLayerView,
isSeriesWithMixedChartTypes,
isSqlRunnerChartTile,
isVizConfigWithChartType,
getChartIcon,
getChartTileUuidFromTile
} from '@lightdash/common';
/**
* Enum for comparison difference types (positive/negative/none)
*/
enum ComparisonDiffTypes {
POSITIVE = 'positive',
NEGATIVE = 'negative',
NONE = 'none',
NAN = 'NaN',
UNDEFINED = 'undefined',
}
/**
* Enum for funnel chart legend positioning
*/
enum FunnelChartLegendPosition {
HORIZONTAL = 'horizontal',
VERTICAL = 'vertical',
TOP = 'top',
BOTTOM = 'bottom',
LEFT = 'left',
RIGHT = 'right',
}
/**
* Constants for pie chart configuration
*/
const PieChartLegendPositions = {
horizontal: 'Horizontal',
vertical: 'Vertical',
} as const;
const PieChartValueLabels = {
hidden: 'Hidden',
inside: 'Inside',
outside: 'Outside',
} as const;
const PieChartLegendPositionDefault = 'horizontal';
const PieChartLegendLabelMaxLengthDefault = 30;
const PieChartTooltipLabelMaxLength = 40;
/**
* Cartesian series type (line, bar, scatter, etc.)
*/
type CartesianSeriesType = 'line' | 'bar' | 'scatter' | 'area' | 'mixed';
/**
* Complete cartesian chart layout with all required properties
*/
type CompleteCartesianChartLayout = {
xField: string;
yField: string[];
flipAxes?: boolean;
showGridX?: boolean;
showGridY?: boolean;
showLegend?: boolean;
};
/**
* Complete ECharts configuration object
*/
type CompleteEChartsConfig = {
series: any[];
xAxis: any;
yAxis: any;
legend?: any;
tooltip?: any;
grid?: any;
};
/**
* Summary information for a chart version
*/
type ChartVersionSummary = {
versionUuid: string;
createdAt: Date;
createdBy: {
userUuid: string;
firstName: string;
lastName: string;
};
chartUuid: string;
};
/**
* API response for listing charts
*/
type ApiChartListResponse = {
status: 'ok';
results: SavedChart[];
};
/**
* API response for listing chart summaries
*/
type ApiChartSummaryListResponse = {
status: 'ok';
results: ChartSummary[];
};
/**
* Type for creating a new chart
*/
type CreateChart = Omit<
SavedChart,
| 'uuid'
| 'createdAt'
| 'updatedAt'
| 'projectUuid'
| 'organizationUuid'
| 'spaceUuid'
| 'spaceName'
| 'views'
| 'firstViewedAt'
| 'pinnedListUuid'
| 'pinnedListOrder'
>;
/**
* Type for updating multiple charts
*/
type UpdateMultipleChart = {
uuid: string;
} & Partial<CreateChart>;
/**
* Request to calculate total from a metric query
*/
type CalculateTotalFromQuery = {
metricQuery: MetricQuery;
explore: Explore;
fieldId: string;
};
/**
* Response containing calculated total
*/
type ApiCalculateTotalResponse = {
status: 'ok';
results: {
total: number | null;
};
};
/**
* Request to calculate subtotals from a metric query
*/
type CalculateSubtotalsFromQuery = {
metricQuery: MetricQuery;
explore: Explore;
fieldId: string;
};
/**
* Response containing calculated subtotals
*/
type ApiCalculateSubtotalsResponse = {
status: 'ok';
results: {
subtotals: Record<string, number | null>;
};
};
/**
* Type guard to check if a tile is a chart tile
*/
function isChartTile(tile: DashboardTile): tile is DashboardChartTile;
/**
* Type guard to check if a saved chart is from semantic layer
*/
function isSemanticLayerView(
chart: SavedChart
): chart is SavedChart & { semanticLayerView: string };
/**
* Type guard to check if series uses mixed chart types
*/
function isSeriesWithMixedChartTypes(series: any): boolean;
/**
* Type guard to check if a tile is a SQL runner chart tile
*/
function isSqlRunnerChartTile(tile: DashboardTile): tile is DashboardSqlChartTile;
/**
* Type guard to check if viz config has chart type
*/
function isVizConfigWithChartType(config: any): config is { type: ChartType };
/**
* Get the icon name for a chart kind
*/
function getChartIcon(chartKind: ChartKind | null | undefined): string;
/**
* Extract chart UUID from a dashboard tile
*/
function getChartTileUuidFromTile(
tile: DashboardChartTile | DashboardSqlChartTile
): string;
/**
* Get custom labels from table configuration
*/
function getCustomLabelsFromTableConfig(
tableConfig: TableChartConfig
): Record<string, string>;type TreeCreateSpace = CreateSpace & {
children?: TreeCreateSpace[];
groupAccess?: {
groupUuid: string;
role: SpaceMemberRole;
}[];
};Type for representing hierarchical space structures with nested children and group access configuration.
Types for exporting and importing charts and dashboards as code, enabling version control and programmatic management of analytics content.
/** Chart exported as code with version control support */
type ChartAsCode = Pick<
SavedChart,
| 'name'
| 'description'
| 'tableName'
| 'metricQuery'
| 'chartConfig'
| 'tableConfig'
| 'pivotConfig'
| 'slug'
| 'updatedAt'
> & {
dashboardSlug: string | undefined;
version: number;
spaceSlug: string;
downloadedAt?: Date;
};
/** Dashboard exported as code with version control support */
type DashboardAsCode = Pick<
Dashboard,
'name' | 'description' | 'updatedAt' | 'tabs' | 'slug'
> & {
tiles: DashboardTileAsCode[];
version: number;
spaceSlug: string;
downloadedAt?: Date;
filters: Omit<DashboardFilters, 'dimensions'> & {
dimensions: Omit<DashboardFilterRule, 'id'>[];
};
};
/** Dashboard tile in as-code format */
type DashboardTileAsCode = Omit<DashboardTile, 'properties' | 'uuid'> & {
uuid: DashboardTile['uuid'] | undefined;
tileSlug: string | undefined;
properties:
| Pick<
DashboardChartTileProperties['properties'],
'title' | 'hideTitle' | 'chartSlug' | 'chartName'
>
| DashboardMarkdownTileProperties['properties']
| DashboardLoomTileProperties['properties'];
};
/** Dashboard tile with slug identifier */
type DashboardTileWithSlug = DashboardTile & {
tileSlug: string | undefined;
};
/** API response for listing charts as code */
interface ApiChartAsCodeListResponse {
status: 'ok';
results: {
charts: ChartAsCode[];
languageMap: Array<PartialDeep<ChartAsCodeLanguageMap, { recurseIntoArrays: true }> | undefined> | undefined;
missingIds: string[];
total: number;
offset: number;
};
}
/** API response for upserting chart as code */
interface ApiChartAsCodeUpsertResponse {
status: 'ok';
results: PromotionChanges;
}
/** API response for listing dashboards as code */
interface ApiDashboardAsCodeListResponse {
status: 'ok';
results: {
dashboards: DashboardAsCode[];
languageMap: Array<PartialDeep<DashboardAsCodeLanguageMap, { recurseIntoArrays: true }> | undefined> | undefined;
missingIds: string[];
total: number;
offset: number;
};
}
/** API response for upserting dashboard as code */
interface ApiDashboardAsCodeUpsertResponse {
status: 'ok';
results: PromotionChanges;
}Install with Tessl CLI
npx tessl i tessl/npm-lightdash--commondocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10
scenario-11
scenario-12
scenario-13
scenario-14
scenario-15
scenario-16
scenario-17
scenario-18
scenario-19
scenario-20