tsledge 0.1.4 → 0.1.5

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 (76) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +1001 -24
  4. package/dist/middleware/authentication/index.d.ts +4 -0
  5. package/dist/middleware/authentication/index.d.ts.map +1 -0
  6. package/dist/middleware/authentication/session.d.ts +74 -0
  7. package/dist/middleware/authentication/session.d.ts.map +1 -0
  8. package/dist/middleware/authentication/types.d.ts +12 -0
  9. package/dist/middleware/authentication/types.d.ts.map +1 -0
  10. package/dist/middleware/authentication/validation.d.ts +55 -0
  11. package/dist/middleware/authentication/validation.d.ts.map +1 -0
  12. package/dist/middleware/index.d.ts +2 -0
  13. package/dist/middleware/index.d.ts.map +1 -1
  14. package/dist/middleware/logger.d.ts.map +1 -1
  15. package/dist/middleware/types.d.ts +2 -0
  16. package/dist/middleware/types.d.ts.map +1 -0
  17. package/dist/models/auth-user.d.ts +14 -0
  18. package/dist/models/auth-user.d.ts.map +1 -0
  19. package/dist/models/index.d.ts +3 -0
  20. package/dist/models/index.d.ts.map +1 -0
  21. package/dist/models/token-blocklist.d.ts +12 -0
  22. package/dist/models/token-blocklist.d.ts.map +1 -0
  23. package/dist/src/index.js +1000 -0
  24. package/dist/tests/main.js +932 -0
  25. package/dist/utils/encoding.d.ts +7 -0
  26. package/dist/utils/encoding.d.ts.map +1 -0
  27. package/dist/utils/env.d.ts +9 -0
  28. package/dist/utils/env.d.ts.map +1 -0
  29. package/dist/utils/index.d.ts +2 -0
  30. package/dist/utils/index.d.ts.map +1 -1
  31. package/dist/utils/validation.d.ts +9 -0
  32. package/dist/utils/validation.d.ts.map +1 -1
  33. package/package.json +16 -6
  34. package/dist/app.js +0 -30
  35. package/dist/app.js.map +0 -1
  36. package/dist/core/http.js +0 -79
  37. package/dist/core/http.js.map +0 -1
  38. package/dist/core/index.js +0 -20
  39. package/dist/core/index.js.map +0 -1
  40. package/dist/core/query-builder.js +0 -271
  41. package/dist/core/query-builder.js.map +0 -1
  42. package/dist/core/types.js +0 -49
  43. package/dist/core/types.js.map +0 -1
  44. package/dist/db/index.js +0 -18
  45. package/dist/db/index.js.map +0 -1
  46. package/dist/db/mongodb.js +0 -28
  47. package/dist/db/mongodb.js.map +0 -1
  48. package/dist/exitCodes.js +0 -7
  49. package/dist/exitCodes.js.map +0 -1
  50. package/dist/fluent-interface/fluent-pattern-executor.d.ts +0 -45
  51. package/dist/fluent-interface/fluent-pattern-executor.d.ts.map +0 -1
  52. package/dist/fluent-interface/fluent-pattern-executor.js +0 -137
  53. package/dist/fluent-interface/fluent-pattern-executor.js.map +0 -1
  54. package/dist/fluent-interface/fluent-pattern-handler.js +0 -166
  55. package/dist/fluent-interface/fluent-pattern-handler.js.map +0 -1
  56. package/dist/fluent-interface/index.js +0 -19
  57. package/dist/fluent-interface/index.js.map +0 -1
  58. package/dist/fluent-interface/types.js +0 -16
  59. package/dist/fluent-interface/types.js.map +0 -1
  60. package/dist/index.js.map +0 -1
  61. package/dist/middleware/file-storage.js +0 -26
  62. package/dist/middleware/file-storage.js.map +0 -1
  63. package/dist/middleware/index.js +0 -19
  64. package/dist/middleware/index.js.map +0 -1
  65. package/dist/middleware/logger.js +0 -30
  66. package/dist/middleware/logger.js.map +0 -1
  67. package/dist/types.js +0 -3
  68. package/dist/types.js.map +0 -1
  69. package/dist/utils/date.js +0 -8
  70. package/dist/utils/date.js.map +0 -1
  71. package/dist/utils/index.js +0 -20
  72. package/dist/utils/index.js.map +0 -1
  73. package/dist/utils/mongo-relation.js +0 -89
  74. package/dist/utils/mongo-relation.js.map +0 -1
  75. package/dist/utils/validation.js +0 -17
  76. package/dist/utils/validation.js.map +0 -1
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Encodes any object into a base64 string.
3
+ * @param obj The object to encode.
4
+ * @returns Encoded string in base64 format.
5
+ */
6
+ export declare function encodeToBase64(obj: any): string;
7
+ //# sourceMappingURL=encoding.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encoding.d.ts","sourceRoot":"","sources":["../../src/utils/encoding.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CAE/C"}
@@ -0,0 +1,9 @@
1
+ export declare const JwtSecret: string;
2
+ export declare const JwtRefreshSecret: string;
3
+ /**
4
+ * Utility function to check if the application is in debug mode based on the DEBUG environment variable.
5
+ * @param func Optional function to execute if debug mode is enabled.
6
+ * @returns True if debug mode is enabled, false otherwise.
7
+ */
8
+ export declare function isDebug(func?: (() => void) | undefined): boolean;
9
+ //# sourceMappingURL=env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/utils/env.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,QAAqC,CAAC;AAC5D,eAAO,MAAM,gBAAgB,QAAqD,CAAC;AAEnF;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,IAAI,GAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAqB,GAAG,OAAO,CAW3E"}
@@ -1,4 +1,6 @@
1
1
  export * from './date';
