@lightdash/common 0.1464.3 → 0.1466.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. package/LICENSE +6 -2
  2. package/dist/compiler/exploreCompiler.d.ts +1 -1
  3. package/dist/compiler/exploreCompiler.js +3 -7
  4. package/dist/compiler/exploreCompiler.mock.js +2 -0
  5. package/dist/compiler/lightdashProjectConfig.d.ts +19 -0
  6. package/dist/compiler/lightdashProjectConfig.js +41 -0
  7. package/dist/compiler/translator.js +9 -11
  8. package/dist/compiler/translator.mock.js +9 -0
  9. package/dist/ee/Ai/schemas.d.ts +2094 -0
  10. package/dist/ee/Ai/schemas.js +201 -0
  11. package/dist/ee/Ai/types.d.ts +136 -0
  12. package/dist/ee/Ai/types.js +12 -0
  13. package/dist/ee/commercialFeatureFlags.d.ts +5 -0
  14. package/dist/ee/commercialFeatureFlags.js +9 -0
  15. package/dist/ee/embed/index.d.ts +180 -0
  16. package/dist/ee/embed/index.js +73 -0
  17. package/dist/ee/index.d.ts +14 -0
  18. package/dist/ee/index.js +19 -0
  19. package/dist/ee/scim/errors.d.ts +32 -0
  20. package/dist/ee/scim/errors.js +24 -0
  21. package/dist/ee/scim/types.d.ts +119 -0
  22. package/dist/ee/scim/types.js +2 -0
  23. package/dist/index.d.ts +4 -1
  24. package/dist/index.js +3 -1
  25. package/dist/index.test.js +23 -0
  26. package/dist/schemas/json/lightdash-dbt-2.0.json +50 -6
  27. package/dist/schemas/json/lightdash-project-config-1.0.json +33 -1
  28. package/dist/types/analytics.d.ts +2 -0
  29. package/dist/types/analytics.js +2 -0
  30. package/dist/types/catalog.d.ts +3 -2
  31. package/dist/types/dashboard.d.ts +2 -2
  32. package/dist/types/dbt.d.ts +5 -2
  33. package/dist/types/dbt.js +7 -9
  34. package/dist/types/explore.d.ts +2 -1
  35. package/dist/types/field.d.ts +2 -1
  36. package/dist/types/lightdashProjectConfig.d.ts +8 -1
  37. package/dist/types/slack.d.ts +1 -0
  38. package/dist/types/slackSettings.js +1 -0
  39. package/dist/types/tags.d.ts +5 -0
  40. package/dist/utils/email.d.ts +1 -0
  41. package/dist/utils/email.js +3 -1
  42. package/dist/utils/item.d.ts +1 -0
  43. package/package.json +1 -1
package/LICENSE CHANGED
@@ -1,6 +1,10 @@
1
- MIT License
1
+ Copyright (c) 2021-present Telescope Technology Limited (trading as “Lightdash”)
2
2
 
3
- Copyright (c) 2021 Telescope Technologies Inc.
3
+ Portions of this software are licensed as follows:
4
+
5
+ * All content that resides under the "packages/backend/src/ee" directory of this repository, if that directory exists, is licensed under the license defined in "packages/backend/src/ee/LICENSE".
6
+ * All third party components incorporated into the Lightdash Software are licensed under the original license provided by the owner of the applicable component.
7
+ * Content outside of the above mentioned directories or restrictions above is available under the "MIT" license as defined below.
4
8
 
5
9
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
10
  of this software and associated documentation files (the "Software"), to deal
@@ -1,9 +1,9 @@
1
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
- import { type WarehouseClient } from '../types/warehouse';
5
4
  import { type LightdashProjectConfig } from '../types/lightdashProjectConfig';
6
5
  import { type DateGranularity } from '../types/timeFrames';
6
+ import { type WarehouseClient } from '../types/warehouse';
7
7
  export declare const lightdashVariablePattern: RegExp;
