@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
@@ -0,0 +1,119 @@
1
+ import { escapeSingleQuotes } from '@sisense/sdk-common';
2
+ /**
3
+ * Stringifies the argument, with an option to exclude specific properties from objects without a 'composeCode'.
4
+ * Keys with spaces in objects will be enclosed in single quotes.
5
+ *
6
+ * @param arg - The argument to stringify.
7
+ * @param excludeProps - Optional array of property names to exclude when stringifying objects (that don't have 'composeCode').
8
+ * @returns The stringified representation of the argument.
9
+ */
10
+ export function stringifyHelper(arg, excludeProps = []) {
11
+ try {
12
+ if (arg === null || arg === undefined) {
13
+ return String(arg);
14
+ }
15
+ if (typeof arg === 'string') {
16
+ return `'${escapeSingleQuotes(arg)}'`;
17
+ }
18
+ if (typeof arg === 'number' || typeof arg === 'boolean') {
19
+ return String(arg);
20
+ }
21
+ if (arg instanceof Date) {
22
+ return `new Date('${arg.toISOString()}')`;
23
+ }
24
+ if (Array.isArray(arg)) {
25
+ return `[${arg.map((item) => stringifyHelper(item, excludeProps)).join(', ')}]`;
26
+ }
27
+ if (typeof arg === 'object' && arg !== null) {
28
+ if ('composeCode' in arg) {
29
+ return arg.composeCode;
30
+ }
31
+ const entries = Object.entries(arg)
32
+ .filter(([key]) => !excludeProps.includes(key))
33
+ .map(([key, value]) => {
34
+ const formattedKey = /[^a-zA-Z0-9_$]/.test(key) ? `'${key}'` : key;
35
+ return `${formattedKey}: ${stringifyHelper(value, excludeProps)}`;
36
+ });
37
+ return `{ ${entries.join(', ')} }`;
38
+ }
39
+ // Fallback for anything else
40
+ return JSON.stringify(arg);
41
+ }
42
+ catch (e) {
43
+ console.error(e, JSON.stringify(arg, null, 2));
44
+ return JSON.stringify(arg);
45
+ }
46
+ }
47
+ function trimTrailingUndefined(args) {
48
+ let i = args.length;
49
+ while (i > 0 && args[i - 1] === undefined) {
50
+ i--;
51
+ }
52
+ return args.slice(0, i);
53
+ }
54
+ /**
55
+ * Generic high order function to construct compose code for factory functions
56
+ *
57
+ * @param func - factory function
58
+ * @param factoryName - name of the factory (e.g. 'filterFactory', 'measureFactory')
59
+ * @param funcName - name of the factory function. Needed if the function name is minified.
60
+ * @returns factory function with composeCode property added
61
+ */
62
+ function withComposeCode(factoryName, funcName) {
63
+ return function (func) {
64
+ return function (...args) {
65
+ const trimmedArgs = trimTrailingUndefined(args);
66
+ const length = trimmedArgs.length;
67
+ const argValues = trimmedArgs
68
+ .map((arg) => stringifyHelper(arg, ['guid']))
69
+ // Remove trivial arg values from the end of the array
70
+ .filter((str, index) => !(['', '{ }', '[]', 'undefined', 'null'].includes(str) && index === length - 1))
71
+ .join(', ');
72
+ const signature = `${factoryName}.${funcName !== null && funcName !== void 0 ? funcName : func.name}(${argValues})`;
73
+ // Call the original function and get the result
74
+ const result = func(...args);
75
+ result.composeCode = signature; // Type assertion needed here
76
+ return result;
77
+ };
78
+ };
79
+ }
80
+ /**
81
+ * High order function to construct compose code for filter factory functions
82
+ *
83
+ * @param func - filter factory function
84
+ * @param funcName - name of the filter factory function. Needed if the function name is minified.
85
+ * @returns filter factory function with composeCode property added to the filter
86
+ */
87
+ export function withComposeCodeForFilter(func, funcName) {
88
+ return withComposeCode('filterFactory', funcName)(func);
89
+ }
90
+ /**
91
+ * High order function to construct compose code for filter relations factory functions
92
+ *
93
+ * @param func - filter factory function
94
+ * @param funcName - name of the filter factory function. Needed if the function name is minified.
95
+ * @returns filter factory function with composeCode property added to the filter
96
+ */
97
+ export function withComposeCodeForFilterRelations(func, funcName) {
98
+ return withComposeCode('filterFactory.logic', funcName)(func);
99
+ }
100
+ /**
101
+ * High order function to construct compose code for analytics factory functions
102
+ *
103
+ * @param func - analytics factory function
104
+ * @param funcName - name of the analytics factory function. Needed if the function name is minified.
105
+ * @returns analytics factory function with composeCode property added to the analytics
106
+ */
107
+ export function withComposeCodeForAnalytics(func, funcName) {
108
+ return withComposeCode('analyticsFactory', funcName)(func);
109
+ }
110
+ /**
111
+ * High order function to construct compose code for measure factory functions
112
+ *
113
+ * @param func - measure factory function
114
+ * @param funcName - name of the measure factory function. Needed if the function name is minified.
115
+ * @returns measure factory function with composeCode property added to the measure
116
+ */
117
+ export function withComposeCodeForMeasure(func, funcName) {
118
+ return withComposeCode('measureFactory', funcName)(func);
119
+ }
@@ -0,0 +1 @@
1
+ export declare const DATA_MODEL_MODULE_NAME = "DM";
@@ -0,0 +1 @@
1
+ export const DATA_MODEL_MODULE_NAME = 'DM';
@@ -1,5 +1,5 @@
1
- import { DataModel, Element } from './interfaces.js';
2
1
  import { DataSource, DataSourceInfo } from '../interfaces.js';
