@infomaximum/widget-sdk 4.13.0 → 5.0.0-beta10

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/index.js CHANGED
@@ -41,48 +41,6 @@ exports.EDrawerPlacement = void 0;
41
41
  EDrawerPlacement["LEFT"] = "LEFT";
42
42
  EDrawerPlacement["RIGHT"] = "RIGHT";
43
43
  })(exports.EDrawerPlacement || (exports.EDrawerPlacement = {}));
44
- /**
45
- * @deprecated Функция может работать некорректно и будет удалена в будущих версиях.
46
- * Необходимо использовать {@link IWidgetProps.actionValidator }.
47
- */
48
- var isExecuteScriptActionValid = function (action, _a) {
49
- var _b;
50
- var scripts = _a.scripts, tables = _a.tables, variables = _a.variables, systemVariables = _a.systemVariables;
51
- var currentScript = scripts.get((_b = action.scriptKey) !== null && _b !== void 0 ? _b : "");
52
- if (!currentScript) {
53
- return false;
54
- }
55
- var actionInputsMap = new Map(action.parameters.map(function (parameter) { return [parameter.name, parameter]; }));
56
- if (actionInputsMap.size < currentScript.fields.length) {
57
- return false;
58
- }
59
- return currentScript.fields.every(function (_a) {
60
- var name = _a.name, isRequired = _a.isRequired;
61
- var actionInput = actionInputsMap.get(name !== null && name !== void 0 ? name : "");
62
- if (!actionInput) {
63
- return false;
64
- }
65
- if (!isRequired) {
66
- return true;
67
- }
68
- if (actionInput.inputMethod === exports.EWidgetActionInputMethod.VARIABLE &&
69
- !variables.has(actionInput.sourceVariable) &&
70
- !systemVariables.has(actionInput.sourceVariable)) {
71
- return false;
72
- }
73
- if (actionInput.inputMethod === exports.EWidgetActionInputMethod.FORMULA && !actionInput.formula) {
74
- return false;
75
- }
76
- if (actionInput.inputMethod === exports.EWidgetActionInputMethod.DYNAMIC_LIST && !actionInput.options) {
77
- return false;
78
- }
79
- if (actionInput.inputMethod === exports.EWidgetActionInputMethod.COLUMN &&
80
- !tables.has(actionInput.tableName)) {
81
- return false;
82
- }
83
- return true;
84
- });
85
- };
86
44
  exports.EActionButtonsTypes = void 0;
87
45
  (function (EActionButtonsTypes) {
88
46
  EActionButtonsTypes["LINK"] = "link";
@@ -102,10 +60,10 @@ exports.ESimpleDataType = void 0;
102
60
  ESimpleDataType["BOOLEAN"] = "BOOLEAN";
103
61
  })(exports.ESimpleDataType || (exports.ESimpleDataType = {}));
104
62
 