8
8
  type Reference = {
9
9
  refTable: string;
@@ -7,6 +7,7 @@ const timeFrames_1 = require("../types/timeFrames");
7
7
  const timeFrames_2 = require("../utils/timeFrames");
8
8
  const warehouse_1 = require("../utils/warehouse");
9
9
  const filtersCompiler_1 = require("./filtersCompiler");
10
+ const lightdashProjectConfig_1 = require("./lightdashProjectConfig");
10
11
  // exclude lightdash prefix from variable pattern
11
12
  exports.lightdashVariablePattern = /\$\{((?!(lightdash|ld)\.)[a-zA-Z0-9_.]+)\}/g;
12
13
  const getParsedReference = (ref, currentTable) => {
@@ -119,14 +120,8 @@ class ExploreCompiler {
119
120
  }), {});
120
121
  const compiledJoins = joinedTables.map((j) => this.compileJoin(j, includedTables));
121
122
  const spotlightVisibility = meta.spotlight?.visibility ?? spotlightConfig?.default_visibility;
123
+ const spotlightCategories = (0, lightdashProjectConfig_1.getCategoriesFromResource)('explore', name, spotlightConfig, meta.spotlight?.categories);
122
124
  return {
123
- ...(spotlightVisibility !== undefined
124
- ? {
125
- spotlight: {
126
- visibility: spotlightVisibility,
127
- },
128
- }
129
- : {}),
130
125
  name,
131
126
  label,
132
127
  tags,
@@ -138,6 +133,7 @@ class ExploreCompiler {
138
133
  warehouse,
139
134
  ymlPath,
140
135
  sqlPath,
136
+ ...(0, lightdashProjectConfig_1.getSpotlightConfigurationForResource)(spotlightVisibility, spotlightCategories),
141
137
  };
142
138
  }
