@sisense/sdk-data 1.11.0 → 1.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.
Files changed (96) hide show
  1. package/dist/cjs/dimensional-model/analytics/factory.d.ts +47 -0
  2. package/dist/cjs/dimensional-model/analytics/factory.js +151 -0
  3. package/dist/cjs/dimensional-model/analytics/factory.test.d.ts +1 -0
  4. package/dist/cjs/dimensional-model/analytics/factory.test.js +99 -0
  5. package/dist/cjs/dimensional-model/attributes.d.ts +139 -0
  6. package/dist/cjs/dimensional-model/attributes.js +342 -0
  7. package/dist/cjs/dimensional-model/attributes.test.d.ts +1 -0
  8. package/dist/cjs/dimensional-model/attributes.test.js +154 -0
  9. package/dist/cjs/dimensional-model/base.d.ts +43 -0
  10. package/dist/cjs/dimensional-model/base.js +58 -0
  11. package/dist/cjs/dimensional-model/base.test.d.ts +1 -0
  12. package/dist/cjs/dimensional-model/base.test.js +17 -0
  13. package/dist/cjs/dimensional-model/data-model.d.ts +13 -0
  14. package/dist/cjs/dimensional-model/data-model.js +37 -0
  15. package/dist/cjs/dimensional-model/dimensions.d.ts +167 -0
  16. package/dist/cjs/dimensional-model/dimensions.js +307 -0
  17. package/dist/cjs/dimensional-model/dimensions.test.d.ts +1 -0
  18. package/dist/cjs/dimensional-model/dimensions.test.js +54 -0
  19. package/dist/cjs/dimensional-model/factory.d.ts +17 -0
  20. package/dist/cjs/dimensional-model/factory.js +54 -0
  21. package/dist/cjs/dimensional-model/filters/factory.d.ts +796 -0
  22. package/dist/cjs/dimensional-model/filters/factory.js +962 -0
  23. package/dist/cjs/dimensional-model/filters/factory.test.d.ts +1 -0
  24. package/dist/cjs/dimensional-model/filters/factory.test.js +366 -0
  25. package/dist/cjs/dimensional-model/filters/filters.d.ts +321 -0
  26. package/dist/cjs/dimensional-model/filters/filters.js +614 -0
  27. package/dist/cjs/dimensional-model/filters/filters.test.d.ts +1 -0
  28. package/dist/cjs/dimensional-model/filters/filters.test.js +225 -0
  29. package/dist/cjs/dimensional-model/filters/utils/attribute-measure-util.d.ts +47 -0
  30. package/dist/cjs/dimensional-model/filters/utils/attribute-measure-util.js +111 -0
  31. package/dist/cjs/dimensional-model/filters/utils/condition-filter-util.d.ts +21 -0
  32. package/dist/cjs/dimensional-model/filters/utils/condition-filter-util.js +194 -0
  33. package/dist/cjs/dimensional-model/filters/utils/date-time-filter-util.d.ts +2 -0
  34. package/dist/cjs/dimensional-model/filters/utils/date-time-filter-util.js +12 -0
  35. package/dist/cjs/dimensional-model/filters/utils/filter-code-util.d.ts +13 -0
  36. package/dist/cjs/dimensional-model/filters/utils/filter-code-util.js +54 -0
  37. package/dist/cjs/dimensional-model/filters/utils/filter-code-util.test.d.ts +1 -0
  38. package/dist/cjs/dimensional-model/filters/utils/filter-code-util.test.js +32 -0
  39. package/dist/cjs/dimensional-model/filters/utils/filter-from-jaql-util.d.ts +73 -0
  40. package/dist/cjs/dimensional-model/filters/utils/filter-from-jaql-util.js +190 -0
  41. package/dist/cjs/dimensional-model/filters/utils/filter-from-jaql-util.test.d.ts +1 -0
  42. package/dist/cjs/dimensional-model/filters/utils/filter-from-jaql-util.test.js +558 -0
  43. package/dist/cjs/dimensional-model/filters/utils/filter-matcher-utils.d.ts +5 -0
  44. package/dist/cjs/dimensional-model/filters/utils/filter-matcher-utils.js +174 -0
  45. package/dist/cjs/dimensional-model/filters/utils/filter-matcher-utils.test.d.ts +1 -0
  46. package/dist/cjs/dimensional-model/filters/utils/filter-matcher-utils.test.js +236 -0
  47. package/dist/cjs/dimensional-model/filters/utils/filter-types-util.d.ts +17 -0
  48. package/dist/cjs/dimensional-model/filters/utils/filter-types-util.js +79 -0
  49. package/dist/cjs/dimensional-model/filters/utils/types.d.ts +200 -0
  50. package/dist/cjs/dimensional-model/filters/utils/types.js +99 -0
  51. package/dist/cjs/dimensional-model/interfaces.d.ts +512 -0
  52. package/dist/cjs/dimensional-model/interfaces.js +31 -0
  53. package/dist/cjs/dimensional-model/measures/factory.d.ts +920 -0
  54. package/dist/cjs/dimensional-model/measures/factory.js +1188 -0
  55. package/dist/cjs/dimensional-model/measures/factory.test.d.ts +1 -0
  56. package/dist/cjs/dimensional-model/measures/factory.test.js +481 -0
  57. package/dist/cjs/dimensional-model/measures/measures.d.ts +217 -0
  58. package/dist/cjs/dimensional-model/measures/measures.js +416 -0
  59. package/dist/cjs/dimensional-model/measures/measures.test.d.ts +1 -0
  60. package/dist/cjs/dimensional-model/measures/measures.test.js +79 -0
  61. package/dist/cjs/dimensional-model/simple-column-types.d.ts +39 -0
  62. package/dist/cjs/dimensional-model/simple-column-types.js +134 -0
  63. package/dist/cjs/dimensional-model/simple-column-types.test.d.ts +1 -0
  64. package/dist/cjs/dimensional-model/simple-column-types.test.js +85 -0
  65. package/dist/cjs/dimensional-model/types.d.ts +256 -0
  66. package/dist/cjs/dimensional-model/types.js +298 -0
  67. package/dist/cjs/dimensional-model/types.test.d.ts +1 -0
  68. package/dist/cjs/dimensional-model/types.test.js +33 -0
  69. package/dist/cjs/index.d.ts +93 -0
  70. package/dist/cjs/index.js +123 -0
  71. package/dist/cjs/interfaces.d.ts +367 -0
  72. package/dist/cjs/interfaces.js +21 -0
  73. package/dist/cjs/translation/initialize-i18n.d.ts +2 -0
  74. package/dist/cjs/translation/initialize-i18n.js +14 -0
  75. package/dist/cjs/translation/resources/en.d.ts +28 -0
  76. package/dist/cjs/translation/resources/en.js +30 -0
  77. package/dist/cjs/translation/resources/index.d.ts +53 -0
  78. package/dist/cjs/translation/resources/index.js +10 -0
  79. package/dist/cjs/translation/resources/uk.d.ts +5 -0
  80. package/dist/cjs/translation/resources/uk.js +30 -0
  81. package/dist/cjs/translation/translatable-error.d.ts +5 -0
  82. package/dist/cjs/translation/translatable-error.js +15 -0
  83. package/dist/cjs/utils.d.ts +37 -0
  84. package/dist/cjs/utils.js +105 -0
  85. package/dist/cjs/utils.test.d.ts +1 -0
  86. package/dist/cjs/utils.test.js +158 -0
  87. package/dist/dimensional-model/filters/factory.d.ts +80 -42
  88. package/dist/dimensional-model/filters/factory.js +123 -85
  89. package/dist/dimensional-model/filters/filters.d.ts +34 -12
  90. package/dist/dimensional-model/filters/filters.js +69 -27
  91. package/dist/dimensional-model/filters/utils/condition-filter-util.d.ts +4 -2
  92. package/dist/dimensional-model/filters/utils/condition-filter-util.js +27 -25
  93. package/dist/dimensional-model/filters/utils/filter-code-util.js +1 -1
  94. package/dist/dimensional-model/filters/utils/filter-from-jaql-util.d.ts +16 -10
  95. package/dist/dimensional-model/filters/utils/filter-from-jaql-util.js +34 -27
  96. package/package.json +18 -9
