@forklaunch/core 0.2.22 → 0.2.24

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.
@@ -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;IAEtD;;;;;OAKG;IACH,YAAY,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpD;;;;;OAKG;IACH,UAAU,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAE5D;;;;;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"}
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,EACd,GAAG,EACH,KAAK,EACL,eAAsC,EACvC,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAMjC;;;;;OAKG;IACG,YAAY,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzD;;;;;;OAMG;IACG,UAAU,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAajE;;;;;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"}
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: unknown;
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,GAAG;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,OAAO,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;CACzB,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,MA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AAC,CAAC;IAEpD;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,CAG9B;IAEF;;;;OAIG;gBACS,eAAe,EAAE,EAAE;IAI/B;;;;;OAKG;IACH,IAAI,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,EASzB;IAED;;;;OAIG;IACH,IAAI,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC,CAEtB;IAED;;;;;;;OAOG;IACH,MAAM,CAAC,MAAM,CAAC,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
- if (!this.schemaValidator.validate(this.schemaValidator.schemify(this.schema), _dto)) {
52
- throw new Error('Invalid DTO');
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
- fromJson(json: this['_dto']): this;
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
- deserializeJsonToEntity(json: this['_dto'], ...additionalArgs: unknown[]): Entity;
41
+ deserializeDtoToEntity(json: this['_dto'], ...additionalArgs: Parameters<this['toEntity']>): 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 fromJson<T extends RequestDtoMapper<BaseEntity, SV>, SV extends AnySchemaValidator, JsonType extends T['_dto']>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, json: JsonType): T;
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 deserializeJsonToEntity<T extends RequestDtoMapper<BaseEntity, SV>, SV extends AnySchemaValidator, JsonType extends T['_dto']>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, json: JsonType, ...additionalArgs: unknown[]): T['_Entity'];
66
+ static deserializeDtoToEntity<T extends RequestDtoMapper<BaseEntity, SV>, SV extends AnySchemaValidator, JsonType extends T['_dto']>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, json: JsonType, ...additionalArgs: Parameters<T['toEntity']>): 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,EAA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AE,CAAC,EAC1C,EAAE,SAAS,kBAAkB,EAC7B,QAAQ,SAAS,CAAC,CAAC,MAAM,CAAC,EAE1B,IAAI,EAAE,oBAAoB,CAAC,CAAC,EAAE,EAAE,CAAC,EACjC,eAAe,EAAE,EAAE,EACnB,IAAI,EAAE,QAAQ,EACd,GAAG,cAAc,EAAE,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,GAC3C,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
- fromJson(json) {
23
- if (!this.schemaValidator.validate(this.schemaValidator.schemify(this.schema), json)) {
24
- throw new Error('Invalid DTO');
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
- deserializeJsonToEntity(json, ...additionalArgs) {
37
- return this.fromJson(json).toEntity(...additionalArgs);
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 fromJson(schemaValidator, json) {
51
- return construct(this, schemaValidator).fromJson(json);
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 deserializeJsonToEntity(schemaValidator, json, ...additionalArgs) {
66
+ static deserializeDtoToEntity(schemaValidator, json, ...additionalArgs) {
66
67
  return construct(this, schemaValidator)
67
- .fromJson(json)
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
- toJson(): this['_dto'];
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
- serializeEntityToJson(entity: Entity): this['_dto'];
42
+ serializeEntityToDto(...[entity, ...additionalArgs]: Parameters<this['fromEntity']>): this['_dto'];
43
43
  /**
44
44
  * Populates entity mapper with DTO from an entity.
45
45
  *
@@ -50,7 +50,7 @@ export declare abstract class ResponseDtoMapper<Entity extends BaseEntity, SV ex
50
50
  * @param {T['_Entity']} entity - The entity to convert.
51
51
  * @returns {T} - An instance of the T.
52
52
  */
53
- static fromEntity<T extends ResponseDtoMapper<BaseEntity, SV>, SV extends AnySchemaValidator>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, entity: T['_Entity']): T;
53
+ static fromEntity<T extends ResponseDtoMapper<BaseEntity, SV>, SV extends AnySchemaValidator>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, ...[entity, ...additionalArgs]: Parameters<T['fromEntity']>): T;
54
54
  /**
55
55
  * Serializes an entity to a JSON object.
56
56
  *
@@ -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 serializeEntityToJson<T extends ResponseDtoMapper<BaseEntity, SV>, SV extends AnySchemaValidator>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, entity: T['_Entity']): T['_dto'];
65
+ static serializeEntityToDto<T extends ResponseDtoMapper<BaseEntity, SV>, SV extends AnySchemaValidator, DtoType extends T['_dto']>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, ...[entity, ...additionalArgs]: Parameters<T['fromEntity']>): DtoType;
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,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAa,MAAM,uBAAuB,CAAC;AAEjE;;;;;;GAMG;AACH,8BAAsB,iBAAiB,CACrC,MAAM,SAAS,UAAU,EACzB,EAAE,SAAS,kBAAkB,CAC7B,SAAQ,aAAa,CAAC,EAAE,CAAC;IACzB;;;;OAIG;IACH,OAAO,EAAG,MAAM,CAAC;IAEjB;;;;;;;OAOG;IACH,QAAQ,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,cAAc,EAAE,OAAO,EAAE,GAAG,IAAI;IAEvE;;;;;OAKG;IACH,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC;IAYtB;;;;;;OAMG;IACH,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IAIn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MG;IACH,oBAAoB,CAClB,GAAG,CAAC,MAAM,EAAE,GAAG,cAAc,CAAC,EAAE,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,GAC7D,IAAI,CAAC,MAAM,CAAC;IAIf;;;;;;;;;OASG;IACH,MAAM,CAAC,UAAU,CACf,CAAC,SAAS,iBAAiB,CAAC,UAAU,EAAE,EAAE,CAAC,EAC3C,EAAE,SAAS,kBAAkB,EAE7B,IAAI,EAAE,oBAAoB,CAAC,CAAC,EAAE,EAAE,CAAC,EACjC,eAAe,EAAE,EAAE,EACnB,GAAG,CAAC,MAAM,EAAE,GAAG,cAAc,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,GAC1D,CAAC;IAOJ;;;;;;;;;;OAUG;IACH,MAAM,CAAC,oBAAoB,CACzB,CAAC,SAAS,iBAAiB,CAAC,UAAU,EAAE,EAAE,CAAC,EAC3C,EAAE,SAAS,kBAAkB,EAC7B,OAAO,SAAS,CAAC,CAAC,MAAM,CAAC,EAEzB,IAAI,EAAE,oBAAoB,CAAC,CAAC,EAAE,EAAE,CAAC,EACjC,eAAe,EAAE,EAAE,EACnB,GAAG,CAAC,MAAM,EAAE,GAAG,cAAc,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,GAC1D,OAAO;CAKX"}
@@ -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
- toJson() {
23
- if (!this.schemaValidator.validate(this.schemaValidator.schemify(this.schema), this.dto)) {
24
- throw new Error('Invalid DTO');
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
- serializeEntityToJson(entity) {
36
- return this.fromEntity(entity).toJson();
36
+ serializeEntityToDto(...[entity, ...additionalArgs]) {
37
+ return this.fromEntity(entity, ...additionalArgs).toDto();
37
38
  }
38
39
  /**
39
40
  * Populates entity mapper with DTO from an entity.
@@ -45,8 +46,8 @@ export class ResponseDtoMapper extends BaseDtoMapper {
45
46
  * @param {T['_Entity']} entity - The entity to convert.
46
47
  * @returns {T} - An instance of the T.
47
48
  */
48
- static fromEntity(schemaValidator, entity) {
49
- return construct(this, schemaValidator).fromEntity(entity);
49
+ static fromEntity(schemaValidator, ...[entity, ...additionalArgs]) {
50
+ return construct(this, schemaValidator).fromEntity(entity, ...additionalArgs);
50
51
  }
51
52
  /**
52
53
  * Serializes an entity to a JSON object.
@@ -59,7 +60,9 @@ 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 serializeEntityToJson(schemaValidator, entity) {
63
- return construct(this, schemaValidator).serializeEntityToJson(entity);
63
+ static serializeEntityToDto(schemaValidator, ...[entity, ...additionalArgs]) {
64
+ return construct(this, schemaValidator)
65
+ .fromEntity(entity, ...additionalArgs)
66
+ .toDto();
64
67
  }
65
68
  }
@@ -26,7 +26,7 @@ class TestRequestDtoMapper extends RequestDtoMapper {
26
26
  name: string,
27
27
  age: number
28
28
  };
29
- toEntity(...additionalArgs) {
29
+ toEntity(arg1, arg2) {
30
30
  const entity = new TestEntity();
31
31
  entity.id = this.dto.id;
32
32
  entity.name = this.dto.name;
@@ -40,7 +40,7 @@ class TestResponseDtoMapper extends ResponseDtoMapper {
40
40
  name: string,
41
41
  age: number
42
42
  };
43
- fromEntity(entity) {
43
+ fromEntity(entity, arg1, arg2) {
44
44
  this.dto = {
45
45
  id: entity.id,
46
46
  name: entity.name,
@@ -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(SchemaValidator());
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.fromJson(json);
72
- const staticDM = TestRequestDtoMapper.fromJson(SchemaValidator(), json);
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,9 @@ describe('request dtoMapper tests', () => {
85
88
  name: 'test',
86
89
  age: 1
87
90
  };
88
- const entity = extractNonTimeBasedEntityFields(TestRequestDM.deserializeJsonToEntity(json));
89
- const objectEntity = extractNonTimeBasedEntityFields(TestRequestDM.fromJson(json).toEntity());
90
- const staticEntity = extractNonTimeBasedEntityFields(TestRequestDtoMapper.deserializeJsonToEntity(SchemaValidator(), json));
91
+ const entity = extractNonTimeBasedEntityFields(TestRequestDM.deserializeDtoToEntity(json, 'arg1'));
92
+ const objectEntity = extractNonTimeBasedEntityFields(TestRequestDM.fromDto(json).toEntity('arg1'));
93
+ const staticEntity = extractNonTimeBasedEntityFields(TestRequestDtoMapper.deserializeDtoToEntity(SV, json, 'arg1', 'arg2'));
91
94
  let expectedEntity = new TestEntity();
92
95
  expectedEntity.id = '123';
93
96
  expectedEntity.name = 'test';
@@ -107,16 +110,15 @@ describe('request dtoMapper tests', () => {
107
110
  name: 'test'
108
111
  };
109
112
  // @ts-expect-error
110
- expect(() => TestRequestDM.fromJson(json)).toThrow();
111
- expect(() =>
113
+ expect(() => TestRequestDM.fromDto(json)).toThrow();
112
114
  // @ts-expect-error
113
- TestRequestDtoMapper.fromJson(new TypeboxSchemaValidator(), json)).toThrow();
115
+ expect(() => TestRequestDtoMapper.fromDto(SV, json)).toThrow();
114
116
  });
115
117
  });
116
118
  describe('response dtoMapper tests', () => {
117
119
  let TestResponseDM;
118
120
  beforeAll(() => {
119
- TestResponseDM = new TestResponseDtoMapper(SchemaValidator());
121
+ TestResponseDM = new TestResponseDtoMapper(SV);
120
122
  });
121
123
  test('schema static and constructed equality', async () => {
122
124
  expect(TestResponseDM.schema).toEqual(TestResponseDtoMapper.schema());
@@ -126,8 +128,8 @@ describe('response dtoMapper tests', () => {
126
128
  entity.id = '123';
127
129
  entity.name = 'test';
128
130
  entity.age = 1;
129
- const responseDM = TestResponseDM.fromEntity(entity);
130
- const staticDM = TestResponseDtoMapper.fromEntity(SchemaValidator(), entity);
131
+ const responseDM = TestResponseDM.fromEntity(entity, 'arg1');
132
+ const staticDM = TestResponseDtoMapper.fromEntity(SV, entity, 'arg1');
131
133
  const expectedDto = {
132
134
  id: '123',
133
135
  name: 'test',
@@ -142,9 +144,9 @@ describe('response dtoMapper tests', () => {
142
144
  entity.id = '123';
143
145
  entity.name = 'test';
144
146
  entity.age = 1;
145
- const json = TestResponseDM.serializeEntityToJson(entity);
146
- const objectJson = TestResponseDM.fromEntity(entity).toJson();
147
- const staticJson = TestResponseDtoMapper.serializeEntityToJson(SchemaValidator(), entity);
147
+ const json = genericDtoWrapperFunction(TestResponseDM.serializeEntityToDto(entity, 'arg1'));
148
+ const objectJson = genericDtoWrapperFunction(TestResponseDM.fromEntity(entity, 'arg1').toDto());
149
+ const staticJson = genericDtoWrapperFunction(TestResponseDtoMapper.serializeEntityToDto(SV, entity, 'arg1', 'arg2'));
148
150
  const expectedJson = {
149
151
  id: '123',
150
152
  name: 'test',
@@ -162,7 +164,7 @@ describe('response dtoMapper tests', () => {
162
164
  const entity = new TestEntity();
163
165
  entity.id = '123';
164
166
  entity.name = 'test';
165
- expect(() => TestResponseDM.fromEntity(entity).toJson()).toThrow();
166
- expect(() => TestResponseDtoMapper.fromEntity(SchemaValidator(), entity).toJson()).toThrow();
167
+ expect(() => TestResponseDM.fromEntity(entity, 'arg1').toDto()).toThrow();
168
+ expect(() => TestResponseDtoMapper.fromEntity(SV, entity, 'arg1', 'arg2').toDto()).toThrow();
167
169
  });
168
170
  });