@sisense/sdk-data 1.1.0 → 1.3.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.
@@ -1,4 +1,4 @@
1
- import { DateDimension, LevelAttribute, Attribute, Measure, Filter, BaseMeasure, FilterRelationNode, FilterRelation } from '../interfaces.js';
1
+ import { DateDimension, LevelAttribute, Attribute, Measure, Filter, BaseMeasure, FilterRelationsNode, FilterRelations } from '../interfaces.js';
2
2
  /**
3
3
  * Creates a filter representing the union of multiple filters on the same attribute. The resulting
4
4
  * union filter filters on items that match any of the given filters.
@@ -632,7 +632,7 @@ export declare function topRanking(attribute: Attribute, measure: Measure, count
632
632
  */
633
633
  export declare function bottomRanking(attribute: Attribute, measure: Measure, count: number): Filter;
634
634
  /**
635
- * Set of logic operators for filter relation construction
635
+ * Set of logic operators for filter relations construction
636
636
  *
637
637
  * These operators are still in beta.
638
638
  *
@@ -646,7 +646,7 @@ export declare function bottomRanking(attribute: Attribute, measure: Measure, co
646
646
  * const genderFilter = filterFactory.doesntContain(DM.Commerce.Gender, 'Unspecified');
647
647
  * const costFilter = filterFactory.between(DM.Commerce.Cost, 1000, 2000);
648
648
  *
649
- * // create filter relation of two filters
649
+ * // create filter relations of two filters
650
650
  * const orFilerRelations = filterFactory.logic.or(revenueFilter, countryFilter);
651
651
  * // revenueFilter OR countryFilter
652
652
  *
@@ -662,10 +662,10 @@ export declare function bottomRanking(attribute: Attribute, measure: Measure, co
662
662
  */
663
663
  export declare namespace logic {
664
664
  /**
665
- * Creates an 'AND' filter relation
665
+ * Creates an 'AND' filter relations
666
666
  *
667
667
  * @example
668
- * Create a filter relation for items that have a revenue greater than 100 and are in new condition
668
+ * Create filter relations for items that have a revenue greater than 100 and are in new condition
669
669
  * in the Sample ECommerce data model.
670
670
  * ```ts
671
671
  * const revenueFilter = filterFactory.greaterThan(DM.Commerce.Revenue, 100);
@@ -673,17 +673,17 @@ export declare namespace logic {
673
673
  *
674
674
  * const andFilerRelation = filterFactory.logic.and(revenueFilter, conditionFilter);
675
675
  * ```
676
- * @param left First filter or filter relation
677
- * @param right Second filter or filter relation
678
- * @returns A filter relation
676
+ * @param left First filter or filter relations
677
+ * @param right Second filter or filter relations
678
+ * @returns Filter relations
679
679
  * @beta
680
680
  */
681
- const and: (left: FilterRelationNode, right: FilterRelationNode) => FilterRelation;
681
+ const and: (left: FilterRelationsNode, right: FilterRelationsNode) => FilterRelations;
682
682
  /**
683
- * Creates an 'OR' filter relation
683
+ * Creates an 'OR' filter relations
684
684
  *
685
685
  * @example
686
- * Create a filter relation for items that have a revenue greater than 100 or are in new condition
686
+ * Create filter relations for items that have a revenue greater than 100 or are in new condition
687
687
  * in the Sample ECommerce data model.
688
688
  * ```ts
689
689
  * const revenueFilter = filterFactory.greaterThan(DM.Commerce.Revenue, 100);
@@ -691,10 +691,10 @@ export declare namespace logic {
691
691
  *
692
692
  * const orFilerRelation = filterFactory.logic.or(revenueFilter, conditionFilter);
693
693
  * ```
694
- * @param left First filter or filter relation
695
- * @param right Second filter or filter relation
696
- * @returns A filter relation
694
+ * @param left First filter or filter relations
695
+ * @param right Second filter or filter relations
696
+ * @returns Filter relations
697
697
  * @beta
698
698
  */
699
- const or: (left: FilterRelationNode, right: FilterRelationNode) => FilterRelation;
699
+ const or: (left: FilterRelationsNode, right: FilterRelationsNode) => FilterRelations;
700
700
  }
@@ -734,7 +734,7 @@ const relate = (node) => {
734
734
  return node;
735
735
  };
