tsledge 0.1.0 → 0.1.2

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 (77) hide show
  1. package/dist/app.d.ts +14 -0
  2. package/dist/app.d.ts.map +1 -0
  3. package/dist/app.js +30 -0
  4. package/dist/app.js.map +1 -0
  5. package/dist/core/index.d.ts +3 -0
  6. package/dist/core/index.d.ts.map +1 -0
  7. package/dist/core/index.js +19 -0
  8. package/dist/core/index.js.map +1 -0
  9. package/dist/core/query-builder.d.ts +96 -0
  10. package/dist/core/query-builder.d.ts.map +1 -0
  11. package/dist/core/query-builder.js +271 -0
  12. package/dist/core/query-builder.js.map +1 -0
  13. package/dist/core/types.d.ts +33 -0
  14. package/dist/core/types.d.ts.map +1 -0
  15. package/dist/core/types.js +42 -0
  16. package/dist/core/types.js.map +1 -0
  17. package/dist/db/index.d.ts +2 -0
  18. package/dist/db/index.d.ts.map +1 -0
  19. package/dist/db/index.js +18 -0
  20. package/dist/db/index.js.map +1 -0
  21. package/dist/db/mongodb.d.ts +2 -0
  22. package/dist/db/mongodb.d.ts.map +1 -0
  23. package/dist/db/mongodb.js +23 -0
  24. package/dist/db/mongodb.js.map +1 -0
  25. package/dist/exitCodes.d.ts +4 -0
  26. package/dist/exitCodes.d.ts.map +1 -0
  27. package/dist/exitCodes.js +7 -0
  28. package/dist/exitCodes.js.map +1 -0
  29. package/dist/fluent-interface/fluent-pattern-executor.d.ts +45 -0
  30. package/dist/fluent-interface/fluent-pattern-executor.d.ts.map +1 -0
  31. package/dist/fluent-interface/fluent-pattern-executor.js +137 -0
  32. package/dist/fluent-interface/fluent-pattern-executor.js.map +1 -0
  33. package/dist/fluent-interface/index.d.ts +3 -0
  34. package/dist/fluent-interface/index.d.ts.map +1 -0
  35. package/dist/fluent-interface/index.js +19 -0
  36. package/dist/fluent-interface/index.js.map +1 -0
  37. package/dist/fluent-interface/types.d.ts +24 -0
  38. package/dist/fluent-interface/types.d.ts.map +1 -0
  39. package/dist/fluent-interface/types.js +3 -0
  40. package/dist/fluent-interface/types.js.map +1 -0
  41. package/dist/index.d.ts +9 -0
  42. package/dist/index.d.ts.map +1 -0
  43. package/dist/index.js +25 -0
  44. package/dist/index.js.map +1 -0
  45. package/dist/middleware/file-storage.d.ts +4 -0
  46. package/dist/middleware/file-storage.d.ts.map +1 -0
  47. package/dist/middleware/file-storage.js +26 -0
  48. package/dist/middleware/file-storage.js.map +1 -0
  49. package/dist/middleware/index.d.ts +3 -0
  50. package/dist/middleware/index.d.ts.map +1 -0
  51. package/dist/middleware/index.js +19 -0
  52. package/dist/middleware/index.js.map +1 -0
  53. package/dist/middleware/logger.d.ts +4 -0
  54. package/dist/middleware/logger.d.ts.map +1 -0
  55. package/dist/middleware/logger.js +29 -0
  56. package/dist/middleware/logger.js.map +1 -0
  57. package/dist/types.d.ts +2 -0
  58. package/dist/types.d.ts.map +1 -0
  59. package/dist/types.js +3 -0
  60. package/dist/types.js.map +1 -0
  61. package/dist/utils/date.d.ts +2 -0
  62. package/dist/utils/date.d.ts.map +1 -0
  63. package/dist/utils/date.js +8 -0
  64. package/dist/utils/date.js.map +1 -0
  65. package/dist/utils/index.d.ts +4 -0
  66. package/dist/utils/index.d.ts.map +1 -0
  67. package/dist/utils/index.js +20 -0
  68. package/dist/utils/index.js.map +1 -0
  69. package/dist/utils/mongo-relation.d.ts +21 -0
  70. package/dist/utils/mongo-relation.d.ts.map +1 -0
  71. package/dist/utils/mongo-relation.js +89 -0
  72. package/dist/utils/mongo-relation.js.map +1 -0
  73. package/dist/utils/validation.d.ts +7 -0
  74. package/dist/utils/validation.d.ts.map +1 -0
  75. package/dist/utils/validation.js +17 -0
  76. package/dist/utils/validation.js.map +1 -0
  77. package/package.json +1 -1
