@sisense/sdk-data 0.16.0 → 1.1.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,29 +1,69 @@
1
1
  import { TextOperators, NumericOperators, DateOperators, LogicalOperators, RankingOperators, LogicalAttributeFilter, MembersFilter, ExcludeFilter, NumericFilter, MeasureFilter, RankingFilter, TextFilter, DateRangeFilter, RelativeDateFilter, } from './filters.js';
2
2
  // LOGICAL FILTERS
3
3
  /**
4
- * Creates a filter representing a union of multiple filters of the same attribute.
5
- *
6
- * @param filters - Filters, of the same attribute, to union
7
- * @returns A filter representing a union of the given filters
4
+ * Creates a filter representing the union of multiple filters on the same attribute. The resulting
5
+ * union filter filters on items that match any of the given filters.
6
+ *
7
+ * To create 'or' filters using different attributes, use the {@link logic.and | `or()`} function.
8
+ *
9
+ * @example
10
+ * Filter for countries that start with the letter 'A' **or** end with the letter 'A'
11
+ * in the Sample ECommerce data model.
12
+ * ```ts
13
+ * filterFactory.union([
14
+ * filterFactory.startsWith(DM.Country.Country, 'A'),
15
+ * filterFactory.endsWith(DM.Country.Country, 'A'),
16
+ * ])
17
+ * ```
18
+ * @param filters - Filters to union. The filters must all be on the same attribute.
19
+ * @returns A filter instance
8
20
  */
9
21
  export function union(filters) {
10
22
  return new LogicalAttributeFilter(filters, LogicalOperators.Union);
11
23
  }
12
24
  /**
13
- * Creates a filter representing an intersection of multiple filters of the same attribute.
25
+ * Creates a filter representing the intersection of multiple filters on the same attribute. The resulting
26
+ * intersection filter filters on items that match all of the given filters.
27
+ *
28
+ * To create 'and' filters using different attributes, use the {@link logic.and | `and()`} function.
14
29
  *
15
- * @param filters - Filters, of the same attribute, to intersect
16
- * @returns A filter representing an intersection of the given filters
30
+ * @example
31
+ * Filter for countries that start with the letter 'A' **and** end with the letter 'A'
32
+ * in the Sample ECommerce data model.
33
+ * ```ts
34
+ * filterFactory.intersection([
35
+ * filterFactory.startsWith(DM.Country.Country, 'A'),
36
+ * filterFactory.endsWith(DM.Country.Country, 'A'),
37
+ * ])
38
+ * ```
39
+ * @param filters - Filters to intersect. The filters must all be on the same attribute.
40
+ * @returns A filter instance
17
41
  */
18
42
  export function intersection(filters) {
19
43
  return new LogicalAttributeFilter(filters, LogicalOperators.Intersection);
20
44
  }
21
45
  /**
22
- * Creates a filter representing an exclusion of the given filter
23
- * from all attribute members or from the optional input filter.
24
- *
46
+ * Creates a filter that excludes items matching the given filter
47
+ * from all items or from items matching the optional input filter.
48
+ *
49
+ * @example
50
+ * Filter for items where the country name does not contain the letter 'A'
51
+ * from the Sample ECommerce data model.
52
+ * ```ts
53
+ * filterFactory.exclude(filterFactory.contains(DM.Country.Country, 'A'))
54
+ * ```
55
+ *
56
+ * Filter for items where the country name starts with the letter 'B' but does not contain the letter 'A'
57
+ * from the Sample ECommerce data model. This filter will match countries like 'Belgium', but will not
58
+ * match countries like 'Bermuda'.
59
+ * ```ts
60
+ * filterFactory.exclude(
61
+ * filterFactory.contains(DM.Country.Country, 'A'),
62
+ * filterFactory.startsWith(DM.Country.Country, 'B')
63
+ * )
64
+ * ```
25
65
  * @param filter - Filter to exclude
26
- * @param input - Input filter to exclude from (optional)
66
+ * @param input - Input filter to exclude from, on the same attribute. If not provided, the filter excludes from all items.
27
67
  * @returns A filter representing an exclusion of the given filter
28
68
  * from all attribute members or from the optional input filter
29
69
  */
@@ -32,81 +72,174 @@ export function exclude(filter, input) {
32
72
  }
33
73
  // TEXT / NUMERIC FILTERS
34
74
  /**
35
- * Creates a "doesn't contain" filter.
75
+ * Creates a filter to isolate attribute values that do not contain a specified string.
76
+ *
77
+ * Matching is case insensitive.
78
+ *
79
+ * You can optionally use wildcard characters for pattern matching, as described in the
80
+ * {@link like | `like()`} function.
36
81
  *
37
- * @param attribute - Text attribute to filter
82
+ * @example
83
+ * Filter for categories in the Sample ECommerce data model where the category name doesn't contain
84
+ * 'digital'. This filter matches categories not like 'Digital Cameras' and 'MP3 & Digital Media Players'.
85
+ * ```ts
86
+ * filterFactory.contains(DM.Category.Category, 'digital')
87
+ * ```
88
+ * @param attribute - Text attribute to filter on
38
89
  * @param value - Value to filter by
39
- * @returns A text filter of the given attribute
90
+ * @returns A filter instance
40
91
  */
