@sisense/sdk-query-client 1.8.0 → 1.10.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.
@@ -1,8 +1,10 @@
1
- import { DataSourceField, ExecutingCsvQueryResult, ExecutingPivotQueryResult, ExecutingQueryResult, PivotQueryDescription, QueryDescription, QueryExecutionConfig } from './types.js';
1
+ import { DataSourceField, DataSourceMetadata, DataSourceSchema, ExecutingCsvQueryResult, ExecutingPivotQueryResult, ExecutingQueryResult, PivotQueryDescription, QueryDescription, QueryExecutionConfig } from './types.js';
2
2
  import { DataSource } from '@sisense/sdk-data';
3
3
  export interface QueryClient {
4
4
  executeQuery(params: QueryDescription, config?: QueryExecutionConfig): ExecutingQueryResult;
5
5
  executeCsvQuery(params: QueryDescription, config?: QueryExecutionConfig): ExecutingCsvQueryResult;
6
6
  executePivotQuery(params: PivotQueryDescription, config?: QueryExecutionConfig): ExecutingPivotQueryResult;
7
7
  getDataSourceFields(dataSource: DataSource): Promise<DataSourceField[]>;
8
+ getDataSourceSchema(datasourceName: string): Promise<DataSourceSchema>;
9
+ getDataSourceList(): Promise<DataSourceMetadata[]>;
8
10
  }
@@ -1,5 +1,3 @@
1
- /* eslint-disable complexity */
2
- /* eslint-disable max-lines */
3
1
  import { v4 as uuid } from 'uuid';
4
2
  import merge from 'ts-deepmerge';
5
3
  import { isPivotAttribute, isPivotMeasure, DEFAULT_PIVOT_GRAND_TOTALS, isDataSourceInfo, } from '@sisense/sdk-data';
@@ -64,10 +62,8 @@ export function getPivotJaqlQueryPayload(pivotQueryDescription, shouldSkipHighli
64
62
  return queryPayload;
65
63
  }
66
64
  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)));
65
+ const isSortedRowAttribute = panel === 'rows' && isPivotAttribute(a) && a.sort && a.sort.direction !== 'sortNone';
66
+ const jaql = Object.assign(Object.assign({}, (isPivotAttribute(a) ? a.attribute.jaql(true) : a.jaql(true))), (isSortedRowAttribute && preparePivotRowJaqlSortOptions(a.sort, index, metadataStats)));
71
67
  return Object.assign(Object.assign({ jaql }, (isPivotAttribute(a) && a.includeSubTotals ? { format: { subtotal: true } } : {})), { panel, field: { index: index, id: `${panel}-${index}` } });
72
68
  }
73
69
  function jaqlPivotMeasure(m, panel, index) {
@@ -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, DataSourceSchema } from '../types.js';
3
+ import { AbortRequestFunction, DataSourceField, JaqlResponse, JaqlQueryPayload, QueryGuid, DataSourceSchema, DataSourceMetadata } from '../types.js';
4
4
  type RequestSendingResult<T> = {
5
5
  responsePromise: Promise<T>;
6
6
  abortHttpRequest: AbortRequestFunction;
@@ -9,6 +9,11 @@ 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 a list of data sources.
14
+ * This method works with user of viewer role or above.
15
+ */
16
+ getDataSourceList(): Promise<DataSourceMetadata[]>;
12
17
  /**
13
18
  * Returns the schema of a data source by its name.
14
19
  */
@@ -28,6 +28,16 @@ export class QueryApiDispatcher {
28
28
  }
29
29
  });
30
30
  }
31
+ /**
32
+ * Returns a list of data sources.
33
+ * This method works with user of viewer role or above.
34
+ */
35
+ getDataSourceList() {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ const url = `${API_DATASOURCES_BASE_PATH}/?sharedWith=r,w`;
38
+ return this.httpClient.get(url);
39
+ });
40
+ }
31
41
  /**
32
42
  * Returns the schema of a data source by its name.
33
43
  */
@@ -41,7 +51,17 @@ export class QueryApiDispatcher {
41
51
  const url = getJaqlUrl(dataSource);
42
52
  const abortController = new AbortController();
43
53
  return {
44
- responsePromise: this.httpClient.post(url, jaqlPayload, undefined, abortController.signal),
54
+ responsePromise: this.httpClient
55
+ .post(url, jaqlPayload, undefined, abortController.signal)
56
+ .then((response) => {
57
+ if (Array.isArray(response)) {
58
+ return {
59
+ values: [],
60
+ metadata: [],
61
+ };
62
+ }
63
+ return response;
64
+ }),
45
65
  abortHttpRequest: (reason) => abortController.abort(reason),
46
66
  };
47
67
  }
