@halix/action-sdk 1.0.27 → 1.0.28
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/lib/cjs/data-aggregate.js +174 -4
- package/lib/cjs/index.js +3 -1
- package/lib/cjs/types/data-aggregate.d.ts +135 -7
- package/lib/cjs/types/data-aggregate.d.ts.map +1 -1
- package/lib/cjs/types/index.d.ts +1 -1
- package/lib/cjs/types/index.d.ts.map +1 -1
- package/lib/esm/data-aggregate.js +173 -4
- package/lib/esm/data-aggregate.js.map +1 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/index.mjs +2 -0
- package/lib/esm/types/data-aggregate.d.ts +135 -7
- package/lib/esm/types/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -20,6 +20,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
20
20
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.AggregationResponse = void 0;
|
|
23
24
|
exports.getAggregateData = getAggregateData;
|
|
24
25
|
exports.getAggregateDataAsObservable = getAggregateDataAsObservable;
|
|
25
26
|
/**
|
|
@@ -39,6 +40,164 @@ exports.getAggregateDataAsObservable = getAggregateDataAsObservable;
|
|
|
39
40
|
const axios_1 = __importDefault(require("axios"));
|
|
40
41
|
const rxjs_1 = require("rxjs");
|
|
41
42
|
const sdk_general_1 = require("./sdk-general");
|
|
43
|
+
/**
|
|
44
|
+
* AggregationResponse provides structured access to aggregated data results.
|
|
45
|
+
* Each row contains:
|
|
46
|
+
* - Group fields named after their groupField property
|
|
47
|
+
* - Aggregation fields named as {aggregationType}_{aggregationField} (e.g., "count_objKey", "sum_totalAmount")
|
|
48
|
+
*/
|
|
49
|
+
class AggregationResponse {
|
|
50
|
+
constructor(data) {
|
|
51
|
+
this.rawData = data || [];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get the raw data array.
|
|
55
|
+
* @returns Array of aggregation result rows
|
|
56
|
+
*/
|
|
57
|
+
getData() {
|
|
58
|
+
return this.rawData;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get the number of rows in the aggregated results.
|
|
62
|
+
*/
|
|
63
|
+
get length() {
|
|
64
|
+
return this.rawData.length;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get a specific row by index.
|
|
68
|
+
* @param index - The row index
|
|
69
|
+
* @returns The row at the specified index, or undefined if out of bounds
|
|
70
|
+
*/
|
|
71
|
+
getRow(index) {
|
|
72
|
+
return this.rawData[index];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get a group field value from a specific row.
|
|
76
|
+
* @param row - The aggregation row
|
|
77
|
+
* @param groupField - The name of the group field
|
|
78
|
+
* @returns The group field value
|
|
79
|
+
*/
|
|
80
|
+
getGroup(row, groupField) {
|
|
81
|
+
return row[groupField];
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Get an aggregation value from a specific row.
|
|
85
|
+
* Handles case-insensitive aggregation type matching.
|
|
86
|
+
* @param row - The aggregation row
|
|
87
|
+
* @param aggregationType - The aggregation type (case-insensitive: 'Count', 'Sum', 'Average', etc.)
|
|
88
|
+
* @param aggregationField - The field that was aggregated
|
|
89
|
+
* @returns The aggregation value
|
|
90
|
+
*/
|
|
91
|
+
getAggregation(row, aggregationType, aggregationField) {
|
|
92
|
+
const fieldName = this.getAggregationFieldName(aggregationType, aggregationField);
|
|
93
|
+
return row[fieldName];
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Build the aggregation field name from type and field.
|
|
97
|
+
* @param aggregationType - The aggregation type (case-insensitive)
|
|
98
|
+
* @param field - The field name
|
|
99
|
+
* @returns The aggregation field name in the format {type}_{field}
|
|
100
|
+
*/
|
|
101
|
+
getAggregationFieldName(aggregationType, field) {
|
|
102
|
+
return `${aggregationType.toLowerCase()}_${field}`;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Find rows matching specific group values.
|
|
106
|
+
* @param groupFilters - Object with group field names as keys and desired values
|
|
107
|
+
* @returns Array of matching rows
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* // Find all rows where status is "Draft"
|
|
111
|
+
* response.findByGroups({ status: 'Draft' })
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* // Find rows where status is "Draft" and homeLanguage is "English"
|
|
115
|
+
* response.findByGroups({ status: 'Draft', homeLanguage: 'English' })
|
|
116
|
+
*/
|
|
117
|
+
findByGroups(groupFilters) {
|
|
118
|
+
return this.rawData.filter(row => {
|
|
119
|
+
return Object.entries(groupFilters).every(([field, value]) => row[field] === value);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Get a specific aggregation value for rows matching group filters.
|
|
124
|
+
* @param groupFilters - Object with group field names as keys and desired values
|
|
125
|
+
* @param aggregationType - The aggregation type (case-insensitive)
|
|
126
|
+
* @param aggregationField - The field that was aggregated
|
|
127
|
+
* @returns The aggregation value from the first matching row, or undefined if no match
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* // Get count of objKey for Draft status and English homeLanguage
|
|
131
|
+
* response.getAggregationValue(
|
|
132
|
+
* { status: 'Draft', homeLanguage: 'English' },
|
|
133
|
+
* 'Count',
|
|
134
|
+
* 'objKey'
|
|
135
|
+
* )
|
|
136
|
+
*/
|
|
137
|
+
getAggregationValue(groupFilters, aggregationType, aggregationField) {
|
|
138
|
+
const row = this.findByGroups(groupFilters)[0];
|
|
139
|
+
return row ? this.getAggregation(row, aggregationType, aggregationField) : undefined;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Iterate over all rows with a callback function.
|
|
143
|
+
* @param callback - Function to execute for each row
|
|
144
|
+
*/
|
|
145
|
+
forEach(callback) {
|
|
146
|
+
this.rawData.forEach(callback);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Map aggregation rows to a new array.
|
|
150
|
+
* @param callback - Function to transform each row
|
|
151
|
+
* @returns New array of transformed values
|
|
152
|
+
*/
|
|
153
|
+
map(callback) {
|
|
154
|
+
return this.rawData.map(callback);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Filter aggregation rows.
|
|
158
|
+
* @param predicate - Function to test each row
|
|
159
|
+
* @returns New array of rows that pass the test
|
|
160
|
+
*/
|
|
161
|
+
filter(predicate) {
|
|
162
|
+
return this.rawData.filter(predicate);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Make the response iterable for use in for...of loops.
|
|
166
|
+
*/
|
|
167
|
+
[Symbol.iterator]() {
|
|
168
|
+
return this.rawData[Symbol.iterator]();
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Get all unique values for a specific group field across all rows.
|
|
172
|
+
* @param groupField - The group field name
|
|
173
|
+
* @returns Array of unique values (excluding null/undefined)
|
|
174
|
+
*/
|
|
175
|
+
getUniqueGroupValues(groupField) {
|
|
176
|
+
const values = new Set();
|
|
177
|
+
this.rawData.forEach(row => {
|
|
178
|
+
const value = row[groupField];
|
|
179
|
+
if (value !== null && value !== undefined) {
|
|
180
|
+
values.add(value);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
return Array.from(values);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Calculate the sum of a specific aggregation across all rows.
|
|
187
|
+
* Useful for totaling aggregated values.
|
|
188
|
+
* @param aggregationType - The aggregation type
|
|
189
|
+
* @param aggregationField - The field that was aggregated
|
|
190
|
+
* @returns Sum of the aggregation values, or 0 if no valid values
|
|
191
|
+
*/
|
|
192
|
+
sumAggregation(aggregationType, aggregationField) {
|
|
193
|
+
const fieldName = this.getAggregationFieldName(aggregationType, aggregationField);
|
|
194
|
+
return this.rawData.reduce((sum, row) => {
|
|
195
|
+
const value = row[fieldName];
|
|
196
|
+
return sum + (typeof value === 'number' ? value : 0);
|
|
197
|
+
}, 0);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
exports.AggregationResponse = AggregationResponse;
|
|
42
201
|
// ================================================================================
|
|
43
202
|
// DATA AGGREGATION FUNCTIONS
|
|
44
203
|
// ================================================================================
|
|
@@ -47,10 +206,10 @@ const sdk_general_1 = require("./sdk-general");
|
|
|
47
206
|
* Supports filtering, grouping with transforms, sorting, and multiple aggregations.
|
|
48
207
|
*
|
|
49
208
|
* @param request - Aggregation configuration including dataElementId, parent scope, groups, aggregations
|
|
50
|
-
* @returns Promise<AggregationResponse>
|
|
209
|
+
* @returns Promise<AggregationResponse> - A class instance providing structured access to aggregated data
|
|
51
210
|
*
|
|
52
211
|
* @example
|
|
53
|
-
* const
|
|
212
|
+
* const result = await getAggregateData({
|
|
54
213
|
* dataElementId: 'order',
|
|
55
214
|
* parentDataElementId: 'company',
|
|
56
215
|
* parentKey: orgProxyKey,
|
|
@@ -66,6 +225,14 @@ const sdk_general_1 = require("./sdk-general");
|
|
|
66
225
|
* aggregationField: 'totalAmount'
|
|
67
226
|
* }]
|
|
68
227
|
* });
|
|
228
|
+
*
|
|
229
|
+
* // Access aggregation values
|
|
230
|
+
* const count = result.getAggregationValue({ status: 'Draft' }, 'Count', 'objKey');
|
|
231
|
+
*
|
|
232
|
+
* // Iterate over results
|
|
233
|
+
* for (const row of result) {
|
|
234
|
+
* console.log(row.status, result.getAggregation(row, 'Sum', 'totalAmount'));
|
|
235
|
+
* }
|
|
69
236
|
*/
|
|
70
237
|
function getAggregateData(request) {
|
|
71
238
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -83,7 +250,7 @@ function getAggregateData(request) {
|
|
|
83
250
|
console.log("Sending POST request to " + url + " with token " + authToken);
|
|
84
251
|
// Make the API request
|
|
85
252
|
let response = yield axios_1.default.post(url, request, { headers });
|
|
86
|
-
return response.data;
|
|
253
|
+
return new AggregationResponse(response.data.data);
|
|
87
254
|
});
|
|
88
255
|
}
|
|
89
256
|
/**
|
|
@@ -94,7 +261,10 @@ function getAggregateData(request) {
|
|
|
94
261
|
* dataElementId: 'order',
|
|
95
262
|
* groups: [{ groupField: 'status', groupDirection: 'asc' }],
|
|
96
263
|
* aggregations: [{ aggregation: 'Count', aggregationField: 'objKey' }]
|
|
97
|
-
* }).subscribe(
|
|
264
|
+
* }).subscribe(result => {
|
|
265
|
+
* console.log('Total rows:', result.length);
|
|
266
|
+
* result.forEach(row => console.log(result.getAggregation(row, 'Count', 'objKey')));
|
|
267
|
+
* });
|
|
98
268
|
*/
|
|
99
269
|
function getAggregateDataAsObservable(request) {
|
|
100
270
|
return (0, rxjs_1.from)(getAggregateData(request));
|
package/lib/cjs/index.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// Unauthorized use outside the Halix platform is prohibited.
|
|
9
9
|
// Full license terms available in the LICENSE file.
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.debounceFn = exports.getValueFromObject = exports.compareValues = exports.sortObjectArray = exports.getAggregateDataAsObservable = exports.getAggregateData = exports.massDeleteAsObservable = exports.massDelete = exports.massEditAsObservable = exports.massEdit = exports.getListDataAsObservable = exports.getListData = exports.getPreferenceAsObservable = exports.getPreference = exports.sendMessageAsObservable = exports.sendMessage = exports.MessageMethod = exports.createOrUpdateResourceAsObservable = exports.createOrUpdateResource = exports.sendFileContentsAsObservable = exports.sendFileContents = exports.saveResourceAsObservable = exports.saveResource = exports.getOrCreateResourceAsObservable = exports.getOrCreateResource = exports.deleteRelatedObjectsAsObservable = exports.deleteRelatedObjects = exports.deleteRelatedObjectAsObservable = exports.deleteRelatedObject = exports.saveRelatedObjectAsObservable = exports.saveRelatedObject = exports.getRelatedObjectsAsObservable = exports.getRelatedObjects = exports.getObjectAsObservable = exports.getObject = exports.prepareErrorResponse = exports.prepareSuccessResponse = exports.initialize = exports.useBody = exports.params = exports.userContext = exports.actionSubject = exports.serviceAddress = exports.sandboxKey = exports.getAuthToken = void 0;
|
|
11
|
+
exports.debounceFn = exports.getValueFromObject = exports.compareValues = exports.sortObjectArray = exports.getAggregateDataAsObservable = exports.getAggregateData = exports.AggregationResponse = exports.massDeleteAsObservable = exports.massDelete = exports.massEditAsObservable = exports.massEdit = exports.getListDataAsObservable = exports.getListData = exports.getPreferenceAsObservable = exports.getPreference = exports.sendMessageAsObservable = exports.sendMessage = exports.MessageMethod = exports.createOrUpdateResourceAsObservable = exports.createOrUpdateResource = exports.sendFileContentsAsObservable = exports.sendFileContents = exports.saveResourceAsObservable = exports.saveResource = exports.getOrCreateResourceAsObservable = exports.getOrCreateResource = exports.deleteRelatedObjectsAsObservable = exports.deleteRelatedObjects = exports.deleteRelatedObjectAsObservable = exports.deleteRelatedObject = exports.saveRelatedObjectAsObservable = exports.saveRelatedObject = exports.getRelatedObjectsAsObservable = exports.getRelatedObjects = exports.getObjectAsObservable = exports.getObject = exports.prepareErrorResponse = exports.prepareSuccessResponse = exports.initialize = exports.useBody = exports.params = exports.userContext = exports.actionSubject = exports.serviceAddress = exports.sandboxKey = exports.getAuthToken = void 0;
|
|
12
12
|
/**
|
|
13
13
|
* @module @halix/action-sdk
|
|
14
14
|
* @description Halix Platform action SDK for developing NodeJS Lambda-based actions on the Halix
|
|
@@ -92,6 +92,8 @@ Object.defineProperty(exports, "massDeleteAsObservable", { enumerable: true, get
|
|
|
92
92
|
// DATA AGGREGATE FUNCTIONS
|
|
93
93
|
// ================================================================================
|
|
94
94
|
var data_aggregate_1 = require("./data-aggregate");
|
|
95
|
+
// Classes
|
|
96
|
+
Object.defineProperty(exports, "AggregationResponse", { enumerable: true, get: function () { return data_aggregate_1.AggregationResponse; } });
|
|
95
97
|
// Functions
|
|
96
98
|
Object.defineProperty(exports, "getAggregateData", { enumerable: true, get: function () { return data_aggregate_1.getAggregateData; } });
|
|
97
99
|
Object.defineProperty(exports, "getAggregateDataAsObservable", { enumerable: true, get: function () { return data_aggregate_1.getAggregateDataAsObservable; } });
|
|
@@ -94,21 +94,138 @@ export interface AggregationRequest {
|
|
|
94
94
|
aggregations: Aggregation[];
|
|
95
95
|
}
|
|
96
96
|
/**
|
|
97
|
-
*
|
|
97
|
+
* AggregationRow represents a single row in the aggregated results.
|
|
98
|
+
* Contains dynamic fields for groups and aggregations.
|
|
98
99
|
*/
|
|
99
|
-
export interface
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
export interface AggregationRow {
|
|
101
|
+
[key: string]: any;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* AggregationResponse provides structured access to aggregated data results.
|
|
105
|
+
* Each row contains:
|
|
106
|
+
* - Group fields named after their groupField property
|
|
107
|
+
* - Aggregation fields named as {aggregationType}_{aggregationField} (e.g., "count_objKey", "sum_totalAmount")
|
|
108
|
+
*/
|
|
109
|
+
export declare class AggregationResponse {
|
|
110
|
+
private rawData;
|
|
111
|
+
constructor(data: AggregationRow[]);
|
|
112
|
+
/**
|
|
113
|
+
* Get the raw data array.
|
|
114
|
+
* @returns Array of aggregation result rows
|
|
115
|
+
*/
|
|
116
|
+
getData(): AggregationRow[];
|
|
117
|
+
/**
|
|
118
|
+
* Get the number of rows in the aggregated results.
|
|
119
|
+
*/
|
|
120
|
+
get length(): number;
|
|
121
|
+
/**
|
|
122
|
+
* Get a specific row by index.
|
|
123
|
+
* @param index - The row index
|
|
124
|
+
* @returns The row at the specified index, or undefined if out of bounds
|
|
125
|
+
*/
|
|
126
|
+
getRow(index: number): AggregationRow | undefined;
|
|
127
|
+
/**
|
|
128
|
+
* Get a group field value from a specific row.
|
|
129
|
+
* @param row - The aggregation row
|
|
130
|
+
* @param groupField - The name of the group field
|
|
131
|
+
* @returns The group field value
|
|
132
|
+
*/
|
|
133
|
+
getGroup(row: AggregationRow, groupField: string): any;
|
|
134
|
+
/**
|
|
135
|
+
* Get an aggregation value from a specific row.
|
|
136
|
+
* Handles case-insensitive aggregation type matching.
|
|
137
|
+
* @param row - The aggregation row
|
|
138
|
+
* @param aggregationType - The aggregation type (case-insensitive: 'Count', 'Sum', 'Average', etc.)
|
|
139
|
+
* @param aggregationField - The field that was aggregated
|
|
140
|
+
* @returns The aggregation value
|
|
141
|
+
*/
|
|
142
|
+
getAggregation(row: AggregationRow, aggregationType: AggregationType | string, aggregationField: string): any;
|
|
143
|
+
/**
|
|
144
|
+
* Build the aggregation field name from type and field.
|
|
145
|
+
* @param aggregationType - The aggregation type (case-insensitive)
|
|
146
|
+
* @param field - The field name
|
|
147
|
+
* @returns The aggregation field name in the format {type}_{field}
|
|
148
|
+
*/
|
|
149
|
+
private getAggregationFieldName;
|
|
150
|
+
/**
|
|
151
|
+
* Find rows matching specific group values.
|
|
152
|
+
* @param groupFilters - Object with group field names as keys and desired values
|
|
153
|
+
* @returns Array of matching rows
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* // Find all rows where status is "Draft"
|
|
157
|
+
* response.findByGroups({ status: 'Draft' })
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* // Find rows where status is "Draft" and homeLanguage is "English"
|
|
161
|
+
* response.findByGroups({ status: 'Draft', homeLanguage: 'English' })
|
|
162
|
+
*/
|
|
163
|
+
findByGroups(groupFilters: {
|
|
164
|
+
[groupField: string]: any;
|
|
165
|
+
}): AggregationRow[];
|
|
166
|
+
/**
|
|
167
|
+
* Get a specific aggregation value for rows matching group filters.
|
|
168
|
+
* @param groupFilters - Object with group field names as keys and desired values
|
|
169
|
+
* @param aggregationType - The aggregation type (case-insensitive)
|
|
170
|
+
* @param aggregationField - The field that was aggregated
|
|
171
|
+
* @returns The aggregation value from the first matching row, or undefined if no match
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* // Get count of objKey for Draft status and English homeLanguage
|
|
175
|
+
* response.getAggregationValue(
|
|
176
|
+
* { status: 'Draft', homeLanguage: 'English' },
|
|
177
|
+
* 'Count',
|
|
178
|
+
* 'objKey'
|
|
179
|
+
* )
|
|
180
|
+
*/
|
|
181
|
+
getAggregationValue(groupFilters: {
|
|
182
|
+
[groupField: string]: any;
|
|
183
|
+
}, aggregationType: AggregationType | string, aggregationField: string): any;
|
|
184
|
+
/**
|
|
185
|
+
* Iterate over all rows with a callback function.
|
|
186
|
+
* @param callback - Function to execute for each row
|
|
187
|
+
*/
|
|
188
|
+
forEach(callback: (row: AggregationRow, index: number) => void): void;
|
|
189
|
+
/**
|
|
190
|
+
* Map aggregation rows to a new array.
|
|
191
|
+
* @param callback - Function to transform each row
|
|
192
|
+
* @returns New array of transformed values
|
|
193
|
+
*/
|
|
194
|
+
map<T>(callback: (row: AggregationRow, index: number) => T): T[];
|
|
195
|
+
/**
|
|
196
|
+
* Filter aggregation rows.
|
|
197
|
+
* @param predicate - Function to test each row
|
|
198
|
+
* @returns New array of rows that pass the test
|
|
199
|
+
*/
|
|
200
|
+
filter(predicate: (row: AggregationRow, index: number) => boolean): AggregationRow[];
|
|
201
|
+
/**
|
|
202
|
+
* Make the response iterable for use in for...of loops.
|
|
203
|
+
*/
|
|
204
|
+
[Symbol.iterator](): Iterator<AggregationRow>;
|
|
205
|
+
/**
|
|
206
|
+
* Get all unique values for a specific group field across all rows.
|
|
207
|
+
* @param groupField - The group field name
|
|
208
|
+
* @returns Array of unique values (excluding null/undefined)
|
|
209
|
+
*/
|
|
210
|
+
getUniqueGroupValues(groupField: string): any[];
|
|
211
|
+
/**
|
|
212
|
+
* Calculate the sum of a specific aggregation across all rows.
|
|
213
|
+
* Useful for totaling aggregated values.
|
|
214
|
+
* @param aggregationType - The aggregation type
|
|
215
|
+
* @param aggregationField - The field that was aggregated
|
|
216
|
+
* @returns Sum of the aggregation values, or 0 if no valid values
|
|
217
|
+
*/
|
|
218
|
+
sumAggregation(aggregationType: AggregationType | string, aggregationField: string): number;
|
|
102
219
|
}
|
|
103
220
|
/**
|
|
104
221
|
* Performs data aggregation operations (count, sum, average, etc.) on grouped data.
|
|
105
222
|
* Supports filtering, grouping with transforms, sorting, and multiple aggregations.
|
|
106
223
|
*
|
|
107
224
|
* @param request - Aggregation configuration including dataElementId, parent scope, groups, aggregations
|
|
108
|
-
* @returns Promise<AggregationResponse>
|
|
225
|
+
* @returns Promise<AggregationResponse> - A class instance providing structured access to aggregated data
|
|
109
226
|
*
|
|
110
227
|
* @example
|
|
111
|
-
* const
|
|
228
|
+
* const result = await getAggregateData({
|
|
112
229
|
* dataElementId: 'order',
|
|
113
230
|
* parentDataElementId: 'company',
|
|
114
231
|
* parentKey: orgProxyKey,
|
|
@@ -124,6 +241,14 @@ export interface AggregationResponse {
|
|
|
124
241
|
* aggregationField: 'totalAmount'
|
|
125
242
|
* }]
|
|
126
243
|
* });
|
|
244
|
+
*
|
|
245
|
+
* // Access aggregation values
|
|
246
|
+
* const count = result.getAggregationValue({ status: 'Draft' }, 'Count', 'objKey');
|
|
247
|
+
*
|
|
248
|
+
* // Iterate over results
|
|
249
|
+
* for (const row of result) {
|
|
250
|
+
* console.log(row.status, result.getAggregation(row, 'Sum', 'totalAmount'));
|
|
251
|
+
* }
|
|
127
252
|
*/
|
|
128
253
|
export declare function getAggregateData(request: AggregationRequest): Promise<AggregationResponse>;
|
|
129
254
|
/**
|
|
@@ -134,7 +259,10 @@ export declare function getAggregateData(request: AggregationRequest): Promise<A
|
|
|
134
259
|
* dataElementId: 'order',
|
|
135
260
|
* groups: [{ groupField: 'status', groupDirection: 'asc' }],
|
|
136
261
|
* aggregations: [{ aggregation: 'Count', aggregationField: 'objKey' }]
|
|
137
|
-
* }).subscribe(
|
|
262
|
+
* }).subscribe(result => {
|
|
263
|
+
* console.log('Total rows:', result.length);
|
|
264
|
+
* result.forEach(row => console.log(result.getAggregation(row, 'Count', 'objKey')));
|
|
265
|
+
* });
|
|
138
266
|
*/
|
|
139
267
|
export declare function getAggregateDataAsObservable(request: AggregationRequest): Observable<AggregationResponse>;
|
|
140
268
|
//# sourceMappingURL=data-aggregate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-aggregate.d.ts","sourceRoot":"","sources":["../../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.ts
CHANGED
|
@@ -10,6 +10,6 @@ export { MessageMethod, type MessageRequest, sendMessage, sendMessageAsObservabl
|
|
|
10
10
|
export { getPreference, getPreferenceAsObservable } from './preferences';
|
|
11
11
|
export { type FilterExpression } from './filter-expressions';
|
|
12
12
|
export { type SortField, type DataSortField, type BaseListDataRequest, type PagedListDataRequest, type ListDataResponse, type ListDataOptions, type ListDataSearchOptions, type MassEditValueType, type MassEditRequest, type MassDeleteRequest, type MassChangeResponse, getListData, getListDataAsObservable, massEdit, massEditAsObservable, massDelete, massDeleteAsObservable } from './lists';
|
|
13
|
-
export { type AggregationRequest, type
|
|
13
|
+
export { AggregationResponse, type AggregationRequest, type AggregationRow, type AggregationGroup, type AggregationSort, type Aggregation, type AggregationGroupTransform, type TransformType, type AggregationType, getAggregateData, getAggregateDataAsObservable } from './data-aggregate';
|
|
14
14
|
export { sortObjectArray, compareValues, getValueFromObject, debounceFn } from './utilities';
|
|
15
15
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AASA;;;;GAIG;AAMH,OAAO,EAEH,YAAY,EACZ,UAAU,EACV,cAAc,EACd,aAAa,EACb,WAAW,EACX,MAAM,EACN,OAAO,EAGP,UAAU,EAGV,KAAK,WAAW,EAChB,KAAK,iBAAiB,EAGtB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,0BAA0B,EAC/B,KAAK,0BAA0B,EAC/B,KAAK,wBAAwB,EAC7B,KAAK,6BAA6B,EAClC,KAAK,yBAAyB,EAC9B,KAAK,aAAa,EAGlB,sBAAsB,EACtB,oBAAoB,EACvB,MAAM,eAAe,CAAC;AAMvB,OAAO,EAEH,KAAK,WAAW,EAGhB,SAAS,EACT,qBAAqB,EACrB,iBAAiB,EACjB,6BAA6B,EAG7B,iBAAiB,EACj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BAAgB,EAChB,4BAA4B,EAC/B,MAAM,kBAAkB,CAAC;AAM1B,OAAO,EACH,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,UAAU,EACb,MAAM,aAAa,CAAC"}
|
|
@@ -23,6 +23,164 @@
|
|
|
23
23
|
import axios from 'axios';
|
|
24
24
|
import { from, lastValueFrom } from 'rxjs';
|
|
25
25
|
import { sandboxKey, serviceAddress, getAuthToken } from './sdk-general';
|
|
26
|
+
/**
|
|
27
|
+
* AggregationResponse provides structured access to aggregated data results.
|
|
28
|
+
* Each row contains:
|
|
29
|
+
* - Group fields named after their groupField property
|
|
30
|
+
* - Aggregation fields named as {aggregationType}_{aggregationField} (e.g., "count_objKey", "sum_totalAmount")
|
|
31
|
+
*/
|
|
32
|
+
export class AggregationResponse {
|
|
33
|
+
rawData;
|
|
34
|
+
constructor(data) {
|
|
35
|
+
this.rawData = data || [];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Get the raw data array.
|
|
39
|
+
* @returns Array of aggregation result rows
|
|
40
|
+
*/
|
|
41
|
+
getData() {
|
|
42
|
+
return this.rawData;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get the number of rows in the aggregated results.
|
|
46
|
+
*/
|
|
47
|
+
get length() {
|
|
48
|
+
return this.rawData.length;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Get a specific row by index.
|
|
52
|
+
* @param index - The row index
|
|
53
|
+
* @returns The row at the specified index, or undefined if out of bounds
|
|
54
|
+
*/
|
|
55
|
+
getRow(index) {
|
|
56
|
+
return this.rawData[index];
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Get a group field value from a specific row.
|
|
60
|
+
* @param row - The aggregation row
|
|
61
|
+
* @param groupField - The name of the group field
|
|
62
|
+
* @returns The group field value
|
|
63
|
+
*/
|
|
64
|
+
getGroup(row, groupField) {
|
|
65
|
+
return row[groupField];
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Get an aggregation value from a specific row.
|
|
69
|
+
* Handles case-insensitive aggregation type matching.
|
|
70
|
+
* @param row - The aggregation row
|
|
71
|
+
* @param aggregationType - The aggregation type (case-insensitive: 'Count', 'Sum', 'Average', etc.)
|
|
72
|
+
* @param aggregationField - The field that was aggregated
|
|
73
|
+
* @returns The aggregation value
|
|
74
|
+
*/
|
|
75
|
+
getAggregation(row, aggregationType, aggregationField) {
|
|
76
|
+
const fieldName = this.getAggregationFieldName(aggregationType, aggregationField);
|
|
77
|
+
return row[fieldName];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Build the aggregation field name from type and field.
|
|
81
|
+
* @param aggregationType - The aggregation type (case-insensitive)
|
|
82
|
+
* @param field - The field name
|
|
83
|
+
* @returns The aggregation field name in the format {type}_{field}
|
|
84
|
+
*/
|
|
85
|
+
getAggregationFieldName(aggregationType, field) {
|
|
86
|
+
return `${aggregationType.toLowerCase()}_${field}`;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Find rows matching specific group values.
|
|
90
|
+
* @param groupFilters - Object with group field names as keys and desired values
|
|
91
|
+
* @returns Array of matching rows
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* // Find all rows where status is "Draft"
|
|
95
|
+
* response.findByGroups({ status: 'Draft' })
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* // Find rows where status is "Draft" and homeLanguage is "English"
|
|
99
|
+
* response.findByGroups({ status: 'Draft', homeLanguage: 'English' })
|
|
100
|
+
*/
|
|
101
|
+
findByGroups(groupFilters) {
|
|
102
|
+
return this.rawData.filter(row => {
|
|
103
|
+
return Object.entries(groupFilters).every(([field, value]) => row[field] === value);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Get a specific aggregation value for rows matching group filters.
|
|
108
|
+
* @param groupFilters - Object with group field names as keys and desired values
|
|
109
|
+
* @param aggregationType - The aggregation type (case-insensitive)
|
|
110
|
+
* @param aggregationField - The field that was aggregated
|
|
111
|
+
* @returns The aggregation value from the first matching row, or undefined if no match
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* // Get count of objKey for Draft status and English homeLanguage
|
|
115
|
+
* response.getAggregationValue(
|
|
116
|
+
* { status: 'Draft', homeLanguage: 'English' },
|
|
117
|
+
* 'Count',
|
|
118
|
+
* 'objKey'
|
|
119
|
+
* )
|
|
120
|
+
*/
|
|
121
|
+
getAggregationValue(groupFilters, aggregationType, aggregationField) {
|
|
122
|
+
const row = this.findByGroups(groupFilters)[0];
|
|
123
|
+
return row ? this.getAggregation(row, aggregationType, aggregationField) : undefined;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Iterate over all rows with a callback function.
|
|
127
|
+
* @param callback - Function to execute for each row
|
|
128
|
+
*/
|
|
129
|
+
forEach(callback) {
|
|
130
|
+
this.rawData.forEach(callback);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Map aggregation rows to a new array.
|
|
134
|
+
* @param callback - Function to transform each row
|
|
135
|
+
* @returns New array of transformed values
|
|
136
|
+
*/
|
|
137
|
+
map(callback) {
|
|
138
|
+
return this.rawData.map(callback);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Filter aggregation rows.
|
|
142
|
+
* @param predicate - Function to test each row
|
|
143
|
+
* @returns New array of rows that pass the test
|
|
144
|
+
*/
|
|
145
|
+
filter(predicate) {
|
|
146
|
+
return this.rawData.filter(predicate);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Make the response iterable for use in for...of loops.
|
|
150
|
+
*/
|
|
151
|
+
[Symbol.iterator]() {
|
|
152
|
+
return this.rawData[Symbol.iterator]();
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Get all unique values for a specific group field across all rows.
|
|
156
|
+
* @param groupField - The group field name
|
|
157
|
+
* @returns Array of unique values (excluding null/undefined)
|
|
158
|
+
*/
|
|
159
|
+
getUniqueGroupValues(groupField) {
|
|
160
|
+
const values = new Set();
|
|
161
|
+
this.rawData.forEach(row => {
|
|
162
|
+
const value = row[groupField];
|
|
163
|
+
if (value !== null && value !== undefined) {
|
|
164
|
+
values.add(value);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
return Array.from(values);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Calculate the sum of a specific aggregation across all rows.
|
|
171
|
+
* Useful for totaling aggregated values.
|
|
172
|
+
* @param aggregationType - The aggregation type
|
|
173
|
+
* @param aggregationField - The field that was aggregated
|
|
174
|
+
* @returns Sum of the aggregation values, or 0 if no valid values
|
|
175
|
+
*/
|
|
176
|
+
sumAggregation(aggregationType, aggregationField) {
|
|
177
|
+
const fieldName = this.getAggregationFieldName(aggregationType, aggregationField);
|
|
178
|
+
return this.rawData.reduce((sum, row) => {
|
|
179
|
+
const value = row[fieldName];
|
|
180
|
+
return sum + (typeof value === 'number' ? value : 0);
|
|
181
|
+
}, 0);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
26
184
|
// ================================================================================
|
|
27
185
|
// DATA AGGREGATION FUNCTIONS
|
|
28
186
|
// ================================================================================
|
|
@@ -31,10 +189,10 @@ import { sandboxKey, serviceAddress, getAuthToken } from './sdk-general';
|
|
|
31
189
|
* Supports filtering, grouping with transforms, sorting, and multiple aggregations.
|
|
32
190
|
*
|
|
33
191
|
* @param request - Aggregation configuration including dataElementId, parent scope, groups, aggregations
|
|
34
|
-
* @returns Promise<AggregationResponse>
|
|
192
|
+
* @returns Promise<AggregationResponse> - A class instance providing structured access to aggregated data
|
|
35
193
|
*
|
|
36
194
|
* @example
|
|
37
|
-
* const
|
|
195
|
+
* const result = await getAggregateData({
|
|
38
196
|
* dataElementId: 'order',
|
|
39
197
|
* parentDataElementId: 'company',
|
|
40
198
|
* parentKey: orgProxyKey,
|
|
@@ -50,6 +208,14 @@ import { sandboxKey, serviceAddress, getAuthToken } from './sdk-general';
|
|
|
50
208
|
* aggregationField: 'totalAmount'
|
|
51
209
|
* }]
|
|
52
210
|
* });
|
|
211
|
+
*
|
|
212
|
+
* // Access aggregation values
|
|
213
|
+
* const count = result.getAggregationValue({ status: 'Draft' }, 'Count', 'objKey');
|
|
214
|
+
*
|
|
215
|
+
* // Iterate over results
|
|
216
|
+
* for (const row of result) {
|
|
217
|
+
* console.log(row.status, result.getAggregation(row, 'Sum', 'totalAmount'));
|
|
218
|
+
* }
|
|
53
219
|
*/
|
|
54
220
|
export async function getAggregateData(request) {
|
|
55
221
|
if (!getAuthToken) {
|
|
@@ -66,7 +232,7 @@ export async function getAggregateData(request) {
|
|
|
66
232
|
console.log("Sending POST request to " + url + " with token " + authToken);
|
|
67
233
|
// Make the API request
|
|
68
234
|
let response = await axios.post(url, request, { headers });
|
|
69
|
-
return response.data;
|
|
235
|
+
return new AggregationResponse(response.data.data);
|
|
70
236
|
}
|
|
71
237
|
/**
|
|
72
238
|
* Observable version of getAggregateData. See getAggregateData for details.
|
|
@@ -76,7 +242,10 @@ export async function getAggregateData(request) {
|
|
|
76
242
|
* dataElementId: 'order',
|
|
77
243
|
* groups: [{ groupField: 'status', groupDirection: 'asc' }],
|
|
78
244
|
* aggregations: [{ aggregation: 'Count', aggregationField: 'objKey' }]
|
|
79
|
-
* }).subscribe(
|
|
245
|
+
* }).subscribe(result => {
|
|
246
|
+
* console.log('Total rows:', result.length);
|
|
247
|
+
* result.forEach(row => console.log(result.getAggregation(row, 'Count', 'objKey')));
|
|
248
|
+
* });
|
|
80
249
|
*/
|
|
81
250
|
export function getAggregateDataAsObservable(request) {
|
|
82
251
|
return from(getAggregateData(request));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-aggregate.js","sourceRoot":"","sources":["../../src/data-aggregate.ts"],"names":[],"mappings":"AAAA,yBAAyB;AACzB,mCAAmC;AACnC,EAAE;AACF,oEAAoE;AACpE,0EAA0E;AAC1E,EAAE;AACF,6DAA6D;AAC7D,oDAAoD;AAEpD;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EACvB,MAAM,eAAe,CAAC;AAEvB,mFAAmF;AACnF,sBAAsB;AACtB,mFAAmF;AAEnF,OAAO;AAIH,iBAAiB;AACjB,SAAS,EACT,qBAAqB,EACrB,iBAAiB,EACjB,6BAA6B;AAE7B,YAAY;AACZ,iBAAiB,EACjB,6BAA6B;AAE7B,cAAc;AACd,mBAAmB,EACnB,+BAA+B,EAC/B,oBAAoB,EACpB,gCAAgC,EACnC,MAAM,aAAa,CAAC;AAErB,mFAAmF;AACnF,oBAAoB;AACpB,mFAAmF;AAEnF,OAAO;AAIH,oBAAoB;AACpB,mBAAmB,EACnB,+BAA+B,EAC/B,YAAY,EACZ,wBAAwB,EACxB,gBAAgB,EAChB,4BAA4B,EAC5B,sBAAsB,EACtB,kCAAkC,EACrC,MAAM,WAAW,CAAC;AAEnB,mFAAmF;AACnF,sBAAsB;AACtB,mFAAmF;AAEnF,OAAO;AACH,kBAAkB;AAClB,aAAa;AAKb,sBAAsB;AACtB,WAAW,EACX,uBAAuB,EAC1B,MAAM,aAAa,CAAC;AAErB,mFAAmF;AACnF,uBAAuB;AACvB,mFAAmF;AAEnF,OAAO;AACH,uBAAuB;AACvB,aAAa,EACb,yBAAyB,EAC5B,MAAM,eAAe,CAAC;AAUvB,mFAAmF;AACnF,sBAAsB;AACtB,mFAAmF;AAEnF,OAAO;AAcH,YAAY;AACZ,WAAW,EACX,uBAAuB,EACvB,QAAQ,EACR,oBAAoB,EACpB,UAAU,EACV,sBAAsB,EACzB,MAAM,SAAS,CAAC;AAEjB,mFAAmF;AACnF,2BAA2B;AAC3B,mFAAmF;AAEnF,OAAO;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,yBAAyB;AACzB,mCAAmC;AACnC,EAAE;AACF,oEAAoE;AACpE,0EAA0E;AAC1E,EAAE;AACF,6DAA6D;AAC7D,oDAAoD;AAEpD;;;;GAIG;AAEH,mFAAmF;AACnF,sDAAsD;AACtD,mF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4BAA4B,EAC/B,MAAM,kBAAkB,CAAC;AAE1B,mFAAmF;AACnF,oBAAoB;AACpB,mFAAmF;AAEnF,OAAO,EACH,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,UAAU,EACb,MAAM,aAAa,CAAC"}
|
package/lib/esm/index.mjs
CHANGED
|
@@ -61,6 +61,8 @@ getListData, getListDataAsObservable, massEdit, massEditAsObservable, massDelete
|
|
|
61
61
|
// DATA AGGREGATE FUNCTIONS
|
|
62
62
|
// ================================================================================
|
|
63
63
|
export {
|
|
64
|
+
// Classes
|
|
65
|
+
AggregationResponse,
|
|
64
66
|
// Functions
|
|
65
67
|
getAggregateData, getAggregateDataAsObservable } from './data-aggregate';
|
|
66
68
|
// ================================================================================
|
|
@@ -94,21 +94,138 @@ export interface AggregationRequest {
|
|
|
94
94
|
aggregations: Aggregation[];
|
|
95
95
|
}
|
|
96
96
|
/**
|
|
97
|
-
*
|
|
97
|
+
* AggregationRow represents a single row in the aggregated results.
|
|
98
|
+
* Contains dynamic fields for groups and aggregations.
|
|
98
99
|
*/
|
|
99
|
-
export interface
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
export interface AggregationRow {
|
|
101
|
+
[key: string]: any;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* AggregationResponse provides structured access to aggregated data results.
|
|
105
|
+
* Each row contains:
|
|
106
|
+
* - Group fields named after their groupField property
|
|
107
|
+
* - Aggregation fields named as {aggregationType}_{aggregationField} (e.g., "count_objKey", "sum_totalAmount")
|
|
108
|
+
*/
|
|
109
|
+
export declare class AggregationResponse {
|
|
110
|
+
private rawData;
|
|
111
|
+
constructor(data: AggregationRow[]);
|
|
112
|
+
/**
|
|
113
|
+
* Get the raw data array.
|
|
114
|
+
* @returns Array of aggregation result rows
|
|
115
|
+
*/
|
|
116
|
+
getData(): AggregationRow[];
|
|
117
|
+
/**
|
|
118
|
+
* Get the number of rows in the aggregated results.
|
|
119
|
+
*/
|
|
120
|
+
get length(): number;
|
|
121
|
+
/**
|
|
122
|
+
* Get a specific row by index.
|
|
123
|
+
* @param index - The row index
|
|
124
|
+
* @returns The row at the specified index, or undefined if out of bounds
|
|
125
|
+
*/
|
|
126
|
+
getRow(index: number): AggregationRow | undefined;
|
|
127
|
+
/**
|
|
128
|
+
* Get a group field value from a specific row.
|
|
129
|
+
* @param row - The aggregation row
|
|
130
|
+
* @param groupField - The name of the group field
|
|
131
|
+
* @returns The group field value
|
|
132
|
+
*/
|
|
133
|
+
getGroup(row: AggregationRow, groupField: string): any;
|
|
134
|
+
/**
|
|
135
|
+
* Get an aggregation value from a specific row.
|
|
136
|
+
* Handles case-insensitive aggregation type matching.
|
|
137
|
+
* @param row - The aggregation row
|
|
138
|
+
* @param aggregationType - The aggregation type (case-insensitive: 'Count', 'Sum', 'Average', etc.)
|
|
139
|
+
* @param aggregationField - The field that was aggregated
|
|
140
|
+
* @returns The aggregation value
|
|
141
|
+
*/
|
|
142
|
+
getAggregation(row: AggregationRow, aggregationType: AggregationType | string, aggregationField: string): any;
|
|
143
|
+
/**
|
|
144
|
+
* Build the aggregation field name from type and field.
|
|
145
|
+
* @param aggregationType - The aggregation type (case-insensitive)
|
|
146
|
+
* @param field - The field name
|
|
147
|
+
* @returns The aggregation field name in the format {type}_{field}
|
|
148
|
+
*/
|
|
149
|
+
private getAggregationFieldName;
|
|
150
|
+
/**
|
|
151
|
+
* Find rows matching specific group values.
|
|
152
|
+
* @param groupFilters - Object with group field names as keys and desired values
|
|
153
|
+
* @returns Array of matching rows
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* // Find all rows where status is "Draft"
|
|
157
|
+
* response.findByGroups({ status: 'Draft' })
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* // Find rows where status is "Draft" and homeLanguage is "English"
|
|
161
|
+
* response.findByGroups({ status: 'Draft', homeLanguage: 'English' })
|
|
162
|
+
*/
|
|
163
|
+
findByGroups(groupFilters: {
|
|
164
|
+
[groupField: string]: any;
|
|
165
|
+
}): AggregationRow[];
|
|
166
|
+
/**
|
|
167
|
+
* Get a specific aggregation value for rows matching group filters.
|
|
168
|
+
* @param groupFilters - Object with group field names as keys and desired values
|
|
169
|
+
* @param aggregationType - The aggregation type (case-insensitive)
|
|
170
|
+
* @param aggregationField - The field that was aggregated
|
|
171
|
+
* @returns The aggregation value from the first matching row, or undefined if no match
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* // Get count of objKey for Draft status and English homeLanguage
|
|
175
|
+
* response.getAggregationValue(
|
|
176
|
+
* { status: 'Draft', homeLanguage: 'English' },
|
|
177
|
+
* 'Count',
|
|
178
|
+
* 'objKey'
|
|
179
|
+
* )
|
|
180
|
+
*/
|
|
181
|
+
getAggregationValue(groupFilters: {
|
|
182
|
+
[groupField: string]: any;
|
|
183
|
+
}, aggregationType: AggregationType | string, aggregationField: string): any;
|
|
184
|
+
/**
|
|
185
|
+
* Iterate over all rows with a callback function.
|
|
186
|
+
* @param callback - Function to execute for each row
|
|
187
|
+
*/
|
|
188
|
+
forEach(callback: (row: AggregationRow, index: number) => void): void;
|
|
189
|
+
/**
|
|
190
|
+
* Map aggregation rows to a new array.
|
|
191
|
+
* @param callback - Function to transform each row
|
|
192
|
+
* @returns New array of transformed values
|
|
193
|
+
*/
|
|
194
|
+
map<T>(callback: (row: AggregationRow, index: number) => T): T[];
|
|
195
|
+
/**
|
|
196
|
+
* Filter aggregation rows.
|
|
197
|
+
* @param predicate - Function to test each row
|
|
198
|
+
* @returns New array of rows that pass the test
|
|
199
|
+
*/
|
|
200
|
+
filter(predicate: (row: AggregationRow, index: number) => boolean): AggregationRow[];
|
|
201
|
+
/**
|
|
202
|
+
* Make the response iterable for use in for...of loops.
|
|
203
|
+
*/
|
|
204
|
+
[Symbol.iterator](): Iterator<AggregationRow>;
|
|
205
|
+
/**
|
|
206
|
+
* Get all unique values for a specific group field across all rows.
|
|
207
|
+
* @param groupField - The group field name
|
|
208
|
+
* @returns Array of unique values (excluding null/undefined)
|
|
209
|
+
*/
|
|
210
|
+
getUniqueGroupValues(groupField: string): any[];
|
|
211
|
+
/**
|
|
212
|
+
* Calculate the sum of a specific aggregation across all rows.
|
|
213
|
+
* Useful for totaling aggregated values.
|
|
214
|
+
* @param aggregationType - The aggregation type
|
|
215
|
+
* @param aggregationField - The field that was aggregated
|
|
216
|
+
* @returns Sum of the aggregation values, or 0 if no valid values
|
|
217
|
+
*/
|
|
218
|
+
sumAggregation(aggregationType: AggregationType | string, aggregationField: string): number;
|
|
102
219
|
}
|
|
103
220
|
/**
|
|
104
221
|
* Performs data aggregation operations (count, sum, average, etc.) on grouped data.
|
|
105
222
|
* Supports filtering, grouping with transforms, sorting, and multiple aggregations.
|
|
106
223
|
*
|
|
107
224
|
* @param request - Aggregation configuration including dataElementId, parent scope, groups, aggregations
|
|
108
|
-
* @returns Promise<AggregationResponse>
|
|
225
|
+
* @returns Promise<AggregationResponse> - A class instance providing structured access to aggregated data
|
|
109
226
|
*
|
|
110
227
|
* @example
|
|
111
|
-
* const
|
|
228
|
+
* const result = await getAggregateData({
|
|
112
229
|
* dataElementId: 'order',
|
|
113
230
|
* parentDataElementId: 'company',
|
|
114
231
|
* parentKey: orgProxyKey,
|
|
@@ -124,6 +241,14 @@ export interface AggregationResponse {
|
|
|
124
241
|
* aggregationField: 'totalAmount'
|
|
125
242
|
* }]
|
|
126
243
|
* });
|
|
244
|
+
*
|
|
245
|
+
* // Access aggregation values
|
|
246
|
+
* const count = result.getAggregationValue({ status: 'Draft' }, 'Count', 'objKey');
|
|
247
|
+
*
|
|
248
|
+
* // Iterate over results
|
|
249
|
+
* for (const row of result) {
|
|
250
|
+
* console.log(row.status, result.getAggregation(row, 'Sum', 'totalAmount'));
|
|
251
|
+
* }
|
|
127
252
|
*/
|
|
128
253
|
export declare function getAggregateData(request: AggregationRequest): Promise<AggregationResponse>;
|
|
129
254
|
/**
|
|
@@ -134,6 +259,9 @@ export declare function getAggregateData(request: AggregationRequest): Promise<A
|
|
|
134
259
|
* dataElementId: 'order',
|
|
135
260
|
* groups: [{ groupField: 'status', groupDirection: 'asc' }],
|
|
136
261
|
* aggregations: [{ aggregation: 'Count', aggregationField: 'objKey' }]
|
|
137
|
-
* }).subscribe(
|
|
262
|
+
* }).subscribe(result => {
|
|
263
|
+
* console.log('Total rows:', result.length);
|
|
264
|
+
* result.forEach(row => console.log(result.getAggregation(row, 'Count', 'objKey')));
|
|
265
|
+
* });
|
|
138
266
|
*/
|
|
139
267
|
export declare function getAggregateDataAsObservable(request: AggregationRequest): Observable<AggregationResponse>;
|
package/lib/esm/types/index.d.ts
CHANGED
|
@@ -10,5 +10,5 @@ export { MessageMethod, type MessageRequest, sendMessage, sendMessageAsObservabl
|
|
|
10
10
|
export { getPreference, getPreferenceAsObservable } from './preferences';
|
|
11
11
|
export { type FilterExpression } from './filter-expressions';
|
|
12
12
|
export { type SortField, type DataSortField, type BaseListDataRequest, type PagedListDataRequest, type ListDataResponse, type ListDataOptions, type ListDataSearchOptions, type MassEditValueType, type MassEditRequest, type MassDeleteRequest, type MassChangeResponse, getListData, getListDataAsObservable, massEdit, massEditAsObservable, massDelete, massDeleteAsObservable } from './lists';
|
|
13
|
-
export { type AggregationRequest, type
|
|
13
|
+
export { AggregationResponse, type AggregationRequest, type AggregationRow, type AggregationGroup, type AggregationSort, type Aggregation, type AggregationGroupTransform, type TransformType, type AggregationType, getAggregateData, getAggregateDataAsObservable } from './data-aggregate';
|
|
14
14
|
export { sortObjectArray, compareValues, getValueFromObject, debounceFn } from './utilities';
|