@dcupl/common 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ import { Aggregation, AggregationDistinctValue, AggregationOptions, InverseIndexValuesMap, ListItem } from './types';
2
+ export declare const getAggregation: (options: AggregationOptions, relevantData: Map<string, ListItem>, indexMap: InverseIndexValuesMap, attribute: string) => Aggregation;
3
+ export declare const getDistinct: (options: AggregationOptions, data: Map<string, ListItem>, indexMap: InverseIndexValuesMap) => AggregationDistinctValue[];
@@ -0,0 +1,234 @@
1
+ "use strict";
2
+ var __values = (this && this.__values) || function(o) {
3
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4
+ if (m) return m.call(o);
5
+ if (o && typeof o.length === "number") return {
6
+ next: function () {
7
+ if (o && i >= o.length) o = void 0;
8
+ return { value: o && o[i++], done: !o };
9
+ }
10
+ };
11
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
12
+ };
13
+ var __read = (this && this.__read) || function (o, n) {
14
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
15
+ if (!m) return o;
16
+ var i = m.call(o), r, ar = [], e;
17
+ try {
18
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
19
+ }
20
+ catch (error) { e = { error: error }; }
21
+ finally {
22
+ try {
23
+ if (r && !r.done && (m = i["return"])) m.call(i);
24
+ }
25
+ finally { if (e) throw e.error; }
26
+ }
27
+ return ar;
28
+ };
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.getDistinct = exports.getAggregation = void 0;
31
+ var decimal_js_light_1 = require("decimal.js-light");
32
+ var getAggregation = function (options, relevantData, indexMap, attribute) {
33
+ if (!attribute) {
34
+ throw new Error('Attribute not found');
35
+ }
36
+ var aggregation = {
37
+ attribute: attribute,
38
+ types: options.types,
39
+ };
40
+ var numberAgg;
41
+ if (aggregation.types.includes('sum') || aggregation.types.includes('avg') || aggregation.types.includes('count')) {
42
+ numberAgg = getNumberAggregation(attribute, relevantData);
43
+ }
44
+ var minMax;
45
+ if (aggregation.types.includes('min') || aggregation.types.includes('max')) {
46
+ minMax = getMinMax(options.attribute, relevantData);
47
+ }
48
+ options.types.forEach(function (type) {
49
+ if (type === 'sum') {
50
+ aggregation.sum = numberAgg === null || numberAgg === void 0 ? void 0 : numberAgg.sum;
51
+ }
52
+ else if (type === 'avg') {
53
+ aggregation.avg = numberAgg === null || numberAgg === void 0 ? void 0 : numberAgg.average;
54
+ }
55
+ else if (type === 'count') {
56
+ aggregation.count = numberAgg === null || numberAgg === void 0 ? void 0 : numberAgg.count;
57
+ }
58
+ else if (type === 'min') {
59
+ aggregation.min = minMax && minMax[0];
60
+ }
61
+ else if (type === 'max') {
62
+ aggregation.max = minMax && minMax[1];
63
+ }
64
+ else if (type === 'distinct') {
65
+ aggregation.distinct = (0, exports.getDistinct)(options, relevantData, indexMap);
66
+ }
67
+ else if (type === 'group') {
68
+ aggregation.group = getGroups(options, relevantData);
69
+ }
70
+ });
71
+ return aggregation;
72
+ };
73
+ exports.getAggregation = getAggregation;
74
+ var getMinMax = function (attribute, data) {
75
+ var e_1, _a;
76
+ var values = Array.from(data.values())
77
+ .filter(Boolean)
78
+ .map(function (item) { return item[attribute]; });
79
+ if (!values) {
80
+ return undefined;
81
+ }
82
+ var minV = values[0];
83
+ var maxV = values[0];
84
+ try {
85
+ for (var values_1 = __values(values), values_1_1 = values_1.next(); !values_1_1.done; values_1_1 = values_1.next()) {
86
+ var a = values_1_1.value;
87
+ if (a < minV)
88
+ minV = a;
89
+ if (a > maxV)
90
+ maxV = a;
91
+ }
92
+ }
93
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
94
+ finally {
95
+ try {
96
+ if (values_1_1 && !values_1_1.done && (_a = values_1.return)) _a.call(values_1);
97
+ }
98
+ finally { if (e_1) throw e_1.error; }
99
+ }
100
+ return [minV, maxV];
101
+ };
102
+ var getGroups = function (options, data) {
103
+ var e_2, _a, e_3, _b;
104
+ var _c, _d, _e, _f;
105
+ var values = [];
106
+ (_d = (_c = options.groupOptions) === null || _c === void 0 ? void 0 : _c.groups) === null || _d === void 0 ? void 0 : _d.forEach(function (group) {
107
+ values.push({
108
+ option: group,
109
+ count: 0,
110
+ keys: [],
111
+ });
112
+ });
113
+ var notFound = {
114
+ option: { value: ['$dcupl_not_found'] },
115
+ count: 0,
116
+ keys: [],
117
+ };
118
+ try {
119
+ for (var _g = __values(data.values()), _h = _g.next(); !_h.done; _h = _g.next()) {
120
+ var item = _h.value;
121
+ var relevantEntry = item[options.attribute];
122
+ try {
123
+ for (var values_2 = (e_3 = void 0, __values(values)), values_2_1 = values_2.next(); !values_2_1.done; values_2_1 = values_2.next()) {
124
+ var group = values_2_1.value;
125
+ if ((typeof group.option.value !== 'undefined' && group.option.value.includes(relevantEntry)) ||
126
+ (typeof group.option.from !== 'undefined' &&
127
+ group.option.from < relevantEntry &&
128
+ typeof group.option.to !== 'undefined' &&
129
+ group.option.to > relevantEntry)) {
130
+ group.count++;
131
+ group.keys.push(item.key);
132
+ }
133
+ else {
134
+ if ((_e = options === null || options === void 0 ? void 0 : options.groupOptions) === null || _e === void 0 ? void 0 : _e.calculateNotFound) {
135
+ notFound.count++;
136
+ notFound.keys.push(item.key);
137
+ }
138
+ }
139
+ }
140
+ }
141
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
142
+ finally {
143
+ try {
144
+ if (values_2_1 && !values_2_1.done && (_b = values_2.return)) _b.call(values_2);
145
+ }
146
+ finally { if (e_3) throw e_3.error; }
147
+ }
148
+ }
149
+ }
150
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
151
+ finally {
152
+ try {
153
+ if (_h && !_h.done && (_a = _g.return)) _a.call(_g);
154
+ }
155
+ finally { if (e_2) throw e_2.error; }
156
+ }
157
+ if ((_f = options === null || options === void 0 ? void 0 : options.groupOptions) === null || _f === void 0 ? void 0 : _f.calculateNotFound) {
158
+ values.push(notFound);
159
+ }
160
+ return values;
161
+ };
162
+ var getNumberAggregation = function (attribute, data) {
163
+ var e_4, _a;
164
+ var aggSum = new decimal_js_light_1.Decimal(0);
165
+ try {
166
+ for (var _b = __values(data.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
167
+ var item = _c.value;
168
+ if (!item)
169
+ continue;
170
+ var value = item[attribute];
171
+ if (Array.isArray(value)) {
172
+ value.forEach(function (val) {
173
+ if (typeof val === 'number') {
174
+ aggSum = aggSum.add(val);
175
+ }
176
+ });
177
+ }
178
+ else {
179
+ if (typeof value === 'number') {
180
+ aggSum = aggSum.add(value);
181
+ }
182
+ }
183
+ }
184
+ }
185
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
186
+ finally {
187
+ try {
188
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
189
+ }
190
+ finally { if (e_4) throw e_4.error; }
191
+ }
192
+ var agg = {
193
+ average: aggSum.dividedBy(data.size).toNumber(),
194
+ count: data.size,
195
+ sum: aggSum.toNumber(),
196
+ };
197
+ return agg;
198
+ };
199
+ var getDistinct = function (options, data, indexMap) {
200
+ var e_5, _a;
201
+ var _b, _c;
202
+ var values = [];
203
+ try {
204
+ for (var indexMap_1 = __values(indexMap), indexMap_1_1 = indexMap_1.next(); !indexMap_1_1.done; indexMap_1_1 = indexMap_1.next()) {
205
+ var _d = __read(indexMap_1_1.value, 2), attributeValue = _d[0], itemKeys = _d[1];
206
+ if (options.excludeUndefineds && attributeValue === undefined) {
207
+ continue;
208
+ }
209
+ if (itemKeys.find(function (key) { return data.has(key); })) {
210
+ var value = {
211
+ value: attributeValue,
212
+ count: itemKeys.length,
213
+ };
214
+ if (!((_b = options.distinctOptions) === null || _b === void 0 ? void 0 : _b.skipKeys)) {
215
+ value.keys = itemKeys;
216
+ }
217
+ values.push(value);
218
+ if (((_c = options.distinctOptions) === null || _c === void 0 ? void 0 : _c.limit) && values.length >= options.distinctOptions.limit) {
219
+ break;
220
+ }
221
+ }
222
+ }
223
+ }
224
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
225
+ finally {
226
+ try {
227
+ if (indexMap_1_1 && !indexMap_1_1.done && (_a = indexMap_1.return)) _a.call(indexMap_1);
228
+ }
229
+ finally { if (e_5) throw e_5.error; }
230
+ }
231
+ return values;
232
+ };
233
+ exports.getDistinct = getDistinct;
234
+ //# sourceMappingURL=getAggregation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getAggregation.js","sourceRoot":"","sources":["../../src/getAggregation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,qDAA2C;AAEpC,IAAM,cAAc,GAAG,UAC5B,OAA2B,EAC3B,YAAmC,EACnC,QAA+B,EAC/B,SAAiB;IAEjB,IAAI,CAAC,SAAS,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;KACxC;IAED,IAAM,WAAW,GAAgB;QAC/B,SAAS,EAAE,SAAS;QACpB,KAAK,EAAE,OAAO,CAAC,KAAK;KACrB,CAAC;IAEF,IAAI,SAA6C,CAAC;IAClD,IAAI,WAAW,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,WAAW,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,WAAW,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;QACjH,SAAS,GAAG,oBAAoB,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;KAC3D;IAED,IAAI,MAAyB,CAAC;IAE9B,IAAI,WAAW,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,WAAW,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;QAC1E,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;KACrD;IAED,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,UAAC,IAAI;QACzB,IAAI,IAAI,KAAK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OAAO,CAAC,eAAe,0CAAE,KAAK,KAAI,MAAM,CAAC,MAAM,IAAI,OAAO,CAAC,eAAe,CAAC,KAAK,EAAE;oBACpF,MAAM;iBACP;aACF;SACF;;;;;;;;;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AA7BW,QAAA,WAAW,eA6BtB"}
@@ -1,9 +1,12 @@
1
- export * from './queryData';
1
+ export * from './changeDetection';
2
2
  export * from './computeSuggestions';
3
- export * from './helper';
3
+ export * from './getAggregation';
4
4
  export * from './getFacets';
5
- export * from './types';
6
- export * from './changeDetection';
5
+ export * from './helper';
6
+ export * from './indices.controller';
7
7
  export * from './performance';
8
+ export * from './pivot';
8
9
  export * from './query-builder';
9
10
  export * from './query.helper';
11
+ export * from './queryData';
12
+ export * from './types';
@@ -14,13 +14,16 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./queryData"), exports);
17
+ __exportStar(require("./changeDetection"), exports);
18
18
  __exportStar(require("./computeSuggestions"), exports);
19
- __exportStar(require("./helper"), exports);
19
+ __exportStar(require("./getAggregation"), exports);
20
20
  __exportStar(require("./getFacets"), exports);
21
- __exportStar(require("./types"), exports);
22
- __exportStar(require("./changeDetection"), exports);
21
+ __exportStar(require("./helper"), exports);
22
+ __exportStar(require("./indices.controller"), exports);
23
23
  __exportStar(require("./performance"), exports);
24
+ __exportStar(require("./pivot"), exports);
24
25
  __exportStar(require("./query-builder"), exports);
25
26
  __exportStar(require("./query.helper"), exports);
27
+ __exportStar(require("./queryData"), exports);
28
+ __exportStar(require("./types"), exports);
26
29
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,uDAAqC;AACrC,2CAAyB;AACzB,8CAA4B;AAC5B,0CAAwB;AACxB,oDAAkC;AAClC,gDAA8B;AAC9B,kDAAgC;AAChC,iDAA+B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,uDAAqC;AACrC,mDAAiC;AACjC,8CAA4B;AAC5B,2CAAyB;AACzB,uDAAqC;AACrC,gDAA8B;AAC9B,0CAAwB;AACxB,kDAAgC;AAChC,iDAA+B;AAC/B,8CAA4B;AAC5B,0CAAwB"}
@@ -0,0 +1,13 @@
1
+ import { InverseIndexValuesMap, InverseIndexDataValuesMap, ListItem } from './types';
2
+ export declare class IndicesController {
3
+ private indexMap;
4
+ private dataMap;
5
+ constructor();
6
+ reset(attributeKey?: string): void;
7
+ fillDataMap(attributeKey: string, attributeValue: Array<string | undefined | ListItem>): void;
8
+ fillInverseIndex(attributeKey: string, originKey: string, foreignKeys: Array<string | undefined | ListItem>): void;
9
+ getIndex(attributeKey: string, context?: any): InverseIndexValuesMap | undefined;
10
+ getData(attributeKey: string, context?: any): InverseIndexDataValuesMap | undefined;
11
+ getOrCreateIndex(attributeKey: string, relevantData: Map<string, ListItem>, context?: any): InverseIndexValuesMap;
12
+ getIndexName(attributeKey: string, context?: any): string;
13
+ }
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+ var __values = (this && this.__values) || function(o) {
3
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4
+ if (m) return m.call(o);
5
+ if (o && typeof o.length === "number") return {
6
+ next: function () {
7
+ if (o && i >= o.length) o = void 0;
8
+ return { value: o && o[i++], done: !o };
9
+ }
10
+ };
11
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.IndicesController = void 0;
18
+ var object_hash_1 = __importDefault(require("object-hash"));
19
+ var IndicesController = /** @class */ (function () {
20
+ function IndicesController() {
21
+ this.indexMap = new Map();
22
+ // Possible performance gain*
23
+ this.dataMap = new Map();
24
+ }
25
+ IndicesController.prototype.reset = function (attributeKey) {
26
+ if (attributeKey) {
27
+ this.indexMap.delete(attributeKey);
28
+ this.dataMap.delete(attributeKey);
29
+ }
30
+ else {
31
+ this.indexMap.clear();
32
+ this.dataMap.clear();
33
+ }
34
+ };
35
+ IndicesController.prototype.fillDataMap = function (attributeKey, attributeValue) {
36
+ var e_1, _a, e_2, _b;
37
+ var _c;
38
+ var valueMap = this.dataMap.get(attributeKey);
39
+ if (!valueMap) {
40
+ valueMap = new Map();
41
+ this.dataMap.set(attributeKey, valueMap);
42
+ }
43
+ try {
44
+ for (var attributeValue_1 = __values(attributeValue), attributeValue_1_1 = attributeValue_1.next(); !attributeValue_1_1.done; attributeValue_1_1 = attributeValue_1.next()) {
45
+ var value = attributeValue_1_1.value;
46
+ var keyAsString = void 0;
47
+ if (typeof value === 'object' && value && value.key) {
48
+ keyAsString = value.key;
49
+ }
50
+ else if (Array.isArray(value)) {
51
+ try {
52
+ for (var value_1 = (e_2 = void 0, __values(value)), value_1_1 = value_1.next(); !value_1_1.done; value_1_1 = value_1.next()) {
53
+ var item = value_1_1.value;
54
+ this.fillDataMap(attributeKey, [item]);
55
+ }
56
+ }
57
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
58
+ finally {
59
+ try {
60
+ if (value_1_1 && !value_1_1.done && (_b = value_1.return)) _b.call(value_1);
61
+ }
62
+ finally { if (e_2) throw e_2.error; }
63
+ }
64
+ return;
65
+ }
66
+ else {
67
+ keyAsString = value;
68
+ }
69
+ var listItem = valueMap.get(keyAsString);
70
+ if (!listItem) {
71
+ listItem = { key: keyAsString };
72
+ (_c = this.dataMap.get(attributeKey)) === null || _c === void 0 ? void 0 : _c.set(keyAsString, listItem);
73
+ }
74
+ }
75
+ }
76
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
77
+ finally {
78
+ try {
79
+ if (attributeValue_1_1 && !attributeValue_1_1.done && (_a = attributeValue_1.return)) _a.call(attributeValue_1);
80
+ }
81
+ finally { if (e_1) throw e_1.error; }
82
+ }
83
+ };
84
+ IndicesController.prototype.fillInverseIndex = function (attributeKey, originKey, foreignKeys) {
85
+ var e_3, _a, e_4, _b;
86
+ if (!attributeKey || !originKey || !foreignKeys || !Array.isArray(foreignKeys)) {
87
+ return;
88
+ }
89
+ var valueMap = this.indexMap.get(attributeKey) || new Map();
90
+ try {
91
+ for (var foreignKeys_1 = __values(foreignKeys), foreignKeys_1_1 = foreignKeys_1.next(); !foreignKeys_1_1.done; foreignKeys_1_1 = foreignKeys_1.next()) {
92
+ var value = foreignKeys_1_1.value;
93
+ var keyAsString = void 0;
94
+ if (typeof value === 'object' && value && value.key) {
95
+ keyAsString = value.key;
96
+ }
97
+ else if (Array.isArray(value)) {
98
+ try {
99
+ // keyAsString = JSON.stringify(value);
100
+ for (var value_2 = (e_4 = void 0, __values(value)), value_2_1 = value_2.next(); !value_2_1.done; value_2_1 = value_2.next()) {
101
+ var item = value_2_1.value;
102
+ this.fillInverseIndex(attributeKey, originKey, [item]);
103
+ }
104
+ }
105
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
106
+ finally {
107
+ try {
108
+ if (value_2_1 && !value_2_1.done && (_b = value_2.return)) _b.call(value_2);
109
+ }
110
+ finally { if (e_4) throw e_4.error; }
111
+ }
112
+ return;
113
+ }
114
+ else {
115
+ keyAsString = value;
116
+ }
117
+ var valueArray = valueMap.get(keyAsString) || [];
118
+ valueArray.push(originKey);
119
+ valueMap.set(keyAsString, valueArray);
120
+ }
121
+ }
122
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
123
+ finally {
124
+ try {
125
+ if (foreignKeys_1_1 && !foreignKeys_1_1.done && (_a = foreignKeys_1.return)) _a.call(foreignKeys_1);
126
+ }
127
+ finally { if (e_3) throw e_3.error; }
128
+ }
129
+ this.indexMap.set(attributeKey, valueMap);
130
+ };
131
+ IndicesController.prototype.getIndex = function (attributeKey, context) {
132
+ var indexName = this.getIndexName(attributeKey, context);
133
+ return this.indexMap.get(indexName);
134
+ };
135
+ IndicesController.prototype.getData = function (attributeKey, context) {
136
+ var indexName = this.getIndexName(attributeKey, context);
137
+ return this.dataMap.get(indexName);
138
+ };
139
+ IndicesController.prototype.getOrCreateIndex = function (attributeKey, relevantData, context) {
140
+ var _this = this;
141
+ var indexName = this.getIndexName(attributeKey, context);
142
+ var index = this.getIndex(indexName);
143
+ if (!index) {
144
+ this.reset(indexName);
145
+ relevantData.forEach(function (entry) {
146
+ var attributeValue = entry[attributeKey];
147
+ _this.fillInverseIndex(indexName, entry.key, [attributeValue]);
148
+ _this.fillDataMap(indexName, [attributeValue]);
149
+ });
150
+ index = this.getIndex(indexName);
151
+ }
152
+ return index;
153
+ };
154
+ IndicesController.prototype.getIndexName = function (attributeKey, context) {
155
+ return context ? attributeKey + '_' + (0, object_hash_1.default)(context) : attributeKey;
156
+ };
157
+ return IndicesController;
158
+ }());
159
+ exports.IndicesController = IndicesController;
160
+ //# sourceMappingURL=indices.controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"indices.controller.js","sourceRoot":"","sources":["../../src/indices.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,4DAAqC;AASrC;IAKE;QAJQ,aAAQ,GAA6B,IAAI,GAAG,EAAE,CAAC;QACvD,6BAA6B;QACrB,YAAO,GAAwB,IAAI,GAAG,EAAE,CAAC;IAElC,CAAC;IAET,iCAAK,GAAZ,UAAa,YAAqB;QAChC,IAAI,YAAY,EAAE;YAChB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;YACnC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;SACnC;aAAM;YACL,IAAI,CAAC,QAAQ,CAAC,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AAD,CAAC,AAlHD,IAkHC;AAlHY,8CAAiB"}
@@ -0,0 +1,25 @@
1
+ import { ListItem, Aggregation, AggregationOptions } from './types';
2
+ type PivotRowOption = {
3
+ attribute: string;
4
+ };
5
+ type PivotColumnOption = {
6
+ attribute: string;
7
+ };
8
+ type PivotValueOption = AggregationOptions;
9
+ export type PivotOptions = {
10
+ rows: PivotRowOption[];
11
+ columns: PivotColumnOption[];
12
+ values: PivotValueOption[];
13
+ options?: {
14
+ includePaths?: boolean;
15
+ };
16
+ };
17
+ type PivotResponseItem = {
18
+ key: string;
19
+ values?: Aggregation[];
20
+ columns?: Omit<PivotResponseItem, 'rows'>[];
21
+ rows?: PivotResponseItem[];
22
+ };
23
+ export type PivotResponse = PivotResponseItem;
24
+ export declare function pivot<ListType extends ListItem = ListItem>(relevantData: Map<string, ListType>, options: PivotOptions, response?: PivotResponse, paths?: any, parentPath?: string): PivotResponse;
25
+ export {};