@forklaunch/core 0.9.20 → 0.9.21

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.
@@ -5,9 +5,9 @@ import { AnySchemaValidator, UnboxedObjectSchema, SchemaValidator, Schema } from
5
5
  *
6
6
  * @template T - The type of the entity mapper.
7
7
  * @template SV - The type of the schema validator.
8
- * @interface DtoMapperConstructor
8
+ * @interface MapperConstructor
9
9
  */
10
- interface DtoMapperConstructor<T, SV extends AnySchemaValidator> {
10
+ interface MapperConstructor<T, SV extends AnySchemaValidator> {
11
11
  /**
12
12
  * Creates a new instance of the entity mapper.
13
13
  *
@@ -21,16 +21,16 @@ interface DtoMapperConstructor<T, SV extends AnySchemaValidator> {
21
21
  * Type representing a schema validator object for an entity mapper.
22
22
  *
23
23
  * @template SV - A type that extends AnySchemaValidator.
24
- * @typedef {SV['_ValidSchemaObject'] | UnboxedObjectSchema<SV>} DtoMapperSchemaValidatorObject
24
+ * @typedef {SV['_ValidSchemaObject'] | UnboxedObjectSchema<SV>} MapperSchemaValidatorObject
25
25
  */
26
- type DtoMapperSchemaValidatorObject<SV extends AnySchemaValidator> = SV['_ValidSchemaObject'] | UnboxedObjectSchema<SV>;
26
+ type MapperSchemaValidatorObject<SV extends AnySchemaValidator> = SV['_ValidSchemaObject'] | UnboxedObjectSchema<SV>;
27
27
 
28
28
  /**
29
29
  * Abstract class representing a base entity mapper.
30
30
  *
31
31
  * @template SV - A type that extends AnySchemaValidator.
32
32
  */
33
- declare abstract class BaseDtoMapper<SV extends AnySchemaValidator> {
33
+ declare abstract class BaseMapper<SV extends AnySchemaValidator> {
34
34
  /**
35
35
  * The schema validator exact type.
36
36
  * @type {SV}
@@ -45,17 +45,17 @@ declare abstract class BaseDtoMapper<SV extends AnySchemaValidator> {
45
45
  protected schemaValidator: SchemaValidator;
46
46
  /**
47
47
  * The schema definition.
48
- * @type {DtoMapperSchemaValidatorObject<SV>}
48
+ * @type {MapperSchemaValidatorObject<SV>}
49
49
  * @abstract
50
50
  */
51
- abstract schema: DtoMapperSchemaValidatorObject<SV>;
51
+ abstract schema: MapperSchemaValidatorObject<SV>;
52
52
  /**
53
53
  * The Data Transfer Object (DTO).
54
54
  * @type {Schema<this['schema'], SV>}
55
55
  */
56
56
  _dto: Schema<this['schema'], SV>;
57
57
  /**
58
- * Creates an instance of BaseDtoMapper.
58
+ * Creates an instance of BaseMapper.
59
59
  *
60
60
  * @param {SV} schemaValidator - The schema provider.
61
61
  */
@@ -76,12 +76,12 @@ declare abstract class BaseDtoMapper<SV extends AnySchemaValidator> {
76
76
  /**
77
77
  * Gets the schema of a T.
78
78
  *
79
- * @template T - A type that extends BaseDtoMapper.
79
+ * @template T - A type that extends BaseMapper.
80
80
  * @template SV - A type that extends AnySchemaValidator.
81
- * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
81
+ * @param {MapperConstructor<T, SV>} this - The constructor of the T.
82
82
  * @returns {T['schema']} - The schema of the T.
83
83
  */
84
- static schema<T extends BaseDtoMapper<SV>, SV extends AnySchemaValidator>(this: DtoMapperConstructor<T, SV>): T['schema'];
84
+ static schema<T extends BaseMapper<SV>, SV extends AnySchemaValidator>(this: MapperConstructor<T, SV>): T['schema'];
85
85
  }
86
86
 
87
87
  /**
@@ -89,9 +89,9 @@ declare abstract class BaseDtoMapper<SV extends AnySchemaValidator> {
89
89
  *
90
90
  * @template Entity - A type that extends SqlBaseEntity.
91
91
  * @template SV - A type that extends AnySchemaValidator.
92
- * @extends {BaseDtoMapper<SV>}
92
+ * @extends {BaseMapper<SV>}
93
93
  */
94
- declare abstract class RequestDtoMapper<Entity, SV extends AnySchemaValidator> extends BaseDtoMapper<SV> {
94
+ declare abstract class RequestMapper<Entity, SV extends AnySchemaValidator> extends BaseMapper<SV> {
95
95
  /**
96
96
  * The entity type.
97
97
  * @type {Entity}
@@ -110,7 +110,7 @@ declare abstract class RequestDtoMapper<Entity, SV extends AnySchemaValidator> e
110
110
  * Populates the DTO with data from a JSON object.
111
111
  *
112
112
  * @param {this['_dto']} json - The JSON object.
113
- * @returns {Promise<this>} - The instance of the RequestDtoMapper.
113
+ * @returns {Promise<this>} - The instance of the RequestMapper.
114
114
  */
115
115
  fromDto(json: this['_dto']): Promise<this>;
116
116
  /**
@@ -122,30 +122,30 @@ declare abstract class RequestDtoMapper<Entity, SV extends AnySchemaValidator> e
122
122
  */
123
123
  deserializeDtoToEntity(json: this['_dto'], ...additionalArgs: Parameters<this['toEntity']>): Promise<Entity>;
124
124
  /**
125
- * Creates an instance of a RequestDtoMapper from a JSON object.
125
+ * Creates an instance of a RequestMapper from a JSON object.
126
126
  *
127
- * @template T - A type that extends RequestDtoMapper.
127
+ * @template T - A type that extends RequestMapper.
128
128
  * @template SV - A type that extends AnySchemaValidator.
129
129
  * @template JsonType - The type of the JSON object.
130
- * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
130
+ * @param {MapperConstructor<T, SV>} this - The constructor of the T.
131
131
  * @param {SV} schemaValidator - The schema provider.
132
132
  * @param {JsonType} json - The JSON object.
133
133
  * @returns {T} - An instance of the T.
134
134
  */
135
- static fromDto<T extends RequestDtoMapper<unknown, SV>, SV extends AnySchemaValidator, JsonType extends T['_dto']>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, json: JsonType): Promise<T>;
135
+ static fromDto<T extends RequestMapper<unknown, SV>, SV extends AnySchemaValidator, JsonType extends T['_dto']>(this: MapperConstructor<T, SV>, schemaValidator: SV, json: JsonType): Promise<T>;
136
136
  /**
137
137
  * Deserializes a JSON object to an entity.
138
138
  *
139
- * @template T - A type that extends RequestDtoMapper.
139
+ * @template T - A type that extends RequestMapper.
140
140
  * @template SV - A type that extends AnySchemaValidator.
141
141
  * @template JsonType - The type of the JSON object.
142
- * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
142
+ * @param {MapperConstructor<T, SV>} this - The constructor of the T.
143
143
  * @param {SV} schemaValidator - The schema provider.
144
144
  * @param {JsonType} json - The JSON object.
145
145
  * @param {...unknown[]} additionalArgs - Additional arguments.
146
146
  * @returns {T['_Entity']} - The entity.
147
147
  */
148
- static deserializeDtoToEntity<T extends RequestDtoMapper<unknown, SV>, SV extends AnySchemaValidator, JsonType extends T['_dto']>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, json: JsonType, ...additionalArgs: Parameters<T['toEntity']>): Promise<T['_Entity']>;
148
+ static deserializeDtoToEntity<T extends RequestMapper<unknown, SV>, SV extends AnySchemaValidator, JsonType extends T['_dto']>(this: MapperConstructor<T, SV>, schemaValidator: SV, json: JsonType, ...additionalArgs: Parameters<T['toEntity']>): Promise<T['_Entity']>;
149
149
  }
150
150
 
151
151
  /**
@@ -153,9 +153,9 @@ declare abstract class RequestDtoMapper<Entity, SV extends AnySchemaValidator> e
153
153
  *
154
154
  * @template Entity - A type that extends SqlBaseEntity.
155
155
  * @template SV - A type that extends AnySchemaValidator.
156
- * @extends {BaseDtoMapper<SV>}
156
+ * @extends {BaseMapper<SV>}
157
157
  */
158
- declare abstract class ResponseDtoMapper<Entity, SV extends AnySchemaValidator> extends BaseDtoMapper<SV> {
158
+ declare abstract class ResponseMapper<Entity, SV extends AnySchemaValidator> extends BaseMapper<SV> {
159
159
  /**
160
160
  * The entity type.
161
161
  * @type {Entity}
@@ -168,7 +168,7 @@ declare abstract class ResponseDtoMapper<Entity, SV extends AnySchemaValidator>
168
168
  * @abstract
169
169
  * @param {Entity} entity - The entity to convert.
170
170
  * @param {...unknown[]} additionalArgs - Additional arguments.
171
- * @returns {this} - The instance of the ResponseDtoMapper.
171
+ * @returns {this} - The instance of the ResponseMapper.
172
172
  */
173
173
  abstract fromEntity(entity: Entity, ...additionalArgs: unknown[]): Promise<this>;
174
174
  /**
@@ -189,26 +189,26 @@ declare abstract class ResponseDtoMapper<Entity, SV extends AnySchemaValidator>
189
189
  /**
190
190
  * Populates entity mapper with DTO from an entity.
191
191
  *
192
- * @template T - A type that extends ResponseDtoMapper.
192
+ * @template T - A type that extends ResponseMapper.
193
193
  * @template SV - A type that extends AnySchemaValidator.
194
- * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
194
+ * @param {MapperConstructor<T, SV>} this - The constructor of the T.
195
195
  * @param {SV} schemaValidator - The schema provider.
196
196
  * @param {T['_Entity']} entity - The entity to convert.
197
197
  * @returns {T} - An instance of the T.
198
198
  */
199
- static fromEntity<T extends ResponseDtoMapper<unknown, SV>, SV extends AnySchemaValidator>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, ...[entity, ...additionalArgs]: Parameters<T['fromEntity']>): Promise<T>;
199
+ static fromEntity<T extends ResponseMapper<unknown, SV>, SV extends AnySchemaValidator>(this: MapperConstructor<T, SV>, schemaValidator: SV, ...[entity, ...additionalArgs]: Parameters<T['fromEntity']>): Promise<T>;
200
200
  /**
201
201
  * Serializes an entity to a JSON object.
202
202
  *
203
- * @template T - A type that extends ResponseDtoMapper.
203
+ * @template T - A type that extends ResponseMapper.
204
204
  * @template SV - A type that extends AnySchemaValidator.
205
- * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
205
+ * @param {MapperConstructor<T, SV>} this - The constructor of the T.
206
206
  * @param {SV} schemaValidator - The schema provider.
207
207
  * @param {T['_Entity']} entity - The entity to serialize.
208
208
  * @returns {T['_dto']} - The JSON object.
209
209
  * @throws {Error} - Throws an error if the DTO is invalid.
210
210
  */
211
- static serializeEntityToDto<T extends ResponseDtoMapper<unknown, SV>, SV extends AnySchemaValidator, DtoType extends T['_dto']>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, ...[entity, ...additionalArgs]: Parameters<T['fromEntity']>): Promise<DtoType>;
211
+ static serializeEntityToDto<T extends ResponseMapper<unknown, SV>, SV extends AnySchemaValidator, DtoType extends T['_dto']>(this: MapperConstructor<T, SV>, schemaValidator: SV, ...[entity, ...additionalArgs]: Parameters<T['fromEntity']>): Promise<DtoType>;
212
212
  }
213
213
 
214
- export { RequestDtoMapper, ResponseDtoMapper };
214
+ export { RequestMapper, ResponseMapper };
@@ -5,9 +5,9 @@ import { AnySchemaValidator, UnboxedObjectSchema, SchemaValidator, Schema } from
5
5
  *
6
6
  * @template T - The type of the entity mapper.
7
7
  * @template SV - The type of the schema validator.
8
- * @interface DtoMapperConstructor
8
+ * @interface MapperConstructor
9
9
  */
10
- interface DtoMapperConstructor<T, SV extends AnySchemaValidator> {
10
+ interface MapperConstructor<T, SV extends AnySchemaValidator> {
11
11
  /**
12
12
  * Creates a new instance of the entity mapper.
13
13
  *
@@ -21,16 +21,16 @@ interface DtoMapperConstructor<T, SV extends AnySchemaValidator> {
21
21
  * Type representing a schema validator object for an entity mapper.
22
22
  *
23
23
  * @template SV - A type that extends AnySchemaValidator.
24
- * @typedef {SV['_ValidSchemaObject'] | UnboxedObjectSchema<SV>} DtoMapperSchemaValidatorObject
24
+ * @typedef {SV['_ValidSchemaObject'] | UnboxedObjectSchema<SV>} MapperSchemaValidatorObject
25
25
  */
26
- type DtoMapperSchemaValidatorObject<SV extends AnySchemaValidator> = SV['_ValidSchemaObject'] | UnboxedObjectSchema<SV>;
26
+ type MapperSchemaValidatorObject<SV extends AnySchemaValidator> = SV['_ValidSchemaObject'] | UnboxedObjectSchema<SV>;
27
27
 
28
28
  /**
29
29
  * Abstract class representing a base entity mapper.
30
30
  *
31
31
  * @template SV - A type that extends AnySchemaValidator.
32
32
  */
33
- declare abstract class BaseDtoMapper<SV extends AnySchemaValidator> {
33
+ declare abstract class BaseMapper<SV extends AnySchemaValidator> {
34
34
  /**
35
35
  * The schema validator exact type.
36
36
  * @type {SV}
@@ -45,17 +45,17 @@ declare abstract class BaseDtoMapper<SV extends AnySchemaValidator> {
45
45
  protected schemaValidator: SchemaValidator;
46
46
  /**
47
47
  * The schema definition.
48
- * @type {DtoMapperSchemaValidatorObject<SV>}
48
+ * @type {MapperSchemaValidatorObject<SV>}
49
49
  * @abstract
50
50
  */
51
- abstract schema: DtoMapperSchemaValidatorObject<SV>;
51
+ abstract schema: MapperSchemaValidatorObject<SV>;
52
52
  /**
53
53
  * The Data Transfer Object (DTO).
54
54
  * @type {Schema<this['schema'], SV>}
55
55
  */
56
56
  _dto: Schema<this['schema'], SV>;
57
57
  /**
58
- * Creates an instance of BaseDtoMapper.
58
+ * Creates an instance of BaseMapper.
59
59
  *
60
60
  * @param {SV} schemaValidator - The schema provider.
61
61
  */
@@ -76,12 +76,12 @@ declare abstract class BaseDtoMapper<SV extends AnySchemaValidator> {
76
76
  /**
77
77
  * Gets the schema of a T.
78
78
  *
79
- * @template T - A type that extends BaseDtoMapper.
79
+ * @template T - A type that extends BaseMapper.
80
80
  * @template SV - A type that extends AnySchemaValidator.
81
- * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
81
+ * @param {MapperConstructor<T, SV>} this - The constructor of the T.
82
82
  * @returns {T['schema']} - The schema of the T.
83
83
  */
84
- static schema<T extends BaseDtoMapper<SV>, SV extends AnySchemaValidator>(this: DtoMapperConstructor<T, SV>): T['schema'];
84
+ static schema<T extends BaseMapper<SV>, SV extends AnySchemaValidator>(this: MapperConstructor<T, SV>): T['schema'];
85
85
  }
86
86
 
87
87
  /**
@@ -89,9 +89,9 @@ declare abstract class BaseDtoMapper<SV extends AnySchemaValidator> {
89
89
  *
90
90
  * @template Entity - A type that extends SqlBaseEntity.
91
91
  * @template SV - A type that extends AnySchemaValidator.
92
- * @extends {BaseDtoMapper<SV>}
92
+ * @extends {BaseMapper<SV>}
93
93
  */
94
- declare abstract class RequestDtoMapper<Entity, SV extends AnySchemaValidator> extends BaseDtoMapper<SV> {
94
+ declare abstract class RequestMapper<Entity, SV extends AnySchemaValidator> extends BaseMapper<SV> {
95
95
  /**
96
96
  * The entity type.
97
97
  * @type {Entity}
@@ -110,7 +110,7 @@ declare abstract class RequestDtoMapper<Entity, SV extends AnySchemaValidator> e
110
110
  * Populates the DTO with data from a JSON object.
111
111
  *
112
112
  * @param {this['_dto']} json - The JSON object.
113
- * @returns {Promise<this>} - The instance of the RequestDtoMapper.
113
+ * @returns {Promise<this>} - The instance of the RequestMapper.
114
114
  */
115
115
  fromDto(json: this['_dto']): Promise<this>;
116
116
  /**
@@ -122,30 +122,30 @@ declare abstract class RequestDtoMapper<Entity, SV extends AnySchemaValidator> e
122
122
  */
123
123
  deserializeDtoToEntity(json: this['_dto'], ...additionalArgs: Parameters<this['toEntity']>): Promise<Entity>;
124
124
  /**
125
- * Creates an instance of a RequestDtoMapper from a JSON object.
125
+ * Creates an instance of a RequestMapper from a JSON object.
126
126
  *
127
- * @template T - A type that extends RequestDtoMapper.
127
+ * @template T - A type that extends RequestMapper.
128
128
  * @template SV - A type that extends AnySchemaValidator.
129
129
  * @template JsonType - The type of the JSON object.
130
- * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
130
+ * @param {MapperConstructor<T, SV>} this - The constructor of the T.
131
131
  * @param {SV} schemaValidator - The schema provider.
132
132
  * @param {JsonType} json - The JSON object.
133
133
  * @returns {T} - An instance of the T.
134
134
  */
135
- static fromDto<T extends RequestDtoMapper<unknown, SV>, SV extends AnySchemaValidator, JsonType extends T['_dto']>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, json: JsonType): Promise<T>;
135
+ static fromDto<T extends RequestMapper<unknown, SV>, SV extends AnySchemaValidator, JsonType extends T['_dto']>(this: MapperConstructor<T, SV>, schemaValidator: SV, json: JsonType): Promise<T>;
136
136
  /**
137
137
  * Deserializes a JSON object to an entity.
138
138
  *
139
- * @template T - A type that extends RequestDtoMapper.
139
+ * @template T - A type that extends RequestMapper.
140
140
  * @template SV - A type that extends AnySchemaValidator.
141
141
  * @template JsonType - The type of the JSON object.
142
- * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
142
+ * @param {MapperConstructor<T, SV>} this - The constructor of the T.
143
143
  * @param {SV} schemaValidator - The schema provider.
144
144
  * @param {JsonType} json - The JSON object.
145
145
  * @param {...unknown[]} additionalArgs - Additional arguments.
146
146
  * @returns {T['_Entity']} - The entity.
147
147
  */
148
- static deserializeDtoToEntity<T extends RequestDtoMapper<unknown, SV>, SV extends AnySchemaValidator, JsonType extends T['_dto']>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, json: JsonType, ...additionalArgs: Parameters<T['toEntity']>): Promise<T['_Entity']>;
148
+ static deserializeDtoToEntity<T extends RequestMapper<unknown, SV>, SV extends AnySchemaValidator, JsonType extends T['_dto']>(this: MapperConstructor<T, SV>, schemaValidator: SV, json: JsonType, ...additionalArgs: Parameters<T['toEntity']>): Promise<T['_Entity']>;
149
149
  }
150
150
 
151
151
  /**
@@ -153,9 +153,9 @@ declare abstract class RequestDtoMapper<Entity, SV extends AnySchemaValidator> e
153
153
  *
154
154
  * @template Entity - A type that extends SqlBaseEntity.
155
155
  * @template SV - A type that extends AnySchemaValidator.
156
- * @extends {BaseDtoMapper<SV>}
156
+ * @extends {BaseMapper<SV>}
157
157
  */
158
- declare abstract class ResponseDtoMapper<Entity, SV extends AnySchemaValidator> extends BaseDtoMapper<SV> {
158
+ declare abstract class ResponseMapper<Entity, SV extends AnySchemaValidator> extends BaseMapper<SV> {
159
159
  /**
160
160
  * The entity type.
161
161
  * @type {Entity}
@@ -168,7 +168,7 @@ declare abstract class ResponseDtoMapper<Entity, SV extends AnySchemaValidator>
168
168
  * @abstract
169
169
  * @param {Entity} entity - The entity to convert.
170
170
  * @param {...unknown[]} additionalArgs - Additional arguments.
171
- * @returns {this} - The instance of the ResponseDtoMapper.
171
+ * @returns {this} - The instance of the ResponseMapper.
172
172
  */
173
173
  abstract fromEntity(entity: Entity, ...additionalArgs: unknown[]): Promise<this>;
174
174
  /**
@@ -189,26 +189,26 @@ declare abstract class ResponseDtoMapper<Entity, SV extends AnySchemaValidator>
189
189
  /**
190
190
  * Populates entity mapper with DTO from an entity.
191
191
  *
192
- * @template T - A type that extends ResponseDtoMapper.
192
+ * @template T - A type that extends ResponseMapper.
193
193
  * @template SV - A type that extends AnySchemaValidator.
194
- * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
194
+ * @param {MapperConstructor<T, SV>} this - The constructor of the T.
195
195
  * @param {SV} schemaValidator - The schema provider.
196
196
  * @param {T['_Entity']} entity - The entity to convert.
197
197
  * @returns {T} - An instance of the T.
198
198
  */
199
- static fromEntity<T extends ResponseDtoMapper<unknown, SV>, SV extends AnySchemaValidator>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, ...[entity, ...additionalArgs]: Parameters<T['fromEntity']>): Promise<T>;
199
+ static fromEntity<T extends ResponseMapper<unknown, SV>, SV extends AnySchemaValidator>(this: MapperConstructor<T, SV>, schemaValidator: SV, ...[entity, ...additionalArgs]: Parameters<T['fromEntity']>): Promise<T>;
200
200
  /**
201
201
  * Serializes an entity to a JSON object.
202
202
  *
203
- * @template T - A type that extends ResponseDtoMapper.
203
+ * @template T - A type that extends ResponseMapper.
204
204
  * @template SV - A type that extends AnySchemaValidator.
205
- * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
205
+ * @param {MapperConstructor<T, SV>} this - The constructor of the T.
206
206
  * @param {SV} schemaValidator - The schema provider.
207
207
  * @param {T['_Entity']} entity - The entity to serialize.
208
208
  * @returns {T['_dto']} - The JSON object.
209
209
  * @throws {Error} - Throws an error if the DTO is invalid.
210
210
  */
211
- static serializeEntityToDto<T extends ResponseDtoMapper<unknown, SV>, SV extends AnySchemaValidator, DtoType extends T['_dto']>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, ...[entity, ...additionalArgs]: Parameters<T['fromEntity']>): Promise<DtoType>;
211
+ static serializeEntityToDto<T extends ResponseMapper<unknown, SV>, SV extends AnySchemaValidator, DtoType extends T['_dto']>(this: MapperConstructor<T, SV>, schemaValidator: SV, ...[entity, ...additionalArgs]: Parameters<T['fromEntity']>): Promise<DtoType>;
212
212
  }
213
213
 
214
- export { RequestDtoMapper, ResponseDtoMapper };
214
+ export { RequestMapper, ResponseMapper };
@@ -20,20 +20,20 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/mappers/index.ts
21
21
  var mappers_exports = {};
22
22
  __export(mappers_exports, {
23
- RequestDtoMapper: () => RequestDtoMapper,
24
- ResponseDtoMapper: () => ResponseDtoMapper
23
+ RequestMapper: () => RequestMapper,
24
+ ResponseMapper: () => ResponseMapper
25
25
  });
26
26
  module.exports = __toCommonJS(mappers_exports);
27
27
 
28
- // src/mappers/models/requestDtoMapper.model.ts
28
+ // src/mappers/models/requestMapper.model.ts
29
29
  var import_validator2 = require("@forklaunch/validator");
30
30
 
31
- // src/mappers/models/baseDtoMapper.model.ts
31
+ // src/mappers/models/baseMapper.model.ts
32
32
  var import_validator = require("@forklaunch/validator");
33
33
  function construct(self, schemaValidator) {
34
34
  return new self(schemaValidator || {});
35
35
  }
36
- var BaseDtoMapper = class {
36
+ var BaseMapper = class {
37
37
  /**
38
38
  * The schema validator exact type.
39
39
  * @type {SV}
@@ -52,7 +52,7 @@ var BaseDtoMapper = class {
52
52
  */
53
53
  _dto;
54
54
  /**
55
- * Creates an instance of BaseDtoMapper.
55
+ * Creates an instance of BaseMapper.
56
56
  *
57
57
  * @param {SV} schemaValidator - The schema provider.
58
58
  */
@@ -86,9 +86,9 @@ var BaseDtoMapper = class {
86
86
  /**
87
87
  * Gets the schema of a T.
88
88
  *
89
- * @template T - A type that extends BaseDtoMapper.
89
+ * @template T - A type that extends BaseMapper.
90
90
  * @template SV - A type that extends AnySchemaValidator.
91
- * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
91
+ * @param {MapperConstructor<T, SV>} this - The constructor of the T.
92
92
  * @returns {T['schema']} - The schema of the T.
93
93
  */
94
94
  static schema() {
@@ -96,8 +96,8 @@ var BaseDtoMapper = class {
96
96
  }
97
97
  };
98
98
 
99
- // src/mappers/models/requestDtoMapper.model.ts
100
- var RequestDtoMapper = class extends BaseDtoMapper {
99
+ // src/mappers/models/requestMapper.model.ts
100
+ var RequestMapper = class extends BaseMapper {
101
101
  /**
102
102
  * The entity type.
103
103
  * @type {Entity}
@@ -108,7 +108,7 @@ var RequestDtoMapper = class extends BaseDtoMapper {
108
108
  * Populates the DTO with data from a JSON object.
109
109
  *
110
110
  * @param {this['_dto']} json - The JSON object.
111
- * @returns {Promise<this>} - The instance of the RequestDtoMapper.
111
+ * @returns {Promise<this>} - The instance of the RequestMapper.
112
112
  */
113
113
  fromDto(json) {
114
114
  const parsedSchema = this.schemaValidator.parse(
@@ -133,12 +133,12 @@ var RequestDtoMapper = class extends BaseDtoMapper {
133
133
  return result.then((r) => r.toEntity(...additionalArgs));
134
134
  }
135
135
  /**
136
- * Creates an instance of a RequestDtoMapper from a JSON object.
136
+ * Creates an instance of a RequestMapper from a JSON object.
137
137
  *
138
- * @template T - A type that extends RequestDtoMapper.
138
+ * @template T - A type that extends RequestMapper.
139
139
  * @template SV - A type that extends AnySchemaValidator.
140
140
  * @template JsonType - The type of the JSON object.
141
- * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
141
+ * @param {MapperConstructor<T, SV>} this - The constructor of the T.
142
142
  * @param {SV} schemaValidator - The schema provider.
143
143
  * @param {JsonType} json - The JSON object.
144
144
  * @returns {T} - An instance of the T.
@@ -149,10 +149,10 @@ var RequestDtoMapper = class extends BaseDtoMapper {
149
149
  /**
150
150
  * Deserializes a JSON object to an entity.
151
151
  *
152
- * @template T - A type that extends RequestDtoMapper.
152
+ * @template T - A type that extends RequestMapper.
153
153
  * @template SV - A type that extends AnySchemaValidator.
154
154
  * @template JsonType - The type of the JSON object.
155
- * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
155
+ * @param {MapperConstructor<T, SV>} this - The constructor of the T.
156
156
  * @param {SV} schemaValidator - The schema provider.
157
157
  * @param {JsonType} json - The JSON object.
158
158
  * @param {...unknown[]} additionalArgs - Additional arguments.
@@ -164,9 +164,9 @@ var RequestDtoMapper = class extends BaseDtoMapper {
164
164
  }
165
165
  };
166
166
 
167
- // src/mappers/models/responseDtoMapper.model.ts
167
+ // src/mappers/models/responseMapper.model.ts
168
168
  var import_validator3 = require("@forklaunch/validator");
169
- var ResponseDtoMapper = class extends BaseDtoMapper {
169
+ var ResponseMapper = class extends BaseMapper {
170
170
  /**
171
171
  * The entity type.
172
172
  * @type {Entity}
@@ -203,9 +203,9 @@ var ResponseDtoMapper = class extends BaseDtoMapper {
203
203
  /**
204
204
  * Populates entity mapper with DTO from an entity.
205
205
  *
206
- * @template T - A type that extends ResponseDtoMapper.
206
+ * @template T - A type that extends ResponseMapper.
207
207
  * @template SV - A type that extends AnySchemaValidator.
208
- * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
208
+ * @param {MapperConstructor<T, SV>} this - The constructor of the T.
209
209
  * @param {SV} schemaValidator - The schema provider.
210
210
  * @param {T['_Entity']} entity - The entity to convert.
211
211
  * @returns {T} - An instance of the T.
@@ -219,9 +219,9 @@ var ResponseDtoMapper = class extends BaseDtoMapper {
219
219
  /**
220
220
  * Serializes an entity to a JSON object.
221
221
  *
222
- * @template T - A type that extends ResponseDtoMapper.
222
+ * @template T - A type that extends ResponseMapper.
223
223
  * @template SV - A type that extends AnySchemaValidator.
224
- * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
224
+ * @param {MapperConstructor<T, SV>} this - The constructor of the T.
225
225
  * @param {SV} schemaValidator - The schema provider.
226
226
  * @param {T['_Entity']} entity - The entity to serialize.
227
227
  * @returns {T['_dto']} - The JSON object.
@@ -237,7 +237,7 @@ var ResponseDtoMapper = class extends BaseDtoMapper {
237
237
  };
238
238
  // Annotate the CommonJS export names for ESM import in node:
239
239
  0 && (module.exports = {
240
- RequestDtoMapper,
241
- ResponseDtoMapper
240
+ RequestMapper,
241
+ ResponseMapper
242
242
  });
243
243
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/mappers/index.ts","../../src/mappers/models/requestDtoMapper.model.ts","../../src/mappers/models/baseDtoMapper.model.ts","../../src/mappers/models/responseDtoMapper.model.ts"],"sourcesContent":["export * from './models/requestDtoMapper.model';\nexport * from './models/responseDtoMapper.model';\n","import {\n AnySchemaValidator,\n prettyPrintParseErrors\n} from '@forklaunch/validator';\nimport { DtoMapperConstructor } from '../interfaces/mappers.interface';\nimport { BaseDtoMapper, construct } from './baseDtoMapper.model';\n\n/**\n * Abstract class representing a request entity mapper.\n *\n * @template Entity - A type that extends SqlBaseEntity.\n * @template SV - A type that extends AnySchemaValidator.\n * @extends {BaseDtoMapper<SV>}\n */\nexport abstract class RequestDtoMapper<\n Entity,\n SV extends AnySchemaValidator\n> extends BaseDtoMapper<SV> {\n /**\n * The entity type.\n * @type {Entity}\n * @protected\n */\n _Entity!: Entity;\n\n /**\n * Converts the underlying DTO to an entity.\n *\n * @abstract\n * @param {...unknown[]} additionalArgs - Additional arguments.\n * @returns {Promise<Entity>} - The entity.\n */\n abstract toEntity(...additionalArgs: unknown[]): Promise<Entity>;\n\n /**\n * Populates the DTO with data from a JSON object.\n *\n * @param {this['_dto']} json - The JSON object.\n * @returns {Promise<this>} - The instance of the RequestDtoMapper.\n */\n fromDto(json: this['_dto']): Promise<this> {\n const parsedSchema = this.schemaValidator.parse(\n this.schemaValidator.schemify(this.schema),\n json\n );\n if (!parsedSchema.ok) {\n throw new Error(prettyPrintParseErrors(parsedSchema.errors, 'DTO'));\n }\n this.dto = json;\n return Promise.resolve(this);\n }\n\n /**\n * Deserializes a JSON object to an entity.\n *\n * @param {this['_dto']} json - The JSON object.\n * @param {...unknown[]} additionalArgs - Additional arguments.\n * @returns {Entity} - The entity.\n */\n deserializeDtoToEntity(\n json: this['_dto'],\n ...additionalArgs: Parameters<this['toEntity']>\n ): Promise<Entity> {\n const result = this.fromDto(json);\n return result.then((r) => r.toEntity(...additionalArgs));\n }\n\n /**\n * Creates an instance of a RequestDtoMapper from a JSON object.\n *\n * @template T - A type that extends RequestDtoMapper.\n * @template SV - A type that extends AnySchemaValidator.\n * @template JsonType - The type of the JSON object.\n * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.\n * @param {SV} schemaValidator - The schema provider.\n * @param {JsonType} json - The JSON object.\n * @returns {T} - An instance of the T.\n */\n static fromDto<\n T extends RequestDtoMapper<unknown, SV>,\n SV extends AnySchemaValidator,\n JsonType extends T['_dto']\n >(\n this: DtoMapperConstructor<T, SV>,\n schemaValidator: SV,\n json: JsonType\n ): Promise<T> {\n return construct(this, schemaValidator).fromDto(json);\n }\n\n /**\n * Deserializes a JSON object to an entity.\n *\n * @template T - A type that extends RequestDtoMapper.\n * @template SV - A type that extends AnySchemaValidator.\n * @template JsonType - The type of the JSON object.\n * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.\n * @param {SV} schemaValidator - The schema provider.\n * @param {JsonType} json - The JSON object.\n * @param {...unknown[]} additionalArgs - Additional arguments.\n * @returns {T['_Entity']} - The entity.\n */\n static deserializeDtoToEntity<\n T extends RequestDtoMapper<unknown, SV>,\n SV extends AnySchemaValidator,\n JsonType extends T['_dto']\n >(\n this: DtoMapperConstructor<T, SV>,\n schemaValidator: SV,\n json: JsonType,\n ...additionalArgs: Parameters<T['toEntity']>\n ): Promise<T['_Entity']> {\n const result = construct(this, schemaValidator).fromDto(json);\n return result.then((r) => r.toEntity(...additionalArgs));\n }\n}\n","import {\n AnySchemaValidator,\n prettyPrintParseErrors,\n Schema,\n SchemaValidator\n} from '@forklaunch/validator';\nimport { DtoMapperSchemaValidatorObject } from '../../../../internal/src/types/mappers.types';\nimport { DtoMapperConstructor } from '../interfaces/mappers.interface';\n\n/**\n * Constructs an instance of a T.\n *\n * @template T - A type that extends BaseDtoMapper.\n * @template SV - A type that extends AnySchemaValidator.\n * @param {DtoMapperConstructor<T, SV>} self - The constructor of the T.\n * @param {SV} [schemaValidator] - The optional schema validator.\n * @returns {T} - An instance of the T.\n */\nexport function construct<T, SV extends AnySchemaValidator>(\n self: DtoMapperConstructor<T, SV>,\n schemaValidator?: SV\n): T {\n return new self(schemaValidator || ({} as SV));\n}\n\n/**\n * Abstract class representing a base entity mapper.\n *\n * @template SV - A type that extends AnySchemaValidator.\n */\nexport abstract class BaseDtoMapper<SV extends AnySchemaValidator> {\n /**\n * The schema validator exact type.\n * @type {SV}\n * @protected\n */\n _SV!: SV;\n\n /**\n * The schema validator as a general type.\n * @type {SchemaValidator}\n * @protected\n */\n protected schemaValidator: SchemaValidator;\n\n /**\n * The schema definition.\n * @type {DtoMapperSchemaValidatorObject<SV>}\n * @abstract\n */\n abstract schema: DtoMapperSchemaValidatorObject<SV>;\n\n /**\n * The Data Transfer Object (DTO).\n * @type {Schema<this['schema'], SV>}\n */\n _dto!: Schema<this['schema'], SV>;\n\n /**\n * Creates an instance of BaseDtoMapper.\n *\n * @param {SV} schemaValidator - The schema provider.\n */\n constructor(schemaValidator: SV) {\n this.schemaValidator = schemaValidator as unknown as SchemaValidator;\n }\n\n /**\n * Validates and sets the Data Transfer Object (DTO).\n *\n * @param {this['_dto']} dto - The Data Transfer Object (DTO).\n * @throws {Error} - Throws an error if the DTO is invalid.\n */\n set dto(_dto: this['_dto']) {\n const parsedSchema = this.schemaValidator.parse(\n this.schemaValidator.schemify(this.schema),\n _dto\n );\n if (!parsedSchema.ok) {\n throw new Error(prettyPrintParseErrors(parsedSchema.errors, 'DTO'));\n }\n this._dto = _dto as unknown as Schema<this['schema'], SV>;\n }\n\n /**\n * Validates and gets the Data Transfer Object (DTO).\n *\n * @returns {this['_dto']} - The Data Transfer Object (DTO).\n */\n get dto(): this['_dto'] {\n return this._dto as unknown as this['_dto'];\n }\n\n /**\n * Gets the schema of a T.\n *\n * @template T - A type that extends BaseDtoMapper.\n * @template SV - A type that extends AnySchemaValidator.\n * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.\n * @returns {T['schema']} - The schema of the T.\n */\n static schema<T extends BaseDtoMapper<SV>, SV extends AnySchemaValidator>(\n this: DtoMapperConstructor<T, SV>\n ): T['schema'] {\n return construct(this).schema;\n }\n}\n","import {\n AnySchemaValidator,\n prettyPrintParseErrors\n} from '@forklaunch/validator';\nimport { DtoMapperConstructor } from '../interfaces/mappers.interface';\nimport { BaseDtoMapper, construct } from './baseDtoMapper.model';\n\n/**\n * Abstract class representing a response entity mapper.\n *\n * @template Entity - A type that extends SqlBaseEntity.\n * @template SV - A type that extends AnySchemaValidator.\n * @extends {BaseDtoMapper<SV>}\n */\nexport abstract class ResponseDtoMapper<\n Entity,\n SV extends AnySchemaValidator\n> extends BaseDtoMapper<SV> {\n /**\n * The entity type.\n * @type {Entity}\n * @protected\n */\n _Entity!: Entity;\n\n /**\n * Populates entity mapper with DTO from an entity.\n *\n * @abstract\n * @param {Entity} entity - The entity to convert.\n * @param {...unknown[]} additionalArgs - Additional arguments.\n * @returns {this} - The instance of the ResponseDtoMapper.\n */\n abstract fromEntity(\n entity: Entity,\n ...additionalArgs: unknown[]\n ): Promise<this>;\n\n /**\n * Converts the underlying DTO to a JSON object.\n *\n * @returns {this['_dto']} - The JSON object.\n * @throws {Error} - Throws an error if the DTO is invalid.\n */\n toDto(): Promise<this['_dto']> {\n const parsedSchema = this.schemaValidator.parse(\n this.schemaValidator.schemify(this.schema),\n this.dto\n );\n if (!parsedSchema.ok) {\n throw new Error(prettyPrintParseErrors(parsedSchema.errors, 'DTO'));\n }\n return Promise.resolve(this.dto) as unknown as Promise<this['_dto']>;\n }\n\n /**\n * Serializes an entity to a JSON object.\n *\n * @param {Entity} entity - The entity to serialize.\n * @returns {this['_dto']} - The JSON object.\n * @throws {Error} - Throws an error if the DTO is invalid.\n */\n serializeEntityToDto(\n ...[entity, ...additionalArgs]: Parameters<this['fromEntity']>\n ): Promise<this['_dto']> {\n const result = this.fromEntity(entity, ...additionalArgs);\n return result.then((r) => r.toDto());\n }\n\n /**\n * Populates entity mapper with DTO from an entity.\n *\n * @template T - A type that extends ResponseDtoMapper.\n * @template SV - A type that extends AnySchemaValidator.\n * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.\n * @param {SV} schemaValidator - The schema provider.\n * @param {T['_Entity']} entity - The entity to convert.\n * @returns {T} - An instance of the T.\n */\n static fromEntity<\n T extends ResponseDtoMapper<unknown, SV>,\n SV extends AnySchemaValidator\n >(\n this: DtoMapperConstructor<T, SV>,\n schemaValidator: SV,\n ...[entity, ...additionalArgs]: Parameters<T['fromEntity']>\n ): Promise<T> {\n return construct(this, schemaValidator).fromEntity(\n entity,\n ...additionalArgs\n );\n }\n\n /**\n * Serializes an entity to a JSON object.\n *\n * @template T - A type that extends ResponseDtoMapper.\n * @template SV - A type that extends AnySchemaValidator.\n * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.\n * @param {SV} schemaValidator - The schema provider.\n * @param {T['_Entity']} entity - The entity to serialize.\n * @returns {T['_dto']} - The JSON object.\n * @throws {Error} - Throws an error if the DTO is invalid.\n */\n static serializeEntityToDto<\n T extends ResponseDtoMapper<unknown, SV>,\n SV extends AnySchemaValidator,\n DtoType extends T['_dto']\n >(\n this: DtoMapperConstructor<T, SV>,\n schemaValidator: SV,\n ...[entity, ...additionalArgs]: Parameters<T['fromEntity']>\n ): Promise<DtoType> {\n const result = construct(this, schemaValidator).fromEntity(\n entity,\n ...additionalArgs\n );\n return result.then((r) => r.toDto()) as Promise<DtoType>;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,oBAGO;;;ACHP,uBAKO;AAaA,SAAS,UACd,MACA,iBACG;AACH,SAAO,IAAI,KAAK,mBAAoB,CAAC,CAAQ;AAC/C;AAOO,IAAe,gBAAf,MAA4D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMjE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOU;AAAA;AAAA;AAAA;AAAA;AAAA,EAaV;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,YAAY,iBAAqB;AAC/B,SAAK,kBAAkB;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,IAAI,IAAI,MAAoB;AAC1B,UAAM,eAAe,KAAK,gBAAgB;AAAA,MACxC,KAAK,gBAAgB,SAAS,KAAK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F;","names":["import_validator","import_validator"]}
1
+ {"version":3,"sources":["../../src/mappers/index.ts","../../src/mappers/models/requestMapper.model.ts","../../src/mappers/models/baseMapper.model.ts","../../src/mappers/models/responseMapper.model.ts"],"sourcesContent":["export * from './models/requestMapper.model';\nexport * from './models/responseMapper.model';\n","import {\n AnySchemaValidator,\n prettyPrintParseErrors\n} from '@forklaunch/validator';\nimport { MapperConstructor } from '../interfaces/mappers.interface';\nimport { BaseMapper, construct } from './baseMapper.model';\n\n/**\n * Abstract class representing a request entity mapper.\n *\n * @template Entity - A type that extends SqlBaseEntity.\n * @template SV - A type that extends AnySchemaValidator.\n * @extends {BaseMapper<SV>}\n */\nexport abstract class RequestMapper<\n Entity,\n SV extends AnySchemaValidator\n> extends BaseMapper<SV> {\n /**\n * The entity type.\n * @type {Entity}\n * @protected\n */\n _Entity!: Entity;\n\n /**\n * Converts the underlying DTO to an entity.\n *\n * @abstract\n * @param {...unknown[]} additionalArgs - Additional arguments.\n * @returns {Promise<Entity>} - The entity.\n */\n abstract toEntity(...additionalArgs: unknown[]): Promise<Entity>;\n\n /**\n * Populates the DTO with data from a JSON object.\n *\n * @param {this['_dto']} json - The JSON object.\n * @returns {Promise<this>} - The instance of the RequestMapper.\n */\n fromDto(json: this['_dto']): Promise<this> {\n const parsedSchema = this.schemaValidator.parse(\n this.schemaValidator.schemify(this.schema),\n json\n );\n if (!parsedSchema.ok) {\n throw new Error(prettyPrintParseErrors(parsedSchema.errors, 'DTO'));\n }\n this.dto = json;\n return Promise.resolve(this);\n }\n\n /**\n * Deserializes a JSON object to an entity.\n *\n * @param {this['_dto']} json - The JSON object.\n * @param {...unknown[]} additionalArgs - Additional arguments.\n * @returns {Entity} - The entity.\n */\n deserializeDtoToEntity(\n json: this['_dto'],\n ...additionalArgs: Parameters<this['toEntity']>\n ): Promise<Entity> {\n const result = this.fromDto(json);\n return result.then((r) => r.toEntity(...additionalArgs));\n }\n\n /**\n * Creates an instance of a RequestMapper from a JSON object.\n *\n * @template T - A type that extends RequestMapper.\n * @template SV - A type that extends AnySchemaValidator.\n * @template JsonType - The type of the JSON object.\n * @param {MapperConstructor<T, SV>} this - The constructor of the T.\n * @param {SV} schemaValidator - The schema provider.\n * @param {JsonType} json - The JSON object.\n * @returns {T} - An instance of the T.\n */\n static fromDto<\n T extends RequestMapper<unknown, SV>,\n SV extends AnySchemaValidator,\n JsonType extends T['_dto']\n >(\n this: MapperConstructor<T, SV>,\n schemaValidator: SV,\n json: JsonType\n ): Promise<T> {\n return construct(this, schemaValidator).fromDto(json);\n }\n\n /**\n * Deserializes a JSON object to an entity.\n *\n * @template T - A type that extends RequestMapper.\n * @template SV - A type that extends AnySchemaValidator.\n * @template JsonType - The type of the JSON object.\n * @param {MapperConstructor<T, SV>} this - The constructor of the T.\n * @param {SV} schemaValidator - The schema provider.\n * @param {JsonType} json - The JSON object.\n * @param {...unknown[]} additionalArgs - Additional arguments.\n * @returns {T['_Entity']} - The entity.\n */\n static deserializeDtoToEntity<\n T extends RequestMapper<unknown, SV>,\n SV extends AnySchemaValidator,\n JsonType extends T['_dto']\n >(\n this: MapperConstructor<T, SV>,\n schemaValidator: SV,\n json: JsonType,\n ...additionalArgs: Parameters<T['toEntity']>\n ): Promise<T['_Entity']> {\n const result = construct(this, schemaValidator).fromDto(json);\n return result.then((r) => r.toEntity(...additionalArgs));\n }\n}\n","import {\n AnySchemaValidator,\n prettyPrintParseErrors,\n Schema,\n SchemaValidator\n} from '@forklaunch/validator';\nimport { MapperSchemaValidatorObject } from '../../../../internal/src/types/mappers.types';\nimport { MapperConstructor } from '../interfaces/mappers.interface';\n\n/**\n * Constructs an instance of a T.\n *\n * @template T - A type that extends BaseMapper.\n * @template SV - A type that extends AnySchemaValidator.\n * @param {MapperConstructor<T, SV>} self - The constructor of the T.\n * @param {SV} [schemaValidator] - The optional schema validator.\n * @returns {T} - An instance of the T.\n */\nexport function construct<T, SV extends AnySchemaValidator>(\n self: MapperConstructor<T, SV>,\n schemaValidator?: SV\n): T {\n return new self(schemaValidator || ({} as SV));\n}\n\n/**\n * Abstract class representing a base entity mapper.\n *\n * @template SV - A type that extends AnySchemaValidator.\n */\nexport abstract class BaseMapper<SV extends AnySchemaValidator> {\n /**\n * The schema validator exact type.\n * @type {SV}\n * @protected\n */\n _SV!: SV;\n\n /**\n * The schema validator as a general type.\n * @type {SchemaValidator}\n * @protected\n */\n protected schemaValidator: SchemaValidator;\n\n /**\n * The schema definition.\n * @type {MapperSchemaValidatorObject<SV>}\n * @abstract\n */\n abstract schema: MapperSchemaValidatorObject<SV>;\n\n /**\n * The Data Transfer Object (DTO).\n * @type {Schema<this['schema'], SV>}\n */\n _dto!: Schema<this['schema'], SV>;\n\n /**\n * Creates an instance of BaseMapper.\n *\n * @param {SV} schemaValidator - The schema provider.\n */\n constructor(schemaValidator: SV) {\n this.schemaValidator = schemaValidator as unknown as SchemaValidator;\n }\n\n /**\n * Validates and sets the Data Transfer Object (DTO).\n *\n * @param {this['_dto']} dto - The Data Transfer Object (DTO).\n * @throws {Error} - Throws an error if the DTO is invalid.\n */\n set dto(_dto: this['_dto']) {\n const parsedSchema = this.schemaValidator.parse(\n this.schemaValidator.schemify(this.schema),\n _dto\n );\n if (!parsedSchema.ok) {\n throw new Error(prettyPrintParseErrors(parsedSchema.errors, 'DTO'));\n }\n this._dto = _dto as unknown as Schema<this['schema'], SV>;\n }\n\n /**\n * Validates and gets the Data Transfer Object (DTO).\n *\n * @returns {this['_dto']} - The Data Transfer Object (DTO).\n */\n get dto(): this['_dto'] {\n return this._dto as unknown as this['_dto'];\n }\n\n /**\n * Gets the schema of a T.\n *\n * @template T - A type that extends BaseMapper.\n * @template SV - A type that extends AnySchemaValidator.\n * @param {MapperConstructor<T, SV>} this - The constructor of the T.\n * @returns {T['schema']} - The schema of the T.\n */\n static schema<T extends BaseMapper<SV>, SV extends AnySchemaValidator>(\n this: MapperConstructor<T, SV>\n ): T['schema'] {\n return construct(this).schema;\n }\n}\n","import {\n AnySchemaValidator,\n prettyPrintParseErrors\n} from '@forklaunch/validator';\nimport { MapperConstructor } from '../interfaces/mappers.interface';\nimport { BaseMapper, construct } from './baseMapper.model';\n\n/**\n * Abstract class representing a response entity mapper.\n *\n * @template Entity - A type that extends SqlBaseEntity.\n * @template SV - A type that extends AnySchemaValidator.\n * @extends {BaseMapper<SV>}\n */\nexport abstract class ResponseMapper<\n Entity,\n SV extends AnySchemaValidator\n> extends BaseMapper<SV> {\n /**\n * The entity type.\n * @type {Entity}\n * @protected\n */\n _Entity!: Entity;\n\n /**\n * Populates entity mapper with DTO from an entity.\n *\n * @abstract\n * @param {Entity} entity - The entity to convert.\n * @param {...unknown[]} additionalArgs - Additional arguments.\n * @returns {this} - The instance of the ResponseMapper.\n */\n abstract fromEntity(\n entity: Entity,\n ...additionalArgs: unknown[]\n ): Promise<this>;\n\n /**\n * Converts the underlying DTO to a JSON object.\n *\n * @returns {this['_dto']} - The JSON object.\n * @throws {Error} - Throws an error if the DTO is invalid.\n */\n toDto(): Promise<this['_dto']> {\n const parsedSchema = this.schemaValidator.parse(\n this.schemaValidator.schemify(this.schema),\n this.dto\n );\n if (!parsedSchema.ok) {\n throw new Error(prettyPrintParseErrors(parsedSchema.errors, 'DTO'));\n }\n return Promise.resolve(this.dto) as unknown as Promise<this['_dto']>;\n }\n\n /**\n * Serializes an entity to a JSON object.\n *\n * @param {Entity} entity - The entity to serialize.\n * @returns {this['_dto']} - The JSON object.\n * @throws {Error} - Throws an error if the DTO is invalid.\n */\n serializeEntityToDto(\n ...[entity, ...additionalArgs]: Parameters<this['fromEntity']>\n ): Promise<this['_dto']> {\n const result = this.fromEntity(entity, ...additionalArgs);\n return result.then((r) => r.toDto());\n }\n\n /**\n * Populates entity mapper with DTO from an entity.\n *\n * @template T - A type that extends ResponseMapper.\n * @template SV - A type that extends AnySchemaValidator.\n * @param {MapperConstructor<T, SV>} this - The constructor of the T.\n * @param {SV} schemaValidator - The schema provider.\n * @param {T['_Entity']} entity - The entity to convert.\n * @returns {T} - An instance of the T.\n */\n static fromEntity<\n T extends ResponseMapper<unknown, SV>,\n SV extends AnySchemaValidator\n >(\n this: MapperConstructor<T, SV>,\n schemaValidator: SV,\n ...[entity, ...additionalArgs]: Parameters<T['fromEntity']>\n ): Promise<T> {\n return construct(this, schemaValidator).fromEntity(\n entity,\n ...additionalArgs\n );\n }\n\n /**\n * Serializes an entity to a JSON object.\n *\n * @template T - A type that extends ResponseMapper.\n * @template SV - A type that extends AnySchemaValidator.\n * @param {MapperConstructor<T, SV>} this - The constructor of the T.\n * @param {SV} schemaValidator - The schema provider.\n * @param {T['_Entity']} entity - The entity to serialize.\n * @returns {T['_dto']} - The JSON object.\n * @throws {Error} - Throws an error if the DTO is invalid.\n */\n static serializeEntityToDto<\n T extends ResponseMapper<unknown, SV>,\n SV extends AnySchemaValidator,\n DtoType extends T['_dto']\n >(\n this: MapperConstructor<T, SV>,\n schemaValidator: SV,\n ...[entity, ...additionalArgs]: Parameters<T['fromEntity']>\n ): Promise<DtoType> {\n const result = construct(this, schemaValidator).fromEntity(\n entity,\n ...additionalArgs\n );\n return result.then((r) => r.toDto()) as Promise<DtoType>;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,oBAGO;;;ACHP,uBAKO;AAaA,SAAS,UACd,MACA,iBACG;AACH,SAAO,IAAI,KAAK,mBAAoB,CAAC,CAAQ;AAC/C;AAOO,IAAe,aAAf,MAAyD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAM9D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOU;AAAA;AAAA;AAAA;AAAA;AAAA,EAaV;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,YAAY,iBAAqB;AAC/B,SAAK,kBAAkB;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,IAAI,IAAI,MAAoB;AAC1B,UAAM,eAAe,KAAK,gBAAgB;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M,EAAE,MAAM,CAAC;AAAA,EACrC;AACF;","names":["import_validator","import_validator"]}
@@ -1,16 +1,16 @@
1
- // src/mappers/models/requestDtoMapper.model.ts
1
+ // src/mappers/models/requestMapper.model.ts
2
2
  import {
3
3
  prettyPrintParseErrors as prettyPrintParseErrors2
4
4
  } from "@forklaunch/validator";
5
5
 
6
- // src/mappers/models/baseDtoMapper.model.ts
6
+ // src/mappers/models/baseMapper.model.ts
7
7
  import {
8
8
  prettyPrintParseErrors
9
9
  } from "@forklaunch/validator";
10
10
  function construct(self, schemaValidator) {
11
11
  return new self(schemaValidator || {});
12
12
  }
13
- var BaseDtoMapper = class {
13
+ var BaseMapper = class {
14
14
  /**
15
15
  * The schema validator exact type.
16
16
  * @type {SV}
@@ -29,7 +29,7 @@ var BaseDtoMapper = class {
29
29
  */
30
30
  _dto;
31
31
  /**
32
- * Creates an instance of BaseDtoMapper.
32
+ * Creates an instance of BaseMapper.
33
33
  *
34
34
  * @param {SV} schemaValidator - The schema provider.
35
35
  */
@@ -63,9 +63,9 @@ var BaseDtoMapper = class {
63
63
  /**
64
64
  * Gets the schema of a T.
65
65
  *
66
- * @template T - A type that extends BaseDtoMapper.
66
+ * @template T - A type that extends BaseMapper.
67
67
  * @template SV - A type that extends AnySchemaValidator.
68
- * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
68
+ * @param {MapperConstructor<T, SV>} this - The constructor of the T.
69
69
  * @returns {T['schema']} - The schema of the T.
70
70
  */
71
71
  static schema() {
@@ -73,8 +73,8 @@ var BaseDtoMapper = class {
73
73
  }
74
74
  };
75
75
 
76
- // src/mappers/models/requestDtoMapper.model.ts
77
- var RequestDtoMapper = class extends BaseDtoMapper {
76
+ // src/mappers/models/requestMapper.model.ts
77
+ var RequestMapper = class extends BaseMapper {
78
78
  /**
79
79
  * The entity type.
80
80
  * @type {Entity}
@@ -85,7 +85,7 @@ var RequestDtoMapper = class extends BaseDtoMapper {
85
85
  * Populates the DTO with data from a JSON object.
86
86
  *
87
87
  * @param {this['_dto']} json - The JSON object.
88
- * @returns {Promise<this>} - The instance of the RequestDtoMapper.
88
+ * @returns {Promise<this>} - The instance of the RequestMapper.
89
89
  */
90
90
  fromDto(json) {
91
91
  const parsedSchema = this.schemaValidator.parse(
@@ -110,12 +110,12 @@ var RequestDtoMapper = class extends BaseDtoMapper {
110
110
  return result.then((r) => r.toEntity(...additionalArgs));
111
111
  }
112
112
  /**
113
- * Creates an instance of a RequestDtoMapper from a JSON object.
113
+ * Creates an instance of a RequestMapper from a JSON object.
114
114
  *
115
- * @template T - A type that extends RequestDtoMapper.
115
+ * @template T - A type that extends RequestMapper.
116
116
  * @template SV - A type that extends AnySchemaValidator.
117
117
  * @template JsonType - The type of the JSON object.
118
- * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
118
+ * @param {MapperConstructor<T, SV>} this - The constructor of the T.
119
119
  * @param {SV} schemaValidator - The schema provider.
120
120
  * @param {JsonType} json - The JSON object.
121
121
  * @returns {T} - An instance of the T.
@@ -126,10 +126,10 @@ var RequestDtoMapper = class extends BaseDtoMapper {
126
126
  /**
127
127
  * Deserializes a JSON object to an entity.
128
128
  *
129
- * @template T - A type that extends RequestDtoMapper.
129
+ * @template T - A type that extends RequestMapper.
130
130
  * @template SV - A type that extends AnySchemaValidator.
131
131
  * @template JsonType - The type of the JSON object.
132
- * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
132
+ * @param {MapperConstructor<T, SV>} this - The constructor of the T.
133
133
  * @param {SV} schemaValidator - The schema provider.
134
134
  * @param {JsonType} json - The JSON object.
135
135
  * @param {...unknown[]} additionalArgs - Additional arguments.
@@ -141,11 +141,11 @@ var RequestDtoMapper = class extends BaseDtoMapper {
141
141
  }
142
142
  };
143
143
 
144
- // src/mappers/models/responseDtoMapper.model.ts
144
+ // src/mappers/models/responseMapper.model.ts
145
145
  import {
146
146
  prettyPrintParseErrors as prettyPrintParseErrors3
147
147
  } from "@forklaunch/validator";
148
- var ResponseDtoMapper = class extends BaseDtoMapper {
148
+ var ResponseMapper = class extends BaseMapper {
149
149
  /**
150
150
  * The entity type.
151
151
  * @type {Entity}
@@ -182,9 +182,9 @@ var ResponseDtoMapper = class extends BaseDtoMapper {
182
182
  /**
183
183
  * Populates entity mapper with DTO from an entity.
184
184
  *
185
- * @template T - A type that extends ResponseDtoMapper.
185
+ * @template T - A type that extends ResponseMapper.
186
186
  * @template SV - A type that extends AnySchemaValidator.
187
- * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
187
+ * @param {MapperConstructor<T, SV>} this - The constructor of the T.
188
188
  * @param {SV} schemaValidator - The schema provider.
189
189
  * @param {T['_Entity']} entity - The entity to convert.
190
190
  * @returns {T} - An instance of the T.
@@ -198,9 +198,9 @@ var ResponseDtoMapper = class extends BaseDtoMapper {
198
198
  /**
199
199
  * Serializes an entity to a JSON object.
200
200
  *
201
- * @template T - A type that extends ResponseDtoMapper.
201
+ * @template T - A type that extends ResponseMapper.
202
202
  * @template SV - A type that extends AnySchemaValidator.
203
- * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
203
+ * @param {MapperConstructor<T, SV>} this - The constructor of the T.
204
204
  * @param {SV} schemaValidator - The schema provider.
205
205
  * @param {T['_Entity']} entity - The entity to serialize.
206
206
  * @returns {T['_dto']} - The JSON object.
@@ -215,7 +215,7 @@ var ResponseDtoMapper = class extends BaseDtoMapper {
215
215
  }
216
216
  };
217
217
  export {
218
- RequestDtoMapper,
219
- ResponseDtoMapper
218
+ RequestMapper,
219
+ ResponseMapper
220
220
  };
221
221
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/mappers/models/requestDtoMapper.model.ts","../../src/mappers/models/baseDtoMapper.model.ts","../../src/mappers/models/responseDtoMapper.model.ts"],"sourcesContent":["import {\n AnySchemaValidator,\n prettyPrintParseErrors\n} from '@forklaunch/validator';\nimport { DtoMapperConstructor } from '../interfaces/mappers.interface';\nimport { BaseDtoMapper, construct } from './baseDtoMapper.model';\n\n/**\n * Abstract class representing a request entity mapper.\n *\n * @template Entity - A type that extends SqlBaseEntity.\n * @template SV - A type that extends AnySchemaValidator.\n * @extends {BaseDtoMapper<SV>}\n */\nexport abstract class RequestDtoMapper<\n Entity,\n SV extends AnySchemaValidator\n> extends BaseDtoMapper<SV> {\n /**\n * The entity type.\n * @type {Entity}\n * @protected\n */\n _Entity!: Entity;\n\n /**\n * Converts the underlying DTO to an entity.\n *\n * @abstract\n * @param {...unknown[]} additionalArgs - Additional arguments.\n * @returns {Promise<Entity>} - The entity.\n */\n abstract toEntity(...additionalArgs: unknown[]): Promise<Entity>;\n\n /**\n * Populates the DTO with data from a JSON object.\n *\n * @param {this['_dto']} json - The JSON object.\n * @returns {Promise<this>} - The instance of the RequestDtoMapper.\n */\n fromDto(json: this['_dto']): Promise<this> {\n const parsedSchema = this.schemaValidator.parse(\n this.schemaValidator.schemify(this.schema),\n json\n );\n if (!parsedSchema.ok) {\n throw new Error(prettyPrintParseErrors(parsedSchema.errors, 'DTO'));\n }\n this.dto = json;\n return Promise.resolve(this);\n }\n\n /**\n * Deserializes a JSON object to an entity.\n *\n * @param {this['_dto']} json - The JSON object.\n * @param {...unknown[]} additionalArgs - Additional arguments.\n * @returns {Entity} - The entity.\n */\n deserializeDtoToEntity(\n json: this['_dto'],\n ...additionalArgs: Parameters<this['toEntity']>\n ): Promise<Entity> {\n const result = this.fromDto(json);\n return result.then((r) => r.toEntity(...additionalArgs));\n }\n\n /**\n * Creates an instance of a RequestDtoMapper from a JSON object.\n *\n * @template T - A type that extends RequestDtoMapper.\n * @template SV - A type that extends AnySchemaValidator.\n * @template JsonType - The type of the JSON object.\n * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.\n * @param {SV} schemaValidator - The schema provider.\n * @param {JsonType} json - The JSON object.\n * @returns {T} - An instance of the T.\n */\n static fromDto<\n T extends RequestDtoMapper<unknown, SV>,\n SV extends AnySchemaValidator,\n JsonType extends T['_dto']\n >(\n this: DtoMapperConstructor<T, SV>,\n schemaValidator: SV,\n json: JsonType\n ): Promise<T> {\n return construct(this, schemaValidator).fromDto(json);\n }\n\n /**\n * Deserializes a JSON object to an entity.\n *\n * @template T - A type that extends RequestDtoMapper.\n * @template SV - A type that extends AnySchemaValidator.\n * @template JsonType - The type of the JSON object.\n * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.\n * @param {SV} schemaValidator - The schema provider.\n * @param {JsonType} json - The JSON object.\n * @param {...unknown[]} additionalArgs - Additional arguments.\n * @returns {T['_Entity']} - The entity.\n */\n static deserializeDtoToEntity<\n T extends RequestDtoMapper<unknown, SV>,\n SV extends AnySchemaValidator,\n JsonType extends T['_dto']\n >(\n this: DtoMapperConstructor<T, SV>,\n schemaValidator: SV,\n json: JsonType,\n ...additionalArgs: Parameters<T['toEntity']>\n ): Promise<T['_Entity']> {\n const result = construct(this, schemaValidator).fromDto(json);\n return result.then((r) => r.toEntity(...additionalArgs));\n }\n}\n","import {\n AnySchemaValidator,\n prettyPrintParseErrors,\n Schema,\n SchemaValidator\n} from '@forklaunch/validator';\nimport { DtoMapperSchemaValidatorObject } from '../../../../internal/src/types/mappers.types';\nimport { DtoMapperConstructor } from '../interfaces/mappers.interface';\n\n/**\n * Constructs an instance of a T.\n *\n * @template T - A type that extends BaseDtoMapper.\n * @template SV - A type that extends AnySchemaValidator.\n * @param {DtoMapperConstructor<T, SV>} self - The constructor of the T.\n * @param {SV} [schemaValidator] - The optional schema validator.\n * @returns {T} - An instance of the T.\n */\nexport function construct<T, SV extends AnySchemaValidator>(\n self: DtoMapperConstructor<T, SV>,\n schemaValidator?: SV\n): T {\n return new self(schemaValidator || ({} as SV));\n}\n\n/**\n * Abstract class representing a base entity mapper.\n *\n * @template SV - A type that extends AnySchemaValidator.\n */\nexport abstract class BaseDtoMapper<SV extends AnySchemaValidator> {\n /**\n * The schema validator exact type.\n * @type {SV}\n * @protected\n */\n _SV!: SV;\n\n /**\n * The schema validator as a general type.\n * @type {SchemaValidator}\n * @protected\n */\n protected schemaValidator: SchemaValidator;\n\n /**\n * The schema definition.\n * @type {DtoMapperSchemaValidatorObject<SV>}\n * @abstract\n */\n abstract schema: DtoMapperSchemaValidatorObject<SV>;\n\n /**\n * The Data Transfer Object (DTO).\n * @type {Schema<this['schema'], SV>}\n */\n _dto!: Schema<this['schema'], SV>;\n\n /**\n * Creates an instance of BaseDtoMapper.\n *\n * @param {SV} schemaValidator - The schema provider.\n */\n constructor(schemaValidator: SV) {\n this.schemaValidator = schemaValidator as unknown as SchemaValidator;\n }\n\n /**\n * Validates and sets the Data Transfer Object (DTO).\n *\n * @param {this['_dto']} dto - The Data Transfer Object (DTO).\n * @throws {Error} - Throws an error if the DTO is invalid.\n */\n set dto(_dto: this['_dto']) {\n const parsedSchema = this.schemaValidator.parse(\n this.schemaValidator.schemify(this.schema),\n _dto\n );\n if (!parsedSchema.ok) {\n throw new Error(prettyPrintParseErrors(parsedSchema.errors, 'DTO'));\n }\n this._dto = _dto as unknown as Schema<this['schema'], SV>;\n }\n\n /**\n * Validates and gets the Data Transfer Object (DTO).\n *\n * @returns {this['_dto']} - The Data Transfer Object (DTO).\n */\n get dto(): this['_dto'] {\n return this._dto as unknown as this['_dto'];\n }\n\n /**\n * Gets the schema of a T.\n *\n * @template T - A type that extends BaseDtoMapper.\n * @template SV - A type that extends AnySchemaValidator.\n * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.\n * @returns {T['schema']} - The schema of the T.\n */\n static schema<T extends BaseDtoMapper<SV>, SV extends AnySchemaValidator>(\n this: DtoMapperConstructor<T, SV>\n ): T['schema'] {\n return construct(this).schema;\n }\n}\n","import {\n AnySchemaValidator,\n prettyPrintParseErrors\n} from '@forklaunch/validator';\nimport { DtoMapperConstructor } from '../interfaces/mappers.interface';\nimport { BaseDtoMapper, construct } from './baseDtoMapper.model';\n\n/**\n * Abstract class representing a response entity mapper.\n *\n * @template Entity - A type that extends SqlBaseEntity.\n * @template SV - A type that extends AnySchemaValidator.\n * @extends {BaseDtoMapper<SV>}\n */\nexport abstract class ResponseDtoMapper<\n Entity,\n SV extends AnySchemaValidator\n> extends BaseDtoMapper<SV> {\n /**\n * The entity type.\n * @type {Entity}\n * @protected\n */\n _Entity!: Entity;\n\n /**\n * Populates entity mapper with DTO from an entity.\n *\n * @abstract\n * @param {Entity} entity - The entity to convert.\n * @param {...unknown[]} additionalArgs - Additional arguments.\n * @returns {this} - The instance of the ResponseDtoMapper.\n */\n abstract fromEntity(\n entity: Entity,\n ...additionalArgs: unknown[]\n ): Promise<this>;\n\n /**\n * Converts the underlying DTO to a JSON object.\n *\n * @returns {this['_dto']} - The JSON object.\n * @throws {Error} - Throws an error if the DTO is invalid.\n */\n toDto(): Promise<this['_dto']> {\n const parsedSchema = this.schemaValidator.parse(\n this.schemaValidator.schemify(this.schema),\n this.dto\n );\n if (!parsedSchema.ok) {\n throw new Error(prettyPrintParseErrors(parsedSchema.errors, 'DTO'));\n }\n return Promise.resolve(this.dto) as unknown as Promise<this['_dto']>;\n }\n\n /**\n * Serializes an entity to a JSON object.\n *\n * @param {Entity} entity - The entity to serialize.\n * @returns {this['_dto']} - The JSON object.\n * @throws {Error} - Throws an error if the DTO is invalid.\n */\n serializeEntityToDto(\n ...[entity, ...additionalArgs]: Parameters<this['fromEntity']>\n ): Promise<this['_dto']> {\n const result = this.fromEntity(entity, ...additionalArgs);\n return result.then((r) => r.toDto());\n }\n\n /**\n * Populates entity mapper with DTO from an entity.\n *\n * @template T - A type that extends ResponseDtoMapper.\n * @template SV - A type that extends AnySchemaValidator.\n * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.\n * @param {SV} schemaValidator - The schema provider.\n * @param {T['_Entity']} entity - The entity to convert.\n * @returns {T} - An instance of the T.\n */\n static fromEntity<\n T extends ResponseDtoMapper<unknown, SV>,\n SV extends AnySchemaValidator\n >(\n this: DtoMapperConstructor<T, SV>,\n schemaValidator: SV,\n ...[entity, ...additionalArgs]: Parameters<T['fromEntity']>\n ): Promise<T> {\n return construct(this, schemaValidator).fromEntity(\n entity,\n ...additionalArgs\n );\n }\n\n /**\n * Serializes an entity to a JSON object.\n *\n * @template T - A type that extends ResponseDtoMapper.\n * @template SV - A type that extends AnySchemaValidator.\n * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.\n * @param {SV} schemaValidator - The schema provider.\n * @param {T['_Entity']} entity - The entity to serialize.\n * @returns {T['_dto']} - The JSON object.\n * @throws {Error} - Throws an error if the DTO is invalid.\n */\n static serializeEntityToDto<\n T extends ResponseDtoMapper<unknown, SV>,\n SV extends AnySchemaValidator,\n DtoType extends T['_dto']\n >(\n this: DtoMapperConstructor<T, SV>,\n schemaValidator: SV,\n ...[entity, ...additionalArgs]: Parameters<T['fromEntity']>\n ): Promise<DtoType> {\n const result = construct(this, schemaValidator).fromEntity(\n entity,\n ...additionalArgs\n );\n return result.then((r) => r.toDto()) as Promise<DtoType>;\n }\n}\n"],"mappings":";AAAA;AAAA,EAEE,0BAAAA;AAAA,OACK;;;ACHP;AAAA,EAEE;AAAA,OAGK;AAaA,SAAS,UACd,MACA,iBACG;AACH,SAAO,IAAI,KAAK,mBAAoB,CAAC,CAAQ;AAC/C;AAOO,IAAe,gBAAf,MAA4D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMjE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOU;AAAA;AAAA;AAAA;AAAA;AAAA,EAaV;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,YAAY,iBAAqB;AAC/B,SAAK,kBAAkB;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,IAAI,IAAI,MAAoB;AAC1B,UAAM,eAAe,KAAK,gBAAgB;AAAA,MACxC,KAAK,gBAAgB,SAAS,KAAK,MAAM;AAAA,MACzC;AAAA,IACF;AACA,QAAI,CAAC,aAAa,IAAI;AACpB,YAAM,IAAI,MAAM,uBAAuB,aAAa,QAAQ,KAAK,CAAC;AAAA,IACpE;AACA,S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AEnHA;AAAA,EAEE,0BAAAC;AAAA,OACK;AAWA,IAAe,oBAAf,cAGG,cAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAM1B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAqBA,QAA+B;AAC7B,UAAM,eAAe,KAAK,gBAAgB;AAAA,MACxC,KAAK,gBAAgB,SAAS,KAAK,MAAM;AAAA,MACzC,KAAK;AAAA,IACP;AACA,QAAI,CAAC,aAAa,IAAI;AACpB,YAAM,IAAI,MAAMC,wBAAuB,aAAa,QAAQ,KAAK,CAAC;AAAA,IACpE;AACA,WAAO,QAAQ,QAAQ,KAAK,GAAG;AAAA,EACjC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,wBACK,CAAC,QAAQ,GAAG,cAAc,GACN;AACvB,UAAM,SAAS,KAAK,WAAW,QAAQ,GAAG,cAAc;AACxD,WAAO,OAAO,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC;AAAA,EACrC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,OAAO,WAKL,oBACG,CAAC,QAAQ,GAAG,cAAc,GACjB;AACZ,WAAO,UAAU,MAAM,eAAe,EAAE;AAAA,MACtC;AAAA,MACA,GAAG;AAAA,IACL;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaA,OAAO,qBAML,oBACG,CAAC,QAAQ,GAAG,cAAc,GACX;AAClB,UAAM,SAAS,UAAU,MAAM,eAAe,EAAE;AAAA,MAC9C;AAAA,MACA,GAAG;AAAA,IACL;AACA,WAAO,OAAO,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC;AAAA,EACrC;AACF;","names":["prettyPrintParseErrors","prettyPrintParseErrors","prettyPrintParseErrors","prettyPrintParseErrors"]}
1
+ {"version":3,"sources":["../../src/mappers/models/requestMapper.model.ts","../../src/mappers/models/baseMapper.model.ts","../../src/mappers/models/responseMapper.model.ts"],"sourcesContent":["import {\n AnySchemaValidator,\n prettyPrintParseErrors\n} from '@forklaunch/validator';\nimport { MapperConstructor } from '../interfaces/mappers.interface';\nimport { BaseMapper, construct } from './baseMapper.model';\n\n/**\n * Abstract class representing a request entity mapper.\n *\n * @template Entity - A type that extends SqlBaseEntity.\n * @template SV - A type that extends AnySchemaValidator.\n * @extends {BaseMapper<SV>}\n */\nexport abstract class RequestMapper<\n Entity,\n SV extends AnySchemaValidator\n> extends BaseMapper<SV> {\n /**\n * The entity type.\n * @type {Entity}\n * @protected\n */\n _Entity!: Entity;\n\n /**\n * Converts the underlying DTO to an entity.\n *\n * @abstract\n * @param {...unknown[]} additionalArgs - Additional arguments.\n * @returns {Promise<Entity>} - The entity.\n */\n abstract toEntity(...additionalArgs: unknown[]): Promise<Entity>;\n\n /**\n * Populates the DTO with data from a JSON object.\n *\n * @param {this['_dto']} json - The JSON object.\n * @returns {Promise<this>} - The instance of the RequestMapper.\n */\n fromDto(json: this['_dto']): Promise<this> {\n const parsedSchema = this.schemaValidator.parse(\n this.schemaValidator.schemify(this.schema),\n json\n );\n if (!parsedSchema.ok) {\n throw new Error(prettyPrintParseErrors(parsedSchema.errors, 'DTO'));\n }\n this.dto = json;\n return Promise.resolve(this);\n }\n\n /**\n * Deserializes a JSON object to an entity.\n *\n * @param {this['_dto']} json - The JSON object.\n * @param {...unknown[]} additionalArgs - Additional arguments.\n * @returns {Entity} - The entity.\n */\n deserializeDtoToEntity(\n json: this['_dto'],\n ...additionalArgs: Parameters<this['toEntity']>\n ): Promise<Entity> {\n const result = this.fromDto(json);\n return result.then((r) => r.toEntity(...additionalArgs));\n }\n\n /**\n * Creates an instance of a RequestMapper from a JSON object.\n *\n * @template T - A type that extends RequestMapper.\n * @template SV - A type that extends AnySchemaValidator.\n * @template JsonType - The type of the JSON object.\n * @param {MapperConstructor<T, SV>} this - The constructor of the T.\n * @param {SV} schemaValidator - The schema provider.\n * @param {JsonType} json - The JSON object.\n * @returns {T} - An instance of the T.\n */\n static fromDto<\n T extends RequestMapper<unknown, SV>,\n SV extends AnySchemaValidator,\n JsonType extends T['_dto']\n >(\n this: MapperConstructor<T, SV>,\n schemaValidator: SV,\n json: JsonType\n ): Promise<T> {\n return construct(this, schemaValidator).fromDto(json);\n }\n\n /**\n * Deserializes a JSON object to an entity.\n *\n * @template T - A type that extends RequestMapper.\n * @template SV - A type that extends AnySchemaValidator.\n * @template JsonType - The type of the JSON object.\n * @param {MapperConstructor<T, SV>} this - The constructor of the T.\n * @param {SV} schemaValidator - The schema provider.\n * @param {JsonType} json - The JSON object.\n * @param {...unknown[]} additionalArgs - Additional arguments.\n * @returns {T['_Entity']} - The entity.\n */\n static deserializeDtoToEntity<\n T extends RequestMapper<unknown, SV>,\n SV extends AnySchemaValidator,\n JsonType extends T['_dto']\n >(\n this: MapperConstructor<T, SV>,\n schemaValidator: SV,\n json: JsonType,\n ...additionalArgs: Parameters<T['toEntity']>\n ): Promise<T['_Entity']> {\n const result = construct(this, schemaValidator).fromDto(json);\n return result.then((r) => r.toEntity(...additionalArgs));\n }\n}\n","import {\n AnySchemaValidator,\n prettyPrintParseErrors,\n Schema,\n SchemaValidator\n} from '@forklaunch/validator';\nimport { MapperSchemaValidatorObject } from '../../../../internal/src/types/mappers.types';\nimport { MapperConstructor } from '../interfaces/mappers.interface';\n\n/**\n * Constructs an instance of a T.\n *\n * @template T - A type that extends BaseMapper.\n * @template SV - A type that extends AnySchemaValidator.\n * @param {MapperConstructor<T, SV>} self - The constructor of the T.\n * @param {SV} [schemaValidator] - The optional schema validator.\n * @returns {T} - An instance of the T.\n */\nexport function construct<T, SV extends AnySchemaValidator>(\n self: MapperConstructor<T, SV>,\n schemaValidator?: SV\n): T {\n return new self(schemaValidator || ({} as SV));\n}\n\n/**\n * Abstract class representing a base entity mapper.\n *\n * @template SV - A type that extends AnySchemaValidator.\n */\nexport abstract class BaseMapper<SV extends AnySchemaValidator> {\n /**\n * The schema validator exact type.\n * @type {SV}\n * @protected\n */\n _SV!: SV;\n\n /**\n * The schema validator as a general type.\n * @type {SchemaValidator}\n * @protected\n */\n protected schemaValidator: SchemaValidator;\n\n /**\n * The schema definition.\n * @type {MapperSchemaValidatorObject<SV>}\n * @abstract\n */\n abstract schema: MapperSchemaValidatorObject<SV>;\n\n /**\n * The Data Transfer Object (DTO).\n * @type {Schema<this['schema'], SV>}\n */\n _dto!: Schema<this['schema'], SV>;\n\n /**\n * Creates an instance of BaseMapper.\n *\n * @param {SV} schemaValidator - The schema provider.\n */\n constructor(schemaValidator: SV) {\n this.schemaValidator = schemaValidator as unknown as SchemaValidator;\n }\n\n /**\n * Validates and sets the Data Transfer Object (DTO).\n *\n * @param {this['_dto']} dto - The Data Transfer Object (DTO).\n * @throws {Error} - Throws an error if the DTO is invalid.\n */\n set dto(_dto: this['_dto']) {\n const parsedSchema = this.schemaValidator.parse(\n this.schemaValidator.schemify(this.schema),\n _dto\n );\n if (!parsedSchema.ok) {\n throw new Error(prettyPrintParseErrors(parsedSchema.errors, 'DTO'));\n }\n this._dto = _dto as unknown as Schema<this['schema'], SV>;\n }\n\n /**\n * Validates and gets the Data Transfer Object (DTO).\n *\n * @returns {this['_dto']} - The Data Transfer Object (DTO).\n */\n get dto(): this['_dto'] {\n return this._dto as unknown as this['_dto'];\n }\n\n /**\n * Gets the schema of a T.\n *\n * @template T - A type that extends BaseMapper.\n * @template SV - A type that extends AnySchemaValidator.\n * @param {MapperConstructor<T, SV>} this - The constructor of the T.\n * @returns {T['schema']} - The schema of the T.\n */\n static schema<T extends BaseMapper<SV>, SV extends AnySchemaValidator>(\n this: MapperConstructor<T, SV>\n ): T['schema'] {\n return construct(this).schema;\n }\n}\n","import {\n AnySchemaValidator,\n prettyPrintParseErrors\n} from '@forklaunch/validator';\nimport { MapperConstructor } from '../interfaces/mappers.interface';\nimport { BaseMapper, construct } from './baseMapper.model';\n\n/**\n * Abstract class representing a response entity mapper.\n *\n * @template Entity - A type that extends SqlBaseEntity.\n * @template SV - A type that extends AnySchemaValidator.\n * @extends {BaseMapper<SV>}\n */\nexport abstract class ResponseMapper<\n Entity,\n SV extends AnySchemaValidator\n> extends BaseMapper<SV> {\n /**\n * The entity type.\n * @type {Entity}\n * @protected\n */\n _Entity!: Entity;\n\n /**\n * Populates entity mapper with DTO from an entity.\n *\n * @abstract\n * @param {Entity} entity - The entity to convert.\n * @param {...unknown[]} additionalArgs - Additional arguments.\n * @returns {this} - The instance of the ResponseMapper.\n */\n abstract fromEntity(\n entity: Entity,\n ...additionalArgs: unknown[]\n ): Promise<this>;\n\n /**\n * Converts the underlying DTO to a JSON object.\n *\n * @returns {this['_dto']} - The JSON object.\n * @throws {Error} - Throws an error if the DTO is invalid.\n */\n toDto(): Promise<this['_dto']> {\n const parsedSchema = this.schemaValidator.parse(\n this.schemaValidator.schemify(this.schema),\n this.dto\n );\n if (!parsedSchema.ok) {\n throw new Error(prettyPrintParseErrors(parsedSchema.errors, 'DTO'));\n }\n return Promise.resolve(this.dto) as unknown as Promise<this['_dto']>;\n }\n\n /**\n * Serializes an entity to a JSON object.\n *\n * @param {Entity} entity - The entity to serialize.\n * @returns {this['_dto']} - The JSON object.\n * @throws {Error} - Throws an error if the DTO is invalid.\n */\n serializeEntityToDto(\n ...[entity, ...additionalArgs]: Parameters<this['fromEntity']>\n ): Promise<this['_dto']> {\n const result = this.fromEntity(entity, ...additionalArgs);\n return result.then((r) => r.toDto());\n }\n\n /**\n * Populates entity mapper with DTO from an entity.\n *\n * @template T - A type that extends ResponseMapper.\n * @template SV - A type that extends AnySchemaValidator.\n * @param {MapperConstructor<T, SV>} this - The constructor of the T.\n * @param {SV} schemaValidator - The schema provider.\n * @param {T['_Entity']} entity - The entity to convert.\n * @returns {T} - An instance of the T.\n */\n static fromEntity<\n T extends ResponseMapper<unknown, SV>,\n SV extends AnySchemaValidator\n >(\n this: MapperConstructor<T, SV>,\n schemaValidator: SV,\n ...[entity, ...additionalArgs]: Parameters<T['fromEntity']>\n ): Promise<T> {\n return construct(this, schemaValidator).fromEntity(\n entity,\n ...additionalArgs\n );\n }\n\n /**\n * Serializes an entity to a JSON object.\n *\n * @template T - A type that extends ResponseMapper.\n * @template SV - A type that extends AnySchemaValidator.\n * @param {MapperConstructor<T, SV>} this - The constructor of the T.\n * @param {SV} schemaValidator - The schema provider.\n * @param {T['_Entity']} entity - The entity to serialize.\n * @returns {T['_dto']} - The JSON object.\n * @throws {Error} - Throws an error if the DTO is invalid.\n */\n static serializeEntityToDto<\n T extends ResponseMapper<unknown, SV>,\n SV extends AnySchemaValidator,\n DtoType extends T['_dto']\n >(\n this: MapperConstructor<T, SV>,\n schemaValidator: SV,\n ...[entity, ...additionalArgs]: Parameters<T['fromEntity']>\n ): Promise<DtoType> {\n const result = construct(this, schemaValidator).fromEntity(\n entity,\n ...additionalArgs\n );\n return result.then((r) => r.toDto()) as Promise<DtoType>;\n }\n}\n"],"mappings":";AAAA;AAAA,EAEE,0BAAAA;AAAA,OACK;;;ACHP;AAAA,EAEE;AAAA,OAGK;AAaA,SAAS,UACd,MACA,iBACG;AACH,SAAO,IAAI,KAAK,mBAAoB,CAAC,CAAQ;AAC/C;AAOO,IAAe,aAAf,MAAyD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAM9D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOU;AAAA;AAAA;AAAA;AAAA;AAAA,EAaV;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,YAAY,iBAAqB;AAC/B,SAAK,kBAAkB;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,IAAI,IAAI,MAAoB;AAC1B,UAAM,eAAe,KAAK,gBAAgB;AAAA,MACxC,KAAK,gBAAgB,SAAS,KAAK,MAAM;AAAA,MACzC;AAAA,IACF;AACA,QAAI,CAAC,aAAa,IAAI;AACpB,YAAM,IAAI,MAAM,uBAAuB,aAAa,QAAQ,KAAK,CAAC;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
1
1
  {
2
2
  "name": "@forklaunch/core",
3
- "version": "0.9.20",
3
+ "version": "0.9.21",
4
4
  "description": "forklaunch-js core package. Contains useful building blocks.",
5
5
  "homepage": "https://github.com/forklaunch/forklaunch-js#readme",
6
6
  "bugs": {
@@ -90,8 +90,8 @@
90
90
  "pino-pretty": "^13.0.0",
91
91
  "redis": "^5.5.6",
92
92
  "uuid": "^11.1.0",
93
- "@forklaunch/common": "0.3.13",
94
- "@forklaunch/validator": "0.6.15"
93
+ "@forklaunch/common": "0.3.14",
94
+ "@forklaunch/validator": "0.6.16"
95
95
  },
96
96
  "devDependencies": {
97
97
  "@eslint/js": "^9.29.0",