@sisense/sdk-data 1.31.0 → 1.33.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 (38) hide show
  1. package/dist/cjs/dimensional-model/attributes.d.ts +4 -2
  2. package/dist/cjs/dimensional-model/attributes.js +17 -3
  3. package/dist/cjs/dimensional-model/dimensions/__mocks__/sample-ecommerce-fields.d.ts +5 -0
  4. package/dist/cjs/dimensional-model/dimensions/__mocks__/sample-ecommerce-fields.js +246 -0
  5. package/dist/cjs/dimensional-model/{dimensions.d.ts → dimensions/dimensions.d.ts} +3 -3
  6. package/dist/cjs/dimensional-model/{dimensions.js → dimensions/dimensions.js} +3 -3
  7. package/dist/cjs/dimensional-model/dimensions/index.d.ts +2 -0
  8. package/dist/cjs/dimensional-model/dimensions/index.js +18 -0
  9. package/dist/cjs/dimensional-model/dimensions/utils.d.ts +11 -0
  10. package/dist/cjs/dimensional-model/dimensions/utils.js +63 -0
  11. package/dist/cjs/dimensional-model/factory.js +2 -2
  12. package/dist/cjs/dimensional-model/filters/filters.d.ts +1 -0
  13. package/dist/cjs/dimensional-model/filters/filters.js +5 -0
  14. package/dist/cjs/dimensional-model/types.d.ts +2 -0
  15. package/dist/cjs/index.d.ts +1 -1
  16. package/dist/cjs/index.js +1 -1
  17. package/dist/cjs/utils.d.ts +6 -6
  18. package/dist/cjs/utils.js +7 -8
  19. package/dist/dimensional-model/attributes.d.ts +4 -2
  20. package/dist/dimensional-model/attributes.js +17 -3
  21. package/dist/dimensional-model/dimensions/__mocks__/sample-ecommerce-fields.d.ts +5 -0
  22. package/dist/dimensional-model/dimensions/__mocks__/sample-ecommerce-fields.js +243 -0
  23. package/dist/dimensional-model/{dimensions.d.ts → dimensions/dimensions.d.ts} +3 -3
  24. package/dist/dimensional-model/{dimensions.js → dimensions/dimensions.js} +3 -3
  25. package/dist/dimensional-model/dimensions/index.d.ts +2 -0
  26. package/dist/dimensional-model/dimensions/index.js +2 -0
  27. package/dist/dimensional-model/dimensions/utils.d.ts +11 -0
  28. package/dist/dimensional-model/dimensions/utils.js +59 -0
  29. package/dist/dimensional-model/factory.js +1 -1
  30. package/dist/dimensional-model/filters/filters.d.ts +1 -0
  31. package/dist/dimensional-model/filters/filters.js +5 -0
  32. package/dist/dimensional-model/types.d.ts +2 -0
  33. package/dist/index.d.ts +1 -1
  34. package/dist/index.js +1 -1
  35. package/dist/tsconfig.prod.cjs.tsbuildinfo +1 -1
  36. package/dist/utils.d.ts +6 -6
  37. package/dist/utils.js +7 -8
  38. package/package.json +3 -3
@@ -10,8 +10,9 @@ export declare const jaqlSimpleColumnType: (datatype: string) => string;
10
10
  */
