@sisense/sdk-data 1.7.2 → 1.9.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 (34) hide show
  1. package/README.md +1 -1
  2. package/dist/dimensional-model/analytics/factory.js +2 -2
  3. package/dist/dimensional-model/attributes.d.ts +11 -0
  4. package/dist/dimensional-model/attributes.js +20 -1
  5. package/dist/dimensional-model/dimensions.js +5 -4
  6. package/dist/dimensional-model/factory.js +0 -1
  7. package/dist/dimensional-model/filters/factory.d.ts +58 -0
  8. package/dist/dimensional-model/filters/factory.js +68 -0
  9. package/dist/dimensional-model/filters/filters.js +0 -3
  10. package/dist/dimensional-model/filters/utils/attribute-measure-util.d.ts +47 -0
  11. package/dist/dimensional-model/filters/utils/attribute-measure-util.js +77 -0
  12. package/dist/dimensional-model/filters/utils/condition-filter-util.d.ts +19 -0
  13. package/dist/dimensional-model/filters/utils/condition-filter-util.js +162 -0
  14. package/dist/dimensional-model/filters/utils/date-time-filter-util.d.ts +2 -0
  15. package/dist/dimensional-model/filters/utils/date-time-filter-util.js +8 -0
  16. package/dist/dimensional-model/filters/utils/filter-code-util.d.ts +13 -0
  17. package/dist/dimensional-model/filters/utils/filter-code-util.js +49 -0
  18. package/dist/dimensional-model/filters/utils/filter-from-jaql-util.d.ts +67 -0
  19. package/dist/dimensional-model/filters/utils/filter-from-jaql-util.js +149 -0
  20. package/dist/dimensional-model/filters/utils/filter-types-util.d.ts +15 -0
  21. package/dist/dimensional-model/filters/utils/filter-types-util.js +71 -0
  22. package/dist/dimensional-model/filters/utils/types.d.ts +200 -0
  23. package/dist/dimensional-model/filters/utils/types.js +96 -0
  24. package/dist/dimensional-model/interfaces.d.ts +58 -8
  25. package/dist/dimensional-model/measures/factory.d.ts +15 -2
  26. package/dist/dimensional-model/measures/factory.js +17 -2
  27. package/dist/dimensional-model/measures/measures.js +1 -4
  28. package/dist/dimensional-model/types.d.ts +37 -5
  29. package/dist/dimensional-model/types.js +6 -8
  30. package/dist/index.d.ts +0 -2
  31. package/dist/index.js +0 -2
  32. package/dist/utils.d.ts +12 -1
  33. package/dist/utils.js +17 -0
  34. package/package.json +3 -3
@@ -10,8 +10,7 @@ export interface DataModel {
10
10
  [propName: string]: any;
11
11
  }
12
12
  /**
13
- * Common interface for elements of
14
- * [dimensional modeling](https://docs.sisense.com/main/SisenseLinux/data-model-building-practices.htm?tocpath=Modeling%20Data%7C_____4).
13
+ * Common interface for elements of a dimensional model.
15
14
  *
16
15
  * @internal
17
16
  */
@@ -61,6 +60,12 @@ export interface Element {
61
60
  * @internal
62
61
  */
63
62
  skipValidation?: boolean;
63
+ /**
64
+ * Optional CSDK code to initialize this element
65
+ *
66
+ * @internal
67
+ */
68
+ composeCode?: string;
64
69
  }
65
70
  /**
66
71
  * Base interface for measure, which is typically numeric aggregation over {@link Attribute}(s).
@@ -210,9 +215,6 @@ export interface Dimension extends Element, Attribute {
210
215
  }
211
216
  /**
212
217
  * Date Dimension extending {@link Dimension}.
213
- *
214
- * See [here](https://docs.sisense.com/main/SisenseLinux/date-and-time-fields.htm)
215
- * for more details on Date and Time Resolution for ElastiCubes and for Live Models.
216
218
  */
