@sisense/sdk-query-client 0.12.0 → 0.13.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,6 +1,6 @@
1
- import { DataSourceField, ExecutingQueryResult, QueryDescription } from './types.js';
1
+ import { DataSourceField, ExecutingQueryResult, QueryDescription, QueryExecutionConfig } from './types.js';
2
2
  import { DataSource } from '@sisense/sdk-data';
3
3
  export interface QueryClient {
4
- executeQuery(params: QueryDescription): ExecutingQueryResult;
4
+ executeQuery(params: QueryDescription, config?: QueryExecutionConfig): ExecutingQueryResult;
5
5
  getDataSourceFields(dataSource: DataSource): Promise<DataSourceField[]>;
6
6
  }
@@ -1,4 +1,4 @@
1
- import { DataSourceField, ExecutingQueryResult, QueryDescription } from './types.js';
1
+ import { DataSourceField, ExecutingQueryResult, QueryDescription, QueryExecutionConfig } from './types.js';
2
2
  import { QueryClient } from './interfaces.js';
3
3
  import { DataSource } from '@sisense/sdk-data';
4
4
  import { HttpClient } from '@sisense/sdk-rest-client';
@@ -16,7 +16,7 @@ export declare class DimensionalQueryClient implements QueryClient {
16
16
  * @returns promise that resolves to query result data and cancel function that can be used to cancel sent query
17
17
  * @throws Error if query description is invalid
18
18
  */
19
- executeQuery(queryDescription: QueryDescription): ExecutingQueryResult;
19
+ executeQuery(queryDescription: QueryDescription, config?: QueryExecutionConfig): ExecutingQueryResult;
20
20
  getDataSourceFields(dataSource: DataSource, count?: number, offset?: number): Promise<DataSourceField[]>;
21
21
  }
22
22
  /**
@@ -29,9 +29,9 @@ export class DimensionalQueryClient {
29
29
  * @returns promise that resolves to query result data and cancel function that can be used to cancel sent query
30
30
  * @throws Error if query description is invalid
31
31
  */
