@forklaunch/core 0.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 (71) hide show
  1. package/dist/cache/interfaces/ttlCache.interface.d.ts +47 -0
  2. package/dist/cache/interfaces/ttlCache.interface.js +3 -0
  3. package/dist/cache/interfaces/ttlCache.interface.js.map +1 -0
  4. package/dist/cache/redisTtlCache.d.ts +64 -0
  5. package/dist/cache/redisTtlCache.js +105 -0
  6. package/dist/cache/redisTtlCache.js.map +1 -0
  7. package/dist/cache/types/ttlCacheRecord.d.ts +13 -0
  8. package/dist/cache/types/ttlCacheRecord.js +3 -0
  9. package/dist/cache/types/ttlCacheRecord.js.map +1 -0
  10. package/dist/controllers/interfaces/controller.interface.d.ts +15 -0
  11. package/dist/controllers/interfaces/controller.interface.js +3 -0
  12. package/dist/controllers/interfaces/controller.interface.js.map +1 -0
  13. package/dist/database/mikro/models/entities/base.entity.d.ts +25 -0
  14. package/dist/database/mikro/models/entities/base.entity.js +53 -0
  15. package/dist/database/mikro/models/entities/base.entity.js.map +1 -0
  16. package/dist/entityMapper/interfaces/entityMapper.interface.d.ts +16 -0
  17. package/dist/entityMapper/interfaces/entityMapper.interface.js +3 -0
  18. package/dist/entityMapper/interfaces/entityMapper.interface.js.map +1 -0
  19. package/dist/entityMapper/models/baseEntityMapper.model.d.ts +71 -0
  20. package/dist/entityMapper/models/baseEntityMapper.model.js +81 -0
  21. package/dist/entityMapper/models/baseEntityMapper.model.js.map +1 -0
  22. package/dist/entityMapper/models/requestEntityMapper.model.d.ts +69 -0
  23. package/dist/entityMapper/models/requestEntityMapper.model.js +77 -0
  24. package/dist/entityMapper/models/requestEntityMapper.model.js.map +1 -0
  25. package/dist/entityMapper/models/responseEntityMapper.model.d.ts +60 -0
  26. package/dist/entityMapper/models/responseEntityMapper.model.js +64 -0
  27. package/dist/entityMapper/models/responseEntityMapper.model.js.map +1 -0
  28. package/dist/entityMapper/types/entityMapper.types.d.ts +28 -0
  29. package/dist/entityMapper/types/entityMapper.types.js +3 -0
  30. package/dist/entityMapper/types/entityMapper.types.js.map +1 -0
  31. package/dist/http/middlewares/request.middleware.d.ts +11 -0
  32. package/dist/http/middlewares/request.middleware.js +187 -0
  33. package/dist/http/middlewares/request.middleware.js.map +1 -0
  34. package/dist/http/middlewares/response.middleware.d.ts +2 -0
  35. package/dist/http/middlewares/response.middleware.js +30 -0
  36. package/dist/http/middlewares/response.middleware.js.map +1 -0
  37. package/dist/http/types/api.types.d.ts +50 -0
  38. package/dist/http/types/api.types.js +3 -0
  39. package/dist/http/types/api.types.js.map +1 -0
  40. package/dist/http/types/primitive.types.d.ts +35 -0
  41. package/dist/http/types/primitive.types.js +3 -0
  42. package/dist/http/types/primitive.types.js.map +1 -0
  43. package/dist/index.d.ts +1 -0
  44. package/dist/index.js +8 -0
  45. package/dist/index.js.map +1 -0
  46. package/dist/jest.config.d.ts +3 -0
  47. package/dist/jest.config.js.map +1 -0
  48. package/dist/services/interfaces/baseService.d.ts +14 -0
  49. package/dist/services/interfaces/baseService.js +3 -0
  50. package/dist/services/interfaces/baseService.js.map +1 -0
  51. package/dist/tests/dto.test.d.ts +1 -0
  52. package/dist/tests/dto.test.js +179 -0
  53. package/dist/tests/dto.test.js.map +1 -0
  54. package/dist/tests/redisTtlCache.test.d.ts +1 -0
  55. package/dist/tests/redisTtlCache.test.js +35 -0
  56. package/dist/tests/redisTtlCache.test.js.map +1 -0
  57. package/entityMapper/interfaces/entityMapper.interface.ts +17 -0
  58. package/entityMapper/models/baseEntityMapper.model.ts +93 -0
  59. package/entityMapper/models/requestEntityMapper.model.ts +91 -0
  60. package/entityMapper/models/responseEntityMapper.model.ts +77 -0
  61. package/entityMapper/types/entityMapper.types.ts +29 -0
  62. package/eslint.config.mjs +12 -0
  63. package/http/middlewares/request.middleware.ts +201 -0
  64. package/http/middlewares/response.middleware.ts +37 -0
  65. package/http/types/api.types.ts +65 -0
  66. package/http/types/primitive.types.ts +55 -0
  67. package/index.ts +5 -0
  68. package/jest.config.ts +10 -0
  69. package/package.json +47 -0
  70. package/tests/dto.test.ts +235 -0
  71. package/tests/redisTtlCache.test.ts +42 -0