41
92
  export function doesntContain(attribute, value) {
42
93
  return new TextFilter(attribute, TextOperators.DoesntContain, value);
43
94
  }
44
95
  /**
45
- * Creates a "doesn't end with" filter.
96
+ * Creates a filter to isolate attribute values that do not end with a specified string.
46
97
  *
47
- * @param attribute - Text attribute to filter
98
+ * Matching is case insensitive.
99
+ *
100
+ * You can optionally use wildcard characters for pattern matching, as described in the
101
+ * {@link like | `like()`} function.
102
+ *
103
+ * @example
104
+ * Filter for countries in the Sample ECommerce data model where the country name doesn't end with
105
+ * 'land'. This filter matches countries not like 'Iceland' and 'Ireland'.
106
+ * ```ts
107
+ * filterFactory.doesntEndWith(DM.Country.Country, 'land')
108
+ * ```
109
+ * @param attribute - Text attribute to filter on
48
110
  * @param value - Value to filter by
49
- * @returns A text filter of the given attribute
111
+ * @returns A filter instance
50
112
  */
51
113
  export function doesntEndWith(attribute, value) {
52
114
  return new TextFilter(attribute, TextOperators.DoesntEndWith, value);
53
115
  }
54
116
  /**
55
- * Creates a "doesn't start with" filter.
117
+ * Creates a filter to isolate attribute values that do not start with a specified string.
118
+ *
119
+ * Matching is case insensitive.
56
120
  *
57
- * @param attribute - Text attribute to filter
121
+ * You can optionally use wildcard characters for pattern matching, as described in the
122
+ * {@link like | `like()`} function.
123
+ *
124
+ * @example
125
+ * Filter for countries in the Sample ECommerce data model where the country name doesn't start with
126
+ * 'United'. This filter matches countries not like 'United States' and 'United Kingdom'.
127
+ * ```ts
128
+ * filterFactory.doesntStartWith(DM.Country.Country, 'United')
129
+ * ```
130
+ * @param attribute - Text attribute to filter on
58
131
  * @param value - Value to filter by
59
- * @returns A text filter of the given attribute
132
+ * @returns A filter instance
60
133
  */
61
134
  export function doesntStartWith(attribute, value) {
62
135
  return new TextFilter(attribute, TextOperators.DoesntStartWith, value);
63
136
  }
64
137
  /**
65
- * Creates a "contains" filter.
138
+ * Creates a filter to isolate attribute values that contain a specified string.
139
+ *
140
+ * Matching is case insensitive.
66
141
  *
67
- * @param attribute - Text attribute to filter
142
+ * You can optionally use wildcard characters for pattern matching, as described in the
143
+ * {@link like | `like()`} function.
144
+ *
145
+ * @example
146
+ * Filter for categories in the Sample ECommerce data model where the category name contains
147
+ * 'digital'. This filter matches categories like 'Digital Cameras' and 'MP3 & Digital Media Players'.
148
+ * ```ts
149
+ * filterFactory.contains(DM.Category.Category, 'digital')
150
+ * ```
151
+ * @param attribute - Text attribute to filter on
68
152
  * @param value - Value to filter by
69
- * @returns A text filter of the given attribute
153
+ * @returns A filter instance
70
154
  */
71
155
  export function contains(attribute, value) {
72
156
  return new TextFilter(attribute, TextOperators.Contains, value);
73
157
  }
74
158
  /**
75
- * Creates an "ends with" filter.
159
+ * Creates a filter to isolate attribute values that end with a specified string.
160
+ *
161
+ * Matching is case insensitive.
162
+ *
163
+ * You can optionally use wildcard characters for pattern matching, as described in the
164
+ * {@link like | `like()`} function.
76
165
  *
77
- * @param attribute - Text attribute to filter
166
+ * @example
167
+ * Filter for countries in the Sample ECommerce data model where the country name ends with
168
+ * 'land'. This filter matches countries like 'Ireland' and 'Iceland'.
169
+ * ```ts
170
+ * filterFactory.endsWith(DM.Country.Country, 'land')
171
+ * ```
172
+ * @param attribute - Text attribute to filter on
78
173
  * @param value - Value to filter by
79
- * @returns A text filter of the given attribute
174
+ * @returns A filter instance
80
175
  */
81
176
  export function endsWith(attribute, value) {
82
177
  return new TextFilter(attribute, TextOperators.EndsWith, value);
83
178
  }
84
179
  /**
85
- * Creates a "starts with" filter.
180
+ * Creates a filter to isolate attribute values that start with a specified string.
181
+ *
182
+ * Matching is case insensitive.
183
+ *
184
+ * You can optionally use wildcard characters for pattern matching, as described in the
185
+ * {@link like | `like()`} function.
86
186
  *
87
- * @param attribute - Text attribute to filter
187
+ * @example
188
+ * Filter for countries in the Sample ECommerce data model where the country name starts with
189
+ * 'United'. This filter matches countries like 'United States' and 'United Kingdom'.
190
+ * ```ts
191
+ * filterFactory.startsWith(DM.Country.Country, 'United')
192
+ * ```
193
+ * @param attribute - Text attribute to filter on
88
194
  * @param value - Value to filter by
89
- * @returns A text filter of the given attribute
195
+ * @returns A filter instance
90
196
  */
