@lightdash/common 0.1462.1 → 0.1463.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,9 @@
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
5
  import { type DateGranularity } from '../types/timeFrames';
6
+ import { type LightdashProjectConfig } from '../types/lightdashProjectConfig';
6
7
  export declare const lightdashVariablePattern: RegExp;
7
8
  type Reference = {
8
9
  refTable: string;
@@ -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
  });
package/dist/index.d.ts CHANGED
@@ -54,6 +54,7 @@ export * from './compiler/translator';
54
54
  export * from './dbt/validation';
55
55
  export * from './pivotTable/pivotQueryResults';
56
56
  export { default as lightdashDbtYamlSchema } from './schemas/json/lightdash-dbt-2.0.json';
57
+ export { default as lightdashProjectConfigSchema } from './schemas/json/lightdash-project-config-1.0.json';
57
58
  export * from './templating/template';
58
59
  export * from './types/analytics';
59
60
  export * from './types/api';
@@ -88,6 +89,7 @@ export * from './types/gitIntegration';
88
89
  export * from './types/groups';
89
90
  export * from './types/job';
90
91
  export * from './types/knex-paginate';
92
+ export * from './types/lightdashProjectConfig';
91
93
  export * from './types/metricQuery';
92
94
  export * from './types/metricsExplorer';
93
95
  export * from './types/notifications';
@@ -152,6 +154,7 @@ export * from './visualizations/TableDataModel';
152
154
  export * from './visualizations/types';
153
155
  export * from './visualizations/types/IResultsRunner';
154
156
  export * from './types/spotlightTableConfig';
157
+ export * from './utils/loadLightdashProjectConfig';
155
158
  export declare const validateEmail: (email: string) => boolean;
156
159
  export declare const getEmailSchema: () => z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
157
160
  export declare const getPasswordSchema: () => z.ZodString;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getProjectDirectory = exports.deepEqual = exports.removeEmptyProperties = exports.formatRows = exports.itemsInMetricQuery = exports.getTableCalculationsFromItemsMap = exports.getMetricsFromItemsMap = exports.getFilterableDimensionsFromItemsMap = exports.getDimensionsFromItemsMap = exports.getItemMap = exports.getFieldMap = exports.getAxisName = exports.getDateGroupLabel = exports.getResultValueArray = exports.DbtProjectTypeLabels = exports.sensitiveDbtCredentialsFieldNames = exports.DBFieldTypes = exports.LightdashInstallType = exports.isLightdashMode = exports.LightdashMode = exports.isApiError = exports.hasInviteCode = exports.TableSelectionType = exports.hasSpecialCharacters = exports.snakeCaseName = exports.findFieldByIdInExplore = exports.getVisibleFields = exports.SEED_GROUP = exports.SEED_SPACE = exports.SEED_PROJECT = exports.SEED_ORG_2_ADMIN_PASSWORD = exports.SEED_ORG_2_ADMIN_EMAIL = exports.SEED_ORG_2_ADMIN = exports.SEED_ORG_2 = exports.SEED_ORG_1_ADMIN_PASSWORD = exports.SEED_ORG_1_ADMIN_EMAIL = exports.SEED_ORG_1_ADMIN = exports.SEED_ORG_1 = exports.hexToRGB = exports.replaceStringInArray = exports.toggleArrayValue = exports.hasIntersection = exports.validatePassword = exports.getPasswordSchema = exports.getEmailSchema = exports.validateEmail = exports.assertUnreachable = exports.lightdashDbtYamlSchema = void 0;
3
+ exports.getProjectDirectory = exports.deepEqual = exports.removeEmptyProperties = exports.formatRows = exports.itemsInMetricQuery = exports.getTableCalculationsFromItemsMap = exports.getMetricsFromItemsMap = exports.getFilterableDimensionsFromItemsMap = exports.getDimensionsFromItemsMap = exports.getItemMap = exports.getFieldMap = exports.getAxisName = exports.getDateGroupLabel = exports.getResultValueArray = exports.DbtProjectTypeLabels = exports.sensitiveDbtCredentialsFieldNames = exports.DBFieldTypes = exports.LightdashInstallType = exports.isLightdashMode = exports.LightdashMode = exports.isApiError = exports.hasInviteCode = exports.TableSelectionType = exports.hasSpecialCharacters = exports.snakeCaseName = exports.findFieldByIdInExplore = exports.getVisibleFields = exports.SEED_GROUP = exports.SEED_SPACE = exports.SEED_PROJECT = exports.SEED_ORG_2_ADMIN_PASSWORD = exports.SEED_ORG_2_ADMIN_EMAIL = exports.SEED_ORG_2_ADMIN = exports.SEED_ORG_2 = exports.SEED_ORG_1_ADMIN_PASSWORD = exports.SEED_ORG_1_ADMIN_EMAIL = exports.SEED_ORG_1_ADMIN = exports.SEED_ORG_1 = exports.hexToRGB = exports.replaceStringInArray = exports.toggleArrayValue = exports.hasIntersection = exports.validatePassword = exports.getPasswordSchema = exports.getEmailSchema = exports.validateEmail = exports.assertUnreachable = exports.lightdashProjectConfigSchema = exports.lightdashDbtYamlSchema = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
6
6
  const utc_1 = tslib_1.__importDefault(require("dayjs/plugin/utc"));