@@ -0,0 +1,47 @@
1
+ import { TtlCacheRecord } from "../types/ttlCacheRecord";
2
+ /**
3
+ * Interface representing a TTL (Time-To-Live) cache.
4
+ */
5
+ export interface TtlCache {
6
+ /**
7
+ * Puts a record into the cache.
8
+ *
9
+ * @param {TtlCacheRecord} cacheRecord - The cache record to put into the cache.
10
+ * @returns {Promise<void>} - A promise that resolves when the record is put into the cache.
11
+ */
12
+ putRecord(cacheRecord: TtlCacheRecord): Promise<void>;
13
+ /**
14
+ * Deletes a record from the cache.
15
+ *
16
+ * @param {string} cacheRecordKey - The key of the cache record to delete.
17
+ * @returns {Promise<void>} - A promise that resolves when the record is deleted from the cache.
18
+ */
19
+ deleteRecord(cacheRecordKey: string): Promise<void>;
20
+ /**
21
+ * Reads a record from the cache.
22
+ *
23
+ * @param {string} cacheRecordKey - The key of the cache record to read.
24
+ * @returns {Promise<TtlCacheRecord>} - A promise that resolves with the cache record.
25
+ */
26
+ readRecord(cacheRecordKey: string): Promise<TtlCacheRecord>;
27
+ /**
28
+ * Peeks at a record in the cache to check if it exists.
29
+ *
30
+ * @param {string} cacheRecordKey - The key of the cache record to peek at.
31
+ * @returns {Promise<boolean>} - A promise that resolves with a boolean indicating if the record exists.
32
+ */
33
+ peekRecord(cacheRecordKey: string): Promise<boolean>;
34
+ /**
35
+ * Gets the TTL (Time-To-Live) in milliseconds.
36
+ *
37
+ * @returns {number} - The TTL in milliseconds.
38
+ */
39
+ getTtlMilliseconds(): number;
40
+ /**
41
+ * Lists the keys in the cache that match a pattern prefix.
42
+ *
43
+ * @param {string} pattern_prefix - The pattern prefix to match.
44
+ * @returns {Promise<string[]>} - A promise that resolves with an array of keys matching the pattern prefix.
45
+ */
46
+ listKeys(pattern_prefix: string): Promise<string[]>;
47
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=ttlCache.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ttlCache.interface.js","sourceRoot":"","sources":["../../../cache/interfaces/ttlCache.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,64 @@
1
+ import { TtlCache } from './interfaces/ttlCache.interface';
2
+ import { TtlCacheRecord } from './types/ttlCacheRecord';
3
+ /**
4
+ * Class representing a Redis-based TTL (Time-To-Live) cache.
5
+ * Implements the TtlCache interface.
6
+ */
7
+ export declare class RedisTtlCache implements TtlCache {
8
+ private ttlMilliseconds;
9
+ private client;
10
+ /**
11
+ * Creates an instance of RedisTtlCache.
12
+ *
13
+ * @param {number} ttlMilliseconds - The default TTL in milliseconds.
14
+ */
15
+ constructor(ttlMilliseconds: number);
16
+ /**
17
+ * Puts a record into the Redis cache.
18
+ *
19
+ * @param {TtlCacheRecord} param0 - The cache record to put into the cache.
20
+ * @returns {Promise<void>} - A promise that resolves when the record is put into the cache.
21
+ */
22
+ putRecord({ key, value, ttlMilliseconds }: TtlCacheRecord): Promise<void>;
23
+ /**
24
+ * Deletes a record from the Redis cache.
25
+ *
26
+ * @param {string} cacheRecordKey - The key of the cache record to delete.
27
+ * @returns {Promise<void>} - A promise that resolves when the record is deleted from the cache.
28
+ */
29
+ deleteRecord(cacheRecordKey: string): Promise<void>;
30
+ /**
31
+ * Reads a record from the Redis cache.
32
+ *
33
+ * @param {string} cacheRecordKey - The key of the cache record to read.
34
+ * @returns {Promise<TtlCacheRecord>} - A promise that resolves with the cache record.
35
+ * @throws {Error} - Throws an error if the record is not found.
36
+ */
37
+ readRecord(cacheRecordKey: string): Promise<TtlCacheRecord>;
38
+ /**
39
+ * Lists the keys in the Redis cache that match a pattern prefix.
40
+ *
41
+ * @param {string} pattern_prefix - The pattern prefix to match.
42
+ * @returns {Promise<string[]>} - A promise that resolves with an array of keys matching the pattern prefix.
43
+ */
44
+ listKeys(pattern_prefix: string): Promise<string[]>;
45
+ /**
46
+ * Peeks at a record in the Redis cache to check if it exists.
47
+ *
48
+ * @param {string} cacheRecordKey - The key of the cache record to peek at.
49
+ * @returns {Promise<boolean>} - A promise that resolves with a boolean indicating if the record exists.
50
+ */
51
+ peekRecord(cacheRecordKey: string): Promise<boolean>;
52
+ /**
53
+ * Disconnects the Redis client.
54
+ *
55
+ * @returns {Promise<void>} - A promise that resolves when the client is disconnected.
56
+ */
57
+ disconnect(): Promise<void>;
58
+ /**
59
+ * Gets the default TTL (Time-To-Live) in milliseconds.
60
+ *
61
+ * @returns {number} - The TTL in milliseconds.
62
+ */
63
+ getTtlMilliseconds(): number;
64
+ }
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RedisTtlCache = void 0;
4
+ const redis_1 = require("redis");
5
+ /**
6
+ * Class representing a Redis-based TTL (Time-To-Live) cache.
7
+ * Implements the TtlCache interface.
8
+ */
9
+ class RedisTtlCache {
10
+ ttlMilliseconds;
11
+ client;
12
+ /**
13
+ * Creates an instance of RedisTtlCache.
14
+ *
15
+ * @param {number} ttlMilliseconds - The default TTL in milliseconds.
16
+ */
17
+ constructor(ttlMilliseconds) {
18
+ this.ttlMilliseconds = ttlMilliseconds;
19
+ // Connects to localhost:6379 by default
20
+ // url usage: redis[s]://[[username][:password]@][host][:port][/db-number]
21
+ this.client = (0, redis_1.createClient)();
22
+ this.client.on('error', (err) => console.log('Redis Client Error', err));
23
+ this.client.on('connect', () => {
24
+ console.log('\x1b[32m%s\x1b[0m', 'Successfully Connected to Redis'); // Green text
25
+ });
26
+ this.client.connect().catch(console.error);
27
+ }
28
+ /**
29
+ * Puts a record into the Redis cache.
30
+ *
31
+ * @param {TtlCacheRecord} param0 - The cache record to put into the cache.
32
+ * @returns {Promise<void>} - A promise that resolves when the record is put into the cache.
33
+ */
34
+ async putRecord({ key, value, ttlMilliseconds = this.ttlMilliseconds }) {
35
+ await this.client.set(key, JSON.stringify(value), {
36
+ PX: ttlMilliseconds
37
+ });
38
+ }
39
+ /**
40
+ * Deletes a record from the Redis cache.
41
+ *
42
+ * @param {string} cacheRecordKey - The key of the cache record to delete.
43
+ * @returns {Promise<void>} - A promise that resolves when the record is deleted from the cache.
44
+ */
45
+ async deleteRecord(cacheRecordKey) {
46
+ await this.client.del(cacheRecordKey);
47
+ }
48
+ /**
49
+ * Reads a record from the Redis cache.
50
+ *
51
+ * @param {string} cacheRecordKey - The key of the cache record to read.
52
+ * @returns {Promise<TtlCacheRecord>} - A promise that resolves with the cache record.
53
+ * @throws {Error} - Throws an error if the record is not found.
54
+ */
55
+ async readRecord(cacheRecordKey) {
56
+ const value = await this.client.get(cacheRecordKey);
57
+ if (value === null) {
58
+ throw new Error(`Record not found for key: ${cacheRecordKey}`);
59
+ }
60
+ const ttl = await this.client.ttl(cacheRecordKey); // Fetch TTL from Redis
61
+ return {
62
+ key: cacheRecordKey,
63
+ value: JSON.parse(value),
64
+ ttlMilliseconds: ttl * 1000
65
+ };
66
+ }
67
+ /**
68
+ * Lists the keys in the Redis cache that match a pattern prefix.
69
+ *
70
+ * @param {string} pattern_prefix - The pattern prefix to match.
71
+ * @returns {Promise<string[]>} - A promise that resolves with an array of keys matching the pattern prefix.
72
+ */
73
+ async listKeys(pattern_prefix) {
74
+ const keys = await this.client.keys(pattern_prefix + '*');
75
+ return keys;
76
+ }
77
+ /**
78
+ * Peeks at a record in the Redis cache to check if it exists.
79
+ *
80
+ * @param {string} cacheRecordKey - The key of the cache record to peek at.
81
+ * @returns {Promise<boolean>} - A promise that resolves with a boolean indicating if the record exists.
82
+ */
83
+ async peekRecord(cacheRecordKey) {
84
+ const result = await this.client.exists(cacheRecordKey);
85
+ return result === 1;
86
+ }
87
+ /**
88
+ * Disconnects the Redis client.
89
+ *
90
+ * @returns {Promise<void>} - A promise that resolves when the client is disconnected.
91
+ */
92
+ async disconnect() {
93
+ await this.client.quit();
94
+ }
95
+ /**
96
+ * Gets the default TTL (Time-To-Live) in milliseconds.
97
+ *
98
+ * @returns {number} - The TTL in milliseconds.
99
+ */
100
+ getTtlMilliseconds() {
101
+ return this.ttlMilliseconds;
102
+ }
103
+ }
104
+ exports.RedisTtlCache = RedisTtlCache;
105
+ //# sourceMappingURL=redisTtlCache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redisTtlCache.js","sourceRoot":"","sources":["../../cache/redisTtlCache.ts"],"names":[],"mappings":";;;AAAA,iCAAqC;AAIrC;;;GAGG;AACH,MAAa,aAAa;IAQJ;IAPZ,MAAM,CAAC;IAEf;;;;OAIG;IACH,YAAoB,eAAuB;QAAvB,oBAAe,GAAf,eAAe,CAAQ;QACzC,wCAAwC;QACxC,0EAA0E;QAC1E,IAAI,CAAC,MAAM,GAAG,IAAA,oBAAY,GAAE,CAAC;QAC7B,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAAC,CAAC;QACzE,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE;YAC7B,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,iCAAiC,CAAC,CAAC,CAAE,aAAa;QACrF,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC7C,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,eAAe,GAAG,IAAI,CAAC,eAAe,EAAkB;QACpF,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE;YAChD,EAAE,EAAE,eAAe;SACpB,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,YAAY,CAAC,cAAsB;QACvC,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IACxC,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,UAAU,CAAC,cAAsB;QACrC,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QACpD,IAAI,KAAK,KAAK,IAAI,EAAE;YAClB,MAAM,IAAI,KAAK,CAAC,6BAA6B,cAAc,EAAE,CAAC,CAAC;SAChE;QACD,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,uBAAuB;QAC1E,OAAO;YACL,GAAG,EAAE,cAAc;YACnB,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;YACxB,eAAe,EAAE,GAAG,GAAG,IAAI;SAC5B,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,QAAQ,CAAC,cAAsB;QACnC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,GAAG,GAAG,CAAC,CAAC;QAC1D,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,UAAU,CAAC,cAAsB;QACrC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;QACxD,OAAO,MAAM,KAAK,CAAC,CAAC;IACtB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,UAAU;QACd,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IAC3B,CAAC;IAED;;;;OAIG;IACH,kBAAkB;QAChB,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;CACF;AApGD,sCAoGC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Type representing a TTL (Time-To-Live) cache record.
3
+ *
4
+ * @typedef {Object} TtlCacheRecord
5
+ * @property {string} key - The key of the cache record.
6
+ * @property {any} value - The value of the cache record.
7
+ * @property {number} ttlMilliseconds - The time-to-live of the cache record in milliseconds.
8
+ */
9
+ export type TtlCacheRecord = {
10
+ key: string;
11
+ value: unknown;
12
+ ttlMilliseconds: number;
13
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=ttlCacheRecord.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ttlCacheRecord.js","sourceRoot":"","sources":["../../../cache/types/ttlCacheRecord.ts"],"names":[],"mappings":""}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Interface representing a controller.
3
+ *
4
+ * @interface Controller
5
+ */
6
+ interface Controller {
7
+ /**
8
+ * The base path for the controller.
9
+ *
10
+ * @type {string}
11
+ * @readonly
12
+ */
13
+ readonly basePath: string;
14
+ }
15
+ export default Controller;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=controller.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"controller.interface.js","sourceRoot":"","sources":["../../../controllers/interfaces/controller.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Abstract class representing a base entity.
3
+ */
4
+ export declare abstract class BaseEntity {
5
+ /**
6
+ * The unique identifier for the entity.
7
+ *
8
+ * @type {string}
9
+ * @readonly
10
+ */
11
+ id: string;
12
+ /**
13
+ * The date when the entity was created.
14
+ *
15
+ * @type {Date}
16
+ */
17
+ createdAt: Date;
18
+ /**
19
+ * The date when the entity was last updated.
20
+ *
21
+ * @type {Date}
22
+ * @readonly
23
+ */
24
+ updatedAt: Date;
25
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.BaseEntity = void 0;
13
+ const uuid_1 = require("uuid");
14
+ const core_1 = require("@mikro-orm/core");
15
+ /**
16
+ * Abstract class representing a base entity.
17
+ */
18
+ class BaseEntity {
19
+ /**
20
+ * The unique identifier for the entity.
21
+ *
22
+ * @type {string}
23
+ * @readonly
24
+ */
25
+ id = (0, uuid_1.v4)();
26
+ /**
27
+ * The date when the entity was created.
28
+ *
29
+ * @type {Date}
30
+ */
31
+ createdAt = new Date();
32
+ /**
33
+ * The date when the entity was last updated.
34
+ *
35
+ * @type {Date}
36
+ * @readonly
37
+ */
38
+ updatedAt = new Date();
39
+ }
40
+ exports.BaseEntity = BaseEntity;
41
+ __decorate([
42
+ (0, core_1.PrimaryKey)({ type: "uuid" }),
43
+ __metadata("design:type", String)
44
+ ], BaseEntity.prototype, "id", void 0);
45
+ __decorate([
46
+ (0, core_1.Property)(),
47
+ __metadata("design:type", Date)
48
+ ], BaseEntity.prototype, "createdAt", void 0);
49
+ __decorate([
50
+ (0, core_1.Property)({ onUpdate: () => new Date() }),
51
+ __metadata("design:type", Date)
52
+ ], BaseEntity.prototype, "updatedAt", void 0);
53
+ //# sourceMappingURL=base.entity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.entity.js","sourceRoot":"","sources":["../../../../../database/mikro/models/entities/base.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+BAA0B;AAC1B,0CAAuD;AAEvD;;GAEG;AACH,MAAsB,UAAU;IAC9B;;;;;OAKG;IAEH,EAAE,GAAW,IAAA,SAAE,GAAE,CAAC;IAElB;;;;OAIG;IAEH,SAAS,GAAS,IAAI,IAAI,EAAE,CAAC;IAE7B;;;;;OAKG;IAEH,SAAS,GAAS,IAAI,IAAI,EAAE,CAAC;CAC9B;AA1BD,gCA0BC;AAlBC;IADC,IAAA,iBAAU,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;sCACX;AAQlB;IADC,IAAA,eAAQ,GAAE;8BACA,IAAI;6CAAc;AAS7B;IADC,IAAA,eAAQ,EAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,EAAE,CAAC;8BAC9B,IAAI;6CAAc"}
@@ -0,0 +1,16 @@
1
+ import { SchemaValidator } from "@forklaunch/validator/interfaces";
2
+ /**
3
+ * Interface representing a constructor for an entity mapper.
4
+ *
5
+ * @template T - The type of the entity mapper.
6
+ * @interface EntityMapperConstructor
7
+ */
8
+ export interface EntityMapperConstructor<T, SV extends SchemaValidator> {
9
+ /**
10
+ * Creates a new instance of the entity mapper.
11
+ *
12
+ * @param {SchemaValidator} schemaValidator - The arguments to pass to the constructor.
13
+ * @returns {T} - A new instance of the entity mapper.
14
+ */
15
+ new (schemaValidator: SV): T;
16
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=entityMapper.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entityMapper.interface.js","sourceRoot":"","sources":["../../../entityMapper/interfaces/entityMapper.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,71 @@
1
+ import { SchemaValidator } from "@forklaunch/validator/interfaces";
2
+ import { EntityMapperConstructor } from "../interfaces/entityMapper.interface";
3
+ import { EntityMapperSchema, EntityMapperSchemaValidatorObject } from "../types/entityMapper.types";
4
+ /**
5
+ * Constructs an instance of a EntityMapperType.
6
+ *
7
+ * @template EntityMapperType - A type that extends BaseEntityMapper.
8
+ * @param {EntityMapperConstructor<EntityMapperType>} self - The constructor of the EntityMapperType.
9
+ * @param {...any[]} args - The arguments to pass to the constructor.
10
+ * @returns {EntityMapperType} - An instance of the EntityMapperType.
11
+ */
12
+ export declare function construct<EntityMapperType, SV extends SchemaValidator>(self: EntityMapperConstructor<EntityMapperType, SV>, schemaValidator?: SV): EntityMapperType;
13
+ /**
14
+ * Abstract class representing a base entityMapper.
15
+ *
16
+ * @template SV - A type that extends SchemaValidator.
17
+ */
18
+ export declare abstract class BaseEntityMapper<SV extends SchemaValidator> {
19
+ /**
20
+ * The schema validator.
21
+ * @type {SV}
22
+ * @protected
23
+ */
24
+ _SV: SV;
25
+ /**
26
+ * The schema provider.
27
+ * @type {SV}
28
+ * @protected
29
+ */
30
+ protected schemaValidator: SV;
31
+ /**
32
+ * The schema definition.
33
+ * @type {EntityMapperSchemaValidatorObject<SV>}
34
+ * @abstract
35
+ */
36
+ abstract schema: EntityMapperSchemaValidatorObject<SV>;
37
+ /**
38
+ * The Data Transfer Object (DTO).
39
+ * @type {EntityMapperSchema<this['schema'], SV>}
40
+ *
41
+ */
42
+ _dto: EntityMapperSchema<this['schema'], SV>;
43
+ /**
44
+ * Creates an instance of BaseEntityMapper.
45
+ *
46
+ * @param {SV} schemaValidator - The schema provider.
47
+ */
48
+ constructor(schemaValidator: SV);
49
+ /**
50
+ * Validates and sets the Data Transfer Object (DTO).
51
+ *
52
+ * @param {this['_dto']} dto - The Data Transfer Object (DTO).
53
+ * @throws {Error} - Throws an error if the DTO is invalid.
54
+ */
55
+ set dto(_dto: this['_dto']);
56
+ /**
57
+ * Validates and gets the Data Transfer Object (DTO).
58
+ *
59
+ * @returns {this['_dto']} - The Data Transfer Object (DTO).
60
+ * @throws {Error} - Throws an error if the DTO is invalid.
61
+ */
62
+ get dto(): this['_dto'];
63
+ /**
64
+ * Gets the schema of a EntityMapperType.
65
+ *
66
+ * @template EntityMapperType - A type that extends BaseEntityMapper.
67
+ * @param {EntityMapperConstructor<EntityMapperType>} this - The constructor of the EntityMapperType.
68
+ * @returns {EntityMapperType['schema']} - The schema of the EntityMapperType.
69
+ */
70
+ static schema<EntityMapperType extends BaseEntityMapper<any>>(this: EntityMapperConstructor<EntityMapperType, EntityMapperType['_SV']>): EntityMapperType['schema'];
71
+ }
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseEntityMapper = exports.construct = void 0;
4
+ /**
5
+ * Constructs an instance of a EntityMapperType.
6
+ *
7
+ * @template EntityMapperType - A type that extends BaseEntityMapper.
8
+ * @param {EntityMapperConstructor<EntityMapperType>} self - The constructor of the EntityMapperType.
9
+ * @param {...any[]} args - The arguments to pass to the constructor.
10
+ * @returns {EntityMapperType} - An instance of the EntityMapperType.
11
+ */
12
+ function construct(self, schemaValidator) {
13
+ return new self(schemaValidator || {});
14
+ }
15
+ exports.construct = construct;
16
+ /**
17
+ * Abstract class representing a base entityMapper.
18
+ *
19
+ * @template SV - A type that extends SchemaValidator.
20
+ */
21
+ class BaseEntityMapper {
22
+ /**
23
+ * The schema validator.
24
+ * @type {SV}
25
+ * @protected
26
+ */
27
+ _SV;
28
+ /**
29
+ * The schema provider.
30
+ * @type {SV}
31
+ * @protected
32
+ */
33
+ schemaValidator;
34
+ /**
35
+ * The Data Transfer Object (DTO).
36
+ * @type {EntityMapperSchema<this['schema'], SV>}
37
+ *
38
+ */
39
+ _dto = {};
40
+ /**
41
+ * Creates an instance of BaseEntityMapper.
42
+ *
43
+ * @param {SV} schemaValidator - The schema provider.
44
+ */
45
+ constructor(schemaValidator) {
46
+ this.schemaValidator = schemaValidator;
47
+ }
48
+ /**
49
+ * Validates and sets the Data Transfer Object (DTO).
50
+ *
51
+ * @param {this['_dto']} dto - The Data Transfer Object (DTO).
52
+ * @throws {Error} - Throws an error if the DTO is invalid.
53
+ */
54
+ set dto(_dto) {
55
+ if (!this.schemaValidator.validate(this.schemaValidator.schemify(this.schema), _dto)) {
56
+ throw new Error('Invalid DTO');
57
+ }
58
+ this._dto = _dto;
59
+ }
60
+ /**
61
+ * Validates and gets the Data Transfer Object (DTO).
62
+ *
63
+ * @returns {this['_dto']} - The Data Transfer Object (DTO).
64
+ * @throws {Error} - Throws an error if the DTO is invalid.
65
+ */
66
+ get dto() {
67
+ return this._dto;
68
+ }
69
+ /**
70
+ * Gets the schema of a EntityMapperType.
71
+ *
72
+ * @template EntityMapperType - A type that extends BaseEntityMapper.
73
+ * @param {EntityMapperConstructor<EntityMapperType>} this - The constructor of the EntityMapperType.
74
+ * @returns {EntityMapperType['schema']} - The schema of the EntityMapperType.
75
+ */
76
+ static schema() {
77
+ return construct(this).schema;
78
+ }
79
+ }
80
+ exports.BaseEntityMapper = BaseEntityMapper;
81
+ //# sourceMappingURL=baseEntityMapper.model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"baseEntityMapper.model.js","sourceRoot":"","sources":["../../../entityMapper/models/baseEntityMapper.model.ts"],"names":[],"mappings":";;;AAIA;;;;;;;GAOG;AACH,SAAgB,SAAS,CAA+C,IAAmD,EAAE,eAAoB;IAC7I,OAAO,IAAI,IAAI,CAAC,eAAe,IAAI,EAAQ,CAAC,CAAC;AACjD,CAAC;AAFD,8BAEC;AAED;;;;GAIG;AACH,MAAsB,gBAAgB;IACjC;;;;MAIE;IACH,GAAG,CAAM;IAET;;;;OAIG;IACO,eAAe,CAAK;IAS9B;;;;OAIG;IACH,IAAI,GAA2C,EAAuD,CAAC;IAEvG;;;;OAIG;IACH,YAAY,eAAmB;QAC3B,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;IAC3C,CAAC;IAED;;;;;OAKG;IACH,IAAI,GAAG,CAAC,IAAkB;QACtB,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,EAAE;YAClF,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC;SAClC;QACD,IAAI,CAAC,IAAI,GAAG,IAAyD,CAAC;IAC1E,CAAC;IAED;;;;;OAKG;IACH,IAAI,GAAG;QACH,OAAO,IAAI,CAAC,IAA+B,CAAC;IAChD,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,MAAM;QACT,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;IAClC,CAAC;CACJ;AAvED,4CAuEC"}
@@ -0,0 +1,69 @@
1
+ import { SchemaValidator } from "@forklaunch/validator/interfaces";
2
+ import { BaseEntity } from "../../database/mikro/models/entities/base.entity";
3
+ import { EntityMapperConstructor } from "../interfaces/entityMapper.interface";
4
+ import { BaseEntityMapper } from "./baseEntityMapper.model";
5
+ /**
6
+ * Abstract class representing a request entityMapper.
7
+ *
8
+ * @template Entity - A type that extends BaseEntity.
9
+ * @template SV - A type that extends SchemaValidator.
10
+ * @extends {BaseEntityMapper<SV>}
11
+ */
12
+ export declare abstract class RequestEntityMapper<Entity extends BaseEntity | unknown, SV extends SchemaValidator> extends BaseEntityMapper<SV> {
13
+ /**
14
+ * The entity.
15
+ * @type {Entity}
16
+ * @protected
17
+ */
18
+ _Entity: Entity;
19
+ /**
20
+ * Creates an instance of RequestEntityMapper.
21
+ *
22
+ * @param {SV} schemaValidator - The schema provider.
23
+ */
24
+ constructor(schemaValidator: SV);
25
+ /**
26
+ * Converts the underlying DTO to an entity.
27
+ *
28
+ * @abstract
29
+ * @param {...unknown[]} additionalArgs - Additional arguments.
30
+ * @returns {Entity} - The entity.
31
+ */
32
+ abstract toEntity(...additionalArgs: unknown[]): Entity;
33
+ /**
34
+ * Populates the DTO with data from a JSON object.
35
+ *
36
+ * @param {this['_dto']} json - The JSON object.
37
+ * @returns {this} - The instance of the RequestEntityMapper.
38
+ */
39
+ fromJson(json: this['_dto']): this;
40
+ /**
41
+ * Deserializes a JSON object to an entity.
42
+ *
43
+ * @param {this['_dto']} json - The JSON object.
44
+ * @param {...unknown[]} additionalArgs - Additional arguments.
45
+ * @returns {Entity} - The entity.
46
+ */
47
+ deserializeJsonToEntity(json: this['_dto'], ...additionalArgs: unknown[]): Entity;
48
+ /**
49
+ * Creates an instance of a RequestEntityMapper from a JSON object.
50
+ *
51
+ * @template EntityMapperType - A type that extends RequestEntityMapper.
52
+ * @param {EntityMapperConstructor<EntityMapperType>} this - The constructor of the EntityMapperType.
53
+ * @param {EntityMapperType['_SV']} schemaValidator - The schema provider.
54
+ * @param {EntityMapperStaticSchema<EntityMapperType>} json - The JSON object.
55
+ * @returns {EntityMapperType} - An instance of the EntityMapperType.
56
+ */
57
+ static fromJson<EntityMapperType extends RequestEntityMapper<unknown, any>>(this: EntityMapperConstructor<EntityMapperType, EntityMapperType['_SV']>, schemaValidator: EntityMapperType['_SV'], json: EntityMapperType['_dto']): EntityMapperType;
58
+ /**
59
+ * Deserializes a JSON object to an entity.
60
+ *
61
+ * @template EntityMapperType - A type that extends RequestEntityMapper.
62
+ * @param {EntityMapperConstructor<EntityMapperType>} this - The constructor of the EntityMapperType.
63
+ * @param {EntityMapperType['_SV']} schemaValidator - The schema provider.
64
+ * @param {EntityMapperStaticSchema<EntityMapperType>} json - The JSON object.
65
+ * @param {...unknown[]} additionalArgs - Additional arguments.
66
+ * @returns {EntityMapperType['_Entity']} - The entity.
67
+ */
68
+ static deserializeJsonToEntity<EntityMapperType extends RequestEntityMapper<unknown, any>>(this: EntityMapperConstructor<EntityMapperType, EntityMapperType['_SV']>, schemaValidator: EntityMapperType['_SV'], json: EntityMapperType['_dto'], ...additionalArgs: unknown[]): EntityMapperType['_Entity'];
69
+ }