91
197
  export function startsWith(attribute, value) {
92
198
  return new TextFilter(attribute, TextOperators.StartsWith, value);
93
199
  }
94
200
  /**
95
- * Creates a "like" filter.
201
+ * Creates a filter to isolate attribute values that match a specified string pattern.
202
+ *
203
+ * The pattern can include the following wildcard characters:
204
+ *
205
+ * + `_`: Matches a single character
206
+ * + `%`: Matches multiple characters
207
+ *
208
+ * To search for a literal underscore (`_`) or percent symbol (`%`), use the backslash (`\`) escape
209
+ * character.
210
+ *
211
+ * Matching is case insensitive.
96
212
  *
97
- * @param attribute - Text attribute to filter
213
+ * @example
214
+ * Filter for countries from the Sample ECommerce data model where the country name starts with an
215
+ * 'A' and ends with an 'a'. This filter matches countries like 'Argentina' and 'Australia'.
216
+ * ```ts
217
+ * filterFactory.like(DM.Country.Country, 'A%a')
218
+ * ```
219
+ * @param attribute - Text attribute to filter on
98
220
  * @param value - Value to filter by
99
- * @returns A text filter of the given attribute
221
+ * @returns A filter instance
100
222
  */
101
223
  export function like(attribute, value) {
102
224
  return new TextFilter(attribute, TextOperators.Like, value);
103
225
  }
104
226
  /**
105
- * Creates a "doesn't equal" filter.
227
+ * Creates a filter to isolate attribute values that do not equal a specified string or number.
106
228
  *
107
- * @param attribute - Text or numeric attribute to filter
229
+ * When filtering against a string:
230
+ *
231
+ * + Matching is case insensitive.
232
+ * + You can optionally use wildcard characters for pattern matching, as described in the
233
+ * {@link like | `like()`} function.
234
+ *
235
+ * @example
236
+ * Filter for items not in new condition from the Sample ECommerce data model.
237
+ * ```ts
238
+ * filterFactory.doesntEqual(DM.Commerce.Condition, 'New')
239
+ * ```
240
+ * @param attribute - Text or numeric attribute to filter on
108
241
  * @param value - Value to filter by
109
- * @returns A filter of the given attribute
242
+ * @returns A filter instance
110
243
  */
