axiodb 15.0.1 → 15.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/README.md +2 -2
  2. package/lib/Services/Aggregation/Aggregation.Operation.d.ts +5 -44
  3. package/lib/Services/Aggregation/Aggregation.Operation.js +54 -214
  4. package/lib/Services/Aggregation/Aggregation.Operation.js.map +1 -1
  5. package/lib/Services/Aggregation/OperatorRegistry.d.ts +11 -0
  6. package/lib/Services/Aggregation/OperatorRegistry.js +35 -0
  7. package/lib/Services/Aggregation/OperatorRegistry.js.map +1 -0
  8. package/lib/Services/Aggregation/operators/accumulatorOperators.d.ts +12 -0
  9. package/lib/Services/Aggregation/operators/accumulatorOperators.js +138 -0
  10. package/lib/Services/Aggregation/operators/accumulatorOperators.js.map +1 -0
  11. package/lib/Services/Aggregation/operators/expressionOperators.d.ts +3 -0
  12. package/lib/Services/Aggregation/operators/expressionOperators.js +587 -0
  13. package/lib/Services/Aggregation/operators/expressionOperators.js.map +1 -0
  14. package/lib/Services/Aggregation/operators/stageOperators.d.ts +38 -0
  15. package/lib/Services/Aggregation/operators/stageOperators.js +564 -0
  16. package/lib/Services/Aggregation/operators/stageOperators.js.map +1 -0
  17. package/lib/Services/Collection/collection.operation.d.ts +3 -1
  18. package/lib/Services/Collection/collection.operation.js +3 -2
  19. package/lib/Services/Collection/collection.operation.js.map +1 -1
  20. package/lib/Services/Database/database.operation.d.ts +8 -0
  21. package/lib/Services/Database/database.operation.js +72 -1
  22. package/lib/Services/Database/database.operation.js.map +1 -1
  23. package/lib/config/DB.d.ts +5 -1
  24. package/lib/config/DB.js +5 -1
  25. package/lib/config/DB.js.map +1 -1
  26. package/lib/config/Interfaces/Operation/aggregation.interface.d.ts +9 -0
  27. package/lib/config/Interfaces/Operation/aggregation.interface.js +4 -0
  28. package/lib/config/Interfaces/Operation/aggregation.interface.js.map +1 -0
  29. package/lib/server/public/AxioControl/.vite/manifest.json +1 -1
  30. package/lib/server/public/AxioControl/assets/{index-DkwtNvzk.js → index-BRccHygR.js} +31 -31
  31. package/lib/server/public/AxioControl/index.html +1 -1
  32. package/lib/server/public/AxioControl/sw.js +1 -1
  33. package/package.json +1 -1
