@lightdash/common 0.1401.0 → 0.1403.0
Sign up to get free protection for your applications and to get access to all the features.
package/dist/types/catalog.d.ts
CHANGED
@@ -146,4 +146,8 @@ export type ChartUsageIn = CatalogFieldWhere & {
|
|
146
146
|
chartUsage: number;
|
147
147
|
};
|
148
148
|
export declare const indexCatalogJob = "indexCatalog";
|
149
|
+
export type ApiMetricsWithAssociatedTimeDimensionResponse = {
|
150
|
+
status: 'ok';
|
151
|
+
results: MetricWithAssociatedTimeDimension[];
|
152
|
+
};
|
149
153
|
export {};
|
@@ -24,6 +24,7 @@ export type MetricExploreDataPoint = {
|
|
24
24
|
};
|
25
25
|
export type MetricsExplorerQueryResults = {
|
26
26
|
metric: MetricWithAssociatedTimeDimension;
|
27
|
+
comparisonMetric: MetricWithAssociatedTimeDimension | undefined;
|
27
28
|
rows: ResultRow[];
|
28
29
|
comparisonRows: ResultRow[] | undefined;
|
29
30
|
fields: ItemsMap;
|
@@ -9,13 +9,15 @@ import type { ResultRow } from '../types/results';
|
|
9
9
|
import { TimeFrames, type DefaultTimeDimension } from '../types/timeFrames';
|
10
10
|
type DateFilter = FilterRule<ConditionalOperator, FieldTarget, unknown, DateFilterSettings>;
|
11
11
|
type ImpelemntedTimeframe = TimeFrames.DAY | TimeFrames.WEEK | TimeFrames.MONTH | TimeFrames.YEAR;
|
12
|
+
type UnimplementedTimeframe = Exclude<TimeFrames, ImpelemntedTimeframe>;
|
13
|
+
export declare const assertUnimplementedTimeframe: (timeframe: UnimplementedTimeframe) => never;
|
12
14
|
export declare const getFieldIdForDateDimension: (fieldId: string, timeframe: TimeFrames) => string;
|
13
15
|
export declare const oneYearBack: (date: Date) => Date;
|
14
16
|
export declare const oneYearForward: (date: Date) => Date;
|
15
17
|
export declare const getGrainForDateRange: (dateRange: [Date, Date]) => ImpelemntedTimeframe;
|
16
18
|
export declare const getMetricExplorerDateRangeFilters: (exploreName: string, dimensionName: string, dateRange: MetricExplorerDateRange) => DateFilter[];
|
17
19
|
export declare const getMetricExplorerDataPoints: (dimension: Dimension, metric: MetricWithAssociatedTimeDimension, metricRows: ResultRow[]) => Array<MetricExploreDataPoint>;
|
18
|
-
export declare const getMetricExplorerDataPointsWithCompare: (dimension: Dimension, metric: MetricWithAssociatedTimeDimension, metricRows: ResultRow[], compareMetricRows: ResultRow[], comparison: MetricExplorerComparisonType) => Array<MetricExploreDataPoint>;
|
20
|
+
export declare const getMetricExplorerDataPointsWithCompare: (dimension: Dimension, compareDimension: Dimension, metric: MetricWithAssociatedTimeDimension, metricRows: ResultRow[], compareMetricRows: ResultRow[], comparison: MetricExplorerComparisonType) => Array<MetricExploreDataPoint>;
|
19
21
|
/**
|
20
22
|
* Get the date range for a given time interval, based on the current date and the time interval
|
21
23
|
* Time grain Year: -> past 5 years (i.e. 5 completed years + this uncompleted year)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.getAvailableTimeDimensionsFromTables = exports.getDefaultTimeDimension = exports.getFirstAvailableTimeDimension = exports.DEFAULT_METRICS_EXPLORER_TIME_INTERVAL = exports.getDefaultDateRangeFromInterval = exports.getMetricExplorerDataPointsWithCompare = exports.getMetricExplorerDataPoints = exports.getMetricExplorerDateRangeFilters = exports.getGrainForDateRange = exports.oneYearForward = exports.oneYearBack = exports.getFieldIdForDateDimension = void 0;
|
3
|
+
exports.getAvailableTimeDimensionsFromTables = exports.getDefaultTimeDimension = exports.getFirstAvailableTimeDimension = exports.DEFAULT_METRICS_EXPLORER_TIME_INTERVAL = exports.getDefaultDateRangeFromInterval = exports.getMetricExplorerDataPointsWithCompare = exports.getMetricExplorerDataPoints = exports.getMetricExplorerDateRangeFilters = exports.getGrainForDateRange = exports.oneYearForward = exports.oneYearBack = exports.getFieldIdForDateDimension = exports.assertUnimplementedTimeframe = void 0;
|
4
4
|
const tslib_1 = require("tslib");
|
5
5
|
const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
|
6
6
|
const lodash_1 = require("lodash");
|
@@ -36,6 +36,7 @@ const assertUnimplementedTimeframe = (timeframe) => {
|
|
36
36
|
return (0, assertUnreachable_1.default)(timeframe, `Unknown time interval: "${timeframe}"`);
|
37
37
|
}
|
38
38
|
};
|
39
|
+
exports.assertUnimplementedTimeframe = assertUnimplementedTimeframe;
|
39
40
|
const getFieldIdForDateDimension = (fieldId, timeframe) => {
|
40
41
|
switch (timeframe) {
|
41
42
|
case timeFrames_1.TimeFrames.DAY:
|
@@ -47,7 +48,7 @@ const getFieldIdForDateDimension = (fieldId, timeframe) => {
|
|
47
48
|
case timeFrames_1.TimeFrames.YEAR:
|
48
49
|
return `${fieldId}_year`;
|
49
50
|
default:
|
50
|
-
return assertUnimplementedTimeframe(timeframe);
|
51
|
+
return (0, exports.assertUnimplementedTimeframe)(timeframe);
|
51
52
|
}
|
52
53
|
};
|
53
54
|
exports.getFieldIdForDateDimension = getFieldIdForDateDimension;
|
@@ -99,7 +100,7 @@ exports.getMetricExplorerDateRangeFilters = getMetricExplorerDateRangeFilters;
|
|
99
100
|
const getMetricExplorerDataPoints = (dimension, metric, metricRows) => {
|
100
101
|
const dimensionId = (0, item_1.getItemId)(dimension);
|
101
102
|
const metricId = (0, item_1.getItemId)(metric);
|
102
|
-
const groupByMetricRows = (0, lodash_1.groupBy)(metricRows, (row) => new Date(String(row[dimensionId].value.raw)).
|
103
|
+
const groupByMetricRows = (0, lodash_1.groupBy)(metricRows, (row) => new Date(String(row[dimensionId].value.raw)).toISOString());
|
103
104
|
return Object.keys(groupByMetricRows).map((date) => ({
|
104
105
|
date: new Date(date),
|
105
106
|
metric: groupByMetricRows[date]?.[0]?.[metricId]?.value.raw ?? null,
|
@@ -107,17 +108,17 @@ const getMetricExplorerDataPoints = (dimension, metric, metricRows) => {
|
|
107
108
|
}));
|
108
109
|
};
|
109
110
|
exports.getMetricExplorerDataPoints = getMetricExplorerDataPoints;
|
110
|
-
const getMetricExplorerDataPointsWithCompare = (dimension, metric, metricRows, compareMetricRows, comparison) => {
|
111
|
+
const getMetricExplorerDataPointsWithCompare = (dimension, compareDimension, metric, metricRows, compareMetricRows, comparison) => {
|
111
112
|
if (comparison.type === metricsExplorer_1.MetricExplorerComparison.NONE) {
|
112
113
|
throw new Error('Comparison type is required');
|
113
114
|
}
|
114
|
-
const dimensionId = (0, item_1.getItemId)(dimension);
|
115
115
|
const metricId = (0, item_1.getItemId)(metric);
|
116
|
-
const
|
117
|
-
const
|
118
|
-
const
|
116
|
+
const dimensionId = (0, item_1.getItemId)(dimension);
|
117
|
+
const compareDimensionId = (0, item_1.getItemId)(compareDimension);
|
118
|
+
const groupByMetricRows = (0, lodash_1.groupBy)(metricRows, (row) => new Date(String(row[dimensionId].value.raw)).toISOString());
|
119
|
+
const groupByCompareMetricRows = (0, lodash_1.groupBy)(compareMetricRows, (row) => new Date(String(row[compareDimensionId].value.raw)).toISOString());
|
119
120
|
const offsetGroupByCompareMetricRows = (0, lodash_1.mapKeys)(groupByCompareMetricRows, (_, date) => comparison.type === metricsExplorer_1.MetricExplorerComparison.PREVIOUS_PERIOD
|
120
|
-
? (0, exports.oneYearForward)(new Date(date)).
|
121
|
+
? (0, exports.oneYearForward)(new Date(date)).toISOString()
|
121
122
|
: date);
|
122
123
|
const dates = new Set([
|
123
124
|
...Object.keys(groupByMetricRows),
|
@@ -170,7 +171,7 @@ const getDefaultDateRangeFromInterval = (timeInterval) => {
|
|
170
171
|
now.toDate(),
|
171
172
|
];
|
172
173
|
default:
|
173
|
-
return assertUnimplementedTimeframe(timeInterval);
|
174
|
+
return (0, exports.assertUnimplementedTimeframe)(timeInterval);
|
174
175
|
}
|
175
176
|
};
|
176
177
|
exports.getDefaultDateRangeFromInterval = getDefaultDateRangeFromInterval;
|