@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.
Files changed (31) hide show
  1. package/LICENSE.md +35 -0
  2. package/README.md +3 -0
  3. package/dist/dimensional-model/attributes.d.ts +124 -0
  4. package/dist/dimensional-model/attributes.js +280 -0
  5. package/dist/dimensional-model/base.d.ts +38 -0
  6. package/dist/dimensional-model/base.js +37 -0
  7. package/dist/dimensional-model/data-model.d.ts +13 -0
  8. package/dist/dimensional-model/data-model.js +32 -0
  9. package/dist/dimensional-model/dimensions.d.ts +165 -0
  10. package/dist/dimensional-model/dimensions.js +297 -0
  11. package/dist/dimensional-model/factory.d.ts +17 -0
  12. package/dist/dimensional-model/factory.js +50 -0
  13. package/dist/dimensional-model/filters/factory.d.ts +315 -0
  14. package/dist/dimensional-model/filters/factory.js +404 -0
  15. package/dist/dimensional-model/filters/filters.d.ts +288 -0
  16. package/dist/dimensional-model/filters/filters.js +534 -0
  17. package/dist/dimensional-model/interfaces.d.ts +341 -0
  18. package/dist/dimensional-model/interfaces.js +1 -0
  19. package/dist/dimensional-model/measures/factory.d.ts +437 -0
  20. package/dist/dimensional-model/measures/factory.js +632 -0
  21. package/dist/dimensional-model/measures/measures.d.ts +217 -0
  22. package/dist/dimensional-model/measures/measures.js +388 -0
  23. package/dist/dimensional-model/simple-column-types.d.ts +39 -0
  24. package/dist/dimensional-model/simple-column-types.js +124 -0
  25. package/dist/dimensional-model/types.d.ts +152 -0
  26. package/dist/dimensional-model/types.js +284 -0
  27. package/dist/index.d.ts +79 -0
  28. package/dist/index.js +79 -0
  29. package/dist/interfaces.d.ts +233 -0
  30. package/dist/interfaces.js +9 -0
  31. package/package.json +47 -0
