@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
package/dist/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { FilterJaqlInternal, JaqlDataSource, RankingFilterJaql } from './dimensional-model/filters/utils/types.js';
1
+ import { FilterJaqlInternal, JaqlDataSource, JaqlDataSourceForDto, RankingFilterJaql } from './dimensional-model/filters/utils/types.js';
2
2
  import { Attribute, BaseMeasure, CalculatedMeasure, Filter, FilterRelations, FilterRelationsJaql, LevelAttribute, SortDirection } from './dimensional-model/interfaces.js';
3
3
  import { BaseJaql, FilterJaql, FormulaJaql, Jaql, JaqlSortDirection, Sort } from './dimensional-model/types.js';
4
4
  import { DataSource, DataSourceInfo } from './interfaces.js';
@@ -41,6 +41,12 @@ export declare function convertDataSource(jaqlDataSource: JaqlDataSource): DataS
41
41
  * @internal
42
42
  */
43
43
  export declare function convertJaqlDataSource(dataSource: DataSource): JaqlDataSource;
44
+ /**
45
+ * Converts a DataSource to JaqlDataSourceForDto.
46
+ *
47
+ * @internal
48
+ */
49
+ export declare function convertJaqlDataSourceForDto(dataSource: DataSource): JaqlDataSourceForDto;
44
50
  /**
45
51
  * Converts a string to a Sort enum
46
52
  *
@@ -68,6 +74,15 @@ export declare function convertSortDirectionToSort(sortDirection: SortDirection)
68
74
  * @internal
69
75
  */
70
76
  export declare const createFilterFromJaql: (jaql: FilterJaql, instanceid?: string, disabled?: boolean, locked?: boolean) => Filter;
77
+ /**
78
+ * Extracts the table and column names from the given expression string.
79
+ *
80
+ * @internal
81
+ */
82
+ export declare function parseExpression(expression: string): {
83
+ table: string;
84
+ column: string;
85
+ };
71
86
  /**
72
87
  * Retrieves the table value from the attribute.
73
88
  *
@@ -94,21 +109,17 @@ export declare function getSortType(jaqlSort: `${JaqlSortDirection}` | undefined
94
109
  * @returns attribute or level attribute
95
110
  * @internal
96
111
  */
