@forklaunch/core 0.1.1 → 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.
- package/.prettierignore +2 -0
- package/.prettierrc +6 -0
- package/dist/cache/index.d.ts +3 -0
- package/dist/cache/index.js +20 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/cache/interfaces/ttlCache.interface.d.ts +1 -1
- package/dist/cache/redisTtlCache.d.ts +3 -2
- package/dist/cache/redisTtlCache.js +2 -2
- package/dist/cache/redisTtlCache.js.map +1 -1
- package/dist/cache/types/{ttlCacheRecord.js → ttlCacheRecord.types.js} +1 -1
- package/dist/cache/types/ttlCacheRecord.types.js.map +1 -0
- package/dist/controllers/index.d.ts +1 -0
- package/dist/controllers/index.js +18 -0
- package/dist/controllers/index.js.map +1 -0
- package/dist/database/index.d.ts +1 -0
- package/dist/database/index.js +18 -0
- package/dist/database/index.js.map +1 -0
- package/dist/database/mikro/models/entities/base.entity.js +1 -1
- package/dist/entityMapper/index.d.ts +2 -0
- package/dist/entityMapper/index.js +19 -0
- package/dist/entityMapper/index.js.map +1 -0
- package/dist/entityMapper/interfaces/entityMapper.interface.d.ts +3 -3
- package/dist/entityMapper/models/baseEntityMapper.model.d.ts +23 -23
- package/dist/entityMapper/models/baseEntityMapper.model.js +15 -15
- package/dist/entityMapper/models/baseEntityMapper.model.js.map +1 -1
- package/dist/entityMapper/models/requestEntityMapper.model.d.ts +17 -23
- package/dist/entityMapper/models/requestEntityMapper.model.js +13 -19
- package/dist/entityMapper/models/requestEntityMapper.model.js.map +1 -1
- package/dist/entityMapper/models/responseEntityMapper.model.d.ts +15 -16
- package/dist/entityMapper/models/responseEntityMapper.model.js +8 -8
- package/dist/entityMapper/models/responseEntityMapper.model.js.map +1 -1
- package/dist/entityMapper/types/entityMapper.types.d.ts +3 -22
- package/dist/http/index.d.ts +2 -0
- package/dist/http/index.js +19 -0
- package/dist/http/index.js.map +1 -0
- package/dist/http/middlewares/index.d.ts +2 -0
- package/dist/http/middlewares/index.js +19 -0
- package/dist/http/middlewares/index.js.map +1 -0
- package/dist/http/middlewares/request.middleware.d.ts +11 -11
- package/dist/http/middlewares/request.middleware.js +23 -21
- package/dist/http/middlewares/request.middleware.js.map +1 -1
- package/dist/http/middlewares/response.middleware.d.ts +3 -3
- package/dist/http/middlewares/response.middleware.js +7 -3
- package/dist/http/middlewares/response.middleware.js.map +1 -1
- package/dist/http/types/api.types.d.ts +16 -12
- package/dist/http/types/index.d.ts +2 -0
- package/dist/http/types/index.js +19 -0
- package/dist/http/types/index.js.map +1 -0
- package/dist/http/types/primitive.types.d.ts +14 -13
- package/dist/index.d.ts +6 -1
- package/dist/index.js +20 -5
- package/dist/index.js.map +1 -1
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +18 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/interfaces/baseService.d.ts +1 -1
- package/dist/tests/{dto.test.js → entityMapper.test.js} +10 -32
- package/dist/tests/entityMapper.test.js.map +1 -0
- package/dist/tests/http.middleware.test.d.ts +1 -0
- package/dist/tests/http.middleware.test.js +79 -0
- package/dist/tests/http.middleware.test.js.map +1 -0
- package/dist/tests/redisTtlCache.test.js +32 -15
- package/dist/tests/redisTtlCache.test.js.map +1 -1
- package/entityMapper/index.ts +2 -0
- package/entityMapper/interfaces/entityMapper.interface.ts +11 -11
- package/entityMapper/models/baseEntityMapper.model.ts +90 -73
- package/entityMapper/models/requestEntityMapper.model.ts +96 -75
- package/entityMapper/models/responseEntityMapper.model.ts +83 -62
- package/entityMapper/types/entityMapper.types.ts +6 -23
- package/http/index.ts +2 -0
- package/http/middlewares/index.ts +2 -0
- package/http/middlewares/request.middleware.ts +103 -55
- package/http/middlewares/response.middleware.ts +56 -31
- package/http/types/api.types.ts +43 -25
- package/http/types/index.ts +2 -0
- package/http/types/primitive.types.ts +65 -44
- package/index.ts +6 -5
- package/jest.config.ts +2 -2
- package/package.json +13 -4
- package/tests/entityMapper.test.ts +219 -0
- package/tests/http.middleware.test.ts +99 -0
- package/tests/redisTtlCache.test.ts +49 -29
- package/dist/cache/types/ttlCacheRecord.js.map +0 -1
- package/dist/tests/dto.test.js.map +0 -1
- package/tests/dto.test.ts +0 -235
- /package/dist/cache/types/{ttlCacheRecord.d.ts → ttlCacheRecord.types.d.ts} +0 -0
- /package/dist/tests/{dto.test.d.ts → entityMapper.test.d.ts} +0 -0
package/.prettierignore
ADDED
package/.prettierrc
ADDED
@@ -0,0 +1,20 @@
|
|
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("./interfaces/ttlCache.interface"), exports);
|
18
|
+
__exportStar(require("./redisTtlCache"), exports);
|
19
|
+
__exportStar(require("./types/ttlCacheRecord.types"), exports);
|
20
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../cache/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kEAAgD;AAChD,kDAAgC;AAChC,+DAA6C"}
|
@@ -1,5 +1,6 @@
|
|
1
|
+
import { RedisClientOptions } from 'redis';
|
1
2
|
import { TtlCache } from './interfaces/ttlCache.interface';
|
2
|
-
import { TtlCacheRecord } from './types/ttlCacheRecord';
|
3
|
+
import { TtlCacheRecord } from './types/ttlCacheRecord.types';
|
3
4
|
/**
|
4
5
|
* Class representing a Redis-based TTL (Time-To-Live) cache.
|
5
6
|
* Implements the TtlCache interface.
|
@@ -12,7 +13,7 @@ export declare class RedisTtlCache implements TtlCache {
|
|
12
13
|
*
|
13
14
|
* @param {number} ttlMilliseconds - The default TTL in milliseconds.
|
14
15
|
*/
|
15
|
-
constructor(ttlMilliseconds: number);
|
16
|
+
constructor(ttlMilliseconds: number, hostingOptions?: RedisClientOptions);
|
16
17
|
/**
|
17
18
|
* Puts a record into the Redis cache.
|
18
19
|
*
|
@@ -14,11 +14,11 @@ class RedisTtlCache {
|
|
14
14
|
*
|
15
15
|
* @param {number} ttlMilliseconds - The default TTL in milliseconds.
|
16
16
|
*/
|
17
|
-
constructor(ttlMilliseconds) {
|
17
|
+
constructor(ttlMilliseconds, hostingOptions) {
|
18
18
|
this.ttlMilliseconds = ttlMilliseconds;
|
19
19
|
// Connects to localhost:6379 by default
|
20
20
|
// url usage: redis[s]://[[username][:password]@][host][:port][/db-number]
|
21
|
-
this.client = (0, redis_1.createClient)();
|
21
|
+
this.client = (0, redis_1.createClient)(hostingOptions);
|
22
22
|
this.client.on('error', (err) => console.log('Redis Client Error', err));
|
23
23
|
this.client.on('connect', () => {
|
24
24
|
console.log('\x1b[32m%s\x1b[0m', 'Successfully Connected to Redis'); // Green text
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"redisTtlCache.js","sourceRoot":"","sources":["../../cache/redisTtlCache.ts"],"names":[],"mappings":";;;AAAA,
|
1
|
+
{"version":3,"file":"redisTtlCache.js","sourceRoot":"","sources":["../../cache/redisTtlCache.ts"],"names":[],"mappings":";;;AAAA,iCAAyD;AAIzD;;;GAGG;AACH,MAAa,aAAa;IASd;IARF,MAAM,CAAC;IAEf;;;;OAIG;IACH,YACU,eAAuB,EAC/B,cAAmC;QAD3B,oBAAe,GAAf,eAAe,CAAQ;QAG/B,wCAAwC;QACxC,0EAA0E;QAC1E,IAAI,CAAC,MAAM,GAAG,IAAA,oBAAY,EAAC,cAAc,CAAC,CAAC;QAC3C,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,CAAC,aAAa;QACpF,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,EACd,GAAG,EACH,KAAK,EACL,eAAe,GAAG,IAAI,CAAC,eAAe,EACvB;QACf,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,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,6BAA6B,cAAc,EAAE,CAAC,CAAC;QACjE,CAAC;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;AA3GD,sCA2GC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"ttlCacheRecord.types.js","sourceRoot":"","sources":["../../../cache/types/ttlCacheRecord.types.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './interfaces/controller.interface';
|
@@ -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("./interfaces/controller.interface"), exports);
|
18
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../controllers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oEAAkD"}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './mikro/models/entities/base.entity';
|
@@ -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("./mikro/models/entities/base.entity"), exports);
|
18
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../database/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sEAAoD"}
|
@@ -39,7 +39,7 @@ class BaseEntity {
|
|
39
39
|
}
|
40
40
|
exports.BaseEntity = BaseEntity;
|
41
41
|
__decorate([
|
42
|
-
(0, core_1.PrimaryKey)({ type:
|
42
|
+
(0, core_1.PrimaryKey)({ type: 'uuid' }),
|
43
43
|
__metadata("design:type", String)
|
44
44
|
], BaseEntity.prototype, "id", void 0);
|
45
45
|
__decorate([
|
@@ -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("./models/requestEntityMapper.model"), exports);
|
18
|
+
__exportStar(require("./models/responseEntityMapper.model"), exports);
|
19
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../entityMapper/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qEAAmD;AACnD,sEAAoD"}
|
@@ -1,15 +1,15 @@
|
|
1
|
-
import {
|
1
|
+
import { AnySchemaValidator } from '@forklaunch/validator';
|
2
2
|
/**
|
3
3
|
* Interface representing a constructor for an entity mapper.
|
4
4
|
*
|
5
5
|
* @template T - The type of the entity mapper.
|
6
6
|
* @interface EntityMapperConstructor
|
7
7
|
*/
|
8
|
-
export interface EntityMapperConstructor<T, SV extends
|
8
|
+
export interface EntityMapperConstructor<T, SV extends AnySchemaValidator> {
|
9
9
|
/**
|
10
10
|
* Creates a new instance of the entity mapper.
|
11
11
|
*
|
12
|
-
* @param {
|
12
|
+
* @param {AnySchemaValidator} schemaValidator - The arguments to pass to the constructor.
|
13
13
|
* @returns {T} - A new instance of the entity mapper.
|
14
14
|
*/
|
15
15
|
new (schemaValidator: SV): T;
|
@@ -1,33 +1,33 @@
|
|
1
|
-
import { SchemaValidator } from
|
2
|
-
import { EntityMapperConstructor } from
|
3
|
-
import {
|
1
|
+
import { AnySchemaValidator, Schema, SchemaValidator } from '@forklaunch/validator';
|
2
|
+
import { EntityMapperConstructor } from '../interfaces/entityMapper.interface';
|
3
|
+
import { EntityMapperSchemaValidatorObject } from '../types/entityMapper.types';
|
4
4
|
/**
|
5
|
-
* Constructs an instance of a
|
5
|
+
* Constructs an instance of a T.
|
6
6
|
*
|
7
|
-
* @template
|
8
|
-
* @param {EntityMapperConstructor<
|
7
|
+
* @template T - A type that extends BaseEntityMapper.
|
8
|
+
* @param {EntityMapperConstructor<T>} self - The constructor of the T.
|
9
9
|
* @param {...any[]} args - The arguments to pass to the constructor.
|
10
|
-
* @returns {
|
10
|
+
* @returns {T} - An instance of the T.
|
11
11
|
*/
|
12
|
-
export declare function construct<
|
12
|
+
export declare function construct<T, SV extends AnySchemaValidator>(self: EntityMapperConstructor<T, SV>, schemaValidator?: SV): T;
|
13
13
|
/**
|
14
14
|
* Abstract class representing a base entityMapper.
|
15
15
|
*
|
16
16
|
* @template SV - A type that extends SchemaValidator.
|
17
17
|
*/
|
18
|
-
export declare abstract class BaseEntityMapper<SV extends
|
18
|
+
export declare abstract class BaseEntityMapper<SV extends AnySchemaValidator> {
|
19
19
|
/**
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
* The schema validator exact type.
|
21
|
+
* @type {SV}
|
22
|
+
* @protected
|
23
|
+
*/
|
24
24
|
_SV: SV;
|
25
25
|
/**
|
26
|
-
* The schema
|
27
|
-
* @type {
|
26
|
+
* The schema validator as a general type.
|
27
|
+
* @type {SchemaValidator}
|
28
28
|
* @protected
|
29
29
|
*/
|
30
|
-
protected schemaValidator:
|
30
|
+
protected schemaValidator: SchemaValidator;
|
31
31
|
/**
|
32
32
|
* The schema definition.
|
33
33
|
* @type {EntityMapperSchemaValidatorObject<SV>}
|
@@ -36,10 +36,10 @@ export declare abstract class BaseEntityMapper<SV extends SchemaValidator> {
|
|
36
36
|
abstract schema: EntityMapperSchemaValidatorObject<SV>;
|
37
37
|
/**
|
38
38
|
* The Data Transfer Object (DTO).
|
39
|
-
* @type {
|
39
|
+
* @type {Schema<this['schema'], SV>}
|
40
40
|
*
|
41
41
|
*/
|
42
|
-
_dto:
|
42
|
+
_dto: Schema<this['schema'], SV>;
|
43
43
|
/**
|
44
44
|
* Creates an instance of BaseEntityMapper.
|
45
45
|
*
|
@@ -61,11 +61,11 @@ export declare abstract class BaseEntityMapper<SV extends SchemaValidator> {
|
|
61
61
|
*/
|
62
62
|
get dto(): this['_dto'];
|
63
63
|
/**
|
64
|
-
* Gets the schema of a
|
64
|
+
* Gets the schema of a T.
|
65
65
|
*
|
66
|
-
* @template
|
67
|
-
* @param {EntityMapperConstructor<
|
68
|
-
* @returns {
|
66
|
+
* @template T - A type that extends BaseEntityMapper.
|
67
|
+
* @param {EntityMapperConstructor<T>} this - The constructor of the T.
|
68
|
+
* @returns {T['schema']} - The schema of the T.
|
69
69
|
*/
|
70
|
-
static schema<
|
70
|
+
static schema<T extends BaseEntityMapper<SV>, SV extends AnySchemaValidator>(this: EntityMapperConstructor<T, SV>): T['schema'];
|
71
71
|
}
|
@@ -3,12 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BaseEntityMapper = void 0;
|
4
4
|
exports.construct = construct;
|
5
5
|
/**
|
6
|
-
* Constructs an instance of a
|
6
|
+
* Constructs an instance of a T.
|
7
7
|
*
|
8
|
-
* @template
|
9
|
-
* @param {EntityMapperConstructor<
|
8
|
+
* @template T - A type that extends BaseEntityMapper.
|
9
|
+
* @param {EntityMapperConstructor<T>} self - The constructor of the T.
|
10
10
|
* @param {...any[]} args - The arguments to pass to the constructor.
|
11
|
-
* @returns {
|
11
|
+
* @returns {T} - An instance of the T.
|
12
12
|
*/
|
13
13
|
function construct(self, schemaValidator) {
|
14
14
|
return new self(schemaValidator || {});
|
@@ -20,20 +20,20 @@ function construct(self, schemaValidator) {
|
|
20
20
|
*/
|
21
21
|
class BaseEntityMapper {
|
22
22
|
/**
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
* The schema validator exact type.
|
24
|
+
* @type {SV}
|
25
|
+
* @protected
|
26
|
+
*/
|
27
27
|
_SV;
|
28
28
|
/**
|
29
|
-
* The schema
|
30
|
-
* @type {
|
29
|
+
* The schema validator as a general type.
|
30
|
+
* @type {SchemaValidator}
|
31
31
|
* @protected
|
32
32
|
*/
|
33
33
|
schemaValidator;
|
34
34
|
/**
|
35
35
|
* The Data Transfer Object (DTO).
|
36
|
-
* @type {
|
36
|
+
* @type {Schema<this['schema'], SV>}
|
37
37
|
*
|
38
38
|
*/
|
39
39
|
_dto = {};
|
@@ -67,11 +67,11 @@ class BaseEntityMapper {
|
|
67
67
|
return this._dto;
|
68
68
|
}
|
69
69
|
/**
|
70
|
-
* Gets the schema of a
|
70
|
+
* Gets the schema of a T.
|
71
71
|
*
|
72
|
-
* @template
|
73
|
-
* @param {EntityMapperConstructor<
|
74
|
-
* @returns {
|
72
|
+
* @template T - A type that extends BaseEntityMapper.
|
73
|
+
* @param {EntityMapperConstructor<T>} this - The constructor of the T.
|
74
|
+
* @returns {T['schema']} - The schema of the T.
|
75
75
|
*/
|
76
76
|
static schema() {
|
77
77
|
return construct(this).schema;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"baseEntityMapper.model.js","sourceRoot":"","sources":["../../../entityMapper/models/baseEntityMapper.model.ts"],"names":[],"mappings":";;;
|
1
|
+
{"version":3,"file":"baseEntityMapper.model.js","sourceRoot":"","sources":["../../../entityMapper/models/baseEntityMapper.model.ts"],"names":[],"mappings":";;;AAgBA,8BAKC;AAbD;;;;;;;GAOG;AACH,SAAgB,SAAS,CACvB,IAAoC,EACpC,eAAoB;IAEpB,OAAO,IAAI,IAAI,CAAC,eAAe,IAAK,EAAS,CAAC,CAAC;AACjD,CAAC;AAED;;;;GAIG;AACH,MAAsB,gBAAgB;IACpC;;;;OAIG;IACH,GAAG,CAAM;IAET;;;;OAIG;IACO,eAAe,CAAkB;IAS3C;;;;OAIG;IACH,IAAI,GAA+B,EAGlC,CAAC;IAEF;;;;OAIG;IACH,YAAY,eAAmB;QAC7B,IAAI,CAAC,eAAe,GAAG,eAA6C,CAAC;IACvE,CAAC;IAED;;;;;OAKG;IACH,IAAI,GAAG,CAAC,IAAkB;QACxB,IACE,CAAC,IAAI,CAAC,eAAe,CAAC,QAAQ,CAC5B,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAC1C,IAAI,CACL,EACD,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC;QACjC,CAAC;QACD,IAAI,CAAC,IAAI,GAAG,IAA6C,CAAC;IAC5D,CAAC;IAED;;;;;OAKG;IACH,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,IAA+B,CAAC;IAC9C,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,MAAM;QAGX,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;IAChC,CAAC;CACF;AAjFD,4CAiFC"}
|
@@ -1,7 +1,7 @@
|
|
1
|
-
import {
|
2
|
-
import { BaseEntity } from
|
3
|
-
import { EntityMapperConstructor } from
|
4
|
-
import { BaseEntityMapper } from
|
1
|
+
import { AnySchemaValidator } from '@forklaunch/validator';
|
2
|
+
import { BaseEntity } from '../../database/mikro/models/entities/base.entity';
|
3
|
+
import { EntityMapperConstructor } from '../interfaces/entityMapper.interface';
|
4
|
+
import { BaseEntityMapper } from './baseEntityMapper.model';
|
5
5
|
/**
|
6
6
|
* Abstract class representing a request entityMapper.
|
7
7
|
*
|
@@ -9,19 +9,13 @@ import { BaseEntityMapper } from "./baseEntityMapper.model";
|
|
9
9
|
* @template SV - A type that extends SchemaValidator.
|
10
10
|
* @extends {BaseEntityMapper<SV>}
|
11
11
|
*/
|
12
|
-
export declare abstract class RequestEntityMapper<Entity extends BaseEntity
|
12
|
+
export declare abstract class RequestEntityMapper<Entity extends BaseEntity, SV extends AnySchemaValidator> extends BaseEntityMapper<SV> {
|
13
13
|
/**
|
14
14
|
* The entity.
|
15
15
|
* @type {Entity}
|
16
16
|
* @protected
|
17
17
|
*/
|
18
18
|
_Entity: Entity;
|
19
|
-
/**
|
20
|
-
* Creates an instance of RequestEntityMapper.
|
21
|
-
*
|
22
|
-
* @param {SV} schemaValidator - The schema provider.
|
23
|
-
*/
|
24
|
-
constructor(schemaValidator: SV);
|
25
19
|
/**
|
26
20
|
* Converts the underlying DTO to an entity.
|
27
21
|
*
|
@@ -48,22 +42,22 @@ export declare abstract class RequestEntityMapper<Entity extends BaseEntity | un
|
|
48
42
|
/**
|
49
43
|
* Creates an instance of a RequestEntityMapper from a JSON object.
|
50
44
|
*
|
51
|
-
* @template
|
52
|
-
* @param {EntityMapperConstructor<
|
53
|
-
* @param {
|
54
|
-
* @param {
|
55
|
-
* @returns {
|
45
|
+
* @template T - A type that extends RequestEntityMapper.
|
46
|
+
* @param {EntityMapperConstructor<T>} this - The constructor of the T.
|
47
|
+
* @param {T['_SV']} schemaValidator - The schema provider.
|
48
|
+
* @param {T['_dto']} json - The JSON object.
|
49
|
+
* @returns {T} - An instance of the T.
|
56
50
|
*/
|
57
|
-
static fromJson<
|
51
|
+
static fromJson<T extends RequestEntityMapper<BaseEntity, SV>, SV extends AnySchemaValidator, JsonType extends T['_dto']>(this: EntityMapperConstructor<T, SV>, schemaValidator: SV, json: JsonType): T;
|
58
52
|
/**
|
59
53
|
* Deserializes a JSON object to an entity.
|
60
54
|
*
|
61
|
-
* @template
|
62
|
-
* @param {EntityMapperConstructor<
|
63
|
-
* @param {
|
64
|
-
* @param {
|
55
|
+
* @template T - A type that extends RequestEntityMapper.
|
56
|
+
* @param {EntityMapperConstructor<T>} this - The constructor of the T.
|
57
|
+
* @param {T['_SV']} schemaValidator - The schema provider.
|
58
|
+
* @param {T['_dto']} json - The JSON object.
|
65
59
|
* @param {...unknown[]} additionalArgs - Additional arguments.
|
66
|
-
* @returns {
|
60
|
+
* @returns {T['_Entity']} - The entity.
|
67
61
|
*/
|
68
|
-
static deserializeJsonToEntity<
|
62
|
+
static deserializeJsonToEntity<T extends RequestEntityMapper<BaseEntity, SV>, SV extends AnySchemaValidator, JsonType extends T['_dto']>(this: EntityMapperConstructor<T, SV>, schemaValidator: SV, json: JsonType, ...additionalArgs: unknown[]): T['_Entity'];
|
69
63
|
}
|
@@ -16,14 +16,6 @@ class RequestEntityMapper extends baseEntityMapper_model_1.BaseEntityMapper {
|
|
16
16
|
* @protected
|
17
17
|
*/
|
18
18
|
_Entity;
|
19
|
-
/**
|
20
|
-
* Creates an instance of RequestEntityMapper.
|
21
|
-
*
|
22
|
-
* @param {SV} schemaValidator - The schema provider.
|
23
|
-
*/
|
24
|
-
constructor(schemaValidator) {
|
25
|
-
super(schemaValidator);
|
26
|
-
}
|
27
19
|
/**
|
28
20
|
* Populates the DTO with data from a JSON object.
|
29
21
|
*
|
@@ -50,11 +42,11 @@ class RequestEntityMapper extends baseEntityMapper_model_1.BaseEntityMapper {
|
|
50
42
|
/**
|
51
43
|
* Creates an instance of a RequestEntityMapper from a JSON object.
|
52
44
|
*
|
53
|
-
* @template
|
54
|
-
* @param {EntityMapperConstructor<
|
55
|
-
* @param {
|
56
|
-
* @param {
|
57
|
-
* @returns {
|
45
|
+
* @template T - A type that extends RequestEntityMapper.
|
46
|
+
* @param {EntityMapperConstructor<T>} this - The constructor of the T.
|
47
|
+
* @param {T['_SV']} schemaValidator - The schema provider.
|
48
|
+
* @param {T['_dto']} json - The JSON object.
|
49
|
+
* @returns {T} - An instance of the T.
|
58
50
|
*/
|
59
51
|
static fromJson(schemaValidator, json) {
|
60
52
|
return (0, baseEntityMapper_model_1.construct)(this, schemaValidator).fromJson(json);
|
@@ -62,15 +54,17 @@ class RequestEntityMapper extends baseEntityMapper_model_1.BaseEntityMapper {
|
|
62
54
|
/**
|
63
55
|
* Deserializes a JSON object to an entity.
|
64
56
|
*
|
65
|
-
* @template
|
66
|
-
* @param {EntityMapperConstructor<
|
67
|
-
* @param {
|
68
|
-
* @param {
|
57
|
+
* @template T - A type that extends RequestEntityMapper.
|
58
|
+
* @param {EntityMapperConstructor<T>} this - The constructor of the T.
|
59
|
+
* @param {T['_SV']} schemaValidator - The schema provider.
|
60
|
+
* @param {T['_dto']} json - The JSON object.
|
69
61
|
* @param {...unknown[]} additionalArgs - Additional arguments.
|
70
|
-
* @returns {
|
62
|
+
* @returns {T['_Entity']} - The entity.
|
71
63
|
*/
|
72
64
|
static deserializeJsonToEntity(schemaValidator, json, ...additionalArgs) {
|
73
|
-
return (0, baseEntityMapper_model_1.construct)(this, schemaValidator)
|
65
|
+
return (0, baseEntityMapper_model_1.construct)(this, schemaValidator)
|
66
|
+
.fromJson(json)
|
67
|
+
.toEntity(...additionalArgs);
|
74
68
|
}
|
75
69
|
}
|
76
70
|
exports.RequestEntityMapper = RequestEntityMapper;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"requestEntityMapper.model.js","sourceRoot":"","sources":["../../../entityMapper/models/requestEntityMapper.model.ts"],"names":[],"mappings":";;;AAGA,qEAAuE;AAEvE;;;;;;GAMG;AACH,MAAsB,
|
1
|
+
{"version":3,"file":"requestEntityMapper.model.js","sourceRoot":"","sources":["../../../entityMapper/models/requestEntityMapper.model.ts"],"names":[],"mappings":";;;AAGA,qEAAuE;AAEvE;;;;;;GAMG;AACH,MAAsB,mBAGpB,SAAQ,yCAAoB;IAC5B;;;;OAIG;IACH,OAAO,CAAU;IAWjB;;;;;OAKG;IACH,QAAQ,CAAC,IAAkB;QACzB,IACE,CAAC,IAAI,CAAC,eAAe,CAAC,QAAQ,CAC5B,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAC1C,IAAI,CACL,EACD,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC;QACjC,CAAC;QACD,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC;QAChB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;OAMG;IACH,uBAAuB,CACrB,IAAkB,EAClB,GAAG,cAAyB;QAE5B,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,GAAG,cAAc,CAAC,CAAC;IACzD,CAAC;IAED;;;;;;;;OAQG;IACH,MAAM,CAAC,QAAQ,CAMb,eAAmB,EACnB,IAAc;QAEd,OAAO,IAAA,kCAAS,EAAC,IAAI,EAAE,eAAe,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACzD,CAAC;IAED;;;;;;;;;OASG;IACH,MAAM,CAAC,uBAAuB,CAM5B,eAAmB,EACnB,IAAc,EACd,GAAG,cAAyB;QAE5B,OAAO,IAAA,kCAAS,EAAC,IAAI,EAAE,eAAe,CAAC;aACpC,QAAQ,CAAC,IAAI,CAAC;aACd,QAAQ,CAAC,GAAG,cAAc,CAAC,CAAC;IACjC,CAAC;CACF;AAlGD,kDAkGC"}
|
@@ -1,8 +1,7 @@
|
|
1
|
-
import {
|
2
|
-
import { BaseEntity } from
|
3
|
-
import { EntityMapperConstructor } from
|
4
|
-
import {
|
5
|
-
import { BaseEntityMapper } from "./baseEntityMapper.model";
|
1
|
+
import { AnySchemaValidator } from '@forklaunch/validator';
|
2
|
+
import { BaseEntity } from '../../database/mikro/models/entities/base.entity';
|
3
|
+
import { EntityMapperConstructor } from '../interfaces/entityMapper.interface';
|
4
|
+
import { BaseEntityMapper } from './baseEntityMapper.model';
|
6
5
|
/**
|
7
6
|
* Abstract class representing a response entityMapper.
|
8
7
|
*
|
@@ -10,7 +9,7 @@ import { BaseEntityMapper } from "./baseEntityMapper.model";
|
|
10
9
|
* @template SV - A type that extends SchemaValidator.
|
11
10
|
* @extends {BaseEntityMapper<SV>}
|
12
11
|
*/
|
13
|
-
export declare abstract class ResponseEntityMapper<Entity extends BaseEntity
|
12
|
+
export declare abstract class ResponseEntityMapper<Entity extends BaseEntity, SV extends AnySchemaValidator> extends BaseEntityMapper<SV> {
|
14
13
|
/**
|
15
14
|
* The entity type.
|
16
15
|
* @type {Entity}
|
@@ -42,19 +41,19 @@ export declare abstract class ResponseEntityMapper<Entity extends BaseEntity | u
|
|
42
41
|
/**
|
43
42
|
* Populates entityMapper with DTO from an entity.
|
44
43
|
*
|
45
|
-
* @template
|
46
|
-
* @param {EntityMapperConstructor<
|
47
|
-
* @param {
|
48
|
-
* @returns {
|
44
|
+
* @template T - A type that extends ResponseEntityMapper.
|
45
|
+
* @param {EntityMapperConstructor<T>} this - The constructor of the T.
|
46
|
+
* @param {T['_Entity']} entity - The entity to convert.
|
47
|
+
* @returns {T} - An instance of the T.
|
49
48
|
*/
|
50
|
-
static fromEntity<
|
49
|
+
static fromEntity<T extends ResponseEntityMapper<BaseEntity, SV>, SV extends AnySchemaValidator>(this: EntityMapperConstructor<T, SV>, schemaValidator: SV, entity: T['_Entity']): T;
|
51
50
|
/**
|
52
51
|
* Serializes an entity to a JSON object.
|
53
52
|
*
|
54
|
-
* @template
|
55
|
-
* @param {EntityMapperConstructor<
|
56
|
-
* @param {
|
57
|
-
* @returns {
|
53
|
+
* @template T - A type that extends ResponseEntityMapper.
|
54
|
+
* @param {EntityMapperConstructor<T>} this - The constructor of the T.
|
55
|
+
* @param {T['_Entity']} entity - The entity to serialize.
|
56
|
+
* @returns {T['_dto']} - The JSON object.
|
58
57
|
*/
|
59
|
-
static serializeEntityToJson<
|
58
|
+
static serializeEntityToJson<T extends ResponseEntityMapper<BaseEntity, SV>, SV extends AnySchemaValidator>(this: EntityMapperConstructor<T, SV>, schemaValidator: SV, entity: T['_Entity']): T['_dto'];
|
60
59
|
}
|
@@ -40,10 +40,10 @@ class ResponseEntityMapper extends baseEntityMapper_model_1.BaseEntityMapper {
|
|
40
40
|
/**
|
41
41
|
* Populates entityMapper with DTO from an entity.
|
42
42
|
*
|
43
|
-
* @template
|
44
|
-
* @param {EntityMapperConstructor<
|
45
|
-
* @param {
|
46
|
-
* @returns {
|
43
|
+
* @template T - A type that extends ResponseEntityMapper.
|
44
|
+
* @param {EntityMapperConstructor<T>} this - The constructor of the T.
|
45
|
+
* @param {T['_Entity']} entity - The entity to convert.
|
46
|
+
* @returns {T} - An instance of the T.
|
47
47
|
*/
|
48
48
|
static fromEntity(schemaValidator, entity) {
|
49
49
|
return (0, baseEntityMapper_model_1.construct)(this, schemaValidator).fromEntity(entity);
|
@@ -51,10 +51,10 @@ class ResponseEntityMapper extends baseEntityMapper_model_1.BaseEntityMapper {
|
|
51
51
|
/**
|
52
52
|
* Serializes an entity to a JSON object.
|
53
53
|
*
|
54
|
-
* @template
|
55
|
-
* @param {EntityMapperConstructor<
|
56
|
-
* @param {
|
57
|
-
* @returns {
|
54
|
+
* @template T - A type that extends ResponseEntityMapper.
|
55
|
+
* @param {EntityMapperConstructor<T>} this - The constructor of the T.
|
56
|
+
* @param {T['_Entity']} entity - The entity to serialize.
|
57
|
+
* @returns {T['_dto']} - The JSON object.
|
58
58
|
*/
|
59
59
|
static serializeEntityToJson(schemaValidator, entity) {
|
60
60
|
return (0, baseEntityMapper_model_1.construct)(this, schemaValidator).serializeEntityToJson(entity);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"responseEntityMapper.model.js","sourceRoot":"","sources":["../../../entityMapper/models/responseEntityMapper.model.ts"],"names":[],"mappings":";;;
|
1
|
+
{"version":3,"file":"responseEntityMapper.model.js","sourceRoot":"","sources":["../../../entityMapper/models/responseEntityMapper.model.ts"],"names":[],"mappings":";;;AAGA,qEAAuE;AAEvE;;;;;;GAMG;AACH,MAAsB,oBAGpB,SAAQ,yCAAoB;IAC5B;;;;OAIG;IACH,OAAO,CAAU;IAWjB;;;;;OAKG;IACH,MAAM;QACJ,IACE,CAAC,IAAI,CAAC,eAAe,CAAC,QAAQ,CAC5B,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAC1C,IAAI,CAAC,GAAG,CACT,EACD,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC;QACjC,CAAC;QACD,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;IAED;;;;;OAKG;IACH,qBAAqB,CAAC,MAAc;QAClC,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC;IAC1C,CAAC;IAED;;;;;;;OAOG;IACH,MAAM,CAAC,UAAU,CAKf,eAAmB,EACnB,MAAoB;QAEpB,OAAO,IAAA,kCAAS,EAAC,IAAI,EAAE,eAAe,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IAC7D,CAAC;IAED;;;;;;;OAOG;IACH,MAAM,CAAC,qBAAqB,CAK1B,eAAmB,EACnB,MAAoB;QAEpB,OAAO,IAAA,kCAAS,EAAC,IAAI,EAAE,eAAe,CAAC,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC;IACxE,CAAC;CACF;AArFD,oDAqFC"}
|