@bundle-stats/utils 3.4.0-alpha.5 → 4.0.0-alpha.7

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 (84) hide show
  1. package/lib/constants.js +1 -8
  2. package/lib/constants.js.map +1 -1
  3. package/lib/index.js +0 -15
  4. package/lib/index.js.map +1 -1
  5. package/lib/jobs/create-job.js +2 -2
  6. package/lib/jobs/create-job.js.map +1 -1
  7. package/lib/jobs/create-jobs.js +2 -2
  8. package/lib/jobs/create-jobs.js.map +1 -1
  9. package/lib/utils/format.js +12 -4
  10. package/lib/utils/format.js.map +1 -1
  11. package/lib/webpack/constants.js +14 -28
  12. package/lib/webpack/constants.js.map +1 -1
  13. package/lib/webpack/extract/assets-size-total-insight.js +4 -4
  14. package/lib/webpack/extract/assets-size-total-insight.js.map +1 -1
  15. package/lib/webpack/extract/assets-size.js +4 -3
  16. package/lib/webpack/extract/assets-size.js.map +1 -1
  17. package/lib/webpack/extract/assets.js +11 -7
  18. package/lib/webpack/extract/assets.js.map +1 -1
  19. package/lib/webpack/extract/index.js +1 -26
  20. package/lib/webpack/extract/index.js.map +1 -1
  21. package/lib/webpack/extract/modules-packages-duplicate.js +2 -2
  22. package/lib/webpack/extract/modules-packages-duplicate.js.map +1 -1
  23. package/lib/webpack/metrics.js +18 -29
  24. package/lib/webpack/metrics.js.map +1 -1
  25. package/lib-esm/constants.js +0 -7
  26. package/lib-esm/constants.js.map +1 -1
  27. package/lib-esm/index.js +0 -3
  28. package/lib-esm/index.js.map +1 -1
  29. package/lib-esm/jobs/create-job.js +2 -2
  30. package/lib-esm/jobs/create-job.js.map +1 -1
  31. package/lib-esm/jobs/create-jobs.js +2 -2
  32. package/lib-esm/jobs/create-jobs.js.map +1 -1
  33. package/lib-esm/utils/format.js +12 -4
  34. package/lib-esm/utils/format.js.map +1 -1
  35. package/lib-esm/webpack/constants.js +13 -27
  36. package/lib-esm/webpack/constants.js.map +1 -1
  37. package/lib-esm/webpack/extract/assets-size-total-insight.js +4 -4
  38. package/lib-esm/webpack/extract/assets-size-total-insight.js.map +1 -1
  39. package/lib-esm/webpack/extract/assets-size.js +4 -3
  40. package/lib-esm/webpack/extract/assets-size.js.map +1 -1
  41. package/lib-esm/webpack/extract/assets.js +11 -7
  42. package/lib-esm/webpack/extract/assets.js.map +1 -1
  43. package/lib-esm/webpack/extract/index.js +1 -3
  44. package/lib-esm/webpack/extract/index.js.map +1 -1
  45. package/lib-esm/webpack/extract/modules-packages-duplicate.js +2 -2
  46. package/lib-esm/webpack/extract/modules-packages-duplicate.js.map +1 -1
  47. package/lib-esm/webpack/metrics.js +18 -29
  48. package/lib-esm/webpack/metrics.js.map +1 -1
  49. package/package.json +14 -14
  50. package/src/constants.ts +0 -7
  51. package/src/index.js +0 -2
  52. package/src/jobs/create-job.js +2 -2
  53. package/src/jobs/create-jobs.js +2 -2
  54. package/src/utils/format.js +17 -4
  55. package/src/webpack/{constants.ts → constants.js} +13 -28
  56. package/src/webpack/extract/assets-size-total-insight.js +4 -4
  57. package/src/webpack/extract/assets-size.js +5 -3
  58. package/src/webpack/extract/{assets.js → assets.ts} +41 -12
  59. package/src/webpack/extract/index.js +5 -7
  60. package/src/webpack/extract/modules-packages-duplicate.js +2 -2
  61. package/src/webpack/{metrics.ts → metrics.js} +18 -29
  62. package/types/constants.d.ts +0 -6
  63. package/types/index.d.ts +0 -2
  64. package/types/jobs/create-job.d.ts +1 -1
  65. package/types/jobs/create-jobs.d.ts +1 -1
  66. package/types/report/add-row-metric-data.d.ts +1 -1
  67. package/types/webpack/constants.d.ts +9 -33
  68. package/types/webpack/extract/assets.d.ts +6 -3
  69. package/types/webpack/extract/index.d.ts +1 -1
  70. package/types/webpack/extract/modules-packages-duplicate.d.ts +1 -2
  71. package/types/webpack/extract/modules-packages.d.ts +1 -1
  72. package/types/webpack/metrics.d.ts +153 -116
  73. package/lib/transformers/budgets-insights.js +0 -85
  74. package/lib/transformers/budgets-insights.js.map +0 -1
  75. package/lib/transformers/index.js +0 -28
  76. package/lib/transformers/index.js.map +0 -1
  77. package/lib-esm/transformers/budgets-insights.js +0 -77
  78. package/lib-esm/transformers/budgets-insights.js.map +0 -1
  79. package/lib-esm/transformers/index.js +0 -3
  80. package/lib-esm/transformers/index.js.map +0 -1
  81. package/src/transformers/budgets-insights.ts +0 -143
  82. package/src/transformers/index.ts +0 -1
  83. package/types/transformers/budgets-insights.d.ts +0 -36
  84. package/types/transformers/index.d.ts +0 -1