package/README.md CHANGED
@@ -155,7 +155,7 @@ const db = new AxioDB({
155
155
  ### Querying
156
156
  - **Chainable Query API:** `.query()`, `.Sort()`, `.Limit()`, `.Skip()`, `.setCount()`, `.setProject()`, `.exec()` / `.findOne()`
157
157
  - **MongoDB-style Query Operators:** `$gt`, `$gte`, `$lt`, `$lte`, `$ne`, `$in`, `$nin`, `$exists`, `$regex`, `$or`, `$and`
158
- - **Aggregation Pipelines:** MongoDB-compatible (`$match`, `$group`, `$sort`, `$project`, `$limit`, `$skip`, `$unwind`, `$addFields`, ...)
158
+ - **Aggregation Pipelines:** 60+ MongoDB-compatible stages (`$match`, `$group`, `$sort`, `$project`, `$limit`, `$skip`, `$unwind`, `$addFields`, `$lookup`, `$facet`, `$bucket`, `$count`, `$sample`, ...) with full expression evaluator, cross-collection `$lookup` joins, and custom operator registration via `OperatorRegistry`
159
159
  - **Bulk Operations:** high-performance `insertMany`, `UpdateMany`, `deleteMany`
160
160
 
161
161
  ### Indexing
@@ -882,7 +882,7 @@ For vulnerability reporting, see [SECURITY.md](SECURITY.md).
882
882
  | **Built-in caching** | ❌ | ❌ | ❌ | ✅ InMemoryCache |
883
883
  | **Worker Threads** | ❌ | ❌ | ❌ | ✅ |
884
884
  | **ACID Transactions** | ❌ | ❌ | ✅ | ✅ |
885
- | **Aggregation Pipelines** | ❌ | Partial | ❌ | ✅ MongoDB-compatible |
885
+ | **Aggregation Pipelines** | ❌ | Partial | ❌ | ✅ 60+ stages, $lookup, custom operators |
886
886
  | **TypeScript support** | ✅ | Partial | ✅ | ✅ Full |
887
887
  | **Electron compatible** | ✅ | ✅ | ❌ (requires rebuild) | ✅ |
888
888
  | **Sweet spot** | <5K docs | <100K docs | 10M+ (relational) | 10K–500K docs |
@@ -1,52 +1,13 @@
1
1
  import { ErrorInterface, SuccessInterface } from "../../config/Interfaces/Helper/response.helper.interface";
2
- /**
3
- * Class that performs aggregation operations on data.
4
- *
5
- * This class allows for MongoDB-like aggregation pipeline operations on collection data.
6
- * It supports various stages including $match, $group, $sort, $project, $limit, $skip,
7
- * $unwind, and $addFields.
8
- *
9
- */
2
+ import { CollectionResolver } from "../../config/Interfaces/Operation/aggregation.interface";
10
3
  export default class Aggregation {
11
4
  private AllData;
12
5
  private readonly Pipeline;
13
- private path;
6
+ private readonly path;
14
7
  private readonly collectionName;
15
8
  private readonly ResponseHelper;
16
- constructor(collectionName: string, path: string, Pipeline: object[] | any);
17
- /**
18
- * Executes the aggregation pipeline on the data.
19
- *
20
- * This method processes the aggregation pipeline stages in sequence:
21
- * - $match: Filters documents based on specified conditions
22
- * - $group: Groups documents by specified fields and applies aggregation operations
23
- * - $sort: Sorts documents based on specified fields and order
24
- * - $project: Reshapes documents by including specified fields
25
- * - $limit: Limits the number of documents in the result
26
- * - $skip: Skips a specified number of documents
27
- * - $unwind: Deconstructs an array field from input documents
28
- * - $addFields: Adds new fields to documents
29
- *
30
- * The method first validates if the pipeline is an array, loads all buffer data,
31
- * and then processes each stage of the pipeline sequentially.
32
- *
33
- * @throws {Error} If the pipeline is not an array
34
- * @returns {Array<any>} The result of the aggregation pipeline
35
- */
9
+ private readonly collectionResolver?;
10
+ constructor(collectionName: string, path: string, Pipeline: object[] | any, collectionResolver?: CollectionResolver);
36
11
  exec(): Promise<SuccessInterface | ErrorInterface>;
37
- /**
38
- * Loads all buffer raw data from the specified directory.
39
- *
40
- * This method performs the following steps:
41
- * 1. Checks if the directory is locked.
42
- * 2. If the directory is not locked, it lists all files in the directory.
43
- * 3. Reads each file.
44
- * 4. Stores the data in the `AllData` array.
45
- * 5. If the directory is locked, it unlocks the directory, reads the files, and then locks the directory again.
46
- *
47
- * @returns {Promise<SuccessInterface | ErrorInterface>} A promise that resolves to a success or error response.
48
- *
49
- * @throws {Error} Throws an error if any operation fails.
50
- */
51
- private LoadAllBufferRawData;
12
+ private loadSourceData;
52
13
  }
@@ -12,253 +12,93 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
+ /* eslint-disable @typescript-eslint/no-explicit-any */
15
16
  const response_helper_1 = __importDefault(require("../../Helper/response.helper"));
16
17
  const DocumentLoader_helper_1 = __importDefault(require("../../Helper/DocumentLoader.helper"));
17
18
  const Console_helper_1 = __importDefault(require("../../Helper/Console.helper"));
18
19
  const ReadIndex_service_1 = require("../Index/ReadIndex.service");
19
- /**
20
- * Class that performs aggregation operations on data.
21
- *
22
- * This class allows for MongoDB-like aggregation pipeline operations on collection data.
23
- * It supports various stages including $match, $group, $sort, $project, $limit, $skip,
24
- * $unwind, and $addFields.
25
- *
26
- */
20
+ const OperatorRegistry_1 = require("./OperatorRegistry");
21
+ const stageOperators_1 = require("./operators/stageOperators");
27
22
  class Aggregation {
28
- constructor(collectionName, path, Pipeline) {
29
- // property to store the data
23
+ constructor(collectionName, path, Pipeline, collectionResolver) {
30
24
  this.AllData = [];
31
25
  this.collectionName = collectionName;
32
26
  this.path = path;
33
27
  this.AllData = [];
34
28
  this.Pipeline = Pipeline;
35
29
  this.ResponseHelper = new response_helper_1.default();
30
+ this.collectionResolver = collectionResolver;
36
31
  }
37
- /**
38
- * Executes the aggregation pipeline on the data.
39
- *
40
- * This method processes the aggregation pipeline stages in sequence:
41
- * - $match: Filters documents based on specified conditions
42
- * - $group: Groups documents by specified fields and applies aggregation operations
43
- * - $sort: Sorts documents based on specified fields and order
44
- * - $project: Reshapes documents by including specified fields
45
- * - $limit: Limits the number of documents in the result
46
- * - $skip: Skips a specified number of documents
47
- * - $unwind: Deconstructs an array field from input documents
48
- * - $addFields: Adds new fields to documents
49
- *
50
- * The method first validates if the pipeline is an array, loads all buffer data,
51
- * and then processes each stage of the pipeline sequentially.
52
- *
53
- * @throws {Error} If the pipeline is not an array
54
- * @returns {Array<any>} The result of the aggregation pipeline
55
- */
56
32
  exec() {
57
33
  return __awaiter(this, void 0, void 0, function* () {
58
34
  if (!Array.isArray(this.Pipeline)) {
59
35
  throw new Error("Pipeline must be an array of aggregation stages.");
60
36
  }
61
- if (!this.Pipeline[0] || !this.Pipeline[0].$match) {
62
- throw new Error("Pipeline must have a $match operator at top");
63
- }
64
- if (this.Pipeline.$match) {
65
- const fileNames = yield new ReadIndex_service_1.ReadIndex(this.path).getFileFromIndex(this.Pipeline.$match);
66
- if (fileNames.length > 0) {
67
- // Load File Names from Index
68
- yield this.LoadAllBufferRawData(fileNames);
69
- }
70
- else {
71
- // Load all buffer raw data from the specified directory
72
- yield this.LoadAllBufferRawData().then((response) => {
73
- var _a;
74
- if ("data" in response) {
75
- Console_helper_1.default.green(`${(_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.length} Documents Loaded for Aggregation`);
76
- }
77
- });
78
- }
79
- }
80
- else {
81
- // Load all buffer raw data from the specified directory
82
- yield this.LoadAllBufferRawData().then((response) => {
83
- var _a;
84
- if ("data" in response) {
85
- Console_helper_1.default.green(`${(_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.length} Documents Loaded for Aggregation`);
86
- }
87
- });
88
- }
37
+ yield this.loadSourceData();
89
38
  let result = [...this.AllData];
90
39
  for (const stage of this.Pipeline) {
91
- if (stage.$match) {
92
- result = result.filter((item) => {
93
- return Object.entries(stage.$match).every(([key, value]) => {
94
- var _a;
95
- const itemValue = (_a = item[key]) !== null && _a !== void 0 ? _a : ""; // Ensure item[key] exists
96
- if (typeof value === "string" ||
97
- typeof value === "number" ||
98
- typeof value === "boolean") {
99
- return itemValue === value;
100
- }
101
- if (typeof value === "object" && value !== null) {
102
- if (value instanceof RegExp) {
103
- return value.test(itemValue);
104
- }
105
- if ("$regex" in value) {
106
- const regexPattern = value.$regex;
107
- const regexOptions = "$options" in value ? value.$options : "";
108
- try {
109
- const regex = new RegExp(String(regexPattern), regexOptions);
110
- return regex.test(itemValue);
111
- }
112
- catch (error) {
113
- Console_helper_1.default.red(`Invalid regex: ${regexPattern} with options: ${regexOptions}`, error);
114
- return false;
115
- }
116
- }
117
- // Comparison operators
118
- if ("$gte" in value) {
119
- return itemValue >= value.$gte;
120
- }
121
- if ("$gt" in value) {
122
- return itemValue > value.$gt;
123
- }
124
- if ("$lte" in value) {
125
- return itemValue <= value.$lte;
126
- }
127
- if ("$lt" in value) {
128
- return itemValue < value.$lt;
129
- }
130
- if ("$ne" in value) {
131
- return itemValue !== value.$ne;
132
- }
133
- if ("$in" in value) {
134
- return Array.isArray(value.$in) && value.$in.includes(itemValue);
135
- }
136
- if ("$nin" in value) {
137
- return Array.isArray(value.$nin) && !value.$nin.includes(itemValue);
138
- }
139
- }
140
- return false;
141
- });
142
- });
143
- }
144
- if (stage.$group) {
145
- const groupedData = {};
146
- for (const item of result) {
147
- let groupKey;
148
- if (typeof stage.$group._id === "string") {
149
- groupKey = stage.$group._id.startsWith("$")
150
- ? item[stage.$group._id.substring(1)]
151
- : stage.$group._id;
152
- }
153
- else if (typeof stage.$group._id === "object") {
154
- groupKey = JSON.stringify(Object.entries(stage.$group._id).reduce((acc, [k, v]) => {
155
- const fieldPath = v.replace("$", "");
156
- acc[k] = item[fieldPath];
157
- return acc;
158
- }, {}));
159
- }
160
- else {
161
- groupKey = "null";
162
- }
163
- if (!groupedData[groupKey]) {
164
- groupedData[groupKey] = { _id: groupKey };
165
- }
166
- for (const [key, operation] of Object.entries(stage.$group)) {
167
- if (key === "_id")
168
- continue;
169
- if (operation.$avg !== undefined) {
170
- const operand = operation.$avg;
171
- const value = typeof operand === "string" ? item[operand.replace("$", "")] : operand;
172
- groupedData[groupKey][key] = groupedData[groupKey][key] || {
173
- sum: 0,
174
- count: 0,
175
- };
176
- groupedData[groupKey][key].sum += value;
177
- groupedData[groupKey][key].count += 1;
178
- }
179
- if (operation.$sum !== undefined) {
180
- const operand = operation.$sum;
181
- const value = typeof operand === "string" ? item[operand.replace("$", "")] : operand;
182
- groupedData[groupKey][key] = (groupedData[groupKey][key] || 0) + value;
183
- }
184
- }
185
- }
186
- result = Object.values(groupedData).map((group) => {
187
- for (const key in group) {
188
- if (group[key] && group[key].sum !== undefined) {
189
- group[key] = group[key].sum / group[key].count;
190
- }
191
- }
192
- return group;
193
- });
194
- }
195
- if (stage.$sort) {
196
- const [[key, order]] = Object.entries(stage.$sort);
197
- const numOrder = Number(order);
198
- result.sort((a, b) => {
199
- if (a[key] < b[key])
200
- return -numOrder;
201
- if (a[key] > b[key])
202
- return numOrder;
203
- return 0;
204
- });
40
+ if (!stage || typeof stage !== "object")
41
+ continue;
42
+ const opName = Object.keys(stage)[0];
43
+ if (!opName)
44
+ continue;
45
+ const opExpr = stage[opName];
46
+ if (opName === "$lookup") {
47
+ result = yield (0, stageOperators_1.executeLookup)(result, opExpr, this.collectionResolver);
48
+ continue;
205
49
  }
206
- if (stage.$project) {
207
- result = result.map((item) => {
208
- const projected = {};
209
- for (const key in stage.$project) {
210
- if (stage.$project[key] === 1) {
211
- projected[key] = item[key];
212
- }
213
- }
214
- return projected;
215
- });
50
+ if (opName === "$facet") {
51
+ result = [(0, stageOperators_1.executeFacet)(result, opExpr)];
52
+ continue;
216
53
  }
217
- if (stage.$limit) {
218
- result = result.slice(0, stage.$limit);
54
+ if (opName === "$bucket") {
55
+ result = (0, stageOperators_1.executeBucket)(result, opExpr);
56
+ continue;
219
57
  }
220
- if (stage.$skip) {
221
- result = result.slice(stage.$skip);
58
+ if (opName === "$bucketAuto") {
59
+ result = (0, stageOperators_1.executeBucketAuto)(result, opExpr);
60
+ continue;
222
61
  }
223
- if (stage.$unwind) {
224
- const field = stage.$unwind.replace("$", "");
225
- result = result.flatMap((item) => {
226
- return Array.isArray(item[field])
227
- ? item[field].map((value) => (Object.assign(Object.assign({}, item), { [field]: value })))
228
- : [item];
229
- });
62
+ const builtInOp = stageOperators_1.BUILT_IN_STAGE_OPERATORS[opName];
63
+ if (builtInOp) {
64
+ result = builtInOp(result, opExpr);
65
+ continue;
230
66
  }
231
- if (stage.$addFields) {
232
- result = result.map((item) => (Object.assign(Object.assign({}, item), stage.$addFields)));
67
+ const registered = OperatorRegistry_1.OperatorRegistry.getOperator(opName);
68
+ if (registered && registered.type === "stage") {
69
+ const customResult = registered.fn(result, opExpr, this.collectionResolver);
70
+ result = customResult instanceof Promise ? yield customResult : customResult;
71
+ continue;
233
72
  }
73
+ Console_helper_1.default.red(`Unknown aggregation stage operator: ${opName}`);
234
74
  }
235
75
  return this.ResponseHelper.Success(result);
236
76
  });
237
77
  }
238
- /**
239
- * Loads all buffer raw data from the specified directory.
240
- *
241
- * This method performs the following steps:
242
- * 1. Checks if the directory is locked.
243
- * 2. If the directory is not locked, it lists all files in the directory.
244
- * 3. Reads each file.
245
- * 4. Stores the data in the `AllData` array.
246
- * 5. If the directory is locked, it unlocks the directory, reads the files, and then locks the directory again.
247
- *
248
- * @returns {Promise<SuccessInterface | ErrorInterface>} A promise that resolves to a success or error response.
249
- *
250
- * @throws {Error} Throws an error if any operation fails.
251
- */
252
- LoadAllBufferRawData(documentIdDirectFile) {
78
+ loadSourceData() {
253
79
  return __awaiter(this, void 0, void 0, function* () {
254
- // Use shared DocumentLoader helper (DRY - consolidates duplicated code)
255
- const result = yield DocumentLoader_helper_1.default.loadDocuments(this.path, documentIdDirectFile, false // Don't include fileName for Aggregation
256
- );
257
- // Store result in AllData if successful
80
+ const matchExpr = (0, stageOperators_1.extractMatchFromPipeline)(this.Pipeline);
81
+ if (matchExpr) {
82
+ try {
83
+ const fileNames = yield new ReadIndex_service_1.ReadIndex(this.path).getFileFromIndex(matchExpr);
84
+ if (fileNames.length > 0) {
85
+ const result = yield DocumentLoader_helper_1.default.loadDocuments(this.path, fileNames, false);
86
+ if ("data" in result) {
87
+ this.AllData = result.data;
88
+ Console_helper_1.default.green(`${this.AllData.length} Documents Loaded for Aggregation (index-optimized)`);
89
+ return;
90
+ }
91
+ }
92
+ }
93
+ catch (_a) {
94
+ // Index miss - fall through to full scan
95
+ }
96
+ }
97
+ const result = yield DocumentLoader_helper_1.default.loadDocuments(this.path, undefined, false);
258
98
  if ("data" in result) {
259
99
  this.AllData = result.data;
100
+ Console_helper_1.default.green(`${this.AllData.length} Documents Loaded for Aggregation`);
260
101
  }
261
- return result;
262
102
  });
263
103
  }
264
104
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Aggregation.Operation.js","sourceRoot":"","sources":["../../../source/Services/Aggregation/Aggregation.Operation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,mFAA0D;AAK1D,+FAAgE;AAChE,iFAAkD;AAClD,kEAAuD;AAevD;;;;;;;GAOG;AACH;IAQE,YACE,cAAsB,EACtB,IAAY,EACZ,QAAwB;QAV1B,6BAA6B;QACrB,YAAO,GAAU,EAAE,CAAC;QAW1B,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAClB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,cAAc,GAAG,IAAI,yBAAc,EAAE,CAAC;IAC7C,CAAC;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACU,IAAI;;YACf,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAClC,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;YACtE,CAAC;YACD,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;gBAClD,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAA;YAChE,CAAC;YAED,IAAI,IAAI,CAAC,QAAQ,CAAC,MAA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IAAA,yCAAwB,EAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC1D,IAAI,SAAS,EAAE,CAAC;gBACd,IAAI,CAAC;oBACH,MAAM,SAAS,GAAG,MAAM,IAAI,6BAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;oBAC7E,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;wBACzB,MAAM,MAAM,GAAG,MAAM,+BAAc,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;wBAC/E,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;4BACrB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC;4BAC3B,wBAAO,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,qDAAqD,CAAC,CAAC;4BAC3F,OAAO;wBACT,CAAC;oBACH,CAAC;gBACH,CAAC;2BAAO,CAAC;oBACP,yCAAyC;gBAC3C,CAAC;YACH,CAAC;YAED,MAAM,MAAM,GAAG,MAAM,+BAAc,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;YAC/E,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;gBACrB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC;gBAC3B,wBAAO,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,mCAAmC,CAAC,CAAC;YAC3E,CAAC;QACH,CAAC;KAAA;CACF"}
@@ -0,0 +1,11 @@
1
+ import { StageOperatorFn, AccumulatorFn, ExpressionFn, RegisteredOperator } from "../../config/Interfaces/Operation/aggregation.interface";
2
+ export declare class OperatorRegistry {
3
+ private static operators;
4
+ static registerStageOperator(name: string, fn: StageOperatorFn): void;
5
+ static registerAccumulator(name: string, fn: AccumulatorFn): void;
6
+ static registerExpressionOperator(name: string, fn: ExpressionFn): void;
7
+ static getOperator(name: string): RegisteredOperator | undefined;
8
+ static getAllByType(type: "stage" | "accumulator" | "expression"): RegisteredOperator[];
9
+ static getRegisteredNames(): string[];
10
+ static clearAll(): void;
11
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OperatorRegistry = void 0;
4
+ class OperatorRegistry {
5
+ static registerStageOperator(name, fn) {
6
+ if (!name.startsWith("$"))
7
+ throw new Error(`Operator name must start with "$", got: "${name}"`);
8
+ OperatorRegistry.operators.set(name, { type: "stage", name, fn });
9
+ }
10
+ static registerAccumulator(name, fn) {
11
+ if (!name.startsWith("$"))
12
+ throw new Error(`Operator name must start with "$", got: "${name}"`);
13
+ OperatorRegistry.operators.set(name, { type: "accumulator", name, fn });
14
+ }
15
+ static registerExpressionOperator(name, fn) {
16
+ if (!name.startsWith("$"))
17
+ throw new Error(`Operator name must start with "$", got: "${name}"`);
18
+ OperatorRegistry.operators.set(name, { type: "expression", name, fn });
19
+ }
20
+ static getOperator(name) {
21
+ return OperatorRegistry.operators.get(name);
22
+ }
23
+ static getAllByType(type) {
24
+ return [...OperatorRegistry.operators.values()].filter(op => op.type === type);
25
+ }
26
+ static getRegisteredNames() {
27
+ return [...OperatorRegistry.operators.keys()];
28
+ }
29
+ static clearAll() {
30
+ OperatorRegistry.operators.clear();
31
+ }
32
+ }
33
+ exports.OperatorRegistry = OperatorRegistry;
34
+ OperatorRegistry.operators = new Map();
35
+ //# sourceMappingURL=OperatorRegistry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OperatorRegistry.js","sourceRoot":"","sources":["../../../source/Services/Aggregation/OperatorRegistry.ts"],"names":[],"mappings":";;;AAQA;IAGE,MAAM,CAAC,qBAAqB,CAAC,IAAY,EAAE,EAAmB;QAC5D,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,4CAA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AAgB,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IACrC,CAAC;CACF;;AAhCgB,0BAAS,GAAoC,IAAI,GAAG,EAAE,CAAC"}
@@ -0,0 +1,12 @@
1
+ export declare function accumulatorSum(groupDocs: any[], expr: any): number;
2
+ export declare function accumulatorAvg(groupDocs: any[], expr: any): number | null;
3
+ export declare function accumulatorMin(groupDocs: any[], expr: any): any;
4
+ export declare function accumulatorMax(groupDocs: any[], expr: any): any;
5
+ export declare function accumulatorFirst(groupDocs: any[], expr: any): any;
6
+ export declare function accumulatorLast(groupDocs: any[], expr: any): any;
7
+ export declare function accumulatorPush(groupDocs: any[], expr: any): any[];
8
+ export declare function accumulatorAddToSet(groupDocs: any[], expr: any): any[];
9
+ export declare function accumulatorStdDevPop(groupDocs: any[], expr: any): number | null;
10
+ export declare function accumulatorStdDevSamp(groupDocs: any[], expr: any): number | null;
11
+ export declare function accumulatorCount(groupDocs: any[]): number;
12
+ export declare const BUILT_IN_ACCUMULATORS: Record<string, (groupDocs: any[], expr: any) => any>;
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BUILT_IN_ACCUMULATORS = void 0;
4
+ exports.accumulatorSum = accumulatorSum;
5
+ exports.accumulatorAvg = accumulatorAvg;
6
+ exports.accumulatorMin = accumulatorMin;
7
+ exports.accumulatorMax = accumulatorMax;
8
+ exports.accumulatorFirst = accumulatorFirst;
9
+ exports.accumulatorLast = accumulatorLast;
10
+ exports.accumulatorPush = accumulatorPush;
11
+ exports.accumulatorAddToSet = accumulatorAddToSet;
12
+ exports.accumulatorStdDevPop = accumulatorStdDevPop;
13
+ exports.accumulatorStdDevSamp = accumulatorStdDevSamp;
14
+ exports.accumulatorCount = accumulatorCount;
15
+ /* eslint-disable @typescript-eslint/no-explicit-any */
16
+ const expressionOperators_1 = require("./expressionOperators");
17
+ function resolveOperand(doc, operand) {
18
+ if (typeof operand === "string" && operand.startsWith("$")) {
19
+ return doc[operand.substring(1)];
20
+ }
21
+ if (typeof operand === "object" && operand !== null) {
22
+ return (0, expressionOperators_1.evaluateExpression)(doc, operand);
23
+ }
24
+ return operand;
25
+ }
26
+ function accumulatorSum(groupDocs, expr) {
27
+ if (typeof expr === "number")
28
+ return groupDocs.length * expr;
29
+ return groupDocs.reduce((sum, doc) => {
30
+ const val = resolveOperand(doc, expr);
31
+ return sum + (typeof val === "number" ? val : 0);
32
+ }, 0);
33
+ }
34
+ function accumulatorAvg(groupDocs, expr) {
35
+ if (groupDocs.length === 0)
36
+ return null;
37
+ let sum = 0;
38
+ let count = 0;
39
+ for (const doc of groupDocs) {
40
+ const val = resolveOperand(doc, expr);
41
+ if (typeof val === "number" && !isNaN(val)) {
42
+ sum += val;
43
+ count++;
44
+ }
45
+ }
46
+ return count > 0 ? sum / count : null;
47
+ }
48
+ function accumulatorMin(groupDocs, expr) {
49
+ if (groupDocs.length === 0)
50
+ return null;
51
+ let min = undefined;
52
+ for (const doc of groupDocs) {
53
+ const val = resolveOperand(doc, expr);
54
+ if (val !== null && val !== undefined && (min === undefined || val < min)) {
55
+ min = val;
56
+ }
57
+ }
58
+ return min !== undefined ? min : null;
59
+ }
60
+ function accumulatorMax(groupDocs, expr) {
61
+ if (groupDocs.length === 0)
62
+ return null;
63
+ let max = undefined;
64
+ for (const doc of groupDocs) {
65
+ const val = resolveOperand(doc, expr);
66
+ if (val !== null && val !== undefined && (max === undefined || val > max)) {
67
+ max = val;
68
+ }
69
+ }
70
+ return max !== undefined ? max : null;
71
+ }
72
+ function accumulatorFirst(groupDocs, expr) {
73
+ if (groupDocs.length === 0)
74
+ return null;
75
+ return resolveOperand(groupDocs[0], expr);
76
+ }
77
+ function accumulatorLast(groupDocs, expr) {
78
+ if (groupDocs.length === 0)
79
+ return null;
80
+ return resolveOperand(groupDocs[groupDocs.length - 1], expr);
81
+ }
82
+ function accumulatorPush(groupDocs, expr) {
83
+ return groupDocs.map(doc => resolveOperand(doc, expr));
84
+ }
85
+ function accumulatorAddToSet(groupDocs, expr) {
86
+ const seen = new Set();
87
+ const result = [];
88
+ for (const doc of groupDocs) {
89
+ const val = resolveOperand(doc, expr);
90
+ const key = JSON.stringify(val);
91
+ if (!seen.has(key)) {
92
+ seen.add(key);
93
+ result.push(val);
94
+ }
95
+ }
96
+ return result;
97
+ }
98
+ function accumulatorStdDevPop(groupDocs, expr) {
99
+ if (groupDocs.length === 0)
100
+ return null;
101
+ const values = groupDocs
102
+ .map(doc => resolveOperand(doc, expr))
103
+ .filter(v => typeof v === "number" && !isNaN(v));
104
+ if (values.length === 0)
105
+ return null;
106
+ const mean = values.reduce((a, b) => a + b, 0) / values.length;
107
+ const variance = values.reduce((sum, v) => sum + Math.pow(v - mean, 2), 0) / values.length;
108
+ return Math.sqrt(variance);
109
+ }
110
+ function accumulatorStdDevSamp(groupDocs, expr) {
111
+ if (groupDocs.length <= 1)
112
+ return null;
113
+ const values = groupDocs
114
+ .map(doc => resolveOperand(doc, expr))
115
+ .filter(v => typeof v === "number" && !isNaN(v));
116
+ if (values.length <= 1)
117
+ return null;
118
+ const mean = values.reduce((a, b) => a + b, 0) / values.length;
119
+ const variance = values.reduce((sum, v) => sum + Math.pow(v - mean, 2), 0) / (values.length - 1);
120
+ return Math.sqrt(variance);
121
+ }
122
+ function accumulatorCount(groupDocs) {
123
+ return groupDocs.length;
124
+ }
125
+ exports.BUILT_IN_ACCUMULATORS = {
126
+ $sum: accumulatorSum,
127
+ $avg: accumulatorAvg,
128
+ $min: accumulatorMin,
129
+ $max: accumulatorMax,
130
+ $first: accumulatorFirst,
131
+ $last: accumulatorLast,
132
+ $push: accumulatorPush,
133
+ $addToSet: accumulatorAddToSet,
134
+ $stdDevPop: accumulatorStdDevPop,
135
+ $stdDevSamp: accumulatorStdDevSamp,
136
+ $count: accumulatorCount,
137
+ };
138
+ //# sourceMappingURL=accumulatorOperators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accumulatorOperators.js","sourceRoot":"","sources":["../../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C,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;IAC/D,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACjG,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC7B,CAAC;AAED,0BAAiC,SAAgB;IAC/C,OAAO,SAAS,CAAC,MAAM,CAAC;AAC1B,CAAC;AAEY,QAAA,qBAAqB,GAAyD;IACzF,IAAI,EAAE,cAAc;IACpB,IAAI,EAAE,cAAc;IACpB,IAAI,EAAE,cAAc;IACpB,IAAI,EAAE,cAAc;IACpB,MAAM,EAAE,gBAAgB;IACxB,KAAK,EAAE,eAAe;IACtB,KAAK,EAAE,eAAe;IACtB,SAAS,EAAE,mBAAmB;IAC9B,UAAU,EAAE,oBAAoB;IAChC,WAAW,EAAE,qBAAqB;IAClC,MAAM,EAAE,gBAAgB;CACzB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare function getNestedValue(obj: any, path: string): any;
2
+ export declare function setNestedValue(obj: any, path: string, value: any): void;
3
+ export declare function evaluateExpression(doc: any, expr: any): any;