@sisense/sdk-data 1.11.0 → 1.13.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 (99) hide show
  1. package/dist/cjs/dimensional-model/analytics/factory.d.ts +47 -0
  2. package/dist/cjs/dimensional-model/analytics/factory.js +153 -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 +797 -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 +344 -0
  26. package/dist/cjs/dimensional-model/filters/filters.js +663 -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 +196 -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 +58 -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 +82 -0
  40. package/dist/cjs/dimensional-model/filters/utils/filter-from-jaql-util.js +215 -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 +623 -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 +206 -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/analytics/factory.js +6 -4
  88. package/dist/dimensional-model/filters/factory.d.ts +81 -42
  89. package/dist/dimensional-model/filters/factory.js +125 -87
  90. package/dist/dimensional-model/filters/filters.d.ts +58 -13
  91. package/dist/dimensional-model/filters/filters.js +117 -27
  92. package/dist/dimensional-model/filters/utils/condition-filter-util.d.ts +4 -2
  93. package/dist/dimensional-model/filters/utils/condition-filter-util.js +30 -26
  94. package/dist/dimensional-model/filters/utils/filter-code-util.js +5 -1
  95. package/dist/dimensional-model/filters/utils/filter-from-jaql-util.d.ts +26 -11
  96. package/dist/dimensional-model/filters/utils/filter-from-jaql-util.js +58 -27
  97. package/dist/dimensional-model/filters/utils/filter-types-util.js +3 -3
  98. package/dist/dimensional-model/filters/utils/types.d.ts +6 -0
  99. package/package.json +18 -9