2
+ import { DataModel, Element } from './interfaces.js';
3
3
  /**
4
4
  * @internal
5
5
  */
@@ -1,5 +1,5 @@
1
- import { create } from './factory.js';
2
1
  import { TranslatableError } from '../translation/translatable-error.js';
2
+ import { create } from './factory.js';
3
3
  /**
4
4
  * @internal
5
5
  */
@@ -1,6 +1,6 @@
1
- import { Attribute, LevelAttribute, Dimension, DateDimension } from '../interfaces.js';
2
- import { Sort, JaqlDataSource } from '../types.js';
3
1
  import { DimensionalElement } from '../base.js';
2
+ import { Attribute, DateDimension, Dimension, LevelAttribute } from '../interfaces.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
  *
@@ -1,21 +1,39 @@
1
- import { Sort, DateLevels, MetadataTypes } from '../types.js';
2
- import { DimensionalAttribute, DimensionalLevelAttribute, jaqlSimpleColumnType, } from '../attributes.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-return */
6
+ /* eslint-disable sonarjs/no-duplicate-string */
7
+ /* eslint-disable @typescript-eslint/no-unsafe-call */
8
+ /* eslint-disable @typescript-eslint/no-unsafe-argument */
9
+ import { parseExpression } from '../../utils.js';
10
+ import { DimensionalAttribute, DimensionalLevelAttribute, jaqlSimpleColumnType, normalizeAttributeName, } from '../attributes.js';
3
11
  import { DimensionalElement, normalizeName } from '../base.js';
12
+ import { DATA_MODEL_MODULE_NAME } from '../consts.js';
13
+ import { DateLevels, MetadataTypes, Sort } from '../types.js';
4
14
  /**
5
15
  * Represents a Dimension in a Dimensional Model
6
16
  *
7
17
  * @internal
8
18
  */
