This guide shows the most common import patterns for @lightdash/common. For complete API signatures, see the API documentation.
import {
type MetricQuery,
type Explore,
FilterOperator,
UnitOfTime,
getFields,
getDimensions,
getMetrics,
} from "@lightdash/common";Use for: Building and executing queries against explores.
import {
type Dashboard,
type SavedChart,
ChartKind,
type ChartConfig,
type DashboardTile,
} from "@lightdash/common";Use for: Creating and managing dashboards and chart configurations.
import {
formatItemValue,
formatDate,
formatTimestamp,
formatNumberValue,
type CustomFormat,
} from "@lightdash/common";Use for: Formatting query results for display.
import {
defineUserAbility,
type LightdashUser,
type ProjectMemberProfile,
type MemberAbility,
} from "@lightdash/common";Use for: Checking user permissions and access control.
import { ExploreCompiler, type UncompiledExplore, type Explore } from "@lightdash/common";Use for: Compiling dbt models into Lightdash explores.
import {
type WarehouseClient,
WarehouseTypes,
type WarehouseCredentials,
type Project,
} from "@lightdash/common";Use for: Connecting to and querying data warehouses.
import {
CartesianChartDataModel,
PieChartDataModel,
ChartKind,
type VizCartesianChartOptions,
} from "@lightdash/common";Use for: Creating chart visualizations with ECharts.
import {
type Filters,
type FilterGroup,
type FilterRule,
FilterOperator,
isFilterGroup,
} from "@lightdash/common";Use for: Building and managing query filters.
import {
getItemMap,
getFieldMap,
findFieldByIdInExplore,
getItemId,
type ItemsMap,
} from "@lightdash/common";Use for: Working with explore fields and items.
import { validateEmail, validatePassword, isDimension, isMetric, isField } from "@lightdash/common";Use for: Validating data and narrowing TypeScript types.
All essential types and utilities in one place:
import {
// Data Modeling
type Explore,
type MetricQuery,
type Field,
type Dimension,
type Metric,
type CompiledField,
type CompiledDimension,
type CompiledMetric,
type Table,
type CompiledTable,
// Filtering
type Filters,
type FilterGroup,
type FilterRule,
FilterOperator,
// Dashboards & Charts
type Dashboard,
type SavedChart,
type ChartConfig,
ChartKind,
// Warehouses
type WarehouseClient,
type WarehouseCredentials,
WarehouseTypes,
// Projects
type Project,
type Space,
ProjectType,
// Compiler
ExploreCompiler,
// Utilities
getFields,
getDimensions,
getMetrics,
getVisibleFields,
findFieldByIdInExplore,
getFieldMap,
getItemMap,
formatItemValue,
formatDate,
formatTimestamp,
formatNumberValue,
validateEmail,
validatePassword,
defineUserAbility,
CartesianChartDataModel,
PieChartDataModel,
TableDataModel,
} from "@lightdash/common";For CommonJS environments (Node.js with require):
// Note: TypeScript type imports are not available in CommonJS
// Use JSDoc comments for type hints if needed
const {
// Compiler
ExploreCompiler,
// Utilities
getFields,
getDimensions,
getMetrics,
formatItemValue,
validateEmail,
defineUserAbility,
// Data Models
CartesianChartDataModel,
PieChartDataModel,
TableDataModel,
// Enums
FilterOperator,
WarehouseTypes,
ChartKind,
// JSON Schemas
chartAsCodeSchema,
dashboardAsCodeSchema,
// Constants
JWT_HEADER_NAME,
} = require("@lightdash/common");Note: Type definitions are only available when using TypeScript or ESM imports. In CommonJS, types must be specified through JSDoc comments or TypeScript declaration files.