@sisense/sdk-data 1.33.0 → 2.0.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.
Files changed (97) hide show
  1. package/dist/cjs/dimensional-model/analytics/factory.d.ts +10 -10
  2. package/dist/cjs/dimensional-model/analytics/factory.js +15 -16
  3. package/dist/cjs/dimensional-model/attributes.d.ts +13 -6
  4. package/dist/cjs/dimensional-model/attributes.js +39 -12
  5. package/dist/cjs/dimensional-model/base.d.ts +3 -3
  6. package/dist/cjs/dimensional-model/base.js +7 -4
  7. package/dist/cjs/dimensional-model/compose-code-utils.d.ts +41 -0
  8. package/dist/cjs/dimensional-model/compose-code-utils.js +127 -0
  9. package/dist/cjs/dimensional-model/consts.d.ts +1 -0
  10. package/dist/cjs/dimensional-model/consts.js +4 -0
  11. package/dist/cjs/dimensional-model/data-model.d.ts +1 -1
  12. package/dist/cjs/dimensional-model/data-model.js +1 -1
  13. package/dist/cjs/dimensional-model/dimensions/dimensions.d.ts +6 -6
  14. package/dist/cjs/dimensional-model/dimensions/dimensions.js +34 -17
  15. package/dist/cjs/dimensional-model/dimensions/utils.d.ts +1 -0
  16. package/dist/cjs/dimensional-model/dimensions/utils.js +2 -1
  17. package/dist/cjs/dimensional-model/factory.js +5 -5
  18. package/dist/cjs/dimensional-model/filters/factory.d.ts +42 -42
  19. package/dist/cjs/dimensional-model/filters/factory.js +53 -168
  20. package/dist/cjs/dimensional-model/filters/filter-relations.d.ts +11 -2
  21. package/dist/cjs/dimensional-model/filters/filter-relations.js +14 -7
  22. package/dist/cjs/dimensional-model/filters/filters.d.ts +40 -24
  23. package/dist/cjs/dimensional-model/filters/filters.js +106 -56
  24. package/dist/cjs/dimensional-model/filters/helpers.d.ts +1 -1
  25. package/dist/cjs/dimensional-model/filters/helpers.js +2 -2
  26. package/dist/cjs/dimensional-model/filters/utils/attribute-measure-util.js +9 -17
  27. package/dist/cjs/dimensional-model/filters/utils/condition-filter-util.d.ts +1 -1
  28. package/dist/cjs/dimensional-model/filters/utils/condition-filter-util.js +31 -29
  29. package/dist/cjs/dimensional-model/filters/utils/filter-from-jaql-util.d.ts +1 -1
  30. package/dist/cjs/dimensional-model/filters/utils/filter-from-jaql-util.js +13 -19
  31. package/dist/cjs/dimensional-model/filters/utils/filter-types-util.d.ts +1 -1
  32. package/dist/cjs/dimensional-model/filters/utils/filter-types-util.js +1 -1
  33. package/dist/cjs/dimensional-model/filters/utils/types.d.ts +10 -0
  34. package/dist/cjs/dimensional-model/interfaces.d.ts +17 -7
  35. package/dist/cjs/dimensional-model/jaql-element.d.ts +13 -1
  36. package/dist/cjs/dimensional-model/jaql-element.js +54 -2
  37. package/dist/cjs/dimensional-model/measures/factory.d.ts +46 -53
  38. package/dist/cjs/dimensional-model/measures/factory.js +57 -186
  39. package/dist/cjs/dimensional-model/measures/measures.d.ts +10 -10
  40. package/dist/cjs/dimensional-model/measures/measures.js +35 -33
  41. package/dist/cjs/dimensional-model/types.d.ts +41 -16
  42. package/dist/cjs/index.d.ts +7 -7
  43. package/dist/cjs/index.js +7 -7
  44. package/dist/cjs/utils.d.ts +45 -22
  45. package/dist/cjs/utils.js +119 -47
  46. package/dist/dimensional-model/analytics/factory.d.ts +10 -10
  47. package/dist/dimensional-model/analytics/factory.js +15 -14
  48. package/dist/dimensional-model/attributes.d.ts +13 -6
  49. package/dist/dimensional-model/attributes.js +39 -12
  50. package/dist/dimensional-model/base.d.ts +3 -3
  51. package/dist/dimensional-model/base.js +7 -4
  52. package/dist/dimensional-model/compose-code-utils.d.ts +41 -0
  53. package/dist/dimensional-model/compose-code-utils.js +119 -0
  54. package/dist/dimensional-model/consts.d.ts +1 -0
  55. package/dist/dimensional-model/consts.js +1 -0
  56. package/dist/dimensional-model/data-model.d.ts +1 -1
  57. package/dist/dimensional-model/data-model.js +1 -1
  58. package/dist/dimensional-model/dimensions/dimensions.d.ts +6 -6
  59. package/dist/dimensional-model/dimensions/dimensions.js +35 -18
  60. package/dist/dimensional-model/dimensions/utils.d.ts +1 -0
  61. package/dist/dimensional-model/dimensions/utils.js +3 -2
  62. package/dist/dimensional-model/factory.js +5 -5
  63. package/dist/dimensional-model/filters/factory.d.ts +42 -42
  64. package/dist/dimensional-model/filters/factory.js +52 -126
  65. package/dist/dimensional-model/filters/filter-relations.d.ts +11 -2
  66. package/dist/dimensional-model/filters/filter-relations.js +14 -7
  67. package/dist/dimensional-model/filters/filters.d.ts +40 -24
  68. package/dist/dimensional-model/filters/filters.js +106 -56
  69. package/dist/dimensional-model/filters/helpers.d.ts +1 -1
  70. package/dist/dimensional-model/filters/helpers.js +2 -2
  71. package/dist/dimensional-model/filters/utils/attribute-measure-util.js +10 -18
  72. package/dist/dimensional-model/filters/utils/condition-filter-util.d.ts +1 -1
  73. package/dist/dimensional-model/filters/utils/condition-filter-util.js +31 -29
  74. package/dist/dimensional-model/filters/utils/filter-from-jaql-util.d.ts +1 -1
  75. package/dist/dimensional-model/filters/utils/filter-from-jaql-util.js +13 -19
  76. package/dist/dimensional-model/filters/utils/filter-types-util.d.ts +1 -1
  77. package/dist/dimensional-model/filters/utils/filter-types-util.js +1 -1
  78. package/dist/dimensional-model/filters/utils/types.d.ts +10 -0
  79. package/dist/dimensional-model/interfaces.d.ts +17 -7
  80. package/dist/dimensional-model/jaql-element.d.ts +13 -1
  81. package/dist/dimensional-model/jaql-element.js +52 -1
  82. package/dist/dimensional-model/measures/factory.d.ts +46 -53
  83. package/dist/dimensional-model/measures/factory.js +56 -143
  84. package/dist/dimensional-model/measures/measures.d.ts +10 -10
  85. package/dist/dimensional-model/measures/measures.js +35 -33
  86. package/dist/dimensional-model/types.d.ts +41 -16
  87. package/dist/index.d.ts +7 -7
  88. package/dist/index.js +7 -7
  89. package/dist/translation/initialize-i18n.js +1 -1
  90. package/dist/tsconfig.prod.cjs.tsbuildinfo +1 -1
  91. package/dist/utils.d.ts +45 -22
  92. package/dist/utils.js +94 -49
  93. package/package.json +5 -4
  94. package/dist/cjs/dimensional-model/filters/utils/filter-code-util.d.ts +0 -17
  95. package/dist/cjs/dimensional-model/filters/utils/filter-code-util.js +0 -82
  96. package/dist/dimensional-model/filters/utils/filter-code-util.d.ts +0 -17
  97. package/dist/dimensional-model/filters/utils/filter-code-util.js +0 -77
