tessl install tessl/npm-lightdash--common@0.2231.5Shared TypeScript library for the Lightdash platform containing common types, utilities, and business logic for analytics workflows
Agent Success
Agent success rate when using this tile
72%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.09x
Baseline
Agent success rate without this tile
66%
Build a utility that resolves variable references in dimension SQL expressions for a Business Intelligence system. The utility should handle cross-table field references and validate circular dependencies.
Resolves field references in SQL expressions using the ${table.field} syntax.
"CONCAT(${users.first_name}, ' ', ${users.last_name})" and available fields, returns SQL with resolved table references @test"${orders.amount} * 1.1" with a numeric field reference, returns SQL with the correct table reference resolved @test"SELECT 1", returns the SQL unchanged @testResolves references that span multiple tables in a data model.
"${orders.total}" that references a field from the orders table when current table is users, resolves the reference correctly @test"${orders.amount} + ${payments.amount}", resolves both references correctly @testPrevents infinite loops when dimensions reference each other.
Validates references and provides clear error messages.
"${users.invalid_field}", throws an error indicating the field does not exist @test"${invalid_table.field}", throws an error indicating the table does not exist @test@generates
interface Field {
name: string;
table: string;
sql?: string;
}
interface DimensionContext {
fields: Map<string, Field>;
currentTable: string;
}
/**
* Resolves variable references in dimension SQL expressions.
*
* @param sql - SQL expression containing variable references in ${table.field} format
* @param context - Context containing available fields and current table
* @param visitedFields - Set of field references visited (used for circular dependency detection)
* @returns Resolved SQL expression with variable references replaced
* @throws Error if circular dependency detected or invalid reference found
*/
export function resolveDimensionReferences(
sql: string,
context: DimensionContext,
visitedFields?: Set<string>
): string;
/**
* Extracts all variable references from a SQL expression.
*
* @param sql - SQL expression to parse
* @returns Array of references in format "table.field"
*/
export function extractReferences(sql: string): string[];Provides core types and utilities for the Lightdash BI platform.
@satisfied-by
docs
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