@sisense/sdk-query-client 1.4.0 → 1.5.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/helpers/utility-types.d.ts +2 -0
- package/dist/helpers/utility-types.js +1 -0
- package/dist/jaql/get-jaql-query-payload.js +14 -3
- package/dist/query-api-dispatcher/query-api-dispatcher.d.ts +5 -1
- package/dist/query-api-dispatcher/query-api-dispatcher.js +16 -4
- package/dist/query-client.d.ts +5 -1
- package/dist/query-client.js +12 -0
- package/dist/query-task-manager/query-task-manager.d.ts +2 -1
- package/dist/types.d.ts +13 -2
- package/package.json +5 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/* eslint-disable max-lines */
|
|
3
3
|
import { v4 as uuid } from 'uuid';
|
|
4
4
|
import merge from 'ts-deepmerge';
|
|
5
|
-
import { isPivotAttribute, isPivotMeasure, DEFAULT_PIVOT_GRAND_TOTALS, } from '@sisense/sdk-data';
|
|
5
|
+
import { isPivotAttribute, isPivotMeasure, DEFAULT_PIVOT_GRAND_TOTALS, isDataSourceInfo, } from '@sisense/sdk-data';
|
|
6
6
|
import { applyHighlightFilters, matchHighlightsWithAttributes } from './metadata/highlights.js';
|
|
7
7
|
const JAQL_BY_CSDK = 'ComposeSDK';
|
|
8
8
|
export function getJaqlQueryPayload(queryDescription, shouldSkipHighlightsWithoutAttributes) {
|
|
@@ -42,7 +42,7 @@ function prepareQueryMetadata(metadataDescription, shouldSkipHighlightsWithoutAt
|
|
|
42
42
|
return [...attributesMetadata, ...measuresMetadata, ...filtersMetadata];
|
|
43
43
|
}
|
|
44
44
|
function prepareQueryOptions(dataSource, count, offset) {
|
|
45
|
-
return Object.assign(Object.assign({ datasource: dataSource, by: JAQL_BY_CSDK, queryGuid: uuid() }, (count ? { count } : {})), (offset ? { offset } : {}));
|
|
45
|
+
return Object.assign(Object.assign({ datasource: getJaqlDataSource(dataSource), by: JAQL_BY_CSDK, queryGuid: uuid() }, (count ? { count } : {})), (offset ? { offset } : {}));
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
48
|
* Converts a pivot query description to a JAQL query payload.
|
|
@@ -101,5 +101,16 @@ function preparePivotQueryMetadata(pivotMetadataDescription, shouldSkipHighlight
|
|
|
101
101
|
* @param offset
|
|
102
102
|
*/
|
|
103
103
|
function preparePivotQueryOptions(dataSource, grandTotals, count, offset) {
|
|
104
|
-
return Object.assign(Object.assign(Object.assign({ datasource: dataSource, by: JAQL_BY_CSDK, queryGuid: uuid(), dashboard: JAQL_BY_CSDK, widget: JAQL_BY_CSDK, format: 'pivot' }, (count ? { count } : {})), (offset ? { offset } : {})), { grandTotals: Object.assign(Object.assign({}, DEFAULT_PIVOT_GRAND_TOTALS), grandTotals) });
|
|
104
|
+
return Object.assign(Object.assign(Object.assign({ datasource: getJaqlDataSource(dataSource), by: JAQL_BY_CSDK, queryGuid: uuid(), dashboard: JAQL_BY_CSDK, widget: JAQL_BY_CSDK, format: 'pivot' }, (count ? { count } : {})), (offset ? { offset } : {})), { grandTotals: Object.assign(Object.assign({}, DEFAULT_PIVOT_GRAND_TOTALS), grandTotals) });
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Converts a DataSource to a description of data source used in JAQL.
|
|
108
|
+
*/
|
|
109
|
+
function getJaqlDataSource(dataSource) {
|
|
110
|
+
return isDataSourceInfo(dataSource)
|
|
111
|
+
? {
|
|
112
|
+
title: dataSource.title,
|
|
113
|
+
live: dataSource.type === 'live',
|
|
114
|
+
}
|
|
115
|
+
: dataSource;
|
|
105
116
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DataSource } from '@sisense/sdk-data';
|
|
2
2
|
import { HttpClient } from '@sisense/sdk-rest-client';
|
|
3
|
-
import { AbortRequestFunction, DataSourceField, JaqlResponse, JaqlQueryPayload, QueryGuid } from '../types.js';
|
|
3
|
+
import { AbortRequestFunction, DataSourceField, JaqlResponse, JaqlQueryPayload, QueryGuid, DataSourceSchema } from '../types.js';
|
|
4
4
|
type RequestSendingResult<T> = {
|
|
5
5
|
responsePromise: Promise<T>;
|
|
6
6
|
abortHttpRequest: AbortRequestFunction;
|
|
@@ -9,6 +9,10 @@ export declare class QueryApiDispatcher {
|
|
|
9
9
|
private httpClient;
|
|
10
10
|
constructor(httpClient: HttpClient);
|
|
11
11
|
getDataSourceFields(dataSource: DataSource, count?: number, offset?: number): Promise<DataSourceField[]>;
|
|
12
|
+
/**
|
|
13
|
+
* Returns the schema of a data source by its name.
|
|
14
|
+
*/
|
|
15
|
+
getDataSourceSchema(dataSourceName: string): Promise<DataSourceSchema>;
|
|
12
16
|
sendJaqlRequest(dataSource: DataSource, jaqlPayload: JaqlQueryPayload): RequestSendingResult<JaqlResponse>;
|
|
13
17
|
sendDownloadCsvRequest(dataSource: DataSource, jaqlPayload: JaqlQueryPayload): RequestSendingResult<ReadableStream>;
|
|
14
18
|
/**
|
|
@@ -7,14 +7,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
import { getDataSourceName } from '@sisense/sdk-data';
|
|
10
11
|
const API_DATASOURCES_BASE_PATH = 'api/datasources';
|
|
12
|
+
const API_DATAMODELS_BASE_PATH = 'api/v2/datamodels';
|
|
11
13
|
export class QueryApiDispatcher {
|
|
12
14
|
constructor(httpClient) {
|
|
13
15
|
this.httpClient = httpClient;
|
|
14
16
|
}
|
|
15
17
|
getDataSourceFields(dataSource, count = 9999, offset = 0) {
|
|
16
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
const
|
|
19
|
+
const dataSourceName = getDataSourceName(dataSource);
|
|
20
|
+
const url = `${API_DATASOURCES_BASE_PATH}/${encodeURIComponent(dataSourceName)}/fields/search`;
|
|
18
21
|
// when error is encountered, API returns only status code 400 without informative error message
|
|
19
22
|
// to remedy, catch error and throw a more informative error message
|
|
20
23
|
try {
|
|
@@ -25,6 +28,15 @@ export class QueryApiDispatcher {
|
|
|
25
28
|
}
|
|
26
29
|
});
|
|
27
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Returns the schema of a data source by its name.
|
|
33
|
+
*/
|
|
34
|
+
getDataSourceSchema(dataSourceName) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
const url = `${API_DATAMODELS_BASE_PATH}/schema?title=${encodeURIComponent(dataSourceName)}`;
|
|
37
|
+
return this.httpClient.get(url);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
28
40
|
sendJaqlRequest(dataSource, jaqlPayload) {
|
|
29
41
|
const url = getJaqlUrl(dataSource);
|
|
30
42
|
const abortController = new AbortController();
|
|
@@ -86,7 +98,7 @@ export class QueryApiDispatcher {
|
|
|
86
98
|
* @param dataSource
|
|
87
99
|
*/
|
|
88
100
|
function getRegularCancelQueryUrl(dataSource) {
|
|
89
|
-
const datasourcePath = encodeURIComponent(dataSource);
|
|
101
|
+
const datasourcePath = encodeURIComponent(getDataSourceName(dataSource));
|
|
90
102
|
return `${API_DATASOURCES_BASE_PATH}/localhost/${datasourcePath}/cancel_queries`;
|
|
91
103
|
}
|
|
92
104
|
/**
|
|
@@ -96,7 +108,7 @@ function getRegularCancelQueryUrl(dataSource) {
|
|
|
96
108
|
* @param dataSource
|
|
97
109
|
*/
|
|
98
110
|
function getLiveCancelQueryUrl(dataSource) {
|
|
99
|
-
const datasourcePath = encodeURIComponent(dataSource);
|
|
111
|
+
const datasourcePath = encodeURIComponent(getDataSourceName(dataSource));
|
|
100
112
|
return `${API_DATASOURCES_BASE_PATH}/live/${datasourcePath}/cancel_queries`;
|
|
101
113
|
}
|
|
102
114
|
/**
|
|
@@ -105,7 +117,7 @@ function getLiveCancelQueryUrl(dataSource) {
|
|
|
105
117
|
* @param dataSource
|
|
106
118
|
*/
|
|
107
119
|
function getJaqlUrl(dataSource) {
|
|
108
|
-
const dataSourcePath = encodeURIComponent(dataSource);
|
|
120
|
+
const dataSourcePath = encodeURIComponent(getDataSourceName(dataSource));
|
|
109
121
|
return `${API_DATASOURCES_BASE_PATH}/${dataSourcePath}/jaql`;
|
|
110
122
|
}
|
|
111
123
|
/**
|
package/dist/query-client.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DataSourceField, ExecutingCsvQueryResult, ExecutingPivotQueryResult, ExecutingQueryResult, PivotQueryDescription, QueryDescription, QueryExecutionConfig } from './types.js';
|
|
2
2
|
import { QueryClient } from './interfaces.js';
|
|
3
|
-
import { DataSource } from '@sisense/sdk-data';
|
|
3
|
+
import { DataSourceInfo, DataSource } from '@sisense/sdk-data';
|
|
4
4
|
import { HttpClient } from '@sisense/sdk-rest-client';
|
|
5
5
|
import { PivotClient } from '@sisense/sdk-pivot-client';
|
|
6
6
|
/** @internal */
|
|
@@ -30,6 +30,10 @@ export declare class DimensionalQueryClient implements QueryClient {
|
|
|
30
30
|
*/
|
|
31
31
|
executePivotQuery(pivotQueryDescription: PivotQueryDescription, config?: QueryExecutionConfig): ExecutingPivotQueryResult;
|
|
32
32
|
getDataSourceFields(dataSource: DataSource, count?: number, offset?: number): Promise<DataSourceField[]>;
|
|
33
|
+
/**
|
|
34
|
+
* Get info about data source
|
|
35
|
+
*/
|
|
36
|
+
getDataSourceInfo(datasourceName: string): Promise<DataSourceInfo>;
|
|
33
37
|
}
|
|
34
38
|
/**
|
|
35
39
|
* Validates query description
|
package/dist/query-client.js
CHANGED
|
@@ -96,6 +96,18 @@ export class DimensionalQueryClient {
|
|
|
96
96
|
return this.queryApi.getDataSourceFields(dataSource, count, offset);
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Get info about data source
|
|
101
|
+
*/
|
|
102
|
+
getDataSourceInfo(datasourceName) {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
const completeDataSourceSchema = yield this.queryApi.getDataSourceSchema(datasourceName);
|
|
105
|
+
return {
|
|
106
|
+
title: completeDataSourceSchema.title,
|
|
107
|
+
type: completeDataSourceSchema.type === 'extract' ? 'elasticube' : 'live',
|
|
108
|
+
};
|
|
109
|
+
});
|
|
110
|
+
}
|
|
99
111
|
}
|
|
100
112
|
/**
|
|
101
113
|
* Validates query description
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { AbstractTaskManager } from '@sisense/task-manager';
|
|
2
|
-
import {
|
|
2
|
+
import { JaqlResponse } from '../types.js';
|
|
3
3
|
import { PivotQueryTaskPassport, QueryTaskPassport } from './query-task-passport.js';
|
|
4
4
|
import { QueryResultData, PivotQueryResultData } from '@sisense/sdk-data';
|
|
5
5
|
import { QueryApiDispatcher } from '../query-api-dispatcher/query-api-dispatcher.js';
|
|
6
6
|
import { PivotClient } from '@sisense/sdk-pivot-client';
|
|
7
|
+
import { EmptyObject } from '../helpers/utility-types.js';
|
|
7
8
|
export declare class QueryTaskManager extends AbstractTaskManager {
|
|
8
9
|
/** Map of aborters by task id to be able to cancel sent requests */
|
|
9
10
|
private sentRequestsAbortersMap;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Filter, Measure, Attribute, Cell, QueryResultData, DataSource, PivotAttribute, PivotMeasure, PivotQueryResultData, PivotGrandTotals, FilterRelationsJaql } from '@sisense/sdk-data';
|
|
2
|
+
import { AnyObject } from './helpers/utility-types.js';
|
|
2
3
|
/**
|
|
3
4
|
* All the properties that fully describe a query you want to send.
|
|
4
5
|
*/
|
|
@@ -39,8 +40,15 @@ export type QueryExecutionConfig = {
|
|
|
39
40
|
export type QueryExecutionConfigInternal = QueryExecutionConfig & {
|
|
40
41
|
shouldSkipHighlightsWithoutAttributes: boolean;
|
|
41
42
|
};
|
|
43
|
+
/**
|
|
44
|
+
* Data source description used in JAQL.
|
|
45
|
+
*/
|
|
46
|
+
export type JaqlDataSource = string | {
|
|
47
|
+
title: string;
|
|
48
|
+
live: boolean;
|
|
49
|
+
};
|
|
42
50
|
export type QueryOptions = {
|
|
43
|
-
datasource:
|
|
51
|
+
datasource: JaqlDataSource;
|
|
44
52
|
by: string;
|
|
45
53
|
queryGuid: string;
|
|
46
54
|
dashboard?: string;
|
|
@@ -143,6 +151,9 @@ export type JaqlResponse = {
|
|
|
143
151
|
httpStatusCode?: number;
|
|
144
152
|
database?: string;
|
|
145
153
|
};
|
|
154
|
+
export type DataSourceSchema = {
|
|
155
|
+
title: string;
|
|
156
|
+
type: 'extract' | 'live';
|
|
157
|
+
} & AnyObject;
|
|
146
158
|
export type AbortRequestFunction = (reason?: string) => void;
|
|
147
159
|
export type QueryGuid = string;
|
|
148
|
-
export type EmptyObject = Record<string, never>;
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"Sisense",
|
|
12
12
|
"Compose SDK"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.
|
|
14
|
+
"version": "1.5.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.5.0",
|
|
24
|
+
"@sisense/sdk-data": "^1.5.0",
|
|
25
|
+
"@sisense/sdk-pivot-client": "^1.5.0",
|
|
26
|
+
"@sisense/sdk-rest-client": "^1.5.0",
|
|
27
27
|
"@sisense/task-manager": "^0.1.0",
|
|
28
28
|
"numeral": "^2.0.6",
|
|
29
29
|
"ts-deepmerge": "6.0.2",
|