9
19
  export class DimensionalDimension extends DimensionalElement {
10
- constructor(name, expression, attributes, dimensions, type, desc, sort, dataSource) {
11
- super(name, type || MetadataTypes.Dimension, desc, dataSource);
20
+ constructor(name, expression, attributes, dimensions, type, desc, sort, dataSource, composeCode, defaultAttribute) {
21
+ super(name, type || MetadataTypes.Dimension, desc, dataSource, composeCode);
12
22
  this._dimensions = [];
13
23
  this._attributes = [];
14
24
  this._sort = Sort.None;
25
+ // if composeCode is not explicitly set by the caller, extract it from expression
26
+ if (!composeCode && expression) {
27
+ const { table, column } = parseExpression(expression);
28
+ this.composeCode = normalizeAttributeName(table, column, '', DATA_MODEL_MODULE_NAME);
29
+ }
15
30
  this._sort = sort || Sort.None;
16
31
  this._expression = expression;
17
32
  this.setDimensions(dimensions || []);
18
33
  this.setAttributes(attributes);
34
+ if (defaultAttribute) {
35
+ this.defaultAttribute = defaultAttribute;
36
+ }
19
37
  }
20
38
  static parseType(type) {
21
39
  switch (type) {
@@ -101,21 +119,22 @@ export class DimensionalDimension extends DimensionalElement {
101
119
  * @returns An instance representing the sorted {@link Dimension} of this instance
102
120
  */
103
121
  sort(sort) {
104
- return new DimensionalDimension(this.name, this.expression, this.attributes, this.dimensions, this.type, this.description, sort, this.dataSource);
122
+ return new DimensionalDimension(this.name, this.expression, this.attributes, this.dimensions, this.type, this.description, sort, this.dataSource, this.composeCode, this.defaultAttribute);
105
123
  }
106
124
  /**
107
125
  * Gets a serializable representation of the element
108
126
  */
109
- serializable() {
110
- const result = super.serializable();
127
+ serialize() {
128
+ const result = super.serialize();
129
+ result.__serializable = 'DimensionalDimension';
111
130
  result.expression = this.expression;
112
131
  if (this.getSort() !== undefined) {
113
132
  result.sort = this.getSort();
114
133
  }
115
- result.attributes = this._attributes.map((att) => att.serializable());
116
- result.diemsnions = this._dimensions.map((dim) => dim.serializable());
134
+ result.attributes = this._attributes.map((att) => att.serialize());
135
+ result.dimensions = this._dimensions.map((dim) => dim.serialize());
117
136
  if (this.defaultAttribute) {
118
- result.defaultAttribute = this.defaultAttribute.serializable();
137
+ result.defaultAttribute = this.defaultAttribute.serialize();
119
138
  }
120
139
  return result;
121
140
  }
@@ -150,8 +169,8 @@ export class DimensionalDimension extends DimensionalElement {
150
169
  * @internal
151
170
  */
152
171
  export class DimensionalDateDimension extends DimensionalDimension {
153
- constructor(name, expression, desc, sort, dataSource) {
154
- super(name, expression, [], [], MetadataTypes.DateDimension, desc, sort, dataSource);
172
+ constructor(name, expression, desc, sort, dataSource, composeCode) {
173
+ super(name, expression, [], [], MetadataTypes.DateDimension, desc, sort, dataSource, composeCode);
155
174
  this.defaultLevel = DateLevels.Years;
156
175
  this.Years = new DimensionalLevelAttribute(DateLevels.Years, expression, DateLevels.Years, 'yyyy', desc, sort, dataSource);
157
176
  this.Quarters = new DimensionalLevelAttribute(DateLevels.Quarters, expression, DateLevels.Quarters, 'Q yyyy', desc, sort, dataSource);
@@ -211,16 +230,14 @@ export class DimensionalDateDimension extends DimensionalDimension {
211
230
  * @returns An instance representing the sorted {@link Dimension} of this instance
212
231
  */
213
232
  sort(sort) {
214
- return new DimensionalDateDimension(this.name, this.expression, this.description, sort, this.dataSource);
233
+ return new DimensionalDateDimension(this.name, this.expression, this.description, sort, this.dataSource, this.composeCode);
215
234
  }
216
235
  /**
217
236
  * Gets a serializable representation of the element
218
237
  */
219
- serializable() {
220
- const result = super.serializable();
221
- if (this.defaultLevel) {
222
- result.defaultLevel = this.defaultLevel;
223
- }
238
+ serialize() {
239
+ const result = super.serialize();
240
+ result.__serializable = 'DimensionalDateDimension';
224
241
  return result;
225
242
  }
226
243
  /**
@@ -3,6 +3,7 @@ import { Dimension } from '../interfaces.js';
3
3
  import { DataSourceField } from '../types.js';
4
4
  /**
5
5
  * Function to convert data source fields to dimensions.
6
+ *
6
7
  * @param fields - The data source fields to convert.
7
8
  * @param dataSource - The data source title.
8
9
  * @returns - The dimensions created from the data source fields.
@@ -1,8 +1,9 @@
1
- import { createAttribute } from '../attributes.js';
2
- import { createDimension, createDateDimension } from './dimensions.js';
3
1
  import { isDataSourceInfo } from '../../utils.js';
2
+ import { createAttribute } from '../attributes.js';
3
+ import { createDateDimension, createDimension } from './dimensions.js';
4
4
  /**
5
5
  * Function to convert data source fields to dimensions.
6
+ *
6
7
  * @param fields - The data source fields to convert.
7
8
  * @param dataSource - The data source title.
8
9
  * @returns - The dimensions created from the data source fields.
@@ -1,10 +1,10 @@
1
1
  /* eslint-disable @typescript-eslint/no-unsafe-member-access */
2
- import { MetadataTypes } from './types.js';
3
- import { createMeasure } from './measures/measures.js';
4
- import { createFilter } from './filters/filters.js';
5
- import { createDimension } from './dimensions/index.js';
6
- import { createAttribute } from './attributes.js';
7
2
  import { TranslatableError } from '../translation/translatable-error.js';
3
+ import { createAttribute } from './attributes.js';
4
+ import { createDimension } from './dimensions/index.js';
5
+ import { createFilter } from './filters/filters.js';
6
+ import { createMeasure } from './measures/measures.js';
7
+ import { MetadataTypes } from './types.js';
8
8
  /**
9
9
  * Generate an array of dimension model instances out of the given JSON array
10
10
  *