@sisense/sdk-data 1.33.0 → 2.0.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 (97) 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 +13 -6
  4. package/dist/cjs/dimensional-model/attributes.js +39 -12
  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/data-model.d.ts +1 -1
  12. package/dist/cjs/dimensional-model/data-model.js +1 -1
  13. package/dist/cjs/dimensional-model/dimensions/dimensions.d.ts +6 -6
  14. package/dist/cjs/dimensional-model/dimensions/dimensions.js +34 -17
  15. package/dist/cjs/dimensional-model/dimensions/utils.d.ts +1 -0
  16. package/dist/cjs/dimensional-model/dimensions/utils.js +2 -1
  17. package/dist/cjs/dimensional-model/factory.js +5 -5
  18. package/dist/cjs/dimensional-model/filters/factory.d.ts +42 -42
  19. package/dist/cjs/dimensional-model/filters/factory.js +53 -168
  20. package/dist/cjs/dimensional-model/filters/filter-relations.d.ts +11 -2
  21. package/dist/cjs/dimensional-model/filters/filter-relations.js +14 -7
  22. package/dist/cjs/dimensional-model/filters/filters.d.ts +40 -24
  23. package/dist/cjs/dimensional-model/filters/filters.js +106 -56
  24. package/dist/cjs/dimensional-model/filters/helpers.d.ts +1 -1
  25. package/dist/cjs/dimensional-model/filters/helpers.js +2 -2
  26. package/dist/cjs/dimensional-model/filters/utils/attribute-measure-util.js +9 -17
  27. package/dist/cjs/dimensional-model/filters/utils/condition-filter-util.d.ts +1 -1
  28. package/dist/cjs/dimensional-model/filters/utils/condition-filter-util.js +31 -29
  29. package/dist/cjs/dimensional-model/filters/utils/filter-from-jaql-util.d.ts +1 -1
  30. package/dist/cjs/dimensional-model/filters/utils/filter-from-jaql-util.js +13 -19
  31. package/dist/cjs/dimensional-model/filters/utils/filter-types-util.d.ts +1 -1
  32. package/dist/cjs/dimensional-model/filters/utils/filter-types-util.js +1 -1
  33. package/dist/cjs/dimensional-model/filters/utils/types.d.ts +10 -0
  34. package/dist/cjs/dimensional-model/interfaces.d.ts +17 -7
  35. package/dist/cjs/dimensional-model/jaql-element.d.ts +13 -1
  36. package/dist/cjs/dimensional-model/jaql-element.js +54 -2
  37. package/dist/cjs/dimensional-model/measures/factory.d.ts +46 -53
  38. package/dist/cjs/dimensional-model/measures/factory.js +57 -186
  39. package/dist/cjs/dimensional-model/measures/measures.d.ts +10 -10
  40. package/dist/cjs/dimensional-model/measures/measures.js +35 -33
  41. package/dist/cjs/dimensional-model/types.d.ts +41 -16
  42. package/dist/cjs/index.d.ts +7 -7
  43. package/dist/cjs/index.js +7 -7
  44. package/dist/cjs/utils.d.ts +45 -22
  45. package/dist/cjs/utils.js +119 -47
  46. package/dist/dimensional-model/analytics/factory.d.ts +10 -10
  47. package/dist/dimensional-model/analytics/factory.js +15 -14
  48. package/dist/dimensional-model/attributes.d.ts +13 -6
  49. package/dist/dimensional-model/attributes.js +39 -12
  50. package/dist/dimensional-model/base.d.ts +3 -3
  51. package/dist/dimensional-model/base.js +7 -4
  52. package/dist/dimensional-model/compose-code-utils.d.ts +41 -0
  53. package/dist/dimensional-model/compose-code-utils.js +119 -0
  54. package/dist/dimensional-model/consts.d.ts +1 -0
  55. package/dist/dimensional-model/consts.js +1 -0
  56. package/dist/dimensional-model/data-model.d.ts +1 -1
  57. package/dist/dimensional-model/data-model.js +1 -1
  58. package/dist/dimensional-model/dimensions/dimensions.d.ts +6 -6
  59. package/dist/dimensional-model/dimensions/dimensions.js +35 -18
  60. package/dist/dimensional-model/dimensions/utils.d.ts +1 -0
  61. package/dist/dimensional-model/dimensions/utils.js +3 -2
  62. package/dist/dimensional-model/factory.js +5 -5
  63. package/dist/dimensional-model/filters/factory.d.ts +42 -42
  64. package/dist/dimensional-model/filters/factory.js +52 -126
  65. package/dist/dimensional-model/filters/filter-relations.d.ts +11 -2
  66. package/dist/dimensional-model/filters/filter-relations.js +14 -7
  67. package/dist/dimensional-model/filters/filters.d.ts +40 -24
  68. package/dist/dimensional-model/filters/filters.js +106 -56
  69. package/dist/dimensional-model/filters/helpers.d.ts +1 -1
  70. package/dist/dimensional-model/filters/helpers.js +2 -2
  71. package/dist/dimensional-model/filters/utils/attribute-measure-util.js +10 -18
  72. package/dist/dimensional-model/filters/utils/condition-filter-util.d.ts +1 -1
  73. package/dist/dimensional-model/filters/utils/condition-filter-util.js +31 -29
  74. package/dist/dimensional-model/filters/utils/filter-from-jaql-util.d.ts +1 -1
  75. package/dist/dimensional-model/filters/utils/filter-from-jaql-util.js +13 -19
  76. package/dist/dimensional-model/filters/utils/filter-types-util.d.ts +1 -1
  77. package/dist/dimensional-model/filters/utils/filter-types-util.js +1 -1
  78. package/dist/dimensional-model/filters/utils/types.d.ts +10 -0
  79. package/dist/dimensional-model/interfaces.d.ts +17 -7
  80. package/dist/dimensional-model/jaql-element.d.ts +13 -1
  81. package/dist/dimensional-model/jaql-element.js +52 -1
  82. package/dist/dimensional-model/measures/factory.d.ts +46 -53
  83. package/dist/dimensional-model/measures/factory.js +56 -143
  84. package/dist/dimensional-model/measures/measures.d.ts +10 -10
  85. package/dist/dimensional-model/measures/measures.js +35 -33
  86. package/dist/dimensional-model/types.d.ts +41 -16
  87. package/dist/index.d.ts +7 -7
  88. package/dist/index.js +7 -7
  89. package/dist/translation/initialize-i18n.js +1 -1
  90. package/dist/tsconfig.prod.cjs.tsbuildinfo +1 -1
  91. package/dist/utils.d.ts +45 -22
  92. package/dist/utils.js +94 -49
  93. package/package.json +5 -4
  94. package/dist/cjs/dimensional-model/filters/utils/filter-code-util.d.ts +0 -17
  95. package/dist/cjs/dimensional-model/filters/utils/filter-code-util.js +0 -82
  96. package/dist/dimensional-model/filters/utils/filter-code-util.d.ts +0 -17
  97. package/dist/dimensional-model/filters/utils/filter-code-util.js +0 -77
package/dist/utils.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import cloneDeep from 'lodash-es/cloneDeep.js';
2
2
  import mapValues from 'lodash-es/mapValues.js';
3
- import { createFilterFromJaqlInternal } from './dimensional-model/filters/utils/filter-from-jaql-util.js';
4
- import { DataType, JaqlSortDirection, MetadataTypes, Sort, } from './dimensional-model/types.js';
5
- import { escapeSingleQuotes } from '@sisense/sdk-common';
6
- import { DimensionalBaseMeasure, DimensionalCalculatedMeasure, } from './dimensional-model/measures/measures.js';
3
+ import { DimensionalAttribute, DimensionalLevelAttribute } from './dimensional-model/attributes.js';
7
4
  import { isCascadingFilter } from './dimensional-model/filters/filters.js';
8
- import { DimensionalAttribute, DimensionalLevelAttribute, normalizeAttributeName, } from './dimensional-model/attributes.js';
9
- import { isNumber } from './dimensional-model/simple-column-types.js';
5
+ import { createFilterFromJaqlInternal } from './dimensional-model/filters/utils/filter-from-jaql-util.js';
6
+ import * as measureFactory from './dimensional-model/measures/factory.js';
7
+ import { DimensionalBaseMeasure } from './dimensional-model/measures/measures.js';
8
+ import { isDatetime, isNumber } from './dimensional-model/simple-column-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
  *
@@ -130,6 +130,28 @@ export function convertJaqlDataSource(dataSource) {
130
130
  live: false,
131
131
  };
132
132
  }
133
+ /**
134
+ * Converts a DataSource to JaqlDataSourceForDto.
135
+ *
136
+ * @internal
137
+ */
138
+ export function convertJaqlDataSourceForDto(dataSource) {
139
+ var _a;
140
+ if (isDataSourceInfo(dataSource)) {
141
+ return {
142
+ title: dataSource.title,
143
+ live: dataSource.type === 'live',
144
+ id: (_a = dataSource.id) !== null && _a !== void 0 ? _a : '',
145
+ address: dataSource.address,
146
+ };
147
+ }
148
+ else {
149
+ return {
150
+ title: dataSource,
151
+ id: '',
152
+ };
153
+ }
154
+ }
133
155
  /**
134
156
  * Converts a string to a Sort enum
135
157
  *
@@ -145,6 +167,23 @@ export function convertSort(sort) {
145
167
  return Sort.None;
146
168
  }
147
169
  }
170
+ /**
171
+ * Converts a SortDirection to a Sort enum
172
+ *
173
+ * @param sortDirection - The SortDirection to convert
174
+ * @returns The converted Sort enum
175
+ * @internal
176
+ */
177
+ export function convertSortDirectionToSort(sortDirection) {
178
+ switch (sortDirection) {
179
+ case 'sortAsc':
180
+ return Sort.Ascending;
181
+ case 'sortDesc':
182
+ return Sort.Descending;
183
+ default:
184
+ return Sort.None;
185
+ }
186
+ }
148
187
  /**
149
188
  * Creates a filter from a JAQL object.
150
189
  *
@@ -175,7 +214,7 @@ export const createFilterFromJaql = (jaql, instanceid, disabled = false, locked
175
214
  *
176
215
  * @internal
177
216
  */
