@forklaunch/core 0.2.21 → 0.2.23
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/eslint.config.d.mts +1132 -1
- package/lib/src/cache/interfaces/ttlCache.interface.d.ts +2 -2
- package/lib/src/cache/interfaces/ttlCache.interface.d.ts.map +1 -1
- package/lib/src/cache/redisTtlCache.d.ts +2 -2
- package/lib/src/cache/redisTtlCache.d.ts.map +1 -1
- package/lib/src/cache/types/ttlCacheRecord.types.d.ts +2 -2
- package/lib/src/cache/types/ttlCacheRecord.types.d.ts.map +1 -1
- package/lib/src/dtoMapper/models/baseDtoMapper.model.d.ts.map +1 -1
- package/lib/src/dtoMapper/models/baseDtoMapper.model.js +3 -2
- package/lib/src/dtoMapper/models/requestDtoMapper.model.d.ts +4 -4
- package/lib/src/dtoMapper/models/requestDtoMapper.model.d.ts.map +1 -1
- package/lib/src/dtoMapper/models/requestDtoMapper.model.js +10 -9
- package/lib/src/dtoMapper/models/responseDtoMapper.model.d.ts +3 -3
- package/lib/src/dtoMapper/models/responseDtoMapper.model.d.ts.map +1 -1
- package/lib/src/dtoMapper/models/responseDtoMapper.model.js +8 -7
- package/lib/src/services/configInjector.js +1 -1
- package/lib/tests/dtoMapper.test.js +19 -16
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
@@ -9,7 +9,7 @@ export interface TtlCache {
|
|
9
9
|
* @param {TtlCacheRecord} cacheRecord - The cache record to put into the cache.
|
10
10
|
* @returns {Promise<void>} - A promise that resolves when the record is put into the cache.
|
11
11
|
*/
|
12
|
-
putRecord(cacheRecord: TtlCacheRecord): Promise<void>;
|
12
|
+
putRecord<T>(cacheRecord: TtlCacheRecord<T>): Promise<void>;
|
13
13
|
/**
|
14
14
|
* Deletes a record from the cache.
|
15
15
|
*
|
@@ -23,7 +23,7 @@ export interface TtlCache {
|
|
23
23
|
* @param {string} cacheRecordKey - The key of the cache record to read.
|
24
24
|
* @returns {Promise<TtlCacheRecord>} - A promise that resolves with the cache record.
|
25
25
|
*/
|
26
|
-
readRecord(cacheRecordKey: string): Promise<TtlCacheRecord
|
26
|
+
readRecord<T>(cacheRecordKey: string): Promise<TtlCacheRecord<T>>;
|
27
27
|
/**
|
28
28
|
* Peeks at a record in the cache to check if it exists.
|
29
29
|
*
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"ttlCache.interface.d.ts","sourceRoot":"","sources":["../../../../src/cache/interfaces/ttlCache.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAE/D;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB;;;;;OAKG;IACH,SAAS,CAAC,WAAW,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;
|
1
|
+
{"version":3,"file":"ttlCache.interface.d.ts","sourceRoot":"","sources":["../../../../src/cache/interfaces/ttlCache.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAE/D;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB;;;;;OAKG;IACH,SAAS,CAAC,CAAC,EAAE,WAAW,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5D;;;;;OAKG;IACH,YAAY,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpD;;;;;OAKG;IACH,UAAU,CAAC,CAAC,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;IAElE;;;;;OAKG;IACH,UAAU,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAErD;;;;OAIG;IACH,kBAAkB,IAAI,MAAM,CAAC;IAE7B;;;;;OAKG;IACH,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CACrD"}
|
@@ -21,7 +21,7 @@ export declare class RedisTtlCache implements TtlCache {
|
|
21
21
|
* @param {TtlCacheRecord} param0 - The cache record to put into the cache.
|
22
22
|
* @returns {Promise<void>} - A promise that resolves when the record is put into the cache.
|
23
23
|
*/
|
24
|
-
putRecord({ key, value, ttlMilliseconds }: TtlCacheRecord): Promise<void>;
|
24
|
+
putRecord<T>({ key, value, ttlMilliseconds }: TtlCacheRecord<T>): Promise<void>;
|
25
25
|
/**
|
26
26
|
* Deletes a record from the Redis cache.
|
27
27
|
*
|
@@ -36,7 +36,7 @@ export declare class RedisTtlCache implements TtlCache {
|
|
36
36
|
* @returns {Promise<TtlCacheRecord>} - A promise that resolves with the cache record.
|
37
37
|
* @throws {Error} - Throws an error if the record is not found.
|
38
38
|
*/
|
39
|
-
readRecord(cacheRecordKey: string): Promise<TtlCacheRecord
|
39
|
+
readRecord<T>(cacheRecordKey: string): Promise<TtlCacheRecord<T>>;
|
40
40
|
/**
|
41
41
|
* Lists the keys in the Redis cache that match a pattern prefix.
|
42
42
|
*
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"redisTtlCache.d.ts","sourceRoot":"","sources":["../../../src/cache/redisTtlCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAgB,MAAM,OAAO,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D;;;GAGG;AACH,qBAAa,aAAc,YAAW,QAAQ;IAU1C,OAAO,CAAC,eAAe;IATzB,OAAO,CAAC,MAAM,CAAC;IAEf;;;;;OAKG;gBAEO,eAAe,EAAE,MAAM,EAC/B,cAAc,CAAC,EAAE,kBAAkB;IASrC;;;;;OAKG;IACG,SAAS,CAAC,
|
1
|
+
{"version":3,"file":"redisTtlCache.d.ts","sourceRoot":"","sources":["../../../src/cache/redisTtlCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAgB,MAAM,OAAO,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D;;;GAGG;AACH,qBAAa,aAAc,YAAW,QAAQ;IAU1C,OAAO,CAAC,eAAe;IATzB,OAAO,CAAC,MAAM,CAAC;IAEf;;;;;OAKG;gBAEO,eAAe,EAAE,MAAM,EAC/B,cAAc,CAAC,EAAE,kBAAkB;IASrC;;;;;OAKG;IACG,SAAS,CAAC,CAAC,EAAE,EACjB,GAAG,EACH,KAAK,EACL,eAAsC,EACvC,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAMpC;;;;;OAKG;IACG,YAAY,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzD;;;;;;OAMG;IACG,UAAU,CAAC,CAAC,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;IAavE;;;;;OAKG;IACG,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAKzD;;;;;OAKG;IACG,UAAU,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAK1D;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAIjC;;;;OAIG;IACH,kBAAkB,IAAI,MAAM;CAG7B"}
|
@@ -6,9 +6,9 @@
|
|
6
6
|
* @property {any} value - The value of the cache record.
|
7
7
|
* @property {number} ttlMilliseconds - The time-to-live of the cache record in milliseconds.
|
8
8
|
*/
|
9
|
-
export type TtlCacheRecord = {
|
9
|
+
export type TtlCacheRecord<T> = {
|
10
10
|
key: string;
|
11
|
-
value:
|
11
|
+
value: T;
|
12
12
|
ttlMilliseconds: number;
|
13
13
|
};
|
14
14
|
//# sourceMappingURL=ttlCacheRecord.types.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"ttlCacheRecord.types.d.ts","sourceRoot":"","sources":["../../../../src/cache/types/ttlCacheRecord.types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,MAAM,cAAc,
|
1
|
+
{"version":3,"file":"ttlCacheRecord.types.d.ts","sourceRoot":"","sources":["../../../../src/cache/types/ttlCacheRecord.types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,CAAC,CAAC;IACT,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"baseDtoMapper.model.d.ts","sourceRoot":"","sources":["../../../../src/dtoMapper/models/baseDtoMapper.model.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,MAAM,EACN,eAAe,EAChB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,8BAA8B,EAAE,MAAM,0BAA0B,CAAC;AAE1E;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,EAAE,SAAS,kBAAkB,EACxD,IAAI,EAAE,oBAAoB,CAAC,CAAC,EAAE,EAAE,CAAC,EACjC,eAAe,CAAC,EAAE,EAAE,GACnB,CAAC,CAEH;AAED;;;;GAIG;AACH,8BAAsB,aAAa,CAAC,EAAE,SAAS,kBAAkB;IAC/D;;;;OAIG;IACH,GAAG,EAAG,EAAE,CAAC;IAET;;;;OAIG;IACH,SAAS,CAAC,eAAe,EAAE,eAAe,CAAC;IAE3C;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,8BAA8B,CAAC,EAAE,CAAC,CAAC;IAEpD;;;OAGG;IACH,IAA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C,CAAC,SAAS,aAAa,CAAC,EAAE,CAAC,EAAE,EAAE,SAAS,kBAAkB,EACtE,IAAI,EAAE,oBAAoB,CAAC,CAAC,EAAE,EAAE,CAAC,GAChC,CAAC,CAAC,QAAQ,CAAC;CAGf"}
|
@@ -48,8 +48,9 @@ export class BaseDtoMapper {
|
|
48
48
|
* @throws {Error} - Throws an error if the DTO is invalid.
|
49
49
|
*/
|
50
50
|
set dto(_dto) {
|
51
|
-
|
52
|
-
|
51
|
+
const parsedSchema = this.schemaValidator.parse(this.schemaValidator.schemify(this.schema), _dto);
|
52
|
+
if (!parsedSchema.ok) {
|
53
|
+
throw new Error(`Invalid DTO: ${parsedSchema.error}`);
|
53
54
|
}
|
54
55
|
this._dto = _dto;
|
55
56
|
}
|
@@ -30,7 +30,7 @@ export declare abstract class RequestDtoMapper<Entity extends BaseEntity, SV ext
|
|
30
30
|
* @param {this['_dto']} json - The JSON object.
|
31
31
|
* @returns {this} - The instance of the RequestDtoMapper.
|
32
32
|
*/
|
33
|
-
|
33
|
+
fromDto(json: this['_dto']): this;
|
34
34
|
/**
|
35
35
|
* Deserializes a JSON object to an entity.
|
36
36
|
*
|
@@ -38,7 +38,7 @@ export declare abstract class RequestDtoMapper<Entity extends BaseEntity, SV ext
|
|
38
38
|
* @param {...unknown[]} additionalArgs - Additional arguments.
|
39
39
|
* @returns {Entity} - The entity.
|
40
40
|
*/
|
41
|
-
|
41
|
+
deserializeDtoToEntity(json: this['_dto'], ...additionalArgs: unknown[]): Entity;
|
42
42
|
/**
|
43
43
|
* Creates an instance of a RequestDtoMapper from a JSON object.
|
44
44
|
*
|
@@ -50,7 +50,7 @@ export declare abstract class RequestDtoMapper<Entity extends BaseEntity, SV ext
|
|
50
50
|
* @param {JsonType} json - The JSON object.
|
51
51
|
* @returns {T} - An instance of the T.
|
52
52
|
*/
|
53
|
-
static
|
53
|
+
static fromDto<T extends RequestDtoMapper<BaseEntity, SV>, SV extends AnySchemaValidator, JsonType extends T['_dto']>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, json: JsonType): T;
|
54
54
|
/**
|
55
55
|
* Deserializes a JSON object to an entity.
|
56
56
|
*
|
@@ -63,6 +63,6 @@ export declare abstract class RequestDtoMapper<Entity extends BaseEntity, SV ext
|
|
63
63
|
* @param {...unknown[]} additionalArgs - Additional arguments.
|
64
64
|
* @returns {T['_Entity']} - The entity.
|
65
65
|
*/
|
66
|
-
static
|
66
|
+
static deserializeDtoToEntity<T extends RequestDtoMapper<BaseEntity, SV>, SV extends AnySchemaValidator, JsonType extends T['_dto']>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, json: JsonType, ...additionalArgs: unknown[]): T['_Entity'];
|
67
67
|
}
|
68
68
|
//# sourceMappingURL=requestDtoMapper.model.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"requestDtoMapper.model.d.ts","sourceRoot":"","sources":["../../../../src/dtoMapper/models/requestDtoMapper.model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,kDAAkD,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAa,MAAM,uBAAuB,CAAC;AAEjE;;;;;;GAMG;AACH,8BAAsB,gBAAgB,CACpC,MAAM,SAAS,UAAU,EACzB,EAAE,SAAS,kBAAkB,CAC7B,SAAQ,aAAa,CAAC,EAAE,CAAC;IACzB;;;;OAIG;IACH,OAAO,EAAG,MAAM,CAAC;IAEjB;;;;;;OAMG;IACH,QAAQ,CAAC,QAAQ,CAAC,GAAG,cAAc,EAAE,OAAO,EAAE,GAAG,MAAM;IAEvD;;;;;OAKG;IACH,
|
1
|
+
{"version":3,"file":"requestDtoMapper.model.d.ts","sourceRoot":"","sources":["../../../../src/dtoMapper/models/requestDtoMapper.model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,k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EAAE,QAAQ,EACd,GAAG,cAAc,EAAE,OAAO,EAAE,GAC3B,CAAC,CAAC,SAAS,CAAC;CAKhB"}
|
@@ -19,9 +19,10 @@ export class RequestDtoMapper extends BaseDtoMapper {
|
|
19
19
|
* @param {this['_dto']} json - The JSON object.
|
20
20
|
* @returns {this} - The instance of the RequestDtoMapper.
|
21
21
|
*/
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
fromDto(json) {
|
23
|
+
const parsedSchema = this.schemaValidator.parse(this.schemaValidator.schemify(this.schema), json);
|
24
|
+
if (!parsedSchema.ok) {
|
25
|
+
throw new Error(`Invalid DTO: ${parsedSchema.error}`);
|
25
26
|
}
|
26
27
|
this.dto = json;
|
27
28
|
return this;
|
@@ -33,8 +34,8 @@ export class RequestDtoMapper extends BaseDtoMapper {
|
|
33
34
|
* @param {...unknown[]} additionalArgs - Additional arguments.
|
34
35
|
* @returns {Entity} - The entity.
|
35
36
|
*/
|
36
|
-
|
37
|
-
return this.
|
37
|
+
deserializeDtoToEntity(json, ...additionalArgs) {
|
38
|
+
return this.fromDto(json).toEntity(...additionalArgs);
|
38
39
|
}
|
39
40
|
/**
|
40
41
|
* Creates an instance of a RequestDtoMapper from a JSON object.
|
@@ -47,8 +48,8 @@ export class RequestDtoMapper extends BaseDtoMapper {
|
|
47
48
|
* @param {JsonType} json - The JSON object.
|
48
49
|
* @returns {T} - An instance of the T.
|
49
50
|
*/
|
50
|
-
static
|
51
|
-
return construct(this, schemaValidator).
|
51
|
+
static fromDto(schemaValidator, json) {
|
52
|
+
return construct(this, schemaValidator).fromDto(json);
|
52
53
|
}
|
53
54
|
/**
|
54
55
|
* Deserializes a JSON object to an entity.
|
@@ -62,9 +63,9 @@ export class RequestDtoMapper extends BaseDtoMapper {
|
|
62
63
|
* @param {...unknown[]} additionalArgs - Additional arguments.
|
63
64
|
* @returns {T['_Entity']} - The entity.
|
64
65
|
*/
|
65
|
-
static
|
66
|
+
static deserializeDtoToEntity(schemaValidator, json, ...additionalArgs) {
|
66
67
|
return construct(this, schemaValidator)
|
67
|
-
.
|
68
|
+
.fromDto(json)
|
68
69
|
.toEntity(...additionalArgs);
|
69
70
|
}
|
70
71
|
}
|
@@ -31,7 +31,7 @@ export declare abstract class ResponseDtoMapper<Entity extends BaseEntity, SV ex
|
|
31
31
|
* @returns {this['_dto']} - The JSON object.
|
32
32
|
* @throws {Error} - Throws an error if the DTO is invalid.
|
33
33
|
*/
|
34
|
-
|
34
|
+
toDto(): this['_dto'];
|
35
35
|
/**
|
36
36
|
* Serializes an entity to a JSON object.
|
37
37
|
*
|
@@ -39,7 +39,7 @@ export declare abstract class ResponseDtoMapper<Entity extends BaseEntity, SV ex
|
|
39
39
|
* @returns {this['_dto']} - The JSON object.
|
40
40
|
* @throws {Error} - Throws an error if the DTO is invalid.
|
41
41
|
*/
|
42
|
-
|
42
|
+
serializeEntityToDto(entity: Entity): this['_dto'];
|
43
43
|
/**
|
44
44
|
* Populates entity mapper with DTO from an entity.
|
45
45
|
*
|
@@ -62,6 +62,6 @@ export declare abstract class ResponseDtoMapper<Entity extends BaseEntity, SV ex
|
|
62
62
|
* @returns {T['_dto']} - The JSON object.
|
63
63
|
* @throws {Error} - Throws an error if the DTO is invalid.
|
64
64
|
*/
|
65
|
-
static
|
65
|
+
static serializeEntityToDto<T extends ResponseDtoMapper<BaseEntity, SV>, SV extends AnySchemaValidator, JsonType extends T['_dto']>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, entity: T['_Entity']): JsonType;
|
66
66
|
}
|
67
67
|
//# sourceMappingURL=responseDtoMapper.model.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"responseDtoMapper.model.d.ts","sourceRoot":"","sources":["../../../../src/dtoMapper/models/responseDtoMapper.model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,kDAAkD,CAAC;AAC9E,OAAO,EA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UAAU,EAAE,EAAE,CAAC,EAC3C,EAAE,SAAS,kBAAkB,EAE7B,IAAI,EAAE,oBAAoB,CAAC,CAAC,EAAE,EAAE,CAAC,EACjC,eAAe,EAAE,EAAE,EACnB,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,GACnB,CAAC;IAIJ;;;;;;;;;;OAUG;IACH,MAAM,CAAC,oBAAoB,CACzB,CAAC,SAAS,iBAAiB,CAAC,UAAU,EAAE,EAAE,CAAC,EAC3C,EAAE,SAAS,kBAAkB,EAC7B,QAAQ,SAAS,CAAC,CAAC,MAAM,CAAC,EAE1B,IAAI,EAAE,oBAAoB,CAAC,CAAC,EAAE,EAAE,CAAC,EACjC,eAAe,EAAE,EAAE,EACnB,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,GACnB,QAAQ;CAKZ"}
|
@@ -19,9 +19,10 @@ export class ResponseDtoMapper extends BaseDtoMapper {
|
|
19
19
|
* @returns {this['_dto']} - The JSON object.
|
20
20
|
* @throws {Error} - Throws an error if the DTO is invalid.
|
21
21
|
*/
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
toDto() {
|
23
|
+
const parsedSchema = this.schemaValidator.parse(this.schemaValidator.schemify(this.schema), this.dto);
|
24
|
+
if (!parsedSchema.ok) {
|
25
|
+
throw new Error(`Invalid DTO: ${parsedSchema.error}`);
|
25
26
|
}
|
26
27
|
return this.dto;
|
27
28
|
}
|
@@ -32,8 +33,8 @@ export class ResponseDtoMapper extends BaseDtoMapper {
|
|
32
33
|
* @returns {this['_dto']} - The JSON object.
|
33
34
|
* @throws {Error} - Throws an error if the DTO is invalid.
|
34
35
|
*/
|
35
|
-
|
36
|
-
return this.fromEntity(entity).
|
36
|
+
serializeEntityToDto(entity) {
|
37
|
+
return this.fromEntity(entity).toDto();
|
37
38
|
}
|
38
39
|
/**
|
39
40
|
* Populates entity mapper with DTO from an entity.
|
@@ -59,7 +60,7 @@ export class ResponseDtoMapper extends BaseDtoMapper {
|
|
59
60
|
* @returns {T['_dto']} - The JSON object.
|
60
61
|
* @throws {Error} - Throws an error if the DTO is invalid.
|
61
62
|
*/
|
62
|
-
static
|
63
|
-
return construct(this, schemaValidator).
|
63
|
+
static serializeEntityToDto(schemaValidator, entity) {
|
64
|
+
return construct(this, schemaValidator).serializeEntityToDto(entity);
|
64
65
|
}
|
65
66
|
}
|
@@ -76,7 +76,7 @@ export class ConfigInjector {
|
|
76
76
|
}
|
77
77
|
}
|
78
78
|
scopedResolver(token, context, resolutionPath = []) {
|
79
|
-
return (scope) => (scope ?? this).resolve(token, context, resolutionPath);
|
79
|
+
return (scope) => (scope ?? this.createScope()).resolve(token, context, resolutionPath);
|
80
80
|
}
|
81
81
|
createScope() {
|
82
82
|
return new ConfigInjector(this.schemaValidator, this.configShapes, this.dependenciesDefinition);
|
@@ -54,10 +54,13 @@ function extractNonTimeBasedEntityFields(entity) {
|
|
54
54
|
entity.updatedAt = new Date(0);
|
55
55
|
return entity;
|
56
56
|
}
|
57
|
+
function genericDtoWrapperFunction(dto) {
|
58
|
+
return dto;
|
59
|
+
}
|
57
60
|
describe('request dtoMapper tests', () => {
|
58
61
|
let TestRequestDM;
|
59
62
|
beforeAll(() => {
|
60
|
-
TestRequestDM = new TestRequestDtoMapper(
|
63
|
+
TestRequestDM = new TestRequestDtoMapper(SV);
|
61
64
|
});
|
62
65
|
test('schema static and constructed equality', async () => {
|
63
66
|
expect(TestRequestDM.schema).toEqual(TestRequestDtoMapper.schema());
|
@@ -68,8 +71,8 @@ describe('request dtoMapper tests', () => {
|
|
68
71
|
name: 'test',
|
69
72
|
age: 1
|
70
73
|
};
|
71
|
-
const responseDM = TestRequestDM.
|
72
|
-
const staticDM = TestRequestDtoMapper.
|
74
|
+
const responseDM = TestRequestDM.fromDto(json);
|
75
|
+
const staticDM = TestRequestDtoMapper.fromDto(SV, json);
|
73
76
|
const expectedDto = {
|
74
77
|
id: '123',
|
75
78
|
name: 'test',
|
@@ -85,9 +88,10 @@ describe('request dtoMapper tests', () => {
|
|
85
88
|
name: 'test',
|
86
89
|
age: 1
|
87
90
|
};
|
88
|
-
const entity = extractNonTimeBasedEntityFields(TestRequestDM.
|
89
|
-
const objectEntity = extractNonTimeBasedEntityFields(TestRequestDM.
|
90
|
-
const
|
91
|
+
const entity = extractNonTimeBasedEntityFields(TestRequestDM.deserializeDtoToEntity(json));
|
92
|
+
const objectEntity = extractNonTimeBasedEntityFields(TestRequestDM.fromDto(json).toEntity());
|
93
|
+
const e = TestRequestDtoMapper.deserializeDtoToEntity(SV, json);
|
94
|
+
const staticEntity = extractNonTimeBasedEntityFields(TestRequestDtoMapper.deserializeDtoToEntity(SV, json));
|
91
95
|
let expectedEntity = new TestEntity();
|
92
96
|
expectedEntity.id = '123';
|
93
97
|
expectedEntity.name = 'test';
|
@@ -107,16 +111,15 @@ describe('request dtoMapper tests', () => {
|
|
107
111
|
name: 'test'
|
108
112
|
};
|
109
113
|
// @ts-expect-error
|
110
|
-
expect(() => TestRequestDM.
|
111
|
-
expect(() =>
|
114
|
+
expect(() => TestRequestDM.fromDto(json)).toThrow();
|
112
115
|
// @ts-expect-error
|
113
|
-
TestRequestDtoMapper.
|
116
|
+
expect(() => TestRequestDtoMapper.fromDto(SV, json)).toThrow();
|
114
117
|
});
|
115
118
|
});
|
116
119
|
describe('response dtoMapper tests', () => {
|
117
120
|
let TestResponseDM;
|
118
121
|
beforeAll(() => {
|
119
|
-
TestResponseDM = new TestResponseDtoMapper(
|
122
|
+
TestResponseDM = new TestResponseDtoMapper(SV);
|
120
123
|
});
|
121
124
|
test('schema static and constructed equality', async () => {
|
122
125
|
expect(TestResponseDM.schema).toEqual(TestResponseDtoMapper.schema());
|
@@ -127,7 +130,7 @@ describe('response dtoMapper tests', () => {
|
|
127
130
|
entity.name = 'test';
|
128
131
|
entity.age = 1;
|
129
132
|
const responseDM = TestResponseDM.fromEntity(entity);
|
130
|
-
const staticDM = TestResponseDtoMapper.fromEntity(
|
133
|
+
const staticDM = TestResponseDtoMapper.fromEntity(SV, entity);
|
131
134
|
const expectedDto = {
|
132
135
|
id: '123',
|
133
136
|
name: 'test',
|
@@ -142,9 +145,9 @@ describe('response dtoMapper tests', () => {
|
|
142
145
|
entity.id = '123';
|
143
146
|
entity.name = 'test';
|
144
147
|
entity.age = 1;
|
145
|
-
const json = TestResponseDM.
|
146
|
-
const objectJson = TestResponseDM.fromEntity(entity).
|
147
|
-
const staticJson = TestResponseDtoMapper.
|
148
|
+
const json = genericDtoWrapperFunction(TestResponseDM.serializeEntityToDto(entity));
|
149
|
+
const objectJson = genericDtoWrapperFunction(TestResponseDM.fromEntity(entity).toDto());
|
150
|
+
const staticJson = genericDtoWrapperFunction(TestResponseDtoMapper.serializeEntityToDto(SV, entity));
|
148
151
|
const expectedJson = {
|
149
152
|
id: '123',
|
150
153
|
name: 'test',
|
@@ -162,7 +165,7 @@ describe('response dtoMapper tests', () => {
|
|
162
165
|
const entity = new TestEntity();
|
163
166
|
entity.id = '123';
|
164
167
|
entity.name = 'test';
|
165
|
-
expect(() => TestResponseDM.fromEntity(entity).
|
166
|
-
expect(() => TestResponseDtoMapper.fromEntity(
|
168
|
+
expect(() => TestResponseDM.fromEntity(entity).toDto()).toThrow();
|
169
|
+
expect(() => TestResponseDtoMapper.fromEntity(SV, entity).toDto()).toThrow();
|
167
170
|
});
|
168
171
|
});
|