axiodb 1.2.6 → 1.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Caching/cache.operation.d.ts +29 -0
- package/lib/Caching/cache.operation.js +30 -0
- package/lib/Caching/cache.operation.js.map +1 -1
- package/lib/Helper/Converter.helper.d.ts +25 -0
- package/lib/Helper/Converter.helper.js +26 -1
- package/lib/Helper/Converter.helper.js.map +1 -1
- package/lib/Helper/Crypto.helper.d.ts +44 -0
- package/lib/Helper/Crypto.helper.js +40 -0
- package/lib/Helper/Crypto.helper.js.map +1 -1
- package/lib/Helper/response.helper.d.ts +48 -0
- package/lib/Helper/response.helper.js +50 -0
- package/lib/Helper/response.helper.js.map +1 -1
- package/lib/Models/DataTypes.models.js +3 -0
- package/lib/Models/DataTypes.models.js.map +1 -1
- package/lib/Models/validator.models.d.ts +7 -0
- package/lib/Models/validator.models.js +12 -3
- package/lib/Models/validator.models.js.map +1 -1
- package/lib/Operation/CRUD Operation/Create.operation.d.ts +18 -1
- package/lib/Operation/CRUD Operation/Create.operation.js +75 -9
- package/lib/Operation/CRUD Operation/Create.operation.js.map +1 -1
- package/lib/Operation/Collection/collection.operation.d.ts +8 -0
- package/lib/Operation/Collection/collection.operation.js +16 -1
- package/lib/Operation/Collection/collection.operation.js.map +1 -1
- package/lib/Operation/Database/database.operation.d.ts +11 -0
- package/lib/Operation/Database/database.operation.js +22 -6
- package/lib/Operation/Database/database.operation.js.map +1 -1
- package/lib/Operation/Indexation.operation.d.ts +11 -0
- package/lib/Operation/Indexation.operation.js +27 -9
- package/lib/Operation/Indexation.operation.js.map +1 -1
- package/lib/Storage/FileManager.d.ts +64 -0
- package/lib/Storage/FileManager.js +65 -1
- package/lib/Storage/FileManager.js.map +1 -1
- package/lib/Storage/FolderManager.d.ts +24 -0
- package/lib/Storage/FolderManager.js +27 -2
- package/lib/Storage/FolderManager.js.map +1 -1
- package/lib/config/DB.js +2 -0
- package/lib/config/DB.js.map +1 -1
- package/lib/config/Interfaces/Helper/response.helper.interface.js +1 -0
- package/lib/config/Interfaces/Helper/response.helper.interface.js.map +1 -1
- package/lib/config/Keys/Keys.js +1 -0
- package/lib/config/Keys/Keys.js.map +1 -1
- package/lib/server/Fastify.d.ts +13 -0
- package/lib/server/Fastify.js +17 -2
- package/lib/server/Fastify.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description This class is responsible for caching data in memory
|
|
3
|
+
* @class InMemoryCache
|
|
4
|
+
* @export InMemoryCache
|
|
5
|
+
* @version 1.0.1
|
|
6
|
+
* @since 24 December 2024
|
|
7
|
+
**/
|
|
1
8
|
export default class InMemoryCache {
|
|
2
9
|
private readonly ttl;
|
|
3
10
|
private cacheObject;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new instance of the cache operation class
|
|
13
|
+
* @param TTL - Time to live in seconds for cache entries. Defaults to 60 seconds
|
|
14
|
+
*/
|
|
4
15
|
constructor(TTL?: string | number);
|
|
16
|
+
/**
|
|
17
|
+
* Sets a value in the cache with the specified key.
|
|
18
|
+
* The cached item will expire after the TTL (Time To Live) duration set for the cache.
|
|
19
|
+
*
|
|
20
|
+
* @param key - The unique identifier for the cached item
|
|
21
|
+
* @param value - The value to be stored in the cache
|
|
22
|
+
* @returns A Promise that resolves when the value has been cached
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* await cache.setCache('user-123', { name: 'John', age: 30 });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
5
29
|
setCache(key: string, value: any): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Retrieves a value from the cache using the specified key
|
|
32
|
+
* @param key - The unique identifier to lookup in the cache
|
|
33
|
+
* @returns A Promise that resolves to the cached value if found and not expired, null otherwise
|
|
34
|
+
*/
|
|
6
35
|
getCache(key: string): Promise<any>;
|
|
7
36
|
}
|
|
@@ -9,11 +9,36 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
13
|
+
/**
|
|
14
|
+
* @description This class is responsible for caching data in memory
|
|
15
|
+
* @class InMemoryCache
|
|
16
|
+
* @export InMemoryCache
|
|
17
|
+
* @version 1.0.1
|
|
18
|
+
* @since 24 December 2024
|
|
19
|
+
**/
|
|
12
20
|
class InMemoryCache {
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new instance of the cache operation class
|
|
23
|
+
* @param TTL - Time to live in seconds for cache entries. Defaults to 60 seconds
|
|
24
|
+
*/
|
|
13
25
|
constructor(TTL = 60) {
|
|
14
26
|
this.ttl = typeof TTL === "string" ? parseInt(TTL) : TTL;
|
|
15
27
|
this.cacheObject = {};
|
|
16
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Sets a value in the cache with the specified key.
|
|
31
|
+
* The cached item will expire after the TTL (Time To Live) duration set for the cache.
|
|
32
|
+
*
|
|
33
|
+
* @param key - The unique identifier for the cached item
|
|
34
|
+
* @param value - The value to be stored in the cache
|
|
35
|
+
* @returns A Promise that resolves when the value has been cached
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* await cache.setCache('user-123', { name: 'John', age: 30 });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
17
42
|
setCache(key, value) {
|
|
18
43
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19
44
|
this.cacheObject[key] = {
|
|
@@ -22,6 +47,11 @@ class InMemoryCache {
|
|
|
22
47
|
};
|
|
23
48
|
});
|
|
24
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Retrieves a value from the cache using the specified key
|
|
52
|
+
* @param key - The unique identifier to lookup in the cache
|
|
53
|
+
* @returns A Promise that resolves to the cached value if found and not expired, null otherwise
|
|
54
|
+
*/
|
|
25
55
|
getCache(key) {
|
|
26
56
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
57
|
const cacheItem = this.cacheObject[key];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.operation.js","sourceRoot":"","sources":["../../source/Caching/cache.operation.ts"],"names":[],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"cache.operation.js","sourceRoot":"","sources":["../../source/Caching/cache.operation.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,uDAAuD;AACvD;;;;;;IAMI;AACJ,MAAqB,aAAa;IAKhC;;;OAGG;IACH,YAAY,MAAuB,EAAE;QACnC,IAAI,CAAC,GAAG,GAAG,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QACzD,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;IACxB,CAAC;IAED;;;;;;;;;;;;OAYG;IACU,QAAQ,CAAC,GAAW,EAAE,KAAU;;YAC3C,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG;gBACtB,KAAK,EAAE,KAAK;gBACZ,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,GAAG,IAAI;aACrC,CAAC;QACJ,CAAC;KAAA;IAED;;;;OAIG;IACU,QAAQ,CAAC,GAAW;;YAC/B,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;YACxC,IAAI,CAAC,SAAS,EAAE,CAAC;gBACf,OAAO,IAAI,CAAC;YACd,CAAC;YACD,IAAI,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;gBAClC,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;gBAC7B,OAAO,IAAI,CAAC;YACd,CAAC;YACD,OAAO,SAAS,CAAC,KAAK,CAAC;QACzB,CAAC;KAAA;CACF;AAlDD,gCAkDC"}
|
|
@@ -1,8 +1,33 @@
|
|
|
1
1
|
export default class Converter {
|
|
2
2
|
constructor();
|
|
3
|
+
/**
|
|
4
|
+
* Converts a string to a boolean.
|
|
5
|
+
* @param value The string to convert.
|
|
6
|
+
* @returns The boolean value.
|
|
7
|
+
*/
|
|
3
8
|
ToBoolean(value: string): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Converts a string to a number.
|
|
11
|
+
* @param value The string to convert.
|
|
12
|
+
* @returns The number value.
|
|
13
|
+
*/
|
|
4
14
|
ToNumber(value: string): number;
|
|
15
|
+
/**
|
|
16
|
+
* Converts a string to a JSON object.
|
|
17
|
+
* @param value The string to convert.
|
|
18
|
+
* @returns The JSON object.
|
|
19
|
+
*/
|
|
5
20
|
ToObject(value: string): object;
|
|
21
|
+
/**
|
|
22
|
+
* Converts a JSON object to a string.
|
|
23
|
+
* @param value The JSON object to convert.
|
|
24
|
+
* @returns The string.
|
|
25
|
+
*/
|
|
6
26
|
ToString(value: object): string;
|
|
27
|
+
/**
|
|
28
|
+
* Converts a string to a string array.
|
|
29
|
+
* @param value The string to convert.
|
|
30
|
+
* @returns The string array.
|
|
31
|
+
*/
|
|
7
32
|
ToStringArray(value: string): string[];
|
|
8
33
|
}
|
|
@@ -1,19 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
class Converter {
|
|
4
|
-
constructor() { }
|
|
4
|
+
constructor() { } // Empty constructor
|
|
5
|
+
/**
|
|
6
|
+
* Converts a string to a boolean.
|
|
7
|
+
* @param value The string to convert.
|
|
8
|
+
* @returns The boolean value.
|
|
9
|
+
*/
|
|
5
10
|
ToBoolean(value) {
|
|
6
11
|
return value === "true";
|
|
7
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Converts a string to a number.
|
|
15
|
+
* @param value The string to convert.
|
|
16
|
+
* @returns The number value.
|
|
17
|
+
*/
|
|
8
18
|
ToNumber(value) {
|
|
9
19
|
return parseInt(value);
|
|
10
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Converts a string to a JSON object.
|
|
23
|
+
* @param value The string to convert.
|
|
24
|
+
* @returns The JSON object.
|
|
25
|
+
*/
|
|
11
26
|
ToObject(value) {
|
|
12
27
|
return JSON.parse(value);
|
|
13
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Converts a JSON object to a string.
|
|
31
|
+
* @param value The JSON object to convert.
|
|
32
|
+
* @returns The string.
|
|
33
|
+
*/
|
|
14
34
|
ToString(value) {
|
|
15
35
|
return JSON.stringify(value);
|
|
16
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Converts a string to a string array.
|
|
39
|
+
* @param value The string to convert.
|
|
40
|
+
* @returns The string array.
|
|
41
|
+
*/
|
|
17
42
|
ToStringArray(value) {
|
|
18
43
|
return value.split(",");
|
|
19
44
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Converter.helper.js","sourceRoot":"","sources":["../../source/Helper/Converter.helper.ts"],"names":[],"mappings":";;AAAA,MAAqB,SAAS;IAC5B,gBAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"Converter.helper.js","sourceRoot":"","sources":["../../source/Helper/Converter.helper.ts"],"names":[],"mappings":";;AAAA,MAAqB,SAAS;IAC5B,gBAAe,CAAC,CAAC,oBAAoB;IAErC;;;;OAIG;IACI,SAAS,CAAC,KAAa;QAC5B,OAAO,KAAK,KAAK,MAAM,CAAC;IAC1B,CAAC;IAED;;;;OAIG;IAEI,QAAQ,CAAC,KAAa;QAC3B,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC;IAED;;;;OAIG;IACI,QAAQ,CAAC,KAAa;QAC3B,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC;IAED;;;;OAIG;IACI,QAAQ,CAAC,KAAa;QAC3B,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IAED;;;;OAIG;IAEI,aAAa,CAAC,KAAa;QAChC,OAAO,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;CACF;AAjDD,4BAiDC"}
|
|
@@ -1,13 +1,57 @@
|
|
|
1
1
|
import { SuccessInterface } from "../config/Interfaces/Helper/response.helper.interface";
|
|
2
|
+
/**
|
|
3
|
+
* Helper class for cryptographic operations such as encryption and decryption.
|
|
4
|
+
*/
|
|
2
5
|
export declare class CryptoHelper {
|
|
6
|
+
/**
|
|
7
|
+
* The encryption key used for cryptographic operations.
|
|
8
|
+
*/
|
|
3
9
|
private encryptionKey;
|
|
10
|
+
/**
|
|
11
|
+
* Instance of ResponseHelper to handle responses.
|
|
12
|
+
*/
|
|
4
13
|
private readonly responseHelper;
|
|
14
|
+
/**
|
|
15
|
+
* Instance of Cryptography class for performing cryptographic operations.
|
|
16
|
+
*/
|
|
5
17
|
private readonly Cryptography;
|
|
18
|
+
/**
|
|
19
|
+
* Instance of Converter class for converting data formats.
|
|
20
|
+
*/
|
|
6
21
|
private readonly Converter;
|
|
22
|
+
/**
|
|
23
|
+
* Constructor to initialize the CryptoHelper class.
|
|
24
|
+
* @param encryptionKey - Optional encryption key. If not provided, a default key based on hostname and platform will be used.
|
|
25
|
+
*/
|
|
7
26
|
constructor(encryptionKey?: string);
|
|
27
|
+
/**
|
|
28
|
+
* Sets a new encryption key.
|
|
29
|
+
* @param encryptionKey - The new encryption key to be set.
|
|
30
|
+
* @returns A promise that resolves to a success response.
|
|
31
|
+
*/
|
|
8
32
|
setEncryptionKey(encryptionKey: string): Promise<SuccessInterface>;
|
|
33
|
+
/**
|
|
34
|
+
* Encrypts data asynchronously.
|
|
35
|
+
* @param data - The data to be encrypted.
|
|
36
|
+
* @returns A promise that resolves to the encrypted data as a string.
|
|
37
|
+
*/
|
|
9
38
|
encrypt(data: string): Promise<string>;
|
|
39
|
+
/**
|
|
40
|
+
* Decrypts data asynchronously.
|
|
41
|
+
* @param data - The data to be decrypted.
|
|
42
|
+
* @returns A promise that resolves to the decrypted data as an object.
|
|
43
|
+
*/
|
|
10
44
|
decrypt(data: string): Promise<object>;
|
|
45
|
+
/**
|
|
46
|
+
* Encrypts data synchronously.
|
|
47
|
+
* @param data - The data to be encrypted.
|
|
48
|
+
* @returns The encrypted data as a string.
|
|
49
|
+
*/
|
|
11
50
|
encryptSync(data: string): string;
|
|
51
|
+
/**
|
|
52
|
+
* Decrypts data synchronously.
|
|
53
|
+
* @param data - The data to be decrypted.
|
|
54
|
+
* @returns The decrypted data as an object.
|
|
55
|
+
*/
|
|
12
56
|
decryptSync(data: string): object;
|
|
13
57
|
}
|
|
@@ -13,38 +13,78 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.CryptoHelper = void 0;
|
|
16
|
+
// All Imports
|
|
16
17
|
const node_os_1 = require("node:os");
|
|
17
18
|
const response_helper_1 = __importDefault(require("./response.helper"));
|
|
18
19
|
const outers_1 = require("outers");
|
|
19
20
|
const Converter_helper_1 = __importDefault(require("./Converter.helper"));
|
|
21
|
+
/**
|
|
22
|
+
* Helper class for cryptographic operations such as encryption and decryption.
|
|
23
|
+
*/
|
|
20
24
|
class CryptoHelper {
|
|
25
|
+
/**
|
|
26
|
+
* Constructor to initialize the CryptoHelper class.
|
|
27
|
+
* @param encryptionKey - Optional encryption key. If not provided, a default key based on hostname and platform will be used.
|
|
28
|
+
*/
|
|
21
29
|
constructor(encryptionKey) {
|
|
30
|
+
/**
|
|
31
|
+
* Instance of ResponseHelper to handle responses.
|
|
32
|
+
*/
|
|
22
33
|
this.responseHelper = new response_helper_1.default();
|
|
34
|
+
/**
|
|
35
|
+
* Instance of Converter class for converting data formats.
|
|
36
|
+
*/
|
|
23
37
|
this.Converter = new Converter_helper_1.default();
|
|
24
38
|
this.encryptionKey = encryptionKey || `${(0, node_os_1.hostname)()}-${(0, node_os_1.platform)()}`;
|
|
25
39
|
this.responseHelper = new response_helper_1.default();
|
|
26
40
|
this.Cryptography = new outers_1.ClassBased.CryptoGraphy(this.encryptionKey);
|
|
27
41
|
this.Converter = new Converter_helper_1.default();
|
|
28
42
|
}
|
|
43
|
+
// methods
|
|
44
|
+
/**
|
|
45
|
+
* Sets a new encryption key.
|
|
46
|
+
* @param encryptionKey - The new encryption key to be set.
|
|
47
|
+
* @returns A promise that resolves to a success response.
|
|
48
|
+
*/
|
|
29
49
|
setEncryptionKey(encryptionKey) {
|
|
30
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
31
51
|
this.encryptionKey = encryptionKey;
|
|
32
52
|
return this.responseHelper.Success("Encryption key has been set successfully");
|
|
33
53
|
});
|
|
34
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Encrypts data asynchronously.
|
|
57
|
+
* @param data - The data to be encrypted.
|
|
58
|
+
* @returns A promise that resolves to the encrypted data as a string.
|
|
59
|
+
*/
|
|
35
60
|
encrypt(data) {
|
|
36
61
|
return __awaiter(this, void 0, void 0, function* () {
|
|
37
62
|
return yield this.Cryptography.Encrypt(data);
|
|
38
63
|
});
|
|
39
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Decrypts data asynchronously.
|
|
67
|
+
* @param data - The data to be decrypted.
|
|
68
|
+
* @returns A promise that resolves to the decrypted data as an object.
|
|
69
|
+
*/
|
|
40
70
|
decrypt(data) {
|
|
41
71
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
72
|
return this.Converter.ToObject(yield this.Cryptography.Decrypt(data));
|
|
43
73
|
});
|
|
44
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Encrypts data synchronously.
|
|
77
|
+
* @param data - The data to be encrypted.
|
|
78
|
+
* @returns The encrypted data as a string.
|
|
79
|
+
*/
|
|
45
80
|
encryptSync(data) {
|
|
46
81
|
return this.Cryptography.EncryptSync(data);
|
|
47
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Decrypts data synchronously.
|
|
85
|
+
* @param data - The data to be decrypted.
|
|
86
|
+
* @returns The decrypted data as an object.
|
|
87
|
+
*/
|
|
48
88
|
decryptSync(data) {
|
|
49
89
|
return this.Converter.ToObject(this.Cryptography.DecryptSync(data));
|
|
50
90
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Crypto.helper.js","sourceRoot":"","sources":["../../source/Helper/Crypto.helper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"Crypto.helper.js","sourceRoot":"","sources":["../../source/Helper/Crypto.helper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,cAAc;AACd,qCAA6C;AAC7C,wEAA+C;AAE/C,mCAAoC;AACpC,0EAA2C;AAE3C;;GAEG;AACH,MAAa,YAAY;IAsBvB;;;OAGG;IACH,YAAY,aAAsB;QAnBlC;;WAEG;QACc,mBAAc,GAAmB,IAAI,yBAAc,EAAE,CAAC;QAOvE;;WAEG;QACc,cAAS,GAAG,IAAI,0BAAS,EAAE,CAAC;QAO3C,IAAI,CAAC,aAAa,GAAG,aAAa,IAAI,GAAG,IAAA,kBAAQ,GAAE,IAAI,IAAA,kBAAQ,GAAE,EAAE,CAAC;QACpE,IAAI,CAAC,cAAc,GAAG,IAAI,yBAAc,EAAE,CAAC;QAC3C,IAAI,CAAC,YAAY,GAAG,IAAI,mBAAU,CAAC,YAAY,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QACpE,IAAI,CAAC,SAAS,GAAG,IAAI,0BAAS,EAAE,CAAC;IACnC,CAAC;IAED,UAAU;IACV;;;;OAIG;IACU,gBAAgB,CAC3B,aAAqB;;YAErB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;YACnC,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,CAChC,0CAA0C,CAC3C,CAAC;QACJ,CAAC;KAAA;IAED;;;;OAIG;IACU,OAAO,CAAC,IAAY;;YAC/B,OAAO,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC/C,CAAC;KAAA;IAED;;;;OAIG;IACU,OAAO,CAAC,IAAY;;YAC/B,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QACxE,CAAC;KAAA;IAED;;;;OAIG;IACI,WAAW,CAAC,IAAY;QAC7B,OAAO,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAC7C,CAAC;IAED;;;;OAIG;IACI,WAAW,CAAC,IAAY;QAC7B,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;IACtE,CAAC;CACF;AAnFD,oCAmFC"}
|
|
@@ -1,8 +1,56 @@
|
|
|
1
1
|
import { ErrorInterface, SuccessInterface } from "../config/Interfaces/Helper/response.helper.interface";
|
|
2
|
+
/**
|
|
3
|
+
* @class ResponseHelper
|
|
4
|
+
* @description A helper class to standardize API responses.
|
|
5
|
+
*
|
|
6
|
+
* @property {number} SucessCode - The HTTP status code for a successful response.
|
|
7
|
+
* @property {number} ErrorCode - The HTTP status code for an error response.
|
|
8
|
+
*
|
|
9
|
+
* @constructor
|
|
10
|
+
* Initializes the ResponseHelper with default status codes.
|
|
11
|
+
*
|
|
12
|
+
* @method Success
|
|
13
|
+
* @async
|
|
14
|
+
* @param {any} [data] - Optional data to include in the success response.
|
|
15
|
+
* @returns {Promise<SuccessInterface>} A promise that resolves to a success response object.
|
|
16
|
+
*
|
|
17
|
+
* @method Error
|
|
18
|
+
* @async
|
|
19
|
+
* @param {string} [message] - Optional error message to include in the error response.
|
|
20
|
+
* @returns {Promise<ErrorInterface>} A promise that resolves to an error response object.
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* A helper class for generating standardized success and error response objects.
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
* This class provides methods to generate success and error responses with predefined status codes.
|
|
27
|
+
* It uses the `StatusCodes` enumeration to set the HTTP status codes for success and error responses.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const responseHelper = new ResponseHelper();
|
|
32
|
+
* const successResponse = await responseHelper.Success({ key: 'value' });
|
|
33
|
+
* const errorResponse = await responseHelper.Error('An error occurred');
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
2
38
|
export default class ResponseHelper {
|
|
3
39
|
private SucessCode;
|
|
4
40
|
private ErrorCode;
|
|
5
41
|
constructor();
|
|
42
|
+
/**
|
|
43
|
+
* Generates a success response object.
|
|
44
|
+
*
|
|
45
|
+
* @param data - Optional data to include in the success response.
|
|
46
|
+
* @returns A promise that resolves to a success response object implementing the SuccessInterface.
|
|
47
|
+
*/
|
|
6
48
|
Success(data?: any): Promise<SuccessInterface>;
|
|
49
|
+
/**
|
|
50
|
+
* Generates an error response object.
|
|
51
|
+
*
|
|
52
|
+
* @param {string} [message] - Optional error message to include in the response.
|
|
53
|
+
* @returns {Promise<ErrorInterface>} A promise that resolves to an error response object.
|
|
54
|
+
*/
|
|
7
55
|
Error(message?: any): Promise<ErrorInterface>;
|
|
8
56
|
}
|
|
@@ -9,12 +9,56 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
// Purpose: Helper class for response.
|
|
12
13
|
const outers_1 = require("outers");
|
|
14
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
15
|
+
/**
|
|
16
|
+
* @class ResponseHelper
|
|
17
|
+
* @description A helper class to standardize API responses.
|
|
18
|
+
*
|
|
19
|
+
* @property {number} SucessCode - The HTTP status code for a successful response.
|
|
20
|
+
* @property {number} ErrorCode - The HTTP status code for an error response.
|
|
21
|
+
*
|
|
22
|
+
* @constructor
|
|
23
|
+
* Initializes the ResponseHelper with default status codes.
|
|
24
|
+
*
|
|
25
|
+
* @method Success
|
|
26
|
+
* @async
|
|
27
|
+
* @param {any} [data] - Optional data to include in the success response.
|
|
28
|
+
* @returns {Promise<SuccessInterface>} A promise that resolves to a success response object.
|
|
29
|
+
*
|
|
30
|
+
* @method Error
|
|
31
|
+
* @async
|
|
32
|
+
* @param {string} [message] - Optional error message to include in the error response.
|
|
33
|
+
* @returns {Promise<ErrorInterface>} A promise that resolves to an error response object.
|
|
34
|
+
*/
|
|
35
|
+
/**
|
|
36
|
+
* A helper class for generating standardized success and error response objects.
|
|
37
|
+
*
|
|
38
|
+
* @remarks
|
|
39
|
+
* This class provides methods to generate success and error responses with predefined status codes.
|
|
40
|
+
* It uses the `StatusCodes` enumeration to set the HTTP status codes for success and error responses.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const responseHelper = new ResponseHelper();
|
|
45
|
+
* const successResponse = await responseHelper.Success({ key: 'value' });
|
|
46
|
+
* const errorResponse = await responseHelper.Error('An error occurred');
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
13
51
|
class ResponseHelper {
|
|
14
52
|
constructor() {
|
|
15
53
|
this.SucessCode = outers_1.StatusCodes.OK;
|
|
16
54
|
this.ErrorCode = outers_1.StatusCodes.INTERNAL_SERVER_ERROR;
|
|
17
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Generates a success response object.
|
|
58
|
+
*
|
|
59
|
+
* @param data - Optional data to include in the success response.
|
|
60
|
+
* @returns A promise that resolves to a success response object implementing the SuccessInterface.
|
|
61
|
+
*/
|
|
18
62
|
Success(data) {
|
|
19
63
|
return __awaiter(this, void 0, void 0, function* () {
|
|
20
64
|
return {
|
|
@@ -24,6 +68,12 @@ class ResponseHelper {
|
|
|
24
68
|
};
|
|
25
69
|
});
|
|
26
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Generates an error response object.
|
|
73
|
+
*
|
|
74
|
+
* @param {string} [message] - Optional error message to include in the response.
|
|
75
|
+
* @returns {Promise<ErrorInterface>} A promise that resolves to an error response object.
|
|
76
|
+
*/
|
|
27
77
|
Error(message) {
|
|
28
78
|
return __awaiter(this, void 0, void 0, function* () {
|
|
29
79
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response.helper.js","sourceRoot":"","sources":["../../source/Helper/response.helper.ts"],"names":[],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"response.helper.js","sourceRoot":"","sources":["../../source/Helper/response.helper.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,sCAAsC;AACtC,mCAAqC;AAQrC,uDAAuD;AACvD;;;;;;;;;;;;;;;;;;;GAmBG;AACH;;;;;;;;;;;;;;;GAeG;AACH,MAAqB,cAAc;IAKjC;QACE,IAAI,CAAC,UAAU,GAAG,oBAAW,CAAC,EAAE,CAAC;QACjC,IAAI,CAAC,SAAS,GAAG,oBAAW,CAAC,qBAAqB,CAAC;IACrD,CAAC;IAED;;;;;OAKG;IACU,OAAO,CAAC,IAAU;;YAC7B,OAAO;gBACL,UAAU,EAAE,IAAI,CAAC,UAAU;gBAC3B,MAAM,EAAE,IAAI;gBACZ,IAAI,EAAE,IAAI;aACX,CAAC;QACJ,CAAC;KAAA;IAED;;;;;OAKG;IACU,KAAK,CAAC,OAAa;;YAC9B,OAAO;gBACL,UAAU,EAAE,IAAI,CAAC,SAAS;gBAC1B,MAAM,EAAE,KAAK;gBACb,OAAO,EAAE,OAAO;aACjB,CAAC;QACJ,CAAC;KAAA;CACF;AArCD,iCAqCC"}
|
|
@@ -4,7 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.SchemaTypes = void 0;
|
|
7
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
7
8
|
const joi_1 = __importDefault(require("joi"));
|
|
9
|
+
// Create an object to hold all Joi types under the name SchemaTypes
|
|
8
10
|
exports.SchemaTypes = {
|
|
9
11
|
string: joi_1.default.string,
|
|
10
12
|
number: joi_1.default.number,
|
|
@@ -16,6 +18,7 @@ exports.SchemaTypes = {
|
|
|
16
18
|
func: joi_1.default.func,
|
|
17
19
|
ref: joi_1.default.ref,
|
|
18
20
|
any: joi_1.default.any,
|
|
21
|
+
// Add additional types from Joi if needed
|
|
19
22
|
alphanum: joi_1.default.string().alphanum,
|
|
20
23
|
email: joi_1.default.string().email,
|
|
21
24
|
guid: joi_1.default.string().guid,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataTypes.models.js","sourceRoot":"","sources":["../../source/Models/DataTypes.models.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"DataTypes.models.js","sourceRoot":"","sources":["../../source/Models/DataTypes.models.ts"],"names":[],"mappings":";;;;;;AAAA,uDAAuD;AACvD,8CAAsB;AAEtB,oEAAoE;AACvD,QAAA,WAAW,GAAG;IACzB,MAAM,EAAE,aAAG,CAAC,MAAM;IAClB,MAAM,EAAE,aAAG,CAAC,MAAM;IAClB,OAAO,EAAE,aAAG,CAAC,OAAO;IACpB,MAAM,EAAE,aAAG,CAAC,MAAM;IAClB,KAAK,EAAE,aAAG,CAAC,KAAK;IAChB,IAAI,EAAE,aAAG,CAAC,IAAI;IACd,MAAM,EAAE,aAAG,CAAC,MAAM;IAClB,IAAI,EAAE,aAAG,CAAC,IAAI;IACd,GAAG,EAAE,aAAG,CAAC,GAAG;IACZ,GAAG,EAAE,aAAG,CAAC,GAAG;IACZ,0CAA0C;IAC1C,QAAQ,EAAE,aAAG,CAAC,MAAM,EAAE,CAAC,QAAQ;IAC/B,KAAK,EAAE,aAAG,CAAC,MAAM,EAAE,CAAC,KAAK;IACzB,IAAI,EAAE,aAAG,CAAC,MAAM,EAAE,CAAC,IAAI;IACvB,EAAE,EAAE,aAAG,CAAC,MAAM,EAAE,CAAC,EAAE;IACnB,GAAG,EAAE,aAAG,CAAC,MAAM,EAAE,CAAC,GAAG;IACrB,GAAG,EAAE,CAAC,KAA6B,EAAE,EAAE,CAAC,aAAG,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC;IAC/D,GAAG,EAAE,CAAC,KAA6B,EAAE,EAAE,CAAC,aAAG,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC;IAC/D,MAAM,EAAE,CAAC,KAA6B,EAAE,EAAE,CAAC,aAAG,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC;IACrE,OAAO,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,aAAG,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;IACvD,QAAQ,EAAE,GAAG,EAAE,CAAC,aAAG,CAAC,QAAQ,EAAE;IAC9B,QAAQ,EAAE,GAAG,EAAE,CAAC,aAAG,CAAC,QAAQ,EAAE;IAC9B,KAAK,EAAE,CAAC,MAAa,EAAE,EAAE,CAAC,aAAG,CAAC,KAAK,CAAC,MAAM,CAAC;IAC3C,KAAK,EAAE,CAAC,MAAa,EAAE,EAAE,CAAC,aAAG,CAAC,KAAK,CAAC,MAAM,CAAC;CAC5C,CAAC"}
|
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
import { Schema } from "joi";
|
|
2
|
+
/**
|
|
3
|
+
* Validates the provided data against the given Joi schema.
|
|
4
|
+
*
|
|
5
|
+
* @param dataSchema - The Joi schema to validate against.
|
|
6
|
+
* @param data - The data to be validated.
|
|
7
|
+
* @returns A promise that resolves with the validated data if validation is successful, or rejects with a validation error.
|
|
8
|
+
*/
|
|
2
9
|
export default function schemaValidate(dataSchema: Schema, data: any): Promise<any>;
|
|
@@ -13,12 +13,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.default = schemaValidate;
|
|
16
|
-
|
|
16
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
17
|
+
const joi_1 = __importDefault(require("joi")); // Ensure to import Joi correctly
|
|
18
|
+
/**
|
|
19
|
+
* Validates the provided data against the given Joi schema.
|
|
20
|
+
*
|
|
21
|
+
* @param dataSchema - The Joi schema to validate against.
|
|
22
|
+
* @param data - The data to be validated.
|
|
23
|
+
* @returns A promise that resolves with the validated data if validation is successful, or rejects with a validation error.
|
|
24
|
+
*/
|
|
17
25
|
function schemaValidate(dataSchema, data) {
|
|
18
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19
27
|
try {
|
|
20
|
-
|
|
21
|
-
|
|
28
|
+
// Use Joi.object() correctly to wrap the schema and validate data.
|
|
29
|
+
const joiSchema = joi_1.default.object(dataSchema); // Converts the provided schema to a Joi object
|
|
30
|
+
return yield joiSchema.validateAsync(data); // Validate the actual data against the schema
|
|
22
31
|
}
|
|
23
32
|
catch (error) {
|
|
24
33
|
return error;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.models.js","sourceRoot":"","sources":["../../source/Models/validator.models.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAUA,iCAWC;
|
|
1
|
+
{"version":3,"file":"validator.models.js","sourceRoot":"","sources":["../../source/Models/validator.models.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAUA,iCAWC;AArBD,uDAAuD;AACvD,8CAAkC,CAAC,iCAAiC;AAEpE;;;;;;GAMG;AACH,SAA8B,cAAc,CAC1C,UAAkB,EAClB,IAAS;;QAET,IAAI,CAAC;YACH,mEAAmE;YACnE,MAAM,SAAS,GAAG,aAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,+CAA+C;YACzF,OAAO,MAAM,SAAS,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,8CAA8C;QAC5F,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CAAA"}
|
|
@@ -1,8 +1,25 @@
|
|
|
1
1
|
import { ErrorInterface, SuccessInterface } from "../../config/Interfaces/Helper/response.helper.interface";
|
|
2
|
+
/**
|
|
3
|
+
* Class representing an insertion operation.
|
|
4
|
+
*/
|
|
2
5
|
export default class Insertion {
|
|
3
6
|
private readonly collectionName;
|
|
4
7
|
private readonly path;
|
|
5
|
-
|
|
8
|
+
private readonly Converter;
|
|
9
|
+
/**
|
|
10
|
+
* Creates an instance of Insertion.
|
|
11
|
+
* @param {string} collectionName - The name of the collection.
|
|
12
|
+
* @param {string | any} path - The data to be inserted.
|
|
13
|
+
*/
|
|
14
|
+
constructor(collectionName: string, path: string | any);
|
|
15
|
+
/**
|
|
16
|
+
* Saves the data to a file.
|
|
17
|
+
* @returns {Promise<any>} A promise that resolves with the response of the save operation.
|
|
18
|
+
*/
|
|
6
19
|
Save(data: object | any): Promise<SuccessInterface | ErrorInterface>;
|
|
20
|
+
/**
|
|
21
|
+
* Generates a unique document ID.
|
|
22
|
+
* @returns {Promise<string>} A promise that resolves with a unique document ID.
|
|
23
|
+
*/
|
|
7
24
|
private generateUniqueDocumentId;
|
|
8
25
|
}
|