@@ -0,0 +1,167 @@
1
+ import { Attribute, LevelAttribute, Dimension, DateDimension } from './interfaces.js';
2
+ import { Sort } from './types.js';
3
+ import { DimensionalElement } from './base.js';
4
+ /**
5
+ * Represents a Dimension in a Dimensional Model
6
+ *
7
+ * @internal
8
+ */
9
+ export declare class DimensionalDimension extends DimensionalElement implements Dimension, Attribute {
10
+ static parseType(type: string): string;
11
+ [propName: string]: any;
12
+ defaultAttribute: Attribute | undefined;
13
+ protected _dimensions: Dimension[];
14
+ protected _attributes: Attribute[];
15
+ private _expression;
16
+ protected _sort: Sort;
17
+ constructor(name: string, expression: string, attributes: Attribute[], dimensions?: Dimension[], type?: string, desc?: string, sort?: Sort);
18
+ private getAttachedName;
19
+ protected setDimensions(dimensions: Dimension[]): void;
20
+ protected setAttributes(attributes: Attribute[]): void;
21
+ /**
22
+ * gets the element's ID
23
+ */
24
+ get id(): string;
25
+ /**
26
+ * Gets the child attributes
27
+ */
28
+ get attributes(): Attribute[];
29
+ /**
30
+ * Gets the child dimensions
31
+ */
32
+ get dimensions(): Dimension[];
33
+ get expression(): string;
34
+ /**
35
+ * Gets the sort definition of this instance
36
+ *
37
+ * @returns The Sort definition of this instance
38
+ */
39
+ getSort(): Sort;
40
+ /**
41
+ * Gets a sorted {@link Dimension} with the given definition
42
+ *
43
+ * @param sort - Sort definition
44
+ * @returns An instance representing the sorted {@link Dimension} of this instance
45
+ */
46
+ sort(sort: Sort): Attribute;
47
+ /**
48
+ * Gets a serializable representation of the element
49
+ */
50
+ serializable(): any;
51
+ /**
52
+ * Gets the JAQL representation of this instance
53
+ *
54
+ * @param nested - defines whether the JAQL is nested within parent JAQL statement or a root JAQL element
55
+ */
56
+ jaql(nested?: boolean): any;
57
+ }
58
+ /**
59
+ * Represents a Date Dimension in a Dimensional Model
60
+ *
61
+ * @internal
62
+ */
63
+ export declare class DimensionalDateDimension extends DimensionalDimension implements DateDimension {
64
+ constructor(name: string, expression: string, desc?: string, sort?: Sort);
65
+ /**
66
+ * Years level
67
+ */
68
+ readonly Years: LevelAttribute;
69
+ /**
70
+ * Quarters level
71
+ */
72
+ readonly Quarters: LevelAttribute;
73
+ /**
74
+ * Months level
75
+ */
76
+ readonly Months: LevelAttribute;
77
+ /**
78
+ * Weeks level
79
+ */
80
+ readonly Weeks: LevelAttribute;
81
+ /**
82
+ * Days level
83
+ */
84
+ readonly Days: LevelAttribute;
85
+ /**
86
+ * Hours level
87
+ */
88
+ readonly Hours: LevelAttribute;
89
+ /**
90
+ * Minutes (round to 30) level
91
+ */
92
+ readonly MinutesRoundTo30: LevelAttribute;
93
+ /**
94
+ * Minutes (round to 15) level
95
+ */
96
+ readonly MinutesRoundTo15: LevelAttribute;
97
+ /**
98
+ * Aggregated Hours level
99
+ */
100
+ readonly AggHours: LevelAttribute;
101
+ /**
102
+ * Aggregated Minutes (round to 30) level
103
+ */
104
+ readonly AggMinutesRoundTo30: LevelAttribute;
105
+ /**
106
+ * Aggregated Minutes (round to 15) level
107
+ */
108
+ readonly AggMinutesRoundTo15: LevelAttribute;
109
+ /**
110
+ * Aggregated Minutes (every minute) level
111
+ */
112
+ readonly AggMinutesRoundTo1: LevelAttribute;
113
+ defaultLevel: string;
114
+ /**
115
+ * gets the element's ID
116
+ */
117
+ get id(): string;
118
+ protected setDimensions(): void;
119
+ protected setAttributes(attributes: Attribute[]): void;
120
+ /**
121
+ * Gets the sort definition of this instance
122
+ *
123
+ * @returns The Sort definition of this instance
124
+ */
125
+ getSort(): Sort;
126
+ /**
127
+ * Gets a sorted {@link Dimension} with the given definition
128
+ *
129
+ * @param sort - Sort definition
130
+ * @returns An instance representing the sorted {@link Dimension} of this instance
131
+ */
132
+ sort(sort: Sort): Attribute;
133
+ /**
134
+ * Gets a serializable representation of the element
135
+ */
136
+ serializable(): any;
137
+ /**
138
+ * Gets the JAQL representation of this instance
139
+ *
140
+ * @param nested - defines whether the JAQL is nested within parent JAQL statement or a root JAQL element
141
+ */
142
+ jaql(nested?: boolean): any;
143
+ }
144
+ /**
145
+ * Creates a new Dimension instance from the given JSON object.
146
+ *
147
+ * This function is used in the generated data model code to create dimensions for an input data source.
148
+ *
149
+ * See also functions {@link createDateDimension} and {@link createAttribute}.
150
+ *
151
+ * @param json - JSON object representing the Dimension
152
+ * @returns A new Dimension instance
153
+ * @group Data Model Utilities
154
+ */
155
+ export declare function createDimension(json: any): Dimension;
156
+ /**
157
+ * Creates a new Date Dimension instance from the given JSON object.
158
+ *
159
+ * This function is used in the generated data model code to create date dimensions for an input data source.
160
+ *
161
+ * See also functions {@link createDimension} and {@link createAttribute}.
162
+ *
163
+ * @param json - JSON object representing the Date Dimension
164
+ * @returns A new Date Dimension instance
165
+ * @group Data Model Utilities
166
+ */
167
+ export declare function createDateDimension(json: any): DateDimension;
@@ -0,0 +1,307 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createDateDimension = exports.createDimension = exports.DimensionalDateDimension = exports.DimensionalDimension = void 0;
4
+ const types_js_1 = require("./types.js");
5
+ const attributes_js_1 = require("./attributes.js");
6
+ const base_js_1 = require("./base.js");
7
+ /**
8
+ * Represents a Dimension in a Dimensional Model
9
+ *
10
+ * @internal
11
+ */
12
+ class DimensionalDimension extends base_js_1.DimensionalElement {
13
+ constructor(name, expression, attributes, dimensions, type, desc, sort) {
14
+ super(name, type || types_js_1.MetadataTypes.Dimension, desc);
15
+ this._dimensions = [];
16
+ this._attributes = [];
17
+ this._sort = types_js_1.Sort.None;
18
+ this._sort = sort || types_js_1.Sort.None;
19
+ this._expression = expression;
20
+ this.setDimensions(dimensions || []);
21
+ this.setAttributes(attributes);
22
+ }
23
+ static parseType(type) {
24
+ switch (type) {
25
+ case 'datetime':
26
+ case types_js_1.MetadataTypes.DateDimension:
27
+ return types_js_1.MetadataTypes.DateDimension;
28
+ case 'text':
29
+ case types_js_1.MetadataTypes.TextDimension:
30
+ return types_js_1.MetadataTypes.TextDimension;
31
+ case 'numeric':
32
+ case types_js_1.MetadataTypes.NumericDimension:
33
+ return types_js_1.MetadataTypes.NumericDimension;
34
+ }
35
+ return types_js_1.MetadataTypes.TextDimension;
36
+ }
37
+ getAttachedName(name, expression) {
38
+ let result = (0, base_js_1.normalizeName)(name);
39
+ // if exists fallback to expression
40
+ if (result === 'id' ||
41
+ result === 'name' ||
42
+ Object.getOwnPropertyDescriptor(this, result) !== undefined ||
43
+ this[result] !== undefined) {
44
+ result = (0, base_js_1.normalizeName)(expression.replace('.', '_').replace('[', '').replace(']', ''));
45
+ }
46
+ return result;
47
+ }
48
+ setDimensions(dimensions) {
49
+ this._dimensions = dimensions;
50
+ for (let i = 0; i < dimensions.length; i++) {
51
+ const n = this.getAttachedName(dimensions[i].name, dimensions[i].attributes[0].expression);
52
+ this[n] = dimensions[i];
53
+ if (n != dimensions[i].name) {
54
+ dimensions[i].name = n;
55
+ }
56
+ }
57
+ }
58
+ setAttributes(attributes) {
59
+ this._attributes = attributes || [];
60
+ for (let i = 0; i < attributes.length; i++) {
61
+ const n = this.getAttachedName(attributes[i].name, attributes[i].expression);
62
+ this[n] = attributes[i];
63
+ if (attributes[i].name != n) {
64
+ attributes[i].name = n;
65
+ }
66
+ // attaching to dimension
67
+ //this.attributes[i].dimension = this;
68
+ }
69
+ }
70
+ /**
71
+ * gets the element's ID
72
+ */
73
+ get id() {
74
+ return this._expression;
75
+ }
76
+ /**
77
+ * Gets the child attributes
78
+ */
79
+ get attributes() {
80
+ return this._attributes;
81
+ }
82
+ /**
83
+ * Gets the child dimensions
84
+ */
85
+ get dimensions() {
86
+ return this._dimensions;
87
+ }
88
+ get expression() {
89
+ return this._expression;
90
+ }
91
+ /**
92
+ * Gets the sort definition of this instance
93
+ *
94
+ * @returns The Sort definition of this instance
95
+ */
96
+ getSort() {
97
+ return this._sort;
98
+ }
99
+ /**
100
+ * Gets a sorted {@link Dimension} with the given definition
101
+ *
102
+ * @param sort - Sort definition
103
+ * @returns An instance representing the sorted {@link Dimension} of this instance
104
+ */
105
+ sort(sort) {
106
+ return new DimensionalDimension(this.name, this.expression, this.attributes, this.dimensions, this.type, this.description, sort);
107
+ }
108
+ /**
109
+ * Gets a serializable representation of the element
110
+ */
111
+ serializable() {
112
+ const result = super.serializable();
113
+ result.expression = this.expression;
114
+ if (this.getSort() !== undefined) {
115
+ result.sort = this.getSort();
116
+ }
117
+ result.attributes = this._attributes.map((att) => att.serializable());
118
+ result.diemsnions = this._dimensions.map((dim) => dim.serializable());
119
+ if (this.defaultAttribute) {
120
+ result.defaultAttribute = this.defaultAttribute.serializable();
121
+ }
122
+ return result;
123
+ }
124
+ /**
125
+ * Gets the JAQL representation of this instance
126
+ *
127
+ * @param nested - defines whether the JAQL is nested within parent JAQL statement or a root JAQL element
128
+ */
129
+ jaql(nested) {
130
+ if (this.defaultAttribute) {
131
+ return this.defaultAttribute.jaql(nested);
132
+ }
133
+ if (this.dimensions.length > 0) {
134
+ return this.dimensions[0].jaql(nested);
135
+ }
136
+ const result = {
137
+ jaql: {
138
+ title: this.name,
139
+ dim: this.expression,
140
+ datatype: (0, attributes_js_1.jaqlSimpleColumnType)(this.type),
141
+ },
142
+ };
143
+ if (this._sort != types_js_1.Sort.None) {
144
+ result.jaql.sort = this._sort == types_js_1.Sort.Ascending ? 'asc' : 'desc';
145
+ }
146
+ return nested === true ? result.jaql : result;
147
+ }
148
+ }
149
+ exports.DimensionalDimension = DimensionalDimension;
150
+ /**
151
+ * Represents a Date Dimension in a Dimensional Model
152
+ *
153
+ * @internal
154
+ */
155
+ class DimensionalDateDimension extends DimensionalDimension {
156
+ constructor(name, expression, desc, sort) {
157
+ super(name, expression, [], [], types_js_1.MetadataTypes.DateDimension, desc, sort);
158
+ this.defaultLevel = types_js_1.DateLevels.Years;
159
+ this.Years = new attributes_js_1.DimensionalLevelAttribute(types_js_1.DateLevels.Years, expression, types_js_1.DateLevels.Years, 'yyyy');
160
+ this.Quarters = new attributes_js_1.DimensionalLevelAttribute(types_js_1.DateLevels.Quarters, expression, types_js_1.DateLevels.Quarters, 'Q yyyy');
161
+ this.Months = new attributes_js_1.DimensionalLevelAttribute(types_js_1.DateLevels.Months, expression, types_js_1.DateLevels.Months, 'yyyy-MM');
162
+ this.Weeks = new attributes_js_1.DimensionalLevelAttribute(types_js_1.DateLevels.Weeks, expression, types_js_1.DateLevels.Weeks, 'ww yyyy');
163
+ this.Days = new attributes_js_1.DimensionalLevelAttribute(types_js_1.DateLevels.Days, expression, types_js_1.DateLevels.Days, 'yyyy-MM-dd');
164
+ this.Hours = new attributes_js_1.DimensionalLevelAttribute(types_js_1.DateLevels.Hours, expression, types_js_1.DateLevels.Hours, 'yyyy-MM-dd HH:mm');
165
+ this.MinutesRoundTo30 = new attributes_js_1.DimensionalLevelAttribute(types_js_1.DateLevels.MinutesRoundTo30, expression, types_js_1.DateLevels.MinutesRoundTo30, 'yyyy-MM-dd HH:mm');
166
+ this.MinutesRoundTo15 = new attributes_js_1.DimensionalLevelAttribute(types_js_1.DateLevels.MinutesRoundTo15, expression, types_js_1.DateLevels.MinutesRoundTo15, 'yyyy-MM-dd HH:mm');
167
+ this.AggHours = new attributes_js_1.DimensionalLevelAttribute(types_js_1.DateLevels.AggHours, expression, types_js_1.DateLevels.AggHours, 'HH:mm');
168
+ this.AggMinutesRoundTo30 = new attributes_js_1.DimensionalLevelAttribute(types_js_1.DateLevels.AggMinutesRoundTo30, expression, types_js_1.DateLevels.AggMinutesRoundTo30, 'HH:mm');
169
+ this.AggMinutesRoundTo15 = new attributes_js_1.DimensionalLevelAttribute(types_js_1.DateLevels.AggMinutesRoundTo15, expression, types_js_1.DateLevels.AggMinutesRoundTo15, 'HH:mm');
170
+ this.AggMinutesRoundTo1 = new attributes_js_1.DimensionalLevelAttribute(types_js_1.DateLevels.AggMinutesRoundTo1, expression, types_js_1.DateLevels.AggMinutesRoundTo1, 'HH:mm');
171
+ this.setAttributes([
172
+ this.Years,
173
+ this.Quarters,
174
+ this.Months,
175
+ this.Weeks,
176
+ this.Days,
177
+ this.Hours,
178
+ this.MinutesRoundTo30,
179
+ this.MinutesRoundTo15,
180
+ this.AggHours,
181
+ this.AggMinutesRoundTo30,
182
+ this.AggMinutesRoundTo15,
183
+ this.AggMinutesRoundTo1,
184
+ ]);
185
+ }
186
+ /**
187
+ * gets the element's ID
188
+ */
189
+ get id() {
190
+ return this.expression;
191
+ }
192
+ setDimensions() {
193
+ /* */
194
+ }
195
+ setAttributes(attributes) {
196
+ this._attributes = attributes;
197
+ }
198
+ /**
199
+ * Gets the sort definition of this instance
200
+ *
201
+ * @returns The Sort definition of this instance
202
+ */
203
+ getSort() {
204
+ return this._sort;
205
+ }
206
+ /**
207
+ * Gets a sorted {@link Dimension} with the given definition
208
+ *
209
+ * @param sort - Sort definition
210
+ * @returns An instance representing the sorted {@link Dimension} of this instance
211
+ */
212
+ sort(sort) {
213
+ return new DimensionalDateDimension(this.name, this.expression, this.description, sort);
214
+ }
215
+ /**
216
+ * Gets a serializable representation of the element
217
+ */
218
+ serializable() {
219
+ const result = super.serializable();
220
+ if (this.defaultLevel) {
221
+ result.defaultLevel = this.defaultLevel;
222
+ }
223
+ return result;
224
+ }
225
+ /**
226
+ * Gets the JAQL representation of this instance
227
+ *
228
+ * @param nested - defines whether the JAQL is nested within parent JAQL statement or a root JAQL element
229
+ */
230
+ jaql(nested) {
231
+ const result = this[this.defaultLevel].jaql();
232
+ result.jaql.title = this.name;
233
+ return nested ? result.jaql : result;
234
+ }
235
+ }
236
+ exports.DimensionalDateDimension = DimensionalDateDimension;
237
+ /**
238
+ * Creates a new Dimension instance from the given JSON object.
239
+ *
240
+ * This function is used in the generated data model code to create dimensions for an input data source.
241
+ *
242
+ * See also functions {@link createDateDimension} and {@link createAttribute}.
243
+ *
244
+ * @param json - JSON object representing the Dimension
245
+ * @returns A new Dimension instance
246
+ * @group Data Model Utilities
247
+ */
248
+ function createDimension(json) {
249
+ const name = json.name || json.title;
250
+ const description = json.desc || json.description;
251
+ const expression = json.expression || json.dim;
252
+ const type = DimensionalDimension.parseType(json.dimtype || json.type);
253
+ // date dimension
254
+ if (type == types_js_1.MetadataTypes.DateDimension) {
255
+ return new DimensionalDateDimension(name, expression, description);
256
+ }
257
+ // attributes
258
+ const atts = Object.getOwnPropertyNames(json)
259
+ .map((p) => json[p])
260
+ .filter((v) => types_js_1.MetadataTypes.isAttribute(v.type));
261
+ if (atts.length == 0) {
262
+ if (json.attributes) {
263
+ let att;
264
+ for (let i = 0; i < json.attributes.length; i++) {
265
+ att = json.attributes[i];
266
+ atts.push(new attributes_js_1.DimensionalAttribute(att.name, att.expression, att.type, att.description));
267
+ }
268
+ }
269
+ // default attribute
270
+ else if (expression) {
271
+ atts.push(new attributes_js_1.DimensionalAttribute(name, expression, type, description));
272
+ }
273
+ }
274
+ // nested dimensions
275
+ const dims = Object.getOwnPropertyNames(json)
276
+ .map((p) => json[p])
277
+ .filter((v) => types_js_1.MetadataTypes.isDimension(v.type));
278
+ if (dims.length == 0 && json.dimensions) {
279
+ for (let i = 0; i < json.dimensions.length; i++) {
280
+ dims.push(createDimension(json.dimensions[i]));
281
+ }
282
+ }
283
+ const d = new DimensionalDimension(name, expression, atts, dims, type, description);
284
+ if (json.defaultAttribute) {
285
+ d.defaultAttribute = atts.find((a) => a.name === json.defaultAttribute);
286
+ }
287
+ return d;
288
+ }
289
+ exports.createDimension = createDimension;
290
+ /**
291
+ * Creates a new Date Dimension instance from the given JSON object.
292
+ *
293
+ * This function is used in the generated data model code to create date dimensions for an input data source.
294
+ *
295
+ * See also functions {@link createDimension} and {@link createAttribute}.
296
+ *
297
+ * @param json - JSON object representing the Date Dimension
298
+ * @returns A new Date Dimension instance
299
+ * @group Data Model Utilities
300
+ */
301
+ function createDateDimension(json) {
302
+ const name = json.name || json.title;
303
+ const expression = json.expression || json.dim;
304
+ const description = json.desc || json.description;
305
+ return new DimensionalDateDimension(name, expression, description);
306
+ }
307
+ exports.createDateDimension = createDateDimension;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
4
+ /* eslint-disable @typescript-eslint/no-unsafe-call */
5
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
6
+ const attributes_js_1 = require("./attributes.js");
7
+ const dimensions_js_1 = require("./dimensions.js");
8
+ const types_js_1 = require("./types.js");
9
+ describe('Dimension jaql preparations', () => {
10
+ it('must prepare simple text dimension jaql', () => {
11
+ const result = { jaql: { title: 'Brand', dim: '[Brand.Brand]', datatype: 'text' } };
12
+ const dimension = new dimensions_js_1.DimensionalDimension('Brand', '[Brand.Brand]', [new attributes_js_1.DimensionalAttribute('Brand', '[Brand.Brand]')], [], 'textdimension');
13
+ const jaql = dimension.jaql();
14
+ expect(jaql).toStrictEqual(result);
15
+ });
16
+ it('must prepare simple text dimension with default attribute jaql', () => {
17
+ const result = { jaql: { title: 'Brand', dim: '[Brand.Brand]', datatype: 'text' } };
18
+ const attribute = new attributes_js_1.DimensionalAttribute('Brand', '[Brand.Brand]');
19
+ const dimension = new dimensions_js_1.DimensionalDimension('Brand', '[Brand.Brand]', [attribute], [], 'textdimension');
20
+ dimension.defaultAttribute = attribute;
21
+ const jaql = dimension.jaql();
22
+ expect(jaql).toStrictEqual(result);
23
+ });
24
+ it('must prepare simple text dimension with nested dimension jaql', () => {
25
+ const result = { jaql: { title: 'Brand', dim: '[Brand.Brand]', datatype: 'text' } };
26
+ const dimension = new dimensions_js_1.DimensionalDimension('Brand', '', [new attributes_js_1.DimensionalAttribute('Brand', '')], [
27
+ new dimensions_js_1.DimensionalDimension('Brand', '[Brand.Brand]', [new attributes_js_1.DimensionalAttribute('Brand', '[Brand.Brand]')], [], 'textdimension'),
28
+ ], 'textdimension');
29
+ const jaql = dimension.jaql();
30
+ expect(jaql).toStrictEqual(result);
31
+ });
32
+ it('must prepare date dimension jaql', () => {
33
+ const result = {
34
+ jaql: {
35
+ title: 'Date',
36
+ dim: '[Commerce.Date (Calendar)]',
37
+ level: 'years',
38
+ datatype: 'datetime',
39
+ },
40
+ format: { mask: { years: 'yyyy' } },
41
+ };
42
+ const dimension = new dimensions_js_1.DimensionalDateDimension('Date', '[Commerce.Date (Calendar)]');
43
+ const jaql = dimension.jaql();
44
+ expect(jaql).toStrictEqual(result);
45
+ });
46
+ it('must handle sort', () => {
47
+ const dimensionAscSort = new dimensions_js_1.DimensionalDimension('Brand', '[Brand.Brand]', [new attributes_js_1.DimensionalAttribute('Brand', '[Brand.Brand]')], [], 'textdimension', '', types_js_1.Sort.Ascending);
48
+ const dimensionDescSort = new dimensions_js_1.DimensionalDimension('Brand', '[Brand.Brand]', [new attributes_js_1.DimensionalAttribute('Brand', '[Brand.Brand]')], [], 'textdimension', '', types_js_1.Sort.Descending);
49
+ const jaqlAscSort = dimensionAscSort.jaql();
50
+ const jaqlDescSort = dimensionDescSort.jaql();
51
+ expect(jaqlAscSort.jaql.sort).toBe('asc');
52
+ expect(jaqlDescSort.jaql.sort).toBe('desc');
53
+ });
54
+ });
@@ -0,0 +1,17 @@
1
+ import { Element } from './interfaces.js';
2
+ /**
3
+ * Generate an array of dimension model instances out of the given JSON array
4
+ *
5
+ * @param items - a JSON array to create an elements from
6
+ * @returns a dimensional model instances
7
+ * @internal
8
+ */
9
+ export declare function createAll(items: Array<any>): Element[];
10
+ /**
11
+ * Generate a dimension model instance out of the given JSON object
12
+ *
13
+ * @param item - a JSON object to create an Element from
14
+ * @returns a dimensional model instance
15
+ * @internal
16
+ */
17
+ export declare function create(item: any): Element | Element[];
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.create = exports.createAll = void 0;
4
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
5
+ const types_js_1 = require("./types.js");
6
+ const measures_js_1 = require("./measures/measures.js");
7
+ const filters_js_1 = require("./filters/filters.js");
8
+ const dimensions_js_1 = require("./dimensions.js");
9
+ const attributes_js_1 = require("./attributes.js");
10
+ const translatable_error_js_1 = require("../translation/translatable-error.js");
11
+ /**
12
+ * Generate an array of dimension model instances out of the given JSON array
13
+ *
14
+ * @param items - a JSON array to create an elements from
15
+ * @returns a dimensional model instances
16
+ * @internal
17
+ */
18
+ function createAll(items) {
19
+ return items.map((e) => create(e));
20
+ }
21
+ exports.createAll = createAll;
22
+ /**
23
+ * Generate a dimension model instance out of the given JSON object
24
+ *
25
+ * @param item - a JSON object to create an Element from
26
+ * @returns a dimensional model instance
27
+ * @internal
28
+ */
29
+ function create(item) {
30
+ if (Array.isArray(item)) {
31
+ return createAll(item);
32
+ }
33
+ // todo: implement filter generation
34
+ if (types_js_1.MetadataTypes.isFilter(item)) {
35
+ return (0, filters_js_1.createFilter)(item);
36
+ }
37
+ else if (types_js_1.MetadataTypes.isMeasure(item)) {
38
+ return (0, measures_js_1.createMeasure)(item);
39
+ }
40
+ else if (types_js_1.MetadataTypes.isAttribute(item)) {
41
+ return (0, attributes_js_1.createAttribute)(item);
42
+ }
43
+ // dimension
44
+ else if (types_js_1.MetadataTypes.isDimension(item) ||
45
+ item.dim ||
46
+ item.id ||
47
+ item.type === 'dimension' ||
48
+ item.attributes ||
49
+ item.dimtype) {
50
+ return (0, dimensions_js_1.createDimension)(item);
51
+ }
52
+ throw new translatable_error_js_1.TranslatableError('errors.unsupportedDimensionalElement');
53
+ }
54
+ exports.create = create;