package/dist/cjs/utils.js CHANGED
@@ -1,18 +1,41 @@
1
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
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
5
28
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createDimensionalElementFromJaql = exports.createCalculatedMeasureHelper = exports.createMeasureHelper = exports.createAttributeHelper = exports.getSortType = exports.getColumnNameFromAttribute = exports.getTableNameFromAttribute = exports.createFilterFromJaql = exports.convertSort = exports.convertJaqlDataSource = exports.convertDataSource = exports.isDataSourceInfo = exports.getDataSourceName = exports.getFilterListAndRelationsJaql = exports.guidFast = void 0;
29
+ exports.getGranularityFromJaql = exports.createDimensionalElementFromJaql = exports.createCalculatedMeasureHelper = exports.createMeasureHelper = exports.createAttributeHelper = exports.getSortType = exports.getColumnNameFromAttribute = exports.getTableNameFromAttribute = exports.parseExpression = exports.createFilterFromJaql = exports.convertSortDirectionToSort = exports.convertSort = exports.convertJaqlDataSourceForDto = exports.convertJaqlDataSource = exports.convertDataSource = exports.isDataSourceInfo = exports.getDataSourceName = exports.getFilterListAndRelationsJaql = exports.guidFast = void 0;
7
30
  const cloneDeep_js_1 = __importDefault(require("lodash-es/cloneDeep.js"));
8
31
  const mapValues_js_1 = __importDefault(require("lodash-es/mapValues.js"));
32
+ const attributes_js_1 = require("./dimensional-model/attributes.js");
33
+ const filters_js_1 = require("./dimensional-model/filters/filters.js");
9
34
  const filter_from_jaql_util_js_1 = require("./dimensional-model/filters/utils/filter-from-jaql-util.js");
10
- const types_js_1 = require("./dimensional-model/types.js");
11
- const sdk_common_1 = require("@sisense/sdk-common");
35
+ const measureFactory = __importStar(require("./dimensional-model/measures/factory.js"));
12
36
  const measures_js_1 = require("./dimensional-model/measures/measures.js");
13
- const filters_js_1 = require("./dimensional-model/filters/filters.js");
14
- const attributes_js_1 = require("./dimensional-model/attributes.js");
15
37
  const simple_column_types_js_1 = require("./dimensional-model/simple-column-types.js");
