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