CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-lightdash--common

Shared TypeScript library for the Lightdash platform containing common types, utilities, and business logic for analytics workflows

Overall
score

72%

Evaluation72%

1.09x

Agent success when using this tile

Overview
Eval results
Files

rename.mddocs/api/types/

Rename System Types

Types for renaming models and fields across Lightdash resources.

Capabilities

Rename Type Enum

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')
}

Name Changes

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;
};

API Rename Request Body

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;
};

API Rename Chart Request Body

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;
};

Rename Change Record

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;
};

API Rename Response

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[];
  };
};

API Rename Chart Response

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;
  };
};

API Rename Fields Response

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[];
    };
  };
};

Rename Resources Payload

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;
  };

Usage Examples

Renaming a Model

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}`);

Renaming a Field

// 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");
}

Fixing Charts After Rename

// 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}`);
}

Related Types

  • RequestMethod - HTTP methods for API requests
  • Job Types - Background job execution

Install with Tessl CLI

npx tessl i tessl/npm-lightdash--common

docs

api

index.md

tile.json