@lightdash/common 0.1426.3 → 0.1428.0

Sign up to get free protection for your applications and to get access to all the features.
package/dist/types/dbt.js CHANGED
@@ -157,14 +157,14 @@ const convertModelMetric = ({ modelName, name, metric, source, tableLabel, dimen
157
157
  percentile: metric.percentile,
158
158
  dimensionReference,
159
159
  requiredAttributes,
160
- ...(metric.urls ? { urls: metric.urls } : {}),
160
+ ...(metric.urls ? { urls: metric.urls } : null),
161
161
  ...(metric.tags
162
162
  ? {
163
163
  tags: Array.isArray(metric.tags)
164
164
  ? metric.tags
165
165
  : [metric.tags],
166
166
  }
167
- : {}),
167
+ : null),
168
168
  ...(metric.default_time_dimension
169
169
  ? {
170
170
  defaultTimeDimension: {
@@ -172,7 +172,7 @@ const convertModelMetric = ({ modelName, name, metric, source, tableLabel, dimen
172
172
  interval: metric.default_time_dimension.interval,
173
173
  },
174
174
  }
175
- : {}),
175
+ : null),
176
176
  };
177
177
  };
178
178
  exports.convertModelMetric = convertModelMetric;
@@ -200,7 +200,7 @@ const convertColumnMetric = ({ modelName, dimensionName, dimensionSql, name, met
200
200
  interval: metric.default_time_dimension.interval,
201
201
  },
202
202
  }
203
- : {}),
203
+ : null),
204
204
  });
205
205
  exports.convertColumnMetric = convertColumnMetric;
206
206
  var DbtManifestVersion;
@@ -12,12 +12,12 @@ EMPTY_STRING = '' {
12
12
  return {
13
13
  type: '${filter_1.FilterOperator.EQUALS}',
14
14
  values: [],
15
- is: true,
15
+ is: true,
16
16
  }
17
17
  }
18
18
 
19
19
  EXPRESSION
20
- = NUMERICAL / DATE_RESTRICTION / LIST / TERM
20
+ = NUMERICAL / DATE_RESTRICTION / LIST / TERM
21
21
 
22
22
 
23
23
  NUMERICAL = SPACE_SYMBOL* operator:OPERATOR SPACE_SYMBOL* value:NUMBER {
@@ -28,7 +28,7 @@ NUMERICAL = SPACE_SYMBOL* operator:OPERATOR SPACE_SYMBOL* value:NUMBER {
28
28
  }
29
29
 
30
30
  OPERATOR = '>=' / '<=' / '>' / '<'
31
-
31
+
32
32
  DATE_RESTRICTION = SPACE_SYMBOL* operator:DATE_OPERATOR SPACE_SYMBOL* value:NUMBER SPACE_SYMBOL* interval:DATE_INTERVAL {
33
33
  return {
34
34
  type: operator,
@@ -40,7 +40,7 @@ DATE_RESTRICTION = SPACE_SYMBOL* operator:DATE_OPERATOR SPACE_SYMBOL* value:NUMB
40
40
  DATE_OPERATOR = 'inThePast' / 'inTheNext'
41
41
  DATE_INTERVAL = 'milliseconds' / 'seconds' / 'minutes' / 'hours' / 'days' / 'weeks' / 'months' / 'years'
42
42
 
43
- NUMBER
43
+ NUMBER
44
44
  = FLOAT ([Ee] [+-]? INTEGER)?
45
45
  { return Number(text()) }
46
46
 
@@ -91,7 +91,7 @@ MATCH
91
91
  }
92
92
  }
93
93
  PCT
94
- = CONTAINS / STARTS_WITH / ENDS_WITH
94
+ = CONTAINS / STARTS_WITH / ENDS_WITH
95
95
  CONTAINS
96
96
  = PCT_SYMBOL value:(char / UNDERSCORE)+ PCT_SYMBOL !(string / PCT_SYMBOL / UNDERSCORE) {
97
97
  return {
@@ -240,7 +240,7 @@ const parseFilters = (rawFilters) => {
240
240
  unitOfTime: parsedFilter.date_interval,
241
241
  },
242
242
  }
243
- : {}),
243
+ : null),
244
244
  },
245
245
  ];
246
246
  }