package/dist/app.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import * as core from 'express-serve-static-core';
2
+ /**
3
+ * Creates and configures an Express application.
4
+ * @example
5
+ * ```typescript
6
+ * const app = tsledge.createApp();
7
+ * app.listen(PORT, () => {
8
+ * console.log(`Server running on port ${PORT}`);
9
+ * });
10
+ * ```
11
+ * @returns {core.Express} The configured Express application.
12
+ */
13
+ export declare function createApp(): core.Express;
14
+ //# sourceMappingURL=app.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,IAAI,MAAM,2BAA2B,CAAC;AAGlD;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,IAAI,IAAI,CAAC,OAAO,CASxC"}
package/dist/app.js ADDED
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createApp = createApp;
7
+ const express_1 = __importDefault(require("express"));
8
+ const cors_1 = __importDefault(require("cors"));
9
+ const middleware_1 = require("./middleware");
10
+ /**
11
+ * Creates and configures an Express application.
12
+ * @example
13
+ * ```typescript
14
+ * const app = tsledge.createApp();
15
+ * app.listen(PORT, () => {
16
+ * console.log(`Server running on port ${PORT}`);
17
+ * });
18
+ * ```
19
+ * @returns {core.Express} The configured Express application.
20
+ */
21
+ function createApp() {
22
+ const app = (0, express_1.default)();
23
+ app.use((0, cors_1.default)());
24
+ app.use(express_1.default.json());
25
+ app.use(express_1.default.urlencoded({ extended: true }));
26
+ app.use(middleware_1.requestLogger);
27
+ app.use(middleware_1.errorLogger);
28
+ return app;
29
+ }
30
+ //# sourceMappingURL=app.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":";;;;;AAgBA,8BASC;AAzBD,sDAA8B;AAC9B,gDAAwB;AAExB,6CAA0D;AAE1D;;;;;;;;;;GAUG;AACH,SAAgB,SAAS;IACvB,MAAM,GAAG,GAAG,IAAA,iBAAO,GAAE,CAAC;IAEtB,GAAG,CAAC,GAAG,CAAC,IAAA,cAAI,GAAE,CAAC,CAAC;IAChB,GAAG,CAAC,GAAG,CAAC,iBAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IACxB,GAAG,CAAC,GAAG,CAAC,iBAAO,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAChD,GAAG,CAAC,GAAG,CAAC,0BAAa,CAAC,CAAC;IACvB,GAAG,CAAC,GAAG,CAAC,wBAAW,CAAC,CAAC;IACrB,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './query-builder';
2
+ export * from './types';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./query-builder"), exports);
18
+ __exportStar(require("./types"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,0CAAwB"}
@@ -0,0 +1,96 @@
1
+ import { JoinRelation, PromiseDefaultCodec, QueryBuilderConfig } from './types';
2
+ export declare class QueryBuilder {
3
+ private _config;
4
+ private _matchConditions;
5
+ private _stages;
6
+ private _relations;
7
+ private _unsetFields;
8
+ constructor(config: QueryBuilderConfig);
9
+ /**
10
+ * Generates the aggregation pipeline based on the current configuration of the QueryBuilder.
11
+ * @returns
12
+ */
13
+ getAggregationPipeline(): any[];
14
+ /**
15
+ * Returns the current configuration of the QueryBuilder, including model, select fields, and any applied options.
16
+ * @returns
17
+ */
18
+ getConfig(): QueryBuilderConfig;
19
+ /**
20
+ * Applies schema-based options such as joins and unset fields.
21
+ */
22
+ private _applyPathOptions;
23
+ /**
24
+ * Adds match conditions to the query builder.
25
+ * @param match - The match conditions to add.
26
+ * @param conjunction - The logical conjunction ('and' or 'or').
27
+ * @param append - Whether to append to existing conditions or replace them.
28
+ */
29
+ match(match: Record<string, any> | Record<string, any>[], conjunction?: string, append?: boolean): void;
30
+ /**
31
+ * Adds aggregation stages to the query builder.
32
+ * @param stages
33
+ * @returns
34
+ */
35
+ stage(stages: any[] | {} | any): void;
36
+ /**
37
+ * Adds join relations to the query builder.
38
+ * @param rels
39
+ * @returns
40
+ */
41
+ join(rels: JoinRelation | JoinRelation[] | null): void;
42
+ /**
43
+ * Calculates the $lookup stage for a given JoinRelation.
44
+ * @param relation
45
+ * @returns
46
+ */
47
+ private _calculateJoin;
48
+ /**
49
+ * Automatically generates JoinRelation objects from schema refs.
50
+ * @param model The Mongoose model to scan.
51
+ * @param prefix Optional prefix for nested paths (e.g., 'alias.field').
52
+ * @returns Array of JoinRelation objects.
53
+ */
54
+ private _generateSchemaJoins;
55
+ /**
56
+ * Generates the list of fields to unset based on schema select options.
57
+ * @param config - The query request configuration.
58
+ */
59
+ private _generateSchemaUnsetList;
60
+ /**
61
+ * Collects paths from the schema where select is set to false.
62
+ * @param schema - The Mongoose schema to scan.
63
+ * @param prefix - Optional prefix for nested paths.
64
+ * @param select - Optional array of fields to select.
65
+ * @returns Array of paths to unset.
66
+ */
67
+ private _collectSelectFalse;
68
+ /**
69
+ * Generates the aggregation pipeline based on joins, stages, match conditions, and unset fields.
70
+ * @returns The aggregation pipeline array.
71
+ */
72
+ private _generatePipeline;
73
+ /**
74
+ * Executes the aggregation pipeline and returns the results.
75
+ * @param config - Parameters for the query execution.
76
+ * @returns The collection response wrapped in a Codec.
77
+ */
78
+ exec<T = any>(config?: {
79
+ isOne?: boolean;
80
+ limit?: number;
81
+ skip?: number;
82
+ }): PromiseDefaultCodec;
83
+ /**
84
+ * Processes a single document from the aggregation result.
85
+ * @param res - The aggregation result array.
86
+ * @returns The processed document or null if none.
87
+ */
88
+ private _processSingleDocument;
89
+ /**
90
+ * Processes multiple documents from the aggregation result.
91
+ * @param res - The aggregation result array.
92
+ * @returns The array of processed documents.
93
+ */
94
+ private _processMultipleDocuments;
95
+ }
96
+ //# sourceMappingURL=query-builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-builder.d.ts","sourceRoot":"","sources":["../../src/core/query-builder.ts"],"names":[],"mappings":"AACA,OAAO,EAA8B,YAAY,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE5G,qBAAa,YAAY;IACvB,OAAO,CAAC,OAAO,CAAqB;IACpC,OAAO,CAAC,gBAAgB,CAA2B;IACnD,OAAO,CAAC,OAAO,CAAa;IAC5B,OAAO,CAAC,UAAU,CAAsB;IACxC,OAAO,CAAC,YAAY,CAAgB;gBAExB,MAAM,EAAE,kBAAkB;IAKtC;;;OAGG;IACI,sBAAsB,IAAI,GAAG,EAAE;IAItC;;;OAGG;IACI,SAAS,IAAI,kBAAkB;IAItC;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAKzB;;;;;OAKG;IACH,KAAK,CACH,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,EAClD,WAAW,GAAE,MAAc,EAC3B,MAAM,GAAE,OAAc;IAiBxB;;;;OAIG;IACH,KAAK,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG;IAS9B;;;;OAIG;IACH,IAAI,CAAC,IAAI,EAAE,YAAY,GAAG,YAAY,EAAE,GAAG,IAAI;IAM/C;;;;OAIG;IACH,OAAO,CAAC,cAAc;IAYtB;;;;;OAKG;IACH,OAAO,CAAC,oBAAoB;IAuC5B;;;OAGG;IACH,OAAO,CAAC,wBAAwB;IAWhC;;;;;;OAMG;IACH,OAAO,CAAC,mBAAmB;IAuB3B;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAmBzB;;;;OAIG;IACG,IAAI,CAAC,CAAC,GAAG,GAAG,EAAE,MAAM,CAAC,EAAE;QAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,GAAG,mBAAmB;IA6BvB;;;;OAIG;YACW,sBAAsB;IAapC;;;;OAIG;YACW,yBAAyB;CAcxC"}
@@ -0,0 +1,271 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.QueryBuilder = void 0;
7
+ const mongoose_1 = __importDefault(require("mongoose"));
8
+ const types_1 = require("./types");
9
+ class QueryBuilder {
10
+ _config;
11
+ _matchConditions = {};
12
+ _stages = [];
13
+ _relations = [];
14
+ _unsetFields = [];
15
+ constructor(config) {
16
+ this._config = config;
17
+ this._applyPathOptions();
18
+ }
19
+ /**
20
+ * Generates the aggregation pipeline based on the current configuration of the QueryBuilder.
21
+ * @returns
22
+ */
23
+ getAggregationPipeline() {
24
+ return this._generatePipeline();
25
+ }
26
+ /**
27
+ * Returns the current configuration of the QueryBuilder, including model, select fields, and any applied options.
28
+ * @returns
29
+ */
30
+ getConfig() {
31
+ return this._config;
32
+ }
33
+ /**
34
+ * Applies schema-based options such as joins and unset fields.
35
+ */
36
+ _applyPathOptions() {
37
+ this._generateSchemaJoins(this._config.model.schema);
38
+ this._generateSchemaUnsetList(this._config);
39
+ }
40
+ /**
41
+ * Adds match conditions to the query builder.
42
+ * @param match - The match conditions to add.
43
+ * @param conjunction - The logical conjunction ('and' or 'or').
44
+ * @param append - Whether to append to existing conditions or replace them.
45
+ */
46
+ match(match, conjunction = 'and', append = true) {
47
+ if (!match || (Array.isArray(match) ? match.length === 0 : Object.keys(match).length === 0))
48
+ return;
49
+ if (!append) {
50
+ this._matchConditions = Array.isArray(match) ? { $and: match } : match;
51
+ return;
52
+ }
53
+ const key = `$${conjunction}`;
54
+ if (!this._matchConditions[key])
55
+ this._matchConditions[key] = [];
56
+ if (Array.isArray(match)) {
57
+ this._matchConditions[key].push(...match);
58
+ }
59
+ else {
60
+ this._matchConditions[key].push(match);
61
+ }
62
+ }
63
+ /**
64
+ * Adds aggregation stages to the query builder.
65
+ * @param stages
66
+ * @returns
67
+ */
68
+ stage(stages) {
69
+ if (!stages)
70
+ return;
71
+ if (Array.isArray(stages)) {
72
+ this._stages.push(...globalThis.structuredClone(stages));
73
+ }
74
+ else {
75
+ this._stages.push(globalThis.structuredClone(stages));
76
+ }
77
+ }
78
+ /**
79
+ * Adds join relations to the query builder.
80
+ * @param rels
81
+ * @returns
82
+ */
83
+ join(rels) {
84
+ if (!rels)
85
+ return;
86
+ const list = Array.isArray(rels) ? rels : [rels];
87
+ list.forEach((rel) => this._relations.push(rel));
88
+ }
89
+ /**
90
+ * Calculates the $lookup stage for a given JoinRelation.
91
+ * @param relation
92
+ * @returns
93
+ */
94
+ _calculateJoin(relation) {
95
+ if (!(relation instanceof types_1.JoinRelation))
96
+ throw new Error('relation must be JoinRelation');
97
+ return {
98
+ $lookup: {
99
+ from: relation.ref.collection.name,
100
+ localField: relation.localField,
101
+ foreignField: '_id',
102
+ as: relation.alias,
103
+ },
104
+ };
105
+ }
106
+ /**
107
+ * Automatically generates JoinRelation objects from schema refs.
108
+ * @param model The Mongoose model to scan.
109
+ * @param prefix Optional prefix for nested paths (e.g., 'alias.field').
110
+ * @returns Array of JoinRelation objects.
111
+ */
112
+ _generateSchemaJoins(schema, prefix = '') {
113
+ schema.eachPath((path, schematype) => {
114
+ const fullPath = prefix ? `${prefix}.${path}` : path;
115
+ if (schematype.options?.ref) {
116
+ const refModelName = schematype.options.ref;
117
+ try {
118
+ const refModel = mongoose_1.default.model(refModelName);
119
+ let alias = schematype.options?.alias ?? refModel.collection.name;
120
+ this.join(new types_1.JoinRelation(fullPath, refModel, alias));
121
+ }
122
+ catch (err) {
123
+ console.warn(`[QueryBuilder] Could not resolve ref model '${refModelName}' for path '${fullPath}'`);
124
+ }
125
+ }
126
+ if (schematype instanceof mongoose_1.default.Schema.Types.Array &&
127
+ schematype.caster?.options?.ref) {
128
+ const refModelName = schematype.caster.options.ref;
129
+ try {
130
+ const refModel = mongoose_1.default.model(refModelName);
131
+ let alias = schematype.caster.options?.alias ?? refModel.collection.name;
132
+ this.join(new types_1.JoinRelation(fullPath, refModel, alias));
133
+ }
134
+ catch (err) {
135
+ console.warn(`[QueryBuilder] Could not resolve array ref model '${refModelName}' for path '${fullPath}'`);
136
+ }
137
+ }
138
+ // if (schematype instanceof mongoose.Schema.Types.Subdocument) { //TODO Testen ob Subdocuments auch so erkannt werden können
139
+ // joins.push(...this._generateSchemaJoins(model.schema, fullPath));
140
+ // }
141
+ });
142
+ }
143
+ /**
144
+ * Generates the list of fields to unset based on schema select options.
145
+ * @param config - The query request configuration.
146
+ */
147
+ _generateSchemaUnsetList(config) {
148
+ this._unsetFields = [];
149
+ let unset = this._collectSelectFalse(config.model.schema, undefined, config.select);
150
+ for (const relation of this._relations) {
151
+ unset = unset.concat(this._collectSelectFalse(relation.ref.schema, relation.alias, config.select));
152
+ }
153
+ this._unsetFields = Array.from(new Set(unset));
154
+ }
155
+ /**
156
+ * Collects paths from the schema where select is set to false.
157
+ * @param schema - The Mongoose schema to scan.
158
+ * @param prefix - Optional prefix for nested paths.
159
+ * @param select - Optional array of fields to select.
160
+ * @returns Array of paths to unset.
161
+ */
162
+ _collectSelectFalse(schema, prefix = undefined, select = undefined) {
163
+ const unset = [];
164
+ schema.eachPath((path, schematype) => {
165
+ // If select is specified, only consider fields not in select or with select: false
166
+ if (select &&
167
+ select.length > 0 &&
168
+ !select.includes(path) &&
169
+ schematype?.options?.select !== false) {
170
+ return;
171
+ }
172
+ if (schematype?.options?.select === false) {
173
+ unset.push(prefix ? `${prefix}.${path}` : path);
174
+ }
175
+ });
176
+ return unset;
177
+ }
178
+ /**
179
+ * Generates the aggregation pipeline based on joins, stages, match conditions, and unset fields.
180
+ * @returns The aggregation pipeline array.
181
+ */
182
+ _generatePipeline() {
183
+ const pipeline = [];
184
+ // Add join stages
185
+ for (const rel of this._relations) {
186
+ pipeline.push(this._calculateJoin(rel));
187
+ }
188
+ // Add custom stages
189
+ pipeline.push(...this._stages);
190
+ // Add match conditions
191
+ if (Object.keys(this._matchConditions).length) {
192
+ pipeline.push({ $match: this._matchConditions });
193
+ }
194
+ // Add unset fields
195
+ if (this._unsetFields.length) {
196
+ pipeline.push({ $unset: this._unsetFields });
197
+ }
198
+ return pipeline;
199
+ }
200
+ /**
201
+ * Executes the aggregation pipeline and returns the results.
202
+ * @param config - Parameters for the query execution.
203
+ * @returns The collection response wrapped in a Codec.
204
+ */
205
+ async exec(config) {
206
+ try {
207
+ const pipeline = this._generatePipeline();
208
+ const countPipeline = [...pipeline, { $count: 'n' }];
209
+ const queryPipeline = [...pipeline];
210
+ if (config && !config.isOne) {
211
+ if (config.skip)
212
+ queryPipeline.push({ $skip: config.skip });
213
+ if (config.limit)
214
+ queryPipeline.push({ $limit: config.limit });
215
+ }
216
+ const [countRes, res] = await Promise.all([
217
+ this._config.model.aggregate(countPipeline).exec(),
218
+ this._config.model.aggregate(queryPipeline).exec(),
219
+ ]);
220
+ const totalCount = countRes && countRes[0] ? countRes[0].n : 0;
221
+ const documents = config && config.isOne
222
+ ? await this._processSingleDocument(res)
223
+ : await this._processMultipleDocuments(res);
224
+ return new types_1.Codec({ data: documents, meta: { total: totalCount } }, 200);
225
+ }
226
+ catch (err) {
227
+ console.error('[ERROR - QueryBuilder]', err);
228
+ return new types_1.Codec({ data: [], meta: { total: 0 } }, 500);
229
+ }
230
+ }
231
+ /**
232
+ * Processes a single document from the aggregation result.
233
+ * @param res - The aggregation result array.
234
+ * @returns The processed document or null if none.
235
+ */
236
+ async _processSingleDocument(res) {
237
+ if (!res || res.length === 0) {
238
+ return null;
239
+ }
240
+ let doc = this._config.model.hydrate(res[0]);
241
+ if (this._config.eachFunc) {
242
+ doc = this._config.eachFunc(doc);
243
+ }
244
+ else if (this._config.asyncEachFunc) {
245
+ doc = await this._config.asyncEachFunc(doc);
246
+ }
247
+ return doc;
248
+ }
249
+ /**
250
+ * Processes multiple documents from the aggregation result.
251
+ * @param res - The aggregation result array.
252
+ * @returns The array of processed documents.
253
+ */
254
+ async _processMultipleDocuments(res) {
255
+ let final = (res || []).map((doc) => this._config.model.hydrate(doc));
256
+ if (this._config.eachFunc) {
257
+ final = final.map(this._config.eachFunc);
258
+ }
259
+ else if (this._config.asyncEachFunc) {
260
+ const asyncFinal = [];
261
+ for (const doc of final) {
262
+ const newDoc = await this._config.asyncEachFunc(doc);
263
+ asyncFinal.push(newDoc);
264
+ }
265
+ final = asyncFinal;
266
+ }
267
+ return final;
268
+ }
269
+ }
270
+ exports.QueryBuilder = QueryBuilder;
271
+ //# sourceMappingURL=query-builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-builder.js","sourceRoot":"","sources":["../../src/core/query-builder.ts"],"names":[],"mappings":";;;;;;AAAA,wDAAgC;AAChC,mCAA4G;AAE5G,MAAa,YAAY;IACf,OAAO,CAAqB;IAC5B,gBAAgB,GAAwB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ACtC,MAAM,UAAU,GAAQ,EAAE,CAAC;YAC3B,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;gBACxB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;gBACrD,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAC1B,CAAC;YACD,KAAK,GAAG,UAAU,CAAC;QACrB,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AApSD,oCAoSC"}
@@ -0,0 +1,33 @@
1
+ import mongoose from "mongoose";
2
+ export interface DefaultResponseBody extends Record<string, any> {
3
+ data?: any[] | any;
4
+ meta?: {
5
+ total?: number;
6
+ };
7
+ error?: string;
8
+ }
9
+ export declare class Codec<T = any> {
10
+ content: T;
11
+ returnCode: number;
12
+ constructor(content: T, code?: number);
13
+ sendToClient(res: any): void;
14
+ is1xx(): boolean;
15
+ is2xx(): boolean;
16
+ is3xx(): boolean;
17
+ is4xx(): boolean;
18
+ }
19
+ export type DefaultCodec = Codec<DefaultResponseBody>;
20
+ export type PromiseDefaultCodec = Promise<Codec<DefaultResponseBody>>;
21
+ export declare class JoinRelation<T = any> {
22
+ ref: mongoose.Model<T>;
23
+ localField: string;
24
+ alias: string;
25
+ constructor(localField: string, ref: mongoose.Model<T>, alias?: string | undefined);
26
+ }
27
+ export interface QueryBuilderConfig<T = any> {
28
+ model: mongoose.Model<T>;
29
+ select?: string[] | undefined;
30
+ eachFunc?: (doc: any) => any;
31
+ asyncEachFunc?: (doc: any) => Promise<any>;
32
+ }
33
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAEhC,MAAM,WAAW,mBAAoB,SAAQ,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAC9D,IAAI,CAAC,EAAE,G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ation = exports.Codec = void 0;
4
+ class Codec {
5
+ content;
6
+ returnCode;
7
+ constructor(content, code = 202) {
8
+ this.content = content;
9
+ this.returnCode = code;
10
+ }
11
+ sendToClient(res) {
12
+ if (this.content == null) {
13
+ res.status(404).json({});
14
+ }
15
+ res.status(this.returnCode).json(this.content);
16
+ }
17
+ is1xx() {
18
+ return this.returnCode >= 100 && this.returnCode <= 199;
19
+ }
20
+ is2xx() {
21
+ return this.returnCode >= 200 && this.returnCode <= 299;
22
+ }
23
+ is3xx() {
24
+ return this.returnCode >= 300 && this.returnCode <= 399;
25
+ }
26
+ is4xx() {
27
+ return this.returnCode >= 400 && this.returnCode <= 499;
28
+ }
29
+ }
30
+ exports.Codec = Codec;
31
+ class JoinRelation {
32
+ ref;
33
+ localField;
34
+ alias;
35
+ constructor(localField, ref, alias = undefined) {
36
+ this.ref = ref;
37
+ this.localField = localField;
38
+ this.alias = alias ? alias : ref.collection.name;
39
+ }
40
+ }
41
+ exports.JoinRelation = JoinRelation;
42
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":";;;AAQA,MAAa,KAAK;IAChB,OAAO,CAAI;IACX,UAAU,CAAS;IAEnB,YAAY,OAAU,EAAE,OAAe,GAAG;QACxC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;IACzB,CAAC;IAED,YAAY,CAAC,GAAQ;QACnB,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,EAAE,CAAC;YACzB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC3B,CAAC;QACD,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACjD,CAAC;IAED,KAAK;QACH,OAAO,IAAI,CAAC,UAAU,IAAI,GAAG,IAAI,IAAI,CAAC,UAAU,IAAI,GAAG,CAAC;IAC1D,CAAC;IACD,KAAK;QACH,OAAO,IAAI,CAAC,UAAU,IAAI,GAAG,IAAI,IAAI,CAAC,UAAU,IAAI,GAAG,CAAC;IAC1D,CAAC;IACD,KAAK;QACH,OAAO,IAAI,CAAC,UAAU,IAAI,GAAG,IAAI,IAAI,CAAC,UAAU,IAAI,GAAG,CAAC;IAC1D,CAAC;IACD,KAAK;QACH,OAAO,IAAI,CAAC,UAAU,IAAI,GAAG,IAAI,IAAI,CAAC,UAAU,IAAI,GAAG,CAAC;IAC1D,CAAC;CACF;AA5BD,sBA4BC;AAKD,MAAa,YAAY;IACvB,GAAG,CAAoB;IACvB,UAAU,CAAS;IACnB,KAAK,CAAS;IAEd,YAAY,UAAkB,EAAE,GAAsB,EAAE,QAA4B,SAAS;QAC3F,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC;IACnD,CAAC;CACF;AAVD,oCAUC"}
@@ -0,0 +1,2 @@
1
+ export * from './mongodb';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/db/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./mongodb"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/db/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B"}
@@ -0,0 +1,2 @@
1
+ export declare function connectMongoDB(uri: string): Promise<void>;
2
+ //# sourceMappingURL=mongodb.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongodb.d.ts","sourceRoot":"","sources":["../../src/db/mongodb.ts"],"names":[],"mappings":"AAGA,wBAAsB,cAAc,CAAC,GAAG,EAAE,MAAM,iBAY/C"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.connectMongoDB = connectMongoDB;
7
+ const mongoose_1 = __importDefault(require("mongoose"));
8
+ const exitCodes_1 = require("../exitCodes");
9
+ async function connectMongoDB(uri) {
10
+ if (uri == null || uri == undefined || uri.length == 0) {
11
+ console.error(`🛑 [${new Date().toISOString()}] Error: MongoDB URI is not provided`);
12
+ process.exit(exitCodes_1.EXIT_CODE_INVALID_CONFIG);
13
+ }
14
+ try {
15
+ await mongoose_1.default.connect(uri);
16
+ console.log(`✅ [${new Date().toISOString()}] MongoDB connected`);
17
+ }
18
+ catch (err) {
19
+ console.error(`🛑 [${new Date().toISOString()}] Error: MongoDB connection failed`, err);
20
+ process.exit(exitCodes_1.EXIT_CODE_GENERAL_ERROR);
21
+ }
22
+ }
23
+ //# sourceMappingURL=mongodb.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongodb.js","sourceRoot":"","sources":["../../src/db/mongodb.ts"],"names":[],"mappings":";;;;;AAGA,wCAYC;AAfD,wDAAgC;AAChC,4CAAiF;AAE1E,KAAK,UAAU,cAAc,CAAC,GAAW;IAC9C,IAAG,GAAG,IAAI,IAAI,IAAI,GAAG,IAAI,SAAS,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;QACtD,OAAO,CAAC,KAAK,CAAC,OAAO,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,sCAAsC,CAAC,CAAC;QACrF,OAAO,CAAC,IAAI,CAAC,oCAAwB,CAAC,CAAC;IACzC,CAAC;IACD,IAAI,CAAC;QACH,MAAM,kBAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC5B,OAAO,CAAC,GAAG,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,qBAAqB,CAAC,CAAC;IACnE,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,OAAO,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,oCAAoC,EAAE,GAAG,CAAC,CAAC;QACxF,OAAO,CAAC,IAAI,CAAC,mCAAuB,CAAC,CAAC;IACxC,CAAC;AACH,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare const EXIT_CODE_SUCCESS = 0;
2
+ export declare const EXIT_CODE_GENERAL_ERROR = 1;
3
+ export declare const EXIT_CODE_INVALID_CONFIG = 2;
4
+ //# sourceMappingURL=exitCodes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exitCodes.d.ts","sourceRoot":"","sources":["../src/exitCodes.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,IAAI,CAAC;AACnC,eAAO,MAAM,uBAAuB,IAAI,CAAC;AACzC,eAAO,MAAM,wBAAwB,IAAI,CAAC"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EXIT_CODE_INVALID_CONFIG = exports.EXIT_CODE_GENERAL_ERROR = exports.EXIT_CODE_SUCCESS = void 0;
4
+ exports.EXIT_CODE_SUCCESS = 0;
5
+ exports.EXIT_CODE_GENERAL_ERROR = 1; // Ein unspezifischer Fehler ist aufgetreten
6
+ exports.EXIT_CODE_INVALID_CONFIG = 2; // falsche Befehlszeilenargumente oder Syntaxfehler.
7
+ //# sourceMappingURL=exitCodes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exitCodes.js","sourceRoot":"","sources":["../src/exitCodes.ts"],"names":[],"mappings":";;;AAAa,QAAA,iBAAiB,GAAG,CAAC,CAAC;AACtB,QAAA,uBAAuB,GAAG,CAAC,CAAC,CAAC,4CAA4C;AACzE,QAAA,wBAAwB,GAAG,CAAC,CAAC,CAAC,oDAAoD"}