@lightdash/common 0.2385.1 → 0.2386.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.
- package/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/types/periodOverPeriodComparison.d.ts +13 -0
- package/dist/cjs/types/periodOverPeriodComparison.d.ts.map +1 -1
- package/dist/cjs/types/periodOverPeriodComparison.js +77 -29
- package/dist/cjs/types/periodOverPeriodComparison.js.map +1 -1
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/types/periodOverPeriodComparison.d.ts +13 -0
- package/dist/esm/types/periodOverPeriodComparison.d.ts.map +1 -1
- package/dist/esm/types/periodOverPeriodComparison.js +45 -0
- package/dist/esm/types/periodOverPeriodComparison.js.map +1 -1
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/types/periodOverPeriodComparison.d.ts +13 -0
- package/dist/types/types/periodOverPeriodComparison.d.ts.map +1 -1
- package/dist/types/types/periodOverPeriodComparison.js +45 -0
- package/dist/types/types/periodOverPeriodComparison.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { type Metric } from './field';
|
|
2
|
+
import { type AdditionalMetric } from './metricQuery';
|
|
1
3
|
import { TimeFrames } from './timeFrames';
|
|
2
4
|
type PreviousPeriod = {
|
|
3
5
|
type: 'previousPeriod';
|
|
@@ -14,5 +16,16 @@ export declare const validPeriodOverPeriodGranularities: TimeFrames[];
|
|
|
14
16
|
export declare const periodOverPeriodGranularityLabels: Record<TimeFrames, string>;
|
|
15
17
|
export declare const isSupportedPeriodOverPeriodGranularity: (granularity: TimeFrames) => boolean;
|
|
16
18
|
export declare const buildPopAdditionalMetricName: (baseMetricName: string) => string;
|
|
19
|
+
export declare const getPopPeriodLabel: (granularity: TimeFrames, periodOffset: number) => string;
|
|
20
|
+
export declare const buildPopAdditionalMetric: ({ metric, timeDimensionId, granularity, periodOffset, }: {
|
|
21
|
+
metric: Pick<Metric, "table" | "name" | "label" | "description" | "type" | "sql" | "round" | "compact" | "format">;
|
|
22
|
+
timeDimensionId: string;
|
|
23
|
+
granularity: TimeFrames;
|
|
24
|
+
periodOffset: number;
|
|
25
|
+
}) => {
|
|
26
|
+
additionalMetric: AdditionalMetric;
|
|
27
|
+
metricId: string;
|
|
28
|
+
};
|
|
29
|
+
export declare const getGranularityRank: (granularity: TimeFrames) => number;
|
|
17
30
|
export {};
|
|
18
31
|
//# sourceMappingURL=periodOverPeriodComparison.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"periodOverPeriodComparison.d.ts","sourceRoot":"","sources":["../../../src/types/periodOverPeriodComparison.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"periodOverPeriodComparison.d.ts","sourceRoot":"","sources":["../../../src/types/periodOverPeriodComparison.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,KAAK,cAAc,GAAG;IAClB,IAAI,EAAE,gBAAgB,CAAC;IACvB,WAAW,EAAE,UAAU,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG,cAAc,GAAG;IAEtD,KAAK,EAAE;QACH,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;KACjB,CAAC;CACL,CAAC;AAEF,eAAO,MAAM,kCAAkC,cAM9C,CAAC;AAEF,eAAO,MAAM,iCAAiC,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAuBxE,CAAC;AAEF,eAAO,MAAM,sCAAsC,gBAClC,UAAU,YACkC,CAAC;AAE9D,eAAO,MAAM,4BAA4B,mBAAoB,MAAM,WACvC,CAAC;AAE7B,eAAO,MAAM,iBAAiB,gBACb,UAAU,gBACT,MAAM,WAMvB,CAAC;AAEF,eAAO,MAAM,wBAAwB,4DAKlC;IACC,MAAM,EAAE,IAAI,CACR,MAAM,EACJ,OAAO,GACP,MAAM,GACN,OAAO,GACP,aAAa,GACb,MAAM,GACN,KAAK,GACL,OAAO,GACP,SAAS,GACT,QAAQ,CACb,CAAC;IACF,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,UAAU,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;CACxB,KAAG;IAAE,gBAAgB,EAAE,gBAAgB,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CA4BzD,CAAC;AAWF,eAAO,MAAM,kBAAkB,gBAAiB,UAAU,KAAG,MAG5D,CAAC"}
|
|
@@ -1,40 +1,88 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildPopAdditionalMetricName = exports.isSupportedPeriodOverPeriodGranularity = exports.periodOverPeriodGranularityLabels = exports.validPeriodOverPeriodGranularities = void 0;
|
|
4
|
-
const
|
|
3
|
+
exports.getGranularityRank = exports.buildPopAdditionalMetric = exports.getPopPeriodLabel = exports.buildPopAdditionalMetricName = exports.isSupportedPeriodOverPeriodGranularity = exports.periodOverPeriodGranularityLabels = exports.validPeriodOverPeriodGranularities = void 0;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
5
|
+
const item_1 = require("../utils/item");
|
|
6
|
+
const timeFrames_1 = require("../utils/timeFrames");
|
|
7
|
+
const timeFrames_2 = require("./timeFrames");
|
|
5
8
|
exports.validPeriodOverPeriodGranularities = [
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
timeFrames_2.TimeFrames.DAY,
|
|
10
|
+
timeFrames_2.TimeFrames.WEEK,
|
|
11
|
+
timeFrames_2.TimeFrames.MONTH,
|
|
12
|
+
timeFrames_2.TimeFrames.QUARTER,
|
|
13
|
+
timeFrames_2.TimeFrames.YEAR,
|
|
11
14
|
];
|
|
12
15
|
exports.periodOverPeriodGranularityLabels = {
|
|
13
|
-
[
|
|
14
|
-
[
|
|
15
|
-
[
|
|
16
|
-
[
|
|
17
|
-
[
|
|
18
|
-
[
|
|
19
|
-
[
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
24
|
-
[
|
|
25
|
-
[
|
|
26
|
-
[
|
|
27
|
-
[
|
|
28
|
-
[
|
|
29
|
-
[
|
|
30
|
-
[
|
|
31
|
-
[
|
|
32
|
-
[
|
|
33
|
-
[
|
|
34
|
-
[
|
|
16
|
+
[timeFrames_2.TimeFrames.YEAR]: 'Year',
|
|
17
|
+
[timeFrames_2.TimeFrames.QUARTER]: 'Quarter',
|
|
18
|
+
[timeFrames_2.TimeFrames.MONTH]: 'Month',
|
|
19
|
+
[timeFrames_2.TimeFrames.WEEK]: 'Week',
|
|
20
|
+
[timeFrames_2.TimeFrames.DAY]: 'Day',
|
|
21
|
+
[timeFrames_2.TimeFrames.HOUR]: 'Hour',
|
|
22
|
+
[timeFrames_2.TimeFrames.MINUTE]: 'Minute',
|
|
23
|
+
[timeFrames_2.TimeFrames.SECOND]: 'Second',
|
|
24
|
+
[timeFrames_2.TimeFrames.MILLISECOND]: 'Millisecond',
|
|
25
|
+
[timeFrames_2.TimeFrames.RAW]: 'Raw',
|
|
26
|
+
[timeFrames_2.TimeFrames.DAY_OF_WEEK_INDEX]: 'Day of Week Index',
|
|
27
|
+
[timeFrames_2.TimeFrames.DAY_OF_MONTH_NUM]: 'Day of Month',
|
|
28
|
+
[timeFrames_2.TimeFrames.DAY_OF_YEAR_NUM]: 'Day of Year',
|
|
29
|
+
[timeFrames_2.TimeFrames.WEEK_NUM]: 'Week Number',
|
|
30
|
+
[timeFrames_2.TimeFrames.MONTH_NUM]: 'Month Number',
|
|
31
|
+
[timeFrames_2.TimeFrames.QUARTER_NUM]: 'Quarter Number',
|
|
32
|
+
[timeFrames_2.TimeFrames.YEAR_NUM]: 'Year Number',
|
|
33
|
+
[timeFrames_2.TimeFrames.DAY_OF_WEEK_NAME]: 'Day of Week Name',
|
|
34
|
+
[timeFrames_2.TimeFrames.MONTH_NAME]: 'Month Name',
|
|
35
|
+
[timeFrames_2.TimeFrames.QUARTER_NAME]: 'Quarter Name',
|
|
36
|
+
[timeFrames_2.TimeFrames.HOUR_OF_DAY_NUM]: 'Hour of Day',
|
|
37
|
+
[timeFrames_2.TimeFrames.MINUTE_OF_HOUR_NUM]: 'Minute of Hour',
|
|
35
38
|
};
|
|
36
39
|
const isSupportedPeriodOverPeriodGranularity = (granularity) => exports.validPeriodOverPeriodGranularities.includes(granularity);
|
|
37
40
|
exports.isSupportedPeriodOverPeriodGranularity = isSupportedPeriodOverPeriodGranularity;
|
|
38
41
|
const buildPopAdditionalMetricName = (baseMetricName) => `${baseMetricName}__pop`;
|
|
39
42
|
exports.buildPopAdditionalMetricName = buildPopAdditionalMetricName;
|
|
43
|
+
const getPopPeriodLabel = (granularity, periodOffset) => {
|
|
44
|
+
const label = timeFrames_1.timeFrameConfigs[granularity]?.getLabel() || granularity;
|
|
45
|
+
return periodOffset === 1
|
|
46
|
+
? `Previous ${String(label).toLowerCase()}`
|
|
47
|
+
: `${periodOffset} ${String(label).toLowerCase()}s ago`;
|
|
48
|
+
};
|
|
49
|
+
exports.getPopPeriodLabel = getPopPeriodLabel;
|
|
50
|
+
const buildPopAdditionalMetric = ({ metric, timeDimensionId, granularity, periodOffset, }) => {
|
|
51
|
+
const baseMetricId = (0, item_1.getItemId)(metric);
|
|
52
|
+
const popName = (0, exports.buildPopAdditionalMetricName)(metric.name);
|
|
53
|
+
const popMetricId = (0, item_1.getItemId)({ table: metric.table, name: popName });
|
|
54
|
+
const additionalMetric = {
|
|
55
|
+
uuid: (0, uuid_1.v4)(),
|
|
56
|
+
table: metric.table,
|
|
57
|
+
name: popName,
|
|
58
|
+
label: `${metric.label} (${(0, exports.getPopPeriodLabel)(granularity, periodOffset)})`,
|
|
59
|
+
description: metric.description,
|
|
60
|
+
type: metric.type,
|
|
61
|
+
sql: metric.sql,
|
|
62
|
+
hidden: true,
|
|
63
|
+
round: metric.round,
|
|
64
|
+
compact: metric.compact,
|
|
65
|
+
format: metric.format,
|
|
66
|
+
generationType: 'periodOverPeriod',
|
|
67
|
+
baseMetricId,
|
|
68
|
+
timeDimensionId,
|
|
69
|
+
granularity,
|
|
70
|
+
periodOffset,
|
|
71
|
+
};
|
|
72
|
+
return { additionalMetric, metricId: popMetricId };
|
|
73
|
+
};
|
|
74
|
+
exports.buildPopAdditionalMetric = buildPopAdditionalMetric;
|
|
75
|
+
// Granularity order from finest to coarsest (lower index = finer)
|
|
76
|
+
const GRANULARITY_ORDER = [
|
|
77
|
+
timeFrames_2.TimeFrames.DAY,
|
|
78
|
+
timeFrames_2.TimeFrames.WEEK,
|
|
79
|
+
timeFrames_2.TimeFrames.MONTH,
|
|
80
|
+
timeFrames_2.TimeFrames.QUARTER,
|
|
81
|
+
timeFrames_2.TimeFrames.YEAR,
|
|
82
|
+
];
|
|
83
|
+
const getGranularityRank = (granularity) => {
|
|
84
|
+
const index = GRANULARITY_ORDER.indexOf(granularity);
|
|
85
|
+
return index === -1 ? Infinity : index;
|
|
86
|
+
};
|
|
87
|
+
exports.getGranularityRank = getGranularityRank;
|
|
40
88
|
//# sourceMappingURL=periodOverPeriodComparison.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"periodOverPeriodComparison.js","sourceRoot":"","sources":["../../../src/types/periodOverPeriodComparison.ts"],"names":[],"mappings":";;;AAAA,6CAA0C;AAgB7B,QAAA,kCAAkC,GAAG;IAC9C,uBAAU,CAAC,GAAG;IACd,uBAAU,CAAC,IAAI;IACf,uBAAU,CAAC,KAAK;IAChB,uBAAU,CAAC,OAAO;IAClB,uBAAU,CAAC,IAAI;CAClB,CAAC;AAEW,QAAA,iCAAiC,GAA+B;IACzE,CAAC,uBAAU,CAAC,IA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