736
736
  /**
737
- * Set of logic operators for filter relation construction
737
+ * Set of logic operators for filter relations construction
738
738
  *
739
739
  * These operators are still in beta.
740
740
  *
@@ -748,7 +748,7 @@ const relate = (node) => {
748
748
  * const genderFilter = filterFactory.doesntContain(DM.Commerce.Gender, 'Unspecified');
749
749
  * const costFilter = filterFactory.between(DM.Commerce.Cost, 1000, 2000);
750
750
  *
751
- * // create filter relation of two filters
751
+ * // create filter relations of two filters
752
752
  * const orFilerRelations = filterFactory.logic.or(revenueFilter, countryFilter);
753
753
  * // revenueFilter OR countryFilter
754
754
  *
@@ -766,10 +766,10 @@ const relate = (node) => {
766
766
  export var logic;
767
767
  (function (logic) {
768
768
  /**
769
- * Creates an 'AND' filter relation
769
+ * Creates an 'AND' filter relations
770
770
  *
771
771
  * @example
772
- * Create a filter relation for items that have a revenue greater than 100 and are in new condition
772
+ * Create filter relations for items that have a revenue greater than 100 and are in new condition
773
773
  * in the Sample ECommerce data model.
774
774
  * ```ts
775
775
  * const revenueFilter = filterFactory.greaterThan(DM.Commerce.Revenue, 100);
@@ -777,9 +777,9 @@ export var logic;
777
777
  *
778
778
  * const andFilerRelation = filterFactory.logic.and(revenueFilter, conditionFilter);
779
779
  * ```
780
- * @param left First filter or filter relation
781
- * @param right Second filter or filter relation
782
- * @returns A filter relation
780
+ * @param left First filter or filter relations
781
+ * @param right Second filter or filter relations
782
+ * @returns Filter relations
783
783
  * @beta
784
784
  */
785
785
  logic.and = (left, right) => ({
@@ -788,10 +788,10 @@ export var logic;
788
788
  right: relate(right),
789
789
  });
790
790
  /**
791
- * Creates an 'OR' filter relation
791
+ * Creates an 'OR' filter relations
792
792
  *
793
793
  * @example
794
- * Create a filter relation for items that have a revenue greater than 100 or are in new condition
794
+ * Create filter relations for items that have a revenue greater than 100 or are in new condition
795
795
  * in the Sample ECommerce data model.
796
796
  * ```ts
797
797
  * const revenueFilter = filterFactory.greaterThan(DM.Commerce.Revenue, 100);
@@ -799,9 +799,9 @@ export var logic;
799
799
  *
800
800
  * const orFilerRelation = filterFactory.logic.or(revenueFilter, conditionFilter);
801
801
  * ```
802
- * @param left First filter or filter relation
803
- * @param right Second filter or filter relation
804
- * @returns A filter relation
802
+ * @param left First filter or filter relations
803
+ * @param right Second filter or filter relations
804
+ * @returns Filter relations
805
805
  * @beta
806
806
  */