38
+ const types_js_1 = require("./dimensional-model/types.js");
16
39
  /**
17
40
  * A more performant, but slightly bulkier, RFC4122v4 implementation. Performance is improved by minimizing calls to random()
18
41
  *
@@ -142,6 +165,29 @@ function convertJaqlDataSource(dataSource) {
142
165
  };
143
166
  }
144
167
  exports.convertJaqlDataSource = convertJaqlDataSource;
168
+ /**
169
+ * Converts a DataSource to JaqlDataSourceForDto.
170
+ *
171
+ * @internal
172
+ */
173
+ function convertJaqlDataSourceForDto(dataSource) {
174
+ var _a;
175
+ if (isDataSourceInfo(dataSource)) {
176
+ return {
177
+ title: dataSource.title,
178
+ live: dataSource.type === 'live',
179
+ id: (_a = dataSource.id) !== null && _a !== void 0 ? _a : '',
180
+ address: dataSource.address,
181
+ };
182
+ }
183
+ else {
184
+ return {
185
+ title: dataSource,
186
+ id: '',
187
+ };
188
+ }
189
+ }
190
+ exports.convertJaqlDataSourceForDto = convertJaqlDataSourceForDto;
145
191
  /**
146
192
  * Converts a string to a Sort enum
147
193
  *
@@ -158,6 +204,24 @@ function convertSort(sort) {
158
204
  }
159
205
  }
160
206
  exports.convertSort = convertSort;
207
+ /**
208
+ * Converts a SortDirection to a Sort enum
209
+ *
210
+ * @param sortDirection - The SortDirection to convert
211
+ * @returns The converted Sort enum
212
+ * @internal
213
+ */
214
+ function convertSortDirectionToSort(sortDirection) {
215
+ switch (sortDirection) {
216
+ case 'sortAsc':
217
+ return types_js_1.Sort.Ascending;
218
+ case 'sortDesc':
219
+ return types_js_1.Sort.Descending;
220
+ default:
221
+ return types_js_1.Sort.None;
222
+ }
223
+ }
224
+ exports.convertSortDirectionToSort = convertSortDirectionToSort;
161
225
  /**
162
226
  * Creates a filter from a JAQL object.
163
227
  *
@@ -201,6 +265,7 @@ function parseExpression(expression) {
201
265
  : '',
202
266
  };
203
267
  }
268
+ exports.parseExpression = parseExpression;
204
269
  /**
205
270
  * Retrieves the table value from the attribute.
206
271
  *
@@ -237,29 +302,23 @@ function getSortType(jaqlSort) {
237
302
  }
238
303
  }
239
304
  exports.getSortType = getSortType;
240
- const DATA_MODEL_MODULE_NAME = 'DM';
241
305
  /**
242
306
  * Creates an attribute or level attribute from the provided parameters
243
307
  *
244
308
  * @returns attribute or level attribute
245
309
  * @internal
246
310
  */
