@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 CHANGED
@@ -1,3 +1,4 @@
1
+ import './translation/initialize-i18n.js';
1
2
  export { DimensionalQueryClient } from './query-client.js';
2
3
  export * from './types.js';
3
4
  export * from './interfaces.js';
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import './translation/initialize-i18n.js';
1
2
  export { DimensionalQueryClient } from './query-client.js';
2
3
  export * from './types.js';
3
4
  export * from './interfaces.js';
@@ -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;
@@ -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 Error(`Invalid count "${count}". Count should be non-negative.`);
64
+ throw new TranslatableError('errors.invalidCountNegative', { count: count.toString() });
64
65
  }
65
66
  if (count && count > QUERY_DEFAULT_LIMIT) {
66
- throw new Error(`Invalid count "${count}". Count should not exceed ${QUERY_DEFAULT_LIMIT}.`);
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 Error(`Invalid offset "${offset}". Offset should be non-negative.`);
73
+ throw new TranslatableError('errors.invalidOffset', { offset: offset.toString() });
70
74
  }
71
75
  if (attributes.length + measures.length === 0) {
72
- throw new Error('Neither dimensions nor measures found. Query should have at least one dimension or measure.');
76
+ throw new TranslatableError('errors.noDimensionsOrMeasures');
73
77
  }
74
78
  attributes.forEach((attribute) => {
75
79
  if (!attribute.skipValidation && !MetadataTypes.isAttribute(attribute)) {
76
- throw new Error(`Invalid attribute "${attribute.name}". Hint: attributes for query should be extracted from the data model generated by the CLI tool.`);
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 Error(`Invalid measure "${measure.name}". Hint: measures for query can be constructed using the "measures" functions.`);
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 Error(`Invalid filter "${filter.name}". Hint: filters for query can be constructed using the "filters" functions.`);
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 Error(`Invalid highlight "${highlight.name}". Hint: highlights for query can be constructed using the "filters" functions.`);
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 Error('Query requires httpClient to work properly');
104
- if (!httpClient.post)
105
- throw new Error('httpClient must provide "post" method');
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,2 @@
1
+ export declare function initializeI18n(): import("@sisense/sdk-common").I18NextInitResult;
2
+ export declare const i18nextInstance: import("i18next").i18n;
@@ -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,7 @@
1
+ import { translation as enDictionary } from './en.js';
2
+ import { translation as ukDictionary } from './uk.js';
3
+ export const PACKAGE_NAMESPACE = 'sdkQueryClient';
4
+ export const resources = {
5
+ en: enDictionary,
6
+ uk: ukDictionary,
7
+ };
@@ -0,0 +1,2 @@
1
+ import { TranslationDictionary } from './index.js';
2
+ export declare const translation: TranslationDictionary;
@@ -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.11.3",
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-data": "^0.11.3",
13
- "@sisense/sdk-rest-client": "^0.11.3",
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"