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
Types for renaming models and fields across Lightdash resources.
Specifies whether the rename operation targets a model or field.
enum RenameType {
MODEL = "model", // Table/model rename (e.g., 'payment')
FIELD = "field", // Field/column rename (e.g., 'id')
}Defines the from/to mapping for a rename operation including both identifiers and SQL references.
/**
* Describes a rename operation's source and destination names
*/
type NameChanges = {
/** Field ID or table prefix to be replaced (e.g., 'payment_customer_id') */
from: string;
/** New field ID or table prefix */
to: string;
/** Reference used in SQL strings (e.g., 'payment.customer_id') */
fromReference: string;
/** New reference used in SQL strings */
toReference: string;
/** Original field name */
fromFieldName: string | undefined;
/** New field name */
toFieldName: string | undefined;
};Request body for renaming a model or field in the project.
type ApiRenameBody = {
/** New name for the model or field */
to: string;
/** Current name of the model or field */
from: string;
/** Type of rename operation */
type: RenameType;
/** If true, performs validation without making changes */
dryRun?: boolean;
/** Model name (required when renaming a field) */
model?: string;
};Request body for fixing references in a specific chart after a rename.
type ApiRenameChartBody = {
/** Original name */
from: string;
/** New name */
to: string;
/** Type of rename operation */
type: RenameType;
/** If true, fixes all affected charts automatically */
fixAll?: boolean;
};Represents a single resource that was updated during a rename operation.
type RenameChange = {
/** UUID of the affected resource */
uuid: string;
/** Name/title of the affected resource */
name: string;
};Response from a rename operation showing all affected resources.
type ApiRenameResponse = {
status: "ok";
results: {
/** Charts affected by the rename */
charts: RenameChange[];
/** Dashboards affected by the rename */
dashboards: RenameChange[];
/** Alerts affected by the rename */
alerts: RenameChange[];
/** Scheduled deliveries affected by the rename */
dashboardSchedulers: RenameChange[];
};
};Response from a chart-specific rename fix operation.
type ApiRenameChartResponse = {
status: "ok";
results: {
/** Job ID for tracking the async rename operation, if applicable */
jobId: string | undefined;
};
};Response showing fields that would be affected by a rename operation.
type ApiRenameFieldsResponse = {
status: "ok";
results: {
/** Map of chart UUIDs to arrays of affected field IDs */
fields: {
[chartUuid: string]: string[];
};
};
};Internal payload type for rename operations in background jobs.
import { type RequestMethod, type TraceTaskBase } from "@lightdash/common";
type RenameResourcesPayload = TraceTaskBase &
ApiRenameBody & {
/** SQL reference for the original name (set when called from UI) */
fromReference?: string;
/** SQL reference for the new name */
toReference?: string;
/** Original field name */
fromFieldName?: string;
/** New field name */
toFieldName?: string;
/** HTTP method context for the rename request */
context: RequestMethod;
};import { type ApiRenameBody, RenameType } from "@lightdash/common";
// Rename a model (table) from 'old_model' to 'new_model'
const renameRequest: ApiRenameBody = {
from: "old_model",
to: "new_model",
type: RenameType.MODEL,
dryRun: false, // Set to true to preview changes
};
// Response shows all affected resources
const response: ApiRenameResponse = await renameModel(renameRequest);
console.log(`Affected charts: ${response.results.charts.length}`);
console.log(`Affected dashboards: ${response.results.dashboards.length}`);// Rename a field in a specific model
const renameFieldRequest: ApiRenameBody = {
from: "old_field_name",
to: "new_field_name",
type: RenameType.FIELD,
model: "customers", // Required for field renames
dryRun: false,
};
// Check what would be affected first with dry run
const dryRunResponse = await renameField({ ...renameFieldRequest, dryRun: true });
if (dryRunResponse.results.charts.length > 0) {
console.log("This rename will affect existing charts");
}// Fix a specific chart after a model/field rename
const chartFixRequest: ApiRenameChartBody = {
from: "old_name",
to: "new_name",
type: RenameType.FIELD,
fixAll: true, // Automatically fix all references
};
const chartResponse: ApiRenameChartResponse = await fixChartReferences(chartFixRequest);
if (chartResponse.results.jobId) {
console.log(`Rename job started: ${chartResponse.results.jobId}`);
}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