@sisense/sdk-query-client 1.21.0 → 1.23.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/helpers/utility-types.d.ts +2 -0
- package/dist/cjs/helpers/utility-types.js +2 -0
- package/dist/cjs/index.d.ts +6 -0
- package/dist/cjs/index.js +26 -0
- package/dist/cjs/interfaces.d.ts +10 -0
- package/dist/cjs/interfaces.js +2 -0
- package/dist/cjs/jaql/get-jaql-query-payload.d.ts +15 -0
- package/dist/cjs/jaql/get-jaql-query-payload.js +133 -0
- package/dist/cjs/jaql/metadata/highlights.d.ts +4 -0
- package/dist/cjs/jaql/metadata/highlights.js +43 -0
- package/dist/cjs/jaql/metadata/index.d.ts +1 -0
- package/dist/cjs/jaql/metadata/index.js +17 -0
- package/dist/cjs/jaql/pivot/pivot-query-utils.d.ts +37 -0
- package/dist/cjs/jaql/pivot/pivot-query-utils.js +83 -0
- package/dist/cjs/package.json +12 -0
- package/dist/cjs/query-api-dispatcher/query-api-dispatcher.d.ts +39 -0
- package/dist/cjs/query-api-dispatcher/query-api-dispatcher.js +148 -0
- package/dist/cjs/query-client.d.ts +56 -0
- package/dist/cjs/query-client.js +203 -0
- package/dist/cjs/query-result/get-data-from-query-result.d.ts +12 -0
- package/dist/cjs/query-result/get-data-from-query-result.js +77 -0
- package/dist/cjs/query-result/index.d.ts +1 -0
- package/dist/cjs/query-result/index.js +17 -0
- package/dist/cjs/query-task-manager/query-task-manager.d.ts +40 -0
- package/dist/cjs/query-task-manager/query-task-manager.js +133 -0
- package/dist/cjs/query-task-manager/query-task-passport.d.ts +16 -0
- package/dist/cjs/query-task-manager/query-task-passport.js +22 -0
- package/dist/cjs/translation/initialize-i18n.d.ts +2 -0
- package/dist/cjs/translation/initialize-i18n.js +14 -0
- package/dist/cjs/translation/resources/en.d.ts +30 -0
- package/dist/cjs/translation/resources/en.js +18 -0
- package/dist/cjs/translation/resources/index.d.ts +41 -0
- package/dist/cjs/translation/resources/index.js +16 -0
- package/dist/cjs/translation/resources/uk.d.ts +2 -0
- package/dist/cjs/translation/resources/uk.js +18 -0
- package/dist/cjs/translation/translatable-error.d.ts +6 -0
- package/dist/cjs/translation/translatable-error.js +18 -0
- package/dist/cjs/types.d.ts +88 -0
- package/dist/cjs/types.js +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/interfaces.d.ts +2 -2
- package/dist/jaql/metadata/highlights.d.ts +1 -2
- package/dist/jaql/pivot/pivot-query-utils.d.ts +1 -2
- package/dist/query-api-dispatcher/query-api-dispatcher.d.ts +2 -2
- package/dist/query-api-dispatcher/query-api-dispatcher.js +5 -2
- package/dist/query-client.d.ts +3 -3
- package/dist/query-client.js +1 -1
- package/dist/query-task-manager/query-task-manager.js +2 -1
- package/dist/translation/resources/en.d.ts +16 -0
- package/dist/translation/resources/en.js +2 -0
- package/dist/translation/resources/index.d.ts +10 -0
- package/dist/translation/resources/index.js +6 -0
- package/dist/translation/resources/uk.js +11 -9
- package/dist/tsconfig.prod.cjs.tsbuildinfo +1 -0
- package/dist/types.d.ts +1 -122
- package/dist/types.js +1 -5
- package/package.json +6 -6
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import './translation/initialize-i18n.js';
|
|
2
|
+
export { DimensionalQueryClient } from './query-client.js';
|
|
3
|
+
export { getJaqlQueryPayload } from './jaql/get-jaql-query-payload.js';
|
|
4
|
+
export * from './types.js';
|
|
5
|
+
export * from './interfaces.js';
|
|
6
|
+
export { type TranslationDictionary, PACKAGE_NAMESPACE as translationNamespace, } from './translation/resources/index.js';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.translationNamespace = exports.getJaqlQueryPayload = exports.DimensionalQueryClient = void 0;
|
|
18
|
+
require("./translation/initialize-i18n.js");
|
|
19
|
+
var query_client_js_1 = require("./query-client.js");
|
|
20
|
+
Object.defineProperty(exports, "DimensionalQueryClient", { enumerable: true, get: function () { return query_client_js_1.DimensionalQueryClient; } });
|
|
21
|
+
var get_jaql_query_payload_js_1 = require("./jaql/get-jaql-query-payload.js");
|
|
22
|
+
Object.defineProperty(exports, "getJaqlQueryPayload", { enumerable: true, get: function () { return get_jaql_query_payload_js_1.getJaqlQueryPayload; } });
|
|
23
|
+
__exportStar(require("./types.js"), exports);
|
|
24
|
+
__exportStar(require("./interfaces.js"), exports);
|
|
25
|
+
var index_js_1 = require("./translation/resources/index.js");
|
|
26
|
+
Object.defineProperty(exports, "translationNamespace", { enumerable: true, get: function () { return index_js_1.PACKAGE_NAMESPACE; } });
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ExecutingCsvQueryResult, ExecutingPivotQueryResult, ExecutingQueryResult, PivotQueryDescription, QueryDescription, QueryExecutionConfig } from './types.js';
|
|
2
|
+
import { DataSource, DataSourceField, DataSourceMetadata, DataSourceSchema } from '@sisense/sdk-data';
|
|
3
|
+
export interface QueryClient {
|
|
4
|
+
executeQuery(params: QueryDescription, config?: QueryExecutionConfig): ExecutingQueryResult;
|
|
5
|
+
executeCsvQuery(params: QueryDescription, config?: QueryExecutionConfig): ExecutingCsvQueryResult;
|
|
6
|
+
executePivotQuery(params: PivotQueryDescription, config?: QueryExecutionConfig): ExecutingPivotQueryResult;
|
|
7
|
+
getDataSourceFields(dataSource: DataSource): Promise<DataSourceField[]>;
|
|
8
|
+
getDataSourceSchema(datasourceName: string): Promise<DataSourceSchema | undefined>;
|
|
9
|
+
getDataSourceList(): Promise<DataSourceMetadata[]>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { JaqlQueryPayload, QueryDescription, PivotQueryDescription, QueryOptions } from '../types.js';
|
|
2
|
+
import { DataSource } from '@sisense/sdk-data';
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export declare function getJaqlQueryPayload(queryDescription: QueryDescription, shouldSkipHighlightsWithoutAttributes: boolean): JaqlQueryPayload;
|
|
7
|
+
export declare function prepareQueryOptions(dataSource: DataSource, count?: number, offset?: number, includeUngroup?: boolean): QueryOptions;
|
|
8
|
+
/**
|
|
9
|
+
* Converts a pivot query description to a JAQL query payload.
|
|
10
|
+
*
|
|
11
|
+
* @param pivotQueryDescription
|
|
12
|
+
* @param shouldSkipHighlightsWithoutAttributes
|
|
13
|
+
* @returns jaql query payload
|
|
14
|
+
*/
|
|
15
|
+
export declare function getPivotJaqlQueryPayload(pivotQueryDescription: PivotQueryDescription, shouldSkipHighlightsWithoutAttributes: boolean): JaqlQueryPayload;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getPivotJaqlQueryPayload = exports.prepareQueryOptions = exports.getJaqlQueryPayload = void 0;
|
|
7
|
+
const uuid_1 = require("uuid");
|
|
8
|
+
const ts_deepmerge_1 = __importDefault(require("ts-deepmerge"));
|
|
9
|
+
const sdk_data_1 = require("@sisense/sdk-data");
|
|
10
|
+
const highlights_js_1 = require("./metadata/highlights.js");
|
|
11
|
+
const pivot_query_utils_js_1 = require("./pivot/pivot-query-utils.js");
|
|
12
|
+
const JAQL_BY_CSDK = 'ComposeSDK';
|
|
13
|
+
/**
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
function getJaqlQueryPayload(queryDescription, shouldSkipHighlightsWithoutAttributes) {
|
|
17
|
+
const { attributes, measures, filters, filterRelations, highlights, dataSource, count, offset, ungroup, } = queryDescription;
|
|
18
|
+
// "ungroup: true" will be set in JAQL when two conditions are met:
|
|
19
|
+
// (1) ungroup is set to true
|
|
20
|
+
// AND
|
|
21
|
+
// (2) the query has no measures (unaggregated query)
|
|
22
|
+
const includeUngroup = ungroup && measures.length === 0;
|
|
23
|
+
const queryPayload = Object.assign({ metadata: prepareQueryMetadata({ attributes, measures, filters, filterRelations, highlights }, shouldSkipHighlightsWithoutAttributes) }, prepareQueryOptions(dataSource, count, offset, includeUngroup));
|
|
24
|
+
if (filterRelations) {
|
|
25
|
+
return Object.assign(Object.assign({}, queryPayload), { filterRelations });
|
|
26
|
+
}
|
|
27
|
+
return queryPayload;
|
|
28
|
+
}
|
|
29
|
+
exports.getJaqlQueryPayload = getJaqlQueryPayload;
|
|
30
|
+
function prepareFilterMetadata(attributesMetadata, filters, filterRelations, highlights, shouldSkipHighlightsWithoutAttributes) {
|
|
31
|
+
const [highlightsWithAttributes, highlightsWithoutAttributes] = (0, highlights_js_1.matchHighlightsWithAttributes)(attributesMetadata, highlights);
|
|
32
|
+
attributesMetadata.forEach((d) => (0, highlights_js_1.applyHighlightFilters)(d, highlightsWithAttributes));
|
|
33
|
+
const getFilterJaql = (f) => {
|
|
34
|
+
const jaql = f.jaql();
|
|
35
|
+
if (filterRelations) {
|
|
36
|
+
// instanceid is needed for filter relations only
|
|
37
|
+
if (Array.isArray(jaql)) {
|
|
38
|
+
return jaql.map((j) => (Object.assign(Object.assign({}, j), { instanceid: f.guid })));
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
return Object.assign(Object.assign({}, jaql), { instanceid: f.guid });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return jaql;
|
|
45
|
+
};
|
|
46
|
+
const filtersMetadata = (shouldSkipHighlightsWithoutAttributes
|
|
47
|
+
? filters.flatMap((d) => getFilterJaql(d))
|
|
48
|
+
: [...filters, ...highlightsWithoutAttributes].flatMap((d) => getFilterJaql(d))).filter((f) => {
|
|
49
|
+
return Object.keys(f.jaql.filter || {}).length !== 0;
|
|
50
|
+
});
|
|
51
|
+
if (shouldSkipHighlightsWithoutAttributes && highlightsWithoutAttributes.length > 0) {
|
|
52
|
+
console.warn(`The following highlight filters were not applied due to missing attributes: [${highlightsWithoutAttributes
|
|
53
|
+
.map((f) => f.attribute.name)
|
|
54
|
+
.join(', ')}].`);
|
|
55
|
+
}
|
|
56
|
+
return filtersMetadata;
|
|
57
|
+
}
|
|
58
|
+
function prepareQueryMetadata(metadataDescription, shouldSkipHighlightsWithoutAttributes) {
|
|
59
|
+
const { attributes, measures, filters, filterRelations, highlights } = metadataDescription;
|
|
60
|
+
const attributesMetadata = attributes.map((d) => d.jaql());
|
|
61
|
+
const measuresMetadata = measures.map((d) => d.jaql());
|
|
62
|
+
const filtersMetadata = prepareFilterMetadata(attributesMetadata, filters, filterRelations, highlights, shouldSkipHighlightsWithoutAttributes);
|
|
63
|
+
return [...attributesMetadata, ...measuresMetadata, ...filtersMetadata];
|
|
64
|
+
}
|
|
65
|
+
function prepareQueryOptions(dataSource, count, offset, includeUngroup) {
|
|
66
|
+
return Object.assign(Object.assign(Object.assign({ datasource: (0, sdk_data_1.convertJaqlDataSource)(dataSource), by: JAQL_BY_CSDK, queryGuid: (0, uuid_1.v4)() }, (includeUngroup ? { ungroup: true } : {})), (count ? { count } : {})), (offset ? { offset } : {}));
|
|
67
|
+
}
|
|
68
|
+
exports.prepareQueryOptions = prepareQueryOptions;
|
|
69
|
+
/**
|
|
70
|
+
* Converts a pivot query description to a JAQL query payload.
|
|
71
|
+
*
|
|
72
|
+
* @param pivotQueryDescription
|
|
73
|
+
* @param shouldSkipHighlightsWithoutAttributes
|
|
74
|
+
* @returns jaql query payload
|
|
75
|
+
*/
|
|
76
|
+
function getPivotJaqlQueryPayload(pivotQueryDescription, shouldSkipHighlightsWithoutAttributes) {
|
|
77
|
+
const { rowsAttributes, columnsAttributes, measures, filters, filterRelations, grandTotals, highlights, dataSource, count, offset, } = pivotQueryDescription;
|
|
78
|
+
const queryPayload = Object.assign({ metadata: preparePivotQueryMetadata({ rowsAttributes, columnsAttributes, measures, filters, highlights }, shouldSkipHighlightsWithoutAttributes) }, preparePivotQueryOptions(dataSource, grandTotals, count, offset));
|
|
79
|
+
if (filterRelations) {
|
|
80
|
+
return Object.assign(Object.assign({}, queryPayload), { filterRelations });
|
|
81
|
+
}
|
|
82
|
+
return queryPayload;
|
|
83
|
+
}
|
|
84
|
+
exports.getPivotJaqlQueryPayload = getPivotJaqlQueryPayload;
|
|
85
|
+
function jaqlPivotAttribute(a, panel, index, metadataStats) {
|
|
86
|
+
const isSortedRowAttribute = panel === 'rows' && (0, sdk_data_1.isPivotAttribute)(a) && a.sort && a.sort.direction !== 'sortNone';
|
|
87
|
+
const jaql = Object.assign(Object.assign({}, ((0, sdk_data_1.isPivotAttribute)(a) ? a.attribute.jaql(true) : a.jaql(true))), (isSortedRowAttribute && (0, pivot_query_utils_js_1.preparePivotRowJaqlSortOptions)(a.sort, index, metadataStats)));
|
|
88
|
+
return Object.assign(Object.assign({ jaql }, ((0, sdk_data_1.isPivotAttribute)(a) && a.includeSubTotals ? { format: { subtotal: true } } : {})), { panel, field: { index: index, id: `${panel}-${index}` } });
|
|
89
|
+
}
|
|
90
|
+
function jaqlPivotMeasure(m, panel, index) {
|
|
91
|
+
return Object.assign(Object.assign({}, ((0, sdk_data_1.isPivotMeasure)(m)
|
|
92
|
+
? (0, ts_deepmerge_1.default)(m.measure.jaql(), {
|
|
93
|
+
jaql: { subtotalAgg: m.totalsCalculation },
|
|
94
|
+
format: { databars: m.dataBars || false },
|
|
95
|
+
})
|
|
96
|
+
: m.jaql())), { panel, field: { index: index, id: `${panel}-${index}` } });
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Prepares the metadata part of the JAQL payload for a pivot query.
|
|
100
|
+
*
|
|
101
|
+
* @param pivotMetadataDescription
|
|
102
|
+
* @param shouldSkipHighlightsWithoutAttributes
|
|
103
|
+
* @returns array of metadata items of the JAQL payload
|
|
104
|
+
*/
|
|
105
|
+
function preparePivotQueryMetadata(pivotMetadataDescription, shouldSkipHighlightsWithoutAttributes) {
|
|
106
|
+
const { rowsAttributes, columnsAttributes, measures, filters, filterRelations, highlights } = pivotMetadataDescription;
|
|
107
|
+
const metadataStats = (0, pivot_query_utils_js_1.getPivotMetadataStats)(rowsAttributes, columnsAttributes, measures);
|
|
108
|
+
let fieldIndex = 0; // used as a global counter to build field.index in Jaql MetadataItem
|
|
109
|
+
const rowsAttributesMetadata = rowsAttributes.map((a, index) => jaqlPivotAttribute(a, 'rows', index + fieldIndex, metadataStats));
|
|
110
|
+
fieldIndex = fieldIndex + rowsAttributes.length;
|
|
111
|
+
const columnsAttributesMetadata = columnsAttributes.map((a, index) => jaqlPivotAttribute(a, 'columns', index + fieldIndex, metadataStats));
|
|
112
|
+
fieldIndex = fieldIndex + columnsAttributes.length;
|
|
113
|
+
const attributesMetadata = [
|
|
114
|
+
...rowsAttributesMetadata,
|
|
115
|
+
...columnsAttributesMetadata,
|
|
116
|
+
];
|
|
117
|
+
const measuresMetadata = measures.map((m, index) => jaqlPivotMeasure(m, 'measures', index + fieldIndex));
|
|
118
|
+
const filtersMetadata = prepareFilterMetadata(attributesMetadata, filters, filterRelations, highlights, shouldSkipHighlightsWithoutAttributes);
|
|
119
|
+
const metadata = [...attributesMetadata, ...measuresMetadata, ...filtersMetadata];
|
|
120
|
+
(0, pivot_query_utils_js_1.normalizeLastRowSorting)(metadata, metadataStats);
|
|
121
|
+
return metadata;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Prepares the options part of the JAQL payload for a pivot query.
|
|
125
|
+
*
|
|
126
|
+
* @param dataSource
|
|
127
|
+
* @param grandTotals
|
|
128
|
+
* @param count
|
|
129
|
+
* @param offset
|
|
130
|
+
*/
|
|
131
|
+
function preparePivotQueryOptions(dataSource, grandTotals, count, offset) {
|
|
132
|
+
return Object.assign(Object.assign(Object.assign({ datasource: (0, sdk_data_1.convertJaqlDataSource)(dataSource), by: JAQL_BY_CSDK, queryGuid: (0, uuid_1.v4)(), dashboard: JAQL_BY_CSDK, widget: JAQL_BY_CSDK, format: 'pivot' }, (count ? { count } : {})), (offset ? { offset } : {})), { grandTotals: Object.assign(Object.assign({}, sdk_data_1.DEFAULT_PIVOT_GRAND_TOTALS), grandTotals) });
|
|
133
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Filter, MetadataItem } from '@sisense/sdk-data';
|
|
2
|
+
export declare function applyHighlightFilters(metadataItem: MetadataItem, highlights: Filter[]): MetadataItem;
|
|
3
|
+
export declare function matchHighlightsWithAttributes(attributesMetadata: MetadataItem[], highlights: Filter[]): Filter[][];
|
|
4
|
+
export declare function getMetadataItemId(metadataItem: MetadataItem): string;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMetadataItemId = exports.matchHighlightsWithAttributes = exports.applyHighlightFilters = void 0;
|
|
4
|
+
function applyHighlightFilters(metadataItem, highlights) {
|
|
5
|
+
const filter = highlights === null || highlights === void 0 ? void 0 : highlights.find((f) => getMetadataItemId(metadataItem) === f.attribute.id);
|
|
6
|
+
if (filter && !filter.disabled) {
|
|
7
|
+
if (filter.isScope) {
|
|
8
|
+
filter.isScope = false;
|
|
9
|
+
}
|
|
10
|
+
metadataItem.jaql.in = {
|
|
11
|
+
selected: filter.jaql(),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
return metadataItem;
|
|
15
|
+
}
|
|
16
|
+
exports.applyHighlightFilters = applyHighlightFilters;
|
|
17
|
+
function matchHighlightsWithAttributes(attributesMetadata, highlights) {
|
|
18
|
+
const highlightsWithAttributes = [];
|
|
19
|
+
const highlightsWithoutAttributes = [];
|
|
20
|
+
highlights.forEach((filter) => {
|
|
21
|
+
const isMatch = attributesMetadata.some((d) => getMetadataItemId(d) === filter.attribute.id);
|
|
22
|
+
if (isMatch) {
|
|
23
|
+
highlightsWithAttributes.push(filter);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
highlightsWithoutAttributes.push(filter);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return [highlightsWithAttributes, highlightsWithoutAttributes];
|
|
30
|
+
}
|
|
31
|
+
exports.matchHighlightsWithAttributes = matchHighlightsWithAttributes;
|
|
32
|
+
function getMetadataItemId(metadataItem) {
|
|
33
|
+
const { dim, level, dateTimeLevel, bucket } = metadataItem.jaql;
|
|
34
|
+
let id = `${dim}`;
|
|
35
|
+
if (level || dateTimeLevel) {
|
|
36
|
+
id += `_${level || dateTimeLevel}`;
|
|
37
|
+
}
|
|
38
|
+
if (bucket) {
|
|
39
|
+
id += `_${bucket}`;
|
|
40
|
+
}
|
|
41
|
+
return id;
|
|
42
|
+
}
|
|
43
|
+
exports.getMetadataItemId = getMetadataItemId;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './highlights.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./highlights.js"), exports);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Attribute, Measure, MetadataItem, PivotAttribute, PivotMeasure, PivotRowsSort, SortDirection } from '@sisense/sdk-data';
|
|
2
|
+
/**
|
|
3
|
+
* Represents statistics about a pivot table metadata.
|
|
4
|
+
*/
|
|
5
|
+
export type PivotMetadataStats = {
|
|
6
|
+
rowsCount: number;
|
|
7
|
+
columnsCount: number;
|
|
8
|
+
measuresCount: number;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Calculates statistics about the pivot table metadata.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getPivotMetadataStats(rowsAttributes: (Attribute | PivotAttribute)[], columnsAttributes: (Attribute | PivotAttribute)[], measures: (Measure | PivotMeasure)[]): PivotMetadataStats;
|
|
14
|
+
/**
|
|
15
|
+
* Converts sort direction to JAQL sort direction.
|
|
16
|
+
*/
|
|
17
|
+
export declare function convertSortDirectionToJaqlSort(direction: SortDirection): "asc" | "desc" | "none";
|
|
18
|
+
/**
|
|
19
|
+
* Prepares JAQL sort options for pivot table row.
|
|
20
|
+
*/
|
|
21
|
+
export declare function preparePivotRowJaqlSortOptions(sort: PivotRowsSort, rowIndex: number, metadataStats: PivotMetadataStats): {
|
|
22
|
+
sort: string;
|
|
23
|
+
sortDetails: {
|
|
24
|
+
dir: string;
|
|
25
|
+
field?: number | undefined;
|
|
26
|
+
measurePath?: Record<number, string | number> | undefined;
|
|
27
|
+
sortingLastDimension?: boolean | undefined;
|
|
28
|
+
initialized?: boolean | undefined;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Normalizes sorting for the last row of the pivot table.
|
|
33
|
+
*
|
|
34
|
+
* According to the existing pivot JAQL structure,the sorting configuration of the last row
|
|
35
|
+
* should be located inside the target measure metadata
|
|
36
|
+
*/
|
|
37
|
+
export declare function normalizeLastRowSorting(metadata: MetadataItem[], metadataStats: PivotMetadataStats): void;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.normalizeLastRowSorting = exports.preparePivotRowJaqlSortOptions = exports.convertSortDirectionToJaqlSort = exports.getPivotMetadataStats = void 0;
|
|
15
|
+
/**
|
|
16
|
+
* Calculates statistics about the pivot table metadata.
|
|
17
|
+
*/
|
|
18
|
+
function getPivotMetadataStats(rowsAttributes, columnsAttributes, measures) {
|
|
19
|
+
return {
|
|
20
|
+
rowsCount: rowsAttributes.length,
|
|
21
|
+
columnsCount: columnsAttributes.length,
|
|
22
|
+
measuresCount: measures.length,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
exports.getPivotMetadataStats = getPivotMetadataStats;
|
|
26
|
+
/**
|
|
27
|
+
* Converts sort direction to JAQL sort direction.
|
|
28
|
+
*/
|
|
29
|
+
function convertSortDirectionToJaqlSort(direction) {
|
|
30
|
+
switch (direction) {
|
|
31
|
+
case 'sortAsc':
|
|
32
|
+
return 'asc';
|
|
33
|
+
case 'sortDesc':
|
|
34
|
+
return 'desc';
|
|
35
|
+
default:
|
|
36
|
+
return 'none';
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.convertSortDirectionToJaqlSort = convertSortDirectionToJaqlSort;
|
|
40
|
+
/**
|
|
41
|
+
* Prepares JAQL sort options for pivot table row.
|
|
42
|
+
*/
|
|
43
|
+
function preparePivotRowJaqlSortOptions(sort, rowIndex, metadataStats) {
|
|
44
|
+
const sortDirection = convertSortDirectionToJaqlSort(sort.direction);
|
|
45
|
+
const isLastRow = rowIndex === metadataStats.rowsCount - 1;
|
|
46
|
+
const sortDetails = {
|
|
47
|
+
dir: sortDirection,
|
|
48
|
+
initialized: true,
|
|
49
|
+
field: sort.by && 'valuesIndex' in sort.by
|
|
50
|
+
? metadataStats.rowsCount + metadataStats.columnsCount + sort.by.valuesIndex
|
|
51
|
+
: rowIndex,
|
|
52
|
+
};
|
|
53
|
+
if (isLastRow) {
|
|
54
|
+
sortDetails.sortingLastDimension = true;
|
|
55
|
+
}
|
|
56
|
+
if (sort.by) {
|
|
57
|
+
sortDetails.measurePath = (sort.by.columnsMembersPath || []).reduce((path, columnMember, columnIndex) => (Object.assign(Object.assign({}, path), { [metadataStats.rowsCount + columnIndex]: columnMember })), {});
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
sort: sortDirection,
|
|
61
|
+
sortDetails,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
exports.preparePivotRowJaqlSortOptions = preparePivotRowJaqlSortOptions;
|
|
65
|
+
/**
|
|
66
|
+
* Normalizes sorting for the last row of the pivot table.
|
|
67
|
+
*
|
|
68
|
+
* According to the existing pivot JAQL structure,the sorting configuration of the last row
|
|
69
|
+
* should be located inside the target measure metadata
|
|
70
|
+
*/
|
|
71
|
+
function normalizeLastRowSorting(metadata, metadataStats) {
|
|
72
|
+
const lastRowMetadata = metadata[metadataStats.rowsCount - 1];
|
|
73
|
+
const isSortedByMeasure = lastRowMetadata.jaql.sortDetails &&
|
|
74
|
+
lastRowMetadata.jaql.sortDetails.field !== metadataStats.rowsCount - 1;
|
|
75
|
+
if (isSortedByMeasure) {
|
|
76
|
+
const targetMeasureMetadata = metadata[lastRowMetadata.jaql.sortDetails.field];
|
|
77
|
+
const _a = lastRowMetadata.jaql, { sortDetails, sort } = _a, jaqlWithoutSortOptions = __rest(_a, ["sortDetails", "sort"]);
|
|
78
|
+
targetMeasureMetadata.jaql.sortDetails = sortDetails;
|
|
79
|
+
targetMeasureMetadata.jaql.sort = sort;
|
|
80
|
+
lastRowMetadata.jaql = jaqlWithoutSortOptions;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.normalizeLastRowSorting = normalizeLastRowSorting;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { DataSource, DataSourceField, DataSourceMetadata, DataSourceSchema } from '@sisense/sdk-data';
|
|
2
|
+
import { HttpClient } from '@sisense/sdk-rest-client';
|
|
3
|
+
import { JaqlResponse, JaqlQueryPayload, QueryGuid } from '../types.js';
|
|
4
|
+
export declare class QueryApiDispatcher {
|
|
5
|
+
private httpClient;
|
|
6
|
+
constructor(httpClient: HttpClient);
|
|
7
|
+
getDataSourceFields(dataSource: DataSource, count?: number, offset?: number): Promise<DataSourceField[] | undefined>;
|
|
8
|
+
/**
|
|
9
|
+
* Returns a list of data sources.
|
|
10
|
+
* This method works with user of viewer role or above.
|
|
11
|
+
*/
|
|
12
|
+
getDataSourceList(): Promise<DataSourceMetadata[] | undefined>;
|
|
13
|
+
/**
|
|
14
|
+
* Returns the schema of a data source by its name.
|
|
15
|
+
*/
|
|
16
|
+
getDataSourceSchema(dataSourceName: string): Promise<DataSourceSchema | undefined>;
|
|
17
|
+
sendJaqlRequest(dataSource: DataSource, jaqlPayload: JaqlQueryPayload): {
|
|
18
|
+
responsePromise: Promise<JaqlResponse | undefined>;
|
|
19
|
+
abortHttpRequest: (reason?: string) => void;
|
|
20
|
+
};
|
|
21
|
+
sendDownloadCsvRequest(dataSource: DataSource, jaqlPayload: JaqlQueryPayload): {
|
|
22
|
+
responsePromise: Promise<ReadableStream<any> | undefined>;
|
|
23
|
+
abortHttpRequest: (reason?: string) => void;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Sends a request to cancel a JAQL query.
|
|
27
|
+
*
|
|
28
|
+
* @param guid - The guid of the query to cancel.
|
|
29
|
+
* @param dataSource - The datasource of where query sent.
|
|
30
|
+
*/
|
|
31
|
+
sendCancelJaqlQueryRequest(guid: QueryGuid, dataSource: DataSource): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Sends a request to cancel multiple JAQL queries.
|
|
34
|
+
*
|
|
35
|
+
* @param guids - The guids of the queries to cancel.
|
|
36
|
+
* @param dataSource - The datasource of where queries sent.
|
|
37
|
+
*/
|
|
38
|
+
sendCancelMultipleJaqlQueriesRequest(guids: QueryGuid[], dataSource: DataSource): Promise<void>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.QueryApiDispatcher = void 0;
|
|
13
|
+
const sdk_data_1 = require("@sisense/sdk-data");
|
|
14
|
+
const translatable_error_js_1 = require("../translation/translatable-error.js");
|
|
15
|
+
const API_DATASOURCES_BASE_PATH = 'api/datasources';
|
|
16
|
+
const API_DATAMODELS_BASE_PATH = 'api/v2/datamodels';
|
|
17
|
+
class QueryApiDispatcher {
|
|
18
|
+
constructor(httpClient) {
|
|
19
|
+
this.httpClient = httpClient;
|
|
20
|
+
}
|
|
21
|
+
getDataSourceFields(dataSource, count = 9999, offset = 0) {
|
|
22
|
+
const dataSourceName = (0, sdk_data_1.getDataSourceName)(dataSource);
|
|
23
|
+
const url = `${API_DATASOURCES_BASE_PATH}/${encodeURI(dataSourceName)}/fields/search`;
|
|
24
|
+
// when error is encountered, API returns only status code 400 without informative error message
|
|
25
|
+
// to remedy, catch error and throw a more informative error message
|
|
26
|
+
return this.httpClient.post(url, { offset, count }).catch(() => {
|
|
27
|
+
throw new translatable_error_js_1.TranslatableError('errors.dataSourceNotFound', {
|
|
28
|
+
dataSource: typeof dataSource === 'string' ? dataSource : dataSource.title,
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Returns a list of data sources.
|
|
34
|
+
* This method works with user of viewer role or above.
|
|
35
|
+
*/
|
|
36
|
+
getDataSourceList() {
|
|
37
|
+
const url = `${API_DATASOURCES_BASE_PATH}/?sharedWith=r,w`;
|
|
38
|
+
return this.httpClient.get(url);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Returns the schema of a data source by its name.
|
|
42
|
+
*/
|
|
43
|
+
getDataSourceSchema(dataSourceName) {
|
|
44
|
+
const url = `${API_DATAMODELS_BASE_PATH}/schema?title=${encodeURIComponent(dataSourceName)}`;
|
|
45
|
+
return this.httpClient.get(url);
|
|
46
|
+
}
|
|
47
|
+
sendJaqlRequest(dataSource, jaqlPayload) {
|
|
48
|
+
const url = getJaqlUrl(dataSource);
|
|
49
|
+
const abortController = new AbortController();
|
|
50
|
+
return {
|
|
51
|
+
responsePromise: this.httpClient
|
|
52
|
+
.post(url, jaqlPayload, undefined, abortController.signal)
|
|
53
|
+
.then((response) => {
|
|
54
|
+
if (Array.isArray(response)) {
|
|
55
|
+
return {
|
|
56
|
+
values: [],
|
|
57
|
+
metadata: [],
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return response;
|
|
61
|
+
}),
|
|
62
|
+
abortHttpRequest: (reason) => abortController.abort(reason),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
sendDownloadCsvRequest(dataSource, jaqlPayload) {
|
|
66
|
+
const url = getDownloadCsvUrl(dataSource);
|
|
67
|
+
const abortController = new AbortController();
|
|
68
|
+
const params = new URLSearchParams();
|
|
69
|
+
params.append('data', encodeURIComponent(JSON.stringify(jaqlPayload)));
|
|
70
|
+
return {
|
|
71
|
+
responsePromise: this.httpClient.post(url, params, { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }, abortController.signal, { nonJSONBody: true, returnBlob: true }),
|
|
72
|
+
abortHttpRequest: (reason) => abortController.abort(reason),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Sends a request to cancel a JAQL query.
|
|
77
|
+
*
|
|
78
|
+
* @param guid - The guid of the query to cancel.
|
|
79
|
+
* @param dataSource - The datasource of where query sent.
|
|
80
|
+
*/
|
|
81
|
+
sendCancelJaqlQueryRequest(guid, dataSource) {
|
|
82
|
+
return this.sendCancelMultipleJaqlQueriesRequest([guid], dataSource);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Sends a request to cancel multiple JAQL queries.
|
|
86
|
+
*
|
|
87
|
+
* @param guids - The guids of the queries to cancel.
|
|
88
|
+
* @param dataSource - The datasource of where queries sent.
|
|
89
|
+
*/
|
|
90
|
+
sendCancelMultipleJaqlQueriesRequest(guids, dataSource) {
|
|
91
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
const payload = {
|
|
93
|
+
queries: guids.join(';'),
|
|
94
|
+
};
|
|
95
|
+
const regularUrl = getRegularCancelQueryUrl(dataSource);
|
|
96
|
+
try {
|
|
97
|
+
yield this.httpClient.post(regularUrl, payload);
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
if (error.status === '404') {
|
|
101
|
+
// probably this datasource is live and requires a different URL for canceling queries
|
|
102
|
+
const liveUrl = getLiveCancelQueryUrl(dataSource);
|
|
103
|
+
yield this.httpClient.post(liveUrl, payload);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.QueryApiDispatcher = QueryApiDispatcher;
|
|
113
|
+
/**
|
|
114
|
+
* Returns the URL for canceling queries for a regular (non-live) datasource.
|
|
115
|
+
*
|
|
116
|
+
* @param dataSource - The data source of the query.
|
|
117
|
+
*/
|
|
118
|
+
function getRegularCancelQueryUrl(dataSource) {
|
|
119
|
+
const datasourcePath = encodeURIComponent((0, sdk_data_1.getDataSourceName)(dataSource));
|
|
120
|
+
return `${API_DATASOURCES_BASE_PATH}/localhost/${datasourcePath}/cancel_queries`;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Returns the URL for canceling queries for a live datasource.
|
|
124
|
+
* Live datasources require a different URL for canceling queries.
|
|
125
|
+
*
|
|
126
|
+
* @param dataSource - The data source of the query.
|
|
127
|
+
*/
|
|
128
|
+
function getLiveCancelQueryUrl(dataSource) {
|
|
129
|
+
const datasourcePath = encodeURIComponent((0, sdk_data_1.getDataSourceName)(dataSource));
|
|
130
|
+
return `${API_DATASOURCES_BASE_PATH}/live/${datasourcePath}/cancel_queries`;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Returns the URL for sending a JAQL request.
|
|
134
|
+
*
|
|
135
|
+
* @param dataSource - The data source of the query.
|
|
136
|
+
*/
|
|
137
|
+
function getJaqlUrl(dataSource) {
|
|
138
|
+
const dataSourcePath = encodeURIComponent((0, sdk_data_1.getDataSourceName)(dataSource));
|
|
139
|
+
return `${API_DATASOURCES_BASE_PATH}/${dataSourcePath}/jaql`;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Returns the URL for sending a Download CSV request.
|
|
143
|
+
*
|
|
144
|
+
* @param dataSource - The data source of the query.
|
|
145
|
+
*/
|
|
146
|
+
function getDownloadCsvUrl(dataSource) {
|
|
147
|
+
return `${getJaqlUrl(dataSource)}/csv`;
|
|
148
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ExecutingCsvQueryResult, ExecutingPivotQueryResult, ExecutingQueryResult, PivotQueryDescription, QueryDescription, QueryExecutionConfig } from './types.js';
|
|
2
|
+
import { QueryClient } from './interfaces.js';
|
|
3
|
+
import { DataSource } from '@sisense/sdk-data';
|
|
4
|
+
import { HttpClient } from '@sisense/sdk-rest-client';
|
|
5
|
+
import { PivotClient } from '@sisense/sdk-pivot-client';
|
|
6
|
+
/** @internal */
|
|
7
|
+
export declare const QUERY_DEFAULT_LIMIT = 20000;
|
|
8
|
+
export declare class DimensionalQueryClient implements QueryClient {
|
|
9
|
+
private taskManager;
|
|
10
|
+
private queryApi;
|
|
11
|
+
private shouldSkipHighlightsWithoutAttributes;
|
|
12
|
+
constructor(httpClient: HttpClient, pivotClient?: PivotClient, shouldSkipHighlightsWithoutAttributes?: boolean);
|
|
13
|
+
/**
|
|
14
|
+
* Executes query
|
|
15
|
+
*
|
|
16
|
+
* @param queryDescription - all options that describe query
|
|
17
|
+
* @param config - query execution configuration
|
|
18
|
+
* @returns promise that resolves to query result data and cancel function that can be used to cancel sent query
|
|
19
|
+
* @throws Error if query description is invalid
|
|
20
|
+
*/
|
|
21
|
+
executeQuery(queryDescription: QueryDescription, config?: QueryExecutionConfig): ExecutingQueryResult;
|
|
22
|
+
executeCsvQuery(queryDescription: QueryDescription, config?: QueryExecutionConfig): ExecutingCsvQueryResult;
|
|
23
|
+
/**
|
|
24
|
+
* Executes pivot query
|
|
25
|
+
*
|
|
26
|
+
* @param pivotQueryDescription - all options that describe the pivot query
|
|
27
|
+
* @param config - query execution configuration
|
|
28
|
+
* @returns promise that resolves to pivot query result data and cancel function that can be used to cancel sent query
|
|
29
|
+
* @throws Error if query description is invalid
|
|
30
|
+
*/
|
|
31
|
+
executePivotQuery(pivotQueryDescription: PivotQueryDescription, config?: QueryExecutionConfig): ExecutingPivotQueryResult;
|
|
32
|
+
getDataSourceFields(dataSource: DataSource, count?: number, offset?: number): Promise<import("@sisense/sdk-data").DataSourceField[]>;
|
|
33
|
+
/**
|
|
34
|
+
* Returns the schema of a data source by its name.
|
|
35
|
+
*/
|
|
36
|
+
getDataSourceSchema(datasourceName: string): Promise<import("@sisense/sdk-data").DataSourceSchema | undefined>;
|
|
37
|
+
/**
|
|
38
|
+
* Returns a list of data sources
|
|
39
|
+
*/
|
|
40
|
+
getDataSourceList(): Promise<import("@sisense/sdk-data").DataSourceMetadata[]>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Validates query description
|
|
44
|
+
*
|
|
45
|
+
* @param queryDescription - query description to validate
|
|
46
|
+
* @param config - query execution configuration
|
|
47
|
+
* @throws Error if query description is invalid
|
|
48
|
+
*/
|
|
49
|
+
export declare function validateQueryDescription(queryDescription: QueryDescription): void;
|
|
50
|
+
/**
|
|
51
|
+
* Validates pivot query description
|
|
52
|
+
*
|
|
53
|
+
* @param queryDescription - pivot query description to validate
|
|
54
|
+
* @throws Error if query description is invalid
|
|
55
|
+
*/
|
|
56
|
+
export declare function validatePivotQueryDescription(queryDescription: PivotQueryDescription): void;
|