143
139
  compileTable(table, tables) {
@@ -81,6 +81,7 @@ exports.exploreBase = {
81
81
  tags: [],
82
82
  spotlight: {
83
83
  visibility: 'show',
84
+ categories: [],
84
85
  },
85
86
  baseTable: 'a',
86
87
  joinedTables: [],
@@ -1423,6 +1424,7 @@ exports.exploreWithMetricNumberCompiled = {
1423
1424
  groupLabel: exports.exploreWithMetricNumber.groupLabel,
1424
1425
  spotlight: {
1425
1426
  visibility: 'show',
1427
+ categories: [],
1426
1428
  },
1427
1429
  joinedTables: [],
1428
1430
  tables: {
@@ -0,0 +1,19 @@
1
+ import type { Explore } from '../types/explore';
2
+ import type { Metric } from '../types/field';
3
+ import type { LightdashProjectConfig } from '../types/lightdashProjectConfig';
4
+ /**
5
+ * Get the spotlight configuration for a resource
6
+ * @param visibility - The visibility of the resource
7
+ * @param categories - The categories of the resource
8
+ * @returns The spotlight configuration for the resource
9
+ */
10
+ export declare const getSpotlightConfigurationForResource: (visibility?: LightdashProjectConfig['spotlight']['default_visibility'], categories?: string[]) => Pick<Explore, 'spotlight'> | Pick<Metric, 'spotlight'>;
11
+ /**
12
+ * Get the categories from the resource and validate them against the project config
13
+ * @param resourceType - The type of the resource
14
+ * @param resourceName - The name of the resource
15
+ * @param spotlightConfig - The spotlight config
16
+ * @param resourceCategories - The categories from the resource
17
+ * @returns The categories from the resource
18
+ */
19
+ export declare const getCategoriesFromResource: (resourceType: 'metric' | 'explore', resourceName: string, spotlightConfig: LightdashProjectConfig['spotlight'] | undefined, resourceCategories?: string[] | undefined) => string[];
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCategoriesFromResource = exports.getSpotlightConfigurationForResource = void 0;
4
+ const errors_1 = require("../types/errors");
5
+ /**
6
+ * Get the spotlight configuration for a resource
7
+ * @param visibility - The visibility of the resource
8
+ * @param categories - The categories of the resource
9
+ * @returns The spotlight configuration for the resource
10
+ */
11
+ const getSpotlightConfigurationForResource = (visibility, categories) => {
12
+ if (visibility === undefined) {
13
+ return {};
14
+ }
15
+ return {
16
+ spotlight: {
17
+ visibility,
18
+ categories,
19
+ },
20
+ };
21
+ };
22
+ exports.getSpotlightConfigurationForResource = getSpotlightConfigurationForResource;
23
+ /**
24
+ * Get the categories from the resource and validate them against the project config
25
+ * @param resourceType - The type of the resource
26
+ * @param resourceName - The name of the resource
27
+ * @param spotlightConfig - The spotlight config
28
+ * @param resourceCategories - The categories from the resource
29
+ * @returns The categories from the resource
30
+ */
31
+ const getCategoriesFromResource = (resourceType, resourceName, spotlightConfig, resourceCategories = []) => {
32
+ // Get all valid category references from the global spotlight config
33
+ const categoriesDefinedInProjectConfig = Object.keys(spotlightConfig?.categories || {}) || [];
34
+ // Check if any metric categories aren't defined in the global config
35
+ const invalidCategories = resourceCategories.filter((category) => !categoriesDefinedInProjectConfig.includes(category));
36
+ if (invalidCategories.length > 0) {
37
+ throw new errors_1.ParseError(`Invalid spotlight categories found in ${resourceType} '${resourceName}': ${invalidCategories.join(', ')}. Categories must be defined in project config.`);
38
+ }
39
+ return resourceCategories;
40
+ };
41
+ exports.getCategoriesFromResource = getCategoriesFromResource;
@@ -11,6 +11,7 @@ const table_1 = require("../types/table");
11
11
  const assertUnreachable_1 = tslib_1.__importDefault(require("../utils/assertUnreachable"));
12
12
  const timeFrames_1 = require("../utils/timeFrames");
13
13
  const exploreCompiler_1 = require("./exploreCompiler");
14
+ const lightdashProjectConfig_1 = require("./lightdashProjectConfig");
14
15
  const convertTimezone = (timestampSql, default_source_tz, target_tz, adapterType) => {
15
16
  // todo: implement default_source_tz
16
17
  // todo: implement target_tz
@@ -118,7 +119,7 @@ const generateTableLineage = (model, depGraph) => {
118
119
  .map((d) => depGraph.getNodeData(d)),
119
120
  }), {});
120
121
  };
121
- const convertDbtMetricToLightdashMetric = (metric, tableName, tableLabel, spotlightConfig) => {
122
+ const convertDbtMetricToLightdashMetric = (metric, tableName, tableLabel, spotlightConfig, modelCategories) => {
122
123
  let sql;
123
124
  let type;
124
125
  if (metric.calculation_method === 'derived') {
@@ -161,7 +162,8 @@ const convertDbtMetricToLightdashMetric = (metric, tableName, tableLabel, spotli
161
162
  sql = `CASE WHEN ${filterSql} THEN ${sql} ELSE NULL END`;
162
163
  }
163
164
  const groups = (0, dbt_1.convertToGroups)(metric.meta?.groups, metric.meta?.group_label);
164
- const spotlightVisibility = spotlightConfig?.default_visibility;
165
+ const spotlightVisibility = spotlightConfig.default_visibility;
166
+ const spotlightCategories = (0, lightdashProjectConfig_1.getCategoriesFromResource)('metric', metric.name, spotlightConfig, Array.from(new Set([...(modelCategories || [])])));
165
167
  return {
166
168
  fieldType: field_1.FieldType.METRIC,
167
169
  type,
@@ -189,13 +191,7 @@ const convertDbtMetricToLightdashMetric = (metric, tableName, tableLabel, spotli
189
191
  : [metric.meta.tags],
190
192
  }
191
193
  : {}),
192
- ...(spotlightVisibility !== undefined
193
- ? {
194
- spotlight: {
195
- visibility: spotlightVisibility,
196
- },
197
- }
198
- : {}),
194
+ ...(0, lightdashProjectConfig_1.getSpotlightConfigurationForResource)(spotlightVisibility, spotlightCategories),
199
195
  };
200
196
  };
201
197
  const convertTable = (adapterType, model, dbtMetrics, spotlightConfig, startOfWeek) => {
@@ -278,6 +274,7 @@ const convertTable = (adapterType, model, dbtMetrics, spotlightConfig, startOfWe
278
274
  default_visibility: model.meta.spotlight?.visibility ??
279
275
  spotlightConfig.default_visibility,
280
276
  },
277
+ modelCategories: model.meta.spotlight?.categories,
281
278
  }),
282
279
  ]));