105
- var prepareValuesForSql = function (dataType, values) {
106
- return dataType === exports.ESimpleDataType.INTEGER ||
107
- dataType === exports.ESimpleDataType.FLOAT ||
108
- dataType === exports.ESimpleDataType.BOOLEAN
63
+ var prepareValuesForSql = function (simpleType, values) {
64
+ return simpleType === exports.ESimpleDataType.INTEGER ||
65
+ simpleType === exports.ESimpleDataType.FLOAT ||
66
+ simpleType === exports.ESimpleDataType.BOOLEAN
109
67
  ? values
110
68
  : values.map(function (value) {
111
69
  return value === null ? null : "'".concat(escapeSingularQuotes(escapeReverseSlash(value)), "'");
@@ -218,6 +176,128 @@ var compactMap = function (items, f) {
218
176
  var isNil = function (value) {
219
177
  return value === null || value === undefined;
220
178
  };
179
+ function memoize(fn) {
180
+ var cache = new Map();
181
+ return function (arg) {
182
+ if (cache.has(arg)) {
183
+ return cache.get(arg);
184
+ }
185
+ var result = fn(arg);
186
+ cache.set(arg, result);
187
+ return result;
188
+ };
189
+ }
190
+
191
+ exports.EClickHouseBaseTypes = void 0;
192
+ (function (EClickHouseBaseTypes) {
193
+ // DATE
194
+ EClickHouseBaseTypes["Date"] = "Date";
195
+ EClickHouseBaseTypes["Date32"] = "Date32";
196
+ // DATETIME
197
+ EClickHouseBaseTypes["DateTime"] = "DateTime";
198
+ EClickHouseBaseTypes["DateTime32"] = "DateTime32";
199
+ // DATETIME64
200
+ EClickHouseBaseTypes["DateTime64"] = "DateTime64";
201
+ // STRING
202
+ EClickHouseBaseTypes["FixedString"] = "FixedString";
203
+ EClickHouseBaseTypes["String"] = "String";
204
+ // FLOAT
205
+ EClickHouseBaseTypes["Decimal"] = "Decimal";
206
+ EClickHouseBaseTypes["Decimal32"] = "Decimal32";
207
+ EClickHouseBaseTypes["Decimal64"] = "Decimal64";
208
+ EClickHouseBaseTypes["Decimal128"] = "Decimal128";
209
+ EClickHouseBaseTypes["Decimal256"] = "Decimal256";
210
+ EClickHouseBaseTypes["Float32"] = "Float32";
211
+ EClickHouseBaseTypes["Float64"] = "Float64";
212
+ // INTEGER
213
+ EClickHouseBaseTypes["Int8"] = "Int8";
214
+ EClickHouseBaseTypes["Int16"] = "Int16";
215
+ EClickHouseBaseTypes["Int32"] = "Int32";
216
+ EClickHouseBaseTypes["Int64"] = "Int64";
217
+ EClickHouseBaseTypes["Int128"] = "Int128";
218
+ EClickHouseBaseTypes["Int256"] = "Int256";
219
+ EClickHouseBaseTypes["UInt8"] = "UInt8";
220
+ EClickHouseBaseTypes["UInt16"] = "UInt16";
221
+ EClickHouseBaseTypes["UInt32"] = "UInt32";
222
+ EClickHouseBaseTypes["UInt64"] = "UInt64";
223
+ EClickHouseBaseTypes["UInt128"] = "UInt128";
224
+ EClickHouseBaseTypes["UInt256"] = "UInt256";
225
+ // BOOLEAN
226
+ EClickHouseBaseTypes["Bool"] = "Bool";
227
+ })(exports.EClickHouseBaseTypes || (exports.EClickHouseBaseTypes = {}));
228
+ var stringTypes = ["String", "FixedString"];
229
+ var parseClickHouseType = memoize(function (type) {
230
+ if (isNil(type)) {
231
+ return {
232
+ simpleBaseType: exports.ESimpleDataType.OTHER,
233
+ dbBaseDataType: undefined,
234
+ containers: [],
235
+ simpleType: exports.ESimpleDataType.OTHER,
236
+ };
237
+ }
238
+ var _a = extractInnerType(type), containers = _a.containers, dbBaseDataType = _a.dbBaseDataType;
239
+ if (!dbBaseDataType) {
240
+ throw new Error("Invalid ClickHouse type: ".concat(type));
241
+ }
242
+ return {
243
+ dbBaseDataType: dbBaseDataType,
244
+ simpleBaseType: simplifyBaseType(dbBaseDataType),
245
+ containers: containers,
246
+ get simpleType() {
247
+ return containers.includes("Array") ? exports.ESimpleDataType.OTHER : this.simpleBaseType;
248
+ },
249
+ };
250
+ });
251
+ /** 'A(B(C))' -> ['A', 'B', 'C'] */
252
+ var splitByBrackets = function (input) { return input.split(/[\(\)]/).filter(Boolean); };
253
+ /**
254
+ * Отделить внутренний тип от оберток.
255
+ * Не поддерживаются обертки Tuple и LowCardinality.
256
+ */
257
+ var extractInnerType = function (type) {
258
+ var tokens = splitByBrackets(type);
259
+ // Удаление параметров типа.
260
+ if (tokens.length > 0 && isTypeParameters(tokens.at(-1))) {
261
+ tokens.pop();
262
+ }
263
+ var dbBaseDataType = tokens.pop();
264
+ return { containers: tokens, dbBaseDataType: dbBaseDataType };
265
+ };
266
+ var simplifyBaseType = function (dbBaseType) {
267
+ var isSourceTypeStartsWith = function (prefix) { return dbBaseType.startsWith(prefix); };
268
+ if (isSourceTypeStartsWith("Int") || isSourceTypeStartsWith("UInt")) {
269
+ return exports.ESimpleDataType.INTEGER;
270
+ }
271
+ if (isSourceTypeStartsWith("Decimal") || isSourceTypeStartsWith("Float")) {
272
+ return exports.ESimpleDataType.FLOAT;
273
+ }
274
+ if (stringTypes.some(isSourceTypeStartsWith)) {
275
+ return exports.ESimpleDataType.STRING;
276
+ }
277
+ if (isSourceTypeStartsWith("DateTime64")) {
278
+ return exports.ESimpleDataType.DATETIME64;
279
+ }
280
+ if (isSourceTypeStartsWith("DateTime")) {
281
+ return exports.ESimpleDataType.DATETIME;
282
+ }
283
+ if (isSourceTypeStartsWith("Date")) {
284
+ return exports.ESimpleDataType.DATE;
285
+ }
286
+ if (isSourceTypeStartsWith("Bool")) {
287
+ return exports.ESimpleDataType.BOOLEAN;
288
+ }
289
+ return exports.ESimpleDataType.OTHER;
290
+ };
291
+ /**
292
+ * - `3` -> true
293
+ * - `3, 'Europe/Moscow'` -> true
294
+ * - `3, Europe/Moscow` -> false
295
+ *
296
+ * Пример типа с параметрами: `DateTime64(3, 'Europe/Moscow')`
297
+ */
298
+ var isTypeParameters = function (stringifiedParameters) {
299
+ return stringifiedParameters.split(", ").some(function (p) { return !Number.isNaN(Number(p)) || p.startsWith("'"); });
300
+ };
221
301
 
222
302
  exports.EFormatTypes = void 0;
223
303
  (function (EFormatTypes) {
@@ -352,7 +432,7 @@ exports.EFormattingPresets = void 0;
352
432
  EFormattingPresets["R[-]YY"] = "R[-]YY";
353
433
  })(exports.EFormattingPresets || (exports.EFormattingPresets = {}));
354
434
  var formattingConfig = {
355
- get availableFormatsByDataType() {
435
+ get availableFormatsBySimpleType() {
356
436
  var _a;
357
437
  return _a = {},
358
438
  _a[exports.ESimpleDataType.OTHER] = [exports.EFormatTypes.STRING],
@@ -628,17 +708,17 @@ var mapFormulaFilterToCalculatorInput = function (filterValue) {
628
708
  }
629
709
  if (!isFormulaFilterValue(filterValue)) {
630
710
  return {
631
- dataType: exports.ESimpleDataType.OTHER,
711
+ dbDataType: exports.EClickHouseBaseTypes.Bool,
632
712
  formula: filterValue.formula,
633
713
  values: ["1"],
634
714
  filteringMethod: formulaFilterMethods.EQUAL_TO,
635
715
  };
636
716
  }
637
- var formula = filterValue.formula, filteringMethod = filterValue.filteringMethod, dataType = filterValue.dataType;
717
+ var formula = filterValue.formula, filteringMethod = filterValue.filteringMethod, dbDataType = filterValue.dbDataType;
638
718
  return {
639
719
  formula: formula,
640
720
  filteringMethod: filteringMethod,
641
- dataType: dataType,
721
+ dbDataType: dbDataType,
642
722
  values: getFormulaFilterValues(filterValue),
643
723
  };
644
724
  };
@@ -718,11 +798,6 @@ exports.EWidgetIndicatorType = void 0;
718
798
  EWidgetIndicatorType["DIMENSION"] = "DIMENSION";
719
799
  EWidgetIndicatorType["SORTING"] = "SORTING";
720
800
  })(exports.EWidgetIndicatorType || (exports.EWidgetIndicatorType = {}));
721
- exports.EDbType = void 0;
722
- (function (EDbType) {
723
- EDbType["CH"] = "CH";
724
- EDbType["HADOOP"] = "HADOOP";
725
- })(exports.EDbType || (exports.EDbType = {}));
726
801
  /** Режимы значения показателя (на основе чего генерируется формула) */
727
802
  exports.EWidgetIndicatorValueModes = void 0;
728
803
  (function (EWidgetIndicatorValueModes) {
@@ -744,12 +819,14 @@ exports.EIndicatorType = void 0;
744
819
  (function (EIndicatorType) {
745
820
  /** Показатели процесса */
746
821
  EIndicatorType["PROCESS_MEASURE"] = "PROCESS_MEASURE";
747
- /** Статичное значение */
822
+ /** Вводимое значение */
748
823
  EIndicatorType["STATIC"] = "STATIC";
749
824
  /** Статический список */
750
825
  EIndicatorType["STATIC_LIST"] = "STATIC_LIST";
751
826
  /** Динамический список */
752
827
  EIndicatorType["DYNAMIC_LIST"] = "DYNAMIC_LIST";
828
+ /** Список колонок */
829
+ EIndicatorType["COLUMN_LIST"] = "COLUMN_LIST";
753
830
  /** Разрез */
754
831
  EIndicatorType["DIMENSION"] = "DIMENSION";
755
832
  /** Мера */
@@ -759,6 +836,20 @@ exports.EIndicatorType = void 0;
759
836
  /** Пользовательская сортировка */
760
837
  EIndicatorType["USER_SORTING"] = "USER_SORTING";
761
838
  })(exports.EIndicatorType || (exports.EIndicatorType = {}));
839
+ /** Обобщенные типы значений переменных */
840
+ exports.ESimpleInputType = void 0;
841
+ (function (ESimpleInputType) {
842
+ /** Число (точность Float64) */
843
+ ESimpleInputType["NUMBER"] = "FLOAT";
844
+ /** Целое число (точность Int64) */
845
+ ESimpleInputType["INTEGER_NUMBER"] = "INTEGER";
846
+ /** Текст */
847
+ ESimpleInputType["TEXT"] = "STRING";
848
+ /** Дата (точность Date) */
849
+ ESimpleInputType["DATE"] = "DATE";
850
+ /** Дата и время (точность DateTime64) */
851
+ ESimpleInputType["DATE_AND_TIME"] = "DATETIME";
852
+ })(exports.ESimpleInputType || (exports.ESimpleInputType = {}));
762
853
  function isDimensionsHierarchy(indicator) {
763
854
  return "hierarchyDimensions" in indicator;
764
855
  }
@@ -792,17 +883,18 @@ var dimensionTemplateFormulas = (_a$3 = {},
792
883
  _a$3[exports.EDimensionTemplateNames.hour] = "if(defaultValueOfArgumentType({columnFormula}) = {columnFormula}, 0, toHour({columnFormula}))",
793
884
  _a$3);
794
885
  function getDimensionFormula(_a) {
886
+ var _b;
795
887
  var value = _a.value;
796
888
  if (!value) {
797
889
  return "";
798
890
  }
799
891
  if (value.mode === exports.EWidgetIndicatorValueModes.FORMULA) {
800
- return value.formula;
892
+ return (_b = value.formula) !== null && _b !== void 0 ? _b : "";
801
893
  }
802
894
  if (value.mode === exports.EWidgetIndicatorValueModes.TEMPLATE) {
803
895
  var templateName = value.templateName, tableName = value.tableName, columnName = value.columnName;
804
896
  var templateFormula = dimensionTemplateFormulas[templateName];
805
- if (!templateFormula) {
897
+ if (!templateFormula || !tableName || !columnName) {
806
898
  return "";
807
899
  }
808
900
  return fillTemplateString(templateFormula, {
@@ -833,17 +925,18 @@ var measureTemplateFormulas = (_a$2 = {},
833
925
  _a$2[exports.EMeasureTemplateNames.sum] = "sum({columnFormula})",
834
926
  _a$2);
835
927
  function getMeasureFormula(_a) {
928
+ var _b;
836
929
  var value = _a.value;
837
930
  if (!value) {
838
931
  return "";
839
932
  }
840
933
  if (value.mode === exports.EWidgetIndicatorValueModes.FORMULA) {
841
- return value.formula;
934
+ return (_b = value.formula) !== null && _b !== void 0 ? _b : "";
842
935
  }
843
936
  if (value.mode === exports.EWidgetIndicatorValueModes.TEMPLATE) {
844
937
  var templateName = value.templateName, tableName = value.tableName, columnName = value.columnName;
845
938
  var templateFormula = measureTemplateFormulas[templateName];
846
- if (!templateFormula) {
939
+ if (!templateFormula || !tableName || !columnName) {
847
940
  return "";
848
941
  }
849
942
  return fillTemplateString(templateFormula, {
@@ -949,7 +1042,7 @@ function mapMeasureToInput(measure, variables, addFormulas) {
949
1042
  return {
950
1043
  alias: String(measure.id),
951
1044
  mainFormula: mainFormula,
952
- dataType: measure.dataType,
1045
+ dbDataType: measure.dbDataType,
953
1046
  displayConditionFormula: getDisplayConditionFormula(measure.displayCondition),
954
1047
  additionalFormulas: addFormulas(measure),
955
1048
  };
@@ -970,7 +1063,7 @@ function mapDimensionToInput(dimension, variables) {
970
1063
  return {
971
1064
  alias: String(dimension.id),
972
1065
  formula: formula,
973
- dataType: dimension.dataType,
1066
+ dbDataType: dimension.dbDataType,
974
1067
  hideEmpty: dimension.hideEmptyValues,
975
1068
  displayConditionFormula: getDisplayConditionFormula(dimension.displayCondition),
976
1069
  };
@@ -992,7 +1085,7 @@ function mapTransitionMeasureToInput(indicator, process, variables, addFormulas)
992
1085
  return {
993
1086
  alias: String(indicator.id),
994
1087
  mainFormula: mainFormula,
995
- dataType: indicator.dataType,
1088
+ dbDataType: indicator.dbDataType,
996
1089
  displayConditionFormula: getDisplayConditionFormula(indicator.displayCondition),
997
1090
  additionalFormulas: addFormulas(indicator),
998
1091
  };
@@ -1016,7 +1109,7 @@ function mapEventMeasureToInput(indicator, process, variables, addFormulas) {
1016
1109
  return {
1017
1110
  alias: String(indicator.id),
1018
1111
  mainFormula: mainFormula,
1019
- dataType: indicator.dataType,
1112
+ dbDataType: indicator.dbDataType,
1020
1113
  displayConditionFormula: getDisplayConditionFormula(indicator.displayCondition),
1021
1114
  additionalFormulas: addFormulas(indicator),
1022
1115
  };
@@ -1097,7 +1190,7 @@ var getDefaultSortOrders = function (_a) {
1097
1190
  return [
1098
1191
  {
1099
1192
  formula: getDimensionFormula(timeDimension),
1100
- dataType: timeDimension.dataType,
1193
+ dbDataType: timeDimension.dbDataType,
1101
1194
  direction: exports.ESortDirection.ascend,
1102
1195
  },
1103
1196
  ];
@@ -1109,7 +1202,7 @@ var getDefaultSortOrders = function (_a) {
1109
1202
  {
1110
1203
  direction: exports.ESortDirection.descend,
1111
1204
  formula: getMeasureFormula(firstMeasure),
1112
- dataType: firstMeasure.dataType,
1205
+ dbDataType: firstMeasure.dbDataType,
1113
1206
  },
1114
1207
  ];
1115
1208
  }
@@ -1124,7 +1217,7 @@ function mapSortingToInputs(_a) {
1124
1217
  var direction = _a.direction, value = _a.value;
1125
1218
  if (value.mode === exports.ESortingValueModes.FORMULA) {
1126
1219
  return value.formula
1127
- ? { formula: value.formula, direction: direction, dataType: value.dataType }
1220
+ ? { formula: value.formula, direction: direction, dbDataType: value.dbDataType }
1128
1221
  : undefined;
1129
1222
  }
1130
1223
  var indicatorsGroup = settings[value.group];
@@ -1143,7 +1236,7 @@ function mapSortingToInputs(_a) {
1143
1236
  return {
1144
1237
  formula: formula,
1145
1238
  direction: direction,
1146
- dataType: activeDimensions.dataType,
1239
+ dbDataType: activeDimensions.dbDataType,
1147
1240
  displayCondition: ((_b = indicator.displayCondition) === null || _b === void 0 ? void 0 : _b.mode) === exports.EDisplayConditionMode.FORMULA
1148
1241
  ? indicator.displayCondition.formula
1149
1242
  : undefined,
@@ -1152,7 +1245,7 @@ function mapSortingToInputs(_a) {
1152
1245
  return {
1153
1246
  formula: getMeasureFormula(indicator),
1154
1247
  direction: direction,
1155
- dataType: indicator.dataType,
1248
+ dbDataType: indicator.dbDataType,
1156
1249
  };
1157
1250
  });
1158
1251
  return sortOrder;
@@ -1444,7 +1537,6 @@ exports.getMeasureFormula = getMeasureFormula;
1444
1537
  exports.getRuleColor = getRuleColor;
1445
1538
  exports.getTransitionMeasureFormula = getTransitionMeasureFormula;
1446
1539
  exports.isDimensionsHierarchy = isDimensionsHierarchy;
1447
- exports.isExecuteScriptActionValid = isExecuteScriptActionValid;
1448
1540
  exports.isFormulaFilterValue = isFormulaFilterValue;
1449
1541
  exports.isValidColor = isValidColor;
1450
1542
  exports.linkNameRegExp = linkNameRegExp;
@@ -1456,6 +1548,7 @@ exports.mapMeasuresToInputs = mapMeasuresToInputs;
1456
1548
  exports.mapSortingToInputs = mapSortingToInputs;
1457
1549
  exports.mapTransitionMeasuresToInputs = mapTransitionMeasuresToInputs;
1458
1550
  exports.measureTemplateFormulas = measureTemplateFormulas;
1551
+ exports.parseClickHouseType = parseClickHouseType;
1459
1552
  exports.parseIndicatorLink = parseIndicatorLink;
1460
1553
  exports.prepareSortOrders = prepareSortOrders;
1461
1554
  exports.prepareValuesForSql = prepareValuesForSql;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infomaximum/widget-sdk",
3
- "version": "4.13.0",
3
+ "version": "5.0.0-beta10",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.esm.js",
6
6
  "types": "./dist/index.d.ts",
@@ -9,12 +9,14 @@
9
9
  "dist/",
10
10
  "LICENSE"
11
11
  ],
12
+ "sideEffects": false,
12
13
  "scripts": {
13
14
  "build": "rollup -c",
14
15
  "lint": "tsc --noEmit",
15
16
  "release": "npm run lint && standard-version && npm run build",
16
17
  "format": "prettier --find-config-path --write 'src/**/*'",
17
- "prepublishOnly": "npm run build"
18
+ "prepublishOnly": "npm run build",
19
+ "test": "jest"
18
20
  },
19
21
  "dependencies": {
20
22
  "@infomaximum/base-filter": "^1.1.0",
@@ -22,11 +24,16 @@
22
24
  "@infomaximum/localization": "^1.0.4"
23
25
  },
24
26
  "devDependencies": {
27
+ "@babel/core": "^7.26.0",
28
+ "@babel/preset-env": "^7.26.0",
29
+ "@babel/preset-typescript": "^7.26.0",
25
30
  "@infomaximum/config": "^2.6.0",
26
31
  "@rollup/plugin-commonjs": "25.0.7",
27
32
  "@rollup/plugin-node-resolve": "15.2.3",
28
33
  "@rollup/plugin-typescript": "11.1.5",
34
+ "@types/jest": "^29.5.14",
29
35
  "core-js": "^3.38.0",
36
+ "jest": "^29.7.0",
30
37
  "prettier": "3.2.5",
31
38
  "rollup": "4.14.3",
32
39
  "rollup-plugin-delete": "2.0.0",