@@ -1,6 +1,5 @@
1
1
  import { type MetricWithAssociatedTimeDimension } from './catalog';
2
2
  import type { Dimension, ItemsMap } from './field';
3
- import type { ResultValue } from './results';
4
3
  export declare enum MetricExplorerComparison {
5
4
  NONE = "none",
6
5
  PREVIOUS_PERIOD = "previous_period",
@@ -26,12 +25,10 @@ export type MetricExploreDataPoint = {
26
25
  segment: string | null;
27
26
  metric: {
28
27
  value: number | null;
29
- formatted: string | null;
30
28
  label: string | null;
31
29
  };
32
30
  compareMetric: {
33
31
  value: number | null;
34
- formatted: string | null;
35
32
  label: string | null;
36
33
  };
37
34
  };
@@ -55,8 +52,9 @@ export declare enum MetricTotalComparisonType {
55
52
  PREVIOUS_PERIOD = "previous_period"
56
53
  }
57
54
  export type MetricTotalResults = {
58
- value: ResultValue | undefined;
59
- comparisonValue: ResultValue | undefined;
55
+ value: number | null;
56
+ comparisonValue: number | null;
57
+ metric: MetricWithAssociatedTimeDimension;
60
58
  };
61
59
  export type ApiMetricsExplorerTotalResults = {
62
60
  status: 'ok';
@@ -78,6 +78,7 @@ export type CreatePostgresCredentials = SshTunnelConfiguration & {
78
78
  role?: string;
79
79
  sslmode?: string;
80
80
  startOfWeek?: WeekDay | null;
81
+ timeoutSeconds?: number;
81
82
  };
82
83
  export type PostgresCredentials = Omit<CreatePostgresCredentials, SensitiveCredentialsFieldNames>;
83
84
  export type CreateTrinoCredentials = {
@@ -107,6 +108,7 @@ export type CreateRedshiftCredentials = SshTunnelConfiguration & {
107
108
  sslmode?: string;
108
109
  ra3Node?: boolean;
109
110
  startOfWeek?: WeekDay | null;
111
+ timeoutSeconds?: number;
110
112
  };
111
113
  export type RedshiftCredentials = Omit<CreateRedshiftCredentials, SensitiveCredentialsFieldNames>;
112
114
  export type CreateSnowflakeCredentials = {
@@ -193,7 +193,7 @@ export type Series = {
193
193
  position?: 'left' | 'top' | 'right' | 'bottom' | 'inside';
194
194
  };
195
195
  hidden?: boolean;
196
- areaStyle?: {};
196
+ areaStyle?: Record<string, unknown>;
197
197
  showSymbol?: boolean;
198
198
  smooth?: boolean;
199
199
  markLine?: MarkLine;
@@ -246,7 +246,7 @@ export type CompleteCartesianChartLayout = {
246
246
  };
247
247
  export type CartesianChartLayout = Partial<CompleteCartesianChartLayout>;
248
248
  export type CustomVis = {
249
- spec?: object;
249
+ spec?: Record<string, unknown>;
250
250
  };
251
251
  export type CartesianChart = {
252
252
  layout: CartesianChartLayout;
@@ -5,7 +5,6 @@ import type { Dimension } from '../types/field';
5
5
  import { DimensionType, type CompiledDimension, type CompiledMetric } from '../types/field';
6
6
  import { type DateFilterSettings, type FieldTarget, type FilterRule } from '../types/filter';
7
7
  import { type MetricExploreDataPoint, type MetricExplorerDateRange, type MetricExplorerQuery } from '../types/metricsExplorer';
8
- import type { ResultRow } from '../types/results';
9
8
  import { TimeFrames, type DefaultTimeDimension } from '../types/timeFrames';
10
9
  type DateFilter = FilterRule<ConditionalOperator, FieldTarget, unknown, DateFilterSettings>;
11
10
  type ImpelemntedTimeframe = TimeFrames.DAY | TimeFrames.WEEK | TimeFrames.MONTH | TimeFrames.YEAR;
@@ -20,12 +19,13 @@ export declare const METRICS_EXPLORER_DATE_FORMAT = "YYYY-MM-DD";
20
19
  export declare const getDateRangeFromString: (dateRange: [string, string]) => MetricExplorerDateRange;
21
20
  export declare const getGrainForDateRange: (dateRange: [Date, Date]) => ImpelemntedTimeframe;
22
21
  export declare const getMetricExplorerDateRangeFilters: (timeDimensionConfig: TimeDimensionConfig, dateRange: MetricExplorerDateRange) => DateFilter[];
22
+ export declare const parseMetricValue: (value: unknown) => number | null;
23
23
  export declare const MAX_SEGMENT_DIMENSION_UNIQUE_VALUES = 10;
24
- export declare const getMetricExplorerDataPoints: (dimension: Dimension, metric: MetricWithAssociatedTimeDimension, metricRows: ResultRow[], segmentDimensionId: string | null) => {
24
+ export declare const getMetricExplorerDataPoints: (dimension: Dimension, metric: MetricWithAssociatedTimeDimension, metricRows: Record<string, any>[], segmentDimensionId: string | null) => {
25
25
  dataPoints: Array<MetricExploreDataPoint>;
26
26
  isSegmentDimensionFiltered: boolean;
27
27
  };
28
- export declare const getMetricExplorerDataPointsWithCompare: (dimension: Dimension, compareDimension: Dimension, metric: MetricWithAssociatedTimeDimension, metricRows: ResultRow[], compareMetricRows: ResultRow[], query: MetricExplorerQuery, timeFrame: TimeFrames) => {
28
+ export declare const getMetricExplorerDataPointsWithCompare: (dimension: Dimension, compareDimension: Dimension, metric: MetricWithAssociatedTimeDimension, metricRows: Record<string, any>[], compareMetricRows: Record<string, any>[], query: MetricExplorerQuery, timeFrame: TimeFrames) => {
29
29
  dataPoints: Array<MetricExploreDataPoint>;
30
30
  };
31
31
  /**
@@ -38,7 +38,7 @@ export declare const getMetricExplorerDataPointsWithCompare: (dimension: Dimensi
38
38
  * @returns The date range
39
39
  */
40
40
  export declare const getDefaultDateRangeFromInterval: (timeInterval: TimeFrames) => MetricExplorerDateRange;
41
- export declare const getDefaultDateRangeForMetricTotal: (timeFrame: TimeFrames) => MetricExplorerDateRange;
41
+ export declare const getDefaultMetricTreeNodeDateRange: (timeFrame: TimeFrames) => MetricExplorerDateRange;
42
42
  /**
43
43
  * Default time interval to use when no time interval is provided.
44
44
  * For example, when there is no default time dimension defined for a metric or table.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAvailableCompareMetrics = exports.getAvailableSegmentDimensions = exports.getAvailableTimeDimensionsFromTables = exports.getDefaultTimeDimension = exports.getFirstAvailableTimeDimension = exports.DEFAULT_METRICS_EXPLORER_TIME_INTERVAL = exports.getDefaultDateRangeForMetricTotal = exports.getDefaultDateRangeFromInterval = exports.getMetricExplorerDataPointsWithCompare = exports.getMetricExplorerDataPoints = exports.MAX_SEGMENT_DIMENSION_UNIQUE_VALUES = exports.getMetricExplorerDateRangeFilters = exports.getGrainForDateRange = exports.getDateRangeFromString = exports.METRICS_EXPLORER_DATE_FORMAT = exports.getDateCalcUtils = exports.getFieldIdForDateDimension = exports.assertUnimplementedTimeframe = void 0;
3
+ exports.getAvailableCompareMetrics = exports.getAvailableSegmentDimensions = exports.getAvailableTimeDimensionsFromTables = exports.getDefaultTimeDimension = exports.getFirstAvailableTimeDimension = exports.DEFAULT_METRICS_EXPLORER_TIME_INTERVAL = exports.getDefaultMetricTreeNodeDateRange = exports.getDefaultDateRangeFromInterval = exports.getMetricExplorerDataPointsWithCompare = exports.getMetricExplorerDataPoints = exports.MAX_SEGMENT_DIMENSION_UNIQUE_VALUES = exports.parseMetricValue = exports.getMetricExplorerDateRangeFilters = exports.getGrainForDateRange = exports.getDateRangeFromString = exports.METRICS_EXPLORER_DATE_FORMAT = exports.getDateCalcUtils = 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 isoWeek_1 = tslib_1.__importDefault(require("dayjs/plugin/isoWeek"));
@@ -135,7 +135,6 @@ const getMetricExplorerDateRangeFilters = (timeDimensionConfig, dateRange) => {
135
135
  ];
136
136
  };
137
137
  exports.getMetricExplorerDateRangeFilters = getMetricExplorerDateRangeFilters;
138
- // TODO: Should we just use the formatted value instead?
139
138
  // Parse the metric value to a number, returning null if it's not a number
140
139
  const parseMetricValue = (value) => {
141
140
  if (value === null || value === undefined)
@@ -143,6 +142,7 @@ const parseMetricValue = (value) => {
143
142
  const parsed = Number(value);
144
143
  return Number.isNaN(parsed) ? null : parsed;
145
144
  };
145
+ exports.parseMetricValue = parseMetricValue;
146
146
  // we are assuming that the dimension value is a string and if it's not defined we just return null
147
147
  // so actually `null` value will be converted to `"null"` string
148
148
  const parseDimensionValue = (value) => {
@@ -157,28 +157,26 @@ const getMetricExplorerDataPoints = (dimension, metric, metricRows, segmentDimen
157
157
  let filteredMetricRows = metricRows;
158
158
  let isSegmentDimensionFiltered = false;
159
159
  if (segmentDimensionId) {
160
- const countUniqueValues = new Set(metricRows.map((row) => row[segmentDimensionId]?.value.raw)).size;
160
+ const countUniqueValues = new Set(metricRows.map((row) => row[segmentDimensionId])).size;
161
161
  if (countUniqueValues > exports.MAX_SEGMENT_DIMENSION_UNIQUE_VALUES) {
162
162
  isSegmentDimensionFiltered = true;
163
- const first10Values = Array.from(new Set(metricRows.map((row) => row[segmentDimensionId]?.value.raw))).slice(0, exports.MAX_SEGMENT_DIMENSION_UNIQUE_VALUES);
164
- filteredMetricRows = metricRows.filter((row) => first10Values.includes(row[segmentDimensionId]?.value.raw));
163
+ const first10Values = Array.from(new Set(metricRows.map((row) => row[segmentDimensionId]))).slice(0, exports.MAX_SEGMENT_DIMENSION_UNIQUE_VALUES);
164
+ filteredMetricRows = metricRows.filter((row) => first10Values.includes(row[segmentDimensionId]));
165
165
  }
166
166
  }
167
- const groupByMetricRows = (0, lodash_1.groupBy)(filteredMetricRows, (row) => new Date(String(row[dimensionId].value.raw)).toISOString());
167
+ const groupByMetricRows = (0, lodash_1.groupBy)(filteredMetricRows, (row) => new Date(String(row[dimensionId])).toISOString());
168
168
  const dataPoints = Object.entries(groupByMetricRows).flatMap(([date, rows]) => rows.map((row) => {
169
169
  const segmentValue = segmentDimensionId
170
- ? parseDimensionValue(row[segmentDimensionId]?.value.raw)
170
+ ? parseDimensionValue(row[segmentDimensionId])
171
171
  : null;
172
172
  return {
173
173
  date: new Date(date),
174
174
  segment: segmentValue,
175
175
  metric: {
176
- value: parseMetricValue(row[metricId]?.value.raw),
177
- formatted: row[metricId]?.value.formatted,
176
+ value: (0, exports.parseMetricValue)(row[metricId]),
178
177
  label: segmentValue ?? metric.label ?? metric.name,
179
178
  },
180
179
  compareMetric: {
181
- formatted: null,
182
180
  value: null,
183
181
  label: null,
184
182
  },
@@ -208,8 +206,8 @@ const getMetricExplorerDataPointsWithCompare = (dimension, compareDimension, met
208
206
  const metricId = (0, item_1.getItemId)(metric);
209
207
  const dimensionId = (0, item_1.getItemId)(dimension);
210
208
  const compareDimensionId = (0, item_1.getItemId)(compareDimension);
211
- const groupByMetricRows = (0, lodash_1.groupBy)(metricRows, (row) => new Date(String(row[dimensionId].value.raw)).toISOString());
212
- const groupByCompareMetricRows = (0, lodash_1.groupBy)(compareMetricRows, (row) => new Date(String(row[compareDimensionId].value.raw)).toISOString());
209
+ const groupByMetricRows = (0, lodash_1.groupBy)(metricRows, (row) => new Date(String(row[dimensionId])).toISOString());
210
+ const groupByCompareMetricRows = (0, lodash_1.groupBy)(compareMetricRows, (row) => new Date(String(row[compareDimensionId])).toISOString());
213
211
  const offsetGroupByCompareMetricRows = (0, lodash_1.mapKeys)(groupByCompareMetricRows, (_, date) => {
214
212
  if (query.comparison === metricsExplorer_1.MetricExplorerComparison.PREVIOUS_PERIOD) {
215
213
  if (timeFrame === timeFrames_1.TimeFrames.WEEK) {
@@ -242,15 +240,11 @@ const getMetricExplorerDataPointsWithCompare = (dimension, compareDimension, met
242
240
  date: new Date(date),
243
241
  segment: null,
244
242
  metric: {
245
- formatted: groupByMetricRows[date]?.[0]?.[metricId]?.value.formatted,
246
- value: parseMetricValue(groupByMetricRows[date]?.[0]?.[metricId]?.value.raw),
243
+ value: (0, exports.parseMetricValue)(groupByMetricRows[date]?.[0]?.[metricId]),
247
244
  label: metric.label ?? metric.name,
248
245
  },
249
246
  compareMetric: {
250
- formatted: offsetGroupByCompareMetricRows[date]?.[0]?.[compareMetricId]
251
- ?.value.formatted,
252
- value: parseMetricValue(offsetGroupByCompareMetricRows[date]?.[0]?.[compareMetricId]
253
- ?.value.raw),
247
+ value: (0, exports.parseMetricValue)(offsetGroupByCompareMetricRows[date]?.[0]?.[compareMetricId]),
254
248
  label: comparisonMetricLabel,
255
249
  },
256
250
  }));
@@ -291,25 +285,34 @@ const getDefaultDateRangeFromInterval = (timeInterval) => {
291
285
  }
292
286
  };
293
287
  exports.getDefaultDateRangeFromInterval = getDefaultDateRangeFromInterval;
294
- const getDefaultDateRangeForMetricTotal = (timeFrame) => {
288
+ const getDefaultMetricTreeNodeDateRange = (timeFrame) => {
295
289
  const now = (0, dayjs_1.default)();
296
290
  switch (timeFrame) {
297
291
  case timeFrames_1.TimeFrames.DAY:
298
- return [now.startOf('day').toDate(), now.endOf('day').toDate()];
292
+ return [
293
+ now.startOf('day').subtract(1, 'day').toDate(),
294
+ now.endOf('day').subtract(1, 'day').toDate(),
295
+ ];
299
296
  case timeFrames_1.TimeFrames.WEEK:
300
297
  return [
301
- now.startOf('isoWeek').toDate(),
302
- now.endOf('isoWeek').toDate(),
298
+ now.startOf('isoWeek').subtract(1, 'week').toDate(),
299
+ now.endOf('isoWeek').subtract(1, 'week').toDate(),
303
300
  ];
304
301
  case timeFrames_1.TimeFrames.MONTH:
305
- return [now.startOf('month').toDate(), now.endOf('month').toDate()];
302
+ return [
303
+ now.startOf('month').subtract(1, 'month').toDate(),
304
+ now.endOf('month').subtract(1, 'month').toDate(),
305
+ ];
306
306
  case timeFrames_1.TimeFrames.YEAR:
307
- return [now.startOf('year').toDate(), now.endOf('year').toDate()];
307
+ return [
308
+ now.startOf('year').subtract(1, 'year').toDate(),
309
+ now.endOf('year').subtract(1, 'year').toDate(),
310
+ ];
308
311
  default:
309
312
  return (0, exports.assertUnimplementedTimeframe)(timeFrame);
310
313
  }
311
314
  };
312
- exports.getDefaultDateRangeForMetricTotal = getDefaultDateRangeForMetricTotal;
315
+ exports.getDefaultMetricTreeNodeDateRange = getDefaultMetricTreeNodeDateRange;
313
316
  /**
314
317
  * Default time interval to use when no time interval is provided.
315
318
  * For example, when there is no default time dimension defined for a metric or table.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightdash/common",
3
- "version": "0.1426.3",
3
+ "version": "0.1428.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [