@sisense/sdk-data 1.34.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.
- package/dist/cjs/dimensional-model/analytics/factory.d.ts +10 -10
- package/dist/cjs/dimensional-model/analytics/factory.js +15 -16
- package/dist/cjs/dimensional-model/attributes.d.ts +4 -4
- package/dist/cjs/dimensional-model/attributes.js +21 -7
- package/dist/cjs/dimensional-model/base.d.ts +3 -3
- package/dist/cjs/dimensional-model/base.js +7 -4
- package/dist/cjs/dimensional-model/compose-code-utils.d.ts +41 -0
- package/dist/cjs/dimensional-model/compose-code-utils.js +127 -0
- package/dist/cjs/dimensional-model/consts.d.ts +1 -0
- package/dist/cjs/dimensional-model/consts.js +4 -0
- package/dist/cjs/dimensional-model/dimensions/dimensions.d.ts +5 -5
- package/dist/cjs/dimensional-model/dimensions/dimensions.js +25 -16
- package/dist/cjs/dimensional-model/filters/factory.d.ts +41 -41
- package/dist/cjs/dimensional-model/filters/factory.js +53 -168
- package/dist/cjs/dimensional-model/filters/filter-relations.js +2 -5
- package/dist/cjs/dimensional-model/filters/filters.d.ts +39 -23
- package/dist/cjs/dimensional-model/filters/filters.js +102 -52
- package/dist/cjs/dimensional-model/filters/utils/attribute-measure-util.js +6 -14
- package/dist/cjs/dimensional-model/filters/utils/condition-filter-util.js +28 -26
- package/dist/cjs/dimensional-model/filters/utils/filter-from-jaql-util.js +9 -15
- package/dist/cjs/dimensional-model/filters/utils/types.d.ts +10 -0
- package/dist/cjs/dimensional-model/interfaces.d.ts +9 -7
- package/dist/cjs/dimensional-model/jaql-element.d.ts +13 -1
- package/dist/cjs/dimensional-model/jaql-element.js +53 -1
- package/dist/cjs/dimensional-model/measures/factory.d.ts +45 -52
- package/dist/cjs/dimensional-model/measures/factory.js +55 -184
- package/dist/cjs/dimensional-model/measures/measures.d.ts +9 -9
- package/dist/cjs/dimensional-model/measures/measures.js +31 -29
- package/dist/cjs/dimensional-model/types.d.ts +25 -2
- package/dist/cjs/utils.d.ts +26 -19
- package/dist/cjs/utils.js +82 -41
- package/dist/dimensional-model/analytics/factory.d.ts +10 -10
- package/dist/dimensional-model/analytics/factory.js +15 -14
- package/dist/dimensional-model/attributes.d.ts +4 -4
- package/dist/dimensional-model/attributes.js +21 -7
- package/dist/dimensional-model/base.d.ts +3 -3
- package/dist/dimensional-model/base.js +7 -4
- package/dist/dimensional-model/compose-code-utils.d.ts +41 -0
- package/dist/dimensional-model/compose-code-utils.js +119 -0
- package/dist/dimensional-model/consts.d.ts +1 -0
- package/dist/dimensional-model/consts.js +1 -0
- package/dist/dimensional-model/dimensions/dimensions.d.ts +5 -5
- package/dist/dimensional-model/dimensions/dimensions.js +26 -17
- package/dist/dimensional-model/filters/factory.d.ts +41 -41
- package/dist/dimensional-model/filters/factory.js +51 -125
- package/dist/dimensional-model/filters/filter-relations.js +3 -6
- package/dist/dimensional-model/filters/filters.d.ts +39 -23
- package/dist/dimensional-model/filters/filters.js +102 -52
- package/dist/dimensional-model/filters/utils/attribute-measure-util.js +6 -14
- package/dist/dimensional-model/filters/utils/condition-filter-util.js +28 -26
- package/dist/dimensional-model/filters/utils/filter-from-jaql-util.js +9 -15
- package/dist/dimensional-model/filters/utils/types.d.ts +10 -0
- package/dist/dimensional-model/interfaces.d.ts +9 -7
- package/dist/dimensional-model/jaql-element.d.ts +13 -1
- package/dist/dimensional-model/jaql-element.js +52 -1
- package/dist/dimensional-model/measures/factory.d.ts +45 -52
- package/dist/dimensional-model/measures/factory.js +54 -141
- package/dist/dimensional-model/measures/measures.d.ts +9 -9
- package/dist/dimensional-model/measures/measures.js +31 -29
- package/dist/dimensional-model/types.d.ts +25 -2
- package/dist/tsconfig.prod.cjs.tsbuildinfo +1 -1
- package/dist/utils.d.ts +26 -19
- package/dist/utils.js +60 -44
- package/package.json +3 -3
- package/dist/cjs/dimensional-model/filters/utils/filter-code-util.d.ts +0 -17
- package/dist/cjs/dimensional-model/filters/utils/filter-code-util.js +0 -82
- package/dist/dimensional-model/filters/utils/filter-code-util.d.ts +0 -17
- 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: ({
|
|
112
|
+
export declare const createAttributeHelper: ({ expression, dataType, granularity, format, sort, title, panel, dataSource, }: {
|
|
98
113
|
/** Dimension expression */
|
|
99
|
-
|
|
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
|
|
118
|
+
granularity?: string | undefined;
|
|
108
119
|
/** Format */
|
|
109
|
-
format
|
|
120
|
+
format?: string | undefined;
|
|
110
121
|
/** Sort */
|
|
111
|
-
sort
|
|
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: ({
|
|
136
|
+
export declare const createMeasureHelper: ({ expression, dataType, agg, granularity, format, sort, title, dataSource, }: {
|
|
126
137
|
/** Dimension expression */
|
|
127
|
-
|
|
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
|
|
144
|
+
granularity?: string | undefined;
|
|
138
145
|
/** Format */
|
|
139
|
-
format
|
|
146
|
+
format?: string | undefined;
|
|
140
147
|
/** Sort */
|
|
141
|
-
sort
|
|
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
|
|
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
|
|
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
|
*
|
|
@@ -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
|
*
|
|
@@ -192,7 +214,7 @@ export const createFilterFromJaql = (jaql, instanceid, disabled = false, locked
|
|
|
192
214
|
*
|
|
193
215
|
* @internal
|
|
194
216
|
*/
|
|
195
|
-
function parseExpression(expression) {
|
|
217
|
+
export function parseExpression(expression) {
|
|
196
218
|
const [table, column] = expression.slice(1, -1).split('.');
|
|
197
219
|
return {
|
|
198
220
|
table,
|
|
@@ -237,29 +259,23 @@ export function getSortType(jaqlSort) {
|
|
|
237
259
|
return 'sortNone';
|
|
238
260
|
}
|
|
239
261
|
}
|
|
240
|
-
const DATA_MODEL_MODULE_NAME = 'DM';
|
|
241
262
|
/**
|
|
242
263
|
* Creates an attribute or level attribute from the provided parameters
|
|
243
264
|
*
|
|
244
265
|
* @returns attribute or level attribute
|
|
245
266
|
* @internal
|
|
246
267
|
*/
|
|
247
|
-
export const createAttributeHelper = ({
|
|
248
|
-
|
|
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;
|
|
268
|
+
export const createAttributeHelper = ({ expression, dataType, granularity, format, sort, title, panel, dataSource, }) => {
|
|
269
|
+
const column = parseExpression(expression).column;
|
|
252
270
|
const sortEnum = convertSort(sort);
|
|
253
271
|
const isDataTypeDatetime = dataType === DataType.DATETIME;
|
|
254
272
|
if (isDataTypeDatetime) {
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
DimensionalLevelAttribute.getDefaultFormatForGranularity(granularity || DateLevels.Years), 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);
|
|
258
275
|
return levelAttribute;
|
|
259
276
|
}
|
|
260
277
|
const attributeType = !dataType || isNumber(dataType) ? MetadataTypes.NumericAttribute : MetadataTypes.TextAttribute;
|
|
261
|
-
const
|
|
262
|
-
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);
|
|
263
279
|
return attribute;
|
|
264
280
|
};
|
|
265
281
|
/**
|
|
@@ -268,12 +284,9 @@ export const createAttributeHelper = ({ dim, table, column, dataType, granularit
|
|
|
268
284
|
* @returns measure
|
|
269
285
|
* @internal
|
|
270
286
|
*/
|
|
271
|
-
export const createMeasureHelper = ({
|
|
272
|
-
const sortEnum = convertSort(sort);
|
|
287
|
+
export const createMeasureHelper = ({ expression, dataType, agg, granularity, format, sort, title, dataSource, }) => {
|
|
273
288
|
const attribute = createAttributeHelper({
|
|
274
|
-
|
|
275
|
-
table,
|
|
276
|
-
column,
|
|
289
|
+
expression,
|
|
277
290
|
dataType,
|
|
278
291
|
granularity,
|
|
279
292
|
format,
|
|
@@ -282,21 +295,30 @@ export const createMeasureHelper = ({ dim, table, column, dataType, agg, granula
|
|
|
282
295
|
dataSource,
|
|
283
296
|
});
|
|
284
297
|
const tranformedAgg = DimensionalBaseMeasure.aggregationFromJAQL(agg);
|
|
298
|
+
const column = parseExpression(expression).column;
|
|
285
299
|
const updatedTitle = title !== null && title !== void 0 ? title : `${tranformedAgg} ${column}`;
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
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
|
+
}
|
|
300
322
|
};
|
|
301
323
|
/**
|
|
302
324
|
* Creates a measure from the provided parameters
|
|
@@ -306,15 +328,13 @@ const getContextComposeCode = (context) => {
|
|
|
306
328
|
*/
|
|
307
329
|
export const createCalculatedMeasureHelper = (jaql) => {
|
|
308
330
|
var _a;
|
|
309
|
-
const sortEnum = convertSort(jaql.sort);
|
|
310
331
|
const context = mapValues((_a = jaql.context) !== null && _a !== void 0 ? _a : {}, (jaqlContextValue) => {
|
|
311
332
|
if (typeof jaqlContextValue === 'string') {
|
|
312
333
|
return jaqlContextValue;
|
|
313
334
|
}
|
|
314
335
|
return jaqlContextValue && createDimensionalElementFromJaql(jaqlContextValue);
|
|
315
336
|
});
|
|
316
|
-
|
|
317
|
-
return new DimensionalCalculatedMeasure(jaql.title, jaql.formula, context, undefined, undefined, sortEnum, composeCode);
|
|
337
|
+
return measureFactory.customFormula(jaql.title, jaql.formula, context);
|
|
318
338
|
};
|
|
319
339
|
/**
|
|
320
340
|
* Creates a dimensional element from a JAQL object.
|
|
@@ -337,9 +357,7 @@ export function createDimensionalElementFromJaql(jaql, datetimeFormat, panel) {
|
|
|
337
357
|
const hasAggregation = !!jaql.agg;
|
|
338
358
|
if (hasAggregation) {
|
|
339
359
|
return createMeasureHelper({
|
|
340
|
-
|
|
341
|
-
table: jaql.table,
|
|
342
|
-
column: jaql.column,
|
|
360
|
+
expression: jaql.dim,
|
|
343
361
|
dataType: jaql.datatype,
|
|
344
362
|
agg: jaql.agg || '',
|
|
345
363
|
granularity: getGranularityFromJaql(jaql),
|
|
@@ -350,9 +368,7 @@ export function createDimensionalElementFromJaql(jaql, datetimeFormat, panel) {
|
|
|
350
368
|
});
|
|
351
369
|
}
|
|
352
370
|
return createAttributeHelper({
|
|
353
|
-
|
|
354
|
-
table: jaql.table,
|
|
355
|
-
column: jaql.column,
|
|
371
|
+
expression: jaql.dim,
|
|
356
372
|
dataType: jaql.datatype,
|
|
357
373
|
granularity: getGranularityFromJaql(jaql),
|
|
358
374
|
format: datetimeFormat,
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"Sisense",
|
|
12
12
|
"Compose SDK"
|
|
13
13
|
],
|
|
14
|
-
"version": "
|
|
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": "^
|
|
31
|
-
"@sisense/sdk-rest-client": "^
|
|
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",
|
|
@@ -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
|
-
}
|