807
807
  logic.or = (left, right) => ({
@@ -346,12 +346,105 @@ export interface Filter extends Element {
346
346
  export interface CustomFormulaContext {
347
347
  [key: string]: Attribute | Measure;
348
348
  }
349
- export declare type FilterRelationNode = Filter | Filter[] | FilterRelation | FilterRelationJaqlNode;
350
- export interface FilterRelation {
351
- left: FilterRelationNode;
352
- right: FilterRelationNode;
349
+ /**
350
+ * Wrapped attribute with additional options for pivot table
351
+ */
352
+ export interface PivotAttribute {
353
+ attribute: Attribute;
354
+ includeSubTotals?: boolean;
355
+ }
356
+ /**
357
+ * Runs type guard check for PivotAttribute.
358
+ *
359
+ * @param arg - object to check
360
+ * @internal
361
+ */
362
+ export declare function isPivotAttribute(arg: Attribute | PivotAttribute): arg is PivotAttribute;
363
+ export declare type TotalsCalculation = 'sum' | 'max' | 'min' | 'avg' | 'median';
364
+ /**
365
+ * Wrapped measure with additional options for pivot table
366
+ */
367
+ export interface PivotMeasure {
368
+ measure: Measure;
369
+ totalsCalculation: TotalsCalculation;
370
+ }
371
+ /**
372
+ * Runs type guard check for PivotMeasure.
373
+ *
374
+ * @param arg - object to check
375
+ * @internal
376
+ */
377
+ export declare function isPivotMeasure(arg: Measure | PivotMeasure): arg is PivotMeasure;
378
+ /**
379
+ * Data options for grand totals of a pivot table
380
+ */
381
+ export declare type PivotGrandTotals = {
382
+ title?: string;
383
+ rows?: boolean;
384
+ columns?: boolean;
385
+ };
386
+ /**
387
+ * @internal
388
+ */
389
+ export declare const DEFAULT_PIVOT_GRAND_TOTALS: PivotGrandTotals;
390
+ /** A node or a subtree of a {@link FilterRelations} tree */
391
+ export declare type FilterRelationsNode = Filter | Filter[] | FilterRelations;
392
+ /**
393
+ * A node or a subtree of a {@link FilterRelationsModel} tree
394
+ *
395
+ * @internal
396
+ */
397
+ export declare type FilterRelationsModelNode = FilterRelationsModelIdNode | FilterRelationsModelBracketNode | FilterRelationsModel;
398
+ /**
399
+ * A node or a subtree of a {@link FilterRelationsJaql} tree
400
+ *
401
+ * @internal
402
+ */
403
+ export declare type FilterRelationsJaqlNode = FilterRelationsJaqlIdNode | FilterRelationsJaql;
404
+ /**
405
+ * Representation of filter logical relations (AND/OR)
406
+ *
407
+ * Unlike {@link FilterRelationsModel} or {@link FilterRelationsJaql},
408
+ * this interface contains filter objects, not just id nodes
409
+ */
410
+ export interface FilterRelations {
411
+ left: FilterRelationsNode;
412
+ right: FilterRelationsNode;
413
+ operator: 'AND' | 'OR';
414
+ }
415
+ /**
416
+ * Incoming filter logical relations (AND/OR) when fetched from the instance
417
+ *
418
+ * @internal
419
+ */
420
+ export interface FilterRelationsModel {
421
+ left: FilterRelationsModelNode;
422
+ right: FilterRelationsModelNode;
353
423
  operator: 'AND' | 'OR';
354
424
  }
355
- export declare type FilterRelationJaqlNode = {
425
+ /**
426
+ * Outgoing filter logical relations (AND/OR) when added to a query
427
+ *
428
+ * @internal
429
+ */
430
+ export interface FilterRelationsJaql {
431
+ left: FilterRelationsJaqlNode;
432
+ right: FilterRelationsJaqlNode;
433
+ operator: 'AND' | 'OR';
434
+ }
435
+ /** A node of a {@link FilterRelationsJaql} tree that represents a filter */
436
+ export declare type FilterRelationsJaqlIdNode = {
356
437
  instanceid: string;
357
438
  };
439
+ /** A node of a {@link FilterRelationsModel} tree that represents a filter */
440
+ export declare type FilterRelationsModelIdNode = {
441
+ instanceId: string;
442
+ };
443
+ /**
444
+ * A node of a {@link FilterRelationsModel} tree that represents a bracket expression
445
+ *
446
+ * @internal
447
+ */
448
+ export declare type FilterRelationsModelBracketNode = {
449
+ value: FilterRelationsModelNode;
450
+ };
@@ -1 +1,26 @@
1
- export {};
1
+ /**
2
+ * Runs type guard check for PivotAttribute.
3
+ *
4
+ * @param arg - object to check
5
+ * @internal
6
+ */
7
+ export function isPivotAttribute(arg) {
8
+ return 'attribute' in arg;
9
+ }
10
+ /**
11
+ * Runs type guard check for PivotMeasure.
12
+ *
13
+ * @param arg - object to check
14
+ * @internal
15
+ */
16
+ export function isPivotMeasure(arg) {
17
+ return 'measure' in arg;
18
+ }
19
+ /**
20
+ * @internal
21
+ */
22
+ export const DEFAULT_PIVOT_GRAND_TOTALS = {
23
+ title: 'Grand Total',
24
+ rows: false,
25
+ columns: false,
26
+ };
@@ -150,16 +150,20 @@ export declare const DateLevels: {
150
150
  /** @internal */
151
151
  readonly all: string[];
152
152
  };
153
+ /** @internal */
153
154
  export declare enum DataType {
154
155
  TEXT = "text",
155
156
  NUMERIC = "numeric",
156
157
  DATETIME = "datetime"
157
158
  }
159
+ /** @internal */
158
160
  export declare enum SortDirection {
159
161
  ASC = "asc",
160
162
  DESC = "desc"
161
163
  }
164
+ /** @internal */
162
165
  export declare type Jaql = BaseJaql | FormulaJaql | FilterJaql;
166
+ /** @internal */
163
167
  export declare type BaseJaql = {
164
168
  agg?: string;
165
169
  datatype: DataType;
@@ -170,8 +174,11 @@ export declare type BaseJaql = {
170
174
  level?: 'years' | 'quarters' | 'months' | 'weeks' | 'minutes' | 'days';
171
175
  sort?: SortDirection;
172
176
  };
177
+ /** @internal */
173
178
  export declare type FormulaID = string;
179
+ /** @internal */
174
180
  export declare type FormulaContext = BaseJaql | FormulaJaql | FilterJaql;
181
+ /** @internal */
175
182
  export declare type FormulaJaql = {
176
183
  type?: 'measure';
177
184
  sort?: SortDirection;
@@ -179,24 +186,31 @@ export declare type FormulaJaql = {
179
186
  formula: string;
180
187
  context?: Record<FormulaID, FormulaContext>;
181
188
  };
189
+ /** @internal */
182
190
  export declare type BaseFilter = IncludeAllFilter | IncludeMembersFilter | ExcludeMembersFilter;
191
+ /** @internal */
183
192
  export declare type BackgroundFilter = BaseFilter & {
184
193
  level?: 'string';
185
194
  };
195
+ /** @internal */
186
196
  export declare type IncludeAllFilter = {
187
197
  all: true;
188
198
  };
199
+ /** @internal */
189
200
  export declare type IncludeMembersFilter = {
190
201
  members: string[];
191
202
  };
203
+ /** @internal */
192
204
  export declare type ExcludeMembersFilter = {
193
205
  exclude: {
194
206
  members: string[];
195
207
  };
196
208
  };
209
+ /** @internal */
197
210
  export declare type TurnOffMembersFilter = ExcludeMembersFilter & {
198
211
  turnedOff: boolean;
199
212
  };
213
+ /** @internal */
200
214
  export declare type FilterJaql = BaseJaql & {
201
215
  filter: BaseFilter & {
202
216
  filter?: BackgroundFilter | TurnOffMembersFilter;
@@ -282,12 +282,14 @@ export const DateLevels = {
282
282
  ];
283
283
  },
284
284
  };
285
+ /** @internal */
285
286
  export var DataType;
286
287
  (function (DataType) {
287
288
  DataType["TEXT"] = "text";
288
289
  DataType["NUMERIC"] = "numeric";
289
290
  DataType["DATETIME"] = "datetime";
290
291
  })(DataType = DataType || (DataType = {}));
292
+ /** @internal */
291
293
  export var SortDirection;
292
294
  (function (SortDirection) {
293
295
  SortDirection["ASC"] = "asc";
@@ -148,6 +148,133 @@ export interface QueryResultData {
148
148
  /** Two-dimensional array of data {@link Cell | cells} */
149
149
  rows: Cell[][];
150
150
  }
151
+ /**
152
+ * Tree node representing data in a pivot table
153
+ */
154
+ export declare type TreeNode = {
155
+ /**
156
+ * Raw data
157
+ */
158
+ value?: string;
159
+ /**
160
+ * Raw data
161
+ *
162
+ * @internal
163
+ */
164
+ content?: string;
165
+ /**
166
+ * Matched index for condition formatting
167
+ *
168
+ * @internal
169
+ */
170
+ cf?: number;
171
+ /**
172
+ * List of children of this node
173
+ */
174
+ children?: Array<TreeNode>;
175
+ /**
176
+ * Data list for rows nodes
177
+ */
178
+ data?: Array<any>;
179
+ /**
180
+ * Index in data list for columns nodes
181
+ */
182
+ index?: number;
183
+ /**
184
+ * Current node's index divergence
185
+ *
186
+ * @internal
187
+ */
188
+ indexDivergence?: number;
189
+ /**
190
+ * Initial child count in raw data from server
191
+ *
192
+ * @internal
193
+ */
194
+ size?: number;
195
+ /**
196
+ * Boolean flag if node is some part of real node
197
+ *
198
+ * @internal
199
+ */
200
+ isPart?: boolean;
201
+ /**
202
+ * Max number of children (measures) nodes to insert
203
+ *
204
+ * @internal
205
+ */
206
+ maxChilds?: number;
207
+ /**
208
+ * Node deep level
209
+ *
210
+ * @internal
211
+ */
212
+ level?: number;
213
+ /**
214
+ * Node min deep level, for columns nodes with values at the and
215
+ *
216
+ * @internal
217
+ */
218
+ minLevel?: number;
219
+ /**
220
+ * Internal cache, to make sure that node was already mapped
221
+ *
222
+ * @internal
223
+ */
224
+ isMapped?: boolean;
225
+ /**
226
+ * Internal cache, for child count
227
+ *
228
+ * @internal
229
+ */
230
+ childCount?: number;
231
+ /**
232
+ * Internal cache, for child deep
233
+ *
234
+ * @internal
235
+ */
236
+ childDeep?: number;
237
+ /**
238
+ * Internal data store
239
+ *
240
+ * @internal
241
+ */
242
+ store?: {
243
+ [key: string]: any;
244
+ };
245
+ };
246
+ /**
247
+ * Grid of tree nodes
248
+ */
249
+ export declare type PivotGrid = Array<Array<TreeNode | string>>;
250
+ /**
251
+ * Pivot query result data set, which includes both a flat table of {@link QueryResultData} and grids of tree structures.
252
+ */
253
+ export interface PivotQueryResultData {
254
+ /**
255
+ * Flat table structure
256
+ *
257
+ * @category Table
258
+ */
259
+ table: QueryResultData;
260
+ /**
261
+ * Grids of tree structures
262
+ *
263
+ * @category Tree Structures
264
+ */
265
+ grids?: {
266
+ corner: PivotGrid;
267
+ rows: PivotGrid;
268
+ columns: PivotGrid;
269
+ values: PivotGrid;
270
+ };
271
+ }
272
+ /**
273
+ * Empty pivot query result data set
274
+ *
275
+ * @internal
276
+ */
277
+ export declare const EMPTY_PIVOT_QUERY_RESULT_DATA: PivotQueryResultData;
151
278
  /**
152
279
  * Runs type guard check for DataSource.
153
280
  *
@@ -1,3 +1,11 @@
1
+ /**
2
+ * Empty pivot query result data set
3
+ *
4
+ * @internal
5
+ */
6
+ export const EMPTY_PIVOT_QUERY_RESULT_DATA = {
7
+ table: { columns: [], rows: [] },
8
+ };
1
9
  /**
2
10
  * Runs type guard check for DataSource.
3
11
  *
package/dist/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Filter, FilterRelation } from './index.js';
1
+ import { Filter, FilterRelations, FilterRelationsJaql } from './index.js';
2
2
  /**
3
3
  * A more performant, but slightly bulkier, RFC4122v4 implementation. Performance is improved by minimizing calls to random()
4
4
  *
@@ -10,7 +10,7 @@ export declare const guidFast: (len?: number) => string;
10
10
  *
11
11
  * @internal
12
12
  */
13
- export declare const getFilterListAndRelations: (filterRelations: FilterRelation | Filter[] | undefined) => {
13
+ export declare const getFilterListAndRelations: (filterRelations: FilterRelations | Filter[] | undefined) => {
14
14
  filters: Filter[] | undefined;
15
- relations: FilterRelation | undefined;
15
+ relations: FilterRelationsJaql | undefined;
16
16
  };
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "Sisense",
12
12
  "Compose SDK"
13
13
  ],
14
- "version": "1.1.0",
14
+ "version": "1.3.0",
15
15
  "type": "module",
16
16
  "exports": {
17
17
  ".": "./dist/index.js",
@@ -23,8 +23,8 @@
23
23
  "author": "Sisense ",
24
24
  "license": "SEE LICENSE IN LICENSE.md",
25
25
  "dependencies": {
26
- "@sisense/sdk-common": "^1.1.0",
27
- "@sisense/sdk-rest-client": "^1.1.0",
26
+ "@sisense/sdk-common": "^1.3.0",
27
+ "@sisense/sdk-rest-client": "^1.3.0",
28
28
  "guid-typescript": "^1.0.9",
29
29
  "lodash": "^4.17.21",
30
30
  "numeral": "^2.0.6",