@lightdash/common 3.207.0 → 3.209.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/cjs/.tsbuildinfo +1 -1
  2. package/dist/cjs/compiler/translator.d.ts +2 -1
  3. package/dist/cjs/compiler/translator.d.ts.map +1 -1
  4. package/dist/cjs/compiler/translator.js +175 -121
  5. package/dist/cjs/compiler/translator.js.map +1 -1
  6. package/dist/cjs/dbt/schemas/lightdashMetadata.json +7 -0
  7. package/dist/cjs/schemas/json/lightdash-dbt-2.0.json +296 -267
  8. package/dist/cjs/types/dbt.d.ts +5 -0
  9. package/dist/cjs/types/dbt.d.ts.map +1 -1
  10. package/dist/cjs/types/dbt.js.map +1 -1
  11. package/dist/cjs/utils/filters.d.ts +9 -0
  12. package/dist/cjs/utils/filters.d.ts.map +1 -1
  13. package/dist/cjs/utils/filters.js +5 -4
  14. package/dist/cjs/utils/filters.js.map +1 -1
  15. package/dist/esm/.tsbuildinfo +1 -1
  16. package/dist/esm/compiler/translator.d.ts +2 -1
  17. package/dist/esm/compiler/translator.d.ts.map +1 -1
  18. package/dist/esm/compiler/translator.js +173 -120
  19. package/dist/esm/compiler/translator.js.map +1 -1
  20. package/dist/esm/dbt/schemas/lightdashMetadata.json +7 -0
  21. package/dist/esm/schemas/json/lightdash-dbt-2.0.json +296 -267
  22. package/dist/esm/types/dbt.d.ts +5 -0
  23. package/dist/esm/types/dbt.d.ts.map +1 -1
  24. package/dist/esm/types/dbt.js.map +1 -1
  25. package/dist/esm/utils/filters.d.ts +9 -0
  26. package/dist/esm/utils/filters.d.ts.map +1 -1
  27. package/dist/esm/utils/filters.js +1 -1
  28. package/dist/esm/utils/filters.js.map +1 -1
  29. package/dist/types/.tsbuildinfo +1 -1
  30. package/dist/types/compiler/translator.d.ts +2 -1
  31. package/dist/types/compiler/translator.d.ts.map +1 -1
  32. package/dist/types/compiler/translator.js +173 -120
  33. package/dist/types/compiler/translator.js.map +1 -1
  34. package/dist/types/dbt/schemas/lightdashMetadata.json +7 -0
  35. package/dist/types/schemas/json/lightdash-dbt-2.0.json +296 -267
  36. package/dist/types/types/dbt.d.ts +5 -0
  37. package/dist/types/types/dbt.d.ts.map +1 -1
  38. package/dist/types/types/dbt.js.map +1 -1
  39. package/dist/types/utils/filters.d.ts +9 -0
  40. package/dist/types/utils/filters.d.ts.map +1 -1
  41. package/dist/types/utils/filters.js +1 -1
  42. package/dist/types/utils/filters.js.map +1 -1
  43. package/package.json +1 -1
@@ -1,9 +1,10 @@
1
- import { SupportedDbtAdapter, type DbtModelColumn, type DbtModelNode, type ModelInventoryEntry } from '../types/dbt';
1
+ import { SupportedDbtAdapter, type DbtModelColumn, type DbtModelNode, type DbtRawModelNode, type ModelInventoryEntry } from '../types/dbt';
2
2
  import { type Explore, type ExploreError, type Table } from '../types/explore';
3
3
  import { type CustomGranularity, type LightdashProjectConfig } from '../types/lightdashProjectConfig';
4
4
  import { type TimeFrames } from '../types/timeFrames';
5
5
  import { type WarehouseCatalog, type WarehouseCatalogMissingEntry, type WarehouseSqlBuilder } from '../types/warehouse';
6
6
  import { type ResolvedAdditionalTimeIntervals, type WeekDay } from '../utils/timeFrames';
7
+ export declare const hasModelAdditionalDimension: (model: Pick<DbtRawModelNode, 'meta' | 'config'>) => boolean;
7
8
  export declare const convertTable: (adapterType: SupportedDbtAdapter, model: DbtModelNode, spotlightConfig: LightdashProjectConfig['spotlight'], startOfWeek?: WeekDay | null, disableTimestampConversion?: boolean, customGranularities?: Record<string, CustomGranularity>, allowPartialCompilation?: boolean, additionalTimeIntervals?: ResolvedAdditionalTimeIntervals, granularityLabels?: Partial<Record<TimeFrames, string>>) => Omit<Table, 'lineageGraph'>;