247
- const createAttributeHelper = ({ dim, table, column, dataType, level, format, sort, title, panel, dataSource, }) => {
248
- // if table is undefined, extract it from dim
249
- const dimTable = table !== null && table !== void 0 ? table : parseExpression(dim).table;
250
- // if column is undefined, extract it from dim
251
- const dimColumn = column !== null && column !== void 0 ? column : parseExpression(dim).column;
311
+ const createAttributeHelper = ({ expression, dataType, granularity, format, sort, title, panel, dataSource, }) => {
312
+ const column = parseExpression(expression).column;
252
313
  const sortEnum = convertSort(sort);
253
314
  const isDataTypeDatetime = dataType === types_js_1.DataType.DATETIME;
254
315
  if (isDataTypeDatetime) {
255
- const dateLevel = attributes_js_1.DimensionalLevelAttribute.translateJaqlToGranularity({ level });
256
- const composeCode = (0, attributes_js_1.normalizeAttributeName)(dimTable, dimColumn, level, DATA_MODEL_MODULE_NAME);
257
- const levelAttribute = new attributes_js_1.DimensionalLevelAttribute(title !== null && title !== void 0 ? title : dimColumn, dim, dateLevel, format || attributes_js_1.DimensionalLevelAttribute.getDefaultFormatForGranularity(dateLevel), undefined, sortEnum, dataSource, composeCode, panel);
316
+ const levelAttribute = new attributes_js_1.DimensionalLevelAttribute(title !== null && title !== void 0 ? title : column, expression, granularity || types_js_1.DateLevels.Years, format ||
317
+ attributes_js_1.DimensionalLevelAttribute.getDefaultFormatForGranularity(granularity || types_js_1.DateLevels.Years), undefined, sortEnum, dataSource, undefined, panel);
258
318
  return levelAttribute;
259
319
  }
260
320
  const attributeType = !dataType || (0, simple_column_types_js_1.isNumber)(dataType) ? types_js_1.MetadataTypes.NumericAttribute : types_js_1.MetadataTypes.TextAttribute;
261
- const composeCode = (0, attributes_js_1.normalizeAttributeName)(dimTable, dimColumn, undefined, DATA_MODEL_MODULE_NAME);
262
- const attribute = new attributes_js_1.DimensionalAttribute(title !== null && title !== void 0 ? title : dimColumn, dim, attributeType, undefined, sortEnum, dataSource, composeCode, panel);
321
+ const attribute = new attributes_js_1.DimensionalAttribute(title !== null && title !== void 0 ? title : column, expression, attributeType, undefined, sortEnum, dataSource, undefined, panel);
263
322
  return attribute;
264
323
  };
265
324
  exports.createAttributeHelper = createAttributeHelper;
@@ -269,37 +328,43 @@ exports.createAttributeHelper = createAttributeHelper;
269
328
  * @returns measure
270
329
  * @internal
271
330
  */
272
- const createMeasureHelper = ({ dim, table, column, dataType, agg, level, format, sort, title, dataSource, }) => {
273
- const sortEnum = convertSort(sort);
331
+ const createMeasureHelper = ({ expression, dataType, agg, granularity, format, sort, title, dataSource, }) => {
274
332
  const attribute = (0, exports.createAttributeHelper)({
275
- dim,
276
- table,
277
- column,
333
+ expression,
278
334
  dataType,
279
- level,
335
+ granularity,
280
336
  format,
281
337
  sort,
282
338
  title,
283
339
  dataSource,
284
340
  });
285
341
  const tranformedAgg = measures_js_1.DimensionalBaseMeasure.aggregationFromJAQL(agg);
342
+ const column = parseExpression(expression).column;
286
343
  const updatedTitle = title !== null && title !== void 0 ? title : `${tranformedAgg} ${column}`;
287
- // currently, sort and format applied to attribute but not to measure
288
- const composeCode = `measureFactory.${tranformedAgg}(${attribute.composeCode}, '${(0, sdk_common_1.escapeSingleQuotes)(updatedTitle)}')`;
289
- const measure = new measures_js_1.DimensionalBaseMeasure(updatedTitle, attribute, tranformedAgg, undefined, undefined, sortEnum, composeCode);
290
- return measure;
344
+ switch (tranformedAgg) {
345
+ case types_js_1.AggregationTypes.Sum:
346
+ return measureFactory.sum(attribute, updatedTitle, format);
347
+ case types_js_1.AggregationTypes.Average:
348
+ return measureFactory.avg(attribute, updatedTitle, format);
349
+ case types_js_1.AggregationTypes.Min:
350
+ return measureFactory.min(attribute, updatedTitle, format);
351
+ case types_js_1.AggregationTypes.Max:
352
+ return measureFactory.max(attribute, updatedTitle, format);
353
+ case types_js_1.AggregationTypes.Count:
354
+ return measureFactory.count(attribute, updatedTitle, format);
355
+ case types_js_1.AggregationTypes.CountDistinct:
356
+ return measureFactory.countDistinct(attribute, updatedTitle, format);
357
+ case types_js_1.AggregationTypes.Median:
358
+ return measureFactory.median(attribute, updatedTitle, format);
359
+ case types_js_1.AggregationTypes.Variance:
360
+ return measureFactory.aggregate(attribute, types_js_1.AggregationTypes.Variance, updatedTitle, format);
361
+ case types_js_1.AggregationTypes.StandardDeviation:
362
+ return measureFactory.aggregate(attribute, types_js_1.AggregationTypes.StandardDeviation, updatedTitle, format);
363
+ default:
364
+ return measureFactory.sum(attribute, updatedTitle, format);
365
+ }
291
366
  };
292
367
  exports.createMeasureHelper = createMeasureHelper;
293
- const getContextComposeCode = (context) => {
294
- return ('{' +
295
- Object.entries(context).reduce((acc, [key, value]) => {
296
- acc =
297
- acc +
298
- `'${key.slice(1, -1)}': ${value && 'composeCode' in value ? value.composeCode : JSON.stringify(value)},`;
299
- return acc;
300
- }, '') +
301
- '}');
302
- };
303
368
  /**
304
369
  * Creates a measure from the provided parameters
305
370
  *
@@ -308,15 +373,13 @@ const getContextComposeCode = (context) => {
308
373
  */
309
374
  const createCalculatedMeasureHelper = (jaql) => {
310
375
  var _a;
311
- const sortEnum = convertSort(jaql.sort);
312
376
  const context = (0, mapValues_js_1.default)((_a = jaql.context) !== null && _a !== void 0 ? _a : {}, (jaqlContextValue) => {
313
377
  if (typeof jaqlContextValue === 'string') {
314
378
  return jaqlContextValue;
315
379
  }
316
380
  return jaqlContextValue && createDimensionalElementFromJaql(jaqlContextValue);
317
381
  });
318
- const composeCode = `measureFactory.customFormula('${(0, sdk_common_1.escapeSingleQuotes)(jaql.title)}', '${jaql.formula}', ${getContextComposeCode(context)})`;
319
- return new measures_js_1.DimensionalCalculatedMeasure(jaql.title, jaql.formula, context, undefined, undefined, sortEnum, composeCode);
382
+ return measureFactory.customFormula(jaql.title, jaql.formula, context);
320
383
  };
321
384
  exports.createCalculatedMeasureHelper = createCalculatedMeasureHelper;
322
385
  /**
@@ -340,12 +403,10 @@ function createDimensionalElementFromJaql(jaql, datetimeFormat, panel) {
340
403
  const hasAggregation = !!jaql.agg;
341
404
  if (hasAggregation) {
342
405
  return (0, exports.createMeasureHelper)({
343
- dim: jaql.dim,
344
- table: jaql.table,
345
- column: jaql.column,
406
+ expression: jaql.dim,
346
407
  dataType: jaql.datatype,
347
408
  agg: jaql.agg || '',
348
- level: jaql.level,
409
+ granularity: getGranularityFromJaql(jaql),
349
410
  format: datetimeFormat,
350
411
  sort: jaql.sort,
351
412
  title: jaql.title,
@@ -353,11 +414,9 @@ function createDimensionalElementFromJaql(jaql, datetimeFormat, panel) {
353
414
  });
354
415
  }
355
416
  return (0, exports.createAttributeHelper)({
356
- dim: jaql.dim,
357
- table: jaql.table,
358
- column: jaql.column,
417
+ expression: jaql.dim,
359
418
  dataType: jaql.datatype,
360
- level: jaql.level,
419
+ granularity: getGranularityFromJaql(jaql),
361
420
  format: datetimeFormat,
362
421
  sort: jaql.sort,
363
422
  title: jaql.title,
@@ -366,3 +425,16 @@ function createDimensionalElementFromJaql(jaql, datetimeFormat, panel) {
366
425
  });
367
426
  }
368
427
  exports.createDimensionalElementFromJaql = createDimensionalElementFromJaql;
428
+ /**
429
+ * Returns the granularity from the provided JAQL object.
430
+ *
431
+ * @param jaql - The JAQL object.
432
+ * @returns string.
433
+ * @internal
434
+ */
435
+ function getGranularityFromJaql(jaql) {
436
+ return (jaql === null || jaql === void 0 ? void 0 : jaql.datatype) && (0, simple_column_types_js_1.isDatetime)(jaql.datatype)
437
+ ? attributes_js_1.DimensionalLevelAttribute.translateJaqlToGranularity(jaql)
438
+ : undefined;
439
+ }
440
+ exports.getGranularityFromJaql = getGranularityFromJaql;
@@ -13,35 +13,35 @@ export declare const BOX_WHISKER: {
13
13
  /**
14
14
  * Returns an array of values for box whisker plot using interquartile range (IQR) calculations.
15
15
  *
16
- * @param {Attribute} target - The target attribute for calculations.
17
- * @returns {Measure[]} An array of measures representing IQR values for box whisker plots.
16
+ * @param target - The target attribute for calculations.
17
+ * @returns An array of measures representing IQR values for box whisker plots.
18
18
  */
19
19
  export declare function boxWhiskerIqrValues(target: Attribute): Measure[];
20
20
  /**
21
21
  * Returns an array of extremum values for box whisker plot.
22
22
  *
23
- * @param {Attribute} target - The target attribute for calculations.
24
- * @returns {Measure[]} An array of measures representing extremum values for box whisker plots.
23
+ * @param target - The target attribute for calculations.
24
+ * @returns An array of measures representing extremum values for box whisker plots.
25
25
  */
26
26
  export declare function boxWhiskerExtremumsValues(target: Attribute): Measure[];
27
27
  /**
28
28
  * Returns an array of values for box whisker plot using standard deviation calculations.
29
29
  *
30
- * @param {Attribute} target - The target attribute for calculations.
31
- * @returns {Measure[]} An array of measures representing standard deviation values for box whisker plots.
30
+ * @param target - The target attribute for calculations.
31
+ * @returns An array of measures representing standard deviation values for box whisker plots.
32
32
  */
33
33
  export declare function boxWhiskerStdDevValues(target: Attribute): Measure[];
34
34
  /**
35
35
  * Returns an attribute representing outlier points based on interquartile range (IQR) calculations.
36
36
  *
37
- * @param {Attribute} target - The target attribute for calculations.
38
- * @returns {Attribute} An attribute representing outliers for box whisker plots using IQR.
37
+ * @param target - The target attribute for calculations.
38
+ * @returns An attribute representing outliers for box whisker plots using IQR.
39
39
  */
40
40
  export declare const boxWhiskerIqrOutliers: (target: Attribute) => Attribute;
41
41
  /**
42
42
  * Returns an attribute representing outlier points based on standard deviation calculations.
43
43
  *
44
- * @param {Attribute} target - The target attribute for calculations.
45
- * @returns {Attribute} An attribute representing outliers for box whisker plots using standard deviation.
44
+ * @param target - The target attribute for calculations.
45
+ * @returns An attribute representing outliers for box whisker plots using standard deviation.
46
46
  */
47
47
  export declare const boxWhiskerStdDevOutliers: (target: Attribute) => Attribute;
@@ -1,4 +1,5 @@
1
1
  import cloneDeep from 'lodash-es/cloneDeep.js';
2
+ import { withComposeCodeForAnalytics } from '../compose-code-utils.js';
2
3
  import { customFormula } from '../measures/factory.js';
3
4
  /** @internal */
4
5
  export const BOX_WHISKER = {
@@ -27,8 +28,8 @@ function boxWhiskerCommonValues(target) {
27
28
  /**
28
29
  * Returns an array of values for box whisker plot using interquartile range (IQR) calculations.
29
30
  *
30
- * @param {Attribute} target - The target attribute for calculations.
31
- * @returns {Measure[]} An array of measures representing IQR values for box whisker plots.
31
+ * @param target - The target attribute for calculations.
32
+ * @returns An array of measures representing IQR values for box whisker plots.
32
33
  */
33
34
  export function boxWhiskerIqrValues(target) {
34
35
  return [
@@ -47,8 +48,8 @@ export function boxWhiskerIqrValues(target) {
47
48
  /**
48
49
  * Returns an array of extremum values for box whisker plot.
49
50
  *
50
- * @param {Attribute} target - The target attribute for calculations.
51
- * @returns {Measure[]} An array of measures representing extremum values for box whisker plots.
51
+ * @param target - The target attribute for calculations.
52
+ * @returns An array of measures representing extremum values for box whisker plots.
52
53
  */
53
54
  export function boxWhiskerExtremumsValues(target) {
54
55
  return [
@@ -64,8 +65,8 @@ export function boxWhiskerExtremumsValues(target) {
64
65
  /**
65
66
  * Returns an array of values for box whisker plot using standard deviation calculations.
66
67
  *
67
- * @param {Attribute} target - The target attribute for calculations.
68
- * @returns {Measure[]} An array of measures representing standard deviation values for box whisker plots.
68
+ * @param target - The target attribute for calculations.
69
+ * @returns An array of measures representing standard deviation values for box whisker plots.
69
70
  */
70
71
  export function boxWhiskerStdDevValues(target) {
71
72
  return [
@@ -84,10 +85,10 @@ export function boxWhiskerStdDevValues(target) {
84
85
  /**
85
86
  * Returns an attribute representing outlier points based on interquartile range (IQR) calculations.
86
87
  *
87
- * @param {Attribute} target - The target attribute for calculations.
88
- * @returns {Attribute} An attribute representing outliers for box whisker plots using IQR.
88
+ * @param target - The target attribute for calculations.
89
+ * @returns An attribute representing outliers for box whisker plots using IQR.
89
90
  */
90
- export const boxWhiskerIqrOutliers = (target) => {
91
+ export const boxWhiskerIqrOutliers = withComposeCodeForAnalytics((target) => {
91
92
  const outliersAttrWithInnerFilter = cloneDeep(target);
92
93
  const outliersMax = customFormula(BOX_WHISKER.OUTLIER_MAX_VALUE_NAME, '(UPPERWHISKERMIN_IQR([Attr]), all([Attr]))', {
93
94
  Attr: target,
@@ -110,14 +111,14 @@ export const boxWhiskerIqrOutliers = (target) => {
110
111
  return nested ? jaql : { jaql };
111
112
  };
112
113
  return outliersAttrWithInnerFilter;
113
- };
114
+ }, 'boxWhiskerIqrOutliers');
114
115
  /**
115
116
  * Returns an attribute representing outlier points based on standard deviation calculations.
116
117
  *
117
- * @param {Attribute} target - The target attribute for calculations.
118
- * @returns {Attribute} An attribute representing outliers for box whisker plots using standard deviation.
118
+ * @param target - The target attribute for calculations.
119
+ * @returns An attribute representing outliers for box whisker plots using standard deviation.
119
120
  */
120
- export const boxWhiskerStdDevOutliers = (target) => {
121
+ export const boxWhiskerStdDevOutliers = withComposeCodeForAnalytics((target) => {
121
122
  const outliersAttrWithInnerFilter = cloneDeep(target);
122
123
  const outliersMax = customFormula(BOX_WHISKER.OUTLIER_MAX_VALUE_NAME, '(UPPERWHISKERMIN_STDEVP([Attr]), all([Attr]))', {
123
124
  Attr: target,
@@ -139,4 +140,4 @@ export const boxWhiskerStdDevOutliers = (target) => {
139
140
  return nested ? jaql : { jaql };
140
141
  };
141
142
  return outliersAttrWithInnerFilter;
142
- };
143
+ }, 'boxWhiskerStdDevOutliers');
@@ -1,6 +1,6 @@
1
- import { Attribute, LevelAttribute } from './interfaces.js';
2
- import { Sort, JaqlDataSource } from './types.js';
3
1
  import { DimensionalElement } from './base.js';
2
+ import { Attribute, LevelAttribute } from './interfaces.js';
3
+ import { DateLevel, JaqlDataSource, JSONObject, Sort } from './types.js';
4
4
  /**
5
5
  * @internal
6
6
  */
@@ -39,7 +39,7 @@ export declare class DimensionalAttribute extends DimensionalElement implements
39
39
  /**
40
40
  * Gets a serializable representation of the element
41
41
  */
42
- serializable(): any;
42
+ serialize(): JSONObject;
43
43
  }
44
44
  /**
45
45
  * @internal
@@ -48,7 +48,7 @@ export declare class DimensionalLevelAttribute extends DimensionalAttribute impl
48
48
  private _format;
49
49
  readonly granularity: string;
50
50
  readonly panel: string;
51
- constructor(l: string, expression: string, granularity: string, format?: string, desc?: string, sort?: Sort, dataSource?: JaqlDataSource, composeCode?: string, panel?: string);
51
+ constructor(name: string, expression: string, granularity: string, format?: string, desc?: string, sort?: Sort, dataSource?: JaqlDataSource, composeCode?: string, panel?: string);
52
52
  /**
53
53
  * gets the element's ID
54
54
  */
@@ -79,10 +79,17 @@ export declare class DimensionalLevelAttribute extends DimensionalAttribute impl
79
79
  * @returns An instance representing the formatted {@link LevelAttribute} of this instance
80
80
  */
81
81
  format(format: string): LevelAttribute;
82
+ /**
83
+ * Gets a {@link LevelAttribute} with the given granularity
84
+ *
85
+ * @param granularity - Date granularity
86
+ * @returns New instance representing {@link LevelAttribute} with provided granularity
87
+ */
88
+ setGranularity(granularity: DateLevel): LevelAttribute;
82
89
  /**
83
90
  * Gets a serializable representation of the element
84
91
  */
85
- serializable(): any;
92
+ serialize(): JSONObject;
86
93
  /**
87
94
  * Gets the JAQL representation of this instance
88
95
  *
@@ -138,4 +145,4 @@ export declare function createLevel(json: any): LevelAttribute;
138
145
  * @return full normalized attribute name (e.g., DM.CommerceSales.OrderDate.Years)
139
146
  * @internal
140
147
  */
141
- export declare function normalizeAttributeName(tableName: string, columnName: string, dateLevel?: string, modelName?: string): string;
148
+ export declare function normalizeAttributeName(tableName: string, columnName: string, granularity?: string, modelName?: string): string;
@@ -1,6 +1,14 @@
1
- import { Sort, MetadataTypes, DateLevels } from './types.js';
1
+ /* eslint-disable max-params */
2
+ /* eslint-disable no-underscore-dangle */
3
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
4
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
5
+ /* eslint-disable @typescript-eslint/no-unsafe-argument */
6
+ /* eslint-disable sonarjs/no-nested-switch */
7
+ import { parseExpression } from '../utils.js';
2
8
  import { DimensionalElement, normalizeName } from './base.js';
9
+ import { DATA_MODEL_MODULE_NAME } from './consts.js';
3
10
  import { simpleColumnType } from './simple-column-types.js';
11
+ import { DateLevels, MetadataTypes, Sort } from './types.js';
4
12
  /**
5
13
  * @internal
6
14
  */
@@ -13,6 +21,11 @@ export class DimensionalAttribute extends DimensionalElement {
13
21
  super(name, type || MetadataTypes.Attribute, desc, dataSource, composeCode);
14
22
  this._sort = Sort.None;
15
23
  this.expression = expression;
24
+ // if composeCode is not explicitly set by the caller, extract it from expression
25
+ if (!composeCode && expression) {
26
+ const { table, column } = parseExpression(expression);
27
+ this.composeCode = normalizeAttributeName(table, column, '', DATA_MODEL_MODULE_NAME);
28
+ }
16
29
  // panel is not needed in most cases, this is to support break by columns functionality
17
30
  if (panel === 'columns') {
18
31
  this.panel = panel;
@@ -66,11 +79,12 @@ export class DimensionalAttribute extends DimensionalElement {
66
79
  /**
67
80
  * Gets a serializable representation of the element
68
81
  */
69
- serializable() {
70
- const result = super.serializable();
82
+ serialize() {
83
+ const result = super.serialize();
84
+ result.__serializable = 'DimensionalAttribute';
71
85
  result.expression = this.expression;
72
86
  if (this.getSort() !== Sort.None) {
73
- result.sort = this.getSort().toString();
87
+ result.sort = this.getSort();
74
88
  }
75
89
  return result;
76
90
  }
@@ -79,10 +93,15 @@ export class DimensionalAttribute extends DimensionalElement {
79
93
  * @internal
80
94
  */
81
95
  export class DimensionalLevelAttribute extends DimensionalAttribute {
82
- constructor(l, expression, granularity, format, desc, sort, dataSource, composeCode, panel) {
83
- super(l, expression, MetadataTypes.DateLevel, desc, sort, dataSource, composeCode);
96
+ constructor(name, expression, granularity, format, desc, sort, dataSource, composeCode, panel) {
97
+ super(name, expression, MetadataTypes.DateLevel, desc, sort, dataSource, composeCode);
84
98
  this._format = format;
85
99
  this.granularity = granularity;
100
+ // if composeCode is not explicitly set by the caller, extract it from expression and granularity
101
+ if (!composeCode && expression) {
102
+ const { table, column } = parseExpression(expression);
103
+ this.composeCode = normalizeAttributeName(table, column, granularity, DATA_MODEL_MODULE_NAME);
104
+ }
86
105
  // panel is not needed in most cases, this is to support break by columns functionality
87
106
  if (panel === 'columns') {
88
107
  this.panel = panel;
@@ -134,11 +153,21 @@ export class DimensionalLevelAttribute extends DimensionalAttribute {
134
153
  format(format) {
135
154
  return new DimensionalLevelAttribute(this.name, this.expression, this.granularity, format, this.description, this._sort, this.dataSource, this.composeCode);
136
155
  }
156
+ /**
157
+ * Gets a {@link LevelAttribute} with the given granularity
158
+ *
159
+ * @param granularity - Date granularity
160
+ * @returns New instance representing {@link LevelAttribute} with provided granularity
161
+ */
162
+ setGranularity(granularity) {
163
+ return new DimensionalLevelAttribute(this.name, this.expression, granularity, this._format, this.description, this._sort, this.dataSource, this.composeCode);
164
+ }
137
165
  /**
138
166
  * Gets a serializable representation of the element
139
167
  */
140
- serializable() {
141
- const result = super.serializable();
168
+ serialize() {
169
+ const result = super.serialize();
170
+ result.__serializable = 'DimensionalLevelAttribute';
142
171
  result.granularity = this.granularity;
143
172
  if (this.getFormat() !== undefined) {
144
173
  result.format = this.getFormat();
@@ -355,12 +384,10 @@ export function createLevel(json) {
355
384
  * @return full normalized attribute name (e.g., DM.CommerceSales.OrderDate.Years)
356
385
  * @internal
357
386
  */
358
- export function normalizeAttributeName(tableName, columnName, dateLevel, modelName) {
387
+ export function normalizeAttributeName(tableName, columnName, granularity, modelName) {
359
388
  return ((modelName && modelName.length > 0 ? modelName + '.' : '') +
360
389
  normalizeName(tableName) +
361
390
  '.' +
362
391
  normalizeName(columnName) +
363
- (dateLevel && dateLevel.length > 0
364
- ? '.' + DimensionalLevelAttribute.translateJaqlToGranularity({ level: dateLevel })
365
- : ''));
392
+ (granularity && granularity.length > 0 ? '.' + granularity : ''));
366
393
  }
@@ -1,5 +1,5 @@
1
1
  import { Element } from './interfaces.js';
2
- import { JaqlDataSource } from './types.js';
2
+ import { JaqlDataSource, JSONObject } from './types.js';
3
3
  /**
4
4
  * @internal
5
5
  */
@@ -43,8 +43,8 @@ export declare abstract class DimensionalElement implements Element {
43
43
  /**
44
44
  * Gets a serializable representation of the element
45
45
  */
46
- serializable(): any;
47
- toJSON(): any;
46
+ serialize(): JSONObject;
47
+ toJSON(): JSONObject;
48
48
  abstract jaql(nested?: boolean): any;
49
49
  /**
50
50
  * Gets a string representation of the element
@@ -9,7 +9,9 @@ export class DimensionalElement {
9
9
  if (dataSource) {
10
10
  this._dataSource = dataSource;
11
11
  }
12
- this.composeCode = composeCode;
12
+ if (composeCode) {
13
+ this.composeCode = composeCode;
14
+ }
13
15
  }
14
16
  /**
15
17
  * Defines the element's name
@@ -29,17 +31,18 @@ export class DimensionalElement {
29
31
  /**
30
32
  * Gets a serializable representation of the element
31
33
  */
32
- serializable() {
34
+ serialize() {
33
35
  return {
34
36
  name: this.name,
35
37
  type: this.type,
36
- desc: this.description,
38
+ description: this.description,
37
39
  dataSource: this.dataSource,
40
+ composeCode: this.composeCode,
38
41
  __serializable: 'DimensionalElement',
39
42
  };
40
43
  }
41
44
  toJSON() {
42
- return this.serializable();
45
+ return this.serialize();
43
46
  }
44
47
  /**
45
48
  * Gets a string representation of the element
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Stringifies the argument, with an option to exclude specific properties from objects without a 'composeCode'.
3
+ * Keys with spaces in objects will be enclosed in single quotes.
4
+ *
5
+ * @param arg - The argument to stringify.
6
+ * @param excludeProps - Optional array of property names to exclude when stringifying objects (that don't have 'composeCode').
7
+ * @returns The stringified representation of the argument.
8
+ */
9
+ export declare function stringifyHelper(arg: any, excludeProps?: string[]): string;
10
+ /**
11
+ * High order function to construct compose code for filter factory functions
12
+ *
13
+ * @param func - filter factory function
14
+ * @param funcName - name of the filter factory function. Needed if the function name is minified.
15
+ * @returns filter factory function with composeCode property added to the filter
16
+ */
17
+ export declare function withComposeCodeForFilter<T extends (...args: any[]) => any>(func: T, funcName?: string): T;
18
+ /**
19
+ * High order function to construct compose code for filter relations factory functions
20
+ *
21
+ * @param func - filter factory function
22
+ * @param funcName - name of the filter factory function. Needed if the function name is minified.
23
+ * @returns filter factory function with composeCode property added to the filter
24
+ */
25
+ export declare function withComposeCodeForFilterRelations<T extends (...args: any[]) => any>(func: T, funcName?: string): T;
26
+ /**
27
+ * High order function to construct compose code for analytics factory functions
28
+ *
29
+ * @param func - analytics factory function
30
+ * @param funcName - name of the analytics factory function. Needed if the function name is minified.
31
+ * @returns analytics factory function with composeCode property added to the analytics
32
+ */
33
+ export declare function withComposeCodeForAnalytics<T extends (...args: any[]) => any>(func: T, funcName?: string): T;
34
+ /**
35
+ * High order function to construct compose code for measure factory functions
36
+ *
37
+ * @param func - measure factory function
38
+ * @param funcName - name of the measure factory function. Needed if the function name is minified.
39
+ * @returns measure factory function with composeCode property added to the measure
40
+ */
41
+ export declare function withComposeCodeForMeasure<T extends (...args: any[]) => any>(func: T, funcName?: string): T;