217
219
  export interface DateDimension extends Dimension {
218
220
  /**
@@ -265,9 +267,9 @@ export interface DateDimension extends Dimension {
265
267
  readonly AggMinutesRoundTo1: LevelAttribute;
266
268
  }
267
269
  /**
268
- * Common interface of an Attribute as defined in
269
- * [Dimensional Modeling](https://docs.sisense.com/main/SisenseLinux/data-model-building-practices.htm?tocpath=Modeling%20Data%7C_____4).
270
- * It is an extension of a {@link Column} in a generic {@link Data | Data Set}.
270
+ * Common interface of an attribute as in a dimensional model.
271
+ *
272
+ * An attribute is an extension of a {@link Column} in a generic {@link Data | data set}.
271
273
  */
272
274
  export interface Attribute extends Element {
273
275
  /**
@@ -354,6 +356,7 @@ export interface CustomFormulaContext {
354
356
  export interface PivotAttribute {
355
357
  attribute: Attribute;
356
358
  includeSubTotals?: boolean;
359
+ sort?: PivotRowsSort;
357
360
  }
358
361
  /**
359
362
  * Runs type guard check for PivotAttribute.
@@ -454,3 +457,50 @@ export declare type FilterRelationsModelIdNode = {
454
457
  export declare type FilterRelationsModelBracketNode = {
455
458
  value: FilterRelationsModelNode;
456
459
  };
460
+ /** Sorting direction, either in Ascending order, Descending order, or None */
461
+ export declare type SortDirection = 'sortAsc' | 'sortDesc' | 'sortNone';
462
+ /**
463
+ * Sorting configuration for pivot "rows".
464
+ *
465
+ * This configuration allows sorting pivot "rows" either by their data or by data in a specific "values" column.
466
+ *
467
+ * @example
468
+ * Examples of sorting configurations for various scenarios:
469
+ *
470
+ * (1) Row sorted in ascending order by its data:
471
+ * ```ts
472
+ * { direction: 'sortAsc' }
473
+ * ```
474
+ *
475
+ * (2) Row sorted in descending order by data in the first "values" column (index 0):
476
+ * ```ts
477
+ * {
478
+ * direction: 'sortDesc',
479
+ * by: {
480
+ * valuesIndex: 0,
481
+ * }
482
+ * }
483
+ * ```
484
+ *
485
+ * (3) Row sorted in ascending order by data in the second "values" column (index 1) under the "columns" values of "Female" (for Gender) and "0-18" (for AgeRange):
486
+ * ```ts
487
+ * {
488
+ * direction: 'sortAsc',
489
+ * by: {
490
+ * valuesIndex: 1,
491
+ * columnsMembersPath: ['Female', '0-18']
492
+ * }
493
+ * }
494
+ * ```
495
+ */
496
+ export declare type PivotRowsSort = {
497
+ /** {@inheritDoc SortDirection} */
498
+ direction: SortDirection;
499
+ /** Sorting target configuration, allowing sorting "rows" by the data in a specific "values" column */
500
+ by?: {
501
+ /** Index of the target "values" item (measure) */
502
+ valuesIndex?: number;
503
+ /** Path to the target column if selected "columns" items (dimensions) are involved */
504
+ columnsMembersPath?: (string | number)[];
505
+ };
506
+ };
@@ -40,8 +40,8 @@ export declare const RankingSortTypes: {
40
40
  *
41
41
  * You can nest custom formulas by placing one inside the `formula` parameter of another.
42
42
  *
43
- * Note: [Shared formulas](https://docs.sisense.com/main/SisenseLinux/shared-formulas.htm) must be
44
- * fetched prior to use (see {@link @sisense/sdk-ui!useGetSharedFormula | useGetSharedFormula}).
43
+ * Note: To use [shared formulas](https://docs.sisense.com/main/SisenseLinux/shared-formulas.htm)
44
+ * from a Fusion Embed instance, you must fetch them first using {@link @sisense/sdk-ui!useGetSharedFormula | useGetSharedFormula}.
45
45
  *
46
46
  * @example
47
47
  * An example of constructing a custom formulas using dimensions, measures, and nested custom formulas
@@ -125,6 +125,8 @@ export declare function sum(attribute: Attribute, name?: string, format?: string
125
125
  /**
126
126
  * Creates an average aggregation measure over the given attribute.
127
127
  *
128
+ * Both `average()` and `avg()` can be used interchangeably.
129
+ *
128
130
  * @example
129
131
  * Calculate the average cost across all items in a category from the Sample Ecommerce data model.
130
132
  * ```ts
@@ -137,6 +139,17 @@ export declare function sum(attribute: Attribute, name?: string, format?: string
137
139
  * @group Aggregation
138
140
  */
139
141
  export declare function average(attribute: Attribute, name?: string, format?: string): BaseMeasure;
142
+ /**
143
+ * {@inheritDoc average}
144
+ *
145
+ * @example
146
+ * Calculate the average cost across all items in a category from the Sample Ecommerce data model.
147
+ * ```ts
148
+ * measureFactory.avg(DM.Commerce.Cost)
149
+ * ```
150
+ * @group Aggregation
151
+ */
152
+ export declare function avg(attribute: Attribute, name?: string, format?: string): BaseMeasure;
140
153
  /**
141
154
  * Creates a min aggregation measure over the given attribute.
142
155
  *
@@ -105,8 +105,8 @@ function transformCustomFormulaJaql(jaql) {
105
105
  *
106
106
  * You can nest custom formulas by placing one inside the `formula` parameter of another.
107
107
  *
108
- * Note: [Shared formulas](https://docs.sisense.com/main/SisenseLinux/shared-formulas.htm) must be
109
- * fetched prior to use (see {@link @sisense/sdk-ui!useGetSharedFormula | useGetSharedFormula}).
108
+ * Note: To use [shared formulas](https://docs.sisense.com/main/SisenseLinux/shared-formulas.htm)
109
+ * from a Fusion Embed instance, you must fetch them first using {@link @sisense/sdk-ui!useGetSharedFormula | useGetSharedFormula}.
110
110
  *
111
111
  * @example
112
112
  * An example of constructing a custom formulas using dimensions, measures, and nested custom formulas
@@ -217,6 +217,8 @@ export function sum(attribute, name, format) {
217
217
  /**
218
218
  * Creates an average aggregation measure over the given attribute.
219
219
  *
220
+ * Both `average()` and `avg()` can be used interchangeably.
221
+ *
220
222
  * @example
221
223
  * Calculate the average cost across all items in a category from the Sample Ecommerce data model.
222
224
  * ```ts
@@ -231,6 +233,19 @@ export function sum(attribute, name, format) {
231
233
  export function average(attribute, name, format) {
232
234
  return aggregate(attribute, AggregationTypes.Average, name, format);
233
235
  }
236
+ /**
237
+ * {@inheritDoc average}
238
+ *
239
+ * @example
240
+ * Calculate the average cost across all items in a category from the Sample Ecommerce data model.
241
+ * ```ts
242
+ * measureFactory.avg(DM.Commerce.Cost)
243
+ * ```
244
+ * @group Aggregation
245
+ */
246
+ export function avg(attribute, name, format) {
247
+ return average(attribute, name, format);
248
+ }
234
249
  /**
235
250
  * Creates a min aggregation measure over the given attribute.
236
251
  *
@@ -2,11 +2,8 @@
2
2
  /* eslint-disable no-underscore-dangle */
3
3
  /* eslint-disable @typescript-eslint/no-unsafe-assignment */
4
4
  /* eslint-disable @typescript-eslint/no-unsafe-member-access */
5
- /* eslint-disable complexity */
6
- /* eslint-disable max-lines */
7
5
  /* eslint-disable @typescript-eslint/no-unsafe-return */
8
6
  /* eslint-disable @typescript-eslint/no-unsafe-call */
9
- /* eslint-disable sonarjs/cognitive-complexity */
10
7
  /* eslint-disable @typescript-eslint/no-unsafe-argument */
11
8
  import * as m from './factory.js';
12
9
  import { Sort, AggregationTypes, MetadataTypes } from '../types.js';
@@ -352,7 +349,7 @@ export function createMeasure(json) {
352
349
  // legacy
353
350
  const exp = json.dim || json.expression;
354
351
  if (exp) {
355
- att = new DimensionalAttribute(exp, exp);
352
+ att = new DimensionalAttribute(exp, exp, undefined, desc);
356
353
  }
357
354
  // official SDK
358
355
  if (json.attribute) {
@@ -157,12 +157,21 @@ export declare enum DataType {
157
157
  DATETIME = "datetime"
158
158
  }
159
159
  /** @internal */
160
- export declare enum SortDirection {
160
+ export declare enum JaqlSortDirection {
161
161
  ASC = "asc",
162
162
  DESC = "desc"
163
163
  }
164
164
  /** @internal */
165
- export declare type Jaql = BaseJaql | FormulaJaql | FilterJaql;
165
+ export declare type Jaql = BaseJaql | FormulaJaql | FilterJaql | PivotJaql;
166
+ /** @internal */
167
+ export declare type PivotJaql = (BaseJaql | FormulaJaql) & {
168
+ sortDetails?: {
169
+ dir: JaqlSortDirection;
170
+ field: number;
171
+ measurePath?: Record<string, string> | null;
172
+ };
173
+ subtotalAgg?: 'sum' | 'min' | 'max' | 'avg' | 'median';
174
+ };
166
175
  /** @internal */
167
176
  export declare type BaseJaql = {
168
177
  agg?: string;
@@ -172,7 +181,7 @@ export declare type BaseJaql = {
172
181
  column: string;
173
182
  title: string;
174
183
  level?: 'years' | 'quarters' | 'months' | 'weeks' | 'minutes' | 'days';
175
- sort?: SortDirection;
184
+ sort?: JaqlSortDirection;
176
185
  };
177
186
  /** @internal */
178
187
  export declare type FormulaID = string;
@@ -181,13 +190,13 @@ export declare type FormulaContext = BaseJaql | FormulaJaql | FilterJaql;
181
190
  /** @internal */
182
191
  export declare type FormulaJaql = {
183
192
  type?: 'measure';
184
- sort?: SortDirection;
193
+ sort?: JaqlSortDirection;
185
194
  title: string;
186
195
  formula: string;
187
196
  context?: Record<FormulaID, FormulaContext>;
188
197
  };
189
198
  /** @internal */
190
- export declare type BaseFilter = IncludeAllFilter | IncludeMembersFilter | ExcludeMembersFilter;
199
+ export declare type BaseFilter = IncludeAllFilter | IncludeMembersFilter | ExcludeMembersFilter | JaqlNumericFilter | AndFilter<JaqlNumericFilter> | OrFilter<JaqlNumericFilter>;
191
200
  /** @internal */
192
201
  export declare type BackgroundFilter = BaseFilter & {
193
202
  level?: 'string';
@@ -216,3 +225,26 @@ export declare type FilterJaql = BaseJaql & {
216
225
  filter?: BackgroundFilter | TurnOffMembersFilter;
217
226
  };
218
227
  };
228
+ declare type NumericFilterValue = number | FormulaJaql;
229
+ /** @internal */
230
+ export declare type JaqlNumericFilter = {
231
+ equals?: NumericFilterValue;
232
+ doesntEqual?: NumericFilterValue;
233
+ toNotEqual?: NumericFilterValue;
234
+ to?: NumericFilterValue;
235
+ fromNotEqual?: NumericFilterValue;
236
+ from?: NumericFilterValue;
237
+ '='?: NumericFilterValue;
238
+ '<'?: NumericFilterValue;
239
+ '>'?: NumericFilterValue;
240
+ '>='?: NumericFilterValue;
241
+ '<='?: NumericFilterValue;
242
+ };
243
+ declare type AndFilter<FilterItem> = {
244
+ and: FilterItem[];
245
+ };
246
+ /** @internal */
247
+ export declare type OrFilter<FilterItem> = {
248
+ or: FilterItem[];
249
+ };
250
+ export {};
@@ -1,8 +1,6 @@
1
1
  /* eslint-disable @typescript-eslint/no-unsafe-return */
2
2
  /* eslint-disable @typescript-eslint/no-unsafe-member-access */
3
- /* eslint-disable complexity */
4
3
  /* eslint-disable @typescript-eslint/no-unsafe-assignment */
5
- /* eslint-disable max-lines */
6
4
  /*
7
5
  * Types
8
6
  */
@@ -21,7 +19,7 @@ export const AggregationTypes = {
21
19
  /** Count aggregation type */
22
20
  Count: 'count',
23
21
  /** Count distinct aggregation type */
24
- CountDistinct: 'countdistinct',
22
+ CountDistinct: 'countDistinct',
25
23
  /** Median aggregation type */
26
24
  Median: 'median',
27
25
  /** Variance aggregation type */
@@ -290,8 +288,8 @@ export var DataType;
290
288
  DataType["DATETIME"] = "datetime";
291
289
  })(DataType = DataType || (DataType = {}));
292
290
  /** @internal */
293
- export var SortDirection;
294
- (function (SortDirection) {
295
- SortDirection["ASC"] = "asc";
296
- SortDirection["DESC"] = "desc";
297
- })(SortDirection = SortDirection || (SortDirection = {}));
291
+ export var JaqlSortDirection;
292
+ (function (JaqlSortDirection) {
293
+ JaqlSortDirection["ASC"] = "asc";
294
+ JaqlSortDirection["DESC"] = "desc";
295
+ })(JaqlSortDirection = JaqlSortDirection || (JaqlSortDirection = {}));
package/dist/index.d.ts CHANGED
@@ -54,8 +54,6 @@ export * from './dimensional-model/measures/measures.js';
54
54
  * Functions to create measures that aggregate, summarize, and accumulate data,
55
55
  * plus show changes in data over time.
56
56
  *
57
- * They are similar to [Formulas](https://docs.sisense.com/main/SisenseLinux/build-formulas.htm) in Sisense.
58
- *
59
57
  * Measures created with these functions can be used in the data options of UI components such as
60
58
  * {@link @sisense/sdk-ui!ChartProps | Chart}, {@link @sisense/sdk-ui!ChartWidgetProps | ChartWidget},
61
59
  * and {@link @sisense/sdk-ui!ExecuteQueryProps | ExecuteQuery}.
package/dist/index.js CHANGED
@@ -54,8 +54,6 @@ export * from './dimensional-model/measures/measures.js';
54
54
  * Functions to create measures that aggregate, summarize, and accumulate data,
55
55
  * plus show changes in data over time.
56
56
  *
57
- * They are similar to [Formulas](https://docs.sisense.com/main/SisenseLinux/build-formulas.htm) in Sisense.
58
- *
59
57
  * Measures created with these functions can be used in the data options of UI components such as
60
58
  * {@link @sisense/sdk-ui!ChartProps | Chart}, {@link @sisense/sdk-ui!ChartWidgetProps | ChartWidget},
61
59
  * and {@link @sisense/sdk-ui!ExecuteQueryProps | ExecuteQuery}.
package/dist/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Filter, FilterRelations, FilterRelationsJaql, DataSource, DataSourceInfo } from './index.js';
1
+ import { Filter, FilterRelations, FilterRelationsJaql, DataSource, DataSourceInfo, FilterJaql } from './index.js';
2
2
  /**
3
3
  * A more performant, but slightly bulkier, RFC4122v4 implementation. Performance is improved by minimizing calls to random()
4
4
  *
@@ -16,11 +16,22 @@ export declare const getFilterListAndRelations: (filterRelations: FilterRelation
16
16
  };
17
17
  /**
18
18
  * Gets the name of the data source
19
+ *
19
20
  * @internal
20
21
  */
21
22
  export declare function getDataSourceName(dataSource: DataSource): string;
22
23
  /**
23
24
  * Checks if the provided 'dataSource' is a data source info structure that contains more than just the data source name.
25
+ *
24
26
  * @internal
25
27
  */
26
28
  export declare function isDataSourceInfo(dataSource: DataSource): dataSource is DataSourceInfo;
29
+ /**
30
+ * Creates a filter from a JAQL object.
31
+ *
32
+ * @param jaql - The filter JAQL object.
33
+ * @param instanceid - The instance ID.
34
+ * @returns - The created Filter object.
35
+ * @internal
36
+ */
37
+ export declare const createFilterFromJaql: (jaql: FilterJaql, instanceid?: string) => Filter;
package/dist/utils.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import cloneDeep from 'lodash/cloneDeep.js';
2
+ import { createFilterFromJaqlInternal } from './dimensional-model/filters/utils/filter-from-jaql-util.js';
2
3
  /**
3
4
  * A more performant, but slightly bulkier, RFC4122v4 implementation. Performance is improved by minimizing calls to random()
4
5
  *
@@ -63,6 +64,7 @@ export const getFilterListAndRelations = (filterRelations) => {
63
64
  };
64
65
  /**
65
66
  * Gets the name of the data source
67
+ *
66
68
  * @internal
67
69
  */
68
70
  export function getDataSourceName(dataSource) {
@@ -70,8 +72,23 @@ export function getDataSourceName(dataSource) {
70
72
  }
71
73
  /**
72
74
  * Checks if the provided 'dataSource' is a data source info structure that contains more than just the data source name.
75
+ *
73
76
  * @internal
74
77
  */
75
78
  export function isDataSourceInfo(dataSource) {
76
79
  return typeof dataSource === 'object' && 'type' in dataSource && 'title' in dataSource;
77
80
  }
81
+ /**
82
+ * Creates a filter from a JAQL object.
83
+ *
84
+ * @param jaql - The filter JAQL object.
85
+ * @param instanceid - The instance ID.
86
+ * @returns - The created Filter object.
87
+ * @internal
88
+ */
89
+ export const createFilterFromJaql = (jaql, instanceid) => {
90
+ // translation logic is based on FilterJaqlInternal type (from internal modern-analytics-filters)
91
+ // TODO reconcile FilterJaql and FilterJaqlInternal
92
+ const jaqlInternal = jaql;
93
+ return createFilterFromJaqlInternal(jaqlInternal, instanceid);
94
+ };
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "Sisense",
12
12
  "Compose SDK"
13
13
  ],
14
- "version": "1.7.2",
14
+ "version": "1.9.0",
15
15
  "type": "module",
16
16
  "exports": {
17
17
  ".": "./dist/index.js",
@@ -23,8 +23,8 @@
23
23
  "author": "Sisense ",
24
24
  "license": "SEE LICENSE IN LICENSE.md",
25
25
  "dependencies": {
26
- "@sisense/sdk-common": "^1.7.2",
27
- "@sisense/sdk-rest-client": "^1.7.2",
26
+ "@sisense/sdk-common": "^1.9.0",
27
+ "@sisense/sdk-rest-client": "^1.9.0",
28
28
  "guid-typescript": "^1.0.9",
29
29
  "lodash": "^4.17.21",
30
30
  "numeral": "^2.0.6",