111
244
  export function doesntEqual(attribute, value) {
112
245
  if (typeof value === 'string') {
@@ -117,11 +250,22 @@ export function doesntEqual(attribute, value) {
117
250
  }
118
251
  }
119
252
  /**
120
- * Creates an "equals" filter.
253
+ * Creates a filter to isolate attribute values that equal a specified string or number.
254
+ *
255
+ * When filtering against a string:
121
256
  *
122
- * @param attribute - Text or numeric attribute to filter
257
+ * + Matching is case insensitive.
258
+ * + You can optionally use wildcard characters for pattern matching, as described in the
259
+ * {@link like | `like()`} function.
260
+ *
261
+ * @example
262
+ * Filter for items in new condition from the Sample ECommerce data model.
263
+ * ```ts
264
+ * filterFactory.equals(DM.Commerce.Condition, 'New')
265
+ * ```
266
+ * @param attribute - Text or numeric attribute to filter on
123
267
  * @param value - Value to filter by
124
- * @returns A filter of the given attribute
268
+ * @returns A filter instance
125
269
  */
126
270
  export function equals(attribute, value) {
127
271
  if (typeof value === 'string') {
@@ -132,70 +276,112 @@ export function equals(attribute, value) {
132
276
  }
133
277
  }
134
278
  /**
135
- * Creates a "greater than" filter.
279
+ * Creates a filter to isolate attribute values strictly greater than a specified number.
136
280
  *
137
- * @param attribute - Numeric attribute to filter
281
+ * @example
282
+ * Filter for items where the cost is greater than 100 from the Sample ECommerce data model.
283
+ * ```ts
284
+ * filterFactory.greaterThan(DM.Commerce.Cost, 100)
285
+ * ```
286
+ * @param attribute - Numeric attribute to filter on
138
287
  * @param value - Value to filter by
139
- * @returns A numeric filter of the given attribute
288
+ * @returns A filter instance
140
289
  */
141
290
  export function greaterThan(attribute, value) {
142
291
  return numeric(attribute, NumericOperators.FromNotEqual, value);
143
292
  }
144
293
  /**
145
- * Creates a "greater than or equal" filter.
294
+ * Creates a filter to isolate attribute values greater than or equal to a specified number.
146
295
  *
147
- * @param attribute - Numeric attribute to filter
296
+ * @example
297
+ * Filter for items where the cost is greater than or equal to 100 from the Sample ECommerce data model.
298
+ * ```ts
299
+ * filterFactory.greaterThanOrEqual(DM.Commerce.Cost, 100)
300
+ * ```
301
+ * @param attribute - Numeric attribute to filter on
148
302
  * @param value - Value to filter by
149
- * @returns A numeric filter of the given attribute
303
+ * @returns A filter instance
150
304
  */
151
305
  export function greaterThanOrEqual(attribute, value) {
152
306
  return numeric(attribute, NumericOperators.From, value);
153
307
  }
154
308
  /**
155
- * Creates a "less than" filter.
309
+ * Creates a filter to isolate attribute values strictly less than a specified number.
156
310
  *
157
- * @param attribute - Numeric attribute to filter
311
+ * @example
312
+ * Filter for items where the cost is less than 100 from the Sample ECommerce data model.
313
+ * ```ts
314
+ * filterFactory.lessThan(DM.Commerce.Cost, 100)
315
+ * ```
316
+ * @param attribute - Numeric attribute to filter on
158
317
  * @param value - Value to filter by
159
- * @returns A numeric filter of the given attribute
318
+ * @returns A filter instance
160
319
  */
161
320
  export function lessThan(attribute, value) {
162
321
  return numeric(attribute, NumericOperators.ToNotEqual, value);
163
322
  }
164
323
  /**
165
- * Creates a "less than or equal" filter.
324
+ * Creates a filter to isolate attribute values less than or equal to a specified number.
166
325
  *
167
- * @param attribute - Numeric attribute to filter
326
+ * @example
327
+ * Filter for items where the cost is less than or equal to 100 from the Sample ECommerce data model.
328
+ * ```ts
329
+ * filterFactory.lessThanOrEqual(DM.Commerce.Cost, 100)
330
+ * ```
331
+ * @param attribute - Numeric attribute to filter on
168
332
  * @param value - Value to filter by
169
- * @returns A numeric filter of the given attribute
333
+ * @returns A filter instance
170
334
  */
171
335
  export function lessThanOrEqual(attribute, value) {
172
336
  return numeric(attribute, NumericOperators.To, value);
173
337
  }
174
338
  /**
175
- * Creates a "between" filter.
339
+ * Creates a filter to isolate attribute values within or exactly matching two specified numerical boundaries.
176
340
  *
177
- * @param attribute - Numeric attribute to filter
341
+ * @example
342
+ * Filter for items from the Sample ECommerce data model where the cost is greater than or equal to 100 and less than or equal to 200.
343
+ * ```ts
344
+ * filterFactory.between(DM.Commerce.Cost, 100, 200)
345
+ * ```
346
+ * @param attribute - Numeric attribute to filter on
178
347
  * @param valueA - Value to filter from
179
348
  * @param valueB - Value to filter to
180
- * @returns A numeric filter of the given attribute
349
+ * @returns A filter instance
181
350
  */
182
351
  export function between(attribute, valueA, valueB) {
183
352
  return numeric(attribute, NumericOperators.From, valueA, NumericOperators.To, valueB);
184
353
  }
185
354
  /**
186
- * Creates a "between, but not equal" filter.
355
+ * Creates a filter that isolates attribute values strictly within two specified numerical boundaries.
187
356
  *
188
- * @param attribute - Numeric attribute to filter
357
+ * @example
358
+ * Filter for items from the Sample ECommerce data model where the cost is greater than 100 and less than 200.
359
+ * ```ts
360
+ * filterFactory.betweenNotEqual(DM.Commerce.Cost, 100, 200)
361
+ * ```
362
+ * @param attribute - Numeric attribute to filter on
189
363
  * @param valueA - Value to filter from
190
364
  * @param valueB - Value to filter to
191
- * @returns A numeric filter of the given attribute
365
+ * @returns A filter instance
192
366
  */
193
367
  export function betweenNotEqual(attribute, valueA, valueB) {
194
368
  return numeric(attribute, NumericOperators.FromNotEqual, valueA, NumericOperators.ToNotEqual, valueB);
195
369
  }
196
370
  /**
197
- * Creates a custom numeric filter.
198
- *
371
+ * Creates a custom numeric filter that filters for given attribute values.
372
+ *
373
+ * @example
374
+ * Filter for items where the cost is greater than 100 and less than 200
375
+ * from the Sample ECommerce data model.
376
+ * ```ts
377
+ * filterFactory.numeric(
378
+ * DM.Commerce.Cost,
379
+ * NumericOperators.From,
380
+ * 100,
381
+ * NumericOperators.To,
382
+ * 200
383
+ * )
384
+ * ```
199
385
  * @param attribute - Numeric attribute to filter
200
386
  * @param operatorA - First operator
201
387
  * @param valueA - First value
@@ -207,116 +393,192 @@ export function numeric(attribute, operatorA, valueA, operatorB, valueB) {
207
393
  return new NumericFilter(attribute, operatorA, valueA, operatorB, valueB);
208
394
  }
209
395
  /**
210
- * Creates a filter on the given members of the given attribute.
396
+ * Creates a filter to isolate attribute values that match any of the specified strings.
211
397
  *
212
- * @param attribute - Attribute to filter
398
+ * Matching is case sensitive.
399
+ *
400
+ * @example
401
+ * Filter for items where the condition is 'Used' or 'Refurbished'
402
+ * from the Sample ECommerce data model.
403
+ * ```ts
404
+ * filterFactory.members(DM.Commerce.Condition, ['Used', 'Refurbished'])
405
+ * ```
406
+ * @param attribute - Attribute to filter on
213
407
  * @param members - Array of member values to filter by
214
- * @returns A filter instance representing the given members of the given attribute
408
+ * @returns A filter instance
215
409
  */
216
410
  export function members(attribute, members) {
217
411
  return new MembersFilter(attribute, members);
218
412
  }
219
413
  // DATE FILTERS
220
414
  /**
221
- * Creates a filter on all values starting at the given date of the given level.
415
+ * Creates a filter to isolate date values starting from and including the given date and level.
222
416
  *
223
- * @param level - Date level attribute to filter. See {@link DateLevels} for supported levels.
224
- * @param from - Date or String representing the value to filter from
225
- * @returns A filter instance filtering all values starting at the given value
417
+ * @example
418
+ * Filter for items in the Sample ECommerce data model where the date is not before the year 2010.
419
+ * ```ts
420
+ * filterFactory.dateFrom(DM.Commerce.Date.Years, '2010-01')
421
+ * ```
422
+ * @param level - Date {@link LevelAttribute} to filter on
423
+ * @param from - Date or string representing the value to filter from
424
+ * @returns A filter instance
226
425
  */
227
426
  export function dateFrom(level, from) {
228
427
  return dateRange(level, from, undefined);
229
428
  }
230
429
  /**
231
- * Creates a filter on all values ending at the given date of the given level.
430
+ * Creates a filter to isolate items up until and including the given date and level.
232
431
  *
233
- * @param level - Date level attribute to filter. See {@link DateLevels} for supported levels.
234
- * @param to - Date or String representing the last member to filter to
235
- * @returns A filter instance filtering all values ending at the given value
432
+ * @example
433
+ * Filter for items where the date is from the year 2010 or earlier in the Sample ECommerce data model.
434
+ * ```ts
435
+ * filterFactory.dateTo(DM.Commerce.Date.Years, '2010-01')
436
+ * ```
437
+ * @param level - Date {@link LevelAttribute} to filter on
438
+ * @param to - Date or string representing the last member to filter to
439
+ * @returns A filter instance
236
440
  */
237
441
  export function dateTo(level, to) {
238
442
  return dateRange(level, undefined, to);
239
443
  }
240
444
  /**
241
- * Creates a range filter between the given "from" and "to" arguments.
445
+ * Creates a filter to isolate items between and including the given dates and level.
242
446
  *
243
- * @param level - Date level attribute to filter. See {@link DateLevels} for supported levels.
244
- * @param from - Date or String representing the start member to filter from
245
- * @param to - Date or String representing the end member to filter to
246
- * @returns A filter instance filtering all values ending at the given value
447
+ * @example
448
+ * Filter for items in the Sample ECommerce data model where the date is from the years 2009, 2010, or 2011.
449
+ * ```ts
450
+ * filterFactory.dateRange(DM.Commerce.Date.Years, '2009-01', '2011-01')
451
+ * ```
452
+ * @param level - Date {@link LevelAttribute} to filter on
453
+ * @param from - Date or string representing the start member to filter from
454
+ * @param to - Date or string representing the end member to filter to
455
+ * @returns A filter instance
247
456
  */
248
457
  export function dateRange(level, from, to) {
249
458
  return new DateRangeFilter(level, from, to);
250
459
  }
251
460
  /**
252
- * Creates a relative date filter.
253
- *
254
- * @param level - Date level attribute to filter. See {@link DateLevels} for supported levels.
255
- * @param offset - offset to skip from the given anchor, or Today if not provided,
256
- * positive/negative to skip forward/backward
257
- * @param count - number of members to filter
258
- * @param anchor - Anchor to filter from, Today is used if not provided
259
- * @returns A relative date filter
461
+ * Creates a filter to isolate items with a date dimension value within a specified range after a
462
+ * given date and level.
463
+ *
464
+ * Although the `offset` can be used to set a beginning date prior to the `anchor`, the filter range always
465
+ * continues forward after the offset beginning date. So, using an `offset` of `-6` and a `count` of `18` when `level`
466
+ * is a month level creates a range that begins 6 month before the `anchor` date and extends to 12 months after
467
+ * the `anchor` date.
468
+ *
469
+ * @example
470
+ * Filter for items in the Sample ECommerce data model where the date is in 2011 or the first half of 2012.
471
+ * ```ts
472
+ * filterFactory.dateRelative(DM.Commerce.Date.Months, 0, 18, '2011-01'),
473
+ * ```
474
+ *
475
+ * Filter for items in the Sample ECommerce data model where the date is in the second half of 2010 or in 2011.
476
+ * ```ts
477
+ * filterFactory.dateRelative(DM.Commerce.Date.Months, -6, 18, '2011-01'),
478
+ * ```
479
+ *
480
+ * Filter for items in the Sample ECommerce data model where the date is in the past 6 months.
481
+ * ```ts
482
+ * filterFactory.dateRelative(DM.Commerce.Date.Months, -6, 6),
483
+ * ```
484
+ * @param level - Date {@link LevelAttribute} to filter on
485
+ * @param offset - Number of levels to skip from the given `anchor` or the default of the current day.
486
+ * Positive numbers skip forwards and negative numbers skip backwards (e.g. `-6` is 6 months backwards when `level` is a months level attribute)
487
+ * @param count - Number of levels to include in the filter (e.g. `6` is 6 months when `level` is a months level attribute)
488
+ * @param anchor - Date to filter from, defaults to the current day
489
+ * @returns A filter instance
260
490
  */
261
491
  export function dateRelative(level, offset, count, anchor) {
262
492
  return new RelativeDateFilter(level, offset, count, undefined, anchor);
263
493
  }
264
494
  /**
265
- * Creates a relative date filter from the given anchor date.
495
+ * Creates a filter to isolate items with a date dimension value within a specified range after a
496
+ * given date and level.
266
497
  *
267
- * @param level - Date level attribute to filter. See {@link DateLevels} for supported levels.
268
- * @param offset - offset to skip from the given anchor, or Today if not provided
269
- * @param count - number of members to filter
270
- * @param anchor - Anchor to filter from, Today is used if not provided
271
- * @returns A relative date filter
498
+ * @example
499
+ * Filter for items in the Sample ECommerce data model where the date is in 2011 or the first half of 2012.
500
+ * ```ts
501
+ * filterFactory.dateRelativeFrom(DM.Commerce.Date.Months, 0, 18, '2011-01'),
502
+ * ```
503
+ * @param level - Date {@link LevelAttribute} to filter on
504
+ * @param offset - Number of levels to skip from the given `anchor` or the default of the current day (e.g. `6` is 6 months when `level` is a months level attribute)
505
+ * @param count - Number of levels to include in the filter (e.g. `6` is 6 months when `level` is a months level attribute)
506
+ * @param anchor - Date to filter from, defaults to the current day
507
+ * @returns A filter instance
272
508
  */
273
509
  export function dateRelativeFrom(level, offset, count, anchor) {
274
510
  return new RelativeDateFilter(level, offset, count, DateOperators.Next, anchor);
275
511
  }
276
512
  /**
277
- * Creates a relative date filter to the given anchor date.
513
+ * Creates a filter to isolate items with a date dimension value within a specified range before a
514
+ * given date and level.
278
515
  *
279
- * @param level - Date level attribute to filter. See {@link DateLevels} for supported levels.
280
- * @param offset - offset to skip from the given anchor, or Today if not provided
281
- * @param count - number of members to filter
282
- * @param anchor - Anchor to filter from, Today is used if not provided
283
- * @returns A relative date filter
516
+ * @example
517
+ * Filter for items in the Sample ECommerce data model where the date is in the first half of 2010 or in 2011.
518
+ * ```ts
519
+ * filterFactory.dateRelativeTo(DM.Commerce.Date.Months, 0, 18, '2011-12'),
520
+ * ```
521
+ * @param level - Date {@link LevelAttribute} to filter on
522
+ * @param offset - Number of levels to skip from the given `anchor` or the default of the current day (e.g. `6` is 6 months when `level` is a months level attribute)
523
+ * @param count - Number of levels to include in the filter (e.g. `6` is 6 months when `level` is a months level attribute)
524
+ * @param anchor - Date to filter to, defaults to the current day
525
+ * @returns A filter instance
284
526
  */
285
527
  export function dateRelativeTo(level, offset, count, anchor) {
286
528
  return new RelativeDateFilter(level, offset, count, DateOperators.Last, anchor);
287
529
  }
288
530
  /**
289
- * Creates a filter on "This Year" of the given date dimension.
531
+ * Creates a filter to isolate items with a date dimension value in the current calendar year.
290
532
  *
291
- * @param dimension - date dimension to filter
292
- * @returns A "This Year" filter of the given dimension
533
+ * @example
534
+ * Filter for items where the date is in the current calendar year in the Sample ECommerce data model.
535
+ * ```ts
536
+ * filterFactory.thisYear(DM.Commerce.Date)
537
+ * ```
538
+ * @param dimension - Date dimension to filter
539
+ * @returns A filter instance
293
540
  */
294
541
  export function thisYear(dimension) {
295
542
  return dateRelativeTo(dimension.Years, 0, 1);
296
543
  }
297
544
  /**
298
- * Creates a filter on "This Month" of the given date dimension.
545
+ * Creates a filter to isolate items with a date dimension value in the current calendar month.
299
546
  *
300
- * @param dimension - date dimension to filter
301
- * @returns A "This Month" filter of the given dimension
547
+ * @example
548
+ * Filter for items where the date is in the current calendar month in the Sample ECommerce data model.
549
+ * ```ts
550
+ * filterFactory.thisMonth(DM.Commerce.Date)
551
+ * ```
552
+ * @param dimension - Date dimension to filter
553
+ * @returns A filter instance
302
554
  */
303
555
  export function thisMonth(dimension) {
304
556
  return dateRelativeTo(dimension.Months, 0, 1);
305
557
  }
306
558
  /**
307
- * Creates a filter on "This Quarter" of the given date dimension.
559
+ * Creates a filter to isolate items with a date dimension value in the current quarter.
308
560
  *
309
- * @param dimension - date dimension to filter
310
- * @returns A "This Quarter" filter of the given dimension
561
+ * @example
562
+ * Filter for items where the date is in the current quarter in the Sample ECommerce data model.
563
+ * ```ts
564
+ * filterFactory.thisQuarter(DM.Commerce.Date)
565
+ * ```
566
+ * @param dimension - Date dimension to filter
567
+ * @returns A filter instance
311
568
  */
312
569
  export function thisQuarter(dimension) {
313
570
  return dateRelativeTo(dimension.Quarters, 0, 1);
314
571
  }
315
572
  /**
316
- * Creates a filter on "Today" of the given date dimension.
573
+ * Creates a filter to isolate items with a date dimension value of the current date.
317
574
  *
575
+ * @example
576
+ * Filter for items where the date is today in the Sample ECommerce data model.
577
+ * ```ts
578
+ * filterFactory.today(DM.Commerce.Date)
579
+ * ```
318
580
  * @param dimension - date dimension to filter
319
- * @returns A "Today" filter of the given dimension
581
+ * @returns A filter instance
320
582
  */
321
583
  export function today(dimension) {
322
584
  return dateRelativeTo(dimension.Days, 0, 1);
@@ -338,67 +600,213 @@ export function measureBase(attribute, measure, operatorA, valueA, operatorB, va
338
600
  return new MeasureFilter(attribute, measure, operatorA, valueA, operatorB, valueB);
339
601
  }
340
602
  /**
341
- * Creates a filter on all measure values that are greater than or equal to the given value.
603
+ * Creates a filter to isolate a measure value greater than or equal to a given number.
342
604
  *
605
+ * @example
606
+ * Filter for categories that have an average revenue greater than
607
+ * or equal to 50 in the Sample ECommerce data model.
608
+ * ```ts
609
+ * filterFactory.measureGreaterThanOrEqual(
610
+ * measures.average(DM.Commerce.Revenue),
611
+ * 50
612
+ * )
613
+ * ```
343
614
  * @param measure - Measure to filter by
344
615
  * @param value - Min value
345
- * @returns A filter representing the "greater than or equal to" logic
616
+ * @returns A filter instance
346
617
  */
347
618
  export function measureGreaterThanOrEqual(measure, value) {
348
619
  return measureBase(measure.attribute, measure, NumericOperators.From, value);
349
620
  }
350
621
  /**
351
- * Creates a filter on all measure values less than or equal to the given value.
622
+ * Creates a filter to isolate a measure value less than or equal to a given number.
352
623
  *
624
+ * @example
625
+ * Filter for categories that have an average revenue less than
626
+ * or equal to 100 in the Sample ECommerce data model.
627
+ * ```ts
628
+ * filterFactory.measureLessThanOrEqual(
629
+ * measures.average(DM.Commerce.Revenue),
630
+ * 100
631
+ * )
632
+ * ```
353
633
  * @param measure - Measure to filter by
354
634
  * @param value - Max value
355
- * @returns A filter representing the "less than or equal to" logic
635
+ * @returns A filter instance
356
636
  */
357
637
  export function measureLessThanOrEqual(measure, value) {
358
638
  return measureBase(measure.attribute, measure, NumericOperators.To, value);
359
639
  }
360
640
  /**
361
- * Creates a filter on all measure values within a range.
641
+ * Creates a filter to isolate a measure value between or equal to two given numbers.
362
642
  *
643
+ * @example
644
+ * Filter for categories that have an average revenue greater than or equal to 50 and less than
645
+ * or equal to 100 in the Sample ECommerce data model.
646
+ * ```ts
647
+ * filterFactory.measureBetween(
648
+ * measures.average(DM.Commerce.Revenue),
649
+ * 50,
650
+ * 100
651
+ * )
652
+ * ```
363
653
  * @param measure - Measure to filter by
364
654
  * @param valueA - Min value
365
655
  * @param valueB - Max value
366
- * @returns A filter representing the "between" logic
656
+ * @returns A filter instance
367
657
  */
368
658
  export function measureBetween(measure, valueA, valueB) {
369
659
  return measureBase(measure.attribute, measure, NumericOperators.From, valueA, NumericOperators.To, valueB);
370
660
  }
371
661
  /**
372
- * Creates a filter on all measure values within a range but not equal to the min and max values.
662
+ * Creates a filter to isolate a measure value between but not equal to two given numbers.
373
663
  *
664
+ * @example
665
+ * Filter for categories that have an average revenue greater than 50 and less than
666
+ * 100 in the Sample ECommerce data model.
667
+ * ```ts
668
+ * filterFactory.measureBetweenNotEqual(
669
+ * measures.average(DM.Commerce.Revenue),
670
+ * 50,
671
+ * 100
672
+ * )
673
+ * ```
374
674
  * @param measure - Measure to filter by
375
675
  * @param valueA - Min value
376
676
  * @param valueB - Max value
377
- * @returns A filter representing the "between, not equal" logic
677
+ * @returns A filter instance
378
678
  */
379
679
  export function measureBetweenNotEqual(measure, valueA, valueB) {
380
680
  return measureBase(measure.attribute, measure, NumericOperators.FromNotEqual, valueA, NumericOperators.ToNotEqual, valueB);
381
681
  }
382
682
  // RANKING FILTERS
383
683
  /**
384
- * Creates a filter representing a top ranking logic.
385
- *
684
+ * Creates a filter to isolate items that rank towards the top for a given measure.
685
+ *
686
+ * @example
687
+ * Filter for age ranges with the top 3 highest total revenue in the Sample ECommerce data model.
688
+ * ```ts
689
+ * filterFactory.topRanking(
690
+ * DM.Commerce.AgeRange,
691
+ * measures.sum(DM.Commerce.Revenue),
692
+ * 3
693
+ * )
694
+ * ```
386
695
  * @param attribute - Attribute to filter
387
696
  * @param measure - Measure to filter by
388
697
  * @param count - Number of members to return
389
- * @returns A filter representing a top ranking logic on the given attribute by the given measure
698
+ * @returns A filter instance
390
699
  */
391
700
  export function topRanking(attribute, measure, count) {
392
701
  return new RankingFilter(attribute, measure, RankingOperators.Top, count);
393
702
  }
394
703
  /**
395
- * Creates a filter representing a bottom ranking logic.
704
+ * Creates a filter to isolate items that rank towards the bottom for a given measure.
396
705
  *
706
+ * @example
707
+ * Filter for age ranges with the bottom 3 lowest total revenue in the Sample ECommerce data model.
708
+ * ```ts
709
+ * filterFactory.bottomRanking(
710
+ * DM.Commerce.AgeRange,
711
+ * measures.sum(DM.Commerce.Revenue),
712
+ * 3
713
+ * )
714
+ * ```
397
715
  * @param attribute - Attribute to filter
398
716
  * @param measure - Measure to filter by
399
717
  * @param count - Number of members to return
400
- * @returns A filter representing a bottom ranking logic on the given attribute by the given measure
718
+ * @returns A filter instance
401
719
  */
402
720
  export function bottomRanking(attribute, measure, count) {
403
721
  return new RankingFilter(attribute, measure, RankingOperators.Bottom, count);
404
722
  }
723
+ const relate = (node) => {
724
+ if (Array.isArray(node)) {
725
+ const [first, ...rest] = node;
726
+ return rest.length === 0
727
+ ? relate(first)
728
+ : {
729
+ operator: 'AND',
730
+ left: relate(first),
731
+ right: relate(rest),
732
+ };
733
+ }
734
+ return node;
735
+ };
736
+ /**
737
+ * Set of logic operators for filter relation construction
738
+ *
739
+ * These operators are still in beta.
740
+ *
741
+ * @example
742
+ * ```ts
743
+ * import { filters } from '@sisense/sdk-data';
744
+ *
745
+ * // define filters
746
+ * const revenueFilter = filterFactory.greaterThan(DM.Commerce.Revenue, 1000);
747
+ * const countryFilter = filterFactory.members(DM.Commerce.Country, ['USA', 'Canada']);
748
+ * const genderFilter = filterFactory.doesntContain(DM.Commerce.Gender, 'Unspecified');
749
+ * const costFilter = filterFactory.between(DM.Commerce.Cost, 1000, 2000);
750
+ *
751
+ * // create filter relation of two filters
752
+ * const orFilerRelations = filterFactory.logic.or(revenueFilter, countryFilter);
753
+ * // revenueFilter OR countryFilter
754
+ *
755
+ * // filter relations can have nested filter relations
756
+ * const mixedFilterRelations = filterFactory.logic.and(genderFilter, orFilerRelations);
757
+ * // genderFilter AND (revenueFilter OR countryFilter)
758
+ *
759
+ * // array, specified in filter relations, will be converted to an intersection of filters automatically
760
+ * const arrayFilterRelations = filterFactory.logic.or([genderFilter, costFilter], mixedFilterRelations);
761
+ * // (genderFilter AND costFilter) OR (genderFilter AND (revenueFilter OR countryFilter))
762
+ * ```
763
+ * @beta
764
+ */
765
+ // eslint-disable-next-line @typescript-eslint/no-namespace
766
+ export var logic;
767
+ (function (logic) {
768
+ /**
769
+ * Creates an 'AND' filter relation
770
+ *
771
+ * @example
772
+ * Create a filter relation for items that have a revenue greater than 100 and are in new condition
773
+ * in the Sample ECommerce data model.
774
+ * ```ts
775
+ * const revenueFilter = filterFactory.greaterThan(DM.Commerce.Revenue, 100);
776
+ * const conditionFilter = filterFactory.equals(DM.Commerce.Condition, 'New');
777
+ *
778
+ * const andFilerRelation = filterFactory.logic.and(revenueFilter, conditionFilter);
779
+ * ```
780
+ * @param left First filter or filter relation
781
+ * @param right Second filter or filter relation
782
+ * @returns A filter relation
783
+ * @beta
784
+ */
785
+ logic.and = (left, right) => ({
786
+ operator: 'AND',
787
+ left: relate(left),
788
+ right: relate(right),
789
+ });
790
+ /**
791
+ * Creates an 'OR' filter relation
792
+ *
793
+ * @example
794
+ * Create a filter relation for items that have a revenue greater than 100 or are in new condition
795
+ * in the Sample ECommerce data model.
796
+ * ```ts
797
+ * const revenueFilter = filterFactory.greaterThan(DM.Commerce.Revenue, 100);
798
+ * const conditionFilter = filterFactory.equals(DM.Commerce.Condition, 'New');
799
+ *
800
+ * const orFilerRelation = filterFactory.logic.or(revenueFilter, conditionFilter);
801
+ * ```
802
+ * @param left First filter or filter relation
803
+ * @param right Second filter or filter relation
804
+ * @returns A filter relation
805
+ * @beta
806
+ */
807
+ logic.or = (left, right) => ({
808
+ operator: 'OR',
809
+ left: relate(left),
810
+ right: relate(right),
811
+ });
812
+ })(logic = logic || (logic = {}));