@@ -0,0 +1,534 @@
1
+ import { DimensionalElement } from '../base.js';
2
+ import { DateLevels, MetadataTypes } from '../types.js';
3
+ import { Guid } from 'guid-typescript';
4
+ import { create } from '../factory.js';
5
+ import { DimensionalBaseMeasure } from '../measures/measures.js';
6
+ /**
7
+ * Different text operators that can be used with text filters
8
+ *
9
+ * @internal
10
+ */
11
+ export const TextOperators = {
12
+ Contains: 'contains',
13
+ StartsWith: 'startsWith',
14
+ EndsWith: 'endsWith',
15
+ Equals: 'equals',
16
+ DoesntEqual: 'doesntEqual',
17
+ DoesntStartWith: 'doesntStartWith',
18
+ DoesntContain: 'doesntContain',
19
+ DoesntEndWith: 'doesntEndWidth',
20
+ Like: 'like',
21
+ };
22
+ /**
23
+ * Different numeric operators that can be used with numeric filters
24
+ */
25
+ export const NumericOperators = {
26
+ Equals: 'equals',
27
+ DoesntEqual: 'doesntEqual',
28
+ From: 'from',
29
+ FromNotEqual: 'fromNotEqual',
30
+ To: 'to',
31
+ ToNotEqual: 'toNotEqual',
32
+ };
33
+ /**
34
+ * Different date operators that can be used with date filters
35
+ *
36
+ * @internal
37
+ */
38
+ export const DateOperators = {
39
+ From: 'from',
40
+ To: 'to',
41
+ Last: 'last',
42
+ Next: 'next',
43
+ Anchor: 'Anchor',
44
+ };
45
+ /**
46
+ * Different logical operators that can be used with logical filters
47
+ *
48
+ * @internal
49
+ */
50
+ export const LogicalOperators = {
51
+ Union: 'or',
52
+ Intersection: 'and',
53
+ Exclude: 'exclude',
54
+ };
55
+ /**
56
+ * Different ranking operators that can be used with ranking filter
57
+ *
58
+ * @internal
59
+ */
60
+ export const RankingOperators = {
61
+ Top: 'top',
62
+ Bottom: 'bottom',
63
+ };
64
+ /**
65
+ * Different filter types
66
+ *
67
+ * @internal
68
+ */
69
+ export const FilterTypes = {
70
+ logicalAttribute: 'logicalAttribute',
71
+ members: 'members',
72
+ exclude: 'exclude',
73
+ measure: 'measure',
74
+ ranking: 'ranking',
75
+ text: 'text',
76
+ numeric: 'numeric',
77
+ date: 'date',
78
+ relativeDate: 'relativeDate',
79
+ };
80
+ // CLASSES
81
+ /**
82
+ * base implementation for filter classes
83
+ *
84
+ * @internal
85
+ */
86
+ class AbstractFilter extends DimensionalElement {
87
+ constructor(att, filterType) {
88
+ super(Guid.create().toString(), MetadataTypes.Filter);
89
+ this.filterType = filterType;
90
+ AbstractFilter.checkAttributeSupport(att);
91
+ this.attribute = att;
92
+ }
93
+ /**
94
+ * Gets a serializable representation of the element
95
+ */
96
+ serializable() {
97
+ const result = super.serializable();
98
+ result.filterType = this.filterType;
99
+ result.attribute = this.attribute.serializable();
100
+ return result;
101
+ }
102
+ /**
103
+ * Gets the JAQL representation of this instance
104
+ *
105
+ * @param nested - defines whether the JAQL is nested within parent JAQL statement or a root JAQL element
106
+ */
107
+ jaql(nested) {
108
+ const result = this.attribute.jaql(false);
109
+ const level = this.attribute;
110
+ if (level.getFormat && level.getFormat() !== undefined) {
111
+ const granularityJaql = level.translateGranularityToJaql();
112
+ result.format = {
113
+ mask: {
114
+ [granularityJaql.level]: level.getFormat(),
115
+ },
116
+ };
117
+ }
118
+ result.jaql.filter = this.filterJaql();
119
+ if (this.isScope) {
120
+ result.panel = 'scope';
121
+ }
122
+ return nested === true ? result.jaql : result;
123
+ }
124
+ static checkAttributeSupport(attribute) {
125
+ const { granularity } = attribute;
126
+ if (granularity === DateLevels.Hours ||
127
+ granularity === DateLevels.MinutesRoundTo30 ||
128
+ granularity === DateLevels.MinutesRoundTo15) {
129
+ throw new Error('Filters do not support the next "datetime" levels: Hours, MinutesRoundTo30, MinutesRoundTo15');
130
+ }
131
+ }
132
+ }
133
+ /**
134
+ * @internal
135
+ */
136
+ export class LogicalAttributeFilter extends AbstractFilter {
137
+ constructor(filters, operator) {
138
+ super(filters[0].attribute, FilterTypes.logicalAttribute);
139
+ this.operator = operator;
140
+ this.filters = filters;
141
+ }
142
+ /**
143
+ * gets the element's ID
144
+ */
145
+ get id() {
146
+ return `${this.operator}_${this.filters.map((f) => f.id).join()}`;
147
+ }
148
+ /**
149
+ * Gets a serializable representation of the element
150
+ */
151
+ serializable() {
152
+ const result = super.serializable();
153
+ result.operator = this.operator;
154
+ result.filters = this.filters.map((f) => f.serializable());
155
+ return result;
156
+ }
157
+ /**
158
+ * Gets JAQL representing this Filter instance
159
+ */
160
+ filterJaql() {
161
+ const result = {};
162
+ result[this.operator] = this.filters.map((f) => f.filterJaql());
163
+ return result;
164
+ }
165
+ }
166
+ /**
167
+ * @internal
168
+ */
169
+ export class MembersFilter extends AbstractFilter {
170
+ constructor(attribute, members) {
171
+ super(attribute, FilterTypes.members);
172
+ this.members = members !== null && members !== void 0 ? members : [];
173
+ if (this.members.filter((m) => m === null || m === undefined).length > 0) {
174
+ throw `MembersFilter of ${attribute.id} - member cannot be null`;
175
+ }
176
+ }
177
+ /**
178
+ * gets the element's ID
179
+ */
180
+ get id() {
181
+ return `${this.attribute.id}_${this.members.map((m) => m.toString()).join()}`;
182
+ }
183
+ /**
184
+ * Gets a serializable representation of the element
185
+ */
186
+ serializable() {
187
+ const result = super.serializable();
188
+ result.members = this.members;
189
+ return result;
190
+ }
191
+ /**
192
+ * Gets JAQL representing this Filter instance
193
+ */
194
+ filterJaql() {
195
+ return {
196
+ members: this.members.map((m) => m.toString()),
197
+ };
198
+ }
199
+ }
200
+ /**
201
+ * @internal
202
+ */
203
+ export class ExcludeFilter extends AbstractFilter {
204
+ constructor(filter, input) {
205
+ super(filter.attribute, FilterTypes.exclude);
206
+ this.input = input;
207
+ this.filter = filter;
208
+ }
209
+ /**
210
+ * gets the element's ID
211
+ */
212
+ get id() {
213
+ let result = `exclude_${this.filter.id}`;
214
+ if (this.input) {
215
+ result += '_from_' + this.input.id;
216
+ }
217
+ return result;
218
+ }
219
+ /**
220
+ * Gets a serializable representation of the element
221
+ */
222
+ serializable() {
223
+ const result = super.serializable();
224
+ result.filter = this.filter.serializable();
225
+ if (this.input) {
226
+ result.input = this.input.serializable();
227
+ }
228
+ return result;
229
+ }
230
+ /**
231
+ * Gets JAQL representing this Filter instance
232
+ */
233
+ filterJaql() {
234
+ const result = {};
235
+ const exclusion = this.filter.filterJaql();
236
+ if (this.input) {
237
+ result.filter = this.input.filterJaql();
238
+ result.filter.filter = { exclude: exclusion };
239
+ }
240
+ else {
241
+ result.exclude = exclusion;
242
+ }
243
+ return result;
244
+ }
245
+ }
246
+ /**
247
+ * @internal
248
+ */
249
+ export class DoubleOperatorFilter extends AbstractFilter {
250
+ constructor(att, filterType, operatorA, valueA, operatorB, valueB) {
251
+ super(att, filterType);
252
+ if (operatorA && valueA !== undefined) {
253
+ this.valueA = valueA;
254
+ this.operatorA = operatorA;
255
+ }
256
+ if (operatorB && valueB !== undefined) {
257
+ this.operatorB = operatorB;
258
+ this.valueB = valueB;
259
+ }
260
+ }
261
+ /**
262
+ * gets the element's ID
263
+ */
264
+ get id() {
265
+ let result = `${this.attribute.id}`;
266
+ if (this.operatorA && this.valueA !== undefined) {
267
+ result += `_${this.operatorA}:${this.valueA}`;
268
+ }
269
+ if (this.operatorB && this.valueB !== undefined) {
270
+ result += `_${this.operatorB}:${this.valueB}`;
271
+ }
272
+ return result;
273
+ }
274
+ /**
275
+ * Gets a serializable representation of the element
276
+ */
277
+ serializable() {
278
+ const result = super.serializable();
279
+ if (this.operatorA) {
280
+ result.operatorA = this.operatorA;
281
+ }
282
+ if (this.operatorB) {
283
+ result.operatorB = this.operatorB;
284
+ }
285
+ if (this.valueA !== undefined) {
286
+ result.valueA = this.valueA;
287
+ }
288
+ if (this.valueB !== undefined) {
289
+ result.valueB = this.valueB;
290
+ }
291
+ return result;
292
+ }
293
+ /**
294
+ * Gets JAQL representing this Filter instance
295
+ */
296
+ filterJaql() {
297
+ const result = {};
298
+ if (this.operatorA && this.valueA !== undefined) {
299
+ result[this.operatorA] = this.valueA;
300
+ }
301
+ if (this.operatorB && this.valueB !== undefined) {
302
+ result[this.operatorB] = this.valueB;
303
+ }
304
+ return result;
305
+ }
306
+ }
307
+ /**
308
+ * @internal
309
+ */
310
+ export class MeasureFilter extends DoubleOperatorFilter {
311
+ constructor(att, measure, operatorA, valueA, operatorB, valueB) {
312
+ super(att, FilterTypes.measure, operatorA, valueA, operatorB, valueB);
313
+ this.measure = measure;
314
+ }
315
+ /**
316
+ * gets the element's ID
317
+ */
318
+ get id() {
319
+ let result = `${this.attribute.id}_${this.measure.id}`;
320
+ if (this.operatorA && this.valueA !== undefined) {
321
+ result += `_${this.operatorA}:${this.valueA}`;
322
+ }
323
+ if (this.operatorB && this.valueB !== undefined) {
324
+ result += `_${this.operatorB}${this.valueB}`;
325
+ }
326
+ return result;
327
+ }
328
+ /**
329
+ * Gets a serializable representation of the element
330
+ */
331
+ serializable() {
332
+ const result = super.serializable();
333
+ result.measure = this.measure.serializable();
334
+ return result;
335
+ }
336
+ jaql(nested) {
337
+ const result = super.jaql(nested);
338
+ if (this.measure instanceof DimensionalBaseMeasure) {
339
+ Object.entries(this.measure.jaql().jaql).forEach(([key, value]) => {
340
+ result.jaql[key] = value;
341
+ });
342
+ }
343
+ return result;
344
+ }
345
+ }
346
+ /**
347
+ * @internal
348
+ */
349
+ export class RankingFilter extends AbstractFilter {
350
+ constructor(att, measure, operator, count) {
351
+ super(att, FilterTypes.ranking);
352
+ this.count = count;
353
+ this.operator = operator;
354
+ this.measure = measure;
355
+ }
356
+ /**
357
+ * gets the element's ID
358
+ */
359
+ get id() {
360
+ return `${this.operator}_${this.count}_${this.attribute.id}_by_${this.measure.id}`;
361
+ }
362
+ /**
363
+ * Gets a serializable representation of the element
364
+ */
365
+ serializable() {
366
+ const result = super.serializable();
367
+ result.count = this.count;
368
+ result.operator = this.operator;
369
+ result.measure = this.measure.serializable();
370
+ return result;
371
+ }
372
+ /**
373
+ * Gets JAQL representing this Filter instance
374
+ */
375
+ filterJaql() {
376
+ const result = {};
377
+ result[this.operator] = this.count;
378
+ result.by = this.measure.jaql(true);
379
+ return result;
380
+ }
381
+ }
382
+ /**
383
+ * @internal
384
+ */
385
+ export class NumericFilter extends DoubleOperatorFilter {
386
+ constructor(att, operatorA, valueA, operatorB, valueB) {
387
+ super(att, FilterTypes.numeric, operatorA, valueA, operatorB, valueB);
388
+ // if (att.dimension && !MetadataTypes.isTextDimension(att.dimension.type)) {
389
+ // throw 'Dimension must be of Text type to be applied with Text filter';
390
+ // }
391
+ }
392
+ }
393
+ /**
394
+ * @internal
395
+ */
396
+ export class TextFilter extends DoubleOperatorFilter {
397
+ constructor(att, operator, value) {
398
+ super(att, FilterTypes.text, operator, value);
399
+ // if (att.dimension && !MetadataTypes.isTextDimension(att.dimension.type)) {
400
+ // throw 'Dimension must be of Text type to be applied with Text filter';
401
+ // }
402
+ }
403
+ }
404
+ /**
405
+ * @internal
406
+ */
407
+ export class DateRangeFilter extends DoubleOperatorFilter {
408
+ constructor(l, valueFrom, valueTo) {
409
+ super(l, FilterTypes.date, DateOperators.From, valueFrom, DateOperators.To, valueTo);
410
+ if (typeof valueFrom === 'object') {
411
+ this.valueA = valueFrom.toISOString();
412
+ }
413
+ if (typeof valueTo === 'object') {
414
+ this.valueB = valueTo.toISOString();
415
+ }
416
+ }
417
+ get level() {
418
+ return this.attribute;
419
+ }
420
+ get from() {
421
+ return this.valueA;
422
+ }
423
+ get to() {
424
+ return this.valueB;
425
+ }
426
+ /**
427
+ * Gets JAQL representing this Filter instance
428
+ */
429
+ filterJaql() {
430
+ return super.filterJaql();
431
+ }
432
+ }
433
+ /**
434
+ * @internal
435
+ */
436
+ export class RelativeDateFilter extends AbstractFilter {
437
+ constructor(l, offset, count, operator, anchor) {
438
+ super(l, FilterTypes.relativeDate);
439
+ if (!operator) {
440
+ operator = DateOperators.Next;
441
+ }
442
+ this.anchor = anchor;
443
+ this.operator = operator;
444
+ this.offset = offset;
445
+ this.count = count;
446
+ }
447
+ get level() {
448
+ return this.attribute;
449
+ }
450
+ /**
451
+ * gets the element's ID
452
+ */
453
+ get id() {
454
+ let result = `${this.level.id}_${this.operator}_${this.offset}_${this.count}`;
455
+ if (this.anchor) {
456
+ if (typeof this.anchor === 'string') {
457
+ result += `_${this.anchor}`;
458
+ }
459
+ else if (typeof this.anchor === 'object') {
460
+ result += `_${this.anchor.toISOString()}`;
461
+ }
462
+ }
463
+ return result;
464
+ }
465
+ /**
466
+ * Gets a serializable representation of the element
467
+ */
468
+ serializable() {
469
+ const result = super.serializable();
470
+ result.offset = this.offset;
471
+ result.count = this.count;
472
+ result.operator = this.operator;
473
+ if (this.anchor) {
474
+ result.anchor = this.anchor;
475
+ }
476
+ return result;
477
+ }
478
+ /**
479
+ * Gets JAQL representing this Filter instance
480
+ *
481
+ */
482
+ filterJaql() {
483
+ const result = {};
484
+ result[this.operator] = {
485
+ offset: this.offset,
486
+ count: this.count,
487
+ };
488
+ if (this.anchor) {
489
+ if (typeof this.anchor === 'string') {
490
+ result[this.operator].anchor = this.anchor;
491
+ }
492
+ else if (typeof this.anchor === 'object') {
493
+ result[this.operator].anchor = this.anchor.toISOString();
494
+ }
495
+ }
496
+ return result;
497
+ }
498
+ }
499
+ /**
500
+ * @param json
501
+ * @internal
502
+ */
503
+ export function createFilter(json) {
504
+ switch (json.filterType) {
505
+ case FilterTypes.logicalAttribute:
506
+ return new LogicalAttributeFilter(json.filters.map((f) => createFilter(f)), json.operator);
507
+ break;
508
+ case FilterTypes.members:
509
+ return new MembersFilter(create(json.attribute), json.members);
510
+ break;
511
+ case FilterTypes.exclude:
512
+ return new ExcludeFilter(createFilter(json.filter), json.input && createFilter(json.input));
513
+ break;
514
+ case FilterTypes.measure:
515
+ return new MeasureFilter(create(json.attribute), create(json.measure), json.operatorA, json.valueA, json.operatorB, json.valueB);
516
+ break;
517
+ case FilterTypes.ranking:
518
+ return new RankingFilter(create(json.attribute), create(json.measure), json.operator, json.count);
519
+ break;
520
+ case FilterTypes.numeric:
521
+ return new NumericFilter(create(json.attribute), json.operatorA, json.valueA, json.operatorB, json.valueB);
522
+ break;
523
+ case FilterTypes.text:
524
+ return new TextFilter(create(json.attribute), json.operatorA, json.valueA);
525
+ break;
526
+ case FilterTypes.relativeDate:
527
+ return new RelativeDateFilter(create(json.attribute), json.offset, json.count, json.operator, json.anchor);
528
+ break;
529
+ case FilterTypes.date:
530
+ return new DateRangeFilter(create(json.attribute), json.valueA, json.valueB);
531
+ break;
532
+ }
533
+ throw 'unsupported filter type';
534
+ }