@lightdash/common 0.1462.2 → 0.1464.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/compiler/exploreCompiler.d.ts +5 -2
  2. package/dist/compiler/exploreCompiler.js +9 -1
  3. package/dist/compiler/exploreCompiler.mock.js +40 -1
  4. package/dist/compiler/translator.d.ts +3 -2
  5. package/dist/compiler/translator.js +26 -6
  6. package/dist/compiler/translator.mock.js +27 -0
  7. package/dist/compiler/translator.test.js +19 -20
  8. package/dist/dbt/schemas/lightdashMetadata.json +1 -1
  9. package/dist/dbt/validation.d.ts +2 -1
  10. package/dist/index.d.ts +12 -7
  11. package/dist/index.js +8 -3
  12. package/dist/schemas/json/lightdash-dbt-2.0.json +63 -0
  13. package/dist/schemas/json/lightdash-project-config-1.0.json +17 -0
  14. package/dist/types/any.d.ts +7 -0
  15. package/dist/types/any.js +2 -0
  16. package/dist/types/api/errors.d.ts +2 -1
  17. package/dist/types/dbt.d.ts +21 -11
  18. package/dist/types/dbt.js +14 -3
  19. package/dist/types/errors.d.ts +18 -17
  20. package/dist/types/explore.d.ts +4 -0
  21. package/dist/types/field.d.ts +11 -6
  22. package/dist/types/field.js +3 -1
  23. package/dist/types/field.test.js +1 -0
  24. package/dist/types/filter.d.ts +4 -3
  25. package/dist/types/filterGrammar.d.ts +3 -2
  26. package/dist/types/lightdashProjectConfig.d.ts +8 -0
  27. package/dist/types/lightdashProjectConfig.js +6 -0
  28. package/dist/types/metricQuery.d.ts +8 -7
  29. package/dist/types/scheduler.d.ts +3 -2
  30. package/dist/types/user.d.ts +3 -2
  31. package/dist/types/warehouse.d.ts +5 -4
  32. package/dist/utils/filters.d.ts +6 -5
  33. package/dist/utils/formatting.js +2 -1
  34. package/dist/utils/formatting.test.js +5 -1
  35. package/dist/utils/item.d.ts +3 -0
  36. package/dist/utils/loadLightdashProjectConfig.d.ts +2 -0
  37. package/dist/utils/loadLightdashProjectConfig.js +26 -0
  38. package/dist/utils/metricsExplorer.d.ts +3 -2
  39. package/dist/utils/virtualView.js +1 -0
  40. package/dist/visualizations/CartesianChartDataModel.d.ts +4 -3
  41. package/dist/visualizations/PieChartDataModel.d.ts +2 -1
  42. package/dist/visualizations/TableDataModel.d.ts +2 -1
  43. package/package.json +4 -1
@@ -1,7 +1,8 @@
1
- import { type SupportedDbtAdapter } from '../types/dbt';
1
+ import { type DbtRawModelNode, type SupportedDbtAdapter } from '../types/dbt';
2
2
  import { type CompiledExploreJoin, type CompiledTable, type Explore, type ExploreJoin, type Table } from '../types/explore';
3
3
  import { type CompiledCustomDimension, type CompiledCustomSqlDimension, type CompiledDimension, type CompiledMetric, type CustomDimension, type CustomSqlDimension, type Dimension, type Metric } from '../types/field';
4
4
  import { type WarehouseClient } from '../types/warehouse';
5
+ import { type LightdashProjectConfig } from '../types/lightdashProjectConfig';
5
6
  import { type DateGranularity } from '../types/timeFrames';
6
7
  export declare const lightdashVariablePattern: RegExp;
