@sisense/sdk-query-client 1.20.0 → 1.22.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.
Files changed (48) hide show
  1. package/dist/cjs/helpers/utility-types.d.ts +2 -0
  2. package/dist/cjs/helpers/utility-types.js +2 -0
  3. package/dist/cjs/index.d.ts +5 -0
  4. package/dist/cjs/index.js +24 -0
  5. package/dist/cjs/interfaces.d.ts +10 -0
  6. package/dist/cjs/interfaces.js +2 -0
  7. package/dist/cjs/jaql/get-jaql-query-payload.d.ts +15 -0
  8. package/dist/cjs/jaql/get-jaql-query-payload.js +133 -0
  9. package/dist/cjs/jaql/metadata/highlights.d.ts +5 -0
  10. package/dist/cjs/jaql/metadata/highlights.js +43 -0
  11. package/dist/cjs/jaql/metadata/index.d.ts +1 -0
  12. package/dist/cjs/jaql/metadata/index.js +17 -0
  13. package/dist/cjs/jaql/pivot/pivot-query-utils.d.ts +38 -0
  14. package/dist/cjs/jaql/pivot/pivot-query-utils.js +83 -0
  15. package/dist/cjs/package.json +12 -0
  16. package/dist/cjs/query-api-dispatcher/query-api-dispatcher.d.ts +39 -0
  17. package/dist/cjs/query-api-dispatcher/query-api-dispatcher.js +148 -0
  18. package/dist/cjs/query-client.d.ts +56 -0
  19. package/dist/cjs/query-client.js +203 -0
  20. package/dist/cjs/query-result/get-data-from-query-result.d.ts +12 -0
  21. package/dist/cjs/query-result/get-data-from-query-result.js +77 -0
  22. package/dist/cjs/query-result/index.d.ts +1 -0
  23. package/dist/cjs/query-result/index.js +17 -0
  24. package/dist/cjs/query-task-manager/query-task-manager.d.ts +40 -0
  25. package/dist/cjs/query-task-manager/query-task-manager.js +133 -0
  26. package/dist/cjs/query-task-manager/query-task-passport.d.ts +16 -0
  27. package/dist/cjs/query-task-manager/query-task-passport.js +22 -0
  28. package/dist/cjs/translation/initialize-i18n.d.ts +2 -0
  29. package/dist/cjs/translation/initialize-i18n.js +14 -0
  30. package/dist/cjs/translation/resources/en.d.ts +16 -0
  31. package/dist/cjs/translation/resources/en.js +18 -0
  32. package/dist/cjs/translation/resources/index.d.ts +35 -0
  33. package/dist/cjs/translation/resources/index.js +10 -0
  34. package/dist/cjs/translation/resources/uk.d.ts +2 -0
  35. package/dist/cjs/translation/resources/uk.js +18 -0
  36. package/dist/cjs/translation/translatable-error.d.ts +6 -0
  37. package/dist/cjs/translation/translatable-error.js +18 -0
  38. package/dist/cjs/types.d.ts +209 -0
  39. package/dist/cjs/types.js +8 -0
  40. package/dist/query-api-dispatcher/query-api-dispatcher.js +4 -1
  41. package/dist/query-client.js +1 -1
  42. package/dist/query-task-manager/query-task-manager.js +2 -1
  43. package/dist/translation/resources/en.d.ts +2 -0
  44. package/dist/translation/resources/en.js +2 -0
  45. package/dist/translation/resources/index.d.ts +4 -0
  46. package/dist/translation/resources/uk.js +11 -9
  47. package/dist/tsconfig.prod.cjs.tsbuildinfo +1 -0
  48. package/package.json +6 -6