@@ -80,7 +100,7 @@ export class QueryApiDispatcher {
80
100
  yield this.httpClient.post(regularUrl, payload);
81
101
  }
82
102
  catch (error) {
83
- if (error.status === 404) {
103
+ if (error.status === '404') {
84
104
  // probably this datasource is live and requires a different URL for canceling queries
85
105
  const liveUrl = getLiveCancelQueryUrl(dataSource);
86
106
  yield this.httpClient.post(liveUrl, payload);
@@ -1,6 +1,6 @@
1
- import { DataSourceField, ExecutingCsvQueryResult, ExecutingPivotQueryResult, ExecutingQueryResult, PivotQueryDescription, QueryDescription, QueryExecutionConfig } from './types.js';
1
+ import { DataSourceField, DataSourceMetadata, DataSourceSchema, ExecutingCsvQueryResult, ExecutingPivotQueryResult, ExecutingQueryResult, PivotQueryDescription, QueryDescription, QueryExecutionConfig } from './types.js';
2
2
  import { QueryClient } from './interfaces.js';
3
- import { DataSourceInfo, DataSource } from '@sisense/sdk-data';
3
+ import { 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 */
@@ -31,9 +31,13 @@ export declare class DimensionalQueryClient implements QueryClient {
31
31
  executePivotQuery(pivotQueryDescription: PivotQueryDescription, config?: QueryExecutionConfig): ExecutingPivotQueryResult;
32
32
  getDataSourceFields(dataSource: DataSource, count?: number, offset?: number): Promise<DataSourceField[]>;
33
33
  /**
34
- * Get info about data source
34
+ * Returns the schema of a data source by its name.
35
35
  */
36
- getDataSourceInfo(datasourceName: string): Promise<DataSourceInfo>;
36
+ getDataSourceSchema(datasourceName: string): Promise<DataSourceSchema>;
37
+ /**
38
+ * Returns a list of data sources
39
+ */
40
+ getDataSourceList(): Promise<DataSourceMetadata[]>;
37
41
  }
38
42
  /**
39
43
  * Validates query description
@@ -97,15 +97,19 @@ export class DimensionalQueryClient {
97
97
  });
98
98
  }
99
99
  /**
100
- * Get info about data source
100
+ * Returns the schema of a data source by its name.
101
101
  */
102
- getDataSourceInfo(datasourceName) {
102
+ getDataSourceSchema(datasourceName) {
103
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
- };
104
+ return this.queryApi.getDataSourceSchema(datasourceName);
105
+ });
106
+ }
107
+ /**
108
+ * Returns a list of data sources
109
+ */
110
+ getDataSourceList() {
111
+ return __awaiter(this, void 0, void 0, function* () {
112
+ return this.queryApi.getDataSourceList();
109
113
  });
110
114
  }
111
115
  }
@@ -2,4 +2,5 @@ import { AbstractTranslatableError } from '@sisense/sdk-common';
2
2
  import { PACKAGE_NAMESPACE } from './resources/index.js';
3
3
  export declare class TranslatableError extends AbstractTranslatableError<typeof PACKAGE_NAMESPACE> {
4
4
  constructor(translationKey: string, interpolationOptions?: Record<string, string>);
5
+ get status(): string;
5
6
  }
@@ -8,4 +8,7 @@ export class TranslatableError extends AbstractTranslatableError {
8
8
  interpolationOptions: interpolationOptions,
9
9
  }, i18nextInstance.t);
10
10
  }
11
+ get status() {
12
+ return this.interpolationOptions.status;
13
+ }
11
14
  }
package/dist/types.d.ts CHANGED
@@ -201,6 +201,10 @@ export type DataSourceSchema = {
201
201
  title: string;
202
202
  type: 'extract' | 'live';
203
203
  } & AnyObject;
204
+ export type DataSourceMetadata = {
205
+ title: string;
206
+ live: boolean;
207
+ };
204
208
  export type AbortRequestFunction = (reason?: string) => void;
205
209
  export type QueryGuid = string;
206
210
  export {};
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "Sisense",
12
12
  "Compose SDK"
13
13
  ],
14
- "version": "1.8.0",
14
+ "version": "1.10.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.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",
23
+ "@sisense/sdk-common": "^1.10.0",
24
+ "@sisense/sdk-data": "^1.10.0",
25
+ "@sisense/sdk-pivot-client": "^1.10.0",
26
+ "@sisense/sdk-rest-client": "^1.10.0",
27
27
  "@sisense/task-manager": "^0.1.0",
28
28
  "numeral": "^2.0.6",
29
29
  "ts-deepmerge": "6.0.2",