@sisense/sdk-data 1.34.0 → 2.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.
Files changed (68) hide show
  1. package/dist/cjs/dimensional-model/analytics/factory.d.ts +10 -10
  2. package/dist/cjs/dimensional-model/analytics/factory.js +15 -16
  3. package/dist/cjs/dimensional-model/attributes.d.ts +4 -4
  4. package/dist/cjs/dimensional-model/attributes.js +21 -7
  5. package/dist/cjs/dimensional-model/base.d.ts +3 -3
  6. package/dist/cjs/dimensional-model/base.js +7 -4
  7. package/dist/cjs/dimensional-model/compose-code-utils.d.ts +41 -0
  8. package/dist/cjs/dimensional-model/compose-code-utils.js +127 -0
  9. package/dist/cjs/dimensional-model/consts.d.ts +1 -0
  10. package/dist/cjs/dimensional-model/consts.js +4 -0
  11. package/dist/cjs/dimensional-model/dimensions/dimensions.d.ts +5 -5
  12. package/dist/cjs/dimensional-model/dimensions/dimensions.js +25 -16
  13. package/dist/cjs/dimensional-model/filters/factory.d.ts +41 -41
  14. package/dist/cjs/dimensional-model/filters/factory.js +53 -168
  15. package/dist/cjs/dimensional-model/filters/filter-relations.js +2 -5
  16. package/dist/cjs/dimensional-model/filters/filters.d.ts +39 -23
  17. package/dist/cjs/dimensional-model/filters/filters.js +102 -52
  18. package/dist/cjs/dimensional-model/filters/utils/attribute-measure-util.js +6 -14
  19. package/dist/cjs/dimensional-model/filters/utils/condition-filter-util.js +28 -26
  20. package/dist/cjs/dimensional-model/filters/utils/filter-from-jaql-util.js +9 -15
  21. package/dist/cjs/dimensional-model/filters/utils/types.d.ts +10 -0
  22. package/dist/cjs/dimensional-model/interfaces.d.ts +9 -7
  23. package/dist/cjs/dimensional-model/jaql-element.d.ts +13 -1
  24. package/dist/cjs/dimensional-model/jaql-element.js +53 -1
  25. package/dist/cjs/dimensional-model/measures/factory.d.ts +45 -52
  26. package/dist/cjs/dimensional-model/measures/factory.js +55 -184
  27. package/dist/cjs/dimensional-model/measures/measures.d.ts +9 -9
  28. package/dist/cjs/dimensional-model/measures/measures.js +31 -29
  29. package/dist/cjs/dimensional-model/types.d.ts +25 -2
  30. package/dist/cjs/utils.d.ts +26 -19
  31. package/dist/cjs/utils.js +85 -41
  32. package/dist/dimensional-model/analytics/factory.d.ts +10 -10
  33. package/dist/dimensional-model/analytics/factory.js +15 -14
  34. package/dist/dimensional-model/attributes.d.ts +4 -4
  35. package/dist/dimensional-model/attributes.js +21 -7
  36. package/dist/dimensional-model/base.d.ts +3 -3
  37. package/dist/dimensional-model/base.js +7 -4
  38. package/dist/dimensional-model/compose-code-utils.d.ts +41 -0
  39. package/dist/dimensional-model/compose-code-utils.js +119 -0
  40. package/dist/dimensional-model/consts.d.ts +1 -0
  41. package/dist/dimensional-model/consts.js +1 -0
  42. package/dist/dimensional-model/dimensions/dimensions.d.ts +5 -5
  43. package/dist/dimensional-model/dimensions/dimensions.js +26 -17
  44. package/dist/dimensional-model/filters/factory.d.ts +41 -41
  45. package/dist/dimensional-model/filters/factory.js +51 -125
  46. package/dist/dimensional-model/filters/filter-relations.js +3 -6
  47. package/dist/dimensional-model/filters/filters.d.ts +39 -23
  48. package/dist/dimensional-model/filters/filters.js +102 -52
  49. package/dist/dimensional-model/filters/utils/attribute-measure-util.js +6 -14
  50. package/dist/dimensional-model/filters/utils/condition-filter-util.js +28 -26
  51. package/dist/dimensional-model/filters/utils/filter-from-jaql-util.js +9 -15
  52. package/dist/dimensional-model/filters/utils/types.d.ts +10 -0
  53. package/dist/dimensional-model/interfaces.d.ts +9 -7
  54. package/dist/dimensional-model/jaql-element.d.ts +13 -1
  55. package/dist/dimensional-model/jaql-element.js +52 -1
  56. package/dist/dimensional-model/measures/factory.d.ts +45 -52
  57. package/dist/dimensional-model/measures/factory.js +54 -141
  58. package/dist/dimensional-model/measures/measures.d.ts +9 -9
  59. package/dist/dimensional-model/measures/measures.js +31 -29
  60. package/dist/dimensional-model/types.d.ts +25 -2
  61. package/dist/tsconfig.prod.cjs.tsbuildinfo +1 -1
  62. package/dist/utils.d.ts +26 -19
  63. package/dist/utils.js +63 -44
  64. package/package.json +3 -3
  65. package/dist/cjs/dimensional-model/filters/utils/filter-code-util.d.ts +0 -17
  66. package/dist/cjs/dimensional-model/filters/utils/filter-code-util.js +0 -82
  67. package/dist/dimensional-model/filters/utils/filter-code-util.d.ts +0 -17
  68. package/dist/dimensional-model/filters/utils/filter-code-util.js +0 -77
