@forklaunch/core 0.13.8 → 0.13.9

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,4 +1,6 @@
1
- import { AnySchemaValidator, UnboxedObjectSchema, SchemaValidator, Schema } from '@forklaunch/validator';
1
+ import { AnySchemaValidator, UnboxedObjectSchema, SchemaValidator, Schema, IdiomaticSchema } from '@forklaunch/validator';
2
+ import { Constructor } from '@mikro-orm/core';
3
+ import { BaseEntity } from '../persistence/index.mjs';
2
4
 
3
5
  /**
4
6
  * Interface representing a constructor for an entity mapper.
@@ -211,4 +213,13 @@ declare abstract class ResponseMapper<Entity, SV extends AnySchemaValidator> ext
211
213
  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
214
  }
213
215
 
214
- export { RequestMapper, ResponseMapper };
216
+ declare function requestMapper<SV extends AnySchemaValidator, Dto extends IdiomaticSchema<SV>, Entity extends Constructor<BaseEntity>>(schemaValidator: SV, dtoSchema: Dto, toEntity: (dto: Schema<Dto, SV>) => Promise<Entity>): {
217
+ toEntity: (dto: Dto) => Promise<Entity>;
218
+ };
219
+
220
+ declare function responseMapper<SV extends AnySchemaValidator, Dto extends IdiomaticSchema<SV>, Entity extends Constructor<BaseEntity>>(schemaValidator: SV, dtoSchema: Dto, toDto: (entity: Entity) => Promise<Schema<Dto, SV>>): {
221
+ schema: Dto;
222
+ toDto: (entity: Entity) => Promise<Schema<Dto, SV>>;
223
+ };
224
+
225
+ export { RequestMapper, ResponseMapper, requestMapper, responseMapper };
@@ -1,4 +1,6 @@
1
- import { AnySchemaValidator, UnboxedObjectSchema, SchemaValidator, Schema } from '@forklaunch/validator';
1
+ import { AnySchemaValidator, UnboxedObjectSchema, SchemaValidator, Schema, IdiomaticSchema } from '@forklaunch/validator';
2
+ import { Constructor } from '@mikro-orm/core';
3
+ import { BaseEntity } from '../persistence/index.js';
2
4
 
3
5
  /**
4
6
  * Interface representing a constructor for an entity mapper.
@@ -211,4 +213,13 @@ declare abstract class ResponseMapper<Entity, SV extends AnySchemaValidator> ext
211
213
  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
214
  }
213
215
 
214
- export { RequestMapper, ResponseMapper };
216
+ declare function requestMapper<SV extends AnySchemaValidator, Dto extends IdiomaticSchema<SV>, Entity extends Constructor<BaseEntity>>(schemaValidator: SV, dtoSchema: Dto, toEntity: (dto: Schema<Dto, SV>) => Promise<Entity>): {
217
+ toEntity: (dto: Dto) => Promise<Entity>;
218
+ };
219
+
220
+ declare function responseMapper<SV extends AnySchemaValidator, Dto extends IdiomaticSchema<SV>, Entity extends Constructor<BaseEntity>>(schemaValidator: SV, dtoSchema: Dto, toDto: (entity: Entity) => Promise<Schema<Dto, SV>>): {
221
+ schema: Dto;
222
+ toDto: (entity: Entity) => Promise<Schema<Dto, SV>>;
223
+ };
224
+
225
+ export { RequestMapper, ResponseMapper, requestMapper, responseMapper };
@@ -21,7 +21,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var mappers_exports = {};
22
22
  __export(mappers_exports, {
23
23
  RequestMapper: () => RequestMapper,
24
- ResponseMapper: () => ResponseMapper
24
+ ResponseMapper: () => ResponseMapper,
25
+ requestMapper: () => requestMapper,
26
+ responseMapper: () => responseMapper
25
27
  });
26
28
  module.exports = __toCommonJS(mappers_exports);
27
29
 
@@ -235,9 +237,43 @@ var ResponseMapper = class extends BaseMapper {
235
237
  return result.then((r) => r.toDto());
236
238
  }
237
239
  };
240
+
241
+ // src/mappers/requestMapper.ts
242
+ var import_validator4 = require("@forklaunch/validator");
243
+ function requestMapper(schemaValidator, dtoSchema, toEntity) {
244
+ const sv = schemaValidator;
245
+ return {
246
+ toEntity: async (dto) => {
247
+ const parsedSchema = sv.parse(sv.schemify(dtoSchema), dto);
248
+ if (!parsedSchema.ok) {
249
+ throw new Error((0, import_validator4.prettyPrintParseErrors)(parsedSchema.errors, "DTO"));
250
+ }
251
+ return toEntity(dto);
252
+ }
253
+ };
254
+ }
255
+
256
+ // src/mappers/responseMapper.ts
257
+ var import_validator5 = require("@forklaunch/validator");
258
+ function responseMapper(schemaValidator, dtoSchema, toDto) {
259
+ const sv = schemaValidator;
260
+ return {
261
+ schema: dtoSchema,
262
+ toDto: async (entity) => {
263
+ const dto = await toDto(entity);
264
+ const parsedSchema = sv.parse(sv.schemify(dtoSchema), dto);
265
+ if (!parsedSchema.ok) {
266
+ throw new Error((0, import_validator5.prettyPrintParseErrors)(parsedSchema.errors, "DTO"));
267
+ }
268
+ return dto;
269
+ }
270
+ };
271
+ }
238
272
  // Annotate the CommonJS export names for ESM import in node:
239
273
  0 && (module.exports = {
240
274
  RequestMapper,
241
- ResponseMapper
275
+ ResponseMapper,
276
+ requestMapper,
277
+ responseMapper
242
278
  });
243
279
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
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;AAAA,MACxC,KAAK,gBAAgB,SAAS,KAAK,MAAM;AAAA,MACzC;AAAA,IACF;AACA,QAAI,CAAC,aAAa,IAAI;AACpB,YAAM,IAAI,UAAM,yCAAuB,aAAa,QAAQ,KAAK,CAAC;AAAA,IACpE;AACA,SAAK,OAAO;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,MAAoB;AACtB,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,OAAO,SAEQ;AACb,WAAO,UAAU,IAAI,EAAE;AAAA,EACzB;AACF;;;AD5FO,IAAe,gBAAf,cAGG,WAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMvB;AAAA;AAAA;AA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,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":["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","../../src/mappers/requestMapper.ts","../../src/mappers/responseMapper.ts"],"sourcesContent":["export * from './models/requestMapper.model';\nexport * from './models/responseMapper.model';\nexport * from './requestMapper';\nexport * from './responseMapper';\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","import {\n AnySchemaValidator,\n IdiomaticSchema,\n prettyPrintParseErrors,\n Schema,\n SchemaValidator\n} from '@forklaunch/validator';\nimport { Constructor } from '@mikro-orm/core';\nimport { BaseEntity } from '../persistence';\n\nexport function requestMapper<\n SV extends AnySchemaValidator,\n Dto extends IdiomaticSchema<SV>,\n Entity extends Constructor<BaseEntity>\n>(\n schemaValidator: SV,\n dtoSchema: Dto,\n toEntity: (dto: Schema<Dto, SV>) => Promise<Entity>\n) {\n const sv = schemaValidator as SchemaValidator;\n return {\n toEntity: async (dto: Dto) => {\n const parsedSchema = sv.parse(sv.schemify(dtoSchema), dto);\n if (!parsedSchema.ok) {\n throw new Error(prettyPrintParseErrors(parsedSchema.errors, 'DTO'));\n }\n return toEntity(dto as Schema<Dto, SV>);\n }\n };\n}\n","import {\n AnySchemaValidator,\n IdiomaticSchema,\n prettyPrintParseErrors,\n Schema,\n SchemaValidator\n} from '@forklaunch/validator';\nimport { Constructor } from '@mikro-orm/core';\nimport { BaseEntity } from '../persistence';\n\nexport function responseMapper<\n SV extends AnySchemaValidator,\n Dto extends IdiomaticSchema<SV>,\n Entity extends Constructor<BaseEntity>\n>(\n schemaValidator: SV,\n dtoSchema: Dto,\n toDto: (entity: Entity) => Promise<Schema<Dto, SV>>\n) {\n const sv = schemaValidator as SchemaValidator;\n return {\n schema: dtoSchema,\n toDto: async (entity: Entity) => {\n const dto = await toDto(entity);\n const parsedSchema = sv.parse(sv.schemify(dtoSchema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UAAI,CAAC,aAAa,IAAI;AACpB,cAAM,IAAI,UAAM,0CAAuB,aAAa,QAAQ,KAAK,CAAC;AAAA,MACpE;AACA,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":["import_validator","import_validator","import_validator","import_validator"]}
@@ -214,8 +214,46 @@ var ResponseMapper = class extends BaseMapper {
214
214
  return result.then((r) => r.toDto());
215
215
  }
216
216
  };
217
+
218
+ // src/mappers/requestMapper.ts
219
+ import {
220
+ prettyPrintParseErrors as prettyPrintParseErrors4
221
+ } from "@forklaunch/validator";
222
+ function requestMapper(schemaValidator, dtoSchema, toEntity) {
223
+ const sv = schemaValidator;
224
+ return {
225
+ toEntity: async (dto) => {
226
+ const parsedSchema = sv.parse(sv.schemify(dtoSchema), dto);
227
+ if (!parsedSchema.ok) {
228
+ throw new Error(prettyPrintParseErrors4(parsedSchema.errors, "DTO"));
229
+ }
230
+ return toEntity(dto);
231
+ }
232
+ };
233
+ }
234
+
235
+ // src/mappers/responseMapper.ts
236
+ import {
237
+ prettyPrintParseErrors as prettyPrintParseErrors5
238
+ } from "@forklaunch/validator";
239
+ function responseMapper(schemaValidator, dtoSchema, toDto) {
240
+ const sv = schemaValidator;
241
+ return {
242
+ schema: dtoSchema,
243
+ toDto: async (entity) => {
244
+ const dto = await toDto(entity);
245
+ const parsedSchema = sv.parse(sv.schemify(dtoSchema), dto);
246
+ if (!parsedSchema.ok) {
247
+ throw new Error(prettyPrintParseErrors5(parsedSchema.errors, "DTO"));
248
+ }
249
+ return dto;
250
+ }
251
+ };
252
+ }
217
253
  export {
218
254
  RequestMapper,
219
- ResponseMapper
255
+ ResponseMapper,
256
+ requestMapper,
257
+ responseMapper
220
258
  };
221
259
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
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;AAAA,IACpE;AACA,SAAK,OAAO;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,MAAoB;A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A;AAAA;AAAA;AAAA;AAAA,EAMvB;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","../../src/mappers/requestMapper.ts","../../src/mappers/responseMapper.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","import {\n AnySchemaValidator,\n IdiomaticSchema,\n prettyPrintParseErrors,\n Schema,\n SchemaValidator\n} from '@forklaunch/validator';\nimport { Constructor } from '@mikro-orm/core';\nimport { BaseEntity } from '../persistence';\n\nexport function requestMapper<\n SV extends AnySchemaValidator,\n Dto extends IdiomaticSchema<SV>,\n Entity extends Constructor<BaseEntity>\n>(\n schemaValidator: SV,\n dtoSchema: Dto,\n toEntity: (dto: Schema<Dto, SV>) => Promise<Entity>\n) {\n const sv = schemaValidator as SchemaValidator;\n return {\n toEntity: async (dto: Dto) => {\n const parsedSchema = sv.parse(sv.schemify(dtoSchema), dto);\n if (!parsedSchema.ok) {\n throw new Error(prettyPrintParseErrors(parsedSchema.errors, 'DTO'));\n }\n return toEntity(dto as Schema<Dto, SV>);\n }\n };\n}\n","import {\n AnySchemaValidator,\n IdiomaticSchema,\n prettyPrintParseErrors,\n Schema,\n SchemaValidator\n} from '@forklaunch/validator';\nimport { Constructor } from '@mikro-orm/core';\nimport { BaseEntity } from '../persistence';\n\nexport function responseMapper<\n SV extends AnySchemaValidator,\n Dto extends IdiomaticSchema<SV>,\n Entity extends Constructor<BaseEntity>\n>(\n schemaValidator: SV,\n dtoSchema: Dto,\n toDto: (entity: Entity) => Promise<Schema<Dto, SV>>\n) {\n const sv = schemaValidator as SchemaValidator;\n return {\n schema: dtoSchema,\n toDto: async (entity: Entity) => {\n const dto = await toDto(entity);\n const parsedSchema = sv.parse(sv.schemify(dtoSchema), dto);\n if (!parsedSchema.ok) {\n throw new Error(prettyPrintParseErrors(parsedSchema.errors, 'DTO'));\n }\n return dto;\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,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;AAAA,IACpE;AACA,SAAK,OAAO;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,MAAoB;AACtB,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,OAAO,SAEQ;AACb,WAAO,UAAU,IAAI,EAAE;AAAA,EACzB;AACF;;;AD5FO,IAAe,gBAAf,cAGG,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BAAAC;AAAA,OAGK;AAIA,SAAS,eAKd,iBACA,WACA,OACA;AACA,QAAM,KAAK;AACX,SAAO;AAAA,IACL,QAAQ;AAAA,IACR,OAAO,OAAO,WAAmB;AAC/B,YAAM,MAAM,MAAM,MAAM,MAAM;AAC9B,YAAM,eAAe,GAAG,MAAM,GAAG,SAAS,SAAS,GAAG,GAAG;AACzD,UAAI,CAAC,aAAa,IAAI;AACpB,cAAM,IAAI,MAAMA,wBAAuB,aAAa,QAAQ,KAAK,CAAC;AAAA,MACpE;AACA,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":["prettyPrintParseErrors","prettyPrintParseErrors","prettyPrintParseErrors","prettyPrintParseErrors","prettyPrintParseErrors","prettyPrintParseErrors"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forklaunch/core",
3
- "version": "0.13.8",
3
+ "version": "0.13.9",
4
4
  "description": "forklaunch-js core package. Contains useful building blocks.",
5
5
  "homepage": "https://github.com/forklaunch/forklaunch-js#readme",
6
6
  "bugs": {
@@ -66,8 +66,8 @@
66
66
  "dependencies": {
67
67
  "@forklaunch/fastmcp-fork": "^1.0.5",
68
68
  "@forklaunch/opentelemetry-instrumentation-hyper-express": "0.0.5",
69
- "@mikro-orm/core": "^6.4.16",
70
- "@mikro-orm/mongodb": "^6.4.16",
69
+ "@mikro-orm/core": "^6.5.1",
70
+ "@mikro-orm/mongodb": "^6.5.1",
71
71
  "@opentelemetry/api": "^1.9.0",
72
72
  "@opentelemetry/api-logs": "^0.203.0",
73
73
  "@opentelemetry/exporter-logs-otlp-http": "^0.203.0",
@@ -91,19 +91,19 @@
91
91
  "pino-pretty": "^13.1.1",
92
92
  "redis": "^5.8.2",
93
93
  "uuid": "^11.1.0",
94
- "@forklaunch/validator": "0.9.8",
95
- "@forklaunch/common": "0.5.7"
94
+ "@forklaunch/common": "0.5.8",
95
+ "@forklaunch/validator": "0.9.9"
96
96
  },
97
97
  "devDependencies": {
98
98
  "@eslint/js": "^9.34.0",
99
- "@scalar/express-api-reference": "^0.8.15",
99
+ "@scalar/express-api-reference": "^0.8.16",
100
100
  "@types/cors": "^2.8.19",
101
101
  "@types/jest": "^30.0.0",
102
102
  "@types/qs": "^6.14.0",
103
103
  "@types/uuid": "^10.0.0",
104
- "@typescript/native-preview": "7.0.0-dev.20250825.1",
104
+ "@typescript/native-preview": "7.0.0-dev.20250827.1",
105
105
  "globals": "^16.3.0",
106
- "jest": "^30.0.5",
106
+ "jest": "^30.1.1",
107
107
  "jose": "5.10.0",
108
108
  "prettier": "^3.6.2",
109
109
  "testcontainers": "^11.5.1",
@@ -112,7 +112,7 @@
112
112
  "tsup": "^8.5.0",
113
113
  "typedoc": "^0.28.11",
114
114
  "typescript": "^5.9.2",
115
- "typescript-eslint": "^8.40.0"
115
+ "typescript-eslint": "^8.41.0"
116
116
  },
117
117
  "scripts": {
118
118
  "build": "tsgo --noEmit && tsup ./src/cache/index.ts ./src/controllers/index.ts ./src/mappers/index.ts ./src/objectstore/index.ts ./src/persistence/index.ts ./src/http/index.ts ./src/services/index.ts --format cjs,esm --no-splitting --dts --tsconfig tsconfig.json --out-dir lib --clean --sourcemap",