@@ -22,6 +22,8 @@ tslib_1.__exportStar(require("./dbt/validation"), exports);
22
22
  tslib_1.__exportStar(require("./pivotTable/pivotQueryResults"), exports);
23
23
  var lightdash_dbt_2_0_json_1 = require("./schemas/json/lightdash-dbt-2.0.json");
24
24
  Object.defineProperty(exports, "lightdashDbtYamlSchema", { enumerable: true, get: function () { return tslib_1.__importDefault(lightdash_dbt_2_0_json_1).default; } });
25
+ var lightdash_project_config_1_0_json_1 = require("./schemas/json/lightdash-project-config-1.0.json");
26
+ Object.defineProperty(exports, "lightdashProjectConfigSchema", { enumerable: true, get: function () { return tslib_1.__importDefault(lightdash_project_config_1_0_json_1).default; } });
25
27
  tslib_1.__exportStar(require("./templating/template"), exports);
26
28
  tslib_1.__exportStar(require("./types/analytics"), exports);
27
29
  tslib_1.__exportStar(require("./types/api"), exports);
@@ -56,6 +58,7 @@ tslib_1.__exportStar(require("./types/gitIntegration"), exports);
56
58
  tslib_1.__exportStar(require("./types/groups"), exports);
57
59
  tslib_1.__exportStar(require("./types/job"), exports);
58
60
  tslib_1.__exportStar(require("./types/knex-paginate"), exports);
61
+ tslib_1.__exportStar(require("./types/lightdashProjectConfig"), exports);
59
62
  tslib_1.__exportStar(require("./types/metricQuery"), exports);
60
63
  tslib_1.__exportStar(require("./types/metricsExplorer"), exports);
61
64
  tslib_1.__exportStar(require("./types/notifications"), exports);
@@ -121,6 +124,7 @@ tslib_1.__exportStar(require("./visualizations/TableDataModel"), exports);
121
124
  tslib_1.__exportStar(require("./visualizations/types"), exports);
122
125
  tslib_1.__exportStar(require("./visualizations/types/IResultsRunner"), exports);
123
126
  tslib_1.__exportStar(require("./types/spotlightTableConfig"), exports);
127
+ tslib_1.__exportStar(require("./utils/loadLightdashProjectConfig"), exports);
124
128
  const validateEmail = (email) => {
125
129
  if (/\s/.test(email)) {
126
130
  return false;
@@ -186,6 +186,23 @@
186
186
  "field",
187
187
  "interval"
188
188
  ]
189
+ },
190
+ "spotlight": {
191
+ "type": "object",
192
+ "description": "Set the visibility of a metric in Spotlight",
193
+ "properties": {
194
+ "visibility": {
195
+ "type": "string",
196
+ "enum": ["show", "hide"]
197
+ }
198
+ },
199
+ "anyOf": [
200
+ {
201
+ "required": [
202
+ "visibility"
203
+ ]
204
+ }
205
+ ]
189
206
  }
190
207
  },
191
208
  "required": ["type", "sql"]
@@ -212,6 +229,17 @@
212
229
  }
213
230
  },
214
231
  "required": ["field", "interval"]
232
+ },
233
+ "spotlight": {
234
+ "type": "object",
235
+ "description": "Set the visibility of all metrics in this model in Spotlight",
236
+ "properties": {
237
+ "visibility": {
238
+ "type": "string",
239
+ "enum": ["show", "hide"]
240
+ }
241
+ },
242
+ "anyOf": [{ "required": ["visibility"] }]
215
243
  }
216
244
  }
217
245
  },
@@ -354,6 +382,26 @@
354
382
  "field",
355
383
  "interval"
356
384
  ]
