@sisense/sdk-data 0.15.0 → 0.16.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,4 +1,5 @@
1
1
  import { create } from './factory.js';
2
+ import { TranslatableError } from '../translation/translatable-error.js';
2
3
  /**
3
4
  * @internal
4
5
  */
@@ -17,11 +18,11 @@ export class DimensionalDataModel {
17
18
  }
18
19
  }
19
20
  static fromConfig(config) {
20
- if (!config && config.name) {
21
- throw new Error('name must be specified');
21
+ if (config && !config.name) {
22
+ throw new TranslatableError('errors.dataModel.noName');
22
23
  }
23
- if (!config && config.metadata) {
24
- throw new Error('metadata must be specified');
24
+ if (config && !config.metadata) {
25
+ throw new TranslatableError('errors.dataModel.noMetadata');
25
26
  }
26
27
  const metadata = new Array();
27
28
  for (let i = 0; i < config.metadata.length; i++) {
@@ -1,11 +1,11 @@
1
1
  /* eslint-disable complexity */
2
2
  /* eslint-disable @typescript-eslint/no-unsafe-member-access */
3
- /* eslint-disable @typescript-eslint/no-throw-literal */
4
3
  import { MetadataTypes } from './types.js';
5
4
  import { createMeasure } from './measures/measures.js';
6
5
  import { createFilter } from './filters/filters.js';
7
6
  import { createDimension } from './dimensions.js';
8
7
  import { createAttribute } from './attributes.js';
8
+ import { TranslatableError } from '../translation/translatable-error.js';
9
9
  /**
10
10
  * Generate an array of dimension model instances out of the given JSON array
11
11
  *
@@ -46,5 +46,5 @@ export function create(item) {
46
46
  item.dimtype) {
47
47
  return createDimension(item);
48
48
  }
49
- throw 'unsupported';
49
+ throw new TranslatableError('errors.unsupportedDimesionalElement');
50
50
  }
@@ -1,7 +1,6 @@
1
1
  /* eslint-disable @typescript-eslint/no-unsafe-assignment */
2
2
  /* eslint-disable @typescript-eslint/no-unsafe-member-access */
3
3
  /* eslint-disable @typescript-eslint/no-unsafe-return */
4
- /* eslint-disable @typescript-eslint/no-throw-literal */
5
4
  /* eslint-disable @typescript-eslint/no-unsafe-call */
6
5
  /* eslint-disable max-lines */
7
6
  /* eslint-disable max-params */
@@ -14,6 +13,7 @@ import { DimensionalElement } from '../base.js';
14
13
  import { DateLevels, MetadataTypes } from '../types.js';
15
14
  import { create } from '../factory.js';
16
15
  import { DimensionalBaseMeasure } from '../measures/measures.js';
16
+ import { TranslatableError } from '../../translation/translatable-error.js';
17
17
  /**
18
18
  * Different text operators that can be used with text filters
19
19
  *
@@ -140,7 +140,7 @@ class AbstractFilter extends DimensionalElement {
140
140
  if (granularity === DateLevels.Hours ||
141
141
  granularity === DateLevels.MinutesRoundTo30 ||
142
142
  granularity === DateLevels.MinutesRoundTo15) {
143
- throw new Error('Filters do not support the next "datetime" levels: Hours, MinutesRoundTo30, MinutesRoundTo15');
143
+ throw new TranslatableError('errors.filter.unsupportedDatetimeLevel');
144
144
  }
145
145
  }
146
146
  }
@@ -185,7 +185,9 @@ export class MembersFilter extends AbstractFilter {
185
185
  super(attribute, FilterTypes.members);
186
186
  this.members = members !== null && members !== void 0 ? members : [];
187
187
  if (this.members.filter((m) => m === null || m === undefined).length > 0) {
188
- throw `MembersFilter of ${attribute.id} - member cannot be null`;
188
+ throw new TranslatableError('errors.filter.membersFilterNullMember', {
189
+ attributeId: attribute.id,
190
+ });
189
191
  }
190
192
  }
191
193
  /**
@@ -399,9 +401,6 @@ export class RankingFilter extends AbstractFilter {
399
401
  export class NumericFilter extends DoubleOperatorFilter {
400
402
  constructor(att, operatorA, valueA, operatorB, valueB) {
401
403
  super(att, FilterTypes.numeric, operatorA, valueA, operatorB, valueB);
402
- // if (att.dimension && !MetadataTypes.isTextDimension(att.dimension.type)) {
403
- // throw 'Dimension must be of Text type to be applied with Text filter';
404
- // }
405
404
  }
406
405
  }
407
406
  /**
@@ -410,9 +409,6 @@ export class NumericFilter extends DoubleOperatorFilter {
410
409
  export class TextFilter extends DoubleOperatorFilter {
411
410
  constructor(att, operator, value) {
412
411
  super(att, FilterTypes.text, operator, value);
413
- // if (att.dimension && !MetadataTypes.isTextDimension(att.dimension.type)) {
414
- // throw 'Dimension must be of Text type to be applied with Text filter';
415
- // }
416
412
  }
417
413
  }
418
414
  /**
@@ -544,5 +540,7 @@ export function createFilter(json) {
544
540
  return new DateRangeFilter(create(json.attribute), json.valueA, json.valueB);
545
541
  break;
546
542
  }
547
- throw 'unsupported filter type';
543
+ throw new TranslatableError('errors.filter.unsupportedType', {
544
+ filterType: json.filterType,
545
+ });
548
546
  }
@@ -1,7 +1,7 @@
1
1
  import { DimensionalBaseMeasure, DimensionalCalculatedMeasure } from './measures.js';
2
2
  import { AggregationTypes, MetadataTypes, Sort } from '../types.js';
3
3
  import { normalizeName } from '../base.js';
4
- import { mapValues } from 'lodash';
4
+ import mapValues from 'lodash/mapValues.js';
5
5
  import { DimensionalAttribute, DimensionalLevelAttribute } from '../attributes.js';
6
6
  import { isDatetime, isNumber } from './../simple-column-types.js';
7
7
  /**
@@ -190,13 +190,6 @@ function arithmetic(operand1, operator, operand2, name, withParentheses) {
190
190
  * @returns A Measure instance
191
191
  */
192
192
  export function aggregate(attribute, aggregationType, name, format) {
193
- // if (aggregationType == AggregationTypes.Average || aggregationType == AggregationTypes.Max ||
194
- // aggregationType == AggregationTypes.Min || aggregationType == AggregationTypes.Median ||
195
- // aggregationType == AggregationTypes.Sum) {
196
- // if (!MetadataTypes.isNumericDimension(attribute.type)) {
197
- // throw `${aggregationType} is supported for numeric attributes only, where ${attribute.name} is ${attribute.type}`;
198
- // }
199
- // }
200
193
  return new DimensionalBaseMeasure(name !== null && name !== void 0 ? name : `${aggregationType.toString()} ${attribute.name}`, attribute, aggregationType, format);
201
194
  }
202
195
  /**
@@ -634,9 +627,7 @@ export function contribution(measure, name) {
634
627
  */
635
628
  export function trend(measure, name, options) {
636
629
  let params;
637
- const adjustValues = (value) => value
638
- .replace('advancedSmoothing', 'Advanced Smoothing')
639
- .replace('localEstimates', 'Local Estimates');
630
+ const adjustValues = (value) => value.replace('advancedSmoothing', 'smooth').replace('localEstimates', 'local');
640
631
  if (options) {
641
632
  // make a comma separated name=value string based on options
642
633
  params = Object.entries(options)
@@ -670,7 +661,7 @@ export function forecast(measure, name, options) {
670
661
  let params;
671
662
  if (options) {
672
663
  // create ISO string values for any Date objects
673
- const adjustedOptions = Object.assign({}, options);
664
+ const adjustedOptions = Object.assign({ forecastHorizon: 3 }, options);
674
665
  if (adjustedOptions.startDate) {
675
666
  const startDate = new Date(adjustedOptions.startDate);
676
667
  adjustedOptions.startDate = startDate.toISOString().replace(/.\d+Z$/g, '');
@@ -8,12 +8,12 @@
8
8
  /* eslint-disable @typescript-eslint/no-unsafe-call */
9
9
  /* eslint-disable sonarjs/cognitive-complexity */
10
10
  /* eslint-disable @typescript-eslint/no-unsafe-argument */
11
- /* eslint-disable @typescript-eslint/no-throw-literal */
12
11
  import * as m from './factory.js';
13
12
  import { Sort, AggregationTypes, MetadataTypes } from '../types.js';
14
13
  import { DimensionalElement } from '../base.js';
15
14
  import { DimensionalAttribute, createAttribute } from '../attributes.js';
16
15
  import { create } from '../factory.js';
16
+ import { TranslatableError } from '../../translation/translatable-error.js';
17
17
  /**
18
18
  * @internal
19
19
  */
@@ -360,7 +360,7 @@ export function createMeasure(json) {
360
360
  }
361
361
  if (MetadataTypes.isCalculatedMeasure(json)) {
362
362
  if (json.context === undefined) {
363
- throw new Error(`DimensionalCalculatedMeasure must have context property`);
363
+ throw new TranslatableError('errors.measure.dimensionalCalculatedMeasure.noContext');
364
364
  }
365
365
  const context = {};
366
366
  Object.getOwnPropertyNames(json.context).forEach((pname) => {
@@ -370,19 +370,19 @@ export function createMeasure(json) {
370
370
  }
371
371
  else if (MetadataTypes.isMeasureTemplate(json)) {
372
372
  if (att === undefined) {
373
- throw new Error(`DimensionalBaseMeasure must have attribute/dim/expression property`);
373
+ throw new TranslatableError('errors.measure.dimensionalBaseMeasure.noAttributeDimExpression');
374
374
  }
375
375
  return new DimensionalMeasureTemplate(name, att, format, desc);
376
376
  }
377
377
  else if (MetadataTypes.isBaseMeasure(json)) {
378
378
  if (att === undefined) {
379
- throw new Error(`DimensionalBaseMeasure must have attribute/dim/expression property`);
379
+ throw new TranslatableError('errors.measure.dimensionalBaseMeasure.noAttributeDimExpression');
380
380
  }
381
381
  const agg = json.agg || json.aggregation;
382
382
  if (!agg) {
383
- throw `DimensionalBaseMeasure must have agg or aggregation property`;
383
+ throw new TranslatableError('errors.measure.dimensionalBaseMeasure.noAggAggregation');
384
384
  }
385
385
  return new DimensionalBaseMeasure(name, att, agg, format, desc);
386
386
  }
387
- throw 'unsupported measure type';
387
+ throw new TranslatableError('errors.measure.unsupportedType');
388
388
  }
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import './translation/initialize-i18n.js';
1
2
  /**
2
3
  * @packageDocumentation
3
4
  * @beta
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import './translation/initialize-i18n.js';
1
2
  /**
2
3
  * @packageDocumentation
3
4
  * @beta
@@ -184,7 +184,7 @@ export declare type ForecastFormulaOptions = {
184
184
  *
185
185
  * @defaultValue 3
186
186
  */
187
- forecastHorizon: number;
187
+ forecastHorizon?: number;
188
188
  /**
189
189
  * Forecasting model type. The 'auto' option automatically
190
190
  * fits the best combination of models.
@@ -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,28 @@
1
+ /**
2
+ * Translation dictionary for English language.
3
+ */
4
+ export declare const translation: {
5
+ errors: {
6
+ measure: {
7
+ unsupportedType: string;
8
+ dimensionalCalculatedMeasure: {
9
+ noContext: string;
10
+ };
11
+ dimensionalBaseMeasure: {
12
+ noAttributeDimExpression: string;
13
+ noAggAggregation: string;
14
+ };
15
+ };
16
+ dataModelConfig: {
17
+ noName: string;
18
+ noMetadata: string;
19
+ };
20
+ filter: {
21
+ unsupportedType: string;
22
+ unsupportedDatetimeLevel: string;
23
+ membersFilterNullMember: string;
24
+ };
25
+ unsupportedDimesionalElement: string;
26
+ };
27
+ };
28
+ export declare type TranslationDictionary = typeof translation;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Translation dictionary for English language.
3
+ */
4
+ export const translation = {
5
+ errors: {
6
+ measure: {
7
+ unsupportedType: 'Unsupported measure type',
8
+ dimensionalCalculatedMeasure: {
9
+ noContext: "DimensionalCalculatedMeasure must have 'context' property",
10
+ },
11
+ dimensionalBaseMeasure: {
12
+ noAttributeDimExpression: "DimensionalBaseMeasure must have 'attribute'/'dim'/'expression' property",
13
+ noAggAggregation: "DimensionalBaseMeasure must have 'agg' or 'aggregation' property",
14
+ },
15
+ },
16
+ dataModelConfig: {
17
+ noName: "'name' must be specified in config for DataModel",
18
+ noMetadata: "'metadata' must be specified in config for DataModel",
19
+ },
20
+ filter: {
21
+ unsupportedType: 'Unsupported filter type: {{filterType}}',
22
+ unsupportedDatetimeLevel: 'Filters do not support the next "datetime" levels: Hours, MinutesRoundTo30, MinutesRoundTo15',
23
+ membersFilterNullMember: 'MembersFilter of {{attributeId}} - member cannot be null',
24
+ },
25
+ unsupportedDimesionalElement: 'Unsupported dimensional element type',
26
+ },
27
+ };
@@ -0,0 +1,53 @@
1
+ import { TranslationDictionary } from './en.js';
2
+ export type { TranslationDictionary };
3
+ export declare const PACKAGE_NAMESPACE: "sdkData";
4
+ export declare const resources: {
5
+ en: {
6
+ errors: {
7
+ measure: {
8
+ unsupportedType: string;
9
+ dimensionalCalculatedMeasure: {
10
+ noContext: string;
11
+ };
12
+ dimensionalBaseMeasure: {
13
+ noAttributeDimExpression: string;
14
+ noAggAggregation: string;
15
+ };
16
+ };
17
+ dataModelConfig: {
18
+ noName: string;
19
+ noMetadata: string;
20
+ };
21
+ filter: {
22
+ unsupportedType: string;
23
+ unsupportedDatetimeLevel: string;
24
+ membersFilterNullMember: string;
25
+ };
26
+ unsupportedDimesionalElement: string;
27
+ };
28
+ };
29
+ uk: {
30
+ errors: {
31
+ measure: {
32
+ unsupportedType: string;
33
+ dimensionalCalculatedMeasure: {
34
+ noContext: string;
35
+ };
36
+ dimensionalBaseMeasure: {
37
+ noAttributeDimExpression: string;
38
+ noAggAggregation: string;
39
+ };
40
+ };
41
+ dataModelConfig: {
42
+ noName: string;
43
+ noMetadata: string;
44
+ };
45
+ filter: {
46
+ unsupportedType: string;
47
+ unsupportedDatetimeLevel: string;
48
+ membersFilterNullMember: string;
49
+ };
50
+ unsupportedDimesionalElement: string;
51
+ };
52
+ };
53
+ };
@@ -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 = 'sdkData';
4
+ export const resources = {
5
+ en: enDictionary,
6
+ uk: ukDictionary,
7
+ };
@@ -0,0 +1,5 @@
1
+ import { TranslationDictionary } from './index.js';
2
+ /**
3
+ * Translation dictionary for Ukrainian language.
4
+ */
5
+ export declare const translation: TranslationDictionary;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Translation dictionary for Ukrainian language.
3
+ */
4
+ export const translation = {
5
+ errors: {
6
+ measure: {
7
+ unsupportedType: 'Непідтримуваний тип measure',
8
+ dimensionalCalculatedMeasure: {
9
+ noContext: "DimensionalCalculatedMeasure має мати властивість 'context'",
10
+ },
11
+ dimensionalBaseMeasure: {
12
+ noAttributeDimExpression: "DimensionalBaseMeasure має мати властивість 'attribute'/'dim'/'expression'",
13
+ noAggAggregation: "DimensionalBaseMeasure має мати властивість 'agg' або 'aggregation'",
14
+ },
15
+ },
16
+ dataModelConfig: {
17
+ noName: "'name' має бути вказано в конфігурації для DataModel",
18
+ noMetadata: "'metadata' має бути вказано в конфігурації для DataModel",
19
+ },
20
+ filter: {
21
+ unsupportedType: 'Непідтримуваний тип фільтра: {{filterType}}',
22
+ unsupportedDatetimeLevel: 'Фільтри не підтримують наступні рівні "datetime": Hours, MinutesRoundTo30, MinutesRoundTo15',
23
+ membersFilterNullMember: 'MembersFilter у {{attributeId}} - member не може бути нульовим',
24
+ },
25
+ unsupportedDimesionalElement: 'Непідтримуваний тип елемента',
26
+ },
27
+ };
@@ -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-data",
3
- "version": "0.15.0",
3
+ "version": "0.16.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",
@@ -12,7 +12,8 @@
12
12
  "author": "Sisense ",
13
13
  "license": "SEE LICENSE IN LICENSE.md",
14
14
  "dependencies": {
15
- "@sisense/sdk-rest-client": "^0.15.0",
15
+ "@sisense/sdk-common": "^0.16.0",
16
+ "@sisense/sdk-rest-client": "^0.16.0",
16
17
  "guid-typescript": "^1.0.9",
17
18
  "lodash": "^4.17.21",
18
19
  "numeral": "^2.0.6",