@@ -1,116 +1,153 @@
1
- export declare const metrics: {
2
- totalSizeByTypeALL: {
3
- label: string;
4
- description: string;
5
- url: string;
6
- type: string;
7
- biggerIsBetter: boolean;
8
- };
9
- totalInitialSizeJS: {
10
- label: string;
11
- description: string;
12
- url: string;
13
- type: string;
14
- biggerIsBetter: boolean;
15
- };
16
- totalInitialSizeCSS: {
17
- label: string;
18
- description: string;
19
- url: string;
20
- type: string;
21
- biggerIsBetter: boolean;
22
- };
23
- cacheInvalidation: {
24
- label: string;
25
- description: string;
26
- url: string;
27
- type: string;
28
- biggerIsBetter: boolean;
29
- };
30
- chunkCount: {
31
- label: string;
32
- description: string;
33
- url: string;
34
- type: string;
35
- biggerIsBetter: boolean;
36
- };
37
- assetCount: {
38
- label: string;
39
- description: string;
40
- url: string;
41
- type: string;
42
- biggerIsBetter: boolean;
43
- };
44
- moduleCount: {
45
- label: string;
46
- description: string;
47
- url: string;
48
- type: string;
49
- biggerIsBetter: boolean;
50
- };
51
- duplicateModulesCount: {
52
- label: string;
53
- description: string;
54
- url: string;
55
- type: string;
56
- biggerIsBetter: boolean;
57
- };
58
- duplicateCode: {
59
- label: string;
60
- description: string;
61
- url: string;
62
- type: string;
63
- biggerIsBetter: boolean;
64
- };
65
- packageCount: {
66
- label: string;
67
- description: string;
68
- url: string;
69
- type: string;
70
- biggerIsBetter: boolean;
71
- };
72
- duplicatePackagesCount: {
73
- label: string;
74
- description: string;
75
- url: string;
76
- type: string;
77
- biggerIsBetter: boolean;
78
- };
79
- sizes: {
80
- totalSizeByTypeJS: {
81
- label: string;
82
- type: string;
83
- biggerIsBetter: boolean;
84
- };
85
- totalSizeByTypeCSS: {
86
- label: string;
87
- type: string;
88
- biggerIsBetter: boolean;
89
- };
90
- totalSizeByTypeIMG: {
91
- label: string;
92
- type: string;
93
- biggerIsBetter: boolean;
94
- };
95
- totalSizeByTypeMEDIA: {
96
- label: string;
97
- type: string;
98
- biggerIsBetter: boolean;
99
- };
100
- totalSizeByTypeFONT: {
101
- label: string;
102
- type: string;
103
- biggerIsBetter: boolean;
104
- };
105
- totalSizeByTypeHTML: {
106
- label: string;
107
- type: string;
108
- biggerIsBetter: boolean;
109
- };
110
- totalSizeByTypeOTHER: {
111
- label: string;
112
- type: string;
113
- biggerIsBetter: boolean;
114
- };
115
- };
116
- };
1
+ export namespace metrics {
2
+ namespace totalSizeByTypeALL {
3
+ export const label: string;
4
+ export const description: string;
5
+ export const url: string;
6
+ export { METRIC_TYPE_FILE_SIZE as type };
7
+ }
8
+ namespace totalInitialSizeJS {
9
+ const label_1: string;
10
+ export { label_1 as label };
11
+ const description_1: string;
12
+ export { description_1 as description };
13
+ const url_1: string;
14
+ export { url_1 as url };
15
+ export { METRIC_TYPE_FILE_SIZE as type };
16
+ }
17
+ namespace totalInitialSizeCSS {
18
+ const label_2: string;
19
+ export { label_2 as label };
20
+ const description_2: string;
21
+ export { description_2 as description };
22
+ const url_2: string;
23
+ export { url_2 as url };
24
+ export { METRIC_TYPE_FILE_SIZE as type };
25
+ }
26
+ namespace cacheInvalidation {
27
+ const label_3: string;
28
+ export { label_3 as label };
29
+ const description_3: string;
30
+ export { description_3 as description };
31
+ const url_3: string;
32
+ export { url_3 as url };
33
+ export { METRIC_TYPE_PERCENTAGE as type };
34
+ export const biggerIsBetter: boolean;
35
+ }
36
+ namespace chunkCount {
37
+ const label_4: string;
38
+ export { label_4 as label };
39
+ const description_4: string;
40
+ export { description_4 as description };
41
+ const url_4: string;
42
+ export { url_4 as url };
43
+ export { METRIC_TYPE_NUMERIC as type };
44
+ const biggerIsBetter_1: boolean;
45
+ export { biggerIsBetter_1 as biggerIsBetter };
46
+ }
47
+ namespace assetCount {
48
+ const label_5: string;
49
+ export { label_5 as label };
50
+ const description_5: string;
51
+ export { description_5 as description };
52
+ const url_5: string;
53
+ export { url_5 as url };
54
+ export { METRIC_TYPE_NUMERIC as type };
55
+ const biggerIsBetter_2: boolean;
56
+ export { biggerIsBetter_2 as biggerIsBetter };
57
+ }
58
+ namespace moduleCount {
59
+ const label_6: string;
60
+ export { label_6 as label };
61
+ const description_6: string;
62
+ export { description_6 as description };
63
+ const url_6: string;
64
+ export { url_6 as url };
65
+ export { METRIC_TYPE_NUMERIC as type };
66
+ const biggerIsBetter_3: boolean;
67
+ export { biggerIsBetter_3 as biggerIsBetter };
68
+ }
69
+ namespace duplicateModulesCount {
70
+ const label_7: string;
71
+ export { label_7 as label };
72
+ const description_7: string;
73
+ export { description_7 as description };
74
+ const url_7: string;
75
+ export { url_7 as url };
76
+ export { METRIC_TYPE_NUMERIC as type };
77
+ const biggerIsBetter_4: boolean;
78
+ export { biggerIsBetter_4 as biggerIsBetter };
79
+ }
80
+ namespace duplicateCode {
81
+ const label_8: string;
82
+ export { label_8 as label };
83
+ const description_8: string;
84
+ export { description_8 as description };
85
+ const url_8: string;
86
+ export { url_8 as url };
87
+ export { METRIC_TYPE_PERCENTAGE as type };
88
+ const biggerIsBetter_5: boolean;
89
+ export { biggerIsBetter_5 as biggerIsBetter };
90
+ }
91
+ namespace packageCount {
92
+ const label_9: string;
93
+ export { label_9 as label };
94
+ const description_9: string;
95
+ export { description_9 as description };
96
+ const url_9: string;
97
+ export { url_9 as url };
98
+ export { METRIC_TYPE_NUMERIC as type };
99
+ const biggerIsBetter_6: boolean;
100
+ export { biggerIsBetter_6 as biggerIsBetter };
101
+ }
102
+ namespace duplicatePackagesCount {
103
+ const label_10: string;
104
+ export { label_10 as label };
105
+ const description_10: string;
106
+ export { description_10 as description };
107
+ const url_10: string;
108
+ export { url_10 as url };
109
+ export { METRIC_TYPE_NUMERIC as type };
110
+ const biggerIsBetter_7: boolean;
111
+ export { biggerIsBetter_7 as biggerIsBetter };
112
+ }
113
+ namespace sizes {
114
+ namespace totalSizeByTypeJS {
115
+ const label_11: string;
116
+ export { label_11 as label };
117
+ export { METRIC_TYPE_FILE_SIZE as type };
118
+ }
119
+ namespace totalSizeByTypeCSS {
120
+ const label_12: string;
121
+ export { label_12 as label };
122
+ export { METRIC_TYPE_FILE_SIZE as type };
123
+ }
124
+ namespace totalSizeByTypeIMG {
125
+ const label_13: string;
126
+ export { label_13 as label };
127
+ export { METRIC_TYPE_FILE_SIZE as type };
128
+ }
129
+ namespace totalSizeByTypeMEDIA {
130
+ const label_14: string;
131
+ export { label_14 as label };
132
+ export { METRIC_TYPE_FILE_SIZE as type };
133
+ }
134
+ namespace totalSizeByTypeFONT {
135
+ const label_15: string;
136
+ export { label_15 as label };
137
+ export { METRIC_TYPE_FILE_SIZE as type };
138
+ }
139
+ namespace totalSizeByTypeHTML {
140
+ const label_16: string;
141
+ export { label_16 as label };
142
+ export { METRIC_TYPE_FILE_SIZE as type };
143
+ }
144
+ namespace totalSizeByTypeOTHER {
145
+ const label_17: string;
146
+ export { label_17 as label };
147
+ export { METRIC_TYPE_FILE_SIZE as type };
148
+ }
149
+ }
150
+ }
151
+ import { METRIC_TYPE_FILE_SIZE } from "../config/metrics";
152
+ import { METRIC_TYPE_PERCENTAGE } from "../config/metrics";
153
+ import { METRIC_TYPE_NUMERIC } from "../config/metrics";
@@ -1,85 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getInfo = exports.INFO_MESSAGE_TEMPLATE = exports.getExtract = void 0;
7
- const get_1 = __importDefault(require("lodash/get"));
8
- const constants_1 = require("../constants");
9
- const utils_1 = require("../utils");
10
- const getExtract = (source) => (_, currentExtractedData, __, options = {}) => {
11
- const { budgets: budgetsOptions } = options;
12
- if (!budgetsOptions) {
13
- return null;
14
- }
15
- const insights = [];
16
- budgetsOptions.forEach((budgetOption) => {
17
- const { metric: budgetMetricId, value: budgetValue } = budgetOption;
18
- const currentValue = (0, get_1.default)(currentExtractedData, `metrics.${budgetMetricId}.value`);
19
- const metric = (0, utils_1.getGlobalMetricType)(`${source}.${budgetMetricId}`);
20
- if (!currentValue) {
21
- return;
22
- }
23
- const isValueOverBudget = currentValue > budgetValue;
24
- const budgetInsight = {
25
- currentValue,
26
- budgetValue,
27
- failed: metric.biggerIsBetter ? !isValueOverBudget : isValueOverBudget,
28
- };
29
- insights.push([budgetMetricId, budgetInsight]);
30
- });
31
- if (insights.length === 0) {
32
- return null;
33
- }
34
- return {
35
- insights: {
36
- budgets: Object.fromEntries(insights),
37
- },
38
- };
39
- };
40
- exports.getExtract = getExtract;
41
- const resolveDiffLabel = (budgetInsight) => {
42
- const { currentValue, budgetValue } = budgetInsight;
43
- if (currentValue > budgetValue) {
44
- return 'over';
45
- }
46
- if (currentValue < budgetValue) {
47
- return 'under';
48
- }
49
- return 'equal with';
50
- };
51
- const resolveType = (budgetInsight) => {
52
- if (budgetInsight.failed) {
53
- return constants_1.InsightType.ERROR;
54
- }
55
- if (budgetInsight.currentValue === budgetInsight.budgetValue) {
56
- return constants_1.InsightType.WARNING;
57
- }
58
- return constants_1.InsightType.SUCCESS;
59
- };
60
- exports.INFO_MESSAGE_TEMPLATE = '<%= metricLabel %> value \(<%= currentValue %>\) is <%= diffLabel %> <%= budgetValue %> budget';
61
- const getInfo = (globalMetricId, budgetInsight) => {
62
- const metric = (0, utils_1.getGlobalMetricType)(globalMetricId);
63
- const diffLabel = resolveDiffLabel(budgetInsight);
64
- const type = resolveType(budgetInsight);
65
- const currentValue = metric.formatter(budgetInsight.currentValue);
66
- const budgetValue = metric.formatter(budgetInsight.budgetValue);
67
- return {
68
- type,
69
- message: {
70
- template: exports.INFO_MESSAGE_TEMPLATE,
71
- data: {
72
- metricLabel: metric.label,
73
- diffLabel,
74
- currentValue,
75
- budgetValue,
76
- },
77
- },
78
- source: {
79
- metricId: globalMetricId,
80
- budgetInsight,
81
- },
82
- };
83
- };
84
- exports.getInfo = getInfo;
85
- //# sourceMappingURL=budgets-insights.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"budgets-insights.js","sourceRoot":"","sources":["../../src/transformers/budgets-insights.ts"],"names":[],"mappings":";;;;;;AAAA,qDAA6B;AAE7B,4CAA2C;AAC3C,oCAA+C;AAuCxC,MAAM,UAAU,GACrB,CAAC,MAAc,EAAE,EAAE,CAAC,CAClB,CAAU,EACV,oBAAyB,EACzB,EAAW,EACX,UAAmB,EAAE,EACS,EAAE;IAChC,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC;IAE5C,IAAI,CAAC,cAAc,EAAE;QACnB,OAAO,IAAI,CAAC;KACb;IAED,MAAM,QAAQ,GAAmC,EAAE,CAAC;IAEpD,cAAc,CAAC,OAAO,CAAC,CAAC,YAAY,EAAE,EAAE;QACtC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,YAAY,CAAC;QACpE,MAAM,YAAY,GAAG,IAAA,aAAG,EAAC,oBAAoB,EAAE,WAAW,cAAc,QAAQ,CAAC,CAAC;QAClF,MAAM,MAAM,GAAG,IAAA,2BAAmB,EAAC,GAAG,MAAM,IAAI,cAAc,EAAE,CAAC,CAAC;QAElE,IAAI,CAAC,YAAY,EAAE;YACjB,OAAO;SACR;QAED,MAAM,iBAAiB,GAAG,YAAY,GAAG,WAAW,CAAC;QAErD,MAAM,aAAa,GAAG;YACpB,YAAY;YACZ,WAAW;YACX,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,iBAAiB;SACvE,CAAC;QAEF,QAAQ,CAAC,IAAI,CAAC,CAA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M,WAAW,GAAG,MAAM,CAAC,SAAS,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;IAEhE,OAAO;QACL,IAAI;QACJ,OAAO,EAAE;YACP,QAAQ,EAAE,6BAAqB;YAC/B,IAAI,EAAE;gBACJ,WAAW,EAAE,MAAM,CAAC,KAAK;gBACzB,SAAS;gBACT,YAAY;gBACZ,WAAW;aACZ;SACF;QACD,MAAM,EAAE;YACN,QAAQ,EAAE,cAAc;YACxB,aAAa;SACd;KACF,CAAC;AACJ,CAAC,CAAC;AAxBW,QAAA,OAAO,WAwBlB"}
@@ -1,28 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.budgetInsights = void 0;
27
- exports.budgetInsights = __importStar(require("./budgets-insights"));
28
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/transformers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qEAAqD"}
@@ -1,77 +0,0 @@
1
- import get from 'lodash/get';
2
- import { InsightType } from '../constants';
3
- import { getGlobalMetricType } from '../utils';
4
- export const getExtract = (source) => (_, currentExtractedData, __, options = {}) => {
5
- const { budgets: budgetsOptions } = options;
6
- if (!budgetsOptions) {
7
- return null;
8
- }
9
- const insights = [];
10
- budgetsOptions.forEach((budgetOption) => {
11
- const { metric: budgetMetricId, value: budgetValue } = budgetOption;
12
- const currentValue = get(currentExtractedData, `metrics.${budgetMetricId}.value`);
13
- const metric = getGlobalMetricType(`${source}.${budgetMetricId}`);
14
- if (!currentValue) {
15
- return;
16
- }
17
- const isValueOverBudget = currentValue > budgetValue;
18
- const budgetInsight = {
19
- currentValue,
20
- budgetValue,
21
- failed: metric.biggerIsBetter ? !isValueOverBudget : isValueOverBudget,
22
- };
23
- insights.push([budgetMetricId, budgetInsight]);
24
- });
25
- if (insights.length === 0) {
26
- return null;
27
- }
28
- return {
29
- insights: {
30
- budgets: Object.fromEntries(insights),
31
- },
32
- };
33
- };
34
- const resolveDiffLabel = (budgetInsight) => {
35
- const { currentValue, budgetValue } = budgetInsight;
36
- if (currentValue > budgetValue) {
37
- return 'over';
38
- }
39
- if (currentValue < budgetValue) {
40
- return 'under';
41
- }
42
- return 'equal with';
43
- };
44
- const resolveType = (budgetInsight) => {
45
- if (budgetInsight.failed) {
46
- return InsightType.ERROR;
47
- }
48
- if (budgetInsight.currentValue === budgetInsight.budgetValue) {
49
- return InsightType.WARNING;
50
- }
51
- return InsightType.SUCCESS;
52
- };
53
- export const INFO_MESSAGE_TEMPLATE = '<%= metricLabel %> value \(<%= currentValue %>\) is <%= diffLabel %> <%= budgetValue %> budget';
54
- export const getInfo = (globalMetricId, budgetInsight) => {
55
- const metric = getGlobalMetricType(globalMetricId);
56
- const diffLabel = resolveDiffLabel(budgetInsight);
57
- const type = resolveType(budgetInsight);
58
- const currentValue = metric.formatter(budgetInsight.currentValue);
59
- const budgetValue = metric.formatter(budgetInsight.budgetValue);
60
- return {
61
- type,
62
- message: {
63
- template: INFO_MESSAGE_TEMPLATE,
64
- data: {
65
- metricLabel: metric.label,
66
- diffLabel,
67
- currentValue,
68
- budgetValue,
69
- },
70
- },
71
- source: {
72
- metricId: globalMetricId,
73
- budgetInsight,
74
- },
75
- };
76
- };
77
- //# sourceMappingURL=budgets-insights.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"budgets-insights.js","sourceRoot":"","sources":["../../src/transformers/budgets-insights.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAuC/C,MAAM,CAAC,MAAM,UAAU,GACrB,CAAC,MAAc,EAAE,EAAE,CAAC,CAClB,CAAU,EACV,oBAAyB,EACzB,EAAW,EACX,UAAmB,EAAE,EACS,EAAE;IAChC,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC;IAE5C,IAAI,CAAC,cAAc,EAAE;QACnB,OAAO,IAAI,CAAC;KACb;IAED,MAAM,QAAQ,GAAmC,EAAE,CAAC;IAEpD,cAAc,CAAC,OAAO,CAAC,CAAC,YAAY,EAAE,EAAE;QACtC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,YAAY,CAAC;QACpE,MAAM,YAAY,GAAG,GAAG,CAAC,oBAAoB,EAAE,WAAW,cAAc,QAAQ,CAAC,CAAC;QAClF,MAAM,MAAM,GAAG,mBAAmB,CAAC,GAAG,MAAM,IAAI,cAAc,EAAE,CAAC,CAAC;QAElE,IAAI,CAAC,YAAY,EAAE;YACjB,OAAO;SACR;QAED,MAAM,iBAAiB,GAAG,YAAY,GAAG,WAAW,CAAC;QAErD,MAAM,aAAa,GAAG;YACpB,YAAY;YACZ,WAAW;YACX,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC,CAA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,MAAM,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;IAClE,MAAM,WAAW,GAAG,MAAM,CAAC,SAAS,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;IAEhE,OAAO;QACL,IAAI;QACJ,OAAO,EAAE;YACP,QAAQ,EAAE,qBAAqB;YAC/B,IAAI,EAAE;gBACJ,WAAW,EAAE,MAAM,CAAC,KAAK;gBACzB,SAAS;gBACT,YAAY;gBACZ,WAAW;aACZ;SACF;QACD,MAAM,EAAE;YACN,QAAQ,EAAE,cAAc;YACxB,aAAa;SACd;KACF,CAAC;AACJ,CAAC,CAAC"}
@@ -1,3 +0,0 @@
1
- import * as budgetInsights_1 from './budgets-insights';
2
- export { budgetInsights_1 as budgetInsights };
3
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/transformers/index.ts"],"names":[],"mappings":"kCAAgC,oBAAoB;6BAAxC,cAAc"}
@@ -1,143 +0,0 @@
1
- import get from 'lodash/get';
2
-
3
- import { InsightType } from '../constants';
4
- import { getGlobalMetricType } from '../utils';
5
-
6
- interface OptionBudgetMetric {
7
- metric: string;
8
- value: number;
9
- }
10
-
11
- interface Options {
12
- budgets?: Array<OptionBudgetMetric>;
13
- }
14
-
15
- interface BudgetInsight {
16
- currentValue: number;
17
- budgetValue: number;
18
- failed: boolean;
19
- }
20
-
21
- interface BudgetInsightInfo {
22
- type: InsightType;
23
- message: {
24
- template: string;
25
- data: Record<string, unknown>;
26
- };
27
- source: {
28
- metricId: string;
29
- budgetInsight: BudgetInsight;
30
- };
31
- }
32
-
33
- interface BudgetInsights {
34
- [metricId: string]: BudgetInsight;
35
- }
36
-
37
- interface BudgetsInsightsOutput {
38
- insights: {
39
- budgets: BudgetInsights;
40
- };
41
- }
42
-
43
- export const getExtract =
44
- (source: string) => (
45
- _: unknown,
46
- currentExtractedData: any,
47
- __: unknown,
48
- options: Options = {},
49
- ): BudgetsInsightsOutput | null => {
50
- const { budgets: budgetsOptions } = options;
51
-
52
- if (!budgetsOptions) {
53
- return null;
54
- }
55
-
56
- const insights: Array<[string, BudgetInsight]> = [];
57
-
58
- budgetsOptions.forEach((budgetOption) => {
59
- const { metric: budgetMetricId, value: budgetValue } = budgetOption;
60
- const currentValue = get(currentExtractedData, `metrics.${budgetMetricId}.value`);
61
- const metric = getGlobalMetricType(`${source}.${budgetMetricId}`);
62
-
63
- if (!currentValue) {
64
- return;
65
- }
66
-
67
- const isValueOverBudget = currentValue > budgetValue;
68
-
69
- const budgetInsight = {
70
- currentValue,
71
- budgetValue,
72
- failed: metric.biggerIsBetter ? !isValueOverBudget : isValueOverBudget,
73
- };
74
-
75
- insights.push([budgetMetricId, budgetInsight]);
76
- });
77
-
78
- if (insights.length === 0) {
79
- return null;
80
- }
81
-
82
- return {
83
- insights: {
84
- budgets: Object.fromEntries(insights),
85
- },
86
- };
87
- };
88
-
89
- const resolveDiffLabel = (budgetInsight: BudgetInsight): string => {
90
- const { currentValue, budgetValue } = budgetInsight;
91
-
92
- if (currentValue > budgetValue) {
93
- return 'over';
94
- }
95
-
96
- if (currentValue < budgetValue) {
97
- return 'under';
98
- }
99
-
100
- return 'equal with';
101
- };
102
-
103
- const resolveType = (budgetInsight: BudgetInsight): InsightType => {
104
- if (budgetInsight.failed) {
105
- return InsightType.ERROR;
106
- }
107
-
108
- if (budgetInsight.currentValue === budgetInsight.budgetValue) {
109
- return InsightType.WARNING;
110
- }
111
-
112
- return InsightType.SUCCESS;
113
- };
114
-
115
- // Add escapes for (|) to avoid lodash.template syntax errors
116
- // eslint-disable-next-line no-useless-escape
117
- export const INFO_MESSAGE_TEMPLATE = '<%= metricLabel %> value \(<%= currentValue %>\) is <%= diffLabel %> <%= budgetValue %> budget';
118
-
119
- export const getInfo = (globalMetricId: string, budgetInsight: BudgetInsight): BudgetInsightInfo => {
120
- const metric = getGlobalMetricType(globalMetricId);
121
-
122
- const diffLabel = resolveDiffLabel(budgetInsight);
123
- const type = resolveType(budgetInsight);
124
- const currentValue = metric.formatter(budgetInsight.currentValue);
125
- const budgetValue = metric.formatter(budgetInsight.budgetValue);
126
-
127
- return {
128
- type,
129
- message: {
130
- template: INFO_MESSAGE_TEMPLATE,
131
- data: {
132
- metricLabel: metric.label,
133
- diffLabel,
134
- currentValue,
135
- budgetValue,
136
- },
137
- },
138
- source: {
139
- metricId: globalMetricId,
140
- budgetInsight,
141
- },
142
- };
143
- };
@@ -1 +0,0 @@
1
- export * as budgetInsights from './budgets-insights';
@@ -1,36 +0,0 @@
1
- import { InsightType } from '../constants';
2
- interface OptionBudgetMetric {
3
- metric: string;
4
- value: number;
5
- }
6
- interface Options {
7
- budgets?: Array<OptionBudgetMetric>;
8
- }
9
- interface BudgetInsight {
10
- currentValue: number;
11
- budgetValue: number;
12
- failed: boolean;
13
- }
14
- interface BudgetInsightInfo {
15
- type: InsightType;
16
- message: {
17
- template: string;
18
- data: Record<string, unknown>;
19
- };
20
- source: {
21
- metricId: string;
22
- budgetInsight: BudgetInsight;
23
- };
24
- }
25
- interface BudgetInsights {
26
- [metricId: string]: BudgetInsight;
27
- }
28
- interface BudgetsInsightsOutput {
29
- insights: {
30
- budgets: BudgetInsights;
31
- };
32
- }
33
- export declare const getExtract: (source: string) => (_: unknown, currentExtractedData: any, __: unknown, options?: Options) => BudgetsInsightsOutput | null;
34
- export declare const INFO_MESSAGE_TEMPLATE = "<%= metricLabel %> value (<%= currentValue %>) is <%= diffLabel %> <%= budgetValue %> budget";
35
- export declare const getInfo: (globalMetricId: string, budgetInsight: BudgetInsight) => BudgetInsightInfo;
36
- export {};
@@ -1 +0,0 @@
1
- export * as budgetInsights from './budgets-insights';