385
+ },
386
+ "spotlight": {
387
+ "type": "object",
388
+ "description": "Set the visibility of a metric in Spotlight",
389
+ "properties": {
390
+ "visibility": {
391
+ "type": "string",
392
+ "enum": [
393
+ "show",
394
+ "hide"
395
+ ]
396
+ }
397
+ },
398
+ "anyOf": [
399
+ {
400
+ "required": [
401
+ "visibility"
402
+ ]
403
+ }
404
+ ]
357
405
  }
358
406
  },
359
407
  "required": ["type"]
@@ -626,6 +674,17 @@
626
674
  }
627
675
  },
628
676
  "required": ["field", "interval"]
677
+ },
678
+ "spotlight": {
679
+ "type": "object",
680
+ "description": "Set the visibility of a metric in Spotlight",
681
+ "properties": {
682
+ "visibility": {
683
+ "type": "string",
684
+ "enum": ["show", "hide"]
685
+ }
686
+ },
687
+ "anyOf": [{ "required": ["visibility"] }]
629
688
  }
630
689
  }
631
690
  }
@@ -0,0 +1,17 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "$id": "https://schemas.lightdash.com/lightdash/config.json",
4
+ "type": ["object", "null"],
5
+ "properties": {
6
+ "spotlight": {
7
+ "type": ["object", "null"],
8
+ "properties": {
9
+ "default_visibility": {
10
+ "type": "string",
11
+ "enum": ["show", "hide"],
12
+ "default": "show"
13
+ }
14
+ }
15
+ }
16
+ }
17
+ }
@@ -3,6 +3,7 @@ import { type ColumnInfo, type CompiledModelNode, type ParsedMetric } from './db
3
3
  import { type CompactOrAlias, type DimensionType, type FieldUrl, type Format, type Metric, type MetricType, type Source } from './field';
4
4
  import { type OrderFieldsByStrategy } from './table';
5
5
  import { type DefaultTimeDimension, type TimeFrames } from './timeFrames';
6
+ import { type LightdashProjectConfig } from './lightdashProjectConfig';
6
7
  export declare enum SupportedDbtAdapter {
7
8
  BIGQUERY = "bigquery",
8
9
  DATABRICKS = "databricks",
@@ -64,6 +65,9 @@ type DbtModelLightdashConfig = {
64
65
  field: string;
65
66
  interval: TimeFrames;
66
67
  };
68
+ spotlight?: {
69
+ visibility?: NonNullable<LightdashProjectConfig['spotlight']>['default_visibility'];
70
+ };
67
71
  };
68
72
  export type DbtModelGroup = {
69
73
  label: string;
@@ -126,6 +130,9 @@ export type DbtColumnLightdashMetric = {
126
130
  }[];
127
131
  percentile?: number;
128
132
  default_time_dimension?: DefaultTimeDimension;
133
+ spotlight?: {
134
+ visibility?: NonNullable<LightdashProjectConfig['spotlight']>['default_visibility'];
135
+ };
129
136
  } & DbtLightdashFieldTags;
130
137
  export type DbtModelLightdashMetric = DbtColumnLightdashMetric & Required<Pick<DbtColumnLightdashMetric, 'sql'>>;
131
138
  export declare const normaliseModelDatabase: (model: DbtRawModelNode, targetWarehouse: SupportedDbtAdapter) => DbtModelNode;
@@ -239,15 +246,17 @@ type ConvertModelMetricArgs = {
239
246
  tableLabel: string;
240
247
  dimensionReference?: string;
241
248
  requiredAttributes?: Record<string, string | string[]>;
249
+ spotlightConfig?: LightdashProjectConfig['spotlight'];
242
250
  };
243
- export declare const convertModelMetric: ({ modelName, name, metric, source, tableLabel, dimensionReference, requiredAttributes, }: ConvertModelMetricArgs) => Metric;
251
+ export declare const convertModelMetric: ({ modelName, name, metric, source, tableLabel, dimensionReference, requiredAttributes, spotlightConfig, }: ConvertModelMetricArgs) => Metric;
244
252
  type ConvertColumnMetricArgs = Omit<ConvertModelMetricArgs, 'metric'> & {
245
253
  metric: DbtColumnLightdashMetric;
246
254
  dimensionName?: string;
247
255
  dimensionSql: string;
248
256
  requiredAttributes?: Record<string, string | string[]>;
257
+ modelCategories?: string[];
249
258
  };
