@sisense/sdk-data 1.27.1 → 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.
- package/dist/cjs/dimensional-model/attributes.d.ts +2 -2
- package/dist/cjs/dimensional-model/attributes.js +7 -7
- package/dist/cjs/dimensional-model/base.d.ts +7 -1
- package/dist/cjs/dimensional-model/base.js +2 -1
- package/dist/cjs/dimensional-model/filters/factory.d.ts +23 -0
- package/dist/cjs/dimensional-model/filters/factory.js +28 -1
- package/dist/cjs/dimensional-model/filters/filter-config-utils.d.ts +4 -0
- package/dist/cjs/dimensional-model/filters/filter-config-utils.js +5 -2
- package/dist/cjs/dimensional-model/filters/filter-relations.d.ts +187 -0
- package/dist/cjs/dimensional-model/filters/filter-relations.js +532 -0
- package/dist/cjs/dimensional-model/filters/filters.d.ts +3 -3
- package/dist/cjs/dimensional-model/filters/filters.js +7 -8
- package/dist/cjs/dimensional-model/filters/helpers.d.ts +112 -0
- package/dist/cjs/dimensional-model/filters/helpers.js +178 -0
- package/dist/cjs/dimensional-model/filters/index.d.ts +2 -0
- package/dist/cjs/dimensional-model/filters/index.js +18 -0
- package/dist/cjs/dimensional-model/filters/utils/attribute-measure-util.d.ts +1 -35
- package/dist/cjs/dimensional-model/filters/utils/attribute-measure-util.js +37 -101
- package/dist/cjs/dimensional-model/interfaces.d.ts +2 -0
- package/dist/cjs/dimensional-model/measures/factory.js +1 -32
- package/dist/cjs/dimensional-model/measures/measures.d.ts +3 -3
- package/dist/cjs/dimensional-model/measures/measures.js +10 -9
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/interfaces.d.ts +2 -2
- package/dist/cjs/utils.d.ts +74 -2
- package/dist/cjs/utils.js +138 -3
- package/dist/dimensional-model/attributes.d.ts +2 -2
- package/dist/dimensional-model/attributes.js +7 -7
- package/dist/dimensional-model/base.d.ts +7 -1
- package/dist/dimensional-model/base.js +2 -1
- package/dist/dimensional-model/filters/factory.d.ts +23 -0
- package/dist/dimensional-model/filters/factory.js +27 -1
- package/dist/dimensional-model/filters/filter-config-utils.d.ts +4 -0
- package/dist/dimensional-model/filters/filter-config-utils.js +5 -2
- package/dist/dimensional-model/filters/filter-relations.d.ts +187 -0
- package/dist/dimensional-model/filters/filter-relations.js +507 -0
- package/dist/dimensional-model/filters/filters.d.ts +3 -3
- package/dist/dimensional-model/filters/filters.js +7 -8
- package/dist/dimensional-model/filters/helpers.d.ts +112 -0
- package/dist/dimensional-model/filters/helpers.js +169 -0
- package/dist/dimensional-model/filters/index.d.ts +2 -0
- package/dist/dimensional-model/filters/index.js +2 -0
- package/dist/dimensional-model/filters/utils/attribute-measure-util.d.ts +1 -35
- package/dist/dimensional-model/filters/utils/attribute-measure-util.js +36 -74
- package/dist/dimensional-model/interfaces.d.ts +2 -0
- package/dist/dimensional-model/measures/factory.js +2 -30
- package/dist/dimensional-model/measures/measures.d.ts +3 -3
- package/dist/dimensional-model/measures/measures.js +10 -9
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/interfaces.d.ts +2 -2
- package/dist/tsconfig.prod.cjs.tsbuildinfo +1 -1
- package/dist/utils.d.ts +74 -2
- package/dist/utils.js +133 -2
- package/package.json +4 -3
- package/dist/cjs/dimensional-model/filter-relations.d.ts +0 -9
- package/dist/cjs/dimensional-model/filter-relations.js +0 -18
- package/dist/dimensional-model/filter-relations.d.ts +0 -9
- package/dist/dimensional-model/filter-relations.js +0 -14
package/dist/utils.d.ts
CHANGED
|
@@ -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/utils.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import cloneDeep from 'lodash-es/cloneDeep.js';
|
|
2
|
-
import
|
|
2
|
+
import mapValues from 'lodash-es/mapValues.js';
|
|
3
3
|
import { createFilterFromJaqlInternal } from './dimensional-model/filters/utils/filter-from-jaql-util.js';
|
|
4
|
-
import { JaqlSortDirection, Sort } from './dimensional-model/types.js';
|
|
4
|
+
import { DataType, JaqlSortDirection, MetadataTypes, Sort, } from './dimensional-model/types.js';
|
|
5
|
+
import { escapeSingleQuotes } from '@sisense/sdk-common';
|
|
6
|
+
import { DimensionalBaseMeasure, DimensionalCalculatedMeasure, } from './dimensional-model/measures/measures.js';
|
|
7
|
+
import { isCascadingFilter } from './dimensional-model/filters/filters.js';
|
|
8
|
+
import { DimensionalAttribute, DimensionalLevelAttribute, normalizeAttributeName, } from './dimensional-model/attributes.js';
|
|
9
|
+
import { isNumber } from './dimensional-model/simple-column-types.js';
|
|
5
10
|
/**
|
|
6
11
|
* A more performant, but slightly bulkier, RFC4122v4 implementation. Performance is improved by minimizing calls to random()
|
|
7
12
|
*
|
|
@@ -215,3 +220,129 @@ export function getSortType(jaqlSort) {
|
|
|
215
220
|
return 'sortNone';
|
|
216
221
|
}
|
|
217
222
|
}
|
|
223
|
+
const DATA_MODEL_MODULE_NAME = 'DM';
|
|
224
|
+
/**
|
|
225
|
+
* Creates an attribute or level attribute from the provided parameters
|
|
226
|
+
* @returns attribute or level attribute
|
|
227
|
+
*
|
|
228
|
+
* @internal
|
|
229
|
+
*/
|
|
230
|
+
export const createAttributeHelper = ({ dim, table, column, dataType, level, format, sort, title, dataSource, }) => {
|
|
231
|
+
// if table is undefined, extract it from dim
|
|
232
|
+
const dimTable = table !== null && table !== void 0 ? table : parseExpression(dim).table;
|
|
233
|
+
// if column is undefined, extract it from dim
|
|
234
|
+
const dimColumn = column !== null && column !== void 0 ? column : parseExpression(dim).column;
|
|
235
|
+
const sortEnum = convertSort(sort);
|
|
236
|
+
const isDataTypeDatetime = dataType === DataType.DATETIME;
|
|
237
|
+
if (isDataTypeDatetime) {
|
|
238
|
+
const dateLevel = DimensionalLevelAttribute.translateJaqlToGranularity({ level });
|
|
239
|
+
const composeCode = normalizeAttributeName(dimTable, dimColumn, level, DATA_MODEL_MODULE_NAME);
|
|
240
|
+
const levelAttribute = new DimensionalLevelAttribute(title !== null && title !== void 0 ? title : dimColumn, dim, dateLevel, format || DimensionalLevelAttribute.getDefaultFormatForGranularity(dateLevel), undefined, sortEnum, dataSource, composeCode);
|
|
241
|
+
return levelAttribute;
|
|
242
|
+
}
|
|
243
|
+
const attributeType = !dataType || isNumber(dataType) ? MetadataTypes.NumericAttribute : MetadataTypes.TextAttribute;
|
|
244
|
+
const composeCode = normalizeAttributeName(dimTable, dimColumn, undefined, DATA_MODEL_MODULE_NAME);
|
|
245
|
+
const attribute = new DimensionalAttribute(title !== null && title !== void 0 ? title : dimColumn, dim, attributeType, undefined, sortEnum, dataSource, composeCode);
|
|
246
|
+
return attribute;
|
|
247
|
+
};
|
|
248
|
+
/**
|
|
249
|
+
* Creates a measure from the provided parameters
|
|
250
|
+
*
|
|
251
|
+
* @returns measure
|
|
252
|
+
*
|
|
253
|
+
* @internal
|
|
254
|
+
*/
|
|
255
|
+
export const createMeasureHelper = ({ dim, table, column, dataType, agg, level, format, sort, title, dataSource, }) => {
|
|
256
|
+
const sortEnum = convertSort(sort);
|
|
257
|
+
const attribute = createAttributeHelper({
|
|
258
|
+
dim,
|
|
259
|
+
table,
|
|
260
|
+
column,
|
|
261
|
+
dataType,
|
|
262
|
+
level,
|
|
263
|
+
format,
|
|
264
|
+
sort,
|
|
265
|
+
title,
|
|
266
|
+
dataSource,
|
|
267
|
+
});
|
|
268
|
+
const tranformedAgg = DimensionalBaseMeasure.aggregationFromJAQL(agg);
|
|
269
|
+
const updatedTitle = title !== null && title !== void 0 ? title : `${tranformedAgg} ${column}`;
|
|
270
|
+
// currently, sort and format applied to attribute but not to measure
|
|
271
|
+
const composeCode = `measureFactory.${tranformedAgg}(${attribute.composeCode}, '${escapeSingleQuotes(updatedTitle)}')`;
|
|
272
|
+
const measure = new DimensionalBaseMeasure(updatedTitle, attribute, tranformedAgg, undefined, undefined, sortEnum, composeCode);
|
|
273
|
+
return measure;
|
|
274
|
+
};
|
|
275
|
+
const getContextComposeCode = (context) => {
|
|
276
|
+
return ('{' +
|
|
277
|
+
Object.entries(context).reduce((acc, [key, value]) => {
|
|
278
|
+
acc =
|
|
279
|
+
acc +
|
|
280
|
+
`'${key.slice(1, -1)}': ${value && 'composeCode' in value ? value.composeCode : JSON.stringify(value)},`;
|
|
281
|
+
return acc;
|
|
282
|
+
}, '') +
|
|
283
|
+
'}');
|
|
284
|
+
};
|
|
285
|
+
/**
|
|
286
|
+
* Creates a measure from the provided parameters
|
|
287
|
+
*
|
|
288
|
+
* @returns calculated measure
|
|
289
|
+
*
|
|
290
|
+
* @internal
|
|
291
|
+
*/
|
|
292
|
+
export const createCalculatedMeasureHelper = (jaql) => {
|
|
293
|
+
var _a;
|
|
294
|
+
const sortEnum = convertSort(jaql.sort);
|
|
295
|
+
const context = mapValues((_a = jaql.context) !== null && _a !== void 0 ? _a : {}, (jaqlContextValue) => {
|
|
296
|
+
if (typeof jaqlContextValue === 'string') {
|
|
297
|
+
return jaqlContextValue;
|
|
298
|
+
}
|
|
299
|
+
return jaqlContextValue && createDimensionalElementFromJaql(jaqlContextValue);
|
|
300
|
+
});
|
|
301
|
+
const composeCode = `measureFactory.customFormula('${escapeSingleQuotes(jaql.title)}', '${jaql.formula}', ${getContextComposeCode(context)})`;
|
|
302
|
+
return new DimensionalCalculatedMeasure(jaql.title, jaql.formula, context, undefined, undefined, sortEnum, composeCode);
|
|
303
|
+
};
|
|
304
|
+
/**
|
|
305
|
+
* Creates a dimensional element from a JAQL object.
|
|
306
|
+
* @param jaql - The JAQL object.
|
|
307
|
+
* @param datetimeFormat - The datetime format.
|
|
308
|
+
* @returns The created dimensional element.
|
|
309
|
+
*
|
|
310
|
+
* @internal
|
|
311
|
+
*/
|
|
312
|
+
export function createDimensionalElementFromJaql(jaql, datetimeFormat) {
|
|
313
|
+
const isFilterJaql = 'filter' in jaql;
|
|
314
|
+
if (isFilterJaql) {
|
|
315
|
+
return createFilterFromJaql(jaql);
|
|
316
|
+
}
|
|
317
|
+
const isFormulaJaql = 'formula' in jaql;
|
|
318
|
+
if (isFormulaJaql) {
|
|
319
|
+
return createCalculatedMeasureHelper(jaql);
|
|
320
|
+
}
|
|
321
|
+
const dataSource = 'datasource' in jaql ? jaql.datasource : undefined;
|
|
322
|
+
const hasAggregation = !!jaql.agg;
|
|
323
|
+
if (hasAggregation) {
|
|
324
|
+
return createMeasureHelper({
|
|
325
|
+
dim: jaql.dim,
|
|
326
|
+
table: jaql.table,
|
|
327
|
+
column: jaql.column,
|
|
328
|
+
dataType: jaql.datatype,
|
|
329
|
+
agg: jaql.agg || '',
|
|
330
|
+
level: jaql.level,
|
|
331
|
+
format: datetimeFormat,
|
|
332
|
+
sort: jaql.sort,
|
|
333
|
+
title: jaql.title,
|
|
334
|
+
dataSource,
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
return createAttributeHelper({
|
|
338
|
+
dim: jaql.dim,
|
|
339
|
+
table: jaql.table,
|
|
340
|
+
column: jaql.column,
|
|
341
|
+
dataType: jaql.datatype,
|
|
342
|
+
level: jaql.level,
|
|
343
|
+
format: datetimeFormat,
|
|
344
|
+
sort: jaql.sort,
|
|
345
|
+
title: jaql.title,
|
|
346
|
+
dataSource,
|
|
347
|
+
});
|
|
348
|
+
}
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"Sisense",
|
|
12
12
|
"Compose SDK"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.
|
|
14
|
+
"version": "1.29.0",
|
|
15
15
|
"type": "module",
|
|
16
16
|
"main": "./dist/cjs/index.js",
|
|
17
17
|
"module": "./dist/index.js",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"author": "Sisense",
|
|
28
28
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@sisense/sdk-common": "^1.
|
|
31
|
-
"@sisense/sdk-rest-client": "^1.
|
|
30
|
+
"@sisense/sdk-common": "^1.29.0",
|
|
31
|
+
"@sisense/sdk-rest-client": "^1.29.0",
|
|
32
32
|
"guid-typescript": "^1.0.9",
|
|
33
33
|
"hash-it": "^6.0.0",
|
|
34
34
|
"lodash-es": "^4.17.21",
|
|
@@ -55,6 +55,7 @@
|
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@babel/preset-env": "^7.20.2",
|
|
57
57
|
"@types/lodash": "^4.14.201",
|
|
58
|
+
"@types/lodash-es": "^4.17.12",
|
|
58
59
|
"@types/numeral": "2.0.2",
|
|
59
60
|
"eslint": "^8.40.0",
|
|
60
61
|
"prettier": "2.8.4",
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Filter, FilterRelations } from './interfaces.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;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isFilterRelations = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Type guard for checking if the provided filters are FilterRelations.
|
|
6
|
-
*
|
|
7
|
-
* @param filters - The filters to check.
|
|
8
|
-
* @returns `true` if the filters are FilterRelations, `false` otherwise.
|
|
9
|
-
* @group Filter Utilities
|
|
10
|
-
*/
|
|
11
|
-
function isFilterRelations(filters) {
|
|
12
|
-
return (!!filters &&
|
|
13
|
-
'operator' in filters &&
|
|
14
|
-
(filters.operator === 'AND' || filters.operator === 'OR') &&
|
|
15
|
-
!!filters.right &&
|
|
16
|
-
!!filters.left);
|
|
17
|
-
}
|
|
18
|
-
exports.isFilterRelations = isFilterRelations;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Filter, FilterRelations } from './interfaces.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;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type guard for checking if the provided filters are FilterRelations.
|
|
3
|
-
*
|
|
4
|
-
* @param filters - The filters to check.
|
|
5
|
-
* @returns `true` if the filters are FilterRelations, `false` otherwise.
|
|
6
|
-
* @group Filter Utilities
|
|
7
|
-
*/
|
|
8
|
-
export function isFilterRelations(filters) {
|
|
9
|
-
return (!!filters &&
|
|
10
|
-
'operator' in filters &&
|
|
11
|
-
(filters.operator === 'AND' || filters.operator === 'OR') &&
|
|
12
|
-
!!filters.right &&
|
|
13
|
-
!!filters.left);
|
|
14
|
-
}
|