97
- export declare const createAttributeHelper: ({ dim, table, column, dataType, granularity, format, sort, title, panel, dataSource, }: {
112
+ export declare const createAttributeHelper: ({ expression, dataType, granularity, format, sort, title, panel, dataSource, }: {
98
113
  /** Dimension expression */
99
- dim: string;
100
- /** Table name */
101
- table: string | undefined;
102
- /** Column name */
103
- column: string | undefined;
114
+ expression: string;
104
115
  /** Data type */
105
116
  dataType: string;
106
117
  /** Date granularity */
107
- granularity: string | undefined;
118
+ granularity?: string | undefined;
108
119
  /** Format */
109
- format: string | undefined;
120
+ format?: string | undefined;
110
121
  /** Sort */
111
- sort: string | undefined;
122
+ sort?: string | undefined;
112
123
  /** Attribute title */
113
124
  title?: string | undefined;
114
125
  /** Panel */
@@ -122,23 +133,19 @@ export declare const createAttributeHelper: ({ dim, table, column, dataType, gra
122
133
  * @returns measure
123
134
  * @internal
124
135
  */
125
- export declare const createMeasureHelper: ({ dim, table, column, dataType, agg, granularity, format, sort, title, dataSource, }: {
136
+ export declare const createMeasureHelper: ({ expression, dataType, agg, granularity, format, sort, title, dataSource, }: {
126
137
  /** Dimension expression */
127
- dim: string;
128
- /** Table name */
129
- table: string | undefined;
130
- /** Column name */
131
- column: string;
138
+ expression: string;
132
139
  /** Data type */
133
140
  dataType: string;
134
141
  /** Aggregation function */
135
142
  agg: string;
136
143
  /** Date granularity */
137
- granularity: string | undefined;
144
+ granularity?: string | undefined;
138
145
  /** Format */
139
- format: string | undefined;
146
+ format?: string | undefined;
140
147
  /** Sort */
141
- sort: string | undefined;
148
+ sort?: string | undefined;
142
149
  /** Measure title */
143
150
  title?: string | undefined;
144
151
  /** Jaql data source */
package/dist/utils.js CHANGED
@@ -1,12 +1,12 @@
1
- import { escapeSingleQuotes } from '@sisense/sdk-common';
2
1
  import cloneDeep from 'lodash-es/cloneDeep.js';
3
2
  import mapValues from 'lodash-es/mapValues.js';
4
- import { DimensionalAttribute, DimensionalLevelAttribute, normalizeAttributeName, } from './dimensional-model/attributes.js';
3
+ import { DimensionalAttribute, DimensionalLevelAttribute } from './dimensional-model/attributes.js';
5
4
  import { isCascadingFilter } from './dimensional-model/filters/filters.js';
6
5
  import { createFilterFromJaqlInternal } from './dimensional-model/filters/utils/filter-from-jaql-util.js';
7
- import { DimensionalBaseMeasure, DimensionalCalculatedMeasure, } from './dimensional-model/measures/measures.js';
6
+ import * as measureFactory from './dimensional-model/measures/factory.js';
7
+ import { DimensionalBaseMeasure } from './dimensional-model/measures/measures.js';
8
8
  import { isDatetime, isNumber } from './dimensional-model/simple-column-types.js';
9
- import { DataType, DateLevels, JaqlSortDirection, MetadataTypes, Sort, } from './dimensional-model/types.js';
9
+ import { AggregationTypes, DataType, DateLevels, JaqlSortDirection, MetadataTypes, Sort, } from './dimensional-model/types.js';
10
10
  /**
11
11
  * A more performant, but slightly bulkier, RFC4122v4 implementation. Performance is improved by minimizing calls to random()
12
12
  *
@@ -74,6 +74,9 @@ export const getFilterListAndRelationsJaql = (filterRelations) => {
74
74
  if ('right' in node) {
75
75
  node.right = traverse(node.right);
76
76
  }
77
+ if ('composeCode' in node) {
78
+ delete node.composeCode;
79
+ }
77
80
  return node;
78
81
  }
79
82
  }
@@ -130,6 +133,28 @@ export function convertJaqlDataSource(dataSource) {
130
133
  live: false,
131
134
  };
132
135
  }
136
+ /**
137
+ * Converts a DataSource to JaqlDataSourceForDto.
138
+ *
139
+ * @internal
140
+ */
141
+ export function convertJaqlDataSourceForDto(dataSource) {
142
+ var _a;
143
+ if (isDataSourceInfo(dataSource)) {
144
+ return {
145
+ title: dataSource.title,
146
+ live: dataSource.type === 'live',
147
+ id: (_a = dataSource.id) !== null && _a !== void 0 ? _a : '',
148
+ address: dataSource.address,
149
+ };
150
+ }
151
+ else {
152
+ return {
153
+ title: dataSource,
154
+ id: '',
155
+ };
156
+ }
157
+ }
133
158
  /**
134
159
  * Converts a string to a Sort enum
135
160
  *
@@ -192,7 +217,7 @@ export const createFilterFromJaql = (jaql, instanceid, disabled = false, locked
192
217
  *
193
218
  * @internal
194
219
  */
195
- function parseExpression(expression) {
220
+ export function parseExpression(expression) {
196
221
  const [table, column] = expression.slice(1, -1).split('.');
197
222
  return {
198
223
  table,
@@ -237,29 +262,23 @@ export function getSortType(jaqlSort) {
237
262
  return 'sortNone';
238
263
  }
239
264
  }
240
- const DATA_MODEL_MODULE_NAME = 'DM';
241
265
  /**
242
266
  * Creates an attribute or level attribute from the provided parameters
243
267
  *
244
268
  * @returns attribute or level attribute
245
269
  * @internal
246
270
  */
247
- export const createAttributeHelper = ({ dim, table, column, dataType, granularity, format, sort, title, panel, dataSource, }) => {
248
- // if table is undefined, extract it from dim
249
- const dimTable = table !== null && table !== void 0 ? table : parseExpression(dim).table;
250
- // if column is undefined, extract it from dim
251
- const dimColumn = column !== null && column !== void 0 ? column : parseExpression(dim).column;
271
+ export const createAttributeHelper = ({ expression, dataType, granularity, format, sort, title, panel, dataSource, }) => {
272
+ const column = parseExpression(expression).column;
252
273
  const sortEnum = convertSort(sort);
253
274
  const isDataTypeDatetime = dataType === DataType.DATETIME;
254
275
  if (isDataTypeDatetime) {
255
- const composeCode = normalizeAttributeName(dimTable, dimColumn, granularity, DATA_MODEL_MODULE_NAME);
256
- const levelAttribute = new DimensionalLevelAttribute(title !== null && title !== void 0 ? title : dimColumn, dim, granularity || DateLevels.Years, format ||
257
- DimensionalLevelAttribute.getDefaultFormatForGranularity(granularity || DateLevels.Years), undefined, sortEnum, dataSource, composeCode, panel);
276
+ const levelAttribute = new DimensionalLevelAttribute(title !== null && title !== void 0 ? title : column, expression, granularity || DateLevels.Years, format ||
277
+ DimensionalLevelAttribute.getDefaultFormatForGranularity(granularity || DateLevels.Years), undefined, sortEnum, dataSource, undefined, panel);
258
278
  return levelAttribute;
259
279
  }
260
280
  const attributeType = !dataType || isNumber(dataType) ? MetadataTypes.NumericAttribute : MetadataTypes.TextAttribute;
261
- const composeCode = normalizeAttributeName(dimTable, dimColumn, undefined, DATA_MODEL_MODULE_NAME);
262
- const attribute = new DimensionalAttribute(title !== null && title !== void 0 ? title : dimColumn, dim, attributeType, undefined, sortEnum, dataSource, composeCode, panel);
281
+ const attribute = new DimensionalAttribute(title !== null && title !== void 0 ? title : column, expression, attributeType, undefined, sortEnum, dataSource, undefined, panel);
263
282
  return attribute;
264
283
  };
265
284
  /**
@@ -268,12 +287,9 @@ export const createAttributeHelper = ({ dim, table, column, dataType, granularit
268
287
  * @returns measure
269
288
  * @internal
270
289
  */
271
- export const createMeasureHelper = ({ dim, table, column, dataType, agg, granularity, format, sort, title, dataSource, }) => {
272
- const sortEnum = convertSort(sort);
290
+ export const createMeasureHelper = ({ expression, dataType, agg, granularity, format, sort, title, dataSource, }) => {
273
291
  const attribute = createAttributeHelper({
274
- dim,
275
- table,
276
- column,
292
+ expression,
277
293
  dataType,
278
294
  granularity,
279
295
  format,
@@ -282,21 +298,30 @@ export const createMeasureHelper = ({ dim, table, column, dataType, agg, granula
282
298
  dataSource,
283
299
  });
284
300
  const tranformedAgg = DimensionalBaseMeasure.aggregationFromJAQL(agg);
301
+ const column = parseExpression(expression).column;
285
302
  const updatedTitle = title !== null && title !== void 0 ? title : `${tranformedAgg} ${column}`;
286
- // currently, sort and format applied to attribute but not to measure
287
- const composeCode = `measureFactory.${tranformedAgg}(${attribute.composeCode}, '${escapeSingleQuotes(updatedTitle)}')`;
288
- const measure = new DimensionalBaseMeasure(updatedTitle, attribute, tranformedAgg, undefined, undefined, sortEnum, composeCode);
289
- return measure;
290
- };
291
- const getContextComposeCode = (context) => {
292
- return ('{' +
293
- Object.entries(context).reduce((acc, [key, value]) => {
294
- acc =
295
- acc +
296
- `'${key.slice(1, -1)}': ${value && 'composeCode' in value ? value.composeCode : JSON.stringify(value)},`;
297
- return acc;
298
- }, '') +
299
- '}');
303
+ switch (tranformedAgg) {
304
+ case AggregationTypes.Sum:
305
+ return measureFactory.sum(attribute, updatedTitle, format);
306
+ case AggregationTypes.Average:
307
+ return measureFactory.avg(attribute, updatedTitle, format);
308
+ case AggregationTypes.Min:
309
+ return measureFactory.min(attribute, updatedTitle, format);
310
+ case AggregationTypes.Max:
311
+ return measureFactory.max(attribute, updatedTitle, format);
312
+ case AggregationTypes.Count:
313
+ return measureFactory.count(attribute, updatedTitle, format);
314
+ case AggregationTypes.CountDistinct:
315
+ return measureFactory.countDistinct(attribute, updatedTitle, format);
316
+ case AggregationTypes.Median:
317
+ return measureFactory.median(attribute, updatedTitle, format);
318
+ case AggregationTypes.Variance:
319
+ return measureFactory.aggregate(attribute, AggregationTypes.Variance, updatedTitle, format);
320
+ case AggregationTypes.StandardDeviation:
321
+ return measureFactory.aggregate(attribute, AggregationTypes.StandardDeviation, updatedTitle, format);
322
+ default:
323
+ return measureFactory.sum(attribute, updatedTitle, format);
324
+ }
300
325
  };
301
326
  /**
302
327
  * Creates a measure from the provided parameters
@@ -306,15 +331,13 @@ const getContextComposeCode = (context) => {
306
331
  */
307
332
  export const createCalculatedMeasureHelper = (jaql) => {
308
333
  var _a;
309
- const sortEnum = convertSort(jaql.sort);
310
334
  const context = mapValues((_a = jaql.context) !== null && _a !== void 0 ? _a : {}, (jaqlContextValue) => {
311
335
  if (typeof jaqlContextValue === 'string') {
312
336
  return jaqlContextValue;
313
337
  }
314
338
  return jaqlContextValue && createDimensionalElementFromJaql(jaqlContextValue);
315
339
  });
316
- const composeCode = `measureFactory.customFormula('${escapeSingleQuotes(jaql.title)}', '${jaql.formula}', ${getContextComposeCode(context)})`;
317
- return new DimensionalCalculatedMeasure(jaql.title, jaql.formula, context, undefined, undefined, sortEnum, composeCode);
340
+ return measureFactory.customFormula(jaql.title, jaql.formula, context);
318
341
  };
319
342
  /**
320
343
  * Creates a dimensional element from a JAQL object.
@@ -337,9 +360,7 @@ export function createDimensionalElementFromJaql(jaql, datetimeFormat, panel) {
337
360
  const hasAggregation = !!jaql.agg;
338
361
  if (hasAggregation) {
339
362
  return createMeasureHelper({
340
- dim: jaql.dim,
341
- table: jaql.table,
342
- column: jaql.column,
363
+ expression: jaql.dim,
343
364
  dataType: jaql.datatype,
344
365
  agg: jaql.agg || '',
345
366
  granularity: getGranularityFromJaql(jaql),
@@ -350,9 +371,7 @@ export function createDimensionalElementFromJaql(jaql, datetimeFormat, panel) {
350
371
  });
351
372
  }
352
373
  return createAttributeHelper({
353
- dim: jaql.dim,
354
- table: jaql.table,
355
- column: jaql.column,
374
+ expression: jaql.dim,
356
375
  dataType: jaql.datatype,
357
376
  granularity: getGranularityFromJaql(jaql),
358
377
  format: datetimeFormat,
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "Sisense",
12
12
  "Compose SDK"
13
13
  ],
14
- "version": "1.34.0",
14
+ "version": "2.1.0",
15
15
  "type": "module",
16
16
  "main": "./dist/cjs/index.js",
17
17
  "module": "./dist/index.js",
@@ -27,8 +27,8 @@
27
27
  "author": "Sisense",
28
28
  "license": "SEE LICENSE IN LICENSE.md",
29
29
  "dependencies": {
30
- "@sisense/sdk-common": "^1.34.0",
31
- "@sisense/sdk-rest-client": "^1.34.0",
30
+ "@sisense/sdk-common": "^2.1.0",
31
+ "@sisense/sdk-rest-client": "^2.1.0",
32
32
  "guid-typescript": "^1.0.9",
33
33
  "hash-it": "^6.0.0",
34
34
  "lodash-es": "^4.17.21",
@@ -1,17 +0,0 @@
1
- /**
2
- * Stringifies the argument, with an option to exclude specific properties.
3
- *
4
- * @param arg - The argument to stringify.
5
- * @param excludeProps - Optional array of property names to exclude when stringifying objects.
6
- * @returns The stringified representation of the argument.
7
- */
8
- export declare function stringifyHelper(arg: any, excludeProps?: string[]): string;
9
- /**
10
- * High order function to construct compose code for filter factory functions
11
- *
12
- * @param func - filter factory function
13
- * @param funcName - name of the filter factory function. Needed if the function name is minified.
14
- * @param ignoreIndexes - Indexes of parameters to ignore in the generated composeCode
15
- * @returns filter factory function with composeCode property added to the filter
16
- */
17
- export declare function withComposeCode<T extends (...args: any[]) => any>(func: T, funcName?: string, ignoreIndexes?: number[]): T;
@@ -1,82 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.withComposeCode = exports.stringifyHelper = void 0;
4
- /**
5
- * Stringifies the argument, with an option to exclude specific properties.
6
- *
7
- * @param arg - The argument to stringify.
8
- * @param excludeProps - Optional array of property names to exclude when stringifying objects.
9
- * @returns The stringified representation of the argument.
10
- */
11
- function stringifyHelper(arg, excludeProps = []) {
12
- try {
13
- if (arg === null || arg === undefined) {
14
- return JSON.stringify(arg);
15
- }
16
- if (arg === Object(arg) && 'composeCode' in arg) {
17
- return arg.composeCode;
18
- }
19
- if (Array.isArray(arg)) {
20
- return ('[' +
21
- arg
22
- .map((e) => {
23
- return stringifyHelper(e, excludeProps);
24
- })
25
- .join(', ') +
26
- ']');
27
- }
28
- if (typeof arg === 'string') {
29
- return `'${arg}'`;
30
- }
31
- if (typeof arg === 'number' || !isNaN(arg)) {
32
- return arg;
33
- }
34
- if (typeof arg === 'object') {
35
- const filteredObject = Object.keys(arg)
36
- .filter((key) => !excludeProps.includes(key))
37
- .reduce((acc, key) => {
38
- acc[key] = arg[key];
39
- return acc;
40
- }, {});
41
- // Check if the filtered object is empty
42
- if (Object.keys(filteredObject).length === 0) {
43
- return '';
44
- }
45
- return JSON.stringify(filteredObject);
46
- }
47
- }
48
- catch (e) {
49
- console.error(e);
50
- }
51
- return JSON.stringify(arg);
52
- }
53
- exports.stringifyHelper = stringifyHelper;
54
- /**
55
- * High order function to construct compose code for filter factory functions
56
- *
57
- * @param func - filter factory function
58
- * @param funcName - name of the filter factory function. Needed if the function name is minified.
59
- * @param ignoreIndexes - Indexes of parameters to ignore in the generated composeCode
60
- * @returns filter factory function with composeCode property added to the filter
61
- */
62
- function withComposeCode(func, funcName, ignoreIndexes = []) {
63
- return function (...args) {
64
- const argValues = args
65
- .map((arg, index) => {
66
- if (ignoreIndexes.includes(index)) {
67
- return ''; // Placeholder for ignored parameters
68
- }
69
- return stringifyHelper(arg, ['guid']);
70
- })
71
- .join(', ')
72
- // remove any number of trailing commas
73
- .replace(/(,\s*)+$/, '');
74
- const signature = `filterFactory.${funcName !== null && funcName !== void 0 ? funcName : func.name}(${argValues})`;
75
- // Call the original function and get the filter
76
- const filter = func(...args);
77
- // Add the composeCode property
78
- filter.composeCode = signature;
79
- return filter;
80
- };
81
- }
82
- exports.withComposeCode = withComposeCode;
@@ -1,17 +0,0 @@
1
- /**
2
- * Stringifies the argument, with an option to exclude specific properties.
3
- *
4
- * @param arg - The argument to stringify.
5
- * @param excludeProps - Optional array of property names to exclude when stringifying objects.
6
- * @returns The stringified representation of the argument.
7
- */
8
- export declare function stringifyHelper(arg: any, excludeProps?: string[]): string;
9
- /**
10
- * High order function to construct compose code for filter factory functions
11
- *
12
- * @param func - filter factory function
13
- * @param funcName - name of the filter factory function. Needed if the function name is minified.
14
- * @param ignoreIndexes - Indexes of parameters to ignore in the generated composeCode
15
- * @returns filter factory function with composeCode property added to the filter
16
- */
17
- export declare function withComposeCode<T extends (...args: any[]) => any>(func: T, funcName?: string, ignoreIndexes?: number[]): T;
@@ -1,77 +0,0 @@
1
- /**
2
- * Stringifies the argument, with an option to exclude specific properties.
3
- *
4
- * @param arg - The argument to stringify.
5
- * @param excludeProps - Optional array of property names to exclude when stringifying objects.
6
- * @returns The stringified representation of the argument.
7
- */
8
- export function stringifyHelper(arg, excludeProps = []) {
9
- try {
10
- if (arg === null || arg === undefined) {
11
- return JSON.stringify(arg);
12
- }
13
- if (arg === Object(arg) && 'composeCode' in arg) {
14
- return arg.composeCode;
15
- }
16
- if (Array.isArray(arg)) {
17
- return ('[' +
18
- arg
19
- .map((e) => {
20
- return stringifyHelper(e, excludeProps);
21
- })
22
- .join(', ') +
23
- ']');
24
- }
25
- if (typeof arg === 'string') {
26
- return `'${arg}'`;
27
- }
28
- if (typeof arg === 'number' || !isNaN(arg)) {
29
- return arg;
30
- }
31
- if (typeof arg === 'object') {
32
- const filteredObject = Object.keys(arg)
33
- .filter((key) => !excludeProps.includes(key))
34
- .reduce((acc, key) => {
35
- acc[key] = arg[key];
36
- return acc;
37
- }, {});
38
- // Check if the filtered object is empty
39
- if (Object.keys(filteredObject).length === 0) {
40
- return '';
41
- }
42
- return JSON.stringify(filteredObject);
43
- }
44
- }
45
- catch (e) {
46
- console.error(e);
47
- }
48
- return JSON.stringify(arg);
49
- }
50
- /**
51
- * High order function to construct compose code for filter factory functions
52
- *
53
- * @param func - filter factory function
54
- * @param funcName - name of the filter factory function. Needed if the function name is minified.
55
- * @param ignoreIndexes - Indexes of parameters to ignore in the generated composeCode
56
- * @returns filter factory function with composeCode property added to the filter
57
- */
58
- export function withComposeCode(func, funcName, ignoreIndexes = []) {
59
- return function (...args) {
60
- const argValues = args
61
- .map((arg, index) => {
62
- if (ignoreIndexes.includes(index)) {
63
- return ''; // Placeholder for ignored parameters
64
- }
65
- return stringifyHelper(arg, ['guid']);
66
- })
67
- .join(', ')
68
- // remove any number of trailing commas
69
- .replace(/(,\s*)+$/, '');
70
- const signature = `filterFactory.${funcName !== null && funcName !== void 0 ? funcName : func.name}(${argValues})`;
71
- // Call the original function and get the filter
72
- const filter = func(...args);
73
- // Add the composeCode property
74
- filter.composeCode = signature;
75
- return filter;
76
- };
77
- }