@@ -0,0 +1,217 @@
1
+ import { Attribute, Measure, BaseMeasure, MeasureTemplate, CalculatedMeasure, MeasureContext } from '../interfaces.js';
2
+ import { Sort } from '../types.js';
3
+ import { DimensionalElement } from '../base.js';
4
+ /**
5
+ * @internal
6
+ */
7
+ export declare abstract class AbstractMeasure extends DimensionalElement {
8
+ protected _sort: Sort;
9
+ protected _format: string | undefined;
10
+ constructor(name: string, type: string, format?: string, desc?: string, sort?: Sort);
11
+ /**
12
+ * gets the element's ID
13
+ */
14
+ abstract get id(): string;
15
+ /**
16
+ * Gets the sort definition of this instance
17
+ *
18
+ * @returns The Sort definition of this instance
19
+ */
20
+ getSort(): Sort;
21
+ /**
22
+ * The string formatting of this instance
23
+ *
24
+ * @returns string formatting
25
+ */
26
+ getFormat(): string | undefined;
27
+ /**
28
+ * Gets a serializable representation of the element
29
+ */
30
+ serializable(): any;
31
+ /**
32
+ * Gets a sorted {@link Measure} with the given definition
33
+ *
34
+ * @param sort - Sort definition
35
+ * @returns An instance representing the sorted {@link Measure} of this instance
36
+ */
37
+ abstract sort(sort: Sort): Measure;
38
+ /**
39
+ * Gets a formatted {@link Measure} with the given definition
40
+ *
41
+ * @param format - Format string
42
+ * @returns An instance representing the formatted {@link Measure} of this instance
43
+ */
44
+ abstract format(format: string): Measure;
45
+ }
46
+ /**
47
+ * Stands for a Base measure - Aggregation over an Attribute
48
+ *
49
+ * @internal
50
+ */
51
+ export declare class DimensionalBaseMeasure extends AbstractMeasure implements BaseMeasure {
52
+ static aggregationFromJAQL(agg: string): string;
53
+ static aggregationToJAQL(agg: string): string;
54
+ constructor(name: string, attribute: Attribute, agg: string, format?: string, desc?: string, sort?: Sort);
55
+ /**
56
+ * Aggregating attribute
57
+ */
58
+ readonly attribute: Attribute;
59
+ /**
60
+ * Aggregation type
61
+ */
62
+ readonly aggregation: string;
63
+ /**
64
+ * Gets a sorted {@link Measure} with the given definition
65
+ *
66
+ * @param sort - Sort definition
67
+ * @returns An instance representing the sorted {@link Measure} of this instance
68
+ */
69
+ sort(sort: Sort): Measure;
70
+ /**
71
+ * Gets a formatted {@link Measure} with the given definition
72
+ *
73
+ * Input string is in Numeral format - @see http://numeraljs.com/
74
+ *
75
+ * @param format - Format string
76
+ * @returns An instance representing the formatted {@link Measure} of this instance
77
+ */
78
+ format(format: string): Measure;
79
+ /**
80
+ * gets the element's ID
81
+ */
82
+ get id(): string;
83
+ /**
84
+ * Gets a serializable representation of the element
85
+ */
86
+ serializable(): any;
87
+ jaql(nested?: boolean): any;
88
+ }
89
+ /**
90
+ * Stands for a Calculated Measure
91
+ *
92
+ * @see {https://sisense.dev/guides/querying/useJaql/#step-7-adding-a-formula}
93
+ * @internal
94
+ */
95
+ export declare class DimensionalCalculatedMeasure extends AbstractMeasure implements CalculatedMeasure {
96
+ constructor(name: string, expression: string, context: MeasureContext, format?: string, desc?: string, sort?: Sort);
97
+ /**
98
+ * Defines the Calculated measure's expression
99
+ */
100
+ expression: string;
101
+ /**
102
+ * Defines the Calculated measure's context
103
+ */
104
+ context: MeasureContext;
105
+ /**
106
+ * Gets a sorted {@link Measure} with the given definition
107
+ *
108
+ * @param sort - Sort definition
109
+ * @returns An instance representing the sorted {@link Measure} of this instance
110
+ */
111
+ sort(sort: Sort): Measure;
112
+ /**
113
+ * Gets a formatted {@link Measure} with the given definition
114
+ *
115
+ * Input string is in Numeral format - @see http://numeraljs.com/
116
+ *
117
+ * @param format - Format string
118
+ * @returns An instance representing the formatted {@link Measure} of this instance
119
+ */
120
+ format(format: string): Measure;
121
+ /**
122
+ * gets the element's ID
123
+ */
124
+ get id(): string;
125
+ /**
126
+ * Gets a serializable representation of the element
127
+ */
128
+ serializable(): any;
129
+ jaql(nested?: boolean): any;
130
+ }
131
+ /**
132
+ * Stands for a Measure template - generator for different aggregation over Attribute
133
+ *
134
+ * @internal
135
+ */
136
+ export declare class DimensionalMeasureTemplate extends AbstractMeasure implements MeasureTemplate {
137
+ constructor(name: string, attribute: Attribute, format?: string, desc?: string, sort?: Sort);
138
+ /**
139
+ * Aggregating attribute
140
+ */
141
+ readonly attribute: Attribute;
142
+ /**
143
+ * gets the element's ID
144
+ */
145
+ get id(): string;
146
+ /**
147
+ * Gets a serializable representation of the element
148
+ */
149
+ serializable(): any;
150
+ /**
151
+ * Gets a sorted {@link MeasureTemplate} with the given definition
152
+ *
153
+ * @param sort - Sort definition
154
+ * @returns An instance representing the sorted {@link MeasureTemplate} of this instance
155
+ */
156
+ sort(sort: Sort): MeasureTemplate;
157
+ /**
158
+ * Gets a formatted {@link Measure} with the given definition
159
+ *
160
+ * @param format - Format string
161
+ * @returns An instance representing the formatted {@link Measure} of this instance
162
+ */
163
+ format(format: string): Measure;
164
+ /**
165
+ * Gets the JAQL representation of this instance
166
+ *
167
+ * @param nested - defines whether the JAQL is nested within parent JAQL statement or a root JAQL element
168
+ */
169
+ jaql(nested?: boolean): any;
170
+ /**
171
+ * Gets an {@link Measure} defined with sum aggregation
172
+ *
173
+ * @param format - optional format to apply on the resulting {@link Measure}
174
+ */
175
+ sum(format?: string): Measure;
176
+ /**
177
+ * Gets an {@link Measure} defined with average aggregation
178
+ *
179
+ * @param format - optional format to apply on the resulting {@link Measure}
180
+ */
181
+ average(format?: string): Measure;
182
+ /**
183
+ * Gets an {@link Measure} defined with median aggregation
184
+ *
185
+ * @param format - optional format to apply on the resulting {@link Measure}
186
+ */
187
+ median(format?: string): Measure;
188
+ /**
189
+ * Gets an {@link Measure} defined with min aggregation
190
+ *
191
+ * @param format - optional format to apply on the resulting {@link Measure}
192
+ */
193
+ min(format?: string): Measure;
194
+ /**
195
+ * Gets an {@link Measure} defined with max aggregation
196
+ *
197
+ * @param format - optional format to apply on the resulting {@link Measure}
198
+ */
199
+ max(format?: string): Measure;
200
+ /**
201
+ * Gets an {@link Measure} defined with count aggregation
202
+ *
203
+ * @param format - optional format to apply on the resulting {@link Measure}
204
+ */
205
+ count(format?: string): Measure;
206
+ /**
207
+ * Gets an {@link Measure} defined with count distinct aggregation
208
+ *
209
+ * @param format - optional format to apply on the resulting {@link Measure}
210
+ */
211
+ countDistinct(format?: string): Measure;
212
+ }
213
+ /**
214
+ * @param json
215
+ * @internal
216
+ */
217
+ export declare function createMeasure(json: any): Measure | BaseMeasure;
@@ -0,0 +1,416 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.createMeasure = exports.DimensionalMeasureTemplate = exports.DimensionalCalculatedMeasure = exports.DimensionalBaseMeasure = exports.AbstractMeasure = void 0;
27
+ /* eslint-disable max-params */
28
+ /* eslint-disable no-underscore-dangle */
29
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
30
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
31
+ /* eslint-disable @typescript-eslint/no-unsafe-return */
32
+ /* eslint-disable @typescript-eslint/no-unsafe-call */
33
+ /* eslint-disable @typescript-eslint/no-unsafe-argument */
34
+ const m = __importStar(require("./factory.js"));
35
+ const types_js_1 = require("../types.js");
36
+ const base_js_1 = require("../base.js");
37
+ const attributes_js_1 = require("../attributes.js");
38
+ const factory_js_1 = require("../factory.js");
39
+ const translatable_error_js_1 = require("../../translation/translatable-error.js");
40
+ /**
41
+ * @internal
42
+ */
43
+ class AbstractMeasure extends base_js_1.DimensionalElement {
44
+ constructor(name, type, format, desc, sort) {
45
+ super(name, type, desc);
46
+ this._sort = types_js_1.Sort.None;
47
+ this._format = '#,#.00';
48
+ this._format = format;
49
+ this._sort = sort || types_js_1.Sort.None;
50
+ }
51
+ /**
52
+ * Gets the sort definition of this instance
53
+ *
54
+ * @returns The Sort definition of this instance
55
+ */
56
+ getSort() {
57
+ return this._sort;
58
+ }
59
+ /**
60
+ * The string formatting of this instance
61
+ *
62
+ * @returns string formatting
63
+ */
64
+ getFormat() {
65
+ return this._format;
66
+ }
67
+ /**
68
+ * Gets a serializable representation of the element
69
+ */
70
+ serializable() {
71
+ const result = super.serializable();
72
+ if (this.getFormat() !== undefined) {
73
+ result.format = this.getFormat();
74
+ }
75
+ if (this.getSort() !== undefined) {
76
+ result.sort = this.getSort();
77
+ }
78
+ return result;
79
+ }
80
+ }
81
+ exports.AbstractMeasure = AbstractMeasure;
82
+ /**
83
+ * Stands for a Base measure - Aggregation over an Attribute
84
+ *
85
+ * @internal
86
+ */
87
+ class DimensionalBaseMeasure extends AbstractMeasure {
88
+ constructor(name, attribute, agg, format, desc, sort) {
89
+ super(name, types_js_1.MetadataTypes.BaseMeasure, format, desc, sort);
90
+ this.attribute = attribute;
91
+ this.aggregation = agg;
92
+ }
93
+ static aggregationFromJAQL(agg) {
94
+ switch (agg) {
95
+ case 'sum':
96
+ return types_js_1.AggregationTypes.Sum;
97
+ case 'avg':
98
+ return types_js_1.AggregationTypes.Average;
99
+ case 'min':
100
+ return types_js_1.AggregationTypes.Min;
101
+ case 'max':
102
+ return types_js_1.AggregationTypes.Max;
103
+ case 'countduplicates':
104
+ return types_js_1.AggregationTypes.Count;
105
+ case 'median':
106
+ return types_js_1.AggregationTypes.Median;
107
+ case 'count':
108
+ return types_js_1.AggregationTypes.CountDistinct;
109
+ case 'var':
110
+ return types_js_1.AggregationTypes.Variance;
111
+ case 'stdev':
112
+ return types_js_1.AggregationTypes.StandardDeviation;
113
+ }
114
+ return types_js_1.AggregationTypes.Sum;
115
+ }
116
+ static aggregationToJAQL(agg) {
117
+ switch (agg) {
118
+ case types_js_1.AggregationTypes.Sum:
119
+ return 'sum';
120
+ case types_js_1.AggregationTypes.Average:
121
+ return 'avg';
122
+ case types_js_1.AggregationTypes.Min:
123
+ return 'min';
124
+ case types_js_1.AggregationTypes.Max:
125
+ return 'max';
126
+ case types_js_1.AggregationTypes.Count:
127
+ return 'countduplicates';
128
+ case types_js_1.AggregationTypes.CountDistinct:
129
+ return 'count';
130
+ case types_js_1.AggregationTypes.Median:
131
+ return 'median';
132
+ case types_js_1.AggregationTypes.Variance:
133
+ return 'var';
134
+ case types_js_1.AggregationTypes.StandardDeviation:
135
+ return 'stdev';
136
+ }
137
+ return types_js_1.AggregationTypes.Sum;
138
+ }
139
+ /**
140
+ * Gets a sorted {@link Measure} with the given definition
141
+ *
142
+ * @param sort - Sort definition
143
+ * @returns An instance representing the sorted {@link Measure} of this instance
144
+ */
145
+ sort(sort) {
146
+ return new DimensionalBaseMeasure(this.name, this.attribute, this.aggregation, this._format, this.description, sort);
147
+ }
148
+ /**
149
+ * Gets a formatted {@link Measure} with the given definition
150
+ *
151
+ * Input string is in Numeral format - @see http://numeraljs.com/
152
+ *
153
+ * @param format - Format string
154
+ * @returns An instance representing the formatted {@link Measure} of this instance
155
+ */
156
+ format(format) {
157
+ return new DimensionalBaseMeasure(this.name, this.attribute, this.aggregation, format, this.description, this._sort);
158
+ }
159
+ /**
160
+ * gets the element's ID
161
+ */
162
+ get id() {
163
+ return `${this.attribute.expression}_${this.aggregation}`;
164
+ }
165
+ /**
166
+ * Gets a serializable representation of the element
167
+ */
168
+ serializable() {
169
+ const result = super.serializable();
170
+ result.aggregation = this.aggregation;
171
+ result.attribute = this.attribute.serializable();
172
+ return result;
173
+ }
174
+ jaql(nested) {
175
+ const attributeJaql = this.attribute.jaql(true);
176
+ const r = {
177
+ jaql: Object.assign(Object.assign({}, attributeJaql), { title: this.name, agg: DimensionalBaseMeasure.aggregationToJAQL(this.aggregation) }),
178
+ };
179
+ if (this._format) {
180
+ r.format = { number: this._format };
181
+ }
182
+ if (this._sort != types_js_1.Sort.None) {
183
+ r.jaql.sort = this._sort == types_js_1.Sort.Ascending ? 'asc' : 'desc';
184
+ }
185
+ return nested === true ? r.jaql : r;
186
+ }
187
+ }
188
+ exports.DimensionalBaseMeasure = DimensionalBaseMeasure;
189
+ /**
190
+ * Stands for a Calculated Measure
191
+ *
192
+ * @see {https://sisense.dev/guides/querying/useJaql/#step-7-adding-a-formula}
193
+ * @internal
194
+ */
195
+ class DimensionalCalculatedMeasure extends AbstractMeasure {
196
+ constructor(name, expression, context, format, desc, sort) {
197
+ super(name, types_js_1.MetadataTypes.CalculatedMeasure, format, desc, sort);
198
+ this.expression = expression;
199
+ this.context = context;
200
+ }
201
+ /**
202
+ * Gets a sorted {@link Measure} with the given definition
203
+ *
204
+ * @param sort - Sort definition
205
+ * @returns An instance representing the sorted {@link Measure} of this instance
206
+ */
207
+ sort(sort) {
208
+ return new DimensionalCalculatedMeasure(this.name, this.expression, this.context, this._format, this.description, sort);
209
+ }
210
+ /**
211
+ * Gets a formatted {@link Measure} with the given definition
212
+ *
213
+ * Input string is in Numeral format - @see http://numeraljs.com/
214
+ *
215
+ * @param format - Format string
216
+ * @returns An instance representing the formatted {@link Measure} of this instance
217
+ */
218
+ format(format) {
219
+ return new DimensionalCalculatedMeasure(this.name, this.expression, this.context, format, this.description, this._sort);
220
+ }
221
+ /**
222
+ * gets the element's ID
223
+ */
224
+ get id() {
225
+ return this.expression;
226
+ }
227
+ /**
228
+ * Gets a serializable representation of the element
229
+ */
230
+ serializable() {
231
+ const result = super.serializable();
232
+ result.expression = this.expression;
233
+ result.context = {};
234
+ Object.getOwnPropertyNames(this.context).forEach((p) => {
235
+ result.context[p] = this.context[p].serializable();
236
+ });
237
+ return result;
238
+ }
239
+ jaql(nested) {
240
+ const r = {
241
+ jaql: {
242
+ title: this.name,
243
+ formula: this.expression,
244
+ },
245
+ };
246
+ const context = {};
247
+ const keys = Object.getOwnPropertyNames(this.context);
248
+ keys.forEach((k) => (context[k] = this.context[k].jaql(true)));
249
+ r.jaql.context = context;
250
+ if (this._format) {
251
+ r.format = { number: this._format };
252
+ }
253
+ if (this._sort != types_js_1.Sort.None) {
254
+ r.jaql.sort = this._sort == types_js_1.Sort.Ascending ? 'asc' : 'desc';
255
+ }
256
+ return nested === true ? r.jaql : r;
257
+ }
258
+ }
259
+ exports.DimensionalCalculatedMeasure = DimensionalCalculatedMeasure;
260
+ /**
261
+ * Stands for a Measure template - generator for different aggregation over Attribute
262
+ *
263
+ * @internal
264
+ */
265
+ class DimensionalMeasureTemplate extends AbstractMeasure {
266
+ constructor(name, attribute, format, desc, sort) {
267
+ super(name, types_js_1.MetadataTypes.MeasureTemplate, format, desc, sort);
268
+ this.attribute = attribute;
269
+ }
270
+ /**
271
+ * gets the element's ID
272
+ */
273
+ get id() {
274
+ return `${this.attribute.expression}_*`;
275
+ }
276
+ /**
277
+ * Gets a serializable representation of the element
278
+ */
279
+ serializable() {
280
+ const result = super.serializable();
281
+ result.attribute = this.attribute.serializable();
282
+ return result;
283
+ }
284
+ /**
285
+ * Gets a sorted {@link MeasureTemplate} with the given definition
286
+ *
287
+ * @param sort - Sort definition
288
+ * @returns An instance representing the sorted {@link MeasureTemplate} of this instance
289
+ */
290
+ sort(sort) {
291
+ return new DimensionalMeasureTemplate(this.name, this.attribute, this._format, this.description, sort);
292
+ }
293
+ /**
294
+ * Gets a formatted {@link Measure} with the given definition
295
+ *
296
+ * @param format - Format string
297
+ * @returns An instance representing the formatted {@link Measure} of this instance
298
+ */
299
+ format(format) {
300
+ return new DimensionalMeasureTemplate(this.name, this.attribute, format, this.description, this._sort);
301
+ }
302
+ /**
303
+ * Gets the JAQL representation of this instance
304
+ *
305
+ * @param nested - defines whether the JAQL is nested within parent JAQL statement or a root JAQL element
306
+ */
307
+ jaql(nested) {
308
+ return this.sum().sort(this._sort).jaql(nested);
309
+ }
310
+ /**
311
+ * Gets an {@link Measure} defined with sum aggregation
312
+ *
313
+ * @param format - optional format to apply on the resulting {@link Measure}
314
+ */
315
+ sum(format) {
316
+ return m.sum(this.attribute, format).sort(this._sort);
317
+ }
318
+ /**
319
+ * Gets an {@link Measure} defined with average aggregation
320
+ *
321
+ * @param format - optional format to apply on the resulting {@link Measure}
322
+ */
323
+ average(format) {
324
+ return m.average(this.attribute, format).sort(this._sort);
325
+ }
326
+ /**
327
+ * Gets an {@link Measure} defined with median aggregation
328
+ *
329
+ * @param format - optional format to apply on the resulting {@link Measure}
330
+ */
331
+ median(format) {
332
+ return m.median(this.attribute, format).sort(this._sort);
333
+ }
334
+ /**
335
+ * Gets an {@link Measure} defined with min aggregation
336
+ *
337
+ * @param format - optional format to apply on the resulting {@link Measure}
338
+ */
339
+ min(format) {
340
+ return m.median(this.attribute, format).sort(this._sort);
341
+ }
342
+ /**
343
+ * Gets an {@link Measure} defined with max aggregation
344
+ *
345
+ * @param format - optional format to apply on the resulting {@link Measure}
346
+ */
347
+ max(format) {
348
+ return m.max(this.attribute, format).sort(this._sort);
349
+ }
350
+ /**
351
+ * Gets an {@link Measure} defined with count aggregation
352
+ *
353
+ * @param format - optional format to apply on the resulting {@link Measure}
354
+ */
355
+ count(format) {
356
+ return m.count(this.attribute, format).sort(this._sort);
357
+ }
358
+ /**
359
+ * Gets an {@link Measure} defined with count distinct aggregation
360
+ *
361
+ * @param format - optional format to apply on the resulting {@link Measure}
362
+ */
363
+ countDistinct(format) {
364
+ return m.countDistinct(this.attribute, format).sort(this._sort);
365
+ }
366
+ }
367
+ exports.DimensionalMeasureTemplate = DimensionalMeasureTemplate;
368
+ /**
369
+ * @param json
370
+ * @internal
371
+ */
372
+ function createMeasure(json) {
373
+ var _a;
374
+ const name = json.name || json.title;
375
+ const desc = json.desc || json.description;
376
+ const format = json.format;
377
+ const sort = (_a = json.sort) !== null && _a !== void 0 ? _a : json.sort;
378
+ let att = undefined;
379
+ // legacy
380
+ const exp = json.dim || json.expression;
381
+ if (exp) {
382
+ att = new attributes_js_1.DimensionalAttribute(exp, exp, undefined, desc);
383
+ }
384
+ // official SDK
385
+ if (json.attribute) {
386
+ att = (0, attributes_js_1.createAttribute)(json.attribute);
387
+ }
388
+ if (types_js_1.MetadataTypes.isCalculatedMeasure(json)) {
389
+ if (json.context === undefined) {
390
+ throw new translatable_error_js_1.TranslatableError('errors.measure.dimensionalCalculatedMeasure.noContext');
391
+ }
392
+ const context = {};
393
+ Object.getOwnPropertyNames(json.context).forEach((pname) => {
394
+ context[pname] = (0, factory_js_1.create)(json.context[pname]);
395
+ });
396
+ return new DimensionalCalculatedMeasure(name, json.expression || json.formula, context, format, desc, sort);
397
+ }
398
+ else if (types_js_1.MetadataTypes.isMeasureTemplate(json)) {
399
+ if (att === undefined) {
400
+ throw new translatable_error_js_1.TranslatableError('errors.measure.dimensionalBaseMeasure.noAttributeDimExpression');
401
+ }
402
+ return new DimensionalMeasureTemplate(name, att, format, desc);
403
+ }
404
+ else if (types_js_1.MetadataTypes.isBaseMeasure(json)) {
405
+ if (att === undefined) {
406
+ throw new translatable_error_js_1.TranslatableError('errors.measure.dimensionalBaseMeasure.noAttributeDimExpression');
407
+ }
408
+ const agg = json.agg || json.aggregation;
409
+ if (!agg) {
410
+ throw new translatable_error_js_1.TranslatableError('errors.measure.dimensionalBaseMeasure.noAggAggregation');
411
+ }
412
+ return new DimensionalBaseMeasure(name, att, agg, format, desc);
413
+ }
414
+ throw new translatable_error_js_1.TranslatableError('errors.measure.unsupportedType');
415
+ }
416
+ exports.createMeasure = createMeasure;