178
- function parseExpression(expression) {
217
+ export function parseExpression(expression) {
179
218
  const [table, column] = expression.slice(1, -1).split('.');
180
219
  return {
181
220
  table,
@@ -220,29 +259,23 @@ export function getSortType(jaqlSort) {
220
259
  return 'sortNone';
221
260
  }
222
261
  }
223
- const DATA_MODEL_MODULE_NAME = 'DM';
224
262
  /**
225
263
  * Creates an attribute or level attribute from the provided parameters
226
264
  *
227
265
  * @returns attribute or level attribute
228
266
  * @internal
229
267
  */
230
- export const createAttributeHelper = ({ dim, table, column, dataType, level, format, sort, title, panel, dataSource, }) => {
231
- // if table is undefined, extract it from dim
232
- const dimTable = table !== null && table !== void 0 ? table : parseExpression(dim).table;
233
- // if column is undefined, extract it from dim
234
- const dimColumn = column !== null && column !== void 0 ? column : parseExpression(dim).column;
268
+ export const createAttributeHelper = ({ expression, dataType, granularity, format, sort, title, panel, dataSource, }) => {
269
+ const column = parseExpression(expression).column;
235
270
  const sortEnum = convertSort(sort);
236
271
  const isDataTypeDatetime = dataType === DataType.DATETIME;
237
272
  if (isDataTypeDatetime) {
238
- const dateLevel = DimensionalLevelAttribute.translateJaqlToGranularity({ level });
239
- const composeCode = normalizeAttributeName(dimTable, dimColumn, level, DATA_MODEL_MODULE_NAME);
240
- const levelAttribute = new DimensionalLevelAttribute(title !== null && title !== void 0 ? title : dimColumn, dim, dateLevel, format || DimensionalLevelAttribute.getDefaultFormatForGranularity(dateLevel), undefined, sortEnum, dataSource, composeCode, panel);
273
+ const levelAttribute = new DimensionalLevelAttribute(title !== null && title !== void 0 ? title : column, expression, granularity || DateLevels.Years, format ||
274
+ DimensionalLevelAttribute.getDefaultFormatForGranularity(granularity || DateLevels.Years), undefined, sortEnum, dataSource, undefined, panel);
241
275
  return levelAttribute;
242
276
  }
243
277
  const attributeType = !dataType || isNumber(dataType) ? MetadataTypes.NumericAttribute : MetadataTypes.TextAttribute;
244
- const composeCode = normalizeAttributeName(dimTable, dimColumn, undefined, DATA_MODEL_MODULE_NAME);
245
- const attribute = new DimensionalAttribute(title !== null && title !== void 0 ? title : dimColumn, dim, attributeType, undefined, sortEnum, dataSource, composeCode, panel);
278
+ const attribute = new DimensionalAttribute(title !== null && title !== void 0 ? title : column, expression, attributeType, undefined, sortEnum, dataSource, undefined, panel);
246
279
  return attribute;
247
280
  };
248
281
  /**
@@ -251,35 +284,41 @@ export const createAttributeHelper = ({ dim, table, column, dataType, level, for
251
284
  * @returns measure
252
285
  * @internal
253
286
  */
254
- export const createMeasureHelper = ({ dim, table, column, dataType, agg, level, format, sort, title, dataSource, }) => {
255
- const sortEnum = convertSort(sort);
287
+ export const createMeasureHelper = ({ expression, dataType, agg, granularity, format, sort, title, dataSource, }) => {
256
288
  const attribute = createAttributeHelper({
257
- dim,
258
- table,
259
- column,
289
+ expression,
260
290
  dataType,
261
- level,
291
+ granularity,
262
292
  format,
263
293
  sort,
264
294
  title,
265
295
  dataSource,
266
296
  });
267
297
  const tranformedAgg = DimensionalBaseMeasure.aggregationFromJAQL(agg);
298
+ const column = parseExpression(expression).column;
268
299
  const updatedTitle = title !== null && title !== void 0 ? title : `${tranformedAgg} ${column}`;
269
- // currently, sort and format applied to attribute but not to measure
270
- const composeCode = `measureFactory.${tranformedAgg}(${attribute.composeCode}, '${escapeSingleQuotes(updatedTitle)}')`;
271
- const measure = new DimensionalBaseMeasure(updatedTitle, attribute, tranformedAgg, undefined, undefined, sortEnum, composeCode);
272
- return measure;
273
- };
274
- const getContextComposeCode = (context) => {
275
- return ('{' +
276
- Object.entries(context).reduce((acc, [key, value]) => {
277
- acc =
278
- acc +
279
- `'${key.slice(1, -1)}': ${value && 'composeCode' in value ? value.composeCode : JSON.stringify(value)},`;
280
- return acc;
281
- }, '') +
282
- '}');
300
+ switch (tranformedAgg) {
301
+ case AggregationTypes.Sum:
302
+ return measureFactory.sum(attribute, updatedTitle, format);
303
+ case AggregationTypes.Average:
304
+ return measureFactory.avg(attribute, updatedTitle, format);
305
+ case AggregationTypes.Min:
306
+ return measureFactory.min(attribute, updatedTitle, format);
307
+ case AggregationTypes.Max:
308
+ return measureFactory.max(attribute, updatedTitle, format);
309
+ case AggregationTypes.Count:
310
+ return measureFactory.count(attribute, updatedTitle, format);
311
+ case AggregationTypes.CountDistinct:
312
+ return measureFactory.countDistinct(attribute, updatedTitle, format);
313
+ case AggregationTypes.Median:
314
+ return measureFactory.median(attribute, updatedTitle, format);
315
+ case AggregationTypes.Variance:
316
+ return measureFactory.aggregate(attribute, AggregationTypes.Variance, updatedTitle, format);
317
+ case AggregationTypes.StandardDeviation:
318
+ return measureFactory.aggregate(attribute, AggregationTypes.StandardDeviation, updatedTitle, format);
319
+ default:
320
+ return measureFactory.sum(attribute, updatedTitle, format);
321
+ }
283
322
  };
284
323
  /**
285
324
  * Creates a measure from the provided parameters
@@ -289,15 +328,13 @@ const getContextComposeCode = (context) => {
289
328
  */
290
329
  export const createCalculatedMeasureHelper = (jaql) => {
291
330
  var _a;
292
- const sortEnum = convertSort(jaql.sort);
293
331
  const context = mapValues((_a = jaql.context) !== null && _a !== void 0 ? _a : {}, (jaqlContextValue) => {
294
332
  if (typeof jaqlContextValue === 'string') {
295
333
  return jaqlContextValue;
296
334
  }
297
335
  return jaqlContextValue && createDimensionalElementFromJaql(jaqlContextValue);
298
336
  });
299
- const composeCode = `measureFactory.customFormula('${escapeSingleQuotes(jaql.title)}', '${jaql.formula}', ${getContextComposeCode(context)})`;
300
- return new DimensionalCalculatedMeasure(jaql.title, jaql.formula, context, undefined, undefined, sortEnum, composeCode);
337
+ return measureFactory.customFormula(jaql.title, jaql.formula, context);
301
338
  };
302
339
  /**
303
340
  * Creates a dimensional element from a JAQL object.
@@ -320,12 +357,10 @@ export function createDimensionalElementFromJaql(jaql, datetimeFormat, panel) {
320
357
  const hasAggregation = !!jaql.agg;
321
358
  if (hasAggregation) {
322
359
  return createMeasureHelper({
323
- dim: jaql.dim,
324
- table: jaql.table,
325
- column: jaql.column,
360
+ expression: jaql.dim,
326
361
  dataType: jaql.datatype,
327
362
  agg: jaql.agg || '',
328
- level: jaql.level,
363
+ granularity: getGranularityFromJaql(jaql),
329
364
  format: datetimeFormat,
330
365
  sort: jaql.sort,
331
366
  title: jaql.title,
@@ -333,11 +368,9 @@ export function createDimensionalElementFromJaql(jaql, datetimeFormat, panel) {
333
368
  });
334
369
  }
335
370
  return createAttributeHelper({
336
- dim: jaql.dim,
337
- table: jaql.table,
338
- column: jaql.column,
371
+ expression: jaql.dim,
339
372
  dataType: jaql.datatype,
340
- level: jaql.level,
373
+ granularity: getGranularityFromJaql(jaql),
341
374
  format: datetimeFormat,
342
375
  sort: jaql.sort,
343
376
  title: jaql.title,
@@ -345,3 +378,15 @@ export function createDimensionalElementFromJaql(jaql, datetimeFormat, panel) {
345
378
  dataSource,
346
379
  });
347
380
  }
381
+ /**
382
+ * Returns the granularity from the provided JAQL object.
383
+ *
384
+ * @param jaql - The JAQL object.
385
+ * @returns string.
386
+ * @internal
387
+ */
388
+ export function getGranularityFromJaql(jaql) {
389
+ return (jaql === null || jaql === void 0 ? void 0 : jaql.datatype) && isDatetime(jaql.datatype)
390
+ ? DimensionalLevelAttribute.translateJaqlToGranularity(jaql)
391
+ : undefined;
392
+ }
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "Sisense",
12
12
  "Compose SDK"
13
13
  ],
14
- "version": "1.33.0",
14
+ "version": "2.0.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.33.0",
31
- "@sisense/sdk-rest-client": "^1.33.0",
30
+ "@sisense/sdk-common": "^2.0.0",
31
+ "@sisense/sdk-rest-client": "^2.0.0",
32
32
  "guid-typescript": "^1.0.9",
33
33
  "hash-it": "^6.0.0",
34
34
  "lodash-es": "^4.17.21",
@@ -40,7 +40,8 @@
40
40
  "build:prod": "tsc --project tsconfig.prod.json && tsc --project tsconfig.prod.cjs.json && cp package.cjs.json ./dist/cjs/package.json",
41
41
  "build.watch": "tsc --build --watch",
42
42
  "clean": "rm -rf dist coverage tsconfig.build.tsbuildinfo tsconfig.prod.tsbuildinfo",
43
- "lint": "eslint . --fix",
43
+ "lint": "eslint . --quiet",
44
+ "lint:fix": "run lint --fix",
44
45
  "format": "prettier --write .",
45
46
  "format:check": "prettier --check .",
46
47
  "vitest": "run -T vitest",
@@ -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
- }