250
- export declare const convertColumnMetric: ({ modelName, dimensionName, dimensionSql, name, metric, source, tableLabel, requiredAttributes, }: ConvertColumnMetricArgs) => Metric;
259
+ export declare const convertColumnMetric: ({ modelName, dimensionName, dimensionSql, name, metric, source, tableLabel, requiredAttributes, spotlightConfig, }: ConvertColumnMetricArgs) => Metric;
251
260
  export declare enum DbtManifestVersion {
252
261
  V7 = "v7",
253
262
  V8 = "v8",
package/dist/types/dbt.js CHANGED
@@ -134,8 +134,9 @@ const isDbtRpcRunSqlResults = (results) => 'results' in results &&
134
134
  'rows' in result.table &&
135
135
  Array.isArray(result.table.rows));
136
136
  exports.isDbtRpcRunSqlResults = isDbtRpcRunSqlResults;
137
- const convertModelMetric = ({ modelName, name, metric, source, tableLabel, dimensionReference, requiredAttributes, }) => {
137
+ const convertModelMetric = ({ modelName, name, metric, source, tableLabel, dimensionReference, requiredAttributes, spotlightConfig, }) => {
138
138
  const groups = (0, exports.convertToGroups)(metric.groups, metric.group_label);
139
+ const spotlightVisibility = metric.spotlight?.visibility ?? spotlightConfig?.default_visibility;
139
140
  return {
140
141
  fieldType: field_1.FieldType.METRIC,
141
142
  name,
@@ -173,10 +174,17 @@ const convertModelMetric = ({ modelName, name, metric, source, tableLabel, dimen
173
174
  },
174
175
  }
175
176
  : null),
177
+ ...(spotlightVisibility !== undefined
178
+ ? {
179
+ spotlight: {
180
+ visibility: spotlightVisibility,
181
+ },
182
+ }
183
+ : {}),
176
184
  };
177
185
  };
178
186
  exports.convertModelMetric = convertModelMetric;