@@ -1,6 +1,5 @@
1
- import { TranslatableError } from '../../translation/translatable-error.js';
2
- import { createCalculatedMeasureHelper } from '../../utils.js';
3
1
  import { normalizeName } from '../base.js';
2
+ import { withComposeCodeForMeasure } from '../compose-code-utils.js';
4
3
  import { AggregationTypes, MetadataTypes } from '../types.js';
5
4
  import { DimensionalBaseMeasure, DimensionalCalculatedMeasure } from './measures.js';
6
5
  /**
@@ -72,22 +71,6 @@ function measureFunction(measure, name, func, options) {
72
71
  builder.push(')');
73
72
  return new DimensionalCalculatedMeasure(name, builder.join(''), context);
74
73
  }
75
- /**
76
- * Transforms a custom formula jaql into a calculated measure instance.
77
- *
78
- * As custom formulas can be nested, the function performs a recursive transformation via a helper function.
79
- *
80
- * @param jaql - Custom formula jaql
81
- * @returns Calculated measure instance
82
- * @internal
83
- */
84
- export function transformCustomFormulaJaql(jaql) {
85
- const isFormulaJaql = 'formula' in jaql;
86
- if (!isFormulaJaql) {
87
- throw new TranslatableError('errors.measure.notAFormula');
88
- }
89
- return createCalculatedMeasureHelper(jaql);
90
- }
91
74
  /**
92
75
  * Creates a calculated measure for a valid custom formula built from [base functions](/guides/sdk/reference/functions.html#measured-value-functions).
93
76
  *
@@ -140,13 +123,11 @@ export function transformCustomFormulaJaql(jaql) {
140
123
  * @returns A calculated measure instance
141
124
  * @group Advanced Analytics
142
125
  */
