@sisense/sdk-data 1.28.0 → 1.29.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 (52) hide show
  1. package/dist/cjs/dimensional-model/attributes.d.ts +2 -2
  2. package/dist/cjs/dimensional-model/attributes.js +7 -7
  3. package/dist/cjs/dimensional-model/base.d.ts +7 -1
  4. package/dist/cjs/dimensional-model/base.js +2 -1
  5. package/dist/cjs/dimensional-model/filters/filter-config-utils.d.ts +4 -0
  6. package/dist/cjs/dimensional-model/filters/filter-config-utils.js +5 -2
  7. package/dist/cjs/dimensional-model/filters/filter-relations.d.ts +187 -0
  8. package/dist/cjs/dimensional-model/filters/filter-relations.js +532 -0
  9. package/dist/cjs/dimensional-model/filters/helpers.d.ts +112 -0
  10. package/dist/cjs/dimensional-model/filters/helpers.js +178 -0
  11. package/dist/cjs/dimensional-model/filters/index.d.ts +2 -0
  12. package/dist/cjs/dimensional-model/filters/index.js +18 -0
  13. package/dist/cjs/dimensional-model/filters/utils/attribute-measure-util.d.ts +1 -35
  14. package/dist/cjs/dimensional-model/filters/utils/attribute-measure-util.js +37 -101
  15. package/dist/cjs/dimensional-model/interfaces.d.ts +2 -0
  16. package/dist/cjs/dimensional-model/measures/factory.js +1 -32
  17. package/dist/cjs/dimensional-model/measures/measures.d.ts +3 -3
  18. package/dist/cjs/dimensional-model/measures/measures.js +10 -9
  19. package/dist/cjs/index.d.ts +1 -1
  20. package/dist/cjs/index.js +1 -1
  21. package/dist/cjs/interfaces.d.ts +2 -2
  22. package/dist/cjs/utils.d.ts +74 -2
  23. package/dist/cjs/utils.js +138 -3
  24. package/dist/dimensional-model/attributes.d.ts +2 -2
  25. package/dist/dimensional-model/attributes.js +7 -7
  26. package/dist/dimensional-model/base.d.ts +7 -1
  27. package/dist/dimensional-model/base.js +2 -1
  28. package/dist/dimensional-model/filters/filter-config-utils.d.ts +4 -0
  29. package/dist/dimensional-model/filters/filter-config-utils.js +5 -2
  30. package/dist/dimensional-model/filters/filter-relations.d.ts +187 -0
  31. package/dist/dimensional-model/filters/filter-relations.js +507 -0
  32. package/dist/dimensional-model/filters/helpers.d.ts +112 -0
  33. package/dist/dimensional-model/filters/helpers.js +169 -0
  34. package/dist/dimensional-model/filters/index.d.ts +2 -0
  35. package/dist/dimensional-model/filters/index.js +2 -0
  36. package/dist/dimensional-model/filters/utils/attribute-measure-util.d.ts +1 -35
  37. package/dist/dimensional-model/filters/utils/attribute-measure-util.js +36 -74
  38. package/dist/dimensional-model/interfaces.d.ts +2 -0
  39. package/dist/dimensional-model/measures/factory.js +2 -30
  40. package/dist/dimensional-model/measures/measures.d.ts +3 -3
  41. package/dist/dimensional-model/measures/measures.js +10 -9
  42. package/dist/index.d.ts +1 -1
  43. package/dist/index.js +1 -1
  44. package/dist/interfaces.d.ts +2 -2
  45. package/dist/tsconfig.prod.cjs.tsbuildinfo +1 -1
  46. package/dist/utils.d.ts +74 -2
  47. package/dist/utils.js +133 -2
  48. package/package.json +4 -3
  49. package/dist/cjs/dimensional-model/filter-relations.d.ts +0 -9
  50. package/dist/cjs/dimensional-model/filter-relations.js +0 -18
  51. package/dist/dimensional-model/filter-relations.d.ts +0 -9
  52. package/dist/dimensional-model/filter-relations.js +0 -14
@@ -1,7 +1,7 @@
1
1
  import { JaqlDataSource } from './dimensional-model/filters/utils/types.js';
2
- import { Attribute, Filter, FilterRelations, FilterRelationsJaql, SortDirection } from './dimensional-model/interfaces.js';
2
+ import { Attribute, BaseMeasure, CalculatedMeasure, Filter, FilterRelations, FilterRelationsJaql, LevelAttribute, SortDirection } from './dimensional-model/interfaces.js';
3
3
  import { DataSource, DataSourceInfo } from './interfaces.js';