2
2
  export * from './mongo-relation';
3
3
  export * from './validation';
4
+ export * from './env';
5
+ export * from './encoding';
4
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,OAAO,CAAC;AACtB,cAAc,YAAY,CAAC"}
@@ -4,4 +4,13 @@
4
4
  * @returns boolean
5
5
  */
6
6
  export declare function isNonEmptyObjectOrArray(value: any): boolean;
7
+ /**
8
+ * Validates a string value, returning it if it's not empty, undefined, or null.
9
+ * Returns the fallback value otherwise.
10
+ *
11
+ * @param value - The value to validate.
12
+ * @param fallback - The value to return if validation fails.
13
+ * @returns The validated string or the fallback.
14
+ */
15
+ export declare function validateString(value: string | undefined | null, fallback?: any): string | null | any;
7
16
  //# sourceMappingURL=validation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAS3D"}
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAS3D;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,EAAE,QAAQ,GAAE,GAAU,GAAG,MAAM,GAAG,IAAI,GAAG,GAAG,CAW1G"}
package/package.json CHANGED
@@ -2,10 +2,11 @@
2
2
  "author": "Niklas Wockenfuß",
3
3
  "homepage": "https://niklaswockenfuss.de/",
4
4
  "name": "tsledge",
5
- "version": "0.1.4",
5
+ "version": "0.1.5",
6
6
  "license": "MIT",
7
7
  "description": "My playground and some helpful tools for web development ",
8
8
  "main": "dist/index.js",
9
+ "type": "module",
9
10
  "types": "dist/index.d.ts",
10
11
  "files": [
11
12
  "dist/**/*",
@@ -16,25 +17,34 @@
16
17
  "node": ">=23.0.0"
17
18
  },
18
19
  "scripts": {
19
- "dev": "ts-node-dev --respawn tests/main.ts",
20
- "repl": "ts-node --project tsconfig.json ./scripts/repl.ts",
21
- "build": "tsc",
22
- "npmjs": "tsc && npm publish"
20
+ "esbuild:build:watch": "node esbuild.js --watch",
21
+ "esbuild:dev:watch": "node --watch dist/tests/main.js",
22
+ "build": "node esbuild.js && tsc --emitDeclarationOnly",
23
+ "dev": "concurrently \"npm run esbuild:build:watch\" \"npm run esbuild:dev:watch\"",
24
+ "repl": "tsx ./scripts/repl.ts",
25
+ "npmjs": "npm run build && npm publish"
23
26
  },