@@ -0,0 +1,203 @@
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.validatePivotQueryDescription = exports.validateQueryDescription = exports.DimensionalQueryClient = exports.QUERY_DEFAULT_LIMIT = void 0;
13
+ const query_task_manager_js_1 = require("./query-task-manager/query-task-manager.js");
14
+ const query_task_passport_js_1 = require("./query-task-manager/query-task-passport.js");
15
+ const task_manager_1 = require("@sisense/task-manager");
16
+ const query_api_dispatcher_js_1 = require("./query-api-dispatcher/query-api-dispatcher.js");
17
+ const sdk_data_1 = require("@sisense/sdk-data");
18
+ const translatable_error_js_1 = require("./translation/translatable-error.js");
19
+ const sdk_pivot_client_1 = require("@sisense/sdk-pivot-client");
20
+ /** @internal */
21
+ exports.QUERY_DEFAULT_LIMIT = 20000;
22
+ const UNSPECIFIED_REASON = 'Unspecified reason';
23
+ class DimensionalQueryClient {
24
+ constructor(httpClient, pivotClient = new sdk_pivot_client_1.PivotClient(httpClient.url, httpClient.auth), shouldSkipHighlightsWithoutAttributes) {
25
+ validateHttpClient(httpClient);
26
+ this.queryApi = new query_api_dispatcher_js_1.QueryApiDispatcher(httpClient);
27
+ this.taskManager = new query_task_manager_js_1.QueryTaskManager(this.queryApi, pivotClient);
28
+ this.shouldSkipHighlightsWithoutAttributes = shouldSkipHighlightsWithoutAttributes !== null && shouldSkipHighlightsWithoutAttributes !== void 0 ? shouldSkipHighlightsWithoutAttributes : false;
29
+ }
30
+ /**
31
+ * Executes query
32
+ *
33
+ * @param queryDescription - all options that describe query
34
+ * @param config - query execution configuration
35
+ * @returns promise that resolves to query result data and cancel function that can be used to cancel sent query
36
+ * @throws Error if query description is invalid
37
+ */
38
+ executeQuery(queryDescription, config) {
39
+ const taskPassport = new query_task_passport_js_1.QueryTaskPassport('SEND_JAQL_QUERY', queryDescription, Object.assign(Object.assign({}, (config ? config : {})), { shouldSkipHighlightsWithoutAttributes: this.shouldSkipHighlightsWithoutAttributes || false }));
40
+ return {
41
+ resultPromise: new Promise((resolve, reject) => {
42
+ validateQueryDescription(queryDescription);
43
+ void this.taskManager.executeQuerySending(taskPassport).then((executionResult) => {
44
+ if (executionResult.status === task_manager_1.ExecutionResultStatus.SUCCESS) {
45
+ resolve(executionResult.result);
46
+ }
47
+ else {
48
+ reject(executionResult.error);
49
+ }
50
+ });
51
+ }),
52
+ cancel: (reason) => this.taskManager.cancel(taskPassport.taskId, reason || UNSPECIFIED_REASON),
53
+ };
54
+ }
55
+ executeCsvQuery(queryDescription, config) {
56
+ const taskPassport = new query_task_passport_js_1.QueryTaskPassport('SEND_DOWNLOAD_CSV_QUERY', queryDescription, Object.assign(Object.assign({}, (config ? config : {})), { shouldSkipHighlightsWithoutAttributes: this.shouldSkipHighlightsWithoutAttributes || false }));
57
+ return {
58
+ resultPromise: new Promise((resolve, reject) => {
59
+ validateQueryDescription(queryDescription);
60
+ void this.taskManager.executeDownloadCsvSending(taskPassport).then((executionResult) => {
61
+ if (executionResult.status === task_manager_1.ExecutionResultStatus.SUCCESS) {
62
+ resolve(executionResult.result);
63
+ }
64
+ else {
65
+ reject(executionResult.error);
66
+ }
67
+ });
68
+ }),
69
+ cancel: (reason) => this.taskManager.cancel(taskPassport.taskId, reason || UNSPECIFIED_REASON),
70
+ };
71
+ }
72
+ /**
73
+ * Executes pivot query
74
+ *
75
+ * @param pivotQueryDescription - all options that describe the pivot query
76
+ * @param config - query execution configuration
77
+ * @returns promise that resolves to pivot query result data and cancel function that can be used to cancel sent query
78
+ * @throws Error if query description is invalid
79
+ */
80
+ executePivotQuery(pivotQueryDescription, config) {
81
+ const taskPassport = new query_task_passport_js_1.PivotQueryTaskPassport('SEND_JAQL_QUERY', pivotQueryDescription, Object.assign(Object.assign({}, (config ? config : {})), { shouldSkipHighlightsWithoutAttributes: this.shouldSkipHighlightsWithoutAttributes || false }));
82
+ return {
83
+ resultPromise: new Promise((resolve, reject) => {
84
+ validatePivotQueryDescription(pivotQueryDescription);
85
+ void this.taskManager.executePivotQuerySending(taskPassport).then((executionResult) => {
86
+ if (executionResult.status === task_manager_1.ExecutionResultStatus.SUCCESS) {
87
+ resolve(executionResult.result);
88
+ }
89
+ else {
90
+ reject(executionResult.error);
91
+ }
92
+ });
93
+ }),
94
+ cancel: (reason) => this.taskManager.cancel(taskPassport.taskId, reason || UNSPECIFIED_REASON),
95
+ };
96
+ }
97
+ getDataSourceFields(dataSource, count = 9999, offset = 0) {
98
+ return __awaiter(this, void 0, void 0, function* () {
99
+ const dataSourceFields = yield this.queryApi.getDataSourceFields(dataSource, count, offset);
100
+ return dataSourceFields || [];
101
+ });
102
+ }
103
+ /**
104
+ * Returns the schema of a data source by its name.
105
+ */
106
+ getDataSourceSchema(datasourceName) {
107
+ return this.queryApi.getDataSourceSchema(datasourceName);
108
+ }
109
+ /**
110
+ * Returns a list of data sources
111
+ */
112
+ getDataSourceList() {
113
+ return __awaiter(this, void 0, void 0, function* () {
114
+ const dataSourceList = yield this.queryApi.getDataSourceList();
115
+ return dataSourceList || [];
116
+ });
117
+ }
118
+ }
119
+ exports.DimensionalQueryClient = DimensionalQueryClient;
120
+ /**
121
+ * Validates query description
122
+ *
123
+ * @param queryDescription - query description to validate
124
+ * @param config - query execution configuration
125
+ * @throws Error if query description is invalid
126
+ */
127
+ function validateQueryDescription(queryDescription) {
128
+ const { attributes, measures, filters, highlights, count, offset } = queryDescription;
129
+ if (count && count < 0) {
130
+ throw new translatable_error_js_1.TranslatableError('errors.invalidCountNegative', { count: count.toString() });
131
+ }
132
+ if (offset && offset < 0) {
133
+ throw new translatable_error_js_1.TranslatableError('errors.invalidOffset', { offset: offset.toString() });
134
+ }
135
+ if (attributes.length + measures.length === 0) {
136
+ throw new translatable_error_js_1.TranslatableError('errors.noDimensionsOrMeasures');
137
+ }
138
+ attributes.forEach((attribute) => {
139
+ if (!attribute.skipValidation && !sdk_data_1.MetadataTypes.isAttribute(attribute)) {
140
+ const { name: attributeName } = attribute;
141
+ throw new translatable_error_js_1.TranslatableError('errors.invalidAttribute', { attributeName });
142
+ }
143
+ });
144
+ measures.forEach((measure) => {
145
+ if (!measure.skipValidation && !sdk_data_1.MetadataTypes.isMeasure(measure)) {
146
+ throw new translatable_error_js_1.TranslatableError('errors.invalidMeasure', { measureName: measure.name });
147
+ }
148
+ });
149
+ filters.forEach((filter) => {
150
+ if (!filter.skipValidation && !sdk_data_1.MetadataTypes.isFilter(filter)) {
151
+ throw new translatable_error_js_1.TranslatableError('errors.invalidFilter', { filterName: filter.name });
152
+ }
153
+ });
154
+ highlights.forEach((highlight) => {
155
+ if (!highlight.skipValidation && !sdk_data_1.MetadataTypes.isFilter(highlight)) {
156
+ throw new translatable_error_js_1.TranslatableError('errors.invalidHighlight', { highlightName: highlight.name });
157
+ }
158
+ });
159
+ }
160
+ exports.validateQueryDescription = validateQueryDescription;
161
+ /**
162
+ * Validates pivot query description
163
+ *
164
+ * @param queryDescription - pivot query description to validate
165
+ * @throws Error if query description is invalid
166
+ */
167
+ function validatePivotQueryDescription(queryDescription) {
168
+ const { rowsAttributes, columnsAttributes, measures, filters, highlights, count, offset } = queryDescription;
169
+ if (count && count < 0) {
170
+ throw new translatable_error_js_1.TranslatableError('errors.invalidCountNegative', { count: count.toString() });
171
+ }
172
+ if (offset && offset < 0) {
173
+ throw new translatable_error_js_1.TranslatableError('errors.invalidOffset', { offset: offset.toString() });
174
+ }
175
+ if (rowsAttributes.length + columnsAttributes.length + measures.length === 0) {
176
+ throw new translatable_error_js_1.TranslatableError('errors.noDimensionsOrMeasures');
177
+ }
178
+ filters.forEach((filter) => {
179
+ if (!filter.skipValidation && !sdk_data_1.MetadataTypes.isFilter(filter)) {
180
+ throw new translatable_error_js_1.TranslatableError('errors.invalidFilter', { filterName: filter.name });
181
+ }
182
+ });
183
+ highlights.forEach((highlight) => {
184
+ if (!highlight.skipValidation && !sdk_data_1.MetadataTypes.isFilter(highlight)) {
185
+ throw new translatable_error_js_1.TranslatableError('errors.invalidHighlight', { highlightName: highlight.name });
186
+ }
187
+ });
188
+ }
189
+ exports.validatePivotQueryDescription = validatePivotQueryDescription;
190
+ /**
191
+ * Validates http client
192
+ *
193
+ * @param httpClient - http client to validate
194
+ * @throws Error if http client is invalid
195
+ */
196
+ function validateHttpClient(httpClient) {
197
+ if (!httpClient) {
198
+ throw new translatable_error_js_1.TranslatableError('errors.missingHttpClient');
199
+ }
200
+ if (!httpClient.post) {
201
+ throw new translatable_error_js_1.TranslatableError('errors.missingPostMethod');
202
+ }
203
+ }
@@ -0,0 +1,12 @@
1
+ import { Cell, DataCell, Element, QueryResultData } from '@sisense/sdk-data';
2
+ import { JaqlResponse } from '../types.js';
3
+ export declare const getDataFromQueryResult: (result: JaqlResponse, metadata: Element[]) => QueryResultData;
4
+ export declare function prepareResultAsColsAndRows(data: DataCell[][], metadata: Element[]): QueryResultData;
5
+ /**
6
+ * Sets the `blur` property for each cell in a 2D array of data cells based on the `selected` property.
7
+ *
8
+ * @param rows - The 2D array of data cells representing rows and columns.
9
+ * @returns A new 2D array of cells with the `blur` property set.
10
+ */
11
+ export declare function setCellsBlur(rows: DataCell[][]): Cell[][];
12
+ export declare function getQueryResultValues({ values, metadata }: JaqlResponse): DataCell[][];
@@ -0,0 +1,77 @@
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.getQueryResultValues = exports.setCellsBlur = exports.prepareResultAsColsAndRows = exports.getDataFromQueryResult = void 0;
7
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
8
+ const numeral_1 = __importDefault(require("numeral"));
9
+ const sdk_data_1 = require("@sisense/sdk-data");
10
+ const getDataFromQueryResult = (result, metadata) => {
11
+ const values = getQueryResultValues(result);
12
+ return prepareResultAsColsAndRows(values, metadata);
13
+ };
14
+ exports.getDataFromQueryResult = getDataFromQueryResult;
15
+ function prepareResultAsColsAndRows(data, metadata) {
16
+ return {
17
+ columns: metadata === null || metadata === void 0 ? void 0 : metadata.map((d) => ({
18
+ name: d.name,
19
+ type: (0, sdk_data_1.simpleColumnType)(d.type),
20
+ })),
21
+ rows: setCellsBlur(data),
22
+ };
23
+ }
24
+ exports.prepareResultAsColsAndRows = prepareResultAsColsAndRows;
25
+ /**
26
+ * Sets the `blur` property for each cell in a 2D array of data cells based on the `selected` property.
27
+ *
28
+ * @param rows - The 2D array of data cells representing rows and columns.
29
+ * @returns A new 2D array of cells with the `blur` property set.
30
+ */
31
+ function setCellsBlur(rows) {
32
+ var _a;
33
+ // A boolean flag indicating whether highlight is enabled on some column.
34
+ let isHighlightEnabledSomeColumn = false;
35
+ // An array indicating whether highlight is enabled per each column.
36
+ const highlightEnabledPerColumn = (_a = rows[0]) === null || _a === void 0 ? void 0 : _a.map((_value, index) => {
37
+ const isHighlightEnabled = rows.some((r) => 'selected' in r[index]);
38
+ if (isHighlightEnabled) {
39
+ isHighlightEnabledSomeColumn = true;
40
+ }
41
+ return isHighlightEnabled;
42
+ });
43
+ return rows.map((r) => {
44
+ // calculates a single `blur` value for a whole row based on each column (cell) configuration.
45
+ // true: the data value is blurred
46
+ // false: the data value is highlighted
47
+ // undefined: the data value is neutral (neither highlighted nor blurred)
48
+ const blur = !isHighlightEnabledSomeColumn
49
+ ? undefined
50
+ : highlightEnabledPerColumn.some((isHighlightEnabled, columnIndex) => isHighlightEnabled && !r[columnIndex].selected);
51
+ return r.map((d) => blur !== undefined
52
+ ? {
53
+ data: d.data,
54
+ text: d.text,
55
+ blur,
56
+ }
57
+ : { data: d.data, text: d.text });
58
+ });
59
+ }
60
+ exports.setCellsBlur = setCellsBlur;
61
+ function getQueryResultValues({ values = [], metadata = [] }) {
62
+ var _a, _b, _c, _d;
63
+ // fixing measures query result
64
+ if (values[0] && !Array.isArray(values[0])) {
65
+ values = [values];
66
+ }
67
+ for (let i = 0; i < values.length; i++) {
68
+ const row = values[i];
69
+ for (let c = 0; c < row.length; c++) {
70
+ if (metadata[c].format && ((_b = (_a = metadata[c]) === null || _a === void 0 ? void 0 : _a.format) === null || _b === void 0 ? void 0 : _b.number)) {
71
+ row[c].text = (0, numeral_1.default)(row[c].data).format((_d = (_c = metadata[c]) === null || _c === void 0 ? void 0 : _c.format) === null || _d === void 0 ? void 0 : _d.number);
72
+ }
73
+ }
74
+ }
75
+ return values;
76
+ }
77
+ exports.getQueryResultValues = getQueryResultValues;
@@ -0,0 +1 @@
1
+ export * from './get-data-from-query-result.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("./get-data-from-query-result.js"), exports);
@@ -0,0 +1,40 @@
1
+ import { AbstractTaskManager } from '@sisense/task-manager';
2
+ import { JaqlResponse } from '../types.js';
3
+ import { PivotQueryTaskPassport, QueryTaskPassport } from './query-task-passport.js';
4
+ import { QueryResultData, PivotQueryResultData } from '@sisense/sdk-data';
5
+ import { QueryApiDispatcher } from '../query-api-dispatcher/query-api-dispatcher.js';
6
+ import { PivotClient } from '@sisense/sdk-pivot-client';
7
+ import { EmptyObject } from '../helpers/utility-types.js';
8
+ export declare class QueryTaskManager extends AbstractTaskManager {
9
+ /** Map of aborters by task id to be able to cancel sent requests */
10
+ private sentRequestsAbortersMap;
11
+ private queryApi;
12
+ /**
13
+ * Client for handling pivot data
14
+ */
15
+ private pivotClient;
16
+ constructor(queryApi: QueryApiDispatcher, pivotClient: PivotClient);
17
+ private prepareJaqlPayload;
18
+ private sendJaqlQuery;
19
+ private sendCsvQuery;
20
+ private cancelDataRetrievalQuery;
21
+ /**
22
+ * Prepares the JAQL payload for the pivot query
23
+ *
24
+ * @param task
25
+ * @returns JAQL payload
26
+ */
27
+ private preparePivotJaqlPayload;
28
+ /**
29
+ * Executes the pivot query and returns the result
30
+ *
31
+ * @param task
32
+ * @param jaqlPayload
33
+ */
34
+ private sendPivotJaqlQuery;
35
+ private cancelPivotJaqlQuery;
36
+ executeQuerySending: (passport: QueryTaskPassport) => Promise<import("@sisense/task-manager").TaskExecutionResult<QueryResultData, EmptyObject>>;
37
+ executeDownloadCsvSending: (passport: QueryTaskPassport) => Promise<import("@sisense/task-manager").TaskExecutionResult<Blob, EmptyObject>>;
38
+ executePivotQuerySending: (passport: PivotQueryTaskPassport) => Promise<import("@sisense/task-manager").TaskExecutionResult<PivotQueryResultData, EmptyObject>>;
39
+ }
40
+ export declare function validateJaqlResponse(jaqlResponse: JaqlResponse | undefined): asserts jaqlResponse is JaqlResponse;
@@ -0,0 +1,133 @@
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.validateJaqlResponse = exports.QueryTaskManager = void 0;
13
+ const task_manager_1 = require("@sisense/task-manager");
14
+ const get_jaql_query_payload_js_1 = require("../jaql/get-jaql-query-payload.js");
15
+ const index_js_1 = require("../query-result/index.js");
16
+ const query_client_js_1 = require("../query-client.js");
17
+ const translatable_error_js_1 = require("../translation/translatable-error.js");
18
+ class QueryTaskManager extends task_manager_1.AbstractTaskManager {
19
+ constructor(queryApi, pivotClient) {
20
+ super();
21
+ /** Map of aborters by task id to be able to cancel sent requests */
22
+ this.sentRequestsAbortersMap = new Map();
23
+ this.executeQuerySending = super.createFlow([
24
+ new task_manager_1.Step('PREPARE_JAQL_PAYLOAD', this.prepareJaqlPayload.bind(this), () => __awaiter(this, void 0, void 0, function* () { })),
25
+ new task_manager_1.Step('SEND_JAQL_QUERY', this.sendJaqlQuery.bind(this), this.cancelDataRetrievalQuery.bind(this)),
26
+ ]);
27
+ this.executeDownloadCsvSending = super.createFlow([
28
+ new task_manager_1.Step('PREPARE_JAQL_PAYLOAD', this.prepareJaqlPayload.bind(this), () => __awaiter(this, void 0, void 0, function* () { })),
29
+ new task_manager_1.Step('SEND_DOWNLOAD_CSV_QUERY', this.sendCsvQuery.bind(this), this.cancelDataRetrievalQuery.bind(this)),
30
+ ]);
31
+ this.executePivotQuerySending = super.createFlow([
32
+ new task_manager_1.Step('PREPARE_JAQL_PAYLOAD', this.preparePivotJaqlPayload.bind(this), () => __awaiter(this, void 0, void 0, function* () { })),
33
+ new task_manager_1.Step('SEND_JAQL_QUERY', this.sendPivotJaqlQuery.bind(this), this.cancelPivotJaqlQuery.bind(this)),
34
+ ]);
35
+ this.queryApi = queryApi;
36
+ this.pivotClient = pivotClient;
37
+ }
38
+ prepareJaqlPayload(task) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ const { queryDescription, executionConfig } = task.passport;
41
+ const jaqlPayload = (0, get_jaql_query_payload_js_1.getJaqlQueryPayload)(queryDescription, executionConfig.shouldSkipHighlightsWithoutAttributes);
42
+ const onBeforeQuery = task.passport.executionConfig.onBeforeQuery;
43
+ if (onBeforeQuery) {
44
+ return onBeforeQuery(jaqlPayload);
45
+ }
46
+ return jaqlPayload;
47
+ });
48
+ }
49
+ sendJaqlQuery(task, jaqlPayload) {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ const { queryDescription, taskId } = task.passport;
52
+ const { responsePromise, abortHttpRequest } = this.queryApi.sendJaqlRequest(task.passport.queryDescription.dataSource, jaqlPayload);
53
+ this.sentRequestsAbortersMap.set(taskId, abortHttpRequest);
54
+ const jaqlResponse = yield responsePromise.finally(() => {
55
+ this.sentRequestsAbortersMap.delete(taskId);
56
+ });
57
+ validateJaqlResponse(jaqlResponse);
58
+ const metadata = [...queryDescription.attributes, ...queryDescription.measures];
59
+ // extra columns are assumed to have been added by advanced analytics functions
60
+ const extraColumns = (jaqlResponse.headers || [])
61
+ .slice(metadata.length)
62
+ .map((c) => ({ name: c, type: 'number' }));
63
+ return (0, index_js_1.getDataFromQueryResult)(jaqlResponse, [...metadata, ...extraColumns]);
64
+ });
65
+ }
66
+ sendCsvQuery(task, jaqlPayload) {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ const { taskId } = task.passport;
69
+ const { responsePromise, abortHttpRequest } = this.queryApi.sendDownloadCsvRequest(task.passport.queryDescription.dataSource, jaqlPayload);
70
+ this.sentRequestsAbortersMap.set(taskId, abortHttpRequest);
71
+ return responsePromise.finally(() => {
72
+ this.sentRequestsAbortersMap.delete(taskId);
73
+ });
74
+ });
75
+ }
76
+ cancelDataRetrievalQuery(task) {
77
+ const taskId = task.passport.taskId;
78
+ const abortInitialRequest = this.sentRequestsAbortersMap.get(taskId);
79
+ if (abortInitialRequest) {
80
+ abortInitialRequest();
81
+ this.sentRequestsAbortersMap.delete(taskId);
82
+ }
83
+ return this.queryApi.sendCancelJaqlQueryRequest(taskId, task.passport.queryDescription.dataSource);
84
+ }
85
+ /**
86
+ * Prepares the JAQL payload for the pivot query
87
+ *
88
+ * @param task
89
+ * @returns JAQL payload
90
+ */
91
+ preparePivotJaqlPayload(task) {
92
+ return __awaiter(this, void 0, void 0, function* () {
93
+ const { pivotQueryDescription, executionConfig } = task.passport;
94
+ const jaqlPayload = (0, get_jaql_query_payload_js_1.getPivotJaqlQueryPayload)(pivotQueryDescription, executionConfig.shouldSkipHighlightsWithoutAttributes);
95
+ const onBeforeQuery = task.passport.executionConfig.onBeforeQuery;
96
+ if (onBeforeQuery) {
97
+ return onBeforeQuery(jaqlPayload);
98
+ }
99
+ return jaqlPayload;
100
+ });
101
+ }
102
+ /**
103
+ * Executes the pivot query and returns the result
104
+ *
105
+ * @param task
106
+ * @param jaqlPayload
107
+ */
108
+ sendPivotJaqlQuery(task, jaqlPayload) {
109
+ var _a;
110
+ const { pivotQueryDescription } = task.passport;
111
+ return this.pivotClient.queryData(jaqlPayload, true, (_a = pivotQueryDescription.count) !== null && _a !== void 0 ? _a : query_client_js_1.QUERY_DEFAULT_LIMIT, false);
112
+ }
113
+ cancelPivotJaqlQuery(task) {
114
+ const taskId = task.passport.taskId;
115
+ const abortInitialRequest = this.sentRequestsAbortersMap.get(taskId);
116
+ if (abortInitialRequest) {
117
+ abortInitialRequest();
118
+ this.sentRequestsAbortersMap.delete(taskId);
119
+ }
120
+ return this.queryApi.sendCancelJaqlQueryRequest(taskId, task.passport.pivotQueryDescription.dataSource);
121
+ }
122
+ }
123
+ exports.QueryTaskManager = QueryTaskManager;
124
+ function validateJaqlResponse(jaqlResponse) {
125
+ var _a;
126
+ if (!jaqlResponse) {
127
+ throw new translatable_error_js_1.TranslatableError('errors.noJaqlResponse');
128
+ }
129
+ if (jaqlResponse.error) {
130
+ throw new Error(`${jaqlResponse.details} ${(_a = jaqlResponse.database) !== null && _a !== void 0 ? _a : ''} ${jaqlResponse.extraDetails ? JSON.stringify(jaqlResponse.extraDetails) : ''}`);
131
+ }
132
+ }
133
+ exports.validateJaqlResponse = validateJaqlResponse;
@@ -0,0 +1,16 @@
1
+ import { TaskPassport } from '@sisense/task-manager';
2
+ import { PivotQueryDescription, QueryDescription, QueryExecutionConfigInternal } from '../types.js';
3
+ type TaskType = 'SEND_JAQL_QUERY' | 'SEND_DOWNLOAD_CSV_QUERY';
4
+ export declare class QueryTaskPassport extends TaskPassport {
5
+ queryDescription: QueryDescription;
6
+ executionConfig: QueryExecutionConfigInternal;
7
+ type: TaskType;
8
+ constructor(type: TaskType, queryDescription: QueryDescription, executionConfig: QueryExecutionConfigInternal);
9
+ }
10
+ export declare class PivotQueryTaskPassport extends TaskPassport {
11
+ pivotQueryDescription: PivotQueryDescription;
12
+ executionConfig: QueryExecutionConfigInternal;
13
+ type: TaskType;
14
+ constructor(type: TaskType, pivotQueryDescription: PivotQueryDescription, executionConfig: QueryExecutionConfigInternal);
15
+ }
16
+ export {};
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PivotQueryTaskPassport = exports.QueryTaskPassport = void 0;
4
+ const task_manager_1 = require("@sisense/task-manager");
5
+ class QueryTaskPassport extends task_manager_1.TaskPassport {
6
+ constructor(type, queryDescription, executionConfig) {
7
+ super();
8
+ this.queryDescription = queryDescription;
9
+ this.type = type;
10
+ this.executionConfig = executionConfig;
11
+ }
12
+ }
13
+ exports.QueryTaskPassport = QueryTaskPassport;
14
+ class PivotQueryTaskPassport extends task_manager_1.TaskPassport {
15
+ constructor(type, pivotQueryDescription, executionConfig) {
16
+ super();
17
+ this.pivotQueryDescription = pivotQueryDescription;
18
+ this.type = type;
19
+ this.executionConfig = executionConfig;
20
+ }
21
+ }
22
+ exports.PivotQueryTaskPassport = PivotQueryTaskPassport;
@@ -0,0 +1,2 @@
1
+ export declare function initializeI18n(): import("@sisense/sdk-common").I18NextInitResult;
2
+ export declare const i18nextInstance: import("i18next").i18n;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.i18nextInstance = exports.initializeI18n = void 0;
4
+ const sdk_common_1 = require("@sisense/sdk-common");
5
+ const index_js_1 = require("./resources/index.js");
6
+ function initializeI18n() {
7
+ return (0, sdk_common_1.initI18next)({
8
+ resource: index_js_1.resources,
9
+ language: 'en',
10
+ namespace: index_js_1.PACKAGE_NAMESPACE,
11
+ });
12
+ }
13
+ exports.initializeI18n = initializeI18n;
14
+ exports.i18nextInstance = initializeI18n().i18nextInstance;
@@ -0,0 +1,16 @@
1
+ export declare const translation: {
2
+ errors: {
3
+ invalidAttribute: string;
4
+ noDimensionsOrMeasures: string;
5
+ invalidMeasure: string;
6
+ invalidFilter: string;
7
+ invalidHighlight: string;
8
+ invalidCountNegative: string;
9
+ invalidOffset: string;
10
+ missingHttpClient: string;
11
+ missingPostMethod: string;
12
+ noJaqlResponse: string;
13
+ dataSourceNotFound: string;
14
+ };
15
+ };
16
+ export type TranslationDictionary = typeof translation;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.translation = void 0;
4
+ exports.translation = {
5
+ errors: {
6
+ invalidAttribute: 'Invalid attribute {{attributeName}}. Hint: attributes for query should be extracted from the data model generated by the CLI tool.',
7
+ noDimensionsOrMeasures: 'Neither dimensions nor measures found. Query should have at least one dimension or measure.',
8
+ invalidMeasure: 'Invalid measure "{{measureName}}". Hint: measures for the query can be constructed using the "measureFactory" functions.',
9
+ invalidFilter: 'Invalid filter "{{filterName}}". Hint: filters for the query can be constructed using the "filterFactory" functions.',
10
+ invalidHighlight: 'Invalid highlight "{{highlightName}}". Hint: highlights for the query can be constructed using the "filterFactory" functions.',
11
+ invalidCountNegative: 'Invalid count "{{count}}". Count should be non-negative.',
12
+ invalidOffset: 'Invalid offset "{{offset}}". Offset should be non-negative.',
13
+ missingHttpClient: 'Query requires httpClient to work properly.',
14
+ missingPostMethod: 'httpClient must provide "post" method.',
15
+ noJaqlResponse: 'No jaql response received from the server',
16
+ dataSourceNotFound: 'Failed to get fields for data source "{{dataSource}}". Please make sure the data source exists and is accessible.',
17
+ },
18
+ };
@@ -0,0 +1,35 @@
1
+ import { TranslationDictionary } from './en.js';
2
+ export type { TranslationDictionary };
3
+ export declare const PACKAGE_NAMESPACE: "sdkQueryClient";
4
+ export declare const resources: {
5
+ en: {
6
+ errors: {
7
+ invalidAttribute: string;
8
+ noDimensionsOrMeasures: string;
9
+ invalidMeasure: string;
10
+ invalidFilter: string;
11
+ invalidHighlight: string;
12
+ invalidCountNegative: string;
13
+ invalidOffset: string;
14
+ missingHttpClient: string;
15
+ missingPostMethod: string;
16
+ noJaqlResponse: string;
17
+ dataSourceNotFound: string;
18
+ };
19
+ };
20
+ uk: {
21
+ errors: {
22
+ invalidAttribute: string;
23
+ noDimensionsOrMeasures: string;
24
+ invalidMeasure: string;
25
+ invalidFilter: string;
26
+ invalidHighlight: string;
27
+ invalidCountNegative: string;
28
+ invalidOffset: string;
29
+ missingHttpClient: string;
30
+ missingPostMethod: string;
31
+ noJaqlResponse: string;
32
+ dataSourceNotFound: string;
33
+ };
34
+ };
35
+ };
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resources = exports.PACKAGE_NAMESPACE = void 0;
4
+ const en_js_1 = require("./en.js");
5
+ const uk_js_1 = require("./uk.js");
6
+ exports.PACKAGE_NAMESPACE = 'sdkQueryClient';
7
+ exports.resources = {
8
+ en: en_js_1.translation,
9
+ uk: uk_js_1.translation,
10
+ };
@@ -0,0 +1,2 @@
1
+ import { TranslationDictionary } from './index.js';
2
+ export declare const translation: TranslationDictionary;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.translation = void 0;
4
+ exports.translation = {
5
+ errors: {
6
+ invalidAttribute: 'Недійсний атрибут {{attributeName}}. Підказка: атрибути для запиту повинні бути витягнуті з моделі даних, створеної за допомогою CLI-інструменту.',
7
+ noDimensionsOrMeasures: 'Не знайдено ні вимірів, ні показників. Запит повинен мати щонайменше один вимір або показник.',
8
+ invalidMeasure: 'Недійсний показник "{{measureName}}". Підказка: показники для запиту можна створити за допомогою функцій "measureFactory".',
9
+ invalidFilter: 'Недійсний фільтр "{{filterName}}". Підказка: фільтри для запиту можна створити за допомогою функцій "filterFactory".',
10
+ invalidHighlight: 'Недійсне виділення "{{highlightName}}". Підказка: виділення для запиту можна створити за допомогою функцій "filterFactory".',
11
+ invalidCountNegative: 'Недійсний count "{{count}}". Count повинен бути не від\'ємним.',
12
+ invalidOffset: 'Недійсний offset "{{offset}}". Offset повинен бути не від\'ємним.',
13
+ missingHttpClient: 'Для запиту потрібен httpClient, щоб працювати належним чином.',
14
+ missingPostMethod: 'httpClient повинен мати метод "post".',
15
+ noJaqlResponse: 'Відповіді, що містить jaql, від сервера не отримано',
16
+ dataSourceNotFound: 'Не вдалося отримати поля для джерела даних "{{dataSource}}". Переконайтесь що джерело існує і доступне.',
17
+ },
18
+ };