8
9
  export type ExplorePostProcessor = (compiledExplores: Explore[], context: {
9
10
  model: DbtModelNode;
@@ -1 +1 @@
1
- {"version":3,"file":"translator.d.ts","sourceRoot":"","sources":["../../../src/compiler/translator.ts"],"names":[],"mappings":"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IAC7C,cAAc,EAAE,4BAA4B,EAAE,CAAC;CAmDlD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,gCAAgC,kBAC1B,gBAAgB,UACvB,YAAY,EAAE,gBACR,4BAA4B,EAAE,yBACrB,OAAO,KAC/B,OA6BF,CAAC;AAEF,eAAO,MAAM,mBAAmB,WACpB,YAAY,EAAE,oBACJ,gBAAgB,+BACN,OAAO,0BACZ,OAAO,kBACd,CAAC,WAAW,EAAE,sBAAsB,KAAK,IAAI,wBACxC,4BAA4B,EAAE,KACpD,YAAY,EA4Ld,CAAC;AAEF,eAAO,MAAM,+BAA+B,cAC7B,YAAY,EAAE,KAC1B;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EAK/C,CAAC"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSchemaStructureFromDbtModels = exports.attachTypesToModels = exports.haveMissingCatalogEntriesChanged = exports.getMissingCatalogEntries = exports.convertExplores = exports.instantiateNestedTables = exports.getNestedTableTemplates = exports.getNestedTableName = exports.convertTable = void 0;
3
+ exports.getSchemaStructureFromDbtModels = exports.attachTypesToModels = exports.haveMissingCatalogEntriesChanged = exports.getMissingCatalogEntries = exports.convertExplores = exports.instantiateNestedTables = exports.getNestedTableTemplates = exports.getNestedTableName = exports.convertTable = exports.hasModelAdditionalDimension = void 0;
4
4
  exports.iterateExplores = iterateExplores;
5
5
  const tslib_1 = require("tslib");
6
6
  const compat_1 = require("es-toolkit/compat");
@@ -458,12 +458,134 @@ function dropMapValuedModelFilters(owner, filters, allowPartialCompilation) {
458
458
  });
459
459
  return { filters: validFilters, warnings };
460
460
  }
461
+ // Model-level additional dimensions have no column to fall back on.
462
+ const isCompleteAdditionalDimension = (config) => Boolean(config.type && config.sql);
463
+ const getModelAdditionalDimensions = (model) => (0, compat_1.merge)({}, model.meta, model.config?.meta).additional_dimensions ?? {};
464
+ const hasModelAdditionalDimension = (model) => Object.values(getModelAdditionalDimensions(model)).some(isCompleteAdditionalDimension);
465
+ exports.hasModelAdditionalDimension = hasModelAdditionalDimension;
461
466
  const convertTable = (adapterType, model, spotlightConfig, startOfWeek, disableTimestampConversion, customGranularities, allowPartialCompilation, additionalTimeIntervals, granularityLabels) => {
462
467
  // Config block takes priority, then meta block
463
468
  const meta = (0, compat_1.merge)({}, model.meta, model.config?.meta);
464
469
  const tableLabel = meta.label || (0, field_1.friendlyName)(model.name);
465
470
  const tableWarnings = [];
466
- const [dimensions, metrics] = Object.values(model.columns).reduce(([prevDimensions, prevMetrics], column, index) => {
471
+ const processIntervalDimension = (dim, overrideTimeIntervals, column, columnMeta, index) => {
472
+ if (dim.isIntervalBase) {
473
+ let allIntervals = [];
474
+ if (!dim.isAdditionalDimension &&
475
+ columnMeta.dimension?.time_intervals &&
476
+ Array.isArray(columnMeta?.dimension.time_intervals)) {
477
+ allIntervals = columnMeta.dimension.time_intervals;
478
+ }
479
+ else if (dim.isAdditionalDimension &&
480
+ Array.isArray(overrideTimeIntervals)) {
481
+ allIntervals = overrideTimeIntervals;
482
+ }
483
+ else {
484
+ allIntervals = (0, timeFrames_1.getTimeFramesWithProjectDefaults)(dim.type, additionalTimeIntervals);
485
+ }
486
+ // Split into standard TimeFrames and custom granularity names
487
+ const intervals = (0, timeFrames_1.validateTimeFrames)(allIntervals);
488
+ const customIntervalNames = allIntervals.filter((v) => !(0, timeFrames_1.isTimeInterval)(v.toUpperCase()));
489
+ const dimensionMeta = {
490
+ ...columnMeta.dimension,
491
+ type: dim.type,
492
+ label: dim.label,
493
+ groups: dim.groups,
494
+ sql: dim.sql,
495
+ description: dim.description,
496
+ hidden: dim.hidden,
497
+ // Additional-dim children must inherit the additional
498
+ // dimension's own resolved domain, not the parent
499
+ // column's annotation riding in the meta spread.
500
+ timestamp_domain: dim.timestampDomain,
501
+ };
502
+ // Generate standard interval dimensions
503
+ const standardDims = intervals.reduce((acc, interval) => ({
504
+ ...acc,
505
+ [`${dim.name}_${interval.toLowerCase()}`]: convertDimension(index, adapterType, model, tableLabel, {
506
+ ...column,
507
+ ...('isAdditionalDimension' in dim &&
508
+ dim.isAdditionalDimension
509
+ ? {
510
+ name: dim.name,
511
+ meta: {
512
+ dimension: dimensionMeta,
513
+ },
514
+ // In dbt 1.10+, config.meta takes precedence over meta
515
+ // so we must set config.meta.dimension to prevent
516
+ // the base dimension's properties from overwriting
517
+ config: {
518
+ meta: {
519
+ dimension: dimensionMeta,
520
+ },
521
+ },
522
+ }
523
+ : {}),
524
+ }, undefined, interval, startOfWeek, 'isAdditionalDimension' in dim &&
525
+ dim.isAdditionalDimension,
526
+ // Additional-dim children derive from the
527
+ // parent's compiled sql, which already
528
+ // carries the timestamp conversion.
529
+ dim.isAdditionalDimension
530
+ ? true
531
+ : disableTimestampConversion, undefined, granularityLabels),
532
+ }), {});
533
+ // Generate custom granularity dimensions
534
+ const customDims = customIntervalNames.reduce((acc, customName) => {
535
+ const granularity = customGranularities?.[customName];
536
+ if (!granularity) {
537
+ tableWarnings.push({
538
+ type: explore_1.InlineErrorType.FIELD_ERROR,
539
+ message: `Unknown time interval "${customName}" on column "${dim.name}" in model "${model.name}". It is not a standard time frame or a custom granularity defined in lightdash.config.yml.`,
540
+ });
541
+ return acc;
542
+ }
543
+ const customSql = granularity.sql.replace(/\$\{COLUMN\}/g, () => dim.sql);
544
+ const customType = granularity.type || field_1.DimensionType.DATE;
545
+ const customDimName = `${dim.name}_${customName}`;
546
+ const groups = [...(dim.groups || [])];
547
+ if (!groups.includes(dim.label)) {
548
+ groups.push(dim.label);
549
+ }
550
+ return {
551
+ ...acc,
552
+ [customDimName]: {
553
+ index,
554
+ fieldType: field_1.FieldType.DIMENSION,
555
+ name: customDimName,
556
+ label: granularity.label,
557
+ sql: customSql,
558
+ table: model.name,
559
+ tableLabel,
560
+ type: customType,
561
+ description: dim.description,
562
+ source: undefined,
563
+ timeInterval: undefined,
564
+ timeIntervalBaseDimensionName: dim.name,
565
+ timeIntervalBaseDimensionType: dim.type,
566
+ customTimeInterval: customName,
567
+ hidden: dim.hidden,
568
+ format: undefined,
569
+ round: undefined,
570
+ compact: undefined,
571
+ requiredAttributes: dim.requiredAttributes,
572
+ anyAttributes: dim.anyAttributes,
573
+ groups,
574
+ isIntervalBase: false,
575
+ isAdditionalDimension: dim.isAdditionalDimension,
576
+ ...(dim.skipTimezoneConversion
577
+ ? { skipTimezoneConversion: true }
578
+ : {}),
579
+ // Custom granularity SQL may change the base
580
+ // column's domain, so keep its output unknown.
581
+ },
582
+ };
583
+ }, {});
584
+ return { ...standardDims, ...customDims };
585
+ }
586
+ return {};
587
+ };
588
+ const [columnDimensions, metrics] = Object.values(model.columns).reduce(([prevDimensions, prevMetrics], column, index) => {
467
589
  // Config block takes priority, then meta block
468
590
  const columnMeta = (0, compat_1.merge)({}, column.meta, column.config?.meta);
469
591
  const routedByUnnest = !columnMeta.dimension?.sql;
@@ -482,125 +604,10 @@ const convertTable = (adapterType, model, spotlightConfig, startOfWeek, disableT
482
604
  const dimension = isContainer
483
605
  ? undefined
484
606
  : convertDimension(index, adapterType, model, tableLabel, column, undefined, undefined, startOfWeek, undefined, disableTimestampConversion, tableWarnings, granularityLabels);
485
- const processIntervalDimension = (dim, overrideTimeIntervals) => {
486
- if (dim.isIntervalBase) {
487
- let allIntervals = [];
488
- if (!dim.isAdditionalDimension &&
489
- columnMeta.dimension?.time_intervals &&
490
- Array.isArray(columnMeta?.dimension.time_intervals)) {
491
- allIntervals = columnMeta.dimension.time_intervals;
492
- }
493
- else if (dim.isAdditionalDimension &&
494
- Array.isArray(overrideTimeIntervals)) {
495
- allIntervals = overrideTimeIntervals;
496
- }
497
- else {
498
- allIntervals = (0, timeFrames_1.getTimeFramesWithProjectDefaults)(dim.type, additionalTimeIntervals);
499
- }
500
- // Split into standard TimeFrames and custom granularity names
501
- const intervals = (0, timeFrames_1.validateTimeFrames)(allIntervals);
502
- const customIntervalNames = allIntervals.filter((v) => !(0, timeFrames_1.isTimeInterval)(v.toUpperCase()));
503
- const dimensionMeta = {
504
- ...columnMeta.dimension,
505
- type: dim.type,
506
- label: dim.label,
507
- groups: dim.groups,
508
- sql: dim.sql,
509
- description: dim.description,
510
- hidden: dim.hidden,
511
- // Additional-dim children must inherit the additional
512
- // dimension's own resolved domain, not the parent
513
- // column's annotation riding in the meta spread.
514
- timestamp_domain: dim.timestampDomain,
515
- };
516
- // Generate standard interval dimensions
517
- const standardDims = intervals.reduce((acc, interval) => ({
518
- ...acc,
519
- [`${dim.name}_${interval.toLowerCase()}`]: convertDimension(index, adapterType, model, tableLabel, {
520
- ...column,
521
- ...('isAdditionalDimension' in dim &&
522
- dim.isAdditionalDimension
523
- ? {
524
- name: dim.name,
525
- meta: {
526
- dimension: dimensionMeta,
527
- },
528
- // In dbt 1.10+, config.meta takes precedence over meta
529
- // so we must set config.meta.dimension to prevent
530
- // the base dimension's properties from overwriting
531
- config: {
532
- meta: {
533
- dimension: dimensionMeta,
534
- },
535
- },
536
- }
537
- : {}),
538
- }, undefined, interval, startOfWeek, 'isAdditionalDimension' in dim &&
539
- dim.isAdditionalDimension,
540
- // Additional-dim children derive from the
541
- // parent's compiled sql, which already
542
- // carries the timestamp conversion.
543
- dim.isAdditionalDimension
544
- ? true
545
- : disableTimestampConversion, undefined, granularityLabels),
546
- }), {});
547
- // Generate custom granularity dimensions
548
- const customDims = customIntervalNames.reduce((acc, customName) => {
549
- const granularity = customGranularities?.[customName];
550
- if (!granularity) {
551
- tableWarnings.push({
552
- type: explore_1.InlineErrorType.FIELD_ERROR,
553
- message: `Unknown time interval "${customName}" on column "${dim.name}" in model "${model.name}". It is not a standard time frame or a custom granularity defined in lightdash.config.yml.`,
554
- });
555
- return acc;
556
- }
557
- const customSql = granularity.sql.replace(/\$\{COLUMN\}/g, () => dim.sql);
558
- const customType = granularity.type || field_1.DimensionType.DATE;
559
- const customDimName = `${dim.name}_${customName}`;
560
- const groups = [...(dim.groups || [])];
561
- if (!groups.includes(dim.label)) {
562
- groups.push(dim.label);
563
- }
564
- return {
565
- ...acc,
566
- [customDimName]: {
567
- index,
568
- fieldType: field_1.FieldType.DIMENSION,
569
- name: customDimName,
570
- label: granularity.label,
571
- sql: customSql,
572
- table: model.name,
573
- tableLabel,
574
- type: customType,
575
- description: dim.description,
576
- source: undefined,
577
- timeInterval: undefined,
578
- timeIntervalBaseDimensionName: dim.name,
579
- timeIntervalBaseDimensionType: dim.type,
580
- customTimeInterval: customName,
581
- hidden: dim.hidden,
582
- format: undefined,
583
- round: undefined,
584
- compact: undefined,
585
- requiredAttributes: dim.requiredAttributes,
586
- anyAttributes: dim.anyAttributes,
587
- groups,
588
- isIntervalBase: false,
589
- isAdditionalDimension: dim.isAdditionalDimension,
590
- ...(dim.skipTimezoneConversion
591
- ? { skipTimezoneConversion: true }
592
- : {}),
593
- // Custom granularity SQL may change the base
594
- // column's domain, so keep its output unknown.
595
- },
596
- };
597
- }, {});
598
- return { ...standardDims, ...customDims };
599
- }
600
- return {};
601
- };
602
607
  let extraDimensions = dimension
603
- ? { ...processIntervalDimension(dimension, undefined) }
608
+ ? {
609
+ ...processIntervalDimension(dimension, undefined, column, columnMeta, index),
610
+ }
604
611
  : {};
605
612
  extraDimensions = Object.entries(columnMeta.additional_dimensions || {}).reduce((acc, [subDimensionName, subDimension]) => {
606
613
  const additionalDim = convertDimension(index, adapterType, model, tableLabel, {
@@ -619,7 +626,7 @@ const convertTable = (adapterType, model, spotlightConfig, startOfWeek, disableT
619
626
  ...acc,
620
627
  // When the additional dim is interval AND the base dimension is a interval base then we want to compute all additional dims with the parent intervals otherwise just set the additional dim
621
628
  [subDimensionName]: additionalDim,
622
- ...processIntervalDimension(additionalDim, subDimension.time_intervals),
629
+ ...processIntervalDimension(additionalDim, subDimension.time_intervals, column, columnMeta, index),
623
630
  };
624
631
  }, extraDimensions);
625
632
  // Metrics under an array of scalars aggregate its elements and
@@ -662,6 +669,53 @@ const convertTable = (adapterType, model, spotlightConfig, startOfWeek, disableT
662
669
  { ...prevMetrics, ...columnMetrics },
663
670
  ];
664
671
  }, [{}, {}]);
672
+ const dimensions = { ...columnDimensions };
673
+ const metricNames = new Set([
674
+ ...Object.keys(metrics),
675
+ ...Object.keys(meta.metrics ?? {}),
676
+ ]);
677
+ const isDuplicateDimension = (name) => {
678
+ const existing = (dimensions[name] && 'dimension') ||
679
+ (metricNames.has(name) && 'metric');
680
+ if (!existing)
681
+ return false;
682
+ tableWarnings.push({
683
+ type: explore_1.InlineErrorType.DUPLICATE_FIELD_NAME,
684
+ message: `Skipped additional dimension "${name}" in model "${model.name}" because a ${existing} with the same name exists.`,
685
+ });
686
+ return true;
687
+ };
688
+ const columnCount = Object.keys(model.columns).length;
689
+ Object.entries(getModelAdditionalDimensions(model)).forEach(([name, config], position) => {
690
+ if (!isCompleteAdditionalDimension(config)) {
691
+ const missing = [
692
+ ...(config.type ? [] : ['type']),
693
+ ...(config.sql ? [] : ['sql']),
694
+ ]
695
+ .map((key) => `"${key}"`)
696
+ .join(' and ');
697
+ tableWarnings.push({
698
+ type: explore_1.InlineErrorType.FIELD_ERROR,
699
+ message: `Skipped additional dimension "${name}" in model "${model.name}" because it is missing ${missing}. Model-level additional dimensions need both "type" and "sql".`,
700
+ });
701
+ return;
702
+ }
703
+ if (isDuplicateDimension(name))
704
+ return;
705
+ const index = columnCount + position;
706
+ const column = {
707
+ name,
708
+ data_type: config.type,
709
+ meta: { dimension: config },
710
+ };
711
+ const baseDimension = convertDimension(index, adapterType, model, tableLabel, column, undefined, undefined, startOfWeek, true, disableTimestampConversion, tableWarnings, granularityLabels);
712
+ dimensions[name] = baseDimension;
713
+ Object.entries(processIntervalDimension(baseDimension, config.time_intervals, column, { dimension: config }, index)).forEach(([intervalName, intervalDimension]) => {
714
+ if (!isDuplicateDimension(intervalName)) {
715
+ dimensions[intervalName] = intervalDimension;
716
+ }
717
+ });
718
+ });
665
719
  const modelMetrics = Object.fromEntries(Object.entries(meta.metrics || {}).map(([name, metric]) => [
666
720
  name,
667
721
  (0, dbt_1.convertModelMetric)({