24
27
  "dependencies": {
28
+ "bcrypt": "^6.0.0",
25
29
  "cors": "^2.8.6",
26
30
  "dotenv": "^17.2.3",
27
31
  "express": "^5.2.1",
32
+ "jsonwebtoken": "^9.0.3",
28
33
  "mongoose": "^9.1.5",
29
34
  "multer": "^2.0.2"
30
35
  },
31
36
  "devDependencies": {
37
+ "@types/bcrypt": "^6.0.0",
32
38
  "@types/cors": "^2.8.19",
33
39
  "@types/express": "^5.0.6",
40
+ "@types/jsonwebtoken": "^9.0.10",
34
41
  "@types/mongoose": "^5.11.96",
35
42
  "@types/multer": "^2.0.0",
43
+ "concurrently": "^9.2.1",
44
+ "esbuild": "^0.27.3",
36
45
  "ts-node": "^10.9.2",
37
46
  "ts-node-dev": "^2.0.0",
47
+ "tsx": "^4.21.0",
38
48
  "typescript": "^5.9.3"
39
49
  }
40
- }
50
+ }
package/dist/app.js DELETED
@@ -1,30 +0,0 @@
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
package/dist/app.js.map DELETED
@@ -1 +0,0 @@
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"}
package/dist/core/http.js DELETED
@@ -1,79 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formDataParser = formDataParser;
4
- exports.httpRequest = httpRequest;
5
- /**
6
- * Converts an object to a URL-encoded string for form submission.
7
- * With content type application/x-www-form-urlencoded, the body should be a string in the format of key=value&key2=value2.
8
- * @param obj
9
- * @returns
10
- */
11
- function formDataParser(obj) {
12
- return new URLSearchParams(obj).toString();
13
- }
14
- /**
15
- * Executes the HTTP request using axios or fetch as fallback
16
- * @param config RequestConfig
17
- * @returns Promise<T> The response data
18
- */
19
- async function httpRequest(config) {
20
- const url = new URL(config.url);
21
- if (config.urlSearchParams) {
22
- Object.keys(config.urlSearchParams).forEach((key) => {
23
- url.searchParams.set(key, String(config.urlSearchParams[key]));
24
- });
25
- }
26
- let body;
27
- let defaultContentType = 'application/x-www-form-urlencoded';
28
- if (config.body) {
29
- if (typeof config.body === 'object') {
30
- body = JSON.stringify(config.body);
31
- defaultContentType = 'application/json';
32
- }
33
- else {
34
- body = String(config.body);
35
- }
36
- }
37
- const fetchImpl = globalThis.fetch;
38
- if (!fetchImpl) {
39
- throw new Error('fetch() is not available. Please use Node.js 18+ or add a fetch polyfill.');
40
- }
41
- const defaultHeaders = {};
42
- if (!config.headers ||
43
- !Object.keys(config.headers).find((key) => key.toLowerCase() === 'content-type')) {
44
- defaultHeaders['Content-Type'] = defaultContentType;
45
- }
46
- const response = await fetchImpl(url.toString(), {
47
- method: config.method?.toUpperCase() || 'GET',
48
- body,
49
- headers: {
50
- ...defaultHeaders,
51
- ...config.headers,
52
- },
53
- });
54
- const contentType = response.headers.get('content-type') || '';
55
- const isJson = contentType.includes('application/json');
56
- const isBlob = contentType.includes('application/octet-stream');
57
- if (!response.ok) {
58
- const text = await response.text().catch(() => '');
59
- throw new Error(`HTTP ${response.status} ${response.statusText}: ${text}`);
60
- }
61
- let result;
62
- if (isJson) {
63
- result = await response.json().catch(async (error) => {
64
- throw new Error(`Failed to parse JSON response: ${error.message}`);
65
- });
66
- }
67
- else if (isBlob) {
68
- result = await response.blob().catch(async (error) => {
69
- throw new Error(`Failed to get blob response: ${error.message}`);
70
- });
71
- }
72
- else {
73
- result = await response.text().catch(async (error) => {
74
- throw new Error(`Failed to get text response: ${error.message}`);
75
- });
76
- }
77
- return result;
78
- }
79
- //# sourceMappingURL=http.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/core/http.ts"],"names":[],"mappings":";;AAQA,wCAEC;AAOD,kCAgEC;AA/ED;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,GAAwB;IACrD,OAAO,IAAI,eAAe,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC;AAC7C,CAAC;AAED;;;;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,CAAC,CAAC;IACL,CAAC;SAAM,CAAC;QACN,MAAM,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,KAAU,EAAE,EAAE;YACxD,MAAM,IAAI,KAAK,CAAC,gCAAgC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACnE,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,MAAW,CAAC;AACrB,CAAC"}
@@ -1,20 +0,0 @@
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
- __exportStar(require("./http"), exports);
20
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,0CAAwB;AACxB,yCAAuB"}
@@ -1,271 +0,0 @@
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
@@ -1 +0,0 @@
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,EAAE,CAAC;IAC3C,OAAO,GAAU,EAAE,CAAC;IACpB,UAAU,GAAmB,EAAE,CAA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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"}
@@ -1,49 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HttpMethod = exports.JoinRelation = 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
- var HttpMethod;
43
- (function (HttpMethod) {
44
- HttpMethod["POST"] = "post";
45
- HttpMethod["GET"] = "get";
46
- HttpMethod["DELETE"] = "delete";
47
- HttpMethod["PUT"] = "put";
48
- })(HttpMethod || (exports.HttpMethod = HttpMethod = {}));
49
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":";;;AAQA,MAAa,KAAK;IAChB,OAAO,CAAI;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AUC;AASD,IAAY,UAKX;AALD,WAAY,UAAU;IACpB,2BAAa,CAAA;IACb,yBAAW,CAAA;IACX,+BAAiB,CAAA;IACjB,yBAAW,CAAA;AACb,CAAC,EALW,UAAU,0BAAV,UAAU,QAKrB"}
package/dist/db/index.js DELETED
@@ -1,18 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/db/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B"}
@@ -1,28 +0,0 @@
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
- const utils_1 = require("../utils");
10
- /**
11
- * Connects to MongoDB using Mongoose
12
- * @param uri
13
- */
14
- async function connectMongoDB(uri) {
15
- if (uri == null || uri == undefined || uri.length == 0) {
16
- console.error(`🛑 [${(0, utils_1.getCurrentDateString)()}] Error: MongoDB URI is not provided`);
17
- process.exit(exitCodes_1.EXIT_CODE_INVALID_CONFIG);
18
- }
19
- try {
20
- await mongoose_1.default.connect(uri);
21
- console.log(`✅ [${(0, utils_1.getCurrentDateString)()}] MongoDB connected`);
22
- }
23
- catch (err) {
24
- console.error(`🛑 [${(0, utils_1.getCurrentDateString)()}] Error: MongoDB connection failed`, err);
25
- process.exit(exitCodes_1.EXIT_CODE_GENERAL_ERROR);
26
- }
27
- }
28
- //# sourceMappingURL=mongodb.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mongodb.js","sourceRoot":"","sources":["../../src/db/mongodb.ts"],"names":[],"mappings":";;;;;AAQA,wCAYC;AApBD,wDAAgC;AAChC,4CAAiF;AACjF,oCAAgD;AAEhD;;;GAGG;AACI,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,IAAA,4BAAoB,GAAE,sCAAsC,CAAC,CAAC;QACnF,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,IAAA,4BAAoB,GAAE,qBAAqB,CAAC,CAAC;IACjE,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,OAAO,IAAA,4BAAoB,GAAE,oCAAoC,EAAE,GAAG,CAAC,CAAC;QACtF,OAAO,CAAC,IAAI,CAAC,mCAAuB,CAAC,CAAC;IACxC,CAAC;AACH,CAAC"}