4
- import { FilterJaql, JaqlSortDirection, Sort } from './dimensional-model/types.js';
4
+ import { FilterJaql, FormulaJaql, Jaql, JaqlSortDirection, Sort } from './dimensional-model/types.js';
5
5
  /**
6
6
  * A more performant, but slightly bulkier, RFC4122v4 implementation. Performance is improved by minimizing calls to random()
7
7
  *
@@ -80,3 +80,75 @@ export declare function getColumnNameFromAttribute(attribute: Attribute): string
80
80
  * @internal
81
81
  */
82
82
  export declare function getSortType(jaqlSort: `${JaqlSortDirection}` | undefined): SortDirection;
83
+ /**
84
+ * Creates an attribute or level attribute from the provided parameters
85
+ * @returns attribute or level attribute
86
+ *
87
+ * @internal
88
+ */
89
+ export declare const createAttributeHelper: ({ dim, table, column, dataType, level, format, sort, title, dataSource, }: {
90
+ /** Dimension expression */
91
+ dim: string;
92
+ /** Table name */
93
+ table: string | undefined;
94
+ /** Column name */
95
+ column: string | undefined;
96
+ /** Data type */
97
+ dataType: string;
98
+ /** Date level */
99
+ level: string | undefined;
100
+ /** Format */
101
+ format: string | undefined;
102
+ /** Sort */
103
+ sort: string | undefined;
104
+ /** Attribute title */
105
+ title?: string | undefined;
106
+ /** Jaql data source */
107
+ dataSource?: JaqlDataSource | undefined;
108
+ }) => Attribute | LevelAttribute;
109
+ /**
110
+ * Creates a measure from the provided parameters
111
+ *
112
+ * @returns measure
113
+ *
114
+ * @internal
115
+ */
116
+ export declare const createMeasureHelper: ({ dim, table, column, dataType, agg, level, format, sort, title, dataSource, }: {
117
+ /** Dimension expression */
118
+ dim: string;
119
+ /** Table name */
120
+ table: string | undefined;
121
+ /** Column name */
122
+ column: string;
123
+ /** Data type */
124
+ dataType: string;
125
+ /** Aggregation function */
126
+ agg: string;
127
+ /** Date level */
128
+ level: string | undefined;
129
+ /** Format */
130
+ format: string | undefined;
131
+ /** Sort */
132
+ sort: string | undefined;
133
+ /** Measure title */
134
+ title?: string | undefined;
135
+ /** Jaql data source */
136
+ dataSource?: JaqlDataSource | undefined;
137
+ }) => BaseMeasure;
138
+ /**
139
+ * Creates a measure from the provided parameters
140
+ *
141
+ * @returns calculated measure
142
+ *
143
+ * @internal
144
+ */
145
+ export declare const createCalculatedMeasureHelper: (jaql: FormulaJaql) => CalculatedMeasure;
146
+ /**
147
+ * Creates a dimensional element from a JAQL object.
148
+ * @param jaql - The JAQL object.
149
+ * @param datetimeFormat - The datetime format.
150
+ * @returns The created dimensional element.
151
+ *
152
+ * @internal
153
+ */
154
+ export declare function createDimensionalElementFromJaql(jaql: Jaql, datetimeFormat?: string): Attribute | BaseMeasure | CalculatedMeasure | Filter;
package/dist/cjs/utils.js CHANGED
@@ -3,11 +3,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getSortType = exports.getColumnNameFromAttribute = exports.getTableNameFromAttribute = exports.createFilterFromJaql = exports.convertSort = exports.convertJaqlDataSource = exports.convertDataSource = exports.isDataSourceInfo = exports.getDataSourceName = exports.getFilterListAndRelationsJaql = exports.guidFast = void 0;
6
+ exports.createDimensionalElementFromJaql = exports.createCalculatedMeasureHelper = exports.createMeasureHelper = exports.createAttributeHelper = exports.getSortType = exports.getColumnNameFromAttribute = exports.getTableNameFromAttribute = exports.createFilterFromJaql = exports.convertSort = exports.convertJaqlDataSource = exports.convertDataSource = exports.isDataSourceInfo = exports.getDataSourceName = exports.getFilterListAndRelationsJaql = exports.guidFast = void 0;
7
7
  const cloneDeep_js_1 = __importDefault(require("lodash-es/cloneDeep.js"));
