@lightdash/common 0.1390.0 → 0.1391.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/schemas/json/lightdash-dbt-2.0.json +70 -0
- package/dist/types/dbt.d.ts +2 -1
- package/dist/types/dbt.js +16 -0
- package/dist/types/field.d.ts +2 -1
- package/dist/types/table.d.ts +2 -5
- package/dist/types/timeFrames.d.ts +4 -0
- package/dist/utils/filters.d.ts +3 -1
- package/dist/utils/filters.js +30 -2
- package/dist/utils/item.d.ts +1 -4
- package/package.json +1 -1
@@ -134,6 +134,7 @@
|
|
134
134
|
"type": "boolean"
|
135
135
|
},
|
136
136
|
"round": {
|
137
|
+
"description": "Rounds the metric to the specified number of decimal places",
|
137
138
|
"type": "number",
|
138
139
|
"minimum": 0
|
139
140
|
},
|
@@ -160,6 +161,30 @@
|
|
160
161
|
"minLength": 1
|
161
162
|
},
|
162
163
|
"maxItems": 3
|
164
|
+
},
|
165
|
+
"default_time_dimension": {
|
166
|
+
"type": "object",
|
167
|
+
"description": "Specifies the default time dimension field and interval to use for time-based analysis on this metric. If specified, both field and interval are required. If there is already a default time dimension set in the model, this will override it.",
|
168
|
+
"properties": {
|
169
|
+
"field": {
|
170
|
+
"type": "string",
|
171
|
+
"description": "The name of the field to use as the default time dimension"
|
172
|
+
},
|
173
|
+
"interval": {
|
174
|
+
"type": "string",
|
175
|
+
"enum": [
|
176
|
+
"DAY",
|
177
|
+
"WEEK",
|
178
|
+
"MONTH",
|
179
|
+
"YEAR"
|
180
|
+
],
|
181
|
+
"description": "The default time interval to use when analyzing this time dimension"
|
182
|
+
}
|
183
|
+
},
|
184
|
+
"required": [
|
185
|
+
"field",
|
186
|
+
"interval"
|
187
|
+
]
|
163
188
|
}
|
164
189
|
},
|
165
190
|
"required": ["type", "sql"]
|
@@ -303,6 +328,30 @@
|
|
303
328
|
"minLength": 1
|
304
329
|
},
|
305
330
|
"maxItems": 3
|
331
|
+
},
|
332
|
+
"default_time_dimension": {
|
333
|
+
"type": "object",
|
334
|
+
"description": "Specifies the default time dimension field and interval to use for time-based analysis on this metric. If specified, both field and interval are required. If there is already a default time dimension set in the model, this will override it.",
|
335
|
+
"properties": {
|
336
|
+
"field": {
|
337
|
+
"type": "string",
|
338
|
+
"description": "The name of the field to use as the default time dimension"
|
339
|
+
},
|
340
|
+
"interval": {
|
341
|
+
"type": "string",
|
342
|
+
"enum": [
|
343
|
+
"DAY",
|
344
|
+
"WEEK",
|
345
|
+
"MONTH",
|
346
|
+
"YEAR"
|
347
|
+
],
|
348
|
+
"description": "The default time interval to use when analyzing this time dimension"
|
349
|
+
}
|
350
|
+
},
|
351
|
+
"required": [
|
352
|
+
"field",
|
353
|
+
"interval"
|
354
|
+
]
|
306
355
|
}
|
307
356
|
},
|
308
357
|
"required": ["type"]
|
@@ -552,6 +601,27 @@
|
|
552
601
|
"percent",
|
553
602
|
"id"
|
554
603
|
]
|
604
|
+
},
|
605
|
+
"default_time_dimension": {
|
606
|
+
"type": "object",
|
607
|
+
"description": "Specifies the default time dimension field and interval to use for time-based analysis on this metric. If specified, both field and interval are required. If there is already a default time dimension set in the model, this will override it.",
|
608
|
+
"properties": {
|
609
|
+
"field": {
|
610
|
+
"type": "string",
|
611
|
+
"description": "The name of the field to use as the default time dimension"
|
612
|
+
},
|
613
|
+
"interval": {
|
614
|
+
"type": "string",
|
615
|
+
"enum": [
|
616
|
+
"DAY",
|
617
|
+
"WEEK",
|
618
|
+
"MONTH",
|
619
|
+
"YEAR"
|
620
|
+
],
|
621
|
+
"description": "The default time interval to use when analyzing this time dimension"
|
622
|
+
}
|
623
|
+
},
|
624
|
+
"required": ["field", "interval"]
|
555
625
|
}
|
556
626
|
}
|
557
627
|
}
|
package/dist/types/dbt.d.ts
CHANGED
@@ -2,7 +2,7 @@ import { DepGraph } from 'dependency-graph';
|
|
2
2
|
import { type ColumnInfo, type CompiledModelNode, type ParsedMetric } from './dbtFromSchema';
|
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
|
-
import { type TimeFrames } from './timeFrames';
|
5
|
+
import { type DefaultTimeDimension, type TimeFrames } from './timeFrames';
|
6
6
|
export declare enum SupportedDbtAdapter {
|
7
7
|
BIGQUERY = "bigquery",
|
8
8
|
DATABRICKS = "databricks",
|
@@ -125,6 +125,7 @@ export type DbtColumnLightdashMetric = {
|
|
125
125
|
[key: string]: any;
|
126
126
|
}[];
|
127
127
|
percentile?: number;
|
128
|
+
default_time_dimension?: DefaultTimeDimension;
|
128
129
|
} & DbtLightdashFieldTags;
|
129
130
|
export type DbtModelLightdashMetric = DbtColumnLightdashMetric & Required<Pick<DbtColumnLightdashMetric, 'sql'>>;
|
130
131
|
export declare const normaliseModelDatabase: (model: DbtRawModelNode, targetWarehouse: SupportedDbtAdapter) => DbtModelNode;
|
package/dist/types/dbt.js
CHANGED
@@ -165,6 +165,14 @@ const convertModelMetric = ({ modelName, name, metric, source, tableLabel, dimen
|
|
165
165
|
: [metric.tags],
|
166
166
|
}
|
167
167
|
: {}),
|
168
|
+
...(metric.default_time_dimension
|
169
|
+
? {
|
170
|
+
defaultTimeDimension: {
|
171
|
+
field: metric.default_time_dimension.field,
|
172
|
+
interval: metric.default_time_dimension.interval,
|
173
|
+
},
|
174
|
+
}
|
175
|
+
: {}),
|
168
176
|
};
|
169
177
|
};
|
170
178
|
exports.convertModelMetric = convertModelMetric;
|
@@ -185,6 +193,14 @@ const convertColumnMetric = ({ modelName, dimensionName, dimensionSql, name, met
|
|
185
193
|
? (0, item_1.getItemId)({ table: modelName, name: dimensionName })
|
186
194
|
: undefined,
|
187
195
|
requiredAttributes,
|
196
|
+
...(metric.default_time_dimension
|
197
|
+
? {
|
198
|
+
defaultTimeDimension: {
|
199
|
+
field: metric.default_time_dimension.field,
|
200
|
+
interval: metric.default_time_dimension.interval,
|
201
|
+
},
|
202
|
+
}
|
203
|
+
: {}),
|
188
204
|
});
|
189
205
|
exports.convertColumnMetric = convertColumnMetric;
|
190
206
|
var DbtManifestVersion;
|
package/dist/types/field.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { AdditionalMetric, currencies } from '..';
|
1
|
+
import type { AdditionalMetric, currencies, DefaultTimeDimension } from '..';
|
2
2
|
import { type MetricFilterRule } from './filter';
|
3
3
|
import { type TimeFrames } from './timeFrames';
|
4
4
|
export declare enum Compact {
|
@@ -238,6 +238,7 @@ export interface Metric extends Field {
|
|
238
238
|
formatOptions?: CustomFormat;
|
239
239
|
dimensionReference?: string;
|
240
240
|
requiredAttributes?: Record<string, string | string[]>;
|
241
|
+
defaultTimeDimension?: DefaultTimeDimension;
|
241
242
|
}
|
242
243
|
export declare const isFilterableDimension: (dimension: Dimension) => dimension is FilterableDimension;
|
243
244
|
export type FilterableField = TableCalculation | Metric | FilterableDimension | CustomSqlDimension;
|
package/dist/types/table.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { type MetricFilterRule } from './filter';
|
2
|
-
import type {
|
2
|
+
import type { DefaultTimeDimension } from './timeFrames';
|
3
3
|
export declare enum OrderFieldsByStrategy {
|
4
4
|
LABEL = "LABEL",
|
5
5
|
INDEX = "INDEX"
|
@@ -23,8 +23,5 @@ export type TableBase = {
|
|
23
23
|
hidden?: boolean;
|
24
24
|
requiredAttributes?: Record<string, string | string[]>;
|
25
25
|
groupDetails?: Record<string, GroupType>;
|
26
|
-
defaultTimeDimension?:
|
27
|
-
field: string;
|
28
|
-
interval: TimeFrames;
|
29
|
-
};
|
26
|
+
defaultTimeDimension?: DefaultTimeDimension;
|
30
27
|
};
|
package/dist/utils/filters.d.ts
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
import { type DashboardTile } from '../types/dashboard';
|
2
2
|
import { type Table } from '../types/explore';
|
3
3
|
import { type CompiledField, type CustomSqlDimension, type Dimension, type Field, type FilterableDimension, type FilterableField, type FilterableItem, type ItemsMap, type TableCalculation } from '../types/field';
|
4
|
-
import { FilterOperator, FilterType, type AndFilterGroup, type DashboardFieldTarget, type DashboardFilterRule, type DashboardFilters, type FilterDashboardToRule, type FilterGroup, type FilterGroupItem, type FilterRule, type Filters, type MetricFilterRule, type OrFilterGroup } from '../types/filter';
|
4
|
+
import { FilterOperator, FilterType, UnitOfTime, type AndFilterGroup, type DashboardFieldTarget, type DashboardFilterRule, type DashboardFilters, type FilterDashboardToRule, type FilterGroup, type FilterGroupItem, type FilterRule, type Filters, type MetricFilterRule, type OrFilterGroup } from '../types/filter';
|
5
5
|
import { type MetricQuery } from '../types/metricQuery';
|
6
|
+
import { TimeFrames } from '../types/timeFrames';
|
6
7
|
export declare const getFilterRulesFromGroup: (filterGroup: FilterGroup | undefined) => FilterRule[];
|
7
8
|
export declare const getTotalFilterRules: (filters: Filters) => FilterRule[];
|
8
9
|
export declare const countTotalFilterRules: (filters: Filters) => number;
|
@@ -10,6 +11,7 @@ export declare const hasNestedGroups: (filters: Filters) => boolean;
|
|
10
11
|
export declare const getItemsFromFilterGroup: (filterGroup: FilterGroup | undefined) => FilterGroupItem[];
|
11
12
|
export declare const getFilterGroupItemsPropertyName: (filterGroup: FilterGroup | undefined) => 'and' | 'or';
|
12
13
|
export declare const getFilterTypeFromItem: (item: FilterableField) => FilterType;
|
14
|
+
export declare const timeframeToUnitOfTime: (timeframe: TimeFrames) => UnitOfTime | undefined;
|
13
15
|
export declare const getFilterRuleWithDefaultValue: <T extends FilterRule<FilterOperator, import("../types/filter").FieldTarget, any, any>>(field: FilterableField, filterRule: T, values?: any[] | null) => T;
|
14
16
|
export declare const createFilterRuleFromField: (field: FilterableField, value?: any) => FilterRule;
|
15
17
|
export declare const matchFieldExact: (a: Field) => (b: Field) => boolean;
|
package/dist/utils/filters.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.resetRequiredFilterRules = exports.reduceRequiredDimensionFiltersToFilterRules = exports.isFilterRuleInQuery = exports.createFilterRuleFromRequiredMetricRule = exports.addDashboardFiltersToMetricQuery = exports.overrideFilterGroupWithFilterRules = exports.overrideChartFilter = exports.addFiltersToMetricQuery = exports.getDashboardFiltersForTileAndTables = exports.getDashboardFilterRulesForTileAndTables = exports.getDashboardFilterRulesForTables = exports.getTabUuidsForFilterRules = exports.getDashboardFilterRulesForTile = exports.deleteFilterRuleFromGroup = exports.getFiltersFromGroup = exports.isDimensionValueInvalidDate = exports.addFilterRule = exports.createDashboardFilterRuleFromField = exports.applyDefaultTileTargets = exports.isTileFilterable = exports.matchFieldByType = exports.matchFieldByTypeAndName = exports.matchFieldExact = exports.createFilterRuleFromField = exports.getFilterRuleWithDefaultValue = exports.getFilterTypeFromItem = exports.getFilterGroupItemsPropertyName = exports.getItemsFromFilterGroup = exports.hasNestedGroups = exports.countTotalFilterRules = exports.getTotalFilterRules = exports.getFilterRulesFromGroup = void 0;
|
3
|
+
exports.resetRequiredFilterRules = exports.reduceRequiredDimensionFiltersToFilterRules = exports.isFilterRuleInQuery = exports.createFilterRuleFromRequiredMetricRule = exports.addDashboardFiltersToMetricQuery = exports.overrideFilterGroupWithFilterRules = exports.overrideChartFilter = exports.addFiltersToMetricQuery = exports.getDashboardFiltersForTileAndTables = exports.getDashboardFilterRulesForTileAndTables = exports.getDashboardFilterRulesForTables = exports.getTabUuidsForFilterRules = exports.getDashboardFilterRulesForTile = exports.deleteFilterRuleFromGroup = exports.getFiltersFromGroup = exports.isDimensionValueInvalidDate = exports.addFilterRule = exports.createDashboardFilterRuleFromField = exports.applyDefaultTileTargets = exports.isTileFilterable = exports.matchFieldByType = exports.matchFieldByTypeAndName = exports.matchFieldExact = exports.createFilterRuleFromField = exports.getFilterRuleWithDefaultValue = exports.timeframeToUnitOfTime = exports.getFilterTypeFromItem = exports.getFilterGroupItemsPropertyName = exports.getItemsFromFilterGroup = exports.hasNestedGroups = exports.countTotalFilterRules = exports.getTotalFilterRules = exports.getFilterRulesFromGroup = void 0;
|
4
4
|
const tslib_1 = require("tslib");
|
5
5
|
const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
|
6
6
|
const moment_1 = tslib_1.__importDefault(require("moment"));
|
@@ -94,6 +94,31 @@ const getFilterTypeFromItem = (item) => {
|
|
94
94
|
}
|
95
95
|
};
|
96
96
|
exports.getFilterTypeFromItem = getFilterTypeFromItem;
|
97
|
+
const timeframeToUnitOfTime = (timeframe) => {
|
98
|
+
switch (timeframe) {
|
99
|
+
case timeFrames_1.TimeFrames.MILLISECOND:
|
100
|
+
return filter_1.UnitOfTime.milliseconds;
|
101
|
+
case timeFrames_1.TimeFrames.SECOND:
|
102
|
+
return filter_1.UnitOfTime.seconds;
|
103
|
+
case timeFrames_1.TimeFrames.MINUTE:
|
104
|
+
return filter_1.UnitOfTime.minutes;
|
105
|
+
case timeFrames_1.TimeFrames.HOUR:
|
106
|
+
return filter_1.UnitOfTime.hours;
|
107
|
+
case timeFrames_1.TimeFrames.DAY:
|
108
|
+
return filter_1.UnitOfTime.days;
|
109
|
+
case timeFrames_1.TimeFrames.WEEK:
|
110
|
+
return filter_1.UnitOfTime.weeks;
|
111
|
+
case timeFrames_1.TimeFrames.MONTH:
|
112
|
+
return filter_1.UnitOfTime.months;
|
113
|
+
case timeFrames_1.TimeFrames.QUARTER:
|
114
|
+
return filter_1.UnitOfTime.quarters;
|
115
|
+
case timeFrames_1.TimeFrames.YEAR:
|
116
|
+
return filter_1.UnitOfTime.years;
|
117
|
+
default:
|
118
|
+
return undefined;
|
119
|
+
}
|
120
|
+
};
|
121
|
+
exports.timeframeToUnitOfTime = timeframeToUnitOfTime;
|
97
122
|
const getFilterRuleWithDefaultValue = (field, filterRule, values) => {
|
98
123
|
const filterType = (0, exports.getFilterTypeFromItem)(field);
|
99
124
|
const filterRuleDefaults = {};
|
@@ -113,9 +138,12 @@ const getFilterRuleWithDefaultValue = (field, filterRule, values) => {
|
|
113
138
|
const numberValue = value === undefined || typeof value !== 'number'
|
114
139
|
? 1
|
115
140
|
: value;
|
141
|
+
const defaultUnitOfTime = (0, field_1.isDimension)(field) && field.timeInterval
|
142
|
+
? (0, exports.timeframeToUnitOfTime)(field.timeInterval)
|
143
|
+
: filter_1.UnitOfTime.days;
|
116
144
|
filterRuleDefaults.values = [numberValue];
|
117
145
|
filterRuleDefaults.settings = {
|
118
|
-
unitOfTime:
|
146
|
+
unitOfTime: defaultUnitOfTime,
|
119
147
|
completed: false,
|
120
148
|
};
|
121
149
|
}
|
package/dist/utils/item.d.ts
CHANGED
@@ -30,10 +30,7 @@ export declare const replaceDimensionInExplore: (explore: Explore, dimension: Co
|
|
30
30
|
hidden?: boolean | undefined;
|
31
31
|
requiredAttributes?: Record<string, string | string[]> | undefined;
|
32
32
|
groupDetails?: Record<string, import("..").GroupType> | undefined;
|
33
|
-
defaultTimeDimension?:
|
34
|
-
field: string;
|
35
|
-
interval: import("..").TimeFrames;
|
36
|
-
} | undefined;
|
33
|
+
defaultTimeDimension?: import("..").DefaultTimeDimension | undefined;
|
37
34
|
metrics: Record<string, import("../types/field").CompiledMetric>;
|
38
35
|
lineageGraph: import("..").LineageGraph;
|
39
36
|
source?: import("../types/field").Source | undefined;
|