32
- executeQuery(queryDescription) {
32
+ executeQuery(queryDescription, config) {
33
33
  validateQueryDescription(queryDescription);
34
- const taskPassport = new QueryTaskPassport('SEND_JAQL_QUERY', queryDescription, this.shouldSkipHighlightsWithoutAttributes);
34
+ const taskPassport = new QueryTaskPassport('SEND_JAQL_QUERY', queryDescription, Object.assign(Object.assign({}, (config ? config : {})), { shouldSkipHighlightsWithoutAttributes: this.shouldSkipHighlightsWithoutAttributes || false }));
35
35
  return {
36
36
  resultPromise: new Promise((resolve, reject) => {
37
37
  void this.taskManager.executeQuerySending(taskPassport).then((executionResult) => {
@@ -8,6 +8,7 @@ export declare class QueryTaskManager extends AbstractTaskManager {
8
8
  private sentRequestsAbortersMap;
9
9
  private queryApi;
10
10
  constructor(queryApi: QueryApiDispatcher);
11
+ private prepareJaqlPayload;
11
12
  private sendJaqlQuery;
12
13
  private cancelJaqlQuery;
13
14
  executeQuerySending: (passport: QueryTaskPassport) => Promise<import("@sisense/task-manager").TaskExecutionResult<QueryResultData, EmptyObject>>;
@@ -16,16 +16,26 @@ export class QueryTaskManager extends AbstractTaskManager {
16
16
  /** Map of aborters by task id to be able to cancel sent requests */
17
17
  this.sentRequestsAbortersMap = new Map();
18
18
  this.executeQuerySending = super.createFlow([
19
+ new Step('PREPARE_JAQL_PAYLOAD', this.prepareJaqlPayload.bind(this), () => __awaiter(this, void 0, void 0, function* () { })),
19
20
  new Step('SEND_JAQL_QUERY', this.sendJaqlQuery.bind(this), this.cancelJaqlQuery.bind(this)),
20
21
  ]);
21
22
  this.queryApi = queryApi;
22
23
  }
23
- sendJaqlQuery(task) {
24
+ prepareJaqlPayload(task) {
24
25
  return __awaiter(this, void 0, void 0, function* () {
25
- const { queryDescription, shouldSkipHighlightsWithoutAttributes } = task.passport;
26
- const jaqlPayload = getJaqlQueryPayload(queryDescription, shouldSkipHighlightsWithoutAttributes);
26
+ const { queryDescription, executionConfig } = task.passport;
27
+ const jaqlPayload = getJaqlQueryPayload(queryDescription, executionConfig.shouldSkipHighlightsWithoutAttributes);
28
+ const onBeforeQuery = task.passport.executionConfig.onBeforeQuery;
29
+ if (onBeforeQuery) {
30
+ return onBeforeQuery(jaqlPayload);
31
+ }
32
+ return jaqlPayload;
33
+ });
34
+ }
35
+ sendJaqlQuery(task, jaqlPayload) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ const { queryDescription, taskId } = task.passport;
27
38
  const { responsePromise, abortHttpRequest } = this.queryApi.sendJaqlRequest(task.passport.queryDescription.dataSource, jaqlPayload);
28
- const taskId = task.passport.taskId;
29
39
  this.sentRequestsAbortersMap.set(taskId, abortHttpRequest);
30
40
  const jaqlResponse = yield responsePromise.finally(() => {
31
41
  this.sentRequestsAbortersMap.delete(taskId);
@@ -1,10 +1,10 @@
1
1
  import { TaskPassport } from '@sisense/task-manager';
2
- import { QueryDescription } from '../types.js';
2
+ import { QueryDescription, QueryExecutionConfigInternal } from '../types.js';
3
3
  type TaskType = 'SEND_JAQL_QUERY';
4
4
  export declare class QueryTaskPassport extends TaskPassport {
5
5
  queryDescription: QueryDescription;
6
- shouldSkipHighlightsWithoutAttributes: boolean;
6
+ executionConfig: QueryExecutionConfigInternal;
7
7
  type: TaskType;
8
- constructor(type: TaskType, queryDescription: QueryDescription, shouldSkipHighlightsWithoutAttributes?: boolean);
8
+ constructor(type: TaskType, queryDescription: QueryDescription, executionConfig: QueryExecutionConfigInternal);
9
9
  }
10
10
  export {};
@@ -1,9 +1,9 @@
1
1
  import { TaskPassport } from '@sisense/task-manager';
2
2
  export class QueryTaskPassport extends TaskPassport {
3
- constructor(type, queryDescription, shouldSkipHighlightsWithoutAttributes) {
3
+ constructor(type, queryDescription, executionConfig) {
4
4
  super();
5
5
  this.queryDescription = queryDescription;
6
6
  this.type = type;
7
- this.shouldSkipHighlightsWithoutAttributes = shouldSkipHighlightsWithoutAttributes !== null && shouldSkipHighlightsWithoutAttributes !== void 0 ? shouldSkipHighlightsWithoutAttributes : false;
7
+ this.executionConfig = executionConfig;
8
8
  }
9
9
  }
package/dist/types.d.ts CHANGED
@@ -11,6 +11,18 @@ export type QueryDescription = {
11
11
  count?: number;
12
12
  offset?: number;
13
13
  };
14
+ /**
15
+ * Additional configuration for query execution.
16
+ */
17
+ export type QueryExecutionConfig = {
18
+ /**
19
+ * Sync or async callback that allows to modify the JAQL payload before it is sent to the server.
20
+ */
21
+ onBeforeQuery?: (jaql: JaqlQueryPayload) => JaqlQueryPayload | Promise<JaqlQueryPayload>;
22
+ };
23
+ export type QueryExecutionConfigInternal = QueryExecutionConfig & {
24
+ shouldSkipHighlightsWithoutAttributes: boolean;
25
+ };
14
26
  export type QueryOptions = {
15
27
  datasource: string;
16
28
  by: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sisense/sdk-query-client",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "type": "module",
5
5
  "exports": "./dist/index.js",
6
6
  "main": "./dist/index.js",
@@ -9,9 +9,9 @@
9
9
  "author": "Sisense",
10
10
  "license": "SEE LICENSE IN LICENSE.md",
11
11
  "dependencies": {
12
- "@sisense/sdk-common": "^0.12.0",
13
- "@sisense/sdk-data": "^0.12.0",
14
- "@sisense/sdk-rest-client": "^0.12.0",
12
+ "@sisense/sdk-common": "^0.13.0",
13
+ "@sisense/sdk-data": "^0.13.0",
14
+ "@sisense/sdk-rest-client": "^0.13.0",
15
15
  "@sisense/task-manager": "^0.1.0",
16
16
  "numeral": "^2.0.6",
17
17
  "uuid": "^9.0.0"