11
11
  export declare class DimensionalAttribute extends DimensionalElement implements Attribute {
12
12
  readonly expression: string;
13
+ readonly panel: string;
13
14
  protected _sort: Sort;
14
- constructor(name: string, expression: string, type?: string, desc?: string, sort?: Sort, dataSource?: JaqlDataSource, composeCode?: string);
15
+ constructor(name: string, expression: string, type?: string, desc?: string, sort?: Sort, dataSource?: JaqlDataSource, composeCode?: string, panel?: string);
15
16
  /**
16
17
  * gets the element's ID
17
18
  */
@@ -46,7 +47,8 @@ export declare class DimensionalAttribute extends DimensionalElement implements
46
47
  export declare class DimensionalLevelAttribute extends DimensionalAttribute implements LevelAttribute {
47
48
  private _format;
48
49
  readonly granularity: string;
49
- constructor(l: string, expression: string, granularity: string, format?: string, desc?: string, sort?: Sort, dataSource?: JaqlDataSource, composeCode?: string);
50
+ readonly panel: string;
51
+ constructor(l: string, expression: string, granularity: string, format?: string, desc?: string, sort?: Sort, dataSource?: JaqlDataSource, composeCode?: string, panel?: string);
50
52
  /**
51
53
  * gets the element's ID
52
54
  */
@@ -9,10 +9,14 @@ export const jaqlSimpleColumnType = (datatype) => simpleColumnType(datatype).rep
9
9
  * @internal
10
10
  */
11
11
  export class DimensionalAttribute extends DimensionalElement {
12
- constructor(name, expression, type, desc, sort, dataSource, composeCode) {
12
+ constructor(name, expression, type, desc, sort, dataSource, composeCode, panel) {
13
13
  super(name, type || MetadataTypes.Attribute, desc, dataSource, composeCode);
14
14
  this._sort = Sort.None;
15
15
  this.expression = expression;
16
+ // panel is not needed in most cases, this is to support break by columns functionality
17
+ if (panel === 'columns') {
18
+ this.panel = panel;
19
+ }
16
20
  this._sort = sort || Sort.None;
17
21
  }
18
22
  /**
@@ -36,7 +40,7 @@ export class DimensionalAttribute extends DimensionalElement {
36
40
  * @returns An instance representing the sorted {@link Attribute} of this instance
37
41
  */
38
42
  sort(sort) {
39
- return new DimensionalAttribute(this.name, this.expression, this.type, this.description, sort, this.dataSource, this.composeCode);
43
+ return new DimensionalAttribute(this.name, this.expression, this.type, this.description, sort, this.dataSource, this.composeCode, this.panel);
40
44
  }
41
45
  /**
42
46
  * Gets the JAQL representation of this instance
@@ -51,6 +55,9 @@ export class DimensionalAttribute extends DimensionalElement {
51
55
  datatype: jaqlSimpleColumnType(this.type),
52
56
  },
53
57
  };
58
+ if (this.panel) {
59
+ result.panel = this.panel;
60
+ }
54
61
  if (this._sort != Sort.None) {
55
62
  result.jaql.sort = this._sort == Sort.Ascending ? 'asc' : 'desc';
56
63
  }
@@ -72,10 +79,14 @@ export class DimensionalAttribute extends DimensionalElement {
72
79
  * @internal
73
80
  */
74
81
  export class DimensionalLevelAttribute extends DimensionalAttribute {
75
- constructor(l, expression, granularity, format, desc, sort, dataSource, composeCode) {
82
+ constructor(l, expression, granularity, format, desc, sort, dataSource, composeCode, panel) {
76
83
  super(l, expression, MetadataTypes.DateLevel, desc, sort, dataSource, composeCode);
77
84
  this._format = format;
78
85
  this.granularity = granularity;
86
+ // panel is not needed in most cases, this is to support break by columns functionality
87
+ if (panel === 'columns') {
88
+ this.panel = panel;
89
+ }
79
90
  }
80
91
  /**
81
92
  * gets the element's ID
@@ -143,6 +154,9 @@ export class DimensionalLevelAttribute extends DimensionalAttribute {
143
154
  const r = {
144
155
  jaql: Object.assign({ title: this.name, dim: this.expression, datatype: jaqlSimpleColumnType(this.type) }, this.translateGranularityToJaql()),
145
156
  };
157
+ if (this.panel) {
158
+ r.panel = this.panel;
159
+ }
146
160
  if (this._format !== undefined) {
147
161
  const levelName = r.jaql.dateTimeLevel || r.jaql.level;
148
162
  r.format = { mask: {} };
@@ -0,0 +1,5 @@
1
+ import { AnyObject, DataSourceField } from '../../types.js';
2
+ /**
3
+ * Actual fields from the Sample ECommerce datasource returned by server.
4
+ */
5
+ export declare const sampleEcommerceFields: (DataSourceField & AnyObject)[];
@@ -0,0 +1,243 @@
1
+ /**
2
+ * Actual fields from the Sample ECommerce datasource returned by server.
3
+ */
4
+ export const sampleEcommerceFields = [
5
+ {
6
+ id: '[Brand.Brand]',
7
+ type: 'dimension',
8
+ dimtype: 'text',
9
+ title: 'Brand',
10
+ table: 'Brand',
11
+ column: 'Brand',
12
+ merged: false,
13
+ indexed: true,
14
+ tableDescription: null,
15
+ columnDescription: null,
16
+ tableTitle: null,
17
+ semanticIndex: false,
18
+ },
19
+ {
20
+ id: '[Brand.Brand ID]',
21
+ type: 'dimension',
22
+ dimtype: 'numeric',
23
+ title: 'Brand ID',
24
+ table: 'Brand',
25
+ column: 'Brand ID',
26
+ merged: true,
27
+ indexed: false,
28
+ tableDescription: null,
29
+ columnDescription: null,
30
+ tableTitle: null,
31
+ semanticIndex: false,
32
+ },
33
+ {
34
+ id: '[Category.Category]',
35
+ type: 'dimension',
36
+ dimtype: 'text',
37
+ title: 'Category',
38
+ table: 'Category',
39
+ column: 'Category',
40
+ merged: false,
41
+ indexed: true,
42
+ tableDescription: null,
43
+ columnDescription: null,
44
+ tableTitle: null,
45
+ semanticIndex: false,
46
+ },
47
+ {
48
+ id: '[Category.Category ID]',
49
+ type: 'dimension',
50
+ dimtype: 'numeric',
51
+ title: 'Category ID',
52
+ table: 'Category',
53
+ column: 'Category ID',
54
+ merged: true,
55
+ indexed: false,
56
+ tableDescription: null,
57
+ columnDescription: null,
58
+ tableTitle: null,
59
+ semanticIndex: false,
60
+ },
61
+ {
62
+ id: '[Commerce.Age Range]',
63
+ type: 'dimension',
64
+ dimtype: 'text',
65
+ title: 'Age Range',
66
+ table: 'Commerce',
67
+ column: 'Age Range',
68
+ merged: false,
69
+ indexed: true,
70
+ tableDescription: null,
71
+ columnDescription: null,
72
+ tableTitle: null,
73
+ semanticIndex: false,
74
+ },
75
+ {
76
+ id: '[Commerce.Brand ID]',
77
+ type: 'dimension',
78
+ dimtype: 'numeric',
79
+ title: 'Brand ID',
80
+ table: 'Commerce',
81
+ column: 'Brand ID',
82
+ merged: true,
83
+ indexed: false,
84
+ tableDescription: null,
85
+ columnDescription: null,
86
+ tableTitle: null,
87
+ semanticIndex: false,
88
+ },
89
+ {
90
+ id: '[Commerce.Category ID]',
91
+ type: 'dimension',
92
+ dimtype: 'numeric',
93
+ title: 'Category ID',
94
+ table: 'Commerce',
95
+ column: 'Category ID',
96
+ merged: true,
97
+ indexed: false,
98
+ tableDescription: null,
99
+ columnDescription: null,
100
+ tableTitle: null,
101
+ semanticIndex: false,
102
+ },
103
+ {
104
+ id: '[Commerce.Condition]',
105
+ type: 'dimension',
106
+ dimtype: 'text',
107
+ title: 'Condition',
108
+ table: 'Commerce',
109
+ column: 'Condition',
110
+ merged: false,
111
+ indexed: true,
112
+ tableDescription: null,
113
+ columnDescription: null,
114
+ tableTitle: null,
115
+ semanticIndex: false,
116
+ },
117
+ {
118
+ id: '[Commerce.Cost]',
119
+ type: 'dimension',
120
+ dimtype: 'numeric',
121
+ title: 'Cost',
122
+ table: 'Commerce',
123
+ column: 'Cost',
124
+ merged: false,
125
+ indexed: false,
126
+ tableDescription: null,
127
+ columnDescription: null,
128
+ tableTitle: null,
129
+ semanticIndex: false,
130
+ },
131
+ {
132
+ id: '[Commerce.Country ID]',
133
+ type: 'dimension',
134
+ dimtype: 'numeric',
135
+ title: 'Country ID',
136
+ table: 'Commerce',
137
+ column: 'Country ID',
138
+ merged: true,
139
+ indexed: false,
140
+ tableDescription: null,
141
+ columnDescription: null,
142
+ tableTitle: null,
143
+ semanticIndex: false,
144
+ },
145
+ {
146
+ id: '[Commerce.Date (Calendar)]',
147
+ type: 'dimension',
148
+ dimtype: 'datetime',
149
+ title: 'Date',
150
+ table: 'Commerce',
151
+ column: 'Date',
152
+ merged: false,
153
+ indexed: true,
154
+ tableDescription: null,
155
+ columnDescription: null,
156
+ tableTitle: null,
157
+ semanticIndex: false,
158
+ },
159
+ {
160
+ id: '[Commerce.Gender]',
161
+ type: 'dimension',
162
+ dimtype: 'text',
163
+ title: 'Gender',
164
+ table: 'Commerce',
165
+ column: 'Gender',
166
+ merged: false,
167
+ indexed: true,
168
+ tableDescription: null,
169
+ columnDescription: null,
170
+ tableTitle: null,
171
+ semanticIndex: false,
172
+ },
173
+ {
174
+ id: '[Commerce.Quantity]',
175
+ type: 'dimension',
176
+ dimtype: 'numeric',
177
+ title: 'Quantity',
178
+ table: 'Commerce',
179
+ column: 'Quantity',
180
+ merged: false,
181
+ indexed: false,
182
+ tableDescription: null,
183
+ columnDescription: null,
184
+ tableTitle: null,
185
+ semanticIndex: false,
186
+ },
187
+ {
188
+ id: '[Commerce.Revenue]',
189
+ type: 'dimension',
190
+ dimtype: 'numeric',
191
+ title: 'Revenue',
192
+ table: 'Commerce',
193
+ column: 'Revenue',
194
+ merged: false,
195
+ indexed: false,
196
+ tableDescription: null,
197
+ columnDescription: null,
198
+ tableTitle: null,
199
+ semanticIndex: false,
200
+ },
201
+ {
202
+ id: '[Commerce.Visit ID]',
203
+ type: 'dimension',
204
+ dimtype: 'numeric',
205
+ title: 'Visit ID',
206
+ table: 'Commerce',
207
+ column: 'Visit ID',
208
+ merged: false,
209
+ indexed: false,
210
+ tableDescription: null,
211
+ columnDescription: null,
212
+ tableTitle: null,
213
+ semanticIndex: false,
214
+ },
215
+ {
216
+ id: '[Country.Country]',
217
+ type: 'dimension',
218
+ dimtype: 'text',
219
+ title: 'Country',
220
+ table: 'Country',
221
+ column: 'Country',
222
+ merged: false,
223
+ indexed: true,
224
+ tableDescription: null,
225
+ columnDescription: null,
226
+ tableTitle: null,
227
+ semanticIndex: false,
228
+ },
229
+ {
230
+ id: '[Country.Country ID]',
231
+ type: 'dimension',
232
+ dimtype: 'numeric',
233
+ title: 'Country ID',
234
+ table: 'Country',
235
+ column: 'Country ID',
236
+ merged: true,
237
+ indexed: false,
238
+ tableDescription: null,
239
+ columnDescription: null,
240
+ tableTitle: null,
241
+ semanticIndex: false,
242
+ },
243
+ ];
@@ -1,6 +1,6 @@
1
- import { Attribute, LevelAttribute, Dimension, DateDimension } from './interfaces.js';
2
- import { Sort, JaqlDataSource } from './types.js';
3
- import { DimensionalElement } from './base.js';
1
+ import { Attribute, LevelAttribute, Dimension, DateDimension } from '../interfaces.js';
2
+ import { Sort, JaqlDataSource } from '../types.js';
3
+ import { DimensionalElement } from '../base.js';
4
4
  /**
5
5
  * Represents a Dimension in a Dimensional Model
6
6
  *
@@ -1,6 +1,6 @@
1
- import { Sort, DateLevels, MetadataTypes } from './types.js';
2
- import { DimensionalAttribute, DimensionalLevelAttribute, jaqlSimpleColumnType, } from './attributes.js';
3
- import { DimensionalElement, normalizeName } from './base.js';
1
+ import { Sort, DateLevels, MetadataTypes } from '../types.js';
2
+ import { DimensionalAttribute, DimensionalLevelAttribute, jaqlSimpleColumnType, } from '../attributes.js';
3
+ import { DimensionalElement, normalizeName } from '../base.js';
4
4
  /**
5
5
  * Represents a Dimension in a Dimensional Model
6
6
  *
@@ -0,0 +1,2 @@
1
+ export * from './dimensions.js';
2
+ export * from './utils.js';
@@ -0,0 +1,2 @@
1
+ export * from './dimensions.js';
2
+ export * from './utils.js';
@@ -0,0 +1,11 @@
1
+ import { DataSource } from '../../interfaces.js';
2
+ import { Dimension } from '../interfaces.js';
3
+ import { DataSourceField } from '../types.js';
4
+ /**
5
+ * Function to convert data source fields to dimensions.
6
+ * @param fields - The data source fields to convert.
7
+ * @param dataSource - The data source title.
8
+ * @returns - The dimensions created from the data source fields.
9
+ * @internal
10
+ */
11
+ export declare function getDimensionsFromDataSourceFields(fields: DataSourceField[], dataSource: DataSource): Dimension[];
@@ -0,0 +1,59 @@
1
+ import { createAttribute } from '../attributes.js';
2
+ import { createDimension, createDateDimension } from './dimensions.js';
3
+ import { isDataSourceInfo } from '../../utils.js';
4
+ /**
5
+ * Function to convert data source fields to dimensions.
6
+ * @param fields - The data source fields to convert.
7
+ * @param dataSource - The data source title.
8
+ * @returns - The dimensions created from the data source fields.
9
+ * @internal
10
+ */
11
+ export function getDimensionsFromDataSourceFields(fields, dataSource) {
12
+ const attributeEntries = fields.map((field) => createAttributeEntry(field, dataSource));
13
+ const groupedConfigs = groupAttributesByDimension(attributeEntries);
14
+ return Object.values(groupedConfigs).map((config) => createDimension(config));
15
+ }
16
+ /**
17
+ * Given a DataSourceField and the data source title, creates an attribute entry
18
+ * that includes the dimension name, attribute name, and the attribute itself.
19
+ */
20
+ const createAttributeEntry = (field, dataSource) => {
21
+ const dimensionId = field.table;
22
+ const dimensionName = field.tableTitle || dimensionId;
23
+ const attributeId = field.id;
24
+ const attributeName = field.title || attributeId;
25
+ const dataSourceConfig = isDataSourceInfo(dataSource)
26
+ ? dataSource
27
+ : { title: dataSource, live: false };
28
+ const attribute = field.dimtype === 'datetime'
29
+ ? createDateDimension({
30
+ name: attributeName,
31
+ expression: attributeId,
32
+ dataSource: dataSourceConfig,
33
+ })
34
+ : createAttribute({
35
+ name: attributeName,
36
+ type: field.dimtype === 'text' ? 'text-attribute' : 'numeric-attribute',
37
+ expression: attributeId,
38
+ dataSource: dataSourceConfig,
39
+ });
40
+ return {
41
+ dimension: {
42
+ id: dimensionId,
43
+ name: dimensionName,
44
+ },
45
+ attribute,
46
+ };
47
+ };
48
+ /**
49
+ * Groups an array of attribute entries by their dimension name.
50
+ * Returns an object whose keys are dimension names and values are configuration objects
51
+ * that can be passed to createDimension.
52
+ */
53
+ const groupAttributesByDimension = (entries) => entries.reduce((acc, { dimension, attribute }) => {
54
+ const dimensionConfig = acc[dimension.name] || {
55
+ name: dimension.name,
56
+ expression: dimension.id,
57
+ };
58
+ return Object.assign(Object.assign({}, acc), { [dimension.name]: Object.assign(Object.assign({}, dimensionConfig), { [attribute.name]: attribute }) });
59
+ }, {});
@@ -2,7 +2,7 @@
2
2
  import { MetadataTypes } from './types.js';
3
3
  import { createMeasure } from './measures/measures.js';
4
4
  import { createFilter } from './filters/filters.js';
5
- import { createDimension } from './dimensions.js';
5
+ import { createDimension } from './dimensions/index.js';
6
6
  import { createAttribute } from './attributes.js';
7
7
  import { TranslatableError } from '../translation/translatable-error.js';
8
8
  /**
@@ -153,6 +153,7 @@ export declare class MembersFilter extends AbstractFilter {
153
153
  * gets the element's ID
154
154
  */
155
155
  get id(): string;
156
+ get name(): string;
156
157
  /**
157
158
  * Gets a serializable representation of the element
158
159
  */
@@ -6,6 +6,7 @@ import { DimensionalBaseMeasure } from '../measures/measures.js';
6
6
  import { TranslatableError } from '../../translation/translatable-error.js';
7
7
  import { getDefaultBaseFilterConfig, getDefaultMembersFilterConfig, } from './filter-config-utils.js';
8
8
  import merge from 'lodash-es/merge.js';
9
+ import omit from 'lodash-es/omit.js';
9
10
  /**
10
11
  * Different text operators that can be used with text filters
11
12
  *
@@ -210,6 +211,10 @@ export class MembersFilter extends AbstractFilter {
210
211
  get id() {
211
212
  return `${this.attribute.id}_${this.members.map((m) => m.toString()).join()}`;
212
213
  }
214
+ get name() {
215
+ // to hexadecimal string
216
+ return hash([this.jaql(), omit(this.config, ['guid', 'originalFilterJaql'])]).toString(16);
217
+ }
213
218
  /**
214
219
  * Gets a serializable representation of the element
215
220
  */
@@ -197,6 +197,7 @@ export declare type BaseJaql = {
197
197
  };
198
198
  };
199
199
  merged?: boolean;
200
+ panel?: 'rows' | 'columns';
200
201
  };
201
202
  /** @internal */
202
203
  export declare type FormulaID = string;
@@ -403,6 +404,7 @@ export declare type DataSourceField = {
403
404
  indexed: boolean;
404
405
  merged: boolean;
405
406
  table: string;
407
+ tableTitle?: null | string;
406
408
  title: string;
407
409
  type: string;
408
410
  };
package/dist/index.d.ts CHANGED
@@ -12,7 +12,7 @@ export * from './dimensional-model/interfaces.js';
12
12
  export * from './dimensional-model/base.js';
13
13
  export * from './dimensional-model/data-model.js';
14
14
  export * from './dimensional-model/attributes.js';
15
- export * from './dimensional-model/dimensions.js';
15
+ export * from './dimensional-model/dimensions/index.js';
16
16
  export * from './dimensional-model/factory.js';
17
17
  export * from './dimensional-model/jaql-element.js';
18
18
  export * from './dimensional-model/filters/filters.js';
package/dist/index.js CHANGED
@@ -12,7 +12,7 @@ export * from './dimensional-model/interfaces.js';
12
12
  export * from './dimensional-model/base.js';
13
13
  export * from './dimensional-model/data-model.js';
14
14
  export * from './dimensional-model/attributes.js';
15
- export * from './dimensional-model/dimensions.js';
15
+ export * from './dimensional-model/dimensions/index.js';
16
16
  export * from './dimensional-model/factory.js';
17
17
  export * from './dimensional-model/jaql-element.js';
18
18
  export * from './dimensional-model/filters/filters.js';