283
280
  return [
@@ -299,13 +296,14 @@ const convertTable = (adapterType, model, dbtMetrics, spotlightConfig, startOfWe
299
296
  spotlightConfig: {
300
297
  ...spotlightConfig,
301
298
  default_visibility: model.meta.spotlight?.visibility ??
302
- spotlightConfig?.default_visibility,
299
+ spotlightConfig.default_visibility,
303
300
  },
301
+ modelCategories: model.meta.spotlight?.categories,
304
302
  }),
305
303
  ]));
306
304
  const convertedDbtMetrics = Object.fromEntries(dbtMetrics.map((metric) => [
307
305
  metric.name,
308
- convertDbtMetricToLightdashMetric(metric, model.name, tableLabel, spotlightConfig),
306
+ convertDbtMetricToLightdashMetric(metric, model.name, tableLabel, spotlightConfig, model.meta.spotlight?.categories),
309
307
  ]));
310
308
  const allMetrics = Object.values({
311
309
  ...convertedDbtMetrics,
@@ -319,6 +319,7 @@ exports.LIGHTDASH_TABLE_WITH_GROUP_BLOCK = {
319
319
  type: field_1.MetricType.COUNT_DISTINCT,
320
320
  spotlight: {
321
321
  visibility: 'show',
322
+ categories: [],
322
323
  },
323
324
  },
324
325
  },
@@ -399,6 +400,7 @@ exports.LIGHTDASH_TABLE_WITH_DBT_METRICS = {
399
400
  index: 0,
400
401
  spotlight: {
401
402
  visibility: 'show',
403
+ categories: [],
402
404
  },
403
405
  },
404
406
  dbt_metric_2: {
@@ -423,6 +425,7 @@ exports.LIGHTDASH_TABLE_WITH_DBT_METRICS = {
423
425
  index: 1,
424
426
  spotlight: {
425
427
  visibility: 'show',
428
+ categories: [],
426
429
  },
427
430
  },
428
431
  dbt_metric_3: {
@@ -447,6 +450,7 @@ exports.LIGHTDASH_TABLE_WITH_DBT_METRICS = {
447
450
  index: 2,
448
451
  spotlight: {
449
452
  visibility: 'show',
453
+ categories: [],
450
454
  },
451
455
  },
452
456
  dbt_metric_4: {
@@ -471,6 +475,7 @@ exports.LIGHTDASH_TABLE_WITH_DBT_METRICS = {
471
475
  index: 3,
472
476
  spotlight: {
473
477
  visibility: 'show',
478
+ categories: [],
474
479
  },
475
480
  },
476
481
  dbt_metric_5: {
@@ -495,6 +500,7 @@ exports.LIGHTDASH_TABLE_WITH_DBT_METRICS = {
495
500
  index: 4,
496
501
  spotlight: {
497
502
  visibility: 'show',
503
+ categories: [],
498
504
  },
499
505
  },
500
506
  },
@@ -524,6 +530,7 @@ exports.LIGHTDASH_TABLE_WITH_DBT_V9_METRICS = {
524
530
  index: 0,
525
531
  spotlight: {
526
532
  visibility: 'show',
533
+ categories: [],
527
534
  },
528
535
  },
529
536
  },
@@ -649,6 +656,7 @@ exports.LIGHTDASH_TABLE_WITH_METRICS = {
649
656
  requiredAttributes: undefined,
650
657
  spotlight: {
651
658
  visibility: 'show',
659
+ categories: [],
652
660
  },
653
661
  },
654
662
  total_num_participating_athletes: {
@@ -675,6 +683,7 @@ exports.LIGHTDASH_TABLE_WITH_METRICS = {
675
683
  requiredAttributes: undefined,
676
684
  spotlight: {
677
685
  visibility: 'show',
686
+ categories: [],
678
687
  },
679
688
  },
680
689
  },