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