@sisense/sdk-query-client 0.11.3 → 0.12.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/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/query-client.d.ts +7 -0
- package/dist/query-client.js +19 -13
- package/dist/translation/initialize-i18n.d.ts +2 -0
- package/dist/translation/initialize-i18n.js +10 -0
- package/dist/translation/resources/en.d.ts +15 -0
- package/dist/translation/resources/en.js +14 -0
- package/dist/translation/resources/index.d.ts +33 -0
- package/dist/translation/resources/index.js +7 -0
- package/dist/translation/resources/uk.d.ts +2 -0
- package/dist/translation/resources/uk.js +14 -0
- package/dist/translation/translatable-error.d.ts +5 -0
- package/dist/translation/translatable-error.js +11 -0
- package/package.json +4 -3
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/query-client.d.ts
CHANGED
|
@@ -19,3 +19,10 @@ export declare class DimensionalQueryClient implements QueryClient {
|
|
|
19
19
|
executeQuery(queryDescription: QueryDescription): ExecutingQueryResult;
|
|
20
20
|
getDataSourceFields(dataSource: DataSource, count?: number, offset?: number): Promise<DataSourceField[]>;
|
|
21
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Validates query description
|
|
24
|
+
*
|
|
25
|
+
* @param queryDescription - query description to validate
|
|
26
|
+
* @throws Error if query description is invalid
|
|
27
|
+
*/
|
|
28
|
+
export declare function validateQueryDescription(queryDescription: QueryDescription): void;
|
package/dist/query-client.js
CHANGED
|
@@ -12,6 +12,7 @@ import { QueryTaskPassport } from './query-task-manager/query-task-passport.js';
|
|
|
12
12
|
import { ExecutionResultStatus } from '@sisense/task-manager';
|
|
13
13
|
import { QueryApiDispatcher } from './query-api-dispatcher/query-api-dispatcher.js';
|
|
14
14
|
import { MetadataTypes } from '@sisense/sdk-data';
|
|
15
|
+
import { TranslatableError } from './translation/translatable-error.js';
|
|
15
16
|
/** @internal */
|
|
16
17
|
export const QUERY_DEFAULT_LIMIT = 20000;
|
|
17
18
|
export class DimensionalQueryClient {
|
|
@@ -57,38 +58,41 @@ export class DimensionalQueryClient {
|
|
|
57
58
|
* @param queryDescription - query description to validate
|
|
58
59
|
* @throws Error if query description is invalid
|
|
59
60
|
*/
|
|
60
|
-
function validateQueryDescription(queryDescription) {
|
|
61
|
+
export function validateQueryDescription(queryDescription) {
|
|
61
62
|
const { attributes, measures, filters, highlights, count, offset } = queryDescription;
|
|
62
63
|
if (count && count < 0) {
|
|
63
|
-
throw new
|
|
64
|
+
throw new TranslatableError('errors.invalidCountNegative', { count: count.toString() });
|
|
64
65
|
}
|
|
65
66
|
if (count && count > QUERY_DEFAULT_LIMIT) {
|
|
66
|
-
throw new
|
|
67
|
+
throw new TranslatableError('errors.invalidCountLimit', {
|
|
68
|
+
count: count.toString(),
|
|
69
|
+
limit: QUERY_DEFAULT_LIMIT.toString(),
|
|
70
|
+
});
|
|
67
71
|
}
|
|
68
72
|
if (offset && offset < 0) {
|
|
69
|
-
throw new
|
|
73
|
+
throw new TranslatableError('errors.invalidOffset', { offset: offset.toString() });
|
|
70
74
|
}
|
|
71
75
|
if (attributes.length + measures.length === 0) {
|
|
72
|
-
throw new
|
|
76
|
+
throw new TranslatableError('errors.noDimensionsOrMeasures');
|
|
73
77
|
}
|
|
74
78
|
attributes.forEach((attribute) => {
|
|
75
79
|
if (!attribute.skipValidation && !MetadataTypes.isAttribute(attribute)) {
|
|
76
|
-
throw new
|
|
80
|
+
throw new TranslatableError('errors.invalidAttribute', { attributeName: attribute.name });
|
|
77
81
|
}
|
|
78
82
|
});
|
|
79
83
|
measures.forEach((measure) => {
|
|
80
84
|
if (!measure.skipValidation && !MetadataTypes.isMeasure(measure)) {
|
|
81
|
-
throw new
|
|
85
|
+
throw new TranslatableError('errors.invalidMeasure', { measureName: measure.name });
|
|
82
86
|
}
|
|
83
87
|
});
|
|
84
88
|
filters.forEach((filter) => {
|
|
85
89
|
if (!filter.skipValidation && !MetadataTypes.isFilter(filter)) {
|
|
86
|
-
throw new
|
|
90
|
+
throw new TranslatableError('errors.invalidFilter', { filterName: filter.name });
|
|
87
91
|
}
|
|
88
92
|
});
|
|
89
93
|
highlights.forEach((highlight) => {
|
|
90
94
|
if (!highlight.skipValidation && !MetadataTypes.isFilter(highlight)) {
|
|
91
|
-
throw new
|
|
95
|
+
throw new TranslatableError('errors.invalidHighlight', { highlightName: highlight.name });
|
|
92
96
|
}
|
|
93
97
|
});
|
|
94
98
|
}
|
|
@@ -99,8 +103,10 @@ function validateQueryDescription(queryDescription) {
|
|
|
99
103
|
* @throws Error if http client is invalid
|
|
100
104
|
*/
|
|
101
105
|
function validateHttpClient(httpClient) {
|
|
102
|
-
if (!httpClient)
|
|
103
|
-
throw new
|
|
104
|
-
|
|
105
|
-
|
|
106
|
+
if (!httpClient) {
|
|
107
|
+
throw new TranslatableError('errors.missingHttpClient');
|
|
108
|
+
}
|
|
109
|
+
if (!httpClient.post) {
|
|
110
|
+
throw new TranslatableError('errors.missingPostMethod');
|
|
111
|
+
}
|
|
106
112
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { initI18next } from '@sisense/sdk-common';
|
|
2
|
+
import { resources, PACKAGE_NAMESPACE } from './resources/index.js';
|
|
3
|
+
export function initializeI18n() {
|
|
4
|
+
return initI18next({
|
|
5
|
+
resource: resources,
|
|
6
|
+
language: 'en',
|
|
7
|
+
namespace: PACKAGE_NAMESPACE,
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
export const { i18nextInstance } = initializeI18n();
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
invalidCountLimit: string;
|
|
10
|
+
invalidOffset: string;
|
|
11
|
+
missingHttpClient: string;
|
|
12
|
+
missingPostMethod: string;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export type TranslationDictionary = typeof translation;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const translation = {
|
|
2
|
+
errors: {
|
|
3
|
+
invalidAttribute: 'Invalid attribute {{attributeName}}. Hint: attributes for query should be extracted from the data model generated by the CLI tool.',
|
|
4
|
+
noDimensionsOrMeasures: 'Neither dimensions nor measures found. Query should have at least one dimension or measure.',
|
|
5
|
+
invalidMeasure: 'Invalid measure "{{measureName}}". Hint: measures for the query can be constructed using the "measures" functions.',
|
|
6
|
+
invalidFilter: 'Invalid filter "{{filterName}}". Hint: filters for the query can be constructed using the "filters" functions.',
|
|
7
|
+
invalidHighlight: 'Invalid highlight "{{highlightName}}". Hint: highlights for the query can be constructed using the "filters" functions.',
|
|
8
|
+
invalidCountNegative: 'Invalid count "{{count}}". Count should be non-negative.',
|
|
9
|
+
invalidCountLimit: 'Invalid count "{{count}}". Count should not exceed {{limit}}.',
|
|
10
|
+
invalidOffset: 'Invalid offset "{{offset}}". Offset should be non-negative.',
|
|
11
|
+
missingHttpClient: 'Query requires httpClient to work properly.',
|
|
12
|
+
missingPostMethod: 'httpClient must provide "post" method.',
|
|
13
|
+
},
|
|
14
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
invalidCountLimit: string;
|
|
14
|
+
invalidOffset: string;
|
|
15
|
+
missingHttpClient: string;
|
|
16
|
+
missingPostMethod: string;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
uk: {
|
|
20
|
+
errors: {
|
|
21
|
+
invalidAttribute: string;
|
|
22
|
+
noDimensionsOrMeasures: string;
|
|
23
|
+
invalidMeasure: string;
|
|
24
|
+
invalidFilter: string;
|
|
25
|
+
invalidHighlight: string;
|
|
26
|
+
invalidCountNegative: string;
|
|
27
|
+
invalidCountLimit: string;
|
|
28
|
+
invalidOffset: string;
|
|
29
|
+
missingHttpClient: string;
|
|
30
|
+
missingPostMethod: string;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const translation = {
|
|
2
|
+
errors: {
|
|
3
|
+
invalidAttribute: `Недійсний атрибут {{attributeName}}. Підказка: атрибути для запиту повинні бути витягнуті з моделі даних, створеної за допомогою CLI-інструменту.`,
|
|
4
|
+
noDimensionsOrMeasures: `Не знайдено ні розмірів, ні показників. Запит повинен мати щонайменше один розмір або показник.`,
|
|
5
|
+
invalidMeasure: `Недійсний показник "{{measureName}}". Підказка: показники для запиту можна створити за допомогою функцій "measures".`,
|
|
6
|
+
invalidFilter: `Недійсний фільтр "{{filterName}}". Підказка: фільтри для запиту можна створити за допомогою функцій "filters".`,
|
|
7
|
+
invalidHighlight: `Недійсне виділення "{{highlightName}}". Підказка: виділення для запиту можна створити за допомогою функцій "filters".`,
|
|
8
|
+
invalidCountNegative: `Недійсний count "{{count}}". Count повинен бути не від'ємним.`,
|
|
9
|
+
invalidCountLimit: `Недійсний count "{{count}}". Count не повинен перевищувати {{limit}}.`,
|
|
10
|
+
invalidOffset: `Недійсний offset "{{offset}}". Offset повинен бути не від'ємним.`,
|
|
11
|
+
missingHttpClient: `Для запиту потрібен httpClient, щоб працювати належним чином.`,
|
|
12
|
+
missingPostMethod: `httpClient повинен мати метод "post".`,
|
|
13
|
+
},
|
|
14
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { AbstractTranslatableError } from '@sisense/sdk-common';
|
|
2
|
+
import { PACKAGE_NAMESPACE } from './resources/index.js';
|
|
3
|
+
export declare class TranslatableError extends AbstractTranslatableError<typeof PACKAGE_NAMESPACE> {
|
|
4
|
+
constructor(translationKey: string, interpolationOptions?: Record<string, string>);
|
|
5
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AbstractTranslatableError } from '@sisense/sdk-common';
|
|
2
|
+
import { i18nextInstance } from './initialize-i18n.js';
|
|
3
|
+
import { PACKAGE_NAMESPACE } from './resources/index.js';
|
|
4
|
+
export class TranslatableError extends AbstractTranslatableError {
|
|
5
|
+
constructor(translationKey, interpolationOptions) {
|
|
6
|
+
super(PACKAGE_NAMESPACE, {
|
|
7
|
+
key: translationKey,
|
|
8
|
+
interpolationOptions: interpolationOptions,
|
|
9
|
+
}, i18nextInstance.t);
|
|
10
|
+
}
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sisense/sdk-query-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": "./dist/index.js",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
"author": "Sisense",
|
|
10
10
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@sisense/sdk-
|
|
13
|
-
"@sisense/sdk-
|
|
12
|
+
"@sisense/sdk-common": "^0.12.0",
|
|
13
|
+
"@sisense/sdk-data": "^0.12.0",
|
|
14
|
+
"@sisense/sdk-rest-client": "^0.12.0",
|
|
14
15
|
"@sisense/task-manager": "^0.1.0",
|
|
15
16
|
"numeral": "^2.0.6",
|
|
16
17
|
"uuid": "^9.0.0"
|