8
- const index_js_1 = require("./index.js");
8
+ const mapValues_js_1 = __importDefault(require("lodash-es/mapValues.js"));
9
9
  const filter_from_jaql_util_js_1 = require("./dimensional-model/filters/utils/filter-from-jaql-util.js");
10
10
  const types_js_1 = require("./dimensional-model/types.js");
11
+ const sdk_common_1 = require("@sisense/sdk-common");
12
+ const measures_js_1 = require("./dimensional-model/measures/measures.js");
13
+ const filters_js_1 = require("./dimensional-model/filters/filters.js");
14
+ const attributes_js_1 = require("./dimensional-model/attributes.js");
15
+ const simple_column_types_js_1 = require("./dimensional-model/simple-column-types.js");
11
16
  /**
12
17
  * A more performant, but slightly bulkier, RFC4122v4 implementation. Performance is improved by minimizing calls to random()
13
18
  *
@@ -63,7 +68,7 @@ const getFilterListAndRelationsJaql = (filterRelations) => {
63
68
  if (!node)
64
69
  return node;
65
70
  if (isFilter(node)) {
66
- if ((0, index_js_1.isCascadingFilter)(node)) {
71
+ if ((0, filters_js_1.isCascadingFilter)(node)) {
67
72
  return traverseCascade(node.filters);
68
73
  }
69
74
  filters.add(node);
@@ -232,3 +237,133 @@ function getSortType(jaqlSort) {
232
237
  }
233
238
  }
234
239
  exports.getSortType = getSortType;
240
+ const DATA_MODEL_MODULE_NAME = 'DM';
241
+ /**
242
+ * Creates an attribute or level attribute from the provided parameters
243
+ * @returns attribute or level attribute
244
+ *
245
+ * @internal
246
+ */
247
+ const createAttributeHelper = ({ dim, table, column, dataType, level, format, sort, title, dataSource, }) => {
248
+ // if table is undefined, extract it from dim
249
+ const dimTable = table !== null && table !== void 0 ? table : parseExpression(dim).table;
250
+ // if column is undefined, extract it from dim
251
+ const dimColumn = column !== null && column !== void 0 ? column : parseExpression(dim).column;
252
+ const sortEnum = convertSort(sort);
253
+ const isDataTypeDatetime = dataType === types_js_1.DataType.DATETIME;
254
+ if (isDataTypeDatetime) {
255
+ const dateLevel = attributes_js_1.DimensionalLevelAttribute.translateJaqlToGranularity({ level });
256
+ const composeCode = (0, attributes_js_1.normalizeAttributeName)(dimTable, dimColumn, level, DATA_MODEL_MODULE_NAME);
257
+ const levelAttribute = new attributes_js_1.DimensionalLevelAttribute(title !== null && title !== void 0 ? title : dimColumn, dim, dateLevel, format || attributes_js_1.DimensionalLevelAttribute.getDefaultFormatForGranularity(dateLevel), undefined, sortEnum, dataSource, composeCode);
258
+ return levelAttribute;
259
+ }
260
+ const attributeType = !dataType || (0, simple_column_types_js_1.isNumber)(dataType) ? types_js_1.MetadataTypes.NumericAttribute : types_js_1.MetadataTypes.TextAttribute;
261
+ const composeCode = (0, attributes_js_1.normalizeAttributeName)(dimTable, dimColumn, undefined, DATA_MODEL_MODULE_NAME);
262
+ const attribute = new attributes_js_1.DimensionalAttribute(title !== null && title !== void 0 ? title : dimColumn, dim, attributeType, undefined, sortEnum, dataSource, composeCode);
263
+ return attribute;
264
+ };
265
+ exports.createAttributeHelper = createAttributeHelper;
266
+ /**
267
+ * Creates a measure from the provided parameters
268
+ *
269
+ * @returns measure
270
+ *
271
+ * @internal
272
+ */
273
+ const createMeasureHelper = ({ dim, table, column, dataType, agg, level, format, sort, title, dataSource, }) => {
274
+ const sortEnum = convertSort(sort);
275
+ const attribute = (0, exports.createAttributeHelper)({
276
+ dim,
277
+ table,
278
+ column,
279
+ dataType,
280
+ level,
281
+ format,
282
+ sort,
283
+ title,
284
+ dataSource,
285
+ });
286
+ const tranformedAgg = measures_js_1.DimensionalBaseMeasure.aggregationFromJAQL(agg);
287
+ const updatedTitle = title !== null && title !== void 0 ? title : `${tranformedAgg} ${column}`;
288
+ // currently, sort and format applied to attribute but not to measure
289
+ const composeCode = `measureFactory.${tranformedAgg}(${attribute.composeCode}, '${(0, sdk_common_1.escapeSingleQuotes)(updatedTitle)}')`;
290
+ const measure = new measures_js_1.DimensionalBaseMeasure(updatedTitle, attribute, tranformedAgg, undefined, undefined, sortEnum, composeCode);
291
+ return measure;
292
+ };
293
+ exports.createMeasureHelper = createMeasureHelper;
294
+ const getContextComposeCode = (context) => {
295
+ return ('{' +
296
+ Object.entries(context).reduce((acc, [key, value]) => {
297
+ acc =
298
+ acc +
299
+ `'${key.slice(1, -1)}': ${value && 'composeCode' in value ? value.composeCode : JSON.stringify(value)},`;
300
+ return acc;
301
+ }, '') +
302
+ '}');
303
+ };
304
+ /**
305
+ * Creates a measure from the provided parameters
306
+ *
307
+ * @returns calculated measure
308
+ *
309
+ * @internal
310
+ */
311
+ const createCalculatedMeasureHelper = (jaql) => {
312
+ var _a;
313
+ const sortEnum = convertSort(jaql.sort);
314
+ const context = (0, mapValues_js_1.default)((_a = jaql.context) !== null && _a !== void 0 ? _a : {}, (jaqlContextValue) => {
315
+ if (typeof jaqlContextValue === 'string') {
316
+ return jaqlContextValue;
317
+ }
318
+ return jaqlContextValue && createDimensionalElementFromJaql(jaqlContextValue);
319
+ });
320
+ const composeCode = `measureFactory.customFormula('${(0, sdk_common_1.escapeSingleQuotes)(jaql.title)}', '${jaql.formula}', ${getContextComposeCode(context)})`;
321
+ return new measures_js_1.DimensionalCalculatedMeasure(jaql.title, jaql.formula, context, undefined, undefined, sortEnum, composeCode);
322
+ };
323
+ exports.createCalculatedMeasureHelper = createCalculatedMeasureHelper;
324
+ /**
325
+ * Creates a dimensional element from a JAQL object.
326
+ * @param jaql - The JAQL object.
327
+ * @param datetimeFormat - The datetime format.
328
+ * @returns The created dimensional element.
329
+ *
330
+ * @internal
331
+ */
332
+ function createDimensionalElementFromJaql(jaql, datetimeFormat) {
333
+ const isFilterJaql = 'filter' in jaql;
334
+ if (isFilterJaql) {
335
+ return (0, exports.createFilterFromJaql)(jaql);
336
+ }
337
+ const isFormulaJaql = 'formula' in jaql;
338
+ if (isFormulaJaql) {
339
+ return (0, exports.createCalculatedMeasureHelper)(jaql);
340
+ }
341
+ const dataSource = 'datasource' in jaql ? jaql.datasource : undefined;
342
+ const hasAggregation = !!jaql.agg;
343
+ if (hasAggregation) {
344
+ return (0, exports.createMeasureHelper)({
345
+ dim: jaql.dim,
346
+ table: jaql.table,
347
+ column: jaql.column,
348
+ dataType: jaql.datatype,
349
+ agg: jaql.agg || '',
350
+ level: jaql.level,
351
+ format: datetimeFormat,
352
+ sort: jaql.sort,
353
+ title: jaql.title,
354
+ dataSource,
355
+ });
356
+ }
357
+ return (0, exports.createAttributeHelper)({
358
+ dim: jaql.dim,
359
+ table: jaql.table,
360
+ column: jaql.column,
361
+ dataType: jaql.datatype,
362
+ level: jaql.level,
363
+ format: datetimeFormat,
364
+ sort: jaql.sort,
365
+ title: jaql.title,
366
+ dataSource,
367
+ });
368
+ }
369
+ exports.createDimensionalElementFromJaql = createDimensionalElementFromJaql;
@@ -11,7 +11,7 @@ export declare const jaqlSimpleColumnType: (datatype: string) => string;
11
11
  export declare class DimensionalAttribute extends DimensionalElement implements Attribute {
12
12
  readonly expression: string;
13
13
  protected _sort: Sort;
14
- constructor(name: string, expression: string, type?: string, desc?: string, sort?: Sort, dataSource?: JaqlDataSource);
14
+ constructor(name: string, expression: string, type?: string, desc?: string, sort?: Sort, dataSource?: JaqlDataSource, composeCode?: string);
15
15
  /**
16
16
  * gets the element's ID
17
17
  */
@@ -46,7 +46,7 @@ export declare class DimensionalAttribute extends DimensionalElement implements
46
46
  export declare class DimensionalLevelAttribute extends DimensionalAttribute implements LevelAttribute {
47
47
  private _format;
48
48
  readonly granularity: string;
49
- constructor(l: string, expression: string, granularity: string, format?: string, desc?: string, sort?: Sort, dataSource?: JaqlDataSource);
49
+ constructor(l: string, expression: string, granularity: string, format?: string, desc?: string, sort?: Sort, dataSource?: JaqlDataSource, composeCode?: string);
50
50
  /**
51
51
  * gets the element's ID
52
52
  */
@@ -9,8 +9,8 @@ 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) {
13
- super(name, type || MetadataTypes.Attribute, desc, dataSource);
12
+ constructor(name, expression, type, desc, sort, dataSource, composeCode) {
13
+ super(name, type || MetadataTypes.Attribute, desc, dataSource, composeCode);
14
14
  this._sort = Sort.None;
15
15
  this.expression = expression;
16
16
  this._sort = sort || Sort.None;
@@ -36,7 +36,7 @@ export class DimensionalAttribute extends DimensionalElement {
36
36
  * @returns An instance representing the sorted {@link Attribute} of this instance
37
37
  */
38
38
  sort(sort) {
39
- return new DimensionalAttribute(this.name, this.expression, this.type, this.description, sort, this.dataSource);
39
+ return new DimensionalAttribute(this.name, this.expression, this.type, this.description, sort, this.dataSource, this.composeCode);
40
40
  }
41
41
  /**
42
42
  * Gets the JAQL representation of this instance
@@ -72,8 +72,8 @@ export class DimensionalAttribute extends DimensionalElement {
72
72
  * @internal
73
73
  */
74
74
  export class DimensionalLevelAttribute extends DimensionalAttribute {
75
- constructor(l, expression, granularity, format, desc, sort, dataSource) {
76
- super(l, expression, MetadataTypes.DateLevel, desc, sort, dataSource);
75
+ constructor(l, expression, granularity, format, desc, sort, dataSource, composeCode) {
76
+ super(l, expression, MetadataTypes.DateLevel, desc, sort, dataSource, composeCode);
77
77
  this._format = format;
78
78
  this.granularity = granularity;
79
79
  }
@@ -104,7 +104,7 @@ export class DimensionalLevelAttribute extends DimensionalAttribute {
104
104
  * @returns An instance representing the sorted {@link LevelAttribute} of this instance
105
105
  */
106
106
  sort(sort) {
107
- return new DimensionalLevelAttribute(this.name, this.expression, this.granularity, this._format, this.description, sort, this.dataSource);
107
+ return new DimensionalLevelAttribute(this.name, this.expression, this.granularity, this._format, this.description, sort, this.dataSource, this.composeCode);
108
108
  }
109
109
  /**
110
110
  * The string formatting of this instance
@@ -121,7 +121,7 @@ export class DimensionalLevelAttribute extends DimensionalAttribute {
121
121
  * @returns An instance representing the formatted {@link LevelAttribute} of this instance
122
122
  */
123
123
  format(format) {
124
- return new DimensionalLevelAttribute(this.name, this.expression, this.granularity, format, this.description, this._sort, this.dataSource);
124
+ return new DimensionalLevelAttribute(this.name, this.expression, this.granularity, format, this.description, this._sort, this.dataSource, this.composeCode);
125
125
  }
126
126
  /**
127
127
  * Gets a serializable representation of the element
@@ -21,7 +21,7 @@ export declare abstract class DimensionalElement implements Element {
21
21
  * Defines the element's data source
22
22
  */
23
23
  get dataSource(): JaqlDataSource;
24
- constructor(name: string, type: string, desc?: string, dataSource?: JaqlDataSource);
24
+ constructor(name: string, type: string, desc?: string, dataSource?: JaqlDataSource, composeCode?: string);
25
25
  /**
26
26
  * gets the element's description
27
27
  */
@@ -34,6 +34,12 @@ export declare abstract class DimensionalElement implements Element {
34
34
  * gets the element's ID
35
35
  */
36
36
  abstract get id(): string;
37
+ /**
38
+ * Optional CSDK code to initialize this element
39
+ *
40
+ * @internal
41
+ */
42
+ composeCode?: string;
37
43
  /**
38
44
  * Gets a serializable representation of the element
39
45
  */
@@ -2,13 +2,14 @@
2
2
  * @internal
3
3
  */
4
4
  export class DimensionalElement {
5
- constructor(name, type, desc, dataSource) {
5
+ constructor(name, type, desc, dataSource, composeCode) {
6
6
  this._name = name;
7
7
  this.type = type;
8
8
  this.description = desc || '';
9
9
  if (dataSource) {
10
10
  this._dataSource = dataSource;
11
11
  }
12
+ this.composeCode = composeCode;
12
13
  }
13
14
  /**
14
15
  * Defines the element's name
@@ -1,16 +1,19 @@
1
1
  import { BaseFilterConfig, CompleteBaseFilterConfig, CompleteMembersFilterConfig, MembersFilterConfig } from '../interfaces.js';
2
2
  /**
3
3
  * Returns a default configuration for a base filter.
4
+ *
4
5
  * @internal
5
6
  */
6
7
  export declare const getDefaultBaseFilterConfig: () => CompleteBaseFilterConfig;
7
8
  /**
8
9
  * Returns a default configuration for a members filter.
10
+ *
9
11
  * @internal
10
12
  */
11
13
  export declare const getDefaultMembersFilterConfig: () => CompleteMembersFilterConfig;
12
14
  /**
13
15
  * Checks whether the given configuration is a members filter configuration.
16
+ *
14
17
  * @param config - The filter configuration.
15
18
  * @returns Whether the configuration is a members filter configuration.
16
19
  * @internal
@@ -18,6 +21,7 @@ export declare const getDefaultMembersFilterConfig: () => CompleteMembersFilterC
18
21
  export declare function isMembersFilterConfig(config: BaseFilterConfig | MembersFilterConfig): config is MembersFilterConfig;
19
22
  /**
20
23
  * Simplifies the filter configuration by removing default values.
24
+ *
21
25
  * @param config - The filter configuration.
22
26
  * @returns The simplified filter configuration.
23
27
  * @internal
@@ -2,6 +2,7 @@ import isEqual from 'lodash-es/isEqual.js';
2
2
  import { guidFast } from '../../utils.js';
3
3
  /**
4
4
  * Returns a default configuration for a base filter.
5
+ *
5
6
  * @internal
6
7
  */
7
8
  export const getDefaultBaseFilterConfig = () => ({
@@ -11,11 +12,13 @@ export const getDefaultBaseFilterConfig = () => ({
11
12
  });
12
13
  /**
13
14
  * Returns a default configuration for a members filter.
15
+ *
14
16
  * @internal
15
17
  */
16
18
  export const getDefaultMembersFilterConfig = () => (Object.assign(Object.assign({}, getDefaultBaseFilterConfig()), { excludeMembers: false, enableMultiSelection: true, deactivatedMembers: [] }));
17
19
  /**
18
20
  * Checks whether the given configuration is a members filter configuration.
21
+ *
19
22
  * @param config - The filter configuration.
20
23
  * @returns Whether the configuration is a members filter configuration.
21
24
  * @internal
@@ -25,6 +28,7 @@ export function isMembersFilterConfig(config) {
25
28
  }
26
29
  /**
27
30
  * Simplifies the filter configuration by removing default values.
31
+ *
28
32
  * @param config - The filter configuration.
29
33
  * @returns The simplified filter configuration.
30
34
  * @internal
@@ -34,6 +38,5 @@ export const simplifyFilterConfig = (config) => {
34
38
  ? getDefaultMembersFilterConfig()
35
39
  : getDefaultBaseFilterConfig();
36
40
  // Filter out properties that match their default values
37
- const simplifiedConfig = Object.fromEntries(Object.entries(config).filter(([key, value]) => !isEqual(value, defaultConfig[key])));
38
- return simplifiedConfig;
41
+ return Object.fromEntries(Object.entries(config).filter(([key, value]) => !isEqual(value, defaultConfig[key])));
39
42
  };
@@ -0,0 +1,187 @@
1
+ import { Filter, FilterRelations, FilterRelationsJaql, FilterRelationsModel, FilterRelationsModelNode } from '../../index.js';
2
+ /**
3
+ * Type guard for checking if the provided filters are FilterRelations.
4
+ *
5
+ * @param filters - The filters to check.
6
+ * @returns `true` if the filters are FilterRelations, `false` otherwise.
7
+ * @group Filter Utilities
8
+ */
9
+ export declare function isFilterRelations(filters: Filter[] | FilterRelations | undefined): filters is FilterRelations;
10
+ /**
11
+ * Rules of filter relations - logical operators of how filters are related to each other.
12
+ *
13
+ * @internal
14
+ *
15
+ */
16
+ export declare type FilterRelationsRules = FilterRelationsRule | FilterRelationsRuleNode | null;
17
+ /** @internal */
18
+ export declare type FilterRelationsRule = {
19
+ left: FilterRelationsRuleNode;
20
+ right: FilterRelationsRuleNode;
21
+ operator: 'AND' | 'OR';
22
+ };
23
+ /** @internal */
24
+ export declare type FilterRelationsRuleIdNode = {
25
+ instanceid: string;
26
+ };
27
+ /** @internal */
28
+ export declare type FilterRelationsRuleNode = FilterRelationsRule | FilterRelationsRuleIdNode;
29
+ /**
30
+ * Filter action types
31
+ *
32
+ * @internal
33
+ */
34
+ export declare type FilterAction = {
35
+ type: 'add';
36
+ payload: Filter;
37
+ } | {
38
+ type: 'remove';
39
+ payload: Filter;
40
+ };
41
+ /**
42
+ * Merges source filters with target filters and recalculates relations.
43
+ *
44
+ * @param sourceFilters - The source filters or filter relations to merge.
45
+ * @param targetFilters - The target filters or filter relations to merge with.
46
+ * @returns Updated source filters merged with target filters. If the source filters are FilterRelations, the relations are recalculated.
47
+ * @internal
48
+ */
49
+ export declare function mergeFiltersOrFilterRelations(sourceFilters?: Filter[] | FilterRelations, targetFilters?: Filter[] | FilterRelations): Filter[] | FilterRelations;
50
+ /**
51
+ * Splits filters or filter relations into filters and relations rules.
52
+ * @internal
53
+ */
54
+ export declare function splitFiltersAndRelations(filtersOrFilterRelations: Filter[] | FilterRelations | undefined): {
55
+ filters: Filter[];
56
+ relations: FilterRelationsRules;
57
+ };
58
+ /**
59
+ * Returns pure filters array from the given filters or filter relations.
60
+ * @internal
61
+ */
62
+ export declare function getFiltersArray(filtersOrFilterRelations: Filter[] | FilterRelations | undefined): Filter[];
63
+ /**
64
+ * Combines filters and relations into a single FilterRelations object.
65
+ * If the relations are empty or relations are trivial (single node), the filters are returned as is.
66
+ * @internal
67
+ */
68
+ export declare function combineFiltersAndRelations(filters: Filter[], relations: FilterRelationsRules): Filter[] | FilterRelations;
69
+ /** Type guard for checking if a node is a single relations node (trivial case when relations are needless).
70
+ * @internal
71
+ */
72
+ export declare function isTrivialSingleNodeRelations(relations: FilterRelationsRules): relations is FilterRelationsRuleIdNode;
73
+ /**
74
+ * Calculates new relations based on the changes in filters.
75
+ * @internal
76
+ */
77
+ export declare function calculateNewRelations(prevFilters: Filter[], prevRelations: FilterRelationsRules, newFilters: Filter[]): FilterRelationsRules;
78
+ /**
79
+ * Replaces a filter in the relations tree with a new filter.
80
+ * @internal
81
+ */
82
+ export declare function getRelationsWithReplacedFilter(relations: FilterRelationsRules, filterToReplace: Filter, newFilter: Filter): FilterRelationsRules;
83
+ /**
84
+ * Converts filter relations model from Fusion to internal CSDK filter relations rules.
85
+ * @internal
86
+ */
87
+ export declare function convertFilterRelationsModelToRelationRules(filterRelationsModel: FilterRelationsModel | FilterRelationsModelNode | undefined, filters: Filter[]): FilterRelationsRules;
88
+ /**
89
+ * @internal
90
+ */
91
+ export declare function isRelationsRuleIdNode(node: FilterRelationsRuleNode): node is FilterRelationsRuleIdNode;
92
+ /**
93
+ * @internal
94
+ */
95
+ export declare function isRelationsRule(node: FilterRelationsRuleNode): node is FilterRelationsRule;
96
+ /**
97
+ * Converts internal CSDK filter relations rules to filter relations model for Fusion.
98
+ * @internal
99
+ */
100
+ export declare function filterRelationRulesToFilterRelationsModel(filterRelationRules: FilterRelationsRules, filters: Filter[]): FilterRelationsModel | FilterRelationsModelNode | undefined;
101
+ /**
102
+ * @internal
103
+ */
104
+ export declare function findFilterByGuid(filters: Filter[], guid: string): Filter | undefined;
105
+ /**
106
+ * Error thrown when an unknown node type is encountered in filter relations.
107
+ * @internal
108
+ */
109
+ export declare class UnknownRelationsNodeError extends Error {
110
+ constructor();
111
+ }
112
+ /** @internal */
113
+ export declare type FilterRelationsDescription = FilterRelationsDescriptionNode[];
114
+ /** @internal */
115
+ export declare type FilterRelationsDescriptionNode = OpenBracketDescriptionNode | CloseBracketDescriptionNode | AttributeDescriptionNode | OperatorDescriptionNode;
116
+ /** @internal */
117
+ export declare type OpenBracketDescriptionNode = {
118
+ nodeType: 'openBracket';
119
+ };
120
+ /**
121
+ * @internal
122
+ */
123
+ export declare function isOpenBracketDescriptionNode(node: FilterRelationsDescriptionNode): node is OpenBracketDescriptionNode;
124
+ /** @internal */
125
+ export declare type CloseBracketDescriptionNode = {
126
+ nodeType: 'closeBracket';
127
+ };
128
+ /**
129
+ * @internal
130
+ */
131
+ export declare function isCloseBracketDescriptionNode(node: FilterRelationsDescriptionNode): node is CloseBracketDescriptionNode;
132
+ /** @internal */
133
+ export declare type AttributeDescriptionNode = {
134
+ nodeType: 'attribute';
135
+ attribute: string;
136
+ };
137
+ /**
138
+ * @internal
139
+ */
140
+ export declare function isAttributeDescriptionNode(node: FilterRelationsDescriptionNode): node is AttributeDescriptionNode;
141
+ /** @internal */
142
+ export declare type OperatorDescriptionNode = {
143
+ nodeType: 'operator';
144
+ operator: 'AND' | 'OR';
145
+ };
146
+ /**
147
+ * @internal
148
+ */
149
+ export declare function isOperatorDescriptionNode(node: FilterRelationsDescriptionNode): node is OperatorDescriptionNode;
150
+ /**
151
+ * Gets a unique identifier for a filter, combining its attribute expression and granularity if available.
152
+ *
153
+ * @param {Filter} filter - The filter object to generate the unique identifier for.
154
+ * @returns {string} - The unique identifier for the filter.
155
+ * @internal
156
+ */
157
+ export declare function getFilterCompareId(filter: Filter): string;
158
+ /**
159
+ * Merges two arrays of filter objects, prioritizing 'targetFilters' over 'sourceFilters',
160
+ * and removes duplicates based on filter compare id.
161
+ *
162
+ * Saves the 'sourceFilters' filters order, while adds new filters to the end of the array.
163
+ *
164
+ * @param {Filter[]} [sourceFilters=[]] - The source array of filter objects.
165
+ * @param {Filter[]} [targetFilters=[]] - The target array of filter objects.
166
+ * @returns {Filter[]} - The merged array of filter objects.
167
+ * @internal
168
+ */
169
+ export declare function mergeFilters(sourceFilters?: Filter[], targetFilters?: Filter[]): Filter[];
170
+ /**
171
+ * Replaces nodes of filter reations tree with fetched filters by instance id.
172
+ *
173
+ * @param filters - The filters.
174
+ * @param highlights - The highlights
175
+ * @param filterRelations - Fetched filter relations.
176
+ * @returns Filter relations with filters in nodes.
177
+ * @internal
178
+ */
179
+ export declare function getFilterRelationsFromJaql(filters: Filter[], highlights: Filter[], filterRelations: FilterRelationsJaql | undefined): FilterRelations | Filter[];
180
+ /**
181
+ * Converts filter relations model to filter relations jaql.
182
+ *
183
+ * @param filterRelations - Filter relations model.
184
+ * @returns Filter relations jaql.
185
+ * @internal
186
+ */
187
+ export declare function convertFilterRelationsModelToJaql(filterRelations: FilterRelationsModel | FilterRelationsModelNode | undefined): FilterRelationsJaql | undefined;