@sisense/sdk-data 1.34.0 → 2.1.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 (68) 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 +4 -4
  4. package/dist/cjs/dimensional-model/attributes.js +21 -7
  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/dimensions/dimensions.d.ts +5 -5
  12. package/dist/cjs/dimensional-model/dimensions/dimensions.js +25 -16
  13. package/dist/cjs/dimensional-model/filters/factory.d.ts +41 -41
  14. package/dist/cjs/dimensional-model/filters/factory.js +53 -168
  15. package/dist/cjs/dimensional-model/filters/filter-relations.js +2 -5
  16. package/dist/cjs/dimensional-model/filters/filters.d.ts +39 -23
  17. package/dist/cjs/dimensional-model/filters/filters.js +102 -52
  18. package/dist/cjs/dimensional-model/filters/utils/attribute-measure-util.js +6 -14
  19. package/dist/cjs/dimensional-model/filters/utils/condition-filter-util.js +28 -26
  20. package/dist/cjs/dimensional-model/filters/utils/filter-from-jaql-util.js +9 -15
  21. package/dist/cjs/dimensional-model/filters/utils/types.d.ts +10 -0
  22. package/dist/cjs/dimensional-model/interfaces.d.ts +9 -7
  23. package/dist/cjs/dimensional-model/jaql-element.d.ts +13 -1
  24. package/dist/cjs/dimensional-model/jaql-element.js +53 -1
  25. package/dist/cjs/dimensional-model/measures/factory.d.ts +45 -52
  26. package/dist/cjs/dimensional-model/measures/factory.js +55 -184
  27. package/dist/cjs/dimensional-model/measures/measures.d.ts +9 -9
  28. package/dist/cjs/dimensional-model/measures/measures.js +31 -29
  29. package/dist/cjs/dimensional-model/types.d.ts +25 -2
  30. package/dist/cjs/utils.d.ts +26 -19
  31. package/dist/cjs/utils.js +85 -41
  32. package/dist/dimensional-model/analytics/factory.d.ts +10 -10
  33. package/dist/dimensional-model/analytics/factory.js +15 -14
  34. package/dist/dimensional-model/attributes.d.ts +4 -4
  35. package/dist/dimensional-model/attributes.js +21 -7
  36. package/dist/dimensional-model/base.d.ts +3 -3
  37. package/dist/dimensional-model/base.js +7 -4
  38. package/dist/dimensional-model/compose-code-utils.d.ts +41 -0
  39. package/dist/dimensional-model/compose-code-utils.js +119 -0
  40. package/dist/dimensional-model/consts.d.ts +1 -0
  41. package/dist/dimensional-model/consts.js +1 -0
  42. package/dist/dimensional-model/dimensions/dimensions.d.ts +5 -5
  43. package/dist/dimensional-model/dimensions/dimensions.js +26 -17
  44. package/dist/dimensional-model/filters/factory.d.ts +41 -41
  45. package/dist/dimensional-model/filters/factory.js +51 -125
  46. package/dist/dimensional-model/filters/filter-relations.js +3 -6
  47. package/dist/dimensional-model/filters/filters.d.ts +39 -23
  48. package/dist/dimensional-model/filters/filters.js +102 -52
  49. package/dist/dimensional-model/filters/utils/attribute-measure-util.js +6 -14
  50. package/dist/dimensional-model/filters/utils/condition-filter-util.js +28 -26
  51. package/dist/dimensional-model/filters/utils/filter-from-jaql-util.js +9 -15
  52. package/dist/dimensional-model/filters/utils/types.d.ts +10 -0
  53. package/dist/dimensional-model/interfaces.d.ts +9 -7
  54. package/dist/dimensional-model/jaql-element.d.ts +13 -1
  55. package/dist/dimensional-model/jaql-element.js +52 -1
  56. package/dist/dimensional-model/measures/factory.d.ts +45 -52
  57. package/dist/dimensional-model/measures/factory.js +54 -141
  58. package/dist/dimensional-model/measures/measures.d.ts +9 -9
  59. package/dist/dimensional-model/measures/measures.js +31 -29
  60. package/dist/dimensional-model/types.d.ts +25 -2
  61. package/dist/tsconfig.prod.cjs.tsbuildinfo +1 -1
  62. package/dist/utils.d.ts +26 -19
  63. package/dist/utils.js +63 -44
  64. package/package.json +3 -3
  65. package/dist/cjs/dimensional-model/filters/utils/filter-code-util.d.ts +0 -17
  66. package/dist/cjs/dimensional-model/filters/utils/filter-code-util.js +0 -82
  67. package/dist/dimensional-model/filters/utils/filter-code-util.d.ts +0 -17
  68. package/dist/dimensional-model/filters/utils/filter-code-util.js +0 -77