179
- const convertColumnMetric = ({ modelName, dimensionName, dimensionSql, name, metric, source, tableLabel, requiredAttributes, }) => (0, exports.convertModelMetric)({
187
+ const convertColumnMetric = ({ modelName, dimensionName, dimensionSql, name, metric, source, tableLabel, requiredAttributes, spotlightConfig, }) => (0, exports.convertModelMetric)({
180
188
  modelName,
181
189
  name,
182
190
  metric: {
@@ -201,6 +209,7 @@ const convertColumnMetric = ({ modelName, dimensionName, dimensionSql, name, met
201
209
  },
202
210
  }
203
211
  : null),
212
+ spotlightConfig,
204
213
  });
205
214
  exports.convertColumnMetric = convertColumnMetric;
206
215
  var DbtManifestVersion;
@@ -1,5 +1,6 @@
1
1
  import { type DbtModelJoinType, type LineageGraph, type SupportedDbtAdapter } from './dbt';
2
2
  import { type CompiledDimension, type CompiledMetric, type Dimension, type Metric, type Source } from './field';
3
+ import { type LightdashProjectConfig } from './lightdashProjectConfig';
3
4
  import { type TableBase } from './table';
4
5
  export type ExploreJoin = {
5
6
  table: string;
@@ -43,6 +44,9 @@ export type Explore = {
43
44
  ymlPath?: string;
44
45
  sqlPath?: string;
45
46
  type?: ExploreType;
47
+ spotlight?: {
48
+ visibility: Required<NonNullable<LightdashProjectConfig['spotlight']>>['default_visibility'];
49
+ };
46
50
  };
47
51
  export declare enum InlineErrorType {
48
52
  METADATA_PARSE_ERROR = "METADATA_PARSE_ERROR",
@@ -1,4 +1,4 @@
1
- import type { AdditionalMetric, currencies, DefaultTimeDimension } from '..';
1
+ import type { AdditionalMetric, currencies, DefaultTimeDimension, LightdashProjectConfig } from '..';
2
2
  import { type MetricFilterRule } from './filter';
3
3
  import { type TimeFrames } from './timeFrames';
4
4
  export declare enum Compact {
@@ -240,6 +240,9 @@ export interface Metric extends Field {
240
240
  dimensionReference?: string;
241
241
  requiredAttributes?: Record<string, string | string[]>;
242
242
  defaultTimeDimension?: DefaultTimeDimension;
243
+ spotlight?: {
244
+ visibility: Required<NonNullable<LightdashProjectConfig['spotlight']>>['default_visibility'];
245
+ };
243
246
  }
244
247
  export declare const isFilterableDimension: (dimension: Dimension) => dimension is FilterableDimension;
245
248
  export type FilterableField = TableCalculation | Metric | FilterableDimension | CustomSqlDimension;
@@ -0,0 +1,8 @@
1
+ type SpotlightConfig = {
2
+ default_visibility: 'show' | 'hide';
3
+ };
4
+ export type LightdashProjectConfig = {
5
+ spotlight: SpotlightConfig;
6
+ };
7
+ export declare const DEFAULT_SPOTLIGHT_CONFIG: Required<SpotlightConfig>;
8
+ export {};
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_SPOTLIGHT_CONFIG = void 0;
4
+ exports.DEFAULT_SPOTLIGHT_CONFIG = {
5
+ default_visibility: 'show',
6
+ };
@@ -51,5 +51,8 @@ export declare const replaceDimensionInExplore: (explore: Explore, dimension: Co
51
51
  ymlPath?: string | undefined;
52
52
  sqlPath?: string | undefined;
53
53
  type?: import("../types/explore").ExploreType | undefined;
54
+ spotlight?: {
55
+ visibility: "show" | "hide";
56
+ } | undefined;
54
57
  };
55
58
  export declare const canApplyFormattingToCustomMetric: (item: Dimension, customMetricType: MetricType) => boolean;
@@ -0,0 +1,2 @@
1
+ import { type LightdashProjectConfig } from '../types/lightdashProjectConfig';
2
+ export declare const loadLightdashProjectConfig: (yamlFileContents: string) => Promise<LightdashProjectConfig>;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadLightdashProjectConfig = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const ajv_1 = tslib_1.__importDefault(require("ajv"));
6
+ const yaml = tslib_1.__importStar(require("js-yaml"));
7
+ const better_ajv_errors_1 = tslib_1.__importDefault(require("better-ajv-errors"));
8
+ const lightdashProjectConfig_1 = require("../types/lightdashProjectConfig");
9
+ const lightdash_project_config_1_0_json_1 = tslib_1.__importDefault(require("../schemas/json/lightdash-project-config-1.0.json"));
10
+ const errors_1 = require("../types/errors");
11
+ const loadLightdashProjectConfig = async (yamlFileContents) => {
12
+ if (yamlFileContents.trim() === '') {
13
+ return {
14
+ spotlight: lightdashProjectConfig_1.DEFAULT_SPOTLIGHT_CONFIG,
15
+ };
16
+ }
17
+ const configFile = yaml.load(yamlFileContents);
18
+ const ajv = new ajv_1.default({ coerceTypes: true });
19
+ const validate = ajv.compile(lightdash_project_config_1_0_json_1.default);
20
+ if (!validate(configFile)) {
21
+ const errors = (0, better_ajv_errors_1.default)(lightdash_project_config_1_0_json_1.default, configFile, validate.errors || [], { indent: 2 });
22
+ throw new errors_1.ParseError(`Invalid lightdash.config.yml with errors:\n${errors}`);
23
+ }
24
+ return configFile;
25
+ };
26
+ exports.loadLightdashProjectConfig = loadLightdashProjectConfig;
@@ -42,6 +42,7 @@ const createVirtualView = (virtualViewName, sql, columns, warehouseClient, label
42
42
  joinedTables: [],
43
43
  tables: { [virtualViewName]: compiledTable },
44
44
  targetDatabase: warehouseClient.getAdapterType(),
45
+ meta: {},
45
46
  });
46
47
  const virtualView = {
47
48
  ...explore,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightdash/common",
3
- "version": "0.1462.1",
3
+ "version": "0.1463.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -8,6 +8,7 @@
8
8
  ],
9
9
  "license": "MIT",
10
10
  "devDependencies": {
11
+ "@types/js-yaml": "^4.0.9",
11
12
  "@types/pegjs": "^0.10.3",
12
13
  "@types/sanitize-html": "^2.11.0",
13
14
  "@types/uuid": "^10.0.0",
@@ -18,9 +19,11 @@
18
19
  "@types/lodash": "^4.14.202",
19
20
  "ajv": "^8.3.0",
20
21
  "ajv-formats": "^2.1.0",
22
+ "better-ajv-errors": "^1.2.0",
21
23
  "cronstrue": "^2.23.0",
22
24
  "dayjs": "^1.11.9",
23
25
  "dependency-graph": "^0.11.0",
26
+ "js-yaml": "^4.1.0",
24
27
  "liquidjs": "^10.0.0",
25
28
  "lodash": "^4.17.21",
26
29
  "moment": "^2.29.4",