7
8
  type Reference = {
@@ -24,11 +25,13 @@ export type UncompiledExplore = {
24
25
  ymlPath?: string;
25
26
  sqlPath?: string;
26
27
  joinAliases?: Record<string, Record<string, string>>;
28
+ spotlightConfig?: LightdashProjectConfig['spotlight'];
29
+ meta: DbtRawModelNode['meta'];
27
30
  };
28
31
  export declare class ExploreCompiler {
29
32
  private readonly warehouseClient;
30
33
  constructor(warehouseClient: WarehouseClient);
31
- compileExplore({ name, label, tags, baseTable, joinedTables, tables, targetDatabase, groupLabel, warehouse, ymlPath, sqlPath, }: UncompiledExplore): Explore;
34
+ compileExplore({ name, label, tags, baseTable, joinedTables, tables, targetDatabase, groupLabel, warehouse, ymlPath, sqlPath, spotlightConfig, meta, }: UncompiledExplore): Explore;
32
35
  compileTable(table: Table, tables: Record<string, Table>): CompiledTable;
33
36
  compileMetric(metric: Metric, tables: Record<string, Table>): CompiledMetric;
34
37
  compileMetricSql(metric: Metric, tables: Record<string, Table>): {
@@ -33,7 +33,7 @@ class ExploreCompiler {
33
33
  constructor(warehouseClient) {
34
34
  this.warehouseClient = warehouseClient;
35
35
  }
36
- compileExplore({ name, label, tags, baseTable, joinedTables, tables, targetDatabase, groupLabel, warehouse, ymlPath, sqlPath, }) {
36
+ compileExplore({ name, label, tags, baseTable, joinedTables, tables, targetDatabase, groupLabel, warehouse, ymlPath, sqlPath, spotlightConfig, meta, }) {
37
37
  // Check that base table and joined tables exist
38
38
  if (!tables[baseTable]) {
39
39
  throw new errors_1.CompileError(`Failed to compile explore "${name}". Tried to find base table but cannot find table with name "${baseTable}"`, {});
@@ -118,7 +118,15 @@ class ExploreCompiler {
118
118
  [tableName]: this.compileTable(includedTables[tableName], includedTables),
119
119
  }), {});
120
120
  const compiledJoins = joinedTables.map((j) => this.compileJoin(j, includedTables));
121
+ const spotlightVisibility = meta.spotlight?.visibility ?? spotlightConfig?.default_visibility;
121
122
  return {
123
+ ...(spotlightVisibility !== undefined
124
+ ? {
125
+ spotlight: {
126
+ visibility: spotlightVisibility,
127
+ },
128
+ }
129
+ : {}),
122
130
  name,
123
131
  label,
124
132
  tags,
@@ -5,6 +5,7 @@ exports.expectedCompiledCustomSqlDimensionWithReferences = void 0;
5
5
  const dbt_1 = require("../types/dbt");
6
6
  const field_1 = require("../types/field");
7
7
  const filter_1 = require("../types/filter");
8
+ const lightdashProjectConfig_1 = require("../types/lightdashProjectConfig");
8
9
  const timeFrames_1 = require("../types/timeFrames");
9
10
  exports.warehouseClientMock = {
10
11
  credentials: {},
@@ -78,6 +79,9 @@ exports.exploreBase = {
78
79
  name: '',
79
80
  label: '',
80
81
  tags: [],
82
+ spotlight: {
83
+ visibility: 'show',
84
+ },
81
85
  baseTable: 'a',
82
86
  joinedTables: [],
83
87
  tables: {},
@@ -88,6 +92,8 @@ exports.exploreBase = {
88
92
  };
89
93
  exports.exploreOneEmptyTable = {
90
94
  ...exports.exploreBase,
95
+ spotlightConfig: lightdashProjectConfig_1.DEFAULT_SPOTLIGHT_CONFIG,
96
+ meta: {},
91
97
  tables: {
92
98
  a: {
93
99
  name: 'a',
@@ -125,9 +131,13 @@ exports.exploreOneEmptyTableCompiled = {
125
131
  };
126
132
  exports.exploreMissingBaseTable = {
127
133
  ...exports.exploreBase,
134
+ spotlightConfig: lightdashProjectConfig_1.DEFAULT_SPOTLIGHT_CONFIG,
135
+ meta: {},
128
136
  };
129
137
  exports.exploreMissingJoinTable = {
130
138
  ...exports.exploreBase,
139
+ spotlightConfig: lightdashProjectConfig_1.DEFAULT_SPOTLIGHT_CONFIG,
140
+ meta: {},
131
141
  joinedTables: [
132
142
  {
133
143
  table: 'b',
@@ -152,6 +162,8 @@ exports.exploreMissingJoinTable = {
152
162
  };
153
163
  exports.exploreCircularDimensionReference = {
154
164
  ...exports.exploreBase,
165
+ spotlightConfig: lightdashProjectConfig_1.DEFAULT_SPOTLIGHT_CONFIG,
166
+ meta: {},
155
167
  tables: {
156
168
  a: {
157
169
  name: 'a',
@@ -197,6 +209,8 @@ exports.exploreCircularDimensionShortReference = {
197
209
  };
198
210
  exports.exploreCircularMetricReference = {
199
211
  ...exports.exploreBase,
212
+ spotlightConfig: lightdashProjectConfig_1.DEFAULT_SPOTLIGHT_CONFIG,
213
+ meta: {},
200
214
  tables: {
201
215
  a: {
202
216
  name: 'a',
@@ -254,6 +268,8 @@ exports.exploreCircularMetricShortReference = {
254
268
  };
255
269
  exports.exploreTableSelfReference = {
256
270
  ...exports.exploreBase,
271
+ spotlightConfig: lightdashProjectConfig_1.DEFAULT_SPOTLIGHT_CONFIG,
272
+ meta: {},
257
273
  tables: {
258
274
  a: {
259
275
  name: 'a',
@@ -284,6 +300,8 @@ exports.exploreTableSelfReference = {
284
300
  };
285
301
  exports.exploreTableSelfReferenceSqlWhere = {
286
302
  ...exports.exploreBase,
303
+ spotlightConfig: lightdashProjectConfig_1.DEFAULT_SPOTLIGHT_CONFIG,
304
+ meta: {},
287
305
  tables: {
288
306
  a: {
289
307
  name: 'a',
@@ -380,6 +398,8 @@ exports.exploreTableSelfReferenceCompiledSqlWhere = {
380
398
  };
381
399
  exports.exploreReferenceDimension = {
382
400
  ...exports.exploreBase,
401
+ spotlightConfig: lightdashProjectConfig_1.DEFAULT_SPOTLIGHT_CONFIG,
402
+ meta: {},
383
403
  tables: {
384
404
  a: {
385
405
  name: 'a',
@@ -467,6 +487,8 @@ exports.exploreReferenceDimensionCompiled = {
467
487
  };
468
488
  exports.exploreComplexReference = {
469
489
  ...exports.exploreBase,
490
+ spotlightConfig: lightdashProjectConfig_1.DEFAULT_SPOTLIGHT_CONFIG,
491
+ meta: {},
470
492
  tables: {
471
493
  a: {
472
494
  name: 'a',
@@ -606,6 +628,8 @@ exports.exploreComplexReferenceCompiled = {
606
628
  };
607
629
  exports.simpleJoinedExplore = {
608
630
  ...exports.exploreBase,
631
+ spotlightConfig: lightdashProjectConfig_1.DEFAULT_SPOTLIGHT_CONFIG,
632
+ meta: {},
609
633
  joinedTables: [
610
634
  {
611
635
  table: 'b',
@@ -1332,6 +1356,8 @@ exports.compiledJoinedExploreWithJoinAliasAndSubsetOfFieldsThatDontIncludeSqlFie
1332
1356
  };
1333
1357
  exports.exploreWithMetricNumber = {
1334
1358
  ...exports.exploreBase,
1359
+ spotlightConfig: lightdashProjectConfig_1.DEFAULT_SPOTLIGHT_CONFIG,
1360
+ meta: {},
1335
1361
  tables: {
1336
1362
  a: {
1337
1363
  name: 'a',
@@ -1386,7 +1412,18 @@ exports.exploreWithMetricNumber = {
1386
1412
  },
1387
1413
  };
1388
1414
  exports.exploreWithMetricNumberCompiled = {
1389
- ...exports.exploreWithMetricNumber,
1415
+ name: exports.exploreWithMetricNumber.name,
1416
+ label: exports.exploreWithMetricNumber.label,
1417
+ baseTable: exports.exploreWithMetricNumber.baseTable,
1418
+ tags: exports.exploreWithMetricNumber.tags,
1419
+ targetDatabase: exports.exploreWithMetricNumber.targetDatabase,
1420
+ warehouse: exports.exploreWithMetricNumber.warehouse,
1421
+ ymlPath: exports.exploreWithMetricNumber.ymlPath,
1422
+ sqlPath: exports.exploreWithMetricNumber.sqlPath,
1423
+ groupLabel: exports.exploreWithMetricNumber.groupLabel,
1424
+ spotlight: {
1425
+ visibility: 'show',
1426
+ },
1390
1427
  joinedTables: [],
1391
1428
  tables: {
1392
1429
  a: {
@@ -1567,6 +1604,8 @@ exports.tablesWithMetricsWithFilters = {
1567
1604
  };
1568
1605
  exports.exploreWithRequiredAttributes = {
1569
1606
  ...exports.exploreBase,
1607
+ spotlightConfig: lightdashProjectConfig_1.DEFAULT_SPOTLIGHT_CONFIG,
1608
+ meta: {},
1570
1609
  joinedTables: [
1571
1610
  {
1572
1611
  table: 'b',
@@ -1,10 +1,11 @@
1
1
  import { SupportedDbtAdapter, type DbtMetric, type DbtModelNode } from '../types/dbt';
2
2
  import { type Explore, type ExploreError, type Table } from '../types/explore';
3
3
  import { DimensionType } from '../types/field';
4
+ import { type LightdashProjectConfig } from '../types/lightdashProjectConfig';
4
5
  import { type WarehouseClient } from '../types/warehouse';
5
6
  import { type WeekDay } from '../utils/timeFrames';
6
- export declare const convertTable: (adapterType: SupportedDbtAdapter, model: DbtModelNode, dbtMetrics: DbtMetric[], startOfWeek?: WeekDay | null) => Omit<Table, 'lineageGraph'>;
7
- export declare const convertExplores: (models: DbtModelNode[], loadSources: boolean, adapterType: SupportedDbtAdapter, metrics: DbtMetric[], warehouseClient: WarehouseClient) => Promise<(Explore | ExploreError)[]>;
7
+ export declare const convertTable: (adapterType: SupportedDbtAdapter, model: DbtModelNode, dbtMetrics: DbtMetric[], spotlightConfig: LightdashProjectConfig['spotlight'], startOfWeek?: WeekDay | null) => Omit<Table, 'lineageGraph'>;
8
+ export declare const convertExplores: (models: DbtModelNode[], loadSources: boolean, adapterType: SupportedDbtAdapter, metrics: DbtMetric[], warehouseClient: WarehouseClient, lightdashProjectConfig: LightdashProjectConfig) => Promise<(Explore | ExploreError)[]>;
8
9
  export declare const attachTypesToModels: (models: DbtModelNode[], warehouseCatalog: {
9
10
  [database: string]: {
10
11
  [schema: string]: {
@@ -118,7 +118,7 @@ const generateTableLineage = (model, depGraph) => {
118
118
  .map((d) => depGraph.getNodeData(d)),
119
119
  }), {});
120
120
  };
121
- const convertDbtMetricToLightdashMetric = (metric, tableName, tableLabel) => {
121
+ const convertDbtMetricToLightdashMetric = (metric, tableName, tableLabel, spotlightConfig) => {
122
122
  let sql;
123
123
  let type;
124
124
  if (metric.calculation_method === 'derived') {
@@ -161,6 +161,7 @@ const convertDbtMetricToLightdashMetric = (metric, tableName, tableLabel) => {
161
161
  sql = `CASE WHEN ${filterSql} THEN ${sql} ELSE NULL END`;
162
162
  }
163
163
  const groups = (0, dbt_1.convertToGroups)(metric.meta?.groups, metric.meta?.group_label);
164
+ const spotlightVisibility = spotlightConfig?.default_visibility;
164
165
  return {
165
166
  fieldType: field_1.FieldType.METRIC,
166
167
  type,
@@ -188,9 +189,16 @@ const convertDbtMetricToLightdashMetric = (metric, tableName, tableLabel) => {
188
189
  : [metric.meta.tags],
189
190
  }
190
191
  : {}),
192
+ ...(spotlightVisibility !== undefined
193
+ ? {
194
+ spotlight: {
195
+ visibility: spotlightVisibility,
196
+ },
197
+ }
198
+ : {}),
191
199
  };
192
200
  };
193
- const convertTable = (adapterType, model, dbtMetrics, startOfWeek) => {
201
+ const convertTable = (adapterType, model, dbtMetrics, spotlightConfig, startOfWeek) => {
194
202
  const meta = model.config?.meta || model.meta; // Config block takes priority, then meta block
195
203
  const tableLabel = meta.label || (0, field_1.friendlyName)(model.name);
196
204
  const [dimensions, metrics] = Object.values(model.columns).reduce(([prevDimensions, prevMetrics], column, index) => {
@@ -264,7 +272,12 @@ const convertTable = (adapterType, model, dbtMetrics, startOfWeek) => {
264
272
  name,
265
273
  metric,
266
274
  tableLabel,
267
- requiredAttributes: dimension.requiredAttributes, // TODO Join dimension required_attributes with metric required_attributes
275
+ requiredAttributes: dimension.requiredAttributes,
276
+ spotlightConfig: {
277
+ ...spotlightConfig,
278
+ default_visibility: model.meta.spotlight?.visibility ??
279
+ spotlightConfig.default_visibility,
280
+ },
268
281
  }),
269
282
  ]));
270
283
  return [
@@ -283,11 +296,16 @@ const convertTable = (adapterType, model, dbtMetrics, startOfWeek) => {
283
296
  name,
284
297
  metric,
285
298
  tableLabel,
299
+ spotlightConfig: {
300
+ ...spotlightConfig,
301
+ default_visibility: model.meta.spotlight?.visibility ??
302
+ spotlightConfig?.default_visibility,
303
+ },
286
304
  }),
287
305
  ]));
288
306
  const convertedDbtMetrics = Object.fromEntries(dbtMetrics.map((metric) => [
289
307
  metric.name,
290
- convertDbtMetricToLightdashMetric(metric, model.name, tableLabel),
308
+ convertDbtMetricToLightdashMetric(metric, model.name, tableLabel, spotlightConfig),
291
309
  ]));
292
310
  const allMetrics = Object.values({
293
311
  ...convertedDbtMetrics,
@@ -374,7 +392,7 @@ const modelCanUseMetric = (metricName, modelName, metrics) => {
374
392
  }
375
393
  return false;
376
394
  };
377
- const convertExplores = async (models, loadSources, adapterType, metrics, warehouseClient) => {
395
+ const convertExplores = async (models, loadSources, adapterType, metrics, warehouseClient, lightdashProjectConfig) => {
378
396
  const tableLineage = translateDbtModelsToTableLineage(models);
379
397
  const [tables, exploreErrors] = models.reduce(([accTables, accErrors], model) => {
380
398
  const meta = model.config?.meta || model.meta; // Config block takes priority, then meta block
@@ -382,7 +400,7 @@ const convertExplores = async (models, loadSources, adapterType, metrics, wareho
382
400
  try {
383
401
  // base dimensions and metrics
384
402
  const tableMetrics = metrics.filter((metric) => modelCanUseMetric(metric.name, model.name, metrics));
385
- const table = (0, exports.convertTable)(adapterType, model, tableMetrics, warehouseClient.getStartOfWeek());
403
+ const table = (0, exports.convertTable)(adapterType, model, tableMetrics, lightdashProjectConfig.spotlight, warehouseClient.getStartOfWeek());
386
404
  // add sources
387
405
  if (loadSources && model.patch_path !== null) {
388
406
  throw new Error('Not Implemented');
@@ -441,6 +459,8 @@ const convertExplores = async (models, loadSources, adapterType, metrics, wareho
441
459
  warehouse: model.config?.snowflake_warehouse,
442
460
  ymlPath: model.patch_path?.split('://')?.[1],
443
461
  sqlPath: model.path,
462
+ spotlightConfig: lightdashProjectConfig.spotlight,
463
+ meta,
444
464
  });
445
465
  }
446
466
  catch (e) {
@@ -317,6 +317,9 @@ exports.LIGHTDASH_TABLE_WITH_GROUP_BLOCK = {
317
317
  table: 'myTable',
318
318
  tableLabel: 'My table',
319
319
  type: field_1.MetricType.COUNT_DISTINCT,
320
+ spotlight: {
321
+ visibility: 'show',
322
+ },
320
323
  },
321
324
  },
322
325
  groupDetails: {
@@ -394,6 +397,9 @@ exports.LIGHTDASH_TABLE_WITH_DBT_METRICS = {
394
397
  groups: [],
395
398
  filters: [],
396
399
  index: 0,
400
+ spotlight: {
401
+ visibility: 'show',
402
+ },
397
403
  },
398
404
  dbt_metric_2: {
399
405
  description: 'Description',
@@ -415,6 +421,9 @@ exports.LIGHTDASH_TABLE_WITH_DBT_METRICS = {
415
421
  groups: [],
416
422
  filters: [],
417
423
  index: 1,
424
+ spotlight: {
425
+ visibility: 'show',
426
+ },
418
427
  },
419
428
  dbt_metric_3: {
420
429
  description: 'Description',
@@ -436,6 +445,9 @@ exports.LIGHTDASH_TABLE_WITH_DBT_METRICS = {
436
445
  groups: [],
437
446
  filters: [],
438
447
  index: 2,
448
+ spotlight: {
449
+ visibility: 'show',
450
+ },
439
451
  },
440
452
  dbt_metric_4: {
441
453
  description: 'Description',
@@ -457,6 +469,9 @@ exports.LIGHTDASH_TABLE_WITH_DBT_METRICS = {
457
469
  groups: [],
458
470
  filters: [],
459
471
  index: 3,
472
+ spotlight: {
473
+ visibility: 'show',
474
+ },
460
475
  },
461
476
  dbt_metric_5: {
462
477
  description: 'Description',
@@ -478,6 +493,9 @@ exports.LIGHTDASH_TABLE_WITH_DBT_METRICS = {
478
493
  groups: [],
479
494
  filters: [],
480
495
  index: 4,
496
+ spotlight: {
497
+ visibility: 'show',
498
+ },
481
499
  },
482
500
  },
483
501
  };
@@ -504,6 +522,9 @@ exports.LIGHTDASH_TABLE_WITH_DBT_V9_METRICS = {
504
522
  groups: [],
505
523
  filters: [],
506
524
  index: 0,
525
+ spotlight: {
526
+ visibility: 'show',
527
+ },
507
528
  },
508
529
  },
509
530
  };
@@ -626,6 +647,9 @@ exports.LIGHTDASH_TABLE_WITH_METRICS = {
626
647
  index: 0,
627
648
  dimensionReference: 'myTable_user_id',
628
649
  requiredAttributes: undefined,
650
+ spotlight: {
651
+ visibility: 'show',
652
+ },
629
653
  },
630
654
  total_num_participating_athletes: {
631
655
  fieldType: field_1.FieldType.METRIC,
@@ -649,6 +673,9 @@ exports.LIGHTDASH_TABLE_WITH_METRICS = {
649
673
  index: 1,
650
674
  dimensionReference: 'myTable_num_participating_athletes',
651
675
  requiredAttributes: undefined,
676
+ spotlight: {
677
+ visibility: 'show',
678
+ },
652
679
  },
653
680
  },
654
681
  };
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const dbt_1 = require("../types/dbt");
4
+ const lightdashProjectConfig_1 = require("../types/lightdashProjectConfig");
4
5
  const translator_1 = require("./translator");
5
6
  const translator_mock_1 = require("./translator.mock");
6
7
  describe('attachTypesToModels', () => {
@@ -26,7 +27,7 @@ describe('attachTypesToModels', () => {
26
27
  });
27
28
  describe('convert tables from dbt models', () => {
28
29
  it('should convert dbt model without metrics to Lightdash table without autogenerated metrics', () => {
29
- expect((0, translator_1.convertTable)(dbt_1.SupportedDbtAdapter.BIGQUERY, translator_mock_1.MODEL_WITH_NO_METRICS, [])).toStrictEqual(translator_mock_1.LIGHTDASH_TABLE_WITHOUT_AUTO_METRICS);
30
+ expect((0, translator_1.convertTable)(dbt_1.SupportedDbtAdapter.BIGQUERY, translator_mock_1.MODEL_WITH_NO_METRICS, [], lightdashProjectConfig_1.DEFAULT_SPOTLIGHT_CONFIG)).toStrictEqual(translator_mock_1.LIGHTDASH_TABLE_WITHOUT_AUTO_METRICS);
30
31
  });
31
32
  it('should convert dbt model with dbt metrics', () => {
32
33
  expect((0, translator_1.convertTable)(dbt_1.SupportedDbtAdapter.BIGQUERY, translator_mock_1.MODEL_WITH_NO_METRICS, [
@@ -35,56 +36,54 @@ describe('convert tables from dbt models', () => {
35
36
  translator_mock_1.DBT_METRIC_WITH_CUSTOM_SQL,
36
37
  translator_mock_1.DBT_METRIC_WITH_FILTER,
37
38
  translator_mock_1.DBT_METRIC_DERIVED,
38
- ])).toStrictEqual(translator_mock_1.LIGHTDASH_TABLE_WITH_DBT_METRICS);
39
+ ], lightdashProjectConfig_1.DEFAULT_SPOTLIGHT_CONFIG)).toStrictEqual(translator_mock_1.LIGHTDASH_TABLE_WITH_DBT_METRICS);
39
40
  // dbt 1.5 metrics
40
- expect((0, translator_1.convertTable)(dbt_1.SupportedDbtAdapter.BIGQUERY, translator_mock_1.MODEL_WITH_NO_METRICS, [
41
- translator_mock_1.DBT_V9_METRIC,
42
- ])).toStrictEqual(translator_mock_1.LIGHTDASH_TABLE_WITH_DBT_V9_METRICS);
41
+ expect((0, translator_1.convertTable)(dbt_1.SupportedDbtAdapter.BIGQUERY, translator_mock_1.MODEL_WITH_NO_METRICS, [translator_mock_1.DBT_V9_METRIC], lightdashProjectConfig_1.DEFAULT_SPOTLIGHT_CONFIG)).toStrictEqual(translator_mock_1.LIGHTDASH_TABLE_WITH_DBT_V9_METRICS);
43
42
  });
44
43
  it('should convert dbt model with metrics in meta', () => {
45
- expect((0, translator_1.convertTable)(dbt_1.SupportedDbtAdapter.BIGQUERY, translator_mock_1.MODEL_WITH_METRIC, [])).toStrictEqual(translator_mock_1.LIGHTDASH_TABLE_WITH_METRICS);
44
+ expect((0, translator_1.convertTable)(dbt_1.SupportedDbtAdapter.BIGQUERY, translator_mock_1.MODEL_WITH_METRIC, [], lightdashProjectConfig_1.DEFAULT_SPOTLIGHT_CONFIG)).toStrictEqual(translator_mock_1.LIGHTDASH_TABLE_WITH_METRICS);
46
45
  });
47
46
  it('should convert dbt model with dimension with default time intervals bigquery', () => {
48
- expect((0, translator_1.convertTable)(dbt_1.SupportedDbtAdapter.BIGQUERY, translator_mock_1.MODEL_WITH_DEFAULT_TIME_INTERVAL_DIMENSIONS, [])).toStrictEqual(translator_mock_1.LIGHTDASH_TABLE_WITH_DEFAULT_TIME_INTERVAL_DIMENSIONS_BIGQUERY);
47
+ expect((0, translator_1.convertTable)(dbt_1.SupportedDbtAdapter.BIGQUERY, translator_mock_1.MODEL_WITH_DEFAULT_TIME_INTERVAL_DIMENSIONS, [], lightdashProjectConfig_1.DEFAULT_SPOTLIGHT_CONFIG)).toStrictEqual(translator_mock_1.LIGHTDASH_TABLE_WITH_DEFAULT_TIME_INTERVAL_DIMENSIONS_BIGQUERY);
49
48
  });
50
49
  it('should convert dbt model with dimension with no time intervals bigquery', () => {
51
- expect((0, translator_1.convertTable)(dbt_1.SupportedDbtAdapter.BIGQUERY, translator_mock_1.MODEL_WITH_NO_TIME_INTERVAL_DIMENSIONS, [])).toStrictEqual(translator_mock_1.LIGHTDASH_TABLE_WITH_DEFAULT_TIME_INTERVAL_DIMENSIONS_BIGQUERY);
50
+ expect((0, translator_1.convertTable)(dbt_1.SupportedDbtAdapter.BIGQUERY, translator_mock_1.MODEL_WITH_NO_TIME_INTERVAL_DIMENSIONS, [], lightdashProjectConfig_1.DEFAULT_SPOTLIGHT_CONFIG)).toStrictEqual(translator_mock_1.LIGHTDASH_TABLE_WITH_DEFAULT_TIME_INTERVAL_DIMENSIONS_BIGQUERY);
52
51
  });
53
52
  it('should convert dbt model with dimension with default time intervals snowflake', () => {
54
- expect((0, translator_1.convertTable)(dbt_1.SupportedDbtAdapter.SNOWFLAKE, translator_mock_1.MODEL_WITH_DEFAULT_TIME_INTERVAL_DIMENSIONS, [])).toStrictEqual(translator_mock_1.LIGHTDASH_TABLE_WITH_DEFAULT_TIME_INTERVAL_DIMENSIONS_SNOWFLAKE);
53
+ expect((0, translator_1.convertTable)(dbt_1.SupportedDbtAdapter.SNOWFLAKE, translator_mock_1.MODEL_WITH_DEFAULT_TIME_INTERVAL_DIMENSIONS, [], lightdashProjectConfig_1.DEFAULT_SPOTLIGHT_CONFIG)).toStrictEqual(translator_mock_1.LIGHTDASH_TABLE_WITH_DEFAULT_TIME_INTERVAL_DIMENSIONS_SNOWFLAKE);
55
54
  });
56
55
  it('should convert dbt model with dimension with no time intervals snowflake', () => {
57
- expect((0, translator_1.convertTable)(dbt_1.SupportedDbtAdapter.SNOWFLAKE, translator_mock_1.MODEL_WITH_NO_TIME_INTERVAL_DIMENSIONS, [])).toStrictEqual(translator_mock_1.LIGHTDASH_TABLE_WITH_DEFAULT_TIME_INTERVAL_DIMENSIONS_SNOWFLAKE);
56
+ expect((0, translator_1.convertTable)(dbt_1.SupportedDbtAdapter.SNOWFLAKE, translator_mock_1.MODEL_WITH_NO_TIME_INTERVAL_DIMENSIONS, [], lightdashProjectConfig_1.DEFAULT_SPOTLIGHT_CONFIG)).toStrictEqual(translator_mock_1.LIGHTDASH_TABLE_WITH_DEFAULT_TIME_INTERVAL_DIMENSIONS_SNOWFLAKE);
58
57
  });
59
58
  it('should convert dbt model with dimension with off time intervals', () => {
60
- expect((0, translator_1.convertTable)(dbt_1.SupportedDbtAdapter.BIGQUERY, translator_mock_1.MODEL_WITH_OFF_TIME_INTERVAL_DIMENSIONS, [])).toStrictEqual(translator_mock_1.LIGHTDASH_TABLE_WITH_OFF_TIME_INTERVAL_DIMENSIONS);
59
+ expect((0, translator_1.convertTable)(dbt_1.SupportedDbtAdapter.BIGQUERY, translator_mock_1.MODEL_WITH_OFF_TIME_INTERVAL_DIMENSIONS, [], lightdashProjectConfig_1.DEFAULT_SPOTLIGHT_CONFIG)).toStrictEqual(translator_mock_1.LIGHTDASH_TABLE_WITH_OFF_TIME_INTERVAL_DIMENSIONS);
61
60
  });
62
61
  it('should convert dbt model with dimension with off boolean time intervals', () => {
63
- expect((0, translator_1.convertTable)(dbt_1.SupportedDbtAdapter.BIGQUERY, translator_mock_1.MODEL_WITH_OFF_BOOLEAN_TIME_INTERVAL_DIMENSIONS, [])).toStrictEqual(translator_mock_1.LIGHTDASH_TABLE_WITH_OFF_TIME_INTERVAL_DIMENSIONS);
62
+ expect((0, translator_1.convertTable)(dbt_1.SupportedDbtAdapter.BIGQUERY, translator_mock_1.MODEL_WITH_OFF_BOOLEAN_TIME_INTERVAL_DIMENSIONS, [], lightdashProjectConfig_1.DEFAULT_SPOTLIGHT_CONFIG)).toStrictEqual(translator_mock_1.LIGHTDASH_TABLE_WITH_OFF_TIME_INTERVAL_DIMENSIONS);
64
63
  });
65
64
  it('should convert dbt model with dimension with custom time intervals', () => {
66
- expect((0, translator_1.convertTable)(dbt_1.SupportedDbtAdapter.BIGQUERY, translator_mock_1.MODEL_WITH_CUSTOM_TIME_INTERVAL_DIMENSIONS, [])).toStrictEqual(translator_mock_1.LIGHTDASH_TABLE_WITH_CUSTOM_TIME_INTERVAL_DIMENSIONS);
65
+ expect((0, translator_1.convertTable)(dbt_1.SupportedDbtAdapter.BIGQUERY, translator_mock_1.MODEL_WITH_CUSTOM_TIME_INTERVAL_DIMENSIONS, [], lightdashProjectConfig_1.DEFAULT_SPOTLIGHT_CONFIG)).toStrictEqual(translator_mock_1.LIGHTDASH_TABLE_WITH_CUSTOM_TIME_INTERVAL_DIMENSIONS);
67
66
  });
68
67
  it('should throw an error when metric and dimension have the same name', async () => {
69
- expect(() => (0, translator_1.convertTable)(dbt_1.SupportedDbtAdapter.BIGQUERY, translator_mock_1.MODEL_WITH_WRONG_METRIC, [])).toThrowError('Found a metric and a dimension with the same name: user_id');
68
+ expect(() => (0, translator_1.convertTable)(dbt_1.SupportedDbtAdapter.BIGQUERY, translator_mock_1.MODEL_WITH_WRONG_METRIC, [], lightdashProjectConfig_1.DEFAULT_SPOTLIGHT_CONFIG)).toThrowError('Found a metric and a dimension with the same name: user_id');
70
69
  });
71
70
  it('should throw an error when multiple metrics and dimensions have the same name', async () => {
72
- expect(() => (0, translator_1.convertTable)(dbt_1.SupportedDbtAdapter.BIGQUERY, translator_mock_1.MODEL_WITH_WRONG_METRICS, [])).toThrowError('Found multiple metrics and a dimensions with the same name: user_id,user_id2');
71
+ expect(() => (0, translator_1.convertTable)(dbt_1.SupportedDbtAdapter.BIGQUERY, translator_mock_1.MODEL_WITH_WRONG_METRICS, [], lightdashProjectConfig_1.DEFAULT_SPOTLIGHT_CONFIG)).toThrowError('Found multiple metrics and a dimensions with the same name: user_id,user_id2');
73
72
  });
74
73
  it('should convert dbt model with group label', async () => {
75
- expect((0, translator_1.convertTable)(dbt_1.SupportedDbtAdapter.BIGQUERY, translator_mock_1.MODEL_WITH_GROUP_LABEL, [])).toStrictEqual(translator_mock_1.LIGHTDASH_TABLE_WITH_GROUP_LABEL);
74
+ expect((0, translator_1.convertTable)(dbt_1.SupportedDbtAdapter.BIGQUERY, translator_mock_1.MODEL_WITH_GROUP_LABEL, [], lightdashProjectConfig_1.DEFAULT_SPOTLIGHT_CONFIG)).toStrictEqual(translator_mock_1.LIGHTDASH_TABLE_WITH_GROUP_LABEL);
76
75
  });
77
76
  // `sql_where` is an alias of `sql_filter`
78
77
  it('should convert dbt model with sql where', async () => {
79
- expect((0, translator_1.convertTable)(dbt_1.SupportedDbtAdapter.BIGQUERY, translator_mock_1.MODEL_WITH_SQL_WHERE, [])).toStrictEqual(translator_mock_1.LIGHTDASH_TABLE_SQL_WHERE);
78
+ expect((0, translator_1.convertTable)(dbt_1.SupportedDbtAdapter.BIGQUERY, translator_mock_1.MODEL_WITH_SQL_WHERE, [], lightdashProjectConfig_1.DEFAULT_SPOTLIGHT_CONFIG)).toStrictEqual(translator_mock_1.LIGHTDASH_TABLE_SQL_WHERE);
80
79
  });
81
80
  it('should convert dbt model with sql filter', async () => {
82
- expect((0, translator_1.convertTable)(dbt_1.SupportedDbtAdapter.BIGQUERY, translator_mock_1.MODEL_WITH_SQL_FILTER, [])).toStrictEqual(translator_mock_1.LIGHTDASH_TABLE_SQL_WHERE);
81
+ expect((0, translator_1.convertTable)(dbt_1.SupportedDbtAdapter.BIGQUERY, translator_mock_1.MODEL_WITH_SQL_FILTER, [], lightdashProjectConfig_1.DEFAULT_SPOTLIGHT_CONFIG)).toStrictEqual(translator_mock_1.LIGHTDASH_TABLE_SQL_WHERE);
83
82
  });
84
83
  it('should convert dbt model with dimension and additional dimensions', () => {
85
- expect((0, translator_1.convertTable)(dbt_1.SupportedDbtAdapter.POSTGRES, translator_mock_1.MODEL_WITH_ADDITIONAL_DIMENSIONS, [])).toStrictEqual(translator_mock_1.LIGHTDASH_TABLE_WITH_ADDITIONAL_DIMENSIONS);
84
+ expect((0, translator_1.convertTable)(dbt_1.SupportedDbtAdapter.POSTGRES, translator_mock_1.MODEL_WITH_ADDITIONAL_DIMENSIONS, [], lightdashProjectConfig_1.DEFAULT_SPOTLIGHT_CONFIG)).toStrictEqual(translator_mock_1.LIGHTDASH_TABLE_WITH_ADDITIONAL_DIMENSIONS);
86
85
  });
87
86
  it('should convert dbt model with groups meta block', async () => {
88
- expect((0, translator_1.convertTable)(dbt_1.SupportedDbtAdapter.BIGQUERY, translator_mock_1.MODEL_WITH_GROUPS_BLOCK, [])).toStrictEqual(translator_mock_1.LIGHTDASH_TABLE_WITH_GROUP_BLOCK);
87
+ expect((0, translator_1.convertTable)(dbt_1.SupportedDbtAdapter.BIGQUERY, translator_mock_1.MODEL_WITH_GROUPS_BLOCK, [], lightdashProjectConfig_1.DEFAULT_SPOTLIGHT_CONFIG)).toStrictEqual(translator_mock_1.LIGHTDASH_TABLE_WITH_GROUP_BLOCK);
89
88
  });
90
89
  });
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "Format": {
34
34
  "type": "string",
35
- "enum": ["km", "mi", "usd", "gbp", "eur", "jpy", "id", "percent"]
35
+ "enum": ["km", "mi", "usd", "gbp", "eur", "jpy", "dkk", "percent"]
36
36
  },
37
37
  "Urls": {
38
38
  "type": "array",
@@ -1,11 +1,12 @@
1
1
  import { type ValidateFunction } from 'ajv';
2
2
  import { type AnyValidateFunction } from 'ajv/dist/types';
3
+ import { type AnyType } from '../types/any';
3
4
  import { type DbtManifestVersion, type DbtMetric, type DbtRawModelNode } from '../types/dbt';
4
5
  export declare class ManifestValidator {
5
6
  private readonly lightdashSchemaId;
6
7
  private readonly dbtSchemaId;
7
8
  constructor(manifestVersion: DbtManifestVersion);
8
- static isValid: (validator: ValidateFunction<any>, data: any) => [true, undefined] | [false, string];
9
+ static isValid: (validator: ValidateFunction<AnyType>, data: AnyType) => [true, undefined] | [false, string];
9
10
  static formatAjvErrors: (validator: AnyValidateFunction) => string;
10
11
  static getValidator: <T>(schemaRef: string) => AnyValidateFunction<T>;
11
12
  isModelValid: (model: DbtRawModelNode) => [true, undefined] | [false, string];
package/dist/index.d.ts CHANGED
@@ -36,6 +36,8 @@ import { type TableBase } from './types/table';
36
36
  import { type LightdashUser, type LoginOptions, type UserAllowedOrganization } from './types/user';
37
37
  import { type UserWarehouseCredentials } from './types/userWarehouseCredentials';
38
38
  import { type ValidationResponse } from './types/validation';
39
+ import { type AnyType } from './types/any';
40
+ import { type ApiGetSpotlightTableConfig } from './types/api/spotlight';
39
41
  import { type ApiCatalogAnalyticsResults, type ApiCatalogMetadataResults, type ApiGetMetricsTree, type ApiMetricsCatalog } from './types/catalog';
40
42
  import { type ApiChartAsCodeListResponse, type ApiChartAsCodeUpsertResponse, type ApiDashboardAsCodeListResponse } from './types/coder';
41
43
  import { type ApiChartContentResponse, type ApiContentResponse } from './types/content';
@@ -45,7 +47,6 @@ import { type ApiPromotionChangesResponse } from './types/promotion';
45
47
  import { type ApiSemanticLayerClientInfo, type ApiSemanticViewerChartCreate, type ApiSemanticViewerChartGet, type ApiSemanticViewerChartUpdate } from './types/semanticLayer';
46
48
  import { type ApiCreateSqlChart, type ApiCreateVirtualView, type ApiGithubDbtWritePreview, type ApiSqlChart, type ApiSqlRunnerJobStatusResponse, type ApiUpdateSqlChart } from './types/sqlRunner';
47
49
  import { type ApiWarehouseTableFields } from './types/warehouse';
48
- import { type ApiGetSpotlightTableConfig } from './types/api/spotlight';
49
50
  export * from './authorization/index';
50
51
  export * from './authorization/types';
51
52
  export * from './compiler/exploreCompiler';
@@ -54,17 +55,19 @@ export * from './compiler/translator';
54
55
  export * from './dbt/validation';
55
56
  export * from './pivotTable/pivotQueryResults';
56
57
  export { default as lightdashDbtYamlSchema } from './schemas/json/lightdash-dbt-2.0.json';
58
+ export { default as lightdashProjectConfigSchema } from './schemas/json/lightdash-project-config-1.0.json';
57
59
  export * from './templating/template';
58
60
  export * from './types/analytics';
61
+ export * from './types/any';
59
62
  export * from './types/api';
60
63
  export * from './types/api/comments';
61
64
  export * from './types/api/errors';
62
65
  export * from './types/api/notifications';
63
66
  export * from './types/api/share';
64
67
  export * from './types/api/sort';
68
+ export * from './types/api/spotlight';
65
69
  export * from './types/api/success';
66
70
  export * from './types/api/uuid';
67
- export * from './types/api/spotlight';
68
71
  export * from './types/catalog';
69
72
  export * from './types/coder';
70
73
  export * from './types/comments';
@@ -88,6 +91,7 @@ export * from './types/gitIntegration';
88
91
  export * from './types/groups';
89
92
  export * from './types/job';
90
93
  export * from './types/knex-paginate';
94
+ export * from './types/lightdashProjectConfig';
91
95
  export * from './types/metricQuery';
92
96
  export * from './types/metricsExplorer';
93
97
  export * from './types/notifications';
@@ -112,6 +116,7 @@ export * from './types/share';
112
116
  export * from './types/slack';
113
117
  export * from './types/slackSettings';
114
118
  export * from './types/space';
119
+ export * from './types/spotlightTableConfig';
115
120
  export * from './types/sqlRunner';
116
121
  export * from './types/SshKeyPair';
117
122
  export * from './types/table';
@@ -136,6 +141,7 @@ export * from './utils/filters';
136
141
  export * from './utils/formatting';
137
142
  export * from './utils/github';
138
143
  export * from './utils/item';
144
+ export * from './utils/loadLightdashProjectConfig';
139
145
  export * from './utils/metricsExplorer';
140
146
  export * from './utils/projectMemberRole';
141
147
  export * from './utils/sanitizeHtml';
@@ -151,7 +157,6 @@ export * from './visualizations/PieChartDataModel';
151
157
  export * from './visualizations/TableDataModel';
152
158
  export * from './visualizations/types';
153
159
  export * from './visualizations/types/IResultsRunner';
154
- export * from './types/spotlightTableConfig';
155
160
  export declare const validateEmail: (email: string) => boolean;
156
161
  export declare const getEmailSchema: () => z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
157
162
  export declare const getPasswordSchema: () => z.ZodString;
@@ -226,7 +231,7 @@ export declare const SEED_GROUP: {
226
231
  groupUuid: string;
227
232
  name: string;
228
233
  };
229
- export type ArgumentsOf<F extends Function> = F extends (...args: infer A) => any ? A : never;
234
+ export type ArgumentsOf<F extends Function> = F extends (...args: infer A) => AnyType ? A : never;
230
235
  export declare const getVisibleFields: (explore: Explore) => CompiledField[];
231
236
  export declare const findFieldByIdInExplore: (explore: Explore, id: FieldId) => Field | undefined;
232
237
  export declare const snakeCaseName: (text: string) => string;
@@ -549,8 +554,8 @@ export declare const getMetricsFromItemsMap: (itemsMap: ItemsMap, filter?: (valu
549
554
  export declare const getTableCalculationsFromItemsMap: (itemsMap?: ItemsMap) => Record<string, TableCalculation>;
550
555
  export declare function itemsInMetricQuery(metricQuery: MetricQuery | undefined): string[];
551
556
  export declare function formatRows(rows: {
552
- [col: string]: any;
557
+ [col: string]: AnyType;
553
558
  }[], itemsMap: ItemsMap): ResultRow[];
554
- export declare const removeEmptyProperties: (object: Record<string, any>) => Record<string, any>;
555
- export declare const deepEqual: (object1: Record<string, any>, object2: Record<string, any>) => boolean;
559
+ export declare const removeEmptyProperties: (object: Record<string, AnyType>) => Record<string, any>;
560
+ export declare const deepEqual: (object1: Record<string, AnyType>, object2: Record<string, AnyType>) => boolean;
556
561
  export declare const getProjectDirectory: (dbtConnection?: DbtProjectConfig) => string | undefined;