@forklaunch/core 0.9.19 → 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.
@@ -1,15 +1,13 @@
1
1
  import { AnySchemaValidator, UnboxedObjectSchema, SchemaValidator, Schema } from '@forklaunch/validator';
2
- import { TypeboxSchemaValidator } from '@forklaunch/validator/typebox';
3
- import { ZodSchemaValidator } from '@forklaunch/validator/zod';
4
2
 
5
3
  /**
6
4
  * Interface representing a constructor for an entity mapper.
7
5
  *
8
6
  * @template T - The type of the entity mapper.
9
7
  * @template SV - The type of the schema validator.
10
- * @interface DtoMapperConstructor
8
+ * @interface MapperConstructor
11
9
  */
12
- interface DtoMapperConstructor<T, SV extends AnySchemaValidator> {
10
+ interface MapperConstructor<T, SV extends AnySchemaValidator> {
13
11
  /**
14
12
  * Creates a new instance of the entity mapper.
15
13
  *
@@ -23,40 +21,16 @@ interface DtoMapperConstructor<T, SV extends AnySchemaValidator> {
23
21
  * Type representing a schema validator object for an entity mapper.
24
22
  *
25
23
  * @template SV - A type that extends AnySchemaValidator.
26
- * @typedef {SV['_ValidSchemaObject'] | UnboxedObjectSchema<SV>} DtoMapperSchemaValidatorObject
24
+ * @typedef {SV['_ValidSchemaObject'] | UnboxedObjectSchema<SV>} MapperSchemaValidatorObject
27
25
  */
28
- type DtoMapperSchemaValidatorObject<SV extends AnySchemaValidator> = SV['_ValidSchemaObject'] | UnboxedObjectSchema<SV>;
29
- /**
30
- * Type representing a response DTO mapper for an entity mapper.
31
- *
32
- * @template SchemaValidator - A type that extends AnySchemaValidator.
33
- * @template Dto - The type of the DTO object.
34
- * @template Entity - The type of the entity object.
35
- */
36
- type ResponseDtoMapperConstructor<SchemaValidator extends AnySchemaValidator, Dto, Entity, SerializeEntityToDto = unknown> = new (schemaValidator: SchemaValidator) => {
37
- dto: Dto;
38
- _Entity: Entity;
39
- serializeEntityToDto: SerializeEntityToDto;
40
- };
41
- /**
42
- * Type representing a request DTO mapper for an entity mapper.
43
- *
44
- * @template SV - A type that extends AnySchemaValidator.
45
- * @template Dto - The type of the DTO object.
46
- * @template Entity - The type of the entity object.
47
- */
48
- type RequestDtoMapperConstructor<SchemaValidator extends AnySchemaValidator, Dto, Entity, DeserializeDtoToEntity = unknown> = new (schemaValidator: SchemaValidator) => {
49
- dto: Dto;
50
- _Entity: Entity;
51
- deserializeDtoToEntity: DeserializeDtoToEntity;
52
- };
26
+ type MapperSchemaValidatorObject<SV extends AnySchemaValidator> = SV['_ValidSchemaObject'] | UnboxedObjectSchema<SV>;
53
27
 
54
28
  /**
55
29
  * Abstract class representing a base entity mapper.
56
30
  *
57
31
  * @template SV - A type that extends AnySchemaValidator.
58
32
  */
59
- declare abstract class BaseDtoMapper<SV extends AnySchemaValidator> {
33
+ declare abstract class BaseMapper<SV extends AnySchemaValidator> {
60
34
  /**
61
35
  * The schema validator exact type.
62
36
  * @type {SV}
@@ -71,17 +45,17 @@ declare abstract class BaseDtoMapper<SV extends AnySchemaValidator> {
71
45
  protected schemaValidator: SchemaValidator;
72
46
  /**
73
47
  * The schema definition.
74
- * @type {DtoMapperSchemaValidatorObject<SV>}
48
+ * @type {MapperSchemaValidatorObject<SV>}
75
49
  * @abstract
76
50
  */
77
- abstract schema: DtoMapperSchemaValidatorObject<SV>;
51
+ abstract schema: MapperSchemaValidatorObject<SV>;
78
52
  /**
79
53
  * The Data Transfer Object (DTO).
80
54
  * @type {Schema<this['schema'], SV>}
81
55
  */
82
56
  _dto: Schema<this['schema'], SV>;
83
57
  /**
84
- * Creates an instance of BaseDtoMapper.
58
+ * Creates an instance of BaseMapper.
85
59
  *
86
60
  * @param {SV} schemaValidator - The schema provider.
87
61
  */
@@ -102,12 +76,12 @@ declare abstract class BaseDtoMapper<SV extends AnySchemaValidator> {
102
76
  /**
103
77
  * Gets the schema of a T.
104
78
  *
105
- * @template T - A type that extends BaseDtoMapper.
79
+ * @template T - A type that extends BaseMapper.
106
80
  * @template SV - A type that extends AnySchemaValidator.
107
- * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
81
+ * @param {MapperConstructor<T, SV>} this - The constructor of the T.
108
82
  * @returns {T['schema']} - The schema of the T.
109
83
  */
110
- 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'];
111
85
  }
112
86
 
113
87
  /**
@@ -115,9 +89,9 @@ declare abstract class BaseDtoMapper<SV extends AnySchemaValidator> {
115
89
  *
116
90
  * @template Entity - A type that extends SqlBaseEntity.
117
91
  * @template SV - A type that extends AnySchemaValidator.
118
- * @extends {BaseDtoMapper<SV>}
92
+ * @extends {BaseMapper<SV>}
119
93
  */
120
- declare abstract class RequestDtoMapper<Entity, SV extends AnySchemaValidator> extends BaseDtoMapper<SV> {
94
+ declare abstract class RequestMapper<Entity, SV extends AnySchemaValidator> extends BaseMapper<SV> {
121
95
  /**
122
96
  * The entity type.
123
97
  * @type {Entity}
@@ -136,7 +110,7 @@ declare abstract class RequestDtoMapper<Entity, SV extends AnySchemaValidator> e
136
110
  * Populates the DTO with data from a JSON object.
137
111
  *
138
112
  * @param {this['_dto']} json - The JSON object.
139
- * @returns {Promise<this>} - The instance of the RequestDtoMapper.
113
+ * @returns {Promise<this>} - The instance of the RequestMapper.
140
114
  */
141
115
  fromDto(json: this['_dto']): Promise<this>;
142
116
  /**
@@ -148,30 +122,30 @@ declare abstract class RequestDtoMapper<Entity, SV extends AnySchemaValidator> e
148
122
  */
149
123
  deserializeDtoToEntity(json: this['_dto'], ...additionalArgs: Parameters<this['toEntity']>): Promise<Entity>;
150
124
  /**
151
- * Creates an instance of a RequestDtoMapper from a JSON object.
125
+ * Creates an instance of a RequestMapper from a JSON object.
152
126
  *
153
- * @template T - A type that extends RequestDtoMapper.
127
+ * @template T - A type that extends RequestMapper.
154
128
  * @template SV - A type that extends AnySchemaValidator.
155
129
  * @template JsonType - The type of the JSON object.
156
- * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
130
+ * @param {MapperConstructor<T, SV>} this - The constructor of the T.
157
131
  * @param {SV} schemaValidator - The schema provider.
158
132
  * @param {JsonType} json - The JSON object.
159
133
  * @returns {T} - An instance of the T.
160
134
  */
161
- 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>;
162
136
  /**
163
137
  * Deserializes a JSON object to an entity.
164
138
  *
165
- * @template T - A type that extends RequestDtoMapper.
139
+ * @template T - A type that extends RequestMapper.
166
140
  * @template SV - A type that extends AnySchemaValidator.
167
141
  * @template JsonType - The type of the JSON object.
168
- * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
142
+ * @param {MapperConstructor<T, SV>} this - The constructor of the T.
169
143
  * @param {SV} schemaValidator - The schema provider.
170
144
  * @param {JsonType} json - The JSON object.
171
145
  * @param {...unknown[]} additionalArgs - Additional arguments.
172
146
  * @returns {T['_Entity']} - The entity.
173
147
  */
174
- 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']>;
175
149
  }
176
150
 
177
151
  /**
@@ -179,9 +153,9 @@ declare abstract class RequestDtoMapper<Entity, SV extends AnySchemaValidator> e
179
153
  *
180
154
  * @template Entity - A type that extends SqlBaseEntity.
181
155
  * @template SV - A type that extends AnySchemaValidator.
182
- * @extends {BaseDtoMapper<SV>}
156
+ * @extends {BaseMapper<SV>}
183
157
  */
184
- declare abstract class ResponseDtoMapper<Entity, SV extends AnySchemaValidator> extends BaseDtoMapper<SV> {
158
+ declare abstract class ResponseMapper<Entity, SV extends AnySchemaValidator> extends BaseMapper<SV> {
185
159
  /**
186
160
  * The entity type.
187
161
  * @type {Entity}
@@ -194,7 +168,7 @@ declare abstract class ResponseDtoMapper<Entity, SV extends AnySchemaValidator>
194
168
  * @abstract
195
169
  * @param {Entity} entity - The entity to convert.
196
170
  * @param {...unknown[]} additionalArgs - Additional arguments.
197
- * @returns {this} - The instance of the ResponseDtoMapper.
171
+ * @returns {this} - The instance of the ResponseMapper.
198
172
  */
199
173
  abstract fromEntity(entity: Entity, ...additionalArgs: unknown[]): Promise<this>;
200
174
  /**
@@ -215,32 +189,26 @@ declare abstract class ResponseDtoMapper<Entity, SV extends AnySchemaValidator>
215
189
  /**
216
190
  * Populates entity mapper with DTO from an entity.
217
191
  *
218
- * @template T - A type that extends ResponseDtoMapper.
192
+ * @template T - A type that extends ResponseMapper.
219
193
  * @template SV - A type that extends AnySchemaValidator.
220
- * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
194
+ * @param {MapperConstructor<T, SV>} this - The constructor of the T.
221
195
  * @param {SV} schemaValidator - The schema provider.
222
196
  * @param {T['_Entity']} entity - The entity to convert.
223
197
  * @returns {T} - An instance of the T.
224
198
  */
225
- 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>;
226
200
  /**
227
201
  * Serializes an entity to a JSON object.
228
202
  *
229
- * @template T - A type that extends ResponseDtoMapper.
203
+ * @template T - A type that extends ResponseMapper.
230
204
  * @template SV - A type that extends AnySchemaValidator.
231
- * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
205
+ * @param {MapperConstructor<T, SV>} this - The constructor of the T.
232
206
  * @param {SV} schemaValidator - The schema provider.
233
207
  * @param {T['_Entity']} entity - The entity to serialize.
234
208
  * @returns {T['_dto']} - The JSON object.
235
209
  * @throws {Error} - Throws an error if the DTO is invalid.
236
210
  */
237
- 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>;
238
212
  }
239
213
 
240
- type SchemasByValidator<T extends AnySchemaValidator, TypeBoxSchemas extends (...args: never[]) => unknown, ZodSchemas extends (...args: never[]) => unknown> = T extends TypeboxSchemaValidator ? ReturnType<TypeBoxSchemas> : T extends ZodSchemaValidator ? ReturnType<ZodSchemas> : never;
241
-
242
- declare function serviceSchemaResolver<Options extends Record<string, unknown>, TypeBoxSchemas, ZodSchemas>(TypeBoxSchemas: (options: Options) => TypeBoxSchemas, ZodSchemas: (options: Options) => ZodSchemas): <SchemaValidator extends AnySchemaValidator>(options: Options & {
243
- validator: SchemaValidator;
244
- }) => SchemasByValidator<SchemaValidator, (options: Options) => TypeBoxSchemas, (options: Options) => ZodSchemas>;
245
-
246
- export { type DtoMapperSchemaValidatorObject, RequestDtoMapper, type RequestDtoMapperConstructor, ResponseDtoMapper, type ResponseDtoMapperConstructor, type SchemasByValidator, serviceSchemaResolver };
214
+ export { RequestMapper, ResponseMapper };
@@ -1,15 +1,13 @@
1
1
  import { AnySchemaValidator, UnboxedObjectSchema, SchemaValidator, Schema } from '@forklaunch/validator';
2
- import { TypeboxSchemaValidator } from '@forklaunch/validator/typebox';
3
- import { ZodSchemaValidator } from '@forklaunch/validator/zod';
4
2
 
5
3
  /**
6
4
  * Interface representing a constructor for an entity mapper.
7
5
  *
8
6
  * @template T - The type of the entity mapper.
9
7
  * @template SV - The type of the schema validator.
10
- * @interface DtoMapperConstructor
8
+ * @interface MapperConstructor
11
9
  */
12
- interface DtoMapperConstructor<T, SV extends AnySchemaValidator> {
10
+ interface MapperConstructor<T, SV extends AnySchemaValidator> {
13
11
  /**
14
12
  * Creates a new instance of the entity mapper.
15
13
  *
@@ -23,40 +21,16 @@ interface DtoMapperConstructor<T, SV extends AnySchemaValidator> {
23
21
  * Type representing a schema validator object for an entity mapper.
24
22
  *
25
23
  * @template SV - A type that extends AnySchemaValidator.
26
- * @typedef {SV['_ValidSchemaObject'] | UnboxedObjectSchema<SV>} DtoMapperSchemaValidatorObject
24
+ * @typedef {SV['_ValidSchemaObject'] | UnboxedObjectSchema<SV>} MapperSchemaValidatorObject
27
25
  */
28
- type DtoMapperSchemaValidatorObject<SV extends AnySchemaValidator> = SV['_ValidSchemaObject'] | UnboxedObjectSchema<SV>;
29
- /**
30
- * Type representing a response DTO mapper for an entity mapper.
31
- *
32
- * @template SchemaValidator - A type that extends AnySchemaValidator.
33
- * @template Dto - The type of the DTO object.
34
- * @template Entity - The type of the entity object.
35
- */
36
- type ResponseDtoMapperConstructor<SchemaValidator extends AnySchemaValidator, Dto, Entity, SerializeEntityToDto = unknown> = new (schemaValidator: SchemaValidator) => {
37
- dto: Dto;
38
- _Entity: Entity;
39
- serializeEntityToDto: SerializeEntityToDto;
40
- };
41
- /**
42
- * Type representing a request DTO mapper for an entity mapper.
43
- *
44
- * @template SV - A type that extends AnySchemaValidator.
45
- * @template Dto - The type of the DTO object.
46
- * @template Entity - The type of the entity object.
47
- */
48
- type RequestDtoMapperConstructor<SchemaValidator extends AnySchemaValidator, Dto, Entity, DeserializeDtoToEntity = unknown> = new (schemaValidator: SchemaValidator) => {
49
- dto: Dto;
50
- _Entity: Entity;
51
- deserializeDtoToEntity: DeserializeDtoToEntity;
52
- };
26
+ type MapperSchemaValidatorObject<SV extends AnySchemaValidator> = SV['_ValidSchemaObject'] | UnboxedObjectSchema<SV>;
53
27
 
54
28
  /**
55
29
  * Abstract class representing a base entity mapper.
56
30
  *
57
31
  * @template SV - A type that extends AnySchemaValidator.
58
32
  */
59
- declare abstract class BaseDtoMapper<SV extends AnySchemaValidator> {
33
+ declare abstract class BaseMapper<SV extends AnySchemaValidator> {
60
34
  /**
61
35
  * The schema validator exact type.
62
36
  * @type {SV}
@@ -71,17 +45,17 @@ declare abstract class BaseDtoMapper<SV extends AnySchemaValidator> {
71
45
  protected schemaValidator: SchemaValidator;
72
46
  /**
73
47
  * The schema definition.
74
- * @type {DtoMapperSchemaValidatorObject<SV>}
48
+ * @type {MapperSchemaValidatorObject<SV>}
75
49
  * @abstract
76
50
  */
77
- abstract schema: DtoMapperSchemaValidatorObject<SV>;
51
+ abstract schema: MapperSchemaValidatorObject<SV>;
78
52
  /**
79
53
  * The Data Transfer Object (DTO).
80
54
  * @type {Schema<this['schema'], SV>}
81
55
  */
82
56
  _dto: Schema<this['schema'], SV>;
83
57
  /**
84
- * Creates an instance of BaseDtoMapper.
58
+ * Creates an instance of BaseMapper.
85
59
  *
86
60
  * @param {SV} schemaValidator - The schema provider.
87
61
  */
@@ -102,12 +76,12 @@ declare abstract class BaseDtoMapper<SV extends AnySchemaValidator> {
102
76
  /**
103
77
  * Gets the schema of a T.
104
78
  *
105
- * @template T - A type that extends BaseDtoMapper.
79
+ * @template T - A type that extends BaseMapper.
106
80
  * @template SV - A type that extends AnySchemaValidator.
107
- * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
81
+ * @param {MapperConstructor<T, SV>} this - The constructor of the T.
108
82
  * @returns {T['schema']} - The schema of the T.
109
83
  */
110
- 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'];
111
85
  }
112
86
 
113
87
  /**
@@ -115,9 +89,9 @@ declare abstract class BaseDtoMapper<SV extends AnySchemaValidator> {
115
89
  *
116
90
  * @template Entity - A type that extends SqlBaseEntity.
117
91
  * @template SV - A type that extends AnySchemaValidator.
118
- * @extends {BaseDtoMapper<SV>}
92
+ * @extends {BaseMapper<SV>}
119
93
  */
120
- declare abstract class RequestDtoMapper<Entity, SV extends AnySchemaValidator> extends BaseDtoMapper<SV> {
94
+ declare abstract class RequestMapper<Entity, SV extends AnySchemaValidator> extends BaseMapper<SV> {
121
95
  /**
122
96
  * The entity type.
123
97
  * @type {Entity}
@@ -136,7 +110,7 @@ declare abstract class RequestDtoMapper<Entity, SV extends AnySchemaValidator> e
136
110
  * Populates the DTO with data from a JSON object.
137
111
  *
138
112
  * @param {this['_dto']} json - The JSON object.
139
- * @returns {Promise<this>} - The instance of the RequestDtoMapper.
113
+ * @returns {Promise<this>} - The instance of the RequestMapper.
140
114
  */
141
115
  fromDto(json: this['_dto']): Promise<this>;
142
116
  /**
@@ -148,30 +122,30 @@ declare abstract class RequestDtoMapper<Entity, SV extends AnySchemaValidator> e
148
122
  */
149
123
  deserializeDtoToEntity(json: this['_dto'], ...additionalArgs: Parameters<this['toEntity']>): Promise<Entity>;
150
124
  /**
151
- * Creates an instance of a RequestDtoMapper from a JSON object.
125
+ * Creates an instance of a RequestMapper from a JSON object.
152
126
  *
153
- * @template T - A type that extends RequestDtoMapper.
127
+ * @template T - A type that extends RequestMapper.
154
128
  * @template SV - A type that extends AnySchemaValidator.
155
129
  * @template JsonType - The type of the JSON object.
156
- * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
130
+ * @param {MapperConstructor<T, SV>} this - The constructor of the T.
157
131
  * @param {SV} schemaValidator - The schema provider.
158
132
  * @param {JsonType} json - The JSON object.
159
133
  * @returns {T} - An instance of the T.
160
134
  */
161
- 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>;
162
136
  /**
163
137
  * Deserializes a JSON object to an entity.
164
138
  *
165
- * @template T - A type that extends RequestDtoMapper.
139
+ * @template T - A type that extends RequestMapper.
166
140
  * @template SV - A type that extends AnySchemaValidator.
167
141
  * @template JsonType - The type of the JSON object.
168
- * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
142
+ * @param {MapperConstructor<T, SV>} this - The constructor of the T.
169
143
  * @param {SV} schemaValidator - The schema provider.
170
144
  * @param {JsonType} json - The JSON object.
171
145
  * @param {...unknown[]} additionalArgs - Additional arguments.
172
146
  * @returns {T['_Entity']} - The entity.
173
147
  */
174
- 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']>;
175
149
  }
176
150
 
177
151
  /**
@@ -179,9 +153,9 @@ declare abstract class RequestDtoMapper<Entity, SV extends AnySchemaValidator> e
179
153
  *
180
154
  * @template Entity - A type that extends SqlBaseEntity.
181
155
  * @template SV - A type that extends AnySchemaValidator.
182
- * @extends {BaseDtoMapper<SV>}
156
+ * @extends {BaseMapper<SV>}
183
157
  */
184
- declare abstract class ResponseDtoMapper<Entity, SV extends AnySchemaValidator> extends BaseDtoMapper<SV> {
158
+ declare abstract class ResponseMapper<Entity, SV extends AnySchemaValidator> extends BaseMapper<SV> {
185
159
  /**
186
160
  * The entity type.
187
161
  * @type {Entity}
@@ -194,7 +168,7 @@ declare abstract class ResponseDtoMapper<Entity, SV extends AnySchemaValidator>
194
168
  * @abstract
195
169
  * @param {Entity} entity - The entity to convert.
196
170
  * @param {...unknown[]} additionalArgs - Additional arguments.
197
- * @returns {this} - The instance of the ResponseDtoMapper.
171
+ * @returns {this} - The instance of the ResponseMapper.
198
172
  */
199
173
  abstract fromEntity(entity: Entity, ...additionalArgs: unknown[]): Promise<this>;
200
174
  /**
@@ -215,32 +189,26 @@ declare abstract class ResponseDtoMapper<Entity, SV extends AnySchemaValidator>
215
189
  /**
216
190
  * Populates entity mapper with DTO from an entity.
217
191
  *
218
- * @template T - A type that extends ResponseDtoMapper.
192
+ * @template T - A type that extends ResponseMapper.
219
193
  * @template SV - A type that extends AnySchemaValidator.
220
- * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
194
+ * @param {MapperConstructor<T, SV>} this - The constructor of the T.
221
195
  * @param {SV} schemaValidator - The schema provider.
222
196
  * @param {T['_Entity']} entity - The entity to convert.
223
197
  * @returns {T} - An instance of the T.
224
198
  */
225
- 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>;
226
200
  /**
227
201
  * Serializes an entity to a JSON object.
228
202
  *
229
- * @template T - A type that extends ResponseDtoMapper.
203
+ * @template T - A type that extends ResponseMapper.
230
204
  * @template SV - A type that extends AnySchemaValidator.
231
- * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
205
+ * @param {MapperConstructor<T, SV>} this - The constructor of the T.
232
206
  * @param {SV} schemaValidator - The schema provider.
233
207
  * @param {T['_Entity']} entity - The entity to serialize.
234
208
  * @returns {T['_dto']} - The JSON object.
235
209
  * @throws {Error} - Throws an error if the DTO is invalid.
236
210
  */
237
- 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>;
238
212
  }
239
213
 
240
- type SchemasByValidator<T extends AnySchemaValidator, TypeBoxSchemas extends (...args: never[]) => unknown, ZodSchemas extends (...args: never[]) => unknown> = T extends TypeboxSchemaValidator ? ReturnType<TypeBoxSchemas> : T extends ZodSchemaValidator ? ReturnType<ZodSchemas> : never;
241
-
242
- declare function serviceSchemaResolver<Options extends Record<string, unknown>, TypeBoxSchemas, ZodSchemas>(TypeBoxSchemas: (options: Options) => TypeBoxSchemas, ZodSchemas: (options: Options) => ZodSchemas): <SchemaValidator extends AnySchemaValidator>(options: Options & {
243
- validator: SchemaValidator;
244
- }) => SchemasByValidator<SchemaValidator, (options: Options) => TypeBoxSchemas, (options: Options) => ZodSchemas>;
245
-
246
- export { type DtoMapperSchemaValidatorObject, RequestDtoMapper, type RequestDtoMapperConstructor, ResponseDtoMapper, type ResponseDtoMapperConstructor, type SchemasByValidator, serviceSchemaResolver };
214
+ export { RequestMapper, ResponseMapper };
@@ -20,21 +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,
25
- serviceSchemaResolver: () => serviceSchemaResolver
23
+ RequestMapper: () => RequestMapper,
24
+ ResponseMapper: () => ResponseMapper
26
25
  });
27
26
  module.exports = __toCommonJS(mappers_exports);
28
27
 
29
- // src/mappers/models/requestDtoMapper.model.ts
28
+ // src/mappers/models/requestMapper.model.ts
30
29
  var import_validator2 = require("@forklaunch/validator");
31
30
 
32
- // src/mappers/models/baseDtoMapper.model.ts
31
+ // src/mappers/models/baseMapper.model.ts
33
32
  var import_validator = require("@forklaunch/validator");
34
33
  function construct(self, schemaValidator) {
35
34
  return new self(schemaValidator || {});
36
35
  }
37
- var BaseDtoMapper = class {
36
+ var BaseMapper = class {
38
37
  /**
39
38
  * The schema validator exact type.
40
39
  * @type {SV}
@@ -53,7 +52,7 @@ var BaseDtoMapper = class {
53
52
  */
54
53
  _dto;
55
54
  /**
56
- * Creates an instance of BaseDtoMapper.
55
+ * Creates an instance of BaseMapper.
57
56
  *
58
57
  * @param {SV} schemaValidator - The schema provider.
59
58
  */
@@ -87,9 +86,9 @@ var BaseDtoMapper = class {
87
86
  /**
88
87
  * Gets the schema of a T.
89
88
  *
90
- * @template T - A type that extends BaseDtoMapper.
89
+ * @template T - A type that extends BaseMapper.
91
90
  * @template SV - A type that extends AnySchemaValidator.
92
- * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
91
+ * @param {MapperConstructor<T, SV>} this - The constructor of the T.
93
92
  * @returns {T['schema']} - The schema of the T.
94
93
  */
95
94
  static schema() {
@@ -97,8 +96,8 @@ var BaseDtoMapper = class {
97
96
  }
98
97
  };
99
98
 
100
- // src/mappers/models/requestDtoMapper.model.ts
101
- var RequestDtoMapper = class extends BaseDtoMapper {
99
+ // src/mappers/models/requestMapper.model.ts
100
+ var RequestMapper = class extends BaseMapper {
102
101
  /**
103
102
  * The entity type.
104
103
  * @type {Entity}
@@ -109,7 +108,7 @@ var RequestDtoMapper = class extends BaseDtoMapper {
109
108
  * Populates the DTO with data from a JSON object.
110
109
  *
111
110
  * @param {this['_dto']} json - The JSON object.
112
- * @returns {Promise<this>} - The instance of the RequestDtoMapper.
111
+ * @returns {Promise<this>} - The instance of the RequestMapper.
113
112
  */
114
113
  fromDto(json) {
115
114
  const parsedSchema = this.schemaValidator.parse(
@@ -134,12 +133,12 @@ var RequestDtoMapper = class extends BaseDtoMapper {
134
133
  return result.then((r) => r.toEntity(...additionalArgs));
135
134
  }
136
135
  /**
137
- * Creates an instance of a RequestDtoMapper from a JSON object.
136
+ * Creates an instance of a RequestMapper from a JSON object.
138
137
  *
139
- * @template T - A type that extends RequestDtoMapper.
138
+ * @template T - A type that extends RequestMapper.
140
139
  * @template SV - A type that extends AnySchemaValidator.
141
140
  * @template JsonType - The type of the JSON object.
142
- * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
141
+ * @param {MapperConstructor<T, SV>} this - The constructor of the T.
143
142
  * @param {SV} schemaValidator - The schema provider.
144
143
  * @param {JsonType} json - The JSON object.
145
144
  * @returns {T} - An instance of the T.
@@ -150,10 +149,10 @@ var RequestDtoMapper = class extends BaseDtoMapper {
150
149
  /**
151
150
  * Deserializes a JSON object to an entity.
152
151
  *
153
- * @template T - A type that extends RequestDtoMapper.
152
+ * @template T - A type that extends RequestMapper.
154
153
  * @template SV - A type that extends AnySchemaValidator.
155
154
  * @template JsonType - The type of the JSON object.
156
- * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
155
+ * @param {MapperConstructor<T, SV>} this - The constructor of the T.
157
156
  * @param {SV} schemaValidator - The schema provider.
158
157
  * @param {JsonType} json - The JSON object.
159
158
  * @param {...unknown[]} additionalArgs - Additional arguments.
@@ -165,9 +164,9 @@ var RequestDtoMapper = class extends BaseDtoMapper {
165
164
  }
166
165
  };
167
166
 
168
- // src/mappers/models/responseDtoMapper.model.ts
167
+ // src/mappers/models/responseMapper.model.ts
169
168
  var import_validator3 = require("@forklaunch/validator");
170
- var ResponseDtoMapper = class extends BaseDtoMapper {
169
+ var ResponseMapper = class extends BaseMapper {
171
170
  /**
172
171
  * The entity type.
173
172
  * @type {Entity}
@@ -204,9 +203,9 @@ var ResponseDtoMapper = class extends BaseDtoMapper {
204
203
  /**
205
204
  * Populates entity mapper with DTO from an entity.
206
205
  *
207
- * @template T - A type that extends ResponseDtoMapper.
206
+ * @template T - A type that extends ResponseMapper.
208
207
  * @template SV - A type that extends AnySchemaValidator.
209
- * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
208
+ * @param {MapperConstructor<T, SV>} this - The constructor of the T.
210
209
  * @param {SV} schemaValidator - The schema provider.
211
210
  * @param {T['_Entity']} entity - The entity to convert.
212
211
  * @returns {T} - An instance of the T.
@@ -220,9 +219,9 @@ var ResponseDtoMapper = class extends BaseDtoMapper {
220
219
  /**
221
220
  * Serializes an entity to a JSON object.
222
221
  *
223
- * @template T - A type that extends ResponseDtoMapper.
222
+ * @template T - A type that extends ResponseMapper.
224
223
  * @template SV - A type that extends AnySchemaValidator.
225
- * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
224
+ * @param {MapperConstructor<T, SV>} this - The constructor of the T.
226
225
  * @param {SV} schemaValidator - The schema provider.
227
226
  * @param {T['_Entity']} entity - The entity to serialize.
228
227
  * @returns {T['_dto']} - The JSON object.
@@ -236,30 +235,9 @@ var ResponseDtoMapper = class extends BaseDtoMapper {
236
235
  return result.then((r) => r.toDto());
237
236
  }
238
237
  };
239
-
240
- // src/mappers/serviceSchemaResolver.ts
241
- var import_common = require("@forklaunch/common");
242
- function serviceSchemaResolver(TypeBoxSchemas, ZodSchemas) {
243
- return (options) => {
244
- switch (options.validator._Type) {
245
- case "TypeBox":
246
- return TypeBoxSchemas(options);
247
- case "Zod":
248
- return ZodSchemas(options);
249
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
250
- // @ts-ignore
251
- case "Mock":
252
- throw new Error("Mock schema validator not supported");
253
- default:
254
- (0, import_common.isNever)(options.validator._Type);
255
- throw new Error("Invalid schema validator");
256
- }
257
- };
258
- }
259
238
  // Annotate the CommonJS export names for ESM import in node:
260
239
  0 && (module.exports = {
261
- RequestDtoMapper,
262
- ResponseDtoMapper,
263
- serviceSchemaResolver
240
+ RequestMapper,
241
+ ResponseMapper
264
242
  });
265
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","../../src/mappers/serviceSchemaResolver.ts"],"sourcesContent":["export * from './models/requestDtoMapper.model';\nexport * from './models/responseDtoMapper.model';\nexport * from './serviceSchemaResolver';\nexport * from './types/mappers.types';\nexport * from './types/serviceSchemaResolver.types';\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 { DtoMapperConstructor } from '../interfaces/mappers.interface';\nimport { DtoMapperSchemaValidatorObject } from '../types/mappers.types';\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","import { isNever } from '@forklaunch/common';\nimport { AnySchemaValidator } from '@forklaunch/validator';\nimport { SchemasByValidator } from './types/serviceSchemaResolver.types';\n\nexport function serviceSchemaResolver<\n Options extends Record<string, unknown>,\n TypeBoxSchemas,\n ZodSchemas\n>(\n TypeBoxSchemas: (options: Options) => TypeBoxSchemas,\n ZodSchemas: (options: Options) => ZodSchemas\n) {\n return <SchemaValidator extends AnySchemaValidator>(\n options: Options & { validator: SchemaValidator }\n ): SchemasByValidator<\n SchemaValidator,\n (options: Options) => TypeBoxSchemas,\n (options: Options) => ZodSchemas\n > => {\n switch (options.validator._Type) {\n case 'TypeBox':\n return TypeBoxSchemas(options) as SchemasByValidator<\n SchemaValidator,\n (options: Options) => TypeBoxSchemas,\n (options: Options) => ZodSchemas\n >;\n case 'Zod':\n return ZodSchemas(options) as SchemasByValidator<\n SchemaValidator,\n (options: Options) => TypeBoxSchemas,\n (options: Options) => ZodSchemas\n >;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n case 'Mock':\n throw new Error('Mock schema validator not supported');\n default:\n isNever(options.validator._Type);\n throw new Error('Invalid schema validator');\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;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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O,OAAO,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC;AAAA,EACrC;AACF;;;ACvHA,oBAAwB;AAIjB,SAAS,sBAKd,gBACA,YACA;AACA,SAAO,CACL,YAKG;AACH,YAAQ,QAAQ,UAAU,OAAO;AAAA,MAC/B,KAAK;AACH,eAAO,eAAe,OAAO;AAAA,MAK/B,KAAK;AACH,eAAO,WAAW,OAAO;AAAA;AAAA;AAAA,MAO3B,KAAK;AACH,cAAM,IAAI,MAAM,qCAAqC;AAAA,MACvD;AACE,mCAAQ,QAAQ,UAAU,KAAK;AAC/B,cAAM,IAAI,MAAM,0BAA0B;AAAA,IAC9C;AAAA,EACF;AACF;","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;AA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;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":["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.
@@ -214,29 +214,8 @@ var ResponseDtoMapper = class extends BaseDtoMapper {
214
214
  return result.then((r) => r.toDto());
215
215
  }
216
216
  };
217
-
218
- // src/mappers/serviceSchemaResolver.ts
219
- import { isNever } from "@forklaunch/common";
220
- function serviceSchemaResolver(TypeBoxSchemas, ZodSchemas) {
221
- return (options) => {
222
- switch (options.validator._Type) {
223
- case "TypeBox":
224
- return TypeBoxSchemas(options);
225
- case "Zod":
226
- return ZodSchemas(options);
227
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
228
- // @ts-ignore
229
- case "Mock":
230
- throw new Error("Mock schema validator not supported");
231
- default:
232
- isNever(options.validator._Type);
233
- throw new Error("Invalid schema validator");
234
- }
235
- };
236
- }
237
217
  export {
238
- RequestDtoMapper,
239
- ResponseDtoMapper,
240
- serviceSchemaResolver
218
+ RequestMapper,
219
+ ResponseMapper
241
220
  };
242
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","../../src/mappers/serviceSchemaResolver.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 { DtoMapperConstructor } from '../interfaces/mappers.interface';\nimport { DtoMapperSchemaValidatorObject } from '../types/mappers.types';\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","import { isNever } from '@forklaunch/common';\nimport { AnySchemaValidator } from '@forklaunch/validator';\nimport { SchemasByValidator } from './types/serviceSchemaResolver.types';\n\nexport function serviceSchemaResolver<\n Options extends Record<string, unknown>,\n TypeBoxSchemas,\n ZodSchemas\n>(\n TypeBoxSchemas: (options: Options) => TypeBoxSchemas,\n ZodSchemas: (options: Options) => ZodSchemas\n) {\n return <SchemaValidator extends AnySchemaValidator>(\n options: Options & { validator: SchemaValidator }\n ): SchemasByValidator<\n SchemaValidator,\n (options: Options) => TypeBoxSchemas,\n (options: Options) => ZodSchemas\n > => {\n switch (options.validator._Type) {\n case 'TypeBox':\n return TypeBoxSchemas(options) as SchemasByValidator<\n SchemaValidator,\n (options: Options) => TypeBoxSchemas,\n (options: Options) => ZodSchemas\n >;\n case 'Zod':\n return ZodSchemas(options) as SchemasByValidator<\n SchemaValidator,\n (options: Options) => TypeBoxSchemas,\n (options: Options) => ZodSchemas\n >;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n case 'Mock':\n throw new Error('Mock schema validator not supported');\n default:\n isNever(options.validator._Type);\n throw new Error('Invalid schema validator');\n }\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,Y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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;;;ACvHA,SAAS,eAAe;AAIjB,SAAS,sBAKd,gBACA,YACA;AACA,SAAO,CACL,YAKG;AACH,YAAQ,QAAQ,UAAU,OAAO;AAAA,MAC/B,KAAK;AACH,eAAO,eAAe,OAAO;AAAA,MAK/B,KAAK;AACH,eAAO,WAAW,OAAO;AAAA;AAAA;AAAA,MAO3B,KAAK;AACH,cAAM,IAAI,MAAM,qCAAqC;AAAA,MACvD;AACE,gBAAQ,QAAQ,UAAU,KAAK;AAC/B,cAAM,IAAI,MAAM,0BAA0B;AAAA,IAC9C;AAAA,EACF;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.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AK,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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forklaunch/core",
3
- "version": "0.9.19",
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",