@sisense/sdk-query-client 1.7.2 → 1.8.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.
|
@@ -4,6 +4,7 @@ import { v4 as uuid } from 'uuid';
|
|
|
4
4
|
import merge from 'ts-deepmerge';
|
|
5
5
|
import { isPivotAttribute, isPivotMeasure, DEFAULT_PIVOT_GRAND_TOTALS, isDataSourceInfo, } from '@sisense/sdk-data';
|
|
6
6
|
import { applyHighlightFilters, matchHighlightsWithAttributes } from './metadata/highlights.js';
|
|
7
|
+
import { getPivotMetadataStats, normalizeLastRowSorting, preparePivotRowJaqlSortOptions, } from './pivot/pivot-query-utils.js';
|
|
7
8
|
const JAQL_BY_CSDK = 'ComposeSDK';
|
|
8
9
|
/**
|
|
9
10
|
* @internal
|
|
@@ -62,8 +63,12 @@ export function getPivotJaqlQueryPayload(pivotQueryDescription, shouldSkipHighli
|
|
|
62
63
|
}
|
|
63
64
|
return queryPayload;
|
|
64
65
|
}
|
|
65
|
-
function jaqlPivotAttribute(a, panel, index) {
|
|
66
|
-
|
|
66
|
+
function jaqlPivotAttribute(a, panel, index, metadataStats) {
|
|
67
|
+
const jaql = Object.assign(Object.assign({}, (isPivotAttribute(a) ? a.attribute.jaql(true) : a.jaql(true))), (panel === 'rows' &&
|
|
68
|
+
isPivotAttribute(a) &&
|
|
69
|
+
a.sort &&
|
|
70
|
+
preparePivotRowJaqlSortOptions(a.sort, index, metadataStats)));
|
|
71
|
+
return Object.assign(Object.assign({ jaql }, (isPivotAttribute(a) && a.includeSubTotals ? { format: { subtotal: true } } : {})), { panel, field: { index: index, id: `${panel}-${index}` } });
|
|
67
72
|
}
|
|
68
73
|
function jaqlPivotMeasure(m, panel, index) {
|
|
69
74
|
return Object.assign(Object.assign({}, (isPivotMeasure(m)
|
|
@@ -82,10 +87,11 @@ function jaqlPivotMeasure(m, panel, index) {
|
|
|
82
87
|
*/
|
|
83
88
|
function preparePivotQueryMetadata(pivotMetadataDescription, shouldSkipHighlightsWithoutAttributes) {
|
|
84
89
|
const { rowsAttributes, columnsAttributes, measures, filters, filterRelations, highlights } = pivotMetadataDescription;
|
|
90
|
+
const metadataStats = getPivotMetadataStats(rowsAttributes, columnsAttributes, measures);
|
|
85
91
|
let fieldIndex = 0; // used as a global counter to build field.index in Jaql MetadataItem
|
|
86
|
-
const rowsAttributesMetadata = rowsAttributes.map((a, index) => jaqlPivotAttribute(a, 'rows', index + fieldIndex));
|
|
92
|
+
const rowsAttributesMetadata = rowsAttributes.map((a, index) => jaqlPivotAttribute(a, 'rows', index + fieldIndex, metadataStats));
|
|
87
93
|
fieldIndex = fieldIndex + rowsAttributes.length;
|
|
88
|
-
const columnsAttributesMetadata = columnsAttributes.map((a, index) => jaqlPivotAttribute(a, 'columns', index + fieldIndex));
|
|
94
|
+
const columnsAttributesMetadata = columnsAttributes.map((a, index) => jaqlPivotAttribute(a, 'columns', index + fieldIndex, metadataStats));
|
|
89
95
|
fieldIndex = fieldIndex + columnsAttributes.length;
|
|
90
96
|
const attributesMetadata = [
|
|
91
97
|
...rowsAttributesMetadata,
|
|
@@ -93,7 +99,9 @@ function preparePivotQueryMetadata(pivotMetadataDescription, shouldSkipHighlight
|
|
|
93
99
|
];
|
|
94
100
|
const measuresMetadata = measures.map((m, index) => jaqlPivotMeasure(m, 'measures', index + fieldIndex));
|
|
95
101
|
const filtersMetadata = prepareFilterMetadata(attributesMetadata, filters, filterRelations, highlights, shouldSkipHighlightsWithoutAttributes);
|
|
96
|
-
|
|
102
|
+
const metadata = [...attributesMetadata, ...measuresMetadata, ...filtersMetadata];
|
|
103
|
+
normalizeLastRowSorting(metadata, metadataStats);
|
|
104
|
+
return metadata;
|
|
97
105
|
}
|
|
98
106
|
/**
|
|
99
107
|
* Prepares the options part of the JAQL payload for a pivot query.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Attribute, Measure, PivotAttribute, PivotMeasure, PivotRowsSort, SortDirection } from '@sisense/sdk-data';
|
|
2
|
+
import { MetadataItem } from '../../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Represents statistics about a pivot table metadata.
|
|
5
|
+
*/
|
|
6
|
+
export type PivotMetadataStats = {
|
|
7
|
+
rowsCount: number;
|
|
8
|
+
columnsCount: number;
|
|
9
|
+
measuresCount: number;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Calculates statistics about the pivot table metadata.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getPivotMetadataStats(rowsAttributes: (Attribute | PivotAttribute)[], columnsAttributes: (Attribute | PivotAttribute)[], measures: (Measure | PivotMeasure)[]): PivotMetadataStats;
|
|
15
|
+
/**
|
|
16
|
+
* Converts sort direction to JAQL sort direction.
|
|
17
|
+
*/
|
|
18
|
+
export declare function convertSortDirectionToJaqlSort(direction: SortDirection): "asc" | "desc" | "none";
|
|
19
|
+
/**
|
|
20
|
+
* Prepares JAQL sort options for pivot table row.
|
|
21
|
+
*/
|
|
22
|
+
export declare function preparePivotRowJaqlSortOptions(sort: PivotRowsSort, rowIndex: number, metadataStats: PivotMetadataStats): {
|
|
23
|
+
sort: string;
|
|
24
|
+
sortDetails: {
|
|
25
|
+
dir: string;
|
|
26
|
+
field?: number | undefined;
|
|
27
|
+
measurePath?: Record<number, string | number> | undefined;
|
|
28
|
+
sortingLastDimension?: boolean | undefined;
|
|
29
|
+
initialized?: boolean | undefined;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Normalizes sorting for the last row of the pivot table.
|
|
34
|
+
*
|
|
35
|
+
* According to the existing pivot JAQL structure,the sorting configuration of the last row
|
|
36
|
+
* should be located inside the target measure metadata
|
|
37
|
+
*/
|
|
38
|
+
export declare function normalizeLastRowSorting(metadata: MetadataItem[], metadataStats: PivotMetadataStats): void;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Calculates statistics about the pivot table metadata.
|
|
14
|
+
*/
|
|
15
|
+
export function getPivotMetadataStats(rowsAttributes, columnsAttributes, measures) {
|
|
16
|
+
return {
|
|
17
|
+
rowsCount: rowsAttributes.length,
|
|
18
|
+
columnsCount: columnsAttributes.length,
|
|
19
|
+
measuresCount: measures.length,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Converts sort direction to JAQL sort direction.
|
|
24
|
+
*/
|
|
25
|
+
export function convertSortDirectionToJaqlSort(direction) {
|
|
26
|
+
switch (direction) {
|
|
27
|
+
case 'sortAsc':
|
|
28
|
+
return 'asc';
|
|
29
|
+
case 'sortDesc':
|
|
30
|
+
return 'desc';
|
|
31
|
+
default:
|
|
32
|
+
return 'none';
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Prepares JAQL sort options for pivot table row.
|
|
37
|
+
*/
|
|
38
|
+
export function preparePivotRowJaqlSortOptions(sort, rowIndex, metadataStats) {
|
|
39
|
+
const sortDirection = convertSortDirectionToJaqlSort(sort.direction);
|
|
40
|
+
const isLastRow = rowIndex === metadataStats.rowsCount - 1;
|
|
41
|
+
const sortDetails = {
|
|
42
|
+
dir: sortDirection,
|
|
43
|
+
initialized: true,
|
|
44
|
+
field: sort.by && 'valuesIndex' in sort.by
|
|
45
|
+
? metadataStats.rowsCount + metadataStats.columnsCount + sort.by.valuesIndex
|
|
46
|
+
: rowIndex,
|
|
47
|
+
};
|
|
48
|
+
if (isLastRow) {
|
|
49
|
+
sortDetails.sortingLastDimension = true;
|
|
50
|
+
}
|
|
51
|
+
if (sort.by) {
|
|
52
|
+
sortDetails.measurePath = (sort.by.columnsMembersPath || []).reduce((path, columnMember, columnIndex) => (Object.assign(Object.assign({}, path), { [metadataStats.rowsCount + columnIndex]: columnMember })), {});
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
sort: sortDirection,
|
|
56
|
+
sortDetails,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Normalizes sorting for the last row of the pivot table.
|
|
61
|
+
*
|
|
62
|
+
* According to the existing pivot JAQL structure,the sorting configuration of the last row
|
|
63
|
+
* should be located inside the target measure metadata
|
|
64
|
+
*/
|
|
65
|
+
export function normalizeLastRowSorting(metadata, metadataStats) {
|
|
66
|
+
const lastRowMetadata = metadata[metadataStats.rowsCount - 1];
|
|
67
|
+
const isSortedByMeasure = lastRowMetadata.jaql.sortDetails &&
|
|
68
|
+
lastRowMetadata.jaql.sortDetails.field !== metadataStats.rowsCount - 1;
|
|
69
|
+
if (isSortedByMeasure) {
|
|
70
|
+
const targetMeasureMetadata = metadata[lastRowMetadata.jaql.sortDetails.field];
|
|
71
|
+
const _a = lastRowMetadata.jaql, { sortDetails, sort } = _a, jaqlWithoutSortOptions = __rest(_a, ["sortDetails", "sort"]);
|
|
72
|
+
targetMeasureMetadata.jaql.sortDetails = sortDetails;
|
|
73
|
+
targetMeasureMetadata.jaql.sort = sort;
|
|
74
|
+
lastRowMetadata.jaql = jaqlWithoutSortOptions;
|
|
75
|
+
}
|
|
76
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -72,6 +72,42 @@ export type ExecutingPivotQueryResult = {
|
|
|
72
72
|
resultPromise: Promise<PivotQueryResultData>;
|
|
73
73
|
cancel: (reason?: string) => Promise<void>;
|
|
74
74
|
};
|
|
75
|
+
interface DecimalAbbreviations {
|
|
76
|
+
k: boolean;
|
|
77
|
+
m: boolean;
|
|
78
|
+
b: boolean;
|
|
79
|
+
t: boolean;
|
|
80
|
+
}
|
|
81
|
+
export declare enum CurrencyPosition {
|
|
82
|
+
PRE = "pre",
|
|
83
|
+
POST = "post"
|
|
84
|
+
}
|
|
85
|
+
export type NumericMask = {
|
|
86
|
+
isdefault?: boolean;
|
|
87
|
+
abbreviations?: DecimalAbbreviations;
|
|
88
|
+
decimals?: 'auto' | number | string;
|
|
89
|
+
currency?: {
|
|
90
|
+
symbol: string;
|
|
91
|
+
position: CurrencyPosition;
|
|
92
|
+
};
|
|
93
|
+
percent?: boolean;
|
|
94
|
+
number?: {
|
|
95
|
+
separated: boolean;
|
|
96
|
+
};
|
|
97
|
+
separated?: boolean;
|
|
98
|
+
type?: string;
|
|
99
|
+
};
|
|
100
|
+
export type DatetimeMask = {
|
|
101
|
+
isdefault?: boolean;
|
|
102
|
+
years: string;
|
|
103
|
+
quarters: string;
|
|
104
|
+
months: string;
|
|
105
|
+
weeks: string;
|
|
106
|
+
minutes: string;
|
|
107
|
+
days: string;
|
|
108
|
+
type: string;
|
|
109
|
+
dateAndTime?: string;
|
|
110
|
+
};
|
|
75
111
|
export type MetadataItem = {
|
|
76
112
|
instanceid?: string;
|
|
77
113
|
measure?: MetadataItemJaql;
|
|
@@ -79,9 +115,7 @@ export type MetadataItem = {
|
|
|
79
115
|
panel?: string;
|
|
80
116
|
isScope?: boolean;
|
|
81
117
|
format?: {
|
|
82
|
-
mask?:
|
|
83
|
-
[level: string]: string | undefined;
|
|
84
|
-
};
|
|
118
|
+
mask?: Partial<DatetimeMask> | Partial<NumericMask>;
|
|
85
119
|
number?: string;
|
|
86
120
|
subtotal?: boolean;
|
|
87
121
|
width?: number;
|
|
@@ -124,11 +158,19 @@ export type MetadataItemJaql = {
|
|
|
124
158
|
};
|
|
125
159
|
};
|
|
126
160
|
title?: string;
|
|
161
|
+
type?: string;
|
|
127
162
|
formula?: string;
|
|
128
163
|
context?: {
|
|
129
164
|
[itemId: string]: MetadataItemJaql;
|
|
130
165
|
};
|
|
131
166
|
filter?: MetadataItem;
|
|
167
|
+
sortDetails?: {
|
|
168
|
+
dir: string;
|
|
169
|
+
field?: number;
|
|
170
|
+
measurePath?: Record<number, string | number>;
|
|
171
|
+
sortingLastDimension?: boolean;
|
|
172
|
+
initialized?: boolean;
|
|
173
|
+
};
|
|
132
174
|
};
|
|
133
175
|
export type JaqlQueryPayload = QueryOptions & {
|
|
134
176
|
filterRelations?: FilterRelationsJaql;
|
|
@@ -161,3 +203,4 @@ export type DataSourceSchema = {
|
|
|
161
203
|
} & AnyObject;
|
|
162
204
|
export type AbortRequestFunction = (reason?: string) => void;
|
|
163
205
|
export type QueryGuid = string;
|
|
206
|
+
export {};
|
package/dist/types.js
CHANGED
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"Sisense",
|
|
12
12
|
"Compose SDK"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.
|
|
14
|
+
"version": "1.8.0",
|
|
15
15
|
"type": "module",
|
|
16
16
|
"exports": "./dist/index.js",
|
|
17
17
|
"main": "./dist/index.js",
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
"author": "Sisense",
|
|
21
21
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@sisense/sdk-common": "^1.
|
|
24
|
-
"@sisense/sdk-data": "^1.
|
|
25
|
-
"@sisense/sdk-pivot-client": "^1.
|
|
26
|
-
"@sisense/sdk-rest-client": "^1.
|
|
23
|
+
"@sisense/sdk-common": "^1.8.0",
|
|
24
|
+
"@sisense/sdk-data": "^1.8.0",
|
|
25
|
+
"@sisense/sdk-pivot-client": "^1.8.0",
|
|
26
|
+
"@sisense/sdk-rest-client": "^1.8.0",
|
|
27
27
|
"@sisense/task-manager": "^0.1.0",
|
|
28
28
|
"numeral": "^2.0.6",
|
|
29
29
|
"ts-deepmerge": "6.0.2",
|