@@ -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;
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.boxWhiskerStdDevOutliers = exports.boxWhiskerIqrOutliers = exports.boxWhiskerStdDevValues = exports.boxWhiskerExtremumsValues = exports.boxWhiskerIqrValues = exports.BOX_WHISKER = void 0;
7
7
  const cloneDeep_js_1 = __importDefault(require("lodash-es/cloneDeep.js"));
8
+ const compose_code_utils_js_1 = require("../compose-code-utils.js");
8
9
  const factory_js_1 = require("../measures/factory.js");
9
10
  /** @internal */
10
11
  exports.BOX_WHISKER = {
@@ -33,8 +34,8 @@ function boxWhiskerCommonValues(target) {
33
34
  /**
34
35
  * Returns an array of values for box whisker plot using interquartile range (IQR) calculations.
35
36
  *
36
- * @param {Attribute} target - The target attribute for calculations.
37
- * @returns {Measure[]} An array of measures representing IQR values for box whisker plots.
37
+ * @param target - The target attribute for calculations.
38
+ * @returns An array of measures representing IQR values for box whisker plots.
38
39
  */
39
40
  function boxWhiskerIqrValues(target) {
40
41
  return [
@@ -54,8 +55,8 @@ exports.boxWhiskerIqrValues = boxWhiskerIqrValues;
54
55
  /**
55
56
  * Returns an array of extremum values for box whisker plot.
56
57
  *
57
- * @param {Attribute} target - The target attribute for calculations.
58
- * @returns {Measure[]} An array of measures representing extremum values for box whisker plots.
58
+ * @param target - The target attribute for calculations.
59
+ * @returns An array of measures representing extremum values for box whisker plots.
59
60
  */
60
61
  function boxWhiskerExtremumsValues(target) {
61
62
  return [
@@ -72,8 +73,8 @@ exports.boxWhiskerExtremumsValues = boxWhiskerExtremumsValues;
72
73
  /**
73
74
  * Returns an array of values for box whisker plot using standard deviation calculations.
74
75
  *
75
- * @param {Attribute} target - The target attribute for calculations.
76
- * @returns {Measure[]} An array of measures representing standard deviation values for box whisker plots.
76
+ * @param target - The target attribute for calculations.
77
+ * @returns An array of measures representing standard deviation values for box whisker plots.
77
78
  */
78
79
  function boxWhiskerStdDevValues(target) {
79
80
  return [
@@ -93,10 +94,10 @@ exports.boxWhiskerStdDevValues = boxWhiskerStdDevValues;
93
94
  /**
94
95
  * Returns an attribute representing outlier points based on interquartile range (IQR) calculations.
95
96
  *
96
- * @param {Attribute} target - The target attribute for calculations.
97
- * @returns {Attribute} An attribute representing outliers for box whisker plots using IQR.
97
+ * @param target - The target attribute for calculations.
98
+ * @returns An attribute representing outliers for box whisker plots using IQR.
98
99
  */
99
- const boxWhiskerIqrOutliers = (target) => {
100
+ exports.boxWhiskerIqrOutliers = (0, compose_code_utils_js_1.withComposeCodeForAnalytics)((target) => {
100
101
  const outliersAttrWithInnerFilter = (0, cloneDeep_js_1.default)(target);
101
102
  const outliersMax = (0, factory_js_1.customFormula)(exports.BOX_WHISKER.OUTLIER_MAX_VALUE_NAME, '(UPPERWHISKERMIN_IQR([Attr]), all([Attr]))', {
102
103
  Attr: target,
@@ -119,15 +120,14 @@ const boxWhiskerIqrOutliers = (target) => {
119
120
  return nested ? jaql : { jaql };
120
121
  };
121
122
  return outliersAttrWithInnerFilter;
122
- };
123
- exports.boxWhiskerIqrOutliers = boxWhiskerIqrOutliers;
123
+ }, 'boxWhiskerIqrOutliers');
124
124
  /**
125
125
  * Returns an attribute representing outlier points based on standard deviation calculations.
126
126
  *
127
- * @param {Attribute} target - The target attribute for calculations.
128
- * @returns {Attribute} An attribute representing outliers for box whisker plots using standard deviation.
127
+ * @param target - The target attribute for calculations.
128
+ * @returns An attribute representing outliers for box whisker plots using standard deviation.
129
129
  */
130
- const boxWhiskerStdDevOutliers = (target) => {
130
+ exports.boxWhiskerStdDevOutliers = (0, compose_code_utils_js_1.withComposeCodeForAnalytics)((target) => {
131
131
  const outliersAttrWithInnerFilter = (0, cloneDeep_js_1.default)(target);
132
132
  const outliersMax = (0, factory_js_1.customFormula)(exports.BOX_WHISKER.OUTLIER_MAX_VALUE_NAME, '(UPPERWHISKERMIN_STDEVP([Attr]), all([Attr]))', {
133
133
  Attr: target,
@@ -149,5 +149,4 @@ const boxWhiskerStdDevOutliers = (target) => {
149
149
  return nested ? jaql : { jaql };
150
150
  };
151
151
  return outliersAttrWithInnerFilter;
152
- };
153
- exports.boxWhiskerStdDevOutliers = boxWhiskerStdDevOutliers;
152
+ }, 'boxWhiskerStdDevOutliers');
@@ -1,6 +1,6 @@
1
1
  import { DimensionalElement } from './base.js';
2
2
  import { Attribute, LevelAttribute } from './interfaces.js';
3
- import { DateLevel, JaqlDataSource, Sort } from './types.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
  */
@@ -89,7 +89,7 @@ export declare class DimensionalLevelAttribute extends DimensionalAttribute impl
89
89
  /**
90
90
  * Gets a serializable representation of the element
91
91
  */
92
- serializable(): any;
92
+ serialize(): JSONObject;
93
93
  /**
94
94
  * Gets the JAQL representation of this instance
95
95
  *
@@ -7,7 +7,9 @@ exports.normalizeAttributeName = exports.createLevel = exports.createAttribute =
7
7
  /* eslint-disable @typescript-eslint/no-unsafe-member-access */
8
8
  /* eslint-disable @typescript-eslint/no-unsafe-argument */
9
9
  /* eslint-disable sonarjs/no-nested-switch */
10
+ const utils_js_1 = require("../utils.js");
10
11
  const base_js_1 = require("./base.js");
12
+ const consts_js_1 = require("./consts.js");
11
13
  const simple_column_types_js_1 = require("./simple-column-types.js");
12
14
  const types_js_1 = require("./types.js");
13
15
  /**
@@ -23,6 +25,11 @@ class DimensionalAttribute extends base_js_1.DimensionalElement {
23
25
  super(name, type || types_js_1.MetadataTypes.Attribute, desc, dataSource, composeCode);
24
26
  this._sort = types_js_1.Sort.None;
25
27
  this.expression = expression;
28
+ // if composeCode is not explicitly set by the caller, extract it from expression
29
+ if (!composeCode && expression) {
30
+ const { table, column } = (0, utils_js_1.parseExpression)(expression);
31
+ this.composeCode = normalizeAttributeName(table, column, '', consts_js_1.DATA_MODEL_MODULE_NAME);
32
+ }
26
33
  // panel is not needed in most cases, this is to support break by columns functionality
27
34
  if (panel === 'columns') {
28
35
  this.panel = panel;
@@ -76,11 +83,12 @@ class DimensionalAttribute extends base_js_1.DimensionalElement {
76
83
  /**
77
84
  * Gets a serializable representation of the element
78
85
  */
79
- serializable() {
80
- const result = super.serializable();
86
+ serialize() {
87
+ const result = super.serialize();
88
+ result.__serializable = 'DimensionalAttribute';
81
89
  result.expression = this.expression;
82
90
  if (this.getSort() !== types_js_1.Sort.None) {
83
- result.sort = this.getSort().toString();
91
+ result.sort = this.getSort();
84
92
  }
85
93
  return result;
86
94
  }
@@ -90,10 +98,15 @@ exports.DimensionalAttribute = DimensionalAttribute;
90
98
  * @internal
91
99
  */
92
100
  class DimensionalLevelAttribute extends DimensionalAttribute {
93
- constructor(l, expression, granularity, format, desc, sort, dataSource, composeCode, panel) {
94
- super(l, expression, types_js_1.MetadataTypes.DateLevel, desc, sort, dataSource, composeCode);
101
+ constructor(name, expression, granularity, format, desc, sort, dataSource, composeCode, panel) {
102
+ super(name, expression, types_js_1.MetadataTypes.DateLevel, desc, sort, dataSource, composeCode);
95
103
  this._format = format;
96
104
  this.granularity = granularity;
105
+ // if composeCode is not explicitly set by the caller, extract it from expression and granularity
106
+ if (!composeCode && expression) {
107
+ const { table, column } = (0, utils_js_1.parseExpression)(expression);
108
+ this.composeCode = normalizeAttributeName(table, column, granularity, consts_js_1.DATA_MODEL_MODULE_NAME);
109
+ }
97
110
  // panel is not needed in most cases, this is to support break by columns functionality
98
111
  if (panel === 'columns') {
99
112
  this.panel = panel;
@@ -157,8 +170,9 @@ class DimensionalLevelAttribute extends DimensionalAttribute {
157
170
  /**
158
171
  * Gets a serializable representation of the element
159
172
  */
160
- serializable() {
161
- const result = super.serializable();
173
+ serialize() {
174
+ const result = super.serialize();
175
+ result.__serializable = 'DimensionalLevelAttribute';
162
176
  result.granularity = this.granularity;
163
177
  if (this.getFormat() !== undefined) {
164
178
  result.format = this.getFormat();
@@ -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
@@ -12,7 +12,9 @@ class DimensionalElement {
12
12
  if (dataSource) {
13
13
  this._dataSource = dataSource;
14
14
  }
15
- this.composeCode = composeCode;
15
+ if (composeCode) {
16
+ this.composeCode = composeCode;
17
+ }
16
18
  }
17
19
  /**
18
20
  * Defines the element's name
@@ -32,17 +34,18 @@ class DimensionalElement {
32
34
  /**
33
35
  * Gets a serializable representation of the element
34
36
  */
35
- serializable() {
37
+ serialize() {
36
38
  return {
37
39
  name: this.name,
38
40
  type: this.type,
39
- desc: this.description,
41
+ description: this.description,
40
42
  dataSource: this.dataSource,
43
+ composeCode: this.composeCode,
41
44
  __serializable: 'DimensionalElement',
42
45
  };
43
46
  }
44
47
  toJSON() {
45
- return this.serializable();
48
+ return this.serialize();
46
49
  }
47
50
  /**
48
51
  * 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;
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withComposeCodeForMeasure = exports.withComposeCodeForAnalytics = exports.withComposeCodeForFilterRelations = exports.withComposeCodeForFilter = exports.stringifyHelper = void 0;
4
+ const sdk_common_1 = require("@sisense/sdk-common");
5
+ /**
6
+ * Stringifies the argument, with an option to exclude specific properties from objects without a 'composeCode'.
7
+ * Keys with spaces in objects will be enclosed in single quotes.
8
+ *
9
+ * @param arg - The argument to stringify.
10
+ * @param excludeProps - Optional array of property names to exclude when stringifying objects (that don't have 'composeCode').
11
+ * @returns The stringified representation of the argument.
12
+ */
13
+ function stringifyHelper(arg, excludeProps = []) {
14
+ try {
15
+ if (arg === null || arg === undefined) {
16
+ return String(arg);
17
+ }
18
+ if (typeof arg === 'string') {
19
+ return `'${(0, sdk_common_1.escapeSingleQuotes)(arg)}'`;
20
+ }
21
+ if (typeof arg === 'number' || typeof arg === 'boolean') {
22
+ return String(arg);
23
+ }
24
+ if (arg instanceof Date) {
25
+ return `new Date('${arg.toISOString()}')`;
26
+ }
27
+ if (Array.isArray(arg)) {
28
+ return `[${arg.map((item) => stringifyHelper(item, excludeProps)).join(', ')}]`;
29
+ }
30
+ if (typeof arg === 'object' && arg !== null) {
31
+ if ('composeCode' in arg) {
32
+ return arg.composeCode;
33
+ }
34
+ const entries = Object.entries(arg)
35
+ .filter(([key]) => !excludeProps.includes(key))
36
+ .map(([key, value]) => {
37
+ const formattedKey = /[^a-zA-Z0-9_$]/.test(key) ? `'${key}'` : key;
38
+ return `${formattedKey}: ${stringifyHelper(value, excludeProps)}`;
39
+ });
40
+ return `{ ${entries.join(', ')} }`;
41
+ }
42
+ // Fallback for anything else
43
+ return JSON.stringify(arg);
44
+ }
45
+ catch (e) {
46
+ console.error(e, JSON.stringify(arg, null, 2));
47
+ return JSON.stringify(arg);
48
+ }
49
+ }
50
+ exports.stringifyHelper = stringifyHelper;
51
+ function trimTrailingUndefined(args) {
52
+ let i = args.length;
53
+ while (i > 0 && args[i - 1] === undefined) {
54
+ i--;
55
+ }
56
+ return args.slice(0, i);
57
+ }
58
+ /**
59
+ * Generic high order function to construct compose code for factory functions
60
+ *
61
+ * @param func - factory function
62
+ * @param factoryName - name of the factory (e.g. 'filterFactory', 'measureFactory')
63
+ * @param funcName - name of the factory function. Needed if the function name is minified.
64
+ * @returns factory function with composeCode property added
65
+ */
66
+ function withComposeCode(factoryName, funcName) {
67
+ return function (func) {
68
+ return function (...args) {
69
+ const trimmedArgs = trimTrailingUndefined(args);
70
+ const length = trimmedArgs.length;
71
+ const argValues = trimmedArgs
72
+ .map((arg) => stringifyHelper(arg, ['guid']))
73
+ // Remove trivial arg values from the end of the array
74
+ .filter((str, index) => !(['', '{ }', '[]', 'undefined', 'null'].includes(str) && index === length - 1))
75
+ .join(', ');
76
+ const signature = `${factoryName}.${funcName !== null && funcName !== void 0 ? funcName : func.name}(${argValues})`;
77
+ // Call the original function and get the result
78
+ const result = func(...args);
79
+ result.composeCode = signature; // Type assertion needed here
80
+ return result;
81
+ };
82
+ };
83
+ }
84
+ /**
85
+ * High order function to construct compose code for filter factory functions
86
+ *
87
+ * @param func - filter factory function
88
+ * @param funcName - name of the filter factory function. Needed if the function name is minified.
89
+ * @returns filter factory function with composeCode property added to the filter
90
+ */
91
+ function withComposeCodeForFilter(func, funcName) {
92
+ return withComposeCode('filterFactory', funcName)(func);
93
+ }
94
+ exports.withComposeCodeForFilter = withComposeCodeForFilter;
95
+ /**
96
+ * High order function to construct compose code for filter relations factory functions
97
+ *
98
+ * @param func - filter factory function
99
+ * @param funcName - name of the filter factory function. Needed if the function name is minified.
100
+ * @returns filter factory function with composeCode property added to the filter
101
+ */
102
+ function withComposeCodeForFilterRelations(func, funcName) {
103
+ return withComposeCode('filterFactory.logic', funcName)(func);
104
+ }
105
+ exports.withComposeCodeForFilterRelations = withComposeCodeForFilterRelations;
106
+ /**
107
+ * High order function to construct compose code for analytics factory functions
108
+ *
109
+ * @param func - analytics factory function
110
+ * @param funcName - name of the analytics factory function. Needed if the function name is minified.
111
+ * @returns analytics factory function with composeCode property added to the analytics
112
+ */
113
+ function withComposeCodeForAnalytics(func, funcName) {
114
+ return withComposeCode('analyticsFactory', funcName)(func);
115
+ }
116
+ exports.withComposeCodeForAnalytics = withComposeCodeForAnalytics;
117
+ /**
118
+ * High order function to construct compose code for measure factory functions
119
+ *
120
+ * @param func - measure factory function
121
+ * @param funcName - name of the measure factory function. Needed if the function name is minified.
122
+ * @returns measure factory function with composeCode property added to the measure
123
+ */
124
+ function withComposeCodeForMeasure(func, funcName) {
125
+ return withComposeCode('measureFactory', funcName)(func);
126
+ }
127
+ exports.withComposeCodeForMeasure = withComposeCodeForMeasure;
@@ -0,0 +1 @@
1
+ export declare const DATA_MODEL_MODULE_NAME = "DM";
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DATA_MODEL_MODULE_NAME = void 0;
4
+ exports.DATA_MODEL_MODULE_NAME = 'DM';
@@ -1,6 +1,6 @@
1
1
  import { DimensionalElement } from '../base.js';
2
2
  import { Attribute, DateDimension, Dimension, LevelAttribute } from '../interfaces.js';
3
- import { JaqlDataSource, Sort } from '../types.js';
3
+ import { JaqlDataSource, JSONObject, Sort } from '../types.js';
4
4
  /**
5
5
  * Represents a Dimension in a Dimensional Model
6
6
  *
@@ -14,7 +14,7 @@ export declare class DimensionalDimension extends DimensionalElement implements
14
14
  protected _attributes: Attribute[];
15
15
  private _expression;
16
16
  protected _sort: Sort;
17
- constructor(name: string, expression: string, attributes: Attribute[], dimensions?: Dimension[], type?: string, desc?: string, sort?: Sort, dataSource?: JaqlDataSource);
17
+ constructor(name: string, expression: string, attributes: Attribute[], dimensions?: Dimension[], type?: string, desc?: string, sort?: Sort, dataSource?: JaqlDataSource, composeCode?: string, defaultAttribute?: Attribute);
18
18
  private getAttachedName;
19
19
  protected setDimensions(dimensions: Dimension[]): void;
20
20
  protected setAttributes(attributes: Attribute[]): void;
@@ -47,7 +47,7 @@ export declare class DimensionalDimension extends DimensionalElement implements
47
47
  /**
48
48
  * Gets a serializable representation of the element
49
49
  */
50
- serializable(): any;
50
+ serialize(): JSONObject;
51
51
  /**
52
52
  * Gets the JAQL representation of this instance
53
53
  *
@@ -61,7 +61,7 @@ export declare class DimensionalDimension extends DimensionalElement implements
61
61
  * @internal
62
62
  */
63
63
  export declare class DimensionalDateDimension extends DimensionalDimension implements DateDimension {
64
- constructor(name: string, expression: string, desc?: string, sort?: Sort, dataSource?: JaqlDataSource);
64
+ constructor(name: string, expression: string, desc?: string, sort?: Sort, dataSource?: JaqlDataSource, composeCode?: string);
65
65
  /**
66
66
  * Years level
67
67
  */
@@ -141,7 +141,7 @@ export declare class DimensionalDateDimension extends DimensionalDimension imple
141
141
  /**
142
142
  * Gets a serializable representation of the element
143
143
  */
144
- serializable(): any;
144
+ serialize(): JSONObject;
145
145
  /**
146
146
  * Gets the JAQL representation of this instance
147
147
  *
@@ -9,8 +9,10 @@ exports.createDateDimension = exports.createDimension = exports.DimensionalDateD
9
9
  /* eslint-disable sonarjs/no-duplicate-string */
10
10
  /* eslint-disable @typescript-eslint/no-unsafe-call */
11
11
  /* eslint-disable @typescript-eslint/no-unsafe-argument */
12
+ const utils_js_1 = require("../../utils.js");
12
13
  const attributes_js_1 = require("../attributes.js");
13
14
  const base_js_1 = require("../base.js");
15
+ const consts_js_1 = require("../consts.js");
14
16
  const types_js_1 = require("../types.js");
15
17
  /**
16
18
  * Represents a Dimension in a Dimensional Model
@@ -18,15 +20,23 @@ const types_js_1 = require("../types.js");
18
20
  * @internal
19
21
  */
20
22
  class DimensionalDimension extends base_js_1.DimensionalElement {
21
- constructor(name, expression, attributes, dimensions, type, desc, sort, dataSource) {
22
- super(name, type || types_js_1.MetadataTypes.Dimension, desc, dataSource);
23
+ constructor(name, expression, attributes, dimensions, type, desc, sort, dataSource, composeCode, defaultAttribute) {
24
+ super(name, type || types_js_1.MetadataTypes.Dimension, desc, dataSource, composeCode);
23
25
  this._dimensions = [];
24
26
  this._attributes = [];
25
27
  this._sort = types_js_1.Sort.None;
28
+ // if composeCode is not explicitly set by the caller, extract it from expression
29
+ if (!composeCode && expression) {
30
+ const { table, column } = (0, utils_js_1.parseExpression)(expression);
31
+ this.composeCode = (0, attributes_js_1.normalizeAttributeName)(table, column, '', consts_js_1.DATA_MODEL_MODULE_NAME);
32
+ }
26
33
  this._sort = sort || types_js_1.Sort.None;
27
34
  this._expression = expression;
28
35
  this.setDimensions(dimensions || []);
29
36
  this.setAttributes(attributes);
37
+ if (defaultAttribute) {
38
+ this.defaultAttribute = defaultAttribute;
39
+ }
30
40
  }
31
41
  static parseType(type) {
32
42
  switch (type) {
@@ -112,21 +122,22 @@ class DimensionalDimension extends base_js_1.DimensionalElement {
112
122
  * @returns An instance representing the sorted {@link Dimension} of this instance
113
123
  */
114
124
  sort(sort) {
115
- return new DimensionalDimension(this.name, this.expression, this.attributes, this.dimensions, this.type, this.description, sort, this.dataSource);
125
+ return new DimensionalDimension(this.name, this.expression, this.attributes, this.dimensions, this.type, this.description, sort, this.dataSource, this.composeCode, this.defaultAttribute);
116
126
  }
117
127
  /**
118
128
  * Gets a serializable representation of the element
119
129
  */
120
- serializable() {
121
- const result = super.serializable();
130
+ serialize() {
131
+ const result = super.serialize();
132
+ result.__serializable = 'DimensionalDimension';
122
133
  result.expression = this.expression;
123
134
  if (this.getSort() !== undefined) {
124
135
  result.sort = this.getSort();
125
136
  }
126
- result.attributes = this._attributes.map((att) => att.serializable());
127
- result.diemsnions = this._dimensions.map((dim) => dim.serializable());
137
+ result.attributes = this._attributes.map((att) => att.serialize());
138
+ result.dimensions = this._dimensions.map((dim) => dim.serialize());
128
139
  if (this.defaultAttribute) {
129
- result.defaultAttribute = this.defaultAttribute.serializable();
140
+ result.defaultAttribute = this.defaultAttribute.serialize();
130
141
  }
131
142
  return result;
132
143
  }
@@ -162,8 +173,8 @@ exports.DimensionalDimension = DimensionalDimension;
162
173
  * @internal
163
174
  */
164
175
  class DimensionalDateDimension extends DimensionalDimension {
165
- constructor(name, expression, desc, sort, dataSource) {
166
- super(name, expression, [], [], types_js_1.MetadataTypes.DateDimension, desc, sort, dataSource);
176
+ constructor(name, expression, desc, sort, dataSource, composeCode) {
177
+ super(name, expression, [], [], types_js_1.MetadataTypes.DateDimension, desc, sort, dataSource, composeCode);
167
178
  this.defaultLevel = types_js_1.DateLevels.Years;
168
179
  this.Years = new attributes_js_1.DimensionalLevelAttribute(types_js_1.DateLevels.Years, expression, types_js_1.DateLevels.Years, 'yyyy', desc, sort, dataSource);
169
180
  this.Quarters = new attributes_js_1.DimensionalLevelAttribute(types_js_1.DateLevels.Quarters, expression, types_js_1.DateLevels.Quarters, 'Q yyyy', desc, sort, dataSource);
@@ -223,16 +234,14 @@ class DimensionalDateDimension extends DimensionalDimension {
223
234
  * @returns An instance representing the sorted {@link Dimension} of this instance
224
235
  */
225
236
  sort(sort) {
226
- return new DimensionalDateDimension(this.name, this.expression, this.description, sort, this.dataSource);
237
+ return new DimensionalDateDimension(this.name, this.expression, this.description, sort, this.dataSource, this.composeCode);
227
238
  }
228
239
  /**
229
240
  * Gets a serializable representation of the element
230
241
  */
231
- serializable() {
232
- const result = super.serializable();
233
- if (this.defaultLevel) {
234
- result.defaultLevel = this.defaultLevel;
235
- }
242
+ serialize() {
243
+ const result = super.serialize();
244
+ result.__serializable = 'DimensionalDateDimension';
236
245
  return result;
237
246
  }
238
247
  /**