143
- export function customFormula(title, formula, context) {
144
- const newContext = Object.entries(context).reduce((acc, [key, val]) => {
145
- acc[`[${key}]`] = val.jaql().jaql;
146
- return acc;
147
- }, {});
148
- return transformCustomFormulaJaql({ title, formula, context: newContext });
149
- }
126
+ export const customFormula = withComposeCodeForMeasure((title, formula, context) => {
127
+ // context keys must be in brackets
128
+ const newContext = Object.fromEntries(Object.entries(context).map(([key, val]) => [key.startsWith('[') ? key : `[${key}]`, val]));
129
+ return new DimensionalCalculatedMeasure(title, formula, newContext);
130
+ }, 'customFormula');
150
131
  function arithmetic(operand1, operator, operand2, name, withParentheses) {
151
132
  const builder = [];
152
133
  const context = {};
@@ -180,9 +161,7 @@ function arithmetic(operand1, operator, operand2, name, withParentheses) {
180
161
  * @returns A measure instance
181
162
  * @group Aggregation
182
163
  */
183
- export function aggregate(attribute, aggregationType, name, format) {
184
- return new DimensionalBaseMeasure(name !== null && name !== void 0 ? name : `${aggregationType.toString()} ${attribute.name}`, attribute, aggregationType, format);
185
- }
164
+ export const aggregate = withComposeCodeForMeasure((attribute, aggregationType, name, format) => new DimensionalBaseMeasure(name !== null && name !== void 0 ? name : `${aggregationType.toString()} ${attribute.name}`, attribute, aggregationType, format), 'aggregate');
186
165
  /**
187
166
  * Creates a calculated measure from a numeric value.
188
167
  *
@@ -195,9 +174,7 @@ export function aggregate(attribute, aggregationType, name, format) {
195
174
  * @returns A calculated measure instance
196
175
  * @group Arithmetic
197
176
  */
198
- export function constant(value) {
199
- return new DimensionalCalculatedMeasure(`${value}`, `${value}`, {});
200
- }
177
+ export const constant = withComposeCodeForMeasure((value) => new DimensionalCalculatedMeasure(`${value}`, `${value}`, {}), 'constant');
201
178
  /**
202
179
  * Creates a sum aggregation measure over the given attribute.
203
180
  *
@@ -214,9 +191,7 @@ export function constant(value) {
214
191
  * @returns A measure instance
215
192
  * @group Aggregation
216
193
  */
217
- export function sum(attribute, name, format) {
218
- return aggregate(attribute, AggregationTypes.Sum, name, format);
219
- }
194
+ export const sum = withComposeCodeForMeasure((attribute, name, format) => aggregate(attribute, AggregationTypes.Sum, name, format), 'sum');
220
195
  /**
221
196
  * Creates an average aggregation measure over the given attribute.
222
197
  *
@@ -233,9 +208,7 @@ export function sum(attribute, name, format) {
233
208
  * @returns A measure instance
234
209
  * @group Aggregation
235
210
  */
236
- export function average(attribute, name, format) {
237
- return aggregate(attribute, AggregationTypes.Average, name, format);
238
- }
211
+ export const average = withComposeCodeForMeasure((attribute, name, format) => aggregate(attribute, AggregationTypes.Average, name, format), 'average');
239
212
  /**
240
213
  * {@inheritDoc average}
241
214
  *
@@ -244,11 +217,13 @@ export function average(attribute, name, format) {
244
217
  * ```ts
245
218
  * measureFactory.avg(DM.Commerce.Cost)
246
219
  * ```
220
+ * @param attribute - Attribute to aggregate
221
+ * @param name - Optional name for the new measure
222
+ * @param format - Optional numeric formatting to apply using a Numeral.js format string. Can only be used for explicit queries. Cannot be used in charts, tables, etc.
223
+ * @returns A measure instance
247
224
  * @group Aggregation
248
225
  */
249
- export function avg(attribute, name, format) {
250
- return average(attribute, name, format);
251
- }
226
+ export const avg = withComposeCodeForMeasure((attribute, name, format) => aggregate(attribute, AggregationTypes.Average, name, format), 'avg');
252
227
  /**
253
228
  * Creates a min aggregation measure over the given attribute.
254
229
  *
@@ -263,9 +238,7 @@ export function avg(attribute, name, format) {
263
238
  * @returns A measure instance
264
239
  * @group Aggregation
265
240
  */
266
- export function min(attribute, name, format) {
267
- return aggregate(attribute, AggregationTypes.Min, name, format);
268
- }
241
+ export const min = withComposeCodeForMeasure((attribute, name, format) => aggregate(attribute, AggregationTypes.Min, name, format), 'min');
269
242
  /**
270
243
  * Creates a max aggregation measure over the given attribute.
271
244
  *
@@ -280,9 +253,7 @@ export function min(attribute, name, format) {
280
253
  * @returns A measure instance
281
254
  * @group Aggregation
282
255
  */
283
- export function max(attribute, name, format) {
284
- return aggregate(attribute, AggregationTypes.Max, name, format);
285
- }
256
+ export const max = withComposeCodeForMeasure((attribute, name, format) => aggregate(attribute, AggregationTypes.Max, name, format), 'max');
286
257
  /**
287
258
  * Creates a median aggregation measure over the given attribute.
288
259
  *
@@ -297,9 +268,7 @@ export function max(attribute, name, format) {
297
268
  * @returns A measure instance
298
269
  * @group Aggregation
299
270
  */
300
- export function median(attribute, name, format) {
301
- return aggregate(attribute, AggregationTypes.Median, name, format);
302
- }
271
+ export const median = withComposeCodeForMeasure((attribute, name, format) => aggregate(attribute, AggregationTypes.Median, name, format), 'median');
303
272
  /**
304
273
  * Creates a count aggregation measure over the given attribute.
305
274
  *
@@ -316,9 +285,7 @@ export function median(attribute, name, format) {
316
285
  * @returns A measure instance
317
286
  * @group Aggregation
318
287
  */
319
- export function count(attribute, name, format) {
320
- return aggregate(attribute, AggregationTypes.Count, name, format);
321
- }
288
+ export const count = withComposeCodeForMeasure((attribute, name, format) => aggregate(attribute, AggregationTypes.Count, name, format), 'count');
322
289
  /**
323
290
  * Creates a count distinct aggregation measure over the given attribute.
324
291
  *
@@ -335,9 +302,7 @@ export function count(attribute, name, format) {
335
302
  * @returns A measure instance
336
303
  * @group Aggregation
337
304
  */
338
- export function countDistinct(attribute, name, format) {
339
- return aggregate(attribute, AggregationTypes.CountDistinct, name, format);
340
- }
305
+ export const countDistinct = withComposeCodeForMeasure((attribute, name, format) => aggregate(attribute, AggregationTypes.CountDistinct, name, format), 'countDistinct');
341
306
  /**
342
307
  * Creates a measured value with the given measure and set of filters.
343
308
  *
@@ -365,7 +330,7 @@ export function countDistinct(attribute, name, format) {
365
330
  * @returns A calculated measure instance
366
331
  * @group Advanced Analytics
367
332
  */
368
- export function measuredValue(measure, filters, name, format) {
333
+ export const measuredValue = withComposeCodeForMeasure((measure, filters, name, format) => {
369
334
  const builder = [];
370
335
  const context = {};
371
336
  builder.push('(');
@@ -377,7 +342,7 @@ export function measuredValue(measure, filters, name, format) {
377
342
  builder.push(')');
378
343
  const exp = builder.join('');
379
344
  return new DimensionalCalculatedMeasure(name !== null && name !== void 0 ? name : exp, exp, context, format);
380
- }
345
+ }, 'measuredValue');
381
346
  /**
382
347
  * Creates a calculated measure by adding two given numbers or measures.
383
348
  *
@@ -394,9 +359,7 @@ export function measuredValue(measure, filters, name, format) {
394
359
  * @returns A calculated measure instance
395
360
  * @group Arithmetic
396
361
  */
397
- export function add(value1, value2, name, withParentheses) {
398
- return arithmetic(value1, '+', value2, name, withParentheses);
399
- }
362
+ export const add = withComposeCodeForMeasure((value1, value2, name, withParentheses) => arithmetic(value1, '+', value2, name, withParentheses), 'add');
400
363
  /**
401
364
  * Creates a calculated measure by subtracting two given numbers or measures. Subtracts `value2` from `value1`.
402
365
  *
@@ -413,9 +376,7 @@ export function add(value1, value2, name, withParentheses) {
413
376
  * @returns A calculated measure instance
414
377
  * @group Arithmetic
415
378
  */
416
- export function subtract(value1, value2, name, withParentheses) {
417
- return arithmetic(value1, '-', value2, name, withParentheses);
418
- }
379
+ export const subtract = withComposeCodeForMeasure((value1, value2, name, withParentheses) => arithmetic(value1, '-', value2, name, withParentheses), 'subtract');
419
380
  /**
420
381
  * Creates a calculated measure by multiplying two given numbers or measures.
421
382
  *
@@ -432,9 +393,7 @@ export function subtract(value1, value2, name, withParentheses) {
432
393
  * @returns A calculated measure instance
433
394
  * @group Arithmetic
434
395
  */
435
- export function multiply(value1, value2, name, withParentheses) {
436
- return arithmetic(value1, '*', value2, name, withParentheses);
437
- }
396
+ export const multiply = withComposeCodeForMeasure((value1, value2, name, withParentheses) => arithmetic(value1, '*', value2, name, withParentheses), 'multiply');
438
397
  /**
439
398
  * Creates a calculated measure by dividing two given numbers or measures. Divides `value1` by `value2`.
440
399
  *
@@ -451,9 +410,7 @@ export function multiply(value1, value2, name, withParentheses) {
451
410
  * @returns A calculated measure instance
452
411
  * @group Arithmetic
453
412
  */
454
- export function divide(value1, value2, name, withParentheses) {
455
- return arithmetic(value1, '/', value2, name, withParentheses);
456
- }
413
+ export const divide = withComposeCodeForMeasure((value1, value2, name, withParentheses) => arithmetic(value1, '/', value2, name, withParentheses), 'divide');
457
414
  /**
458
415
  * Creates a calculated measure that calculates the running total starting from the beginning
459
416
  * of the year up to the current day, week, month, or quarter.
@@ -472,9 +429,7 @@ export function divide(value1, value2, name, withParentheses) {
472
429
  * @returns A calculated measure instance
473
430
  * @group Time-based
474
431
  */
475
- export function yearToDateSum(measure, name) {
476
- return measureFunction(measure, name !== null && name !== void 0 ? name : 'YTD ' + measure.name, 'YTDSum');
477
- }
432
+ export const yearToDateSum = withComposeCodeForMeasure((measure, name) => measureFunction(measure, name !== null && name !== void 0 ? name : 'YTD ' + measure.name, 'YTDSum'), 'yearToDateSum');
478
433
  /**
479
434
  * Creates a calculated measure that calculates the running total starting from the beginning
480
435
  * of the quarter up to the current day, week, or month.
@@ -493,9 +448,7 @@ export function yearToDateSum(measure, name) {
493
448
  * @returns A calculated measure instance
494
449
  * @group Time-based
495
450
  */
496
- export function quarterToDateSum(measure, name) {
497
- return measureFunction(measure, name !== null && name !== void 0 ? name : 'QTD ' + name, 'QTDSum');
498
- }
451
+ export const quarterToDateSum = withComposeCodeForMeasure((measure, name) => measureFunction(measure, name !== null && name !== void 0 ? name : 'QTD ' + name, 'QTDSum'), 'quarterToDateSum');
499
452
  /**
500
453
  * Creates a calculated measure that calculates the running total starting from the beginning
501
454
  * of the month up to the current day or week.
@@ -514,9 +467,7 @@ export function quarterToDateSum(measure, name) {
514
467
  * @returns A calculated measure instance
515
468
  * @group Time-based
516
469
  */
517
- export function monthToDateSum(measure, name) {
518
- return measureFunction(measure, name !== null && name !== void 0 ? name : 'MTD ' + measure.name, 'MTDSum');
519
- }
470
+ export const monthToDateSum = withComposeCodeForMeasure((measure, name) => measureFunction(measure, name !== null && name !== void 0 ? name : 'MTD ' + measure.name, 'MTDSum'), 'monthToDateSum');
520
471
  /**
521
472
  * Creates a calculated measure that calculates the running total starting from the beginning
522
473
  * of the week up to the current day.
@@ -535,9 +486,7 @@ export function monthToDateSum(measure, name) {
535
486
  * @returns A calculated measure instance
536
487
  * @group Time-based
537
488
  */
538
- export function weekToDateSum(measure, name) {
539
- return measureFunction(measure, name !== null && name !== void 0 ? name : 'MTD ' + measure.name, 'WTDSum');
540
- }
489
+ export const weekToDateSum = withComposeCodeForMeasure((measure, name) => measureFunction(measure, name !== null && name !== void 0 ? name : 'MTD ' + measure.name, 'WTDSum'), 'weekToDateSum');
541
490
  /**
542
491
  * Creates a calculated measure that calculates the running total of a given measure.
543
492
  *
@@ -566,9 +515,7 @@ export function weekToDateSum(measure, name) {
566
515
  * @returns A calculated measure instance
567
516
  * @group Statistics
568
517
  */
569
- export function runningSum(measure, _continuous, name) {
570
- return measureFunction(measure, name !== null && name !== void 0 ? name : 'Running Sum ' + measure.name, 'RSum');
571
- }
518
+ export const runningSum = withComposeCodeForMeasure((measure, _continuous, name) => measureFunction(measure, name !== null && name !== void 0 ? name : 'Running Sum ' + measure.name, 'RSum'), 'runningSum');
572
519
  /**
573
520
  * Creates a calculated measure that calculates growth over a period of time.
574
521
  *
@@ -596,9 +543,7 @@ export function runningSum(measure, _continuous, name) {
596
543
  * @returns A calculated measure instance
597
544
  * @group Statistics
598
545
  */
599
- export function growth(measure, name) {
600
- return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Growth', 'growth');
601
- }
546
+ export const growth = withComposeCodeForMeasure((measure, name) => measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Growth', 'growth'), 'growth');
602
547
  /**
603
548
  * Creates a calculated measure that calculates growth rate over a period of time.
604
549
  *
@@ -626,9 +571,7 @@ export function growth(measure, name) {
626
571
  * @returns A calculated measure instance
627
572
  * @group Statistics
628
573
  */
629
- export function growthRate(measure, name) {
630
- return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Growth', 'growthrate');
631
- }
574
+ export const growthRate = withComposeCodeForMeasure((measure, name) => measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Growth', 'growthrate'), 'growthRate');
632
575
  /**
633
576
  * Creates a calculated measure that calculates the growth from the previous week to the current week.
634
577
  *
@@ -655,9 +598,7 @@ export function growthRate(measure, name) {
655
598
  * @returns A calculated measure instance
656
599
  * @group Statistics
657
600
  */
658
- export function growthPastWeek(measure, name) {
659
- return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Growth', 'growthpastweek');
660
- }
601
+ export const growthPastWeek = withComposeCodeForMeasure((measure, name) => measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Growth', 'growthpastweek'), 'growthPastWeek');
661
602
  /**
662
603
  * Creates a calculated measure that calculates the growth from the previous month to the current month.
663
604
  *
@@ -684,9 +625,7 @@ export function growthPastWeek(measure, name) {
684
625
  * @returns A calculated measure instance
685
626
  * @group Statistics
686
627
  */
687
- export function growthPastMonth(measure, name) {
688
- return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Growth', 'growthpastmonth');
689
- }
628
+ export const growthPastMonth = withComposeCodeForMeasure((measure, name) => measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Growth', 'growthpastmonth'), 'growthPastMonth');
690
629
  /**
691
630
  * Creates a calculated measure that calculates the growth from the previous quarter to the current quarter.
692
631
  *
@@ -713,9 +652,7 @@ export function growthPastMonth(measure, name) {
713
652
  * @returns A calculated measure instance
714
653
  * @group Statistics
715
654
  */
716
- export function growthPastQuarter(measure, name) {
717
- return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Growth', 'growthpastquarter');
718
- }
655
+ export const growthPastQuarter = withComposeCodeForMeasure((measure, name) => measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Growth', 'growthpastquarter'), 'growthPastQuarter');
719
656
  /**
720
657
  * Creates a calculated measure that calculates the growth from the previous year to the current year.
721
658
  *
@@ -742,9 +679,7 @@ export function growthPastQuarter(measure, name) {
742
679
  * @returns A calculated measure instance
743
680
  * @group Statistics
744
681
  */
745
- export function growthPastYear(measure, name) {
746
- return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Growth', 'growthpastyear');
747
- }
682
+ export const growthPastYear = withComposeCodeForMeasure((measure, name) => measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Growth', 'growthpastyear'), 'growthPastYear');
748
683
  /**
749
684
  * Creates a calculated measure that calculates the difference between this period's data
750
685
  * and the data from the previous period for the given measure.
@@ -763,9 +698,7 @@ export function growthPastYear(measure, name) {
763
698
  * @returns A calculated measure instance
764
699
  * @group Time-based
765
700
  */
766
- export function difference(measure, name) {
767
- return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Difference', 'diffpastperiod');
768
- }
701
+ export const difference = withComposeCodeForMeasure((measure, name) => measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Difference', 'diffpastperiod'), 'difference');
769
702
  /**
770
703
  * Creates a calculated measure that calculates the difference between this week's data
771
704
  * and the data from the previous week for the given measure.
@@ -783,9 +716,7 @@ export function difference(measure, name) {
783
716
  * @returns A calculated measure instance
784
717
  * @group Time-based
785
718
  */
786
- export function diffPastWeek(measure, name) {
787
- return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Difference', 'diffpastweek');
788
- }
719
+ export const diffPastWeek = withComposeCodeForMeasure((measure, name) => measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Difference', 'diffpastweek'), 'diffPastWeek');
789
720
  /**
790
721
  * Creates a calculated measure that calculates the difference between this month's data
791
722
  * and the data from the previous month for the given measure.
@@ -803,9 +734,7 @@ export function diffPastWeek(measure, name) {
803
734
  * @returns A calculated measure instance
804
735
  * @group Time-based
805
736
  */
806
- export function diffPastMonth(measure, name) {
807
- return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Difference', 'diffpastmonth');
808
- }
737
+ export const diffPastMonth = withComposeCodeForMeasure((measure, name) => measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Difference', 'diffpastmonth'), 'diffPastMonth');
809
738
  /**
810
739
  * Creates a calculated measure that calculates the difference between this quarter's data
811
740
  * and the data from the previous quarter for the given measure.
@@ -823,9 +752,7 @@ export function diffPastMonth(measure, name) {
823
752
  * @returns A calculated measure instance
824
753
  * @group Time-based
825
754
  */
826
- export function diffPastQuarter(measure, name) {
827
- return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Difference', 'diffpastquarter');
828
- }
755
+ export const diffPastQuarter = withComposeCodeForMeasure((measure, name) => measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Difference', 'diffpastquarter'), 'diffPastQuarter');
829
756
  /**
830
757
  * Creates a calculated measure that calculates the difference between this year's data
831
758
  * and the data from the previous year for the given measure.
@@ -843,9 +770,7 @@ export function diffPastQuarter(measure, name) {
843
770
  * @returns A calculated measure instance
844
771
  * @group Time-based
845
772
  */
846
- export function diffPastYear(measure, name) {
847
- return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Difference', 'diffpastyear');
848
- }
773
+ export const diffPastYear = withComposeCodeForMeasure((measure, name) => measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Difference', 'diffpastyear'), 'diffPastYear');
849
774
  /**
850
775
  * Creates a calculated measure that calculates the value for the previous day.
851
776
  *
@@ -859,9 +784,7 @@ export function diffPastYear(measure, name) {
859
784
  * @returns A calculated measure instance
860
785
  * @group Time-based
861
786
  */
862
- export function pastDay(measure, name) {
863
- return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Past Day', 'pastday');
864
- }
787
+ export const pastDay = withComposeCodeForMeasure((measure, name) => measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Past Day', 'pastday'), 'pastDay');
865
788
  /**
866
789
  * Creates a calculated measure that calculates the value for the same day in the previous week.
867
790
  *
@@ -878,9 +801,7 @@ export function pastDay(measure, name) {
878
801
  * @returns A calculated measure instance
879
802
  * @group Time-based
880
803
  */
881
- export function pastWeek(measure, name) {
882
- return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Past Week', 'pastweek');
883
- }
804
+ export const pastWeek = withComposeCodeForMeasure((measure, name) => measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Past Week', 'pastweek'), 'pastWeek');
884
805
  /**
885
806
  * Creates a calculated measure that calculates the value for the same day or week in the previous month.
886
807
  *
@@ -898,9 +819,7 @@ export function pastWeek(measure, name) {
898
819
  * @returns A calculated measure instance
899
820
  * @group Time-based
900
821
  */
901
- export function pastMonth(measure, name) {
902
- return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Past Month', 'pastmonth');
903
- }
822
+ export const pastMonth = withComposeCodeForMeasure((measure, name) => measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Past Month', 'pastmonth'), 'pastMonth');
904
823
  /**
905
824
  * Creates a calculated measure that calculates the value for the same day, week, or month in the previous quarter.
906
825
  *
@@ -918,9 +837,7 @@ export function pastMonth(measure, name) {
918
837
  * @returns A calculated measure instance
919
838
  * @group Time-based
920
839
  */
921
- export function pastQuarter(measure, name) {
922
- return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Past Quarter', 'pastquarter');
923
- }
840
+ export const pastQuarter = withComposeCodeForMeasure((measure, name) => measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Past Quarter', 'pastquarter'), 'pastQuarter');
924
841
  /**
925
842
  * Creates a calculated measure that calculates the value for the same day, week, month, or quarter in the previous year.
926
843
  *
@@ -938,9 +855,7 @@ export function pastQuarter(measure, name) {
938
855
  * @returns A calculated measure instance
939
856
  * @group Time-based
940
857
  */
941
- export function pastYear(measure, name) {
942
- return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Past Year', 'pastyear');
943
- }
858
+ export const pastYear = withComposeCodeForMeasure((measure, name) => measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Past Year', 'pastyear'), 'pastYear');
944
859
  /**
945
860
  * Creates a calculated contribution measure.
946
861
  *
@@ -975,9 +890,7 @@ export function pastYear(measure, name) {
975
890
  * @returns A calculated measure instance
976
891
  * @group Statistics
977
892
  */
978
- export function contribution(measure, name) {
979
- return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Contribution', 'contribution');
980
- }
893
+ export const contribution = withComposeCodeForMeasure((measure, name) => measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Contribution', 'contribution'), 'contribution');
981
894
  /**
982
895
  * Creates a calculated measure that computes a specified trend type for a given measure.
983
896
  *
@@ -1004,7 +917,7 @@ export function contribution(measure, name) {
1004
917
  * @returns A calculated measure instance
1005
918
  * @group Advanced Analytics
1006
919
  */
1007
- export function trend(measure, name, options) {
920
+ export const trend = withComposeCodeForMeasure((measure, name, options) => {
1008
921
  let params;
1009
922
  const adjustValues = (value) => value.replace('advancedSmoothing', 'smooth').replace('localEstimates', 'local');
1010
923
  if (options) {
@@ -1015,7 +928,7 @@ export function trend(measure, name, options) {
1015
928
  .join(',');
1016
929
  }
1017
930
  return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Trend', 'trend', params);
1018
- }
931
+ }, 'trend');
1019
932
  /**
1020
933
  * Creates a calculated measure that generates a forecast based on a specified measure employing
1021
934
  * advanced autoML techniques.
@@ -1050,7 +963,7 @@ export function trend(measure, name, options) {
1050
963
  * @returns A calculated measure instance
1051
964
  * @group Advanced Analytics
1052
965
  */
1053
- export function forecast(measure, name, options) {
966
+ export const forecast = withComposeCodeForMeasure((measure, name, options) => {
1054
967
  let params;
1055
968
  if (options) {
1056
969
  // create ISO string values for any Date objects
@@ -1073,7 +986,7 @@ export function forecast(measure, name, options) {
1073
986
  params = '"forecastHorizon=3"';
1074
987
  }
1075
988
  return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Forecast', 'forecast', params);
1076
- }
989
+ }, 'forecast');
1077
990
  /**
1078
991
  * Creates a calculated measure that calculates the rank of a value in a list of values.
1079
992
  *
@@ -1124,7 +1037,7 @@ export function forecast(measure, name, options) {
1124
1037
  * @returns A calculated measure instance
1125
1038
  * @group Statistics
1126
1039
  */
1127
- export function rank(measure, name, sort = RankingSortTypes.Descending, rankType = RankingTypes.StandardCompetition, groupBy = []) {
1040
+ export const rank = withComposeCodeForMeasure((measure, name, sort = RankingSortTypes.Descending, rankType = RankingTypes.StandardCompetition, groupBy = []) => {
1128
1041
  const builder = [];
1129
1042
  const context = {};
1130
1043
  builder.push('rank(');
@@ -1141,4 +1054,4 @@ export function rank(measure, name, sort = RankingSortTypes.Descending, rankType
1141
1054
  name = `${measure.name} rank`;
1142
1055
  }
1143
1056
  return new DimensionalCalculatedMeasure(name, exp, context);
1144
- }
1057
+ }, 'rank');
@@ -1,13 +1,13 @@
1
1
  import { DimensionalElement } from '../base.js';
2
2
  import { Attribute, BaseMeasure, CalculatedMeasure, Measure, MeasureContext, MeasureTemplate } from '../interfaces.js';
3
- import { Sort } from '../types.js';
3
+ import { JaqlDataSource, JSONObject, Sort } from '../types.js';
4
4
  /**
5
5
  * @internal
6
6
  */
7
7
  export declare abstract class AbstractMeasure extends DimensionalElement {
8
8
  protected _sort: Sort;
9
9
  protected _format: string | undefined;
10
- constructor(name: string, type: string, format?: string, desc?: string, sort?: Sort, composeCode?: string);
10
+ constructor(name: string, type: string, format?: string, desc?: string, sort?: Sort, dataSource?: JaqlDataSource, composeCode?: string);
11
11
  /**
12
12
  * gets the element's ID
13
13
  */
@@ -27,7 +27,7 @@ export declare abstract class AbstractMeasure extends DimensionalElement {
27
27
  /**
28
28
  * Gets a serializable representation of the element
29
29
  */
30
- serializable(): any;
30
+ serialize(): JSONObject;
31
31
  /**
32
32
  * Gets a sorted {@link Measure} with the given definition
33
33
  *
@@ -51,7 +51,7 @@ export declare abstract class AbstractMeasure extends DimensionalElement {
51
51
  export declare class DimensionalBaseMeasure extends AbstractMeasure implements BaseMeasure {
52
52
  static aggregationFromJAQL(agg: string): string;
53
53
  static aggregationToJAQL(agg: string): string;
54
- constructor(name: string, attribute: Attribute, agg: string, format?: string, desc?: string, sort?: Sort, composeCode?: string);
54
+ constructor(name: string, attribute: Attribute, agg: string, format?: string, desc?: string, sort?: Sort, dataSource?: JaqlDataSource, composeCode?: string);
55
55
  /**
56
56
  * Aggregating attribute
57
57
  */
@@ -83,7 +83,7 @@ export declare class DimensionalBaseMeasure extends AbstractMeasure implements B
83
83
  /**
84
84
  * Gets a serializable representation of the element
85
85
  */
86
- serializable(): any;
86
+ serialize(): JSONObject;
87
87
  jaql(nested?: boolean): any;
88
88
  }
89
89
  /**
@@ -93,7 +93,7 @@ export declare class DimensionalBaseMeasure extends AbstractMeasure implements B
93
93
  * @internal
94
94
  */
95
95
  export declare class DimensionalCalculatedMeasure extends AbstractMeasure implements CalculatedMeasure {
96
- constructor(name: string, expression: string, context: MeasureContext, format?: string, desc?: string, sort?: Sort, composeCode?: string);
96
+ constructor(name: string, expression: string, context: MeasureContext, format?: string, desc?: string, sort?: Sort, dataSource?: JaqlDataSource, composeCode?: string);
97
97
  /**
98
98
  * Defines the Calculated measure's expression
99
99
  */
@@ -125,7 +125,7 @@ export declare class DimensionalCalculatedMeasure extends AbstractMeasure implem
125
125
  /**
126
126
  * Gets a serializable representation of the element
127
127
  */
128
- serializable(): any;
128
+ serialize(): JSONObject;
129
129
  jaql(nested?: boolean): any;
130
130
  }
131
131
  /**
@@ -134,7 +134,7 @@ export declare class DimensionalCalculatedMeasure extends AbstractMeasure implem
134
134
  * @internal
135
135
  */
136
136
  export declare class DimensionalMeasureTemplate extends AbstractMeasure implements MeasureTemplate {
137
- constructor(name: string, attribute: Attribute, format?: string, desc?: string, sort?: Sort);
137
+ constructor(name: string, attribute: Attribute, format?: string, desc?: string, sort?: Sort, dataSource?: JaqlDataSource, composeCode?: string);
138
138
  /**
139
139
  * Aggregating attribute
140
140
  */
@@ -146,7 +146,7 @@ export declare class DimensionalMeasureTemplate extends AbstractMeasure implemen
146
146
  /**
147
147
  * Gets a serializable representation of the element
148
148
  */
149
- serializable(): any;
149
+ serialize(): JSONObject;
150
150
  /**
151
151
  * Gets a sorted {@link MeasureTemplate} with the given definition
152
152
  *