@forklaunch/core 0.6.5 → 0.7.0

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.
Files changed (35) hide show
  1. package/lib/{openTelemetryCollector-CWrfzmmW.d.mts → openTelemetryCollector-CmZ3T_2T.d.mts} +9 -1
  2. package/lib/{openTelemetryCollector-CWrfzmmW.d.ts → openTelemetryCollector-CmZ3T_2T.d.ts} +9 -1
  3. package/lib/src/cache/index.d.mts +210 -24
  4. package/lib/src/cache/index.d.ts +210 -24
  5. package/lib/src/cache/index.js +364 -31
  6. package/lib/src/cache/index.js.map +1 -1
  7. package/lib/src/cache/index.mjs +374 -31
  8. package/lib/src/cache/index.mjs.map +1 -1
  9. package/lib/src/controllers/index.d.mts +10 -0
  10. package/lib/src/controllers/index.d.ts +10 -0
  11. package/lib/src/http/index.d.mts +51 -4
  12. package/lib/src/http/index.d.ts +51 -4
  13. package/lib/src/http/index.js +24 -1
  14. package/lib/src/http/index.js.map +1 -1
  15. package/lib/src/http/index.mjs +23 -1
  16. package/lib/src/http/index.mjs.map +1 -1
  17. package/lib/src/{dtoMapper → mappers}/index.d.mts +3 -3
  18. package/lib/src/{dtoMapper → mappers}/index.d.ts +3 -3
  19. package/lib/src/{dtoMapper → mappers}/index.js +12 -12
  20. package/lib/src/mappers/index.js.map +1 -0
  21. package/lib/src/{dtoMapper → mappers}/index.mjs +8 -8
  22. package/lib/src/mappers/index.mjs.map +1 -0
  23. package/lib/src/persistence/index.d.mts +120 -0
  24. package/lib/src/persistence/index.d.ts +120 -0
  25. package/lib/src/persistence/index.js +152 -0
  26. package/lib/src/persistence/index.js.map +1 -0
  27. package/lib/src/persistence/index.mjs +127 -0
  28. package/lib/src/persistence/index.mjs.map +1 -0
  29. package/lib/src/services/index.d.mts +3 -2
  30. package/lib/src/services/index.d.ts +3 -2
  31. package/lib/src/services/index.js.map +1 -1
  32. package/lib/src/services/index.mjs.map +1 -1
  33. package/package.json +15 -9
  34. package/lib/src/dtoMapper/index.js.map +0 -1
  35. package/lib/src/dtoMapper/index.mjs.map +0 -1
@@ -114,7 +114,7 @@ declare abstract class BaseDtoMapper<SV extends AnySchemaValidator> {
114
114
  /**
115
115
  * Abstract class representing a request entity mapper.
116
116
  *
117
- * @template Entity - A type that extends BaseEntity.
117
+ * @template Entity - A type that extends SqlBaseEntity.
118
118
  * @template SV - A type that extends AnySchemaValidator.
119
119
  * @extends {BaseDtoMapper<SV>}
120
120
  */
@@ -178,7 +178,7 @@ declare abstract class RequestDtoMapper<Entity, SV extends AnySchemaValidator> e
178
178
  /**
179
179
  * Abstract class representing a response entity mapper.
180
180
  *
181
- * @template Entity - A type that extends BaseEntity.
181
+ * @template Entity - A type that extends SqlBaseEntity.
182
182
  * @template SV - A type that extends AnySchemaValidator.
183
183
  * @extends {BaseDtoMapper<SV>}
184
184
  */
@@ -277,6 +277,6 @@ declare function transformIntoInternalDtoMapper<SchemaValidator extends AnySchem
277
277
  dto: unknown;
278
278
  _Entity: unknown;
279
279
  deserializeDtoToEntity: unknown;
280
- }>, Entities extends Record<keyof DtoMapper, unknown>, Dto extends Record<keyof DtoMapper, unknown>>(dtoMappers: DtoMapper, schemaValidator: SchemaValidator): InternalDtoMapper<InstanceTypeRecord<DtoMapper>, Entities, Dto>;
280
+ }>, Entities extends Record<keyof DtoMapper, unknown>, Dto extends Record<keyof DtoMapper, unknown>>(mapperss: DtoMapper, schemaValidator: SchemaValidator): InternalDtoMapper<InstanceTypeRecord<DtoMapper>, Entities, Dto>;
281
281
 
282
282
  export { type DtoMapperSchemaValidatorObject, type InternalDtoMapper, RequestDtoMapper, type RequestDtoMapperConstructor, ResponseDtoMapper, type ResponseDtoMapperConstructor, type SchemasByValidator, serviceSchemaResolver, transformIntoInternalDtoMapper };
@@ -114,7 +114,7 @@ declare abstract class BaseDtoMapper<SV extends AnySchemaValidator> {
114
114
  /**
115
115
  * Abstract class representing a request entity mapper.
116
116
  *
117
- * @template Entity - A type that extends BaseEntity.
117
+ * @template Entity - A type that extends SqlBaseEntity.
118
118
  * @template SV - A type that extends AnySchemaValidator.
119
119
  * @extends {BaseDtoMapper<SV>}
120
120
  */
@@ -178,7 +178,7 @@ declare abstract class RequestDtoMapper<Entity, SV extends AnySchemaValidator> e
178
178
  /**
179
179
  * Abstract class representing a response entity mapper.
180
180
  *
181
- * @template Entity - A type that extends BaseEntity.
181
+ * @template Entity - A type that extends SqlBaseEntity.
182
182
  * @template SV - A type that extends AnySchemaValidator.
183
183
  * @extends {BaseDtoMapper<SV>}
184
184
  */
@@ -277,6 +277,6 @@ declare function transformIntoInternalDtoMapper<SchemaValidator extends AnySchem
277
277
  dto: unknown;
278
278
  _Entity: unknown;
279
279
  deserializeDtoToEntity: unknown;
280
- }>, Entities extends Record<keyof DtoMapper, unknown>, Dto extends Record<keyof DtoMapper, unknown>>(dtoMappers: DtoMapper, schemaValidator: SchemaValidator): InternalDtoMapper<InstanceTypeRecord<DtoMapper>, Entities, Dto>;
280
+ }>, Entities extends Record<keyof DtoMapper, unknown>, Dto extends Record<keyof DtoMapper, unknown>>(mapperss: DtoMapper, schemaValidator: SchemaValidator): InternalDtoMapper<InstanceTypeRecord<DtoMapper>, Entities, Dto>;
281
281
 
282
282
  export { type DtoMapperSchemaValidatorObject, type InternalDtoMapper, RequestDtoMapper, type RequestDtoMapperConstructor, ResponseDtoMapper, type ResponseDtoMapperConstructor, type SchemasByValidator, serviceSchemaResolver, transformIntoInternalDtoMapper };
@@ -17,20 +17,20 @@ var __copyProps = (to, from, except, desc) => {
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
- // src/dtoMapper/index.ts
21
- var dtoMapper_exports = {};
22
- __export(dtoMapper_exports, {
20
+ // src/mappers/index.ts
21
+ var mappers_exports = {};
22
+ __export(mappers_exports, {
23
23
  RequestDtoMapper: () => RequestDtoMapper,
24
24
  ResponseDtoMapper: () => ResponseDtoMapper,
25
25
  serviceSchemaResolver: () => serviceSchemaResolver,
26
26
  transformIntoInternalDtoMapper: () => transformIntoInternalDtoMapper
27
27
  });
28
- module.exports = __toCommonJS(dtoMapper_exports);
28
+ module.exports = __toCommonJS(mappers_exports);
29
29
 
30
- // src/dtoMapper/models/requestDtoMapper.model.ts
30
+ // src/mappers/models/requestDtoMapper.model.ts
31
31
  var import_validator2 = require("@forklaunch/validator");
32
32
 
33
- // src/dtoMapper/models/baseDtoMapper.model.ts
33
+ // src/mappers/models/baseDtoMapper.model.ts
34
34
  var import_validator = require("@forklaunch/validator");
35
35
  function construct(self, schemaValidator) {
36
36
  return new self(schemaValidator || {});
@@ -98,7 +98,7 @@ var BaseDtoMapper = class {
98
98
  }
99
99
  };
100
100
 
101
- // src/dtoMapper/models/requestDtoMapper.model.ts
101
+ // src/mappers/models/requestDtoMapper.model.ts
102
102
  var RequestDtoMapper = class extends BaseDtoMapper {
103
103
  /**
104
104
  * The entity type.
@@ -164,7 +164,7 @@ var RequestDtoMapper = class extends BaseDtoMapper {
164
164
  }
165
165
  };
166
166
 
167
- // src/dtoMapper/models/responseDtoMapper.model.ts
167
+ // src/mappers/models/responseDtoMapper.model.ts
168
168
  var import_validator3 = require("@forklaunch/validator");
169
169
  var ResponseDtoMapper = class extends BaseDtoMapper {
170
170
  /**
@@ -231,7 +231,7 @@ var ResponseDtoMapper = class extends BaseDtoMapper {
231
231
  }
232
232
  };
233
233
 
234
- // src/dtoMapper/serviceSchemaResolver.ts
234
+ // src/mappers/serviceSchemaResolver.ts
235
235
  var import_common = require("@forklaunch/common");
236
236
  function serviceSchemaResolver(TypeBoxSchemas, ZodSchemas) {
237
237
  return (options) => {
@@ -251,10 +251,10 @@ function serviceSchemaResolver(TypeBoxSchemas, ZodSchemas) {
251
251
  };
252
252
  }
253
253
 
254
- // src/dtoMapper/transformIntoInternalDtoMappers.ts
255
- function transformIntoInternalDtoMapper(dtoMappers, schemaValidator) {
254
+ // src/mappers/transformIntoInternalDtoMapper.ts
255
+ function transformIntoInternalDtoMapper(mapperss, schemaValidator) {
256
256
  return Object.fromEntries(
257
- Object.entries(dtoMappers).map(([key, value]) => [
257
+ Object.entries(mapperss).map(([key, value]) => [
258
258
  key,
259
259
  new value(schemaValidator)
260
260
  ])
@@ -0,0 +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","../../../src/mappers/transformIntoInternalDtoMapper.ts"],"sourcesContent":["export * from './models/requestDtoMapper.model';\nexport * from './models/responseDtoMapper.model';\nexport * from './serviceSchemaResolver';\nexport * from './transformIntoInternalDtoMapper';\nexport * from './types/mappers.types';\nexport * from './types/internalDtoMapper.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 {Entity} - The entity.\n */\n abstract toEntity(...additionalArgs: unknown[]): Entity;\n\n /**\n * Populates the DTO with data from a JSON object.\n *\n * @param {this['_dto']} json - The JSON object.\n * @returns {this} - The instance of the RequestDtoMapper.\n */\n fromDto(json: this['_dto']): 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 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 ): Entity {\n return this.fromDto(json).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 >(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, json: JsonType): 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 ): T['_Entity'] {\n return construct(this, schemaValidator)\n .fromDto(json)\n .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> = {} as unknown as Schema<\n this['schema'],\n SV\n >;\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(entity: Entity, ...additionalArgs: unknown[]): 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(): 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 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 ): this['_dto'] {\n return this.fromEntity(entity, ...additionalArgs).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 ): 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 ): DtoType {\n return construct(this, schemaValidator)\n .fromEntity(entity, ...additionalArgs)\n .toDto() as 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","import { InstanceTypeRecord } from '@forklaunch/common';\nimport { AnySchemaValidator } from '@forklaunch/validator';\nimport { InternalDtoMapper } from './types/internalDtoMapper.types';\n\nexport function transformIntoInternalDtoMapper<\n SchemaValidator extends AnySchemaValidator,\n DtoMapper extends Record<\n string,\n new (schemaValidator: SchemaValidator) =>\n | {\n dto: unknown;\n _Entity: unknown;\n serializeEntityToDto: unknown;\n }\n | {\n dto: unknown;\n _Entity: unknown;\n deserializeDtoToEntity: unknown;\n }\n >,\n Entities extends Record<keyof DtoMapper, unknown>,\n Dto extends Record<keyof DtoMapper, unknown>\n>(\n mapperss: DtoMapper,\n schemaValidator: SchemaValidator\n): InternalDtoMapper<InstanceTypeRecord<DtoMapper>, Entities, Dto> {\n return Object.fromEntries(\n Object.entries(mapperss).map(([key, value]) => [\n key,\n new value(schemaValidator)\n ])\n ) as unknown as InternalDtoMapper<\n InstanceTypeRecord<DtoMapper>,\n Entities,\n Dto\n >;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,oBAGO;;;ACHP,u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ACL;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaA,OAAO,qBAML,oBACG,CAAC,QAAQ,GAAG,cAAc,GACpB;AACT,WAAO,UAAU,MAAM,eAAe,EACnC,WAAW,QAAQ,GAAG,cAAc,EACpC,MAAM;AAAA,EACX;AACF;;;ACjHA,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;;;ACrCO,SAAS,+BAmBd,UACA,iBACiE;AACjE,SAAO,OAAO;AAAA,IACZ,OAAO,QAAQ,QAAQ,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AAAA,MAC7C;AAAA,MACA,IAAI,MAAM,eAAe;AAAA,IAC3B,CAAC;AAAA,EACH;AAKF;","names":["import_validator","import_validator"]}
@@ -1,9 +1,9 @@
1
- // src/dtoMapper/models/requestDtoMapper.model.ts
1
+ // src/mappers/models/requestDtoMapper.model.ts
2
2
  import {
3
3
  prettyPrintParseErrors as prettyPrintParseErrors2
4
4
  } from "@forklaunch/validator";
5
5
 
6
- // src/dtoMapper/models/baseDtoMapper.model.ts
6
+ // src/mappers/models/baseDtoMapper.model.ts
7
7
  import {
8
8
  prettyPrintParseErrors
9
9
  } from "@forklaunch/validator";
@@ -73,7 +73,7 @@ var BaseDtoMapper = class {
73
73
  }
74
74
  };
75
75
 
76
- // src/dtoMapper/models/requestDtoMapper.model.ts
76
+ // src/mappers/models/requestDtoMapper.model.ts
77
77
  var RequestDtoMapper = class extends BaseDtoMapper {
78
78
  /**
79
79
  * The entity type.
@@ -139,7 +139,7 @@ var RequestDtoMapper = class extends BaseDtoMapper {
139
139
  }
140
140
  };
141
141
 
142
- // src/dtoMapper/models/responseDtoMapper.model.ts
142
+ // src/mappers/models/responseDtoMapper.model.ts
143
143
  import {
144
144
  prettyPrintParseErrors as prettyPrintParseErrors3
145
145
  } from "@forklaunch/validator";
@@ -208,7 +208,7 @@ var ResponseDtoMapper = class extends BaseDtoMapper {
208
208
  }
209
209
  };
210
210
 
211
- // src/dtoMapper/serviceSchemaResolver.ts
211
+ // src/mappers/serviceSchemaResolver.ts
212
212
  import { isNever } from "@forklaunch/common";
213
213
  function serviceSchemaResolver(TypeBoxSchemas, ZodSchemas) {
214
214
  return (options) => {
@@ -228,10 +228,10 @@ function serviceSchemaResolver(TypeBoxSchemas, ZodSchemas) {
228
228
  };
229
229
  }
230
230
 
231
- // src/dtoMapper/transformIntoInternalDtoMappers.ts
232
- function transformIntoInternalDtoMapper(dtoMappers, schemaValidator) {
231
+ // src/mappers/transformIntoInternalDtoMapper.ts
232
+ function transformIntoInternalDtoMapper(mapperss, schemaValidator) {
233
233
  return Object.fromEntries(
234
- Object.entries(dtoMappers).map(([key, value]) => [
234
+ Object.entries(mapperss).map(([key, value]) => [
235
235
  key,
236
236
  new value(schemaValidator)
237
237
  ])
@@ -0,0 +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","../../../src/mappers/transformIntoInternalDtoMapper.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 {Entity} - The entity.\n */\n abstract toEntity(...additionalArgs: unknown[]): Entity;\n\n /**\n * Populates the DTO with data from a JSON object.\n *\n * @param {this['_dto']} json - The JSON object.\n * @returns {this} - The instance of the RequestDtoMapper.\n */\n fromDto(json: this['_dto']): 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 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 ): Entity {\n return this.fromDto(json).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 >(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, json: JsonType): 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 ): T['_Entity'] {\n return construct(this, schemaValidator)\n .fromDto(json)\n .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> = {} as unknown as Schema<\n this['schema'],\n SV\n >;\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(entity: Entity, ...additionalArgs: unknown[]): 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(): 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 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 ): this['_dto'] {\n return this.fromEntity(entity, ...additionalArgs).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 ): 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 ): DtoType {\n return construct(this, schemaValidator)\n .fromEntity(entity, ...additionalArgs)\n .toDto() as 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","import { InstanceTypeRecord } from '@forklaunch/common';\nimport { AnySchemaValidator } from '@forklaunch/validator';\nimport { InternalDtoMapper } from './types/internalDtoMapper.types';\n\nexport function transformIntoInternalDtoMapper<\n SchemaValidator extends AnySchemaValidator,\n DtoMapper extends Record<\n string,\n new (schemaValidator: SchemaValidator) =>\n | {\n dto: unknown;\n _Entity: unknown;\n serializeEntityToDto: unknown;\n }\n | {\n dto: unknown;\n _Entity: unknown;\n deserializeDtoToEntity: unknown;\n }\n >,\n Entities extends Record<keyof DtoMapper, unknown>,\n Dto extends Record<keyof DtoMapper, unknown>\n>(\n mapperss: DtoMapper,\n schemaValidator: SchemaValidator\n): InternalDtoMapper<InstanceTypeRecord<DtoMapper>, Entities, Dto> {\n return Object.fromEntries(\n Object.entries(mapperss).map(([key, value]) => [\n key,\n new value(schemaValidator)\n ])\n ) as unknown as InternalDtoMapper<\n InstanceTypeRecord<DtoMapper>,\n Entities,\n Dto\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,OAAmC,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUpC,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;AAA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MACA,IAAI,MAAM,eAAe;AAAA,IAC3B,CAAC;AAAA,EACH;AAKF;","names":["prettyPrintParseErrors","prettyPrintParseErrors","prettyPrintParseErrors","prettyPrintParseErrors"]}
@@ -0,0 +1,120 @@
1
+ import { Collection, BaseEntity as BaseEntity$1, Constructor, EntityDTO, FromEntityType } from '@mikro-orm/core';
2
+
3
+ /**
4
+ * Type representing a marked collection of items.
5
+ * A marked collection is a wrapper around an array that indicates it should be treated as a collection.
6
+ *
7
+ * @template T - The type of items in the collection
8
+ * @property {true} _collection - Marker indicating this is a collection
9
+ * @property {T[]} items - The array of items in the collection
10
+ */
11
+ type MarkedCollection<T> = {
12
+ _collection: true;
13
+ items: T[];
14
+ };
15
+
16
+ /**
17
+ * Type representing the shape of data used to create an entity.
18
+ * Converts MikroORM collections to marked collections and omits entity properties.
19
+ *
20
+ * @template Entity - The base entity type
21
+ * @template T - The type being created
22
+ */
23
+ type CreateShape<Entity, T> = {
24
+ [K in keyof Omit<T, keyof Entity>]: T[K] extends Collection<infer U> ? MarkedCollection<U> : T[K];
25
+ };
26
+ /**
27
+ * Type representing the shape of data used to update an entity.
28
+ * Similar to CreateShape but makes all properties optional and includes an id field.
29
+ *
30
+ * @template Entity - The base entity type
31
+ * @template T - The type being updated
32
+ */
33
+ type UpdateShape<Entity, T> = Partial<CreateShape<Entity, T> & {
34
+ id: string;
35
+ }>;
36
+
37
+ /**
38
+ * Type representing a base entity with common fields.
39
+ * Extends BaseEntity with optional id, _id, createdAt, and updatedAt fields.
40
+ */
41
+ type BaseEntityWithId = BaseEntity & {
42
+ id?: unknown;
43
+ _id?: unknown;
44
+ createdAt?: unknown;
45
+ updatedAt?: unknown;
46
+ };
47
+ /**
48
+ * Abstract base class for all entities in the system.
49
+ * Extends MikroORM's BaseEntity and provides common CRUD operations.
50
+ */
51
+ declare abstract class BaseEntity extends BaseEntity$1 {
52
+ /**
53
+ * Static factory method to create a new entity instance.
54
+ *
55
+ * @template Entity - The type of entity being created
56
+ * @param {Constructor<Entity>} this - The entity constructor
57
+ * @param {...Parameters<Entity['create']>} args - Arguments for entity creation
58
+ * @returns {Entity} A new entity instance
59
+ */
60
+ static create<Entity extends BaseEntityWithId>(this: Constructor<Entity>, ...args: Parameters<Entity['create']>): Entity;
61
+ /**
62
+ * Static method to update an entity instance.
63
+ *
64
+ * @template Entity - The type of entity being updated
65
+ * @param {Constructor<Entity>} this - The entity constructor
66
+ * @param {...Parameters<Entity['update']>} args - Arguments for entity update
67
+ * @returns {Entity} The updated entity instance
68
+ */
69
+ static update<Entity extends BaseEntityWithId>(this: Constructor<Entity>, ...args: Parameters<Entity['update']>): Entity;
70
+ /**
71
+ * Static method to map data to an entity instance.
72
+ *
73
+ * @template Entity - The type of entity being mapped
74
+ * @param {Constructor<Entity>} this - The entity constructor
75
+ * @param {Partial<EntityDTO<FromEntityType<Entity>>>} data - The data to map
76
+ * @returns {Entity} A new entity instance with mapped data
77
+ */
78
+ static map<Entity extends BaseEntity>(this: Constructor<Entity>, data: Partial<EntityDTO<FromEntityType<Entity>>>): Entity;
79
+ /**
80
+ * Creates a new entity instance with the provided data.
81
+ *
82
+ * @param {CreateShape<BaseEntityWithId, this>} data - The data to create the entity with
83
+ * @returns {this} The created entity instance
84
+ */
85
+ create(data: CreateShape<BaseEntityWithId, this>): this;
86
+ /**
87
+ * Updates the entity instance with the provided data.
88
+ *
89
+ * @param {UpdateShape<BaseEntityWithId, this>} data - The data to update the entity with
90
+ * @returns {this} The updated entity instance
91
+ */
92
+ update(data: UpdateShape<BaseEntityWithId, this>): this;
93
+ /**
94
+ * Reads the entity data as a plain object.
95
+ *
96
+ * @returns {EntityDTO<this> | this} The entity data as a plain object
97
+ */
98
+ read(): EntityDTO<this> | this;
99
+ /**
100
+ * Maps data to the entity instance.
101
+ *
102
+ * @param {Partial<EntityDTO<FromEntityType<this>>>} data - The data to map
103
+ * @returns {this} The entity instance with mapped data
104
+ */
105
+ map(data: Partial<EntityDTO<FromEntityType<this>>>): this;
106
+ }
107
+
108
+ /**
109
+ * Creates a marked collection from an array of items.
110
+ * A marked collection is a wrapper around an array that indicates it should be treated as a collection.
111
+ *
112
+ * @template T - The type of items in the collection
113
+ * @param {T[]} items - The array of items to wrap in a collection
114
+ * @returns {MarkedCollection<T>} A marked collection containing the provided items
115
+ * @example
116
+ * const users = collection([{ id: 1, name: 'John' }, { id: 2, name: 'Jane' }]);
117
+ */
118
+ declare function collection<T>(items: T[]): MarkedCollection<T>;
119
+
120
+ export { BaseEntity, collection };
@@ -0,0 +1,120 @@
1
+ import { Collection, BaseEntity as BaseEntity$1, Constructor, EntityDTO, FromEntityType } from '@mikro-orm/core';
2
+
3
+ /**
4
+ * Type representing a marked collection of items.
5
+ * A marked collection is a wrapper around an array that indicates it should be treated as a collection.
6
+ *
7
+ * @template T - The type of items in the collection
8
+ * @property {true} _collection - Marker indicating this is a collection
9
+ * @property {T[]} items - The array of items in the collection
10
+ */
11
+ type MarkedCollection<T> = {
12
+ _collection: true;
13
+ items: T[];
14
+ };
15
+
16
+ /**
17
+ * Type representing the shape of data used to create an entity.
18
+ * Converts MikroORM collections to marked collections and omits entity properties.
19
+ *
20
+ * @template Entity - The base entity type
21
+ * @template T - The type being created
22
+ */
23
+ type CreateShape<Entity, T> = {
24
+ [K in keyof Omit<T, keyof Entity>]: T[K] extends Collection<infer U> ? MarkedCollection<U> : T[K];
25
+ };
26
+ /**
27
+ * Type representing the shape of data used to update an entity.
28
+ * Similar to CreateShape but makes all properties optional and includes an id field.
29
+ *
30
+ * @template Entity - The base entity type
31
+ * @template T - The type being updated
32
+ */
33
+ type UpdateShape<Entity, T> = Partial<CreateShape<Entity, T> & {
34
+ id: string;
35
+ }>;
36
+
37
+ /**
38
+ * Type representing a base entity with common fields.
39
+ * Extends BaseEntity with optional id, _id, createdAt, and updatedAt fields.
40
+ */
41
+ type BaseEntityWithId = BaseEntity & {
42
+ id?: unknown;
43
+ _id?: unknown;
44
+ createdAt?: unknown;
45
+ updatedAt?: unknown;
46
+ };
47
+ /**
48
+ * Abstract base class for all entities in the system.
49
+ * Extends MikroORM's BaseEntity and provides common CRUD operations.
50
+ */
51
+ declare abstract class BaseEntity extends BaseEntity$1 {
52
+ /**
53
+ * Static factory method to create a new entity instance.
54
+ *
55
+ * @template Entity - The type of entity being created
56
+ * @param {Constructor<Entity>} this - The entity constructor
57
+ * @param {...Parameters<Entity['create']>} args - Arguments for entity creation
58
+ * @returns {Entity} A new entity instance
59
+ */
60
+ static create<Entity extends BaseEntityWithId>(this: Constructor<Entity>, ...args: Parameters<Entity['create']>): Entity;
61
+ /**
62
+ * Static method to update an entity instance.
63
+ *
64
+ * @template Entity - The type of entity being updated
65
+ * @param {Constructor<Entity>} this - The entity constructor
66
+ * @param {...Parameters<Entity['update']>} args - Arguments for entity update
67
+ * @returns {Entity} The updated entity instance
68
+ */
69
+ static update<Entity extends BaseEntityWithId>(this: Constructor<Entity>, ...args: Parameters<Entity['update']>): Entity;
70
+ /**
71
+ * Static method to map data to an entity instance.
72
+ *
73
+ * @template Entity - The type of entity being mapped
74
+ * @param {Constructor<Entity>} this - The entity constructor
75
+ * @param {Partial<EntityDTO<FromEntityType<Entity>>>} data - The data to map
76
+ * @returns {Entity} A new entity instance with mapped data
77
+ */
78
+ static map<Entity extends BaseEntity>(this: Constructor<Entity>, data: Partial<EntityDTO<FromEntityType<Entity>>>): Entity;
79
+ /**
80
+ * Creates a new entity instance with the provided data.
81
+ *
82
+ * @param {CreateShape<BaseEntityWithId, this>} data - The data to create the entity with
83
+ * @returns {this} The created entity instance
84
+ */
85
+ create(data: CreateShape<BaseEntityWithId, this>): this;
86
+ /**
87
+ * Updates the entity instance with the provided data.
88
+ *
89
+ * @param {UpdateShape<BaseEntityWithId, this>} data - The data to update the entity with
90
+ * @returns {this} The updated entity instance
91
+ */
92
+ update(data: UpdateShape<BaseEntityWithId, this>): this;
93
+ /**
94
+ * Reads the entity data as a plain object.
95
+ *
96
+ * @returns {EntityDTO<this> | this} The entity data as a plain object
97
+ */
98
+ read(): EntityDTO<this> | this;
99
+ /**
100
+ * Maps data to the entity instance.
101
+ *
102
+ * @param {Partial<EntityDTO<FromEntityType<this>>>} data - The data to map
103
+ * @returns {this} The entity instance with mapped data
104
+ */
105
+ map(data: Partial<EntityDTO<FromEntityType<this>>>): this;
106
+ }
107
+
108
+ /**
109
+ * Creates a marked collection from an array of items.
110
+ * A marked collection is a wrapper around an array that indicates it should be treated as a collection.
111
+ *
112
+ * @template T - The type of items in the collection
113
+ * @param {T[]} items - The array of items to wrap in a collection
114
+ * @returns {MarkedCollection<T>} A marked collection containing the provided items
115
+ * @example
116
+ * const users = collection([{ id: 1, name: 'John' }, { id: 2, name: 'Jane' }]);
117
+ */
118
+ declare function collection<T>(items: T[]): MarkedCollection<T>;
119
+
120
+ export { BaseEntity, collection };
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/persistence/index.ts
21
+ var persistence_exports = {};
22
+ __export(persistence_exports, {
23
+ BaseEntity: () => BaseEntity2,
24
+ collection: () => collection
25
+ });
26
+ module.exports = __toCommonJS(persistence_exports);
27
+
28
+ // src/persistence/base.entity.ts
29
+ var import_common = require("@forklaunch/common");
30
+ var import_core2 = require("@mikro-orm/core");
31
+
32
+ // src/persistence/transformRawDto.ts
33
+ var import_core = require("@mikro-orm/core");
34
+
35
+ // src/persistence/guards/isMarkedCollection.ts
36
+ function isMarkedCollection(value) {
37
+ return typeof value === "object" && value !== null && "_collection" in value && typeof value._collection === "boolean" && value._collection;
38
+ }
39
+
40
+ // src/persistence/transformRawDto.ts
41
+ function transformRawDto(data, entity) {
42
+ const transformedObject = {};
43
+ for (const [key, value] of Object.entries(data)) {
44
+ if (isMarkedCollection(value)) {
45
+ transformedObject[key] = new import_core.Collection(entity, value.items);
46
+ } else {
47
+ transformedObject[key] = value;
48
+ }
49
+ }
50
+ return transformedObject;
51
+ }
52
+
53
+ // src/persistence/base.entity.ts
54
+ var BaseEntity2 = class extends import_core2.BaseEntity {
55
+ /**
56
+ * Static factory method to create a new entity instance.
57
+ *
58
+ * @template Entity - The type of entity being created
59
+ * @param {Constructor<Entity>} this - The entity constructor
60
+ * @param {...Parameters<Entity['create']>} args - Arguments for entity creation
61
+ * @returns {Entity} A new entity instance
62
+ */
63
+ static create(...args) {
64
+ const [data, ...additionalArgs] = args;
65
+ return new this().create(
66
+ data,
67
+ ...additionalArgs
68
+ );
69
+ }
70
+ /**
71
+ * Static method to update an entity instance.
72
+ *
73
+ * @template Entity - The type of entity being updated
74
+ * @param {Constructor<Entity>} this - The entity constructor
75
+ * @param {...Parameters<Entity['update']>} args - Arguments for entity update
76
+ * @returns {Entity} The updated entity instance
77
+ */
78
+ static update(...args) {
79
+ const [data, ...additionalArgs] = args;
80
+ return new this().update(
81
+ data,
82
+ ...additionalArgs
83
+ );
84
+ }
85
+ /**
86
+ * Static method to map data to an entity instance.
87
+ *
88
+ * @template Entity - The type of entity being mapped
89
+ * @param {Constructor<Entity>} this - The entity constructor
90
+ * @param {Partial<EntityDTO<FromEntityType<Entity>>>} data - The data to map
91
+ * @returns {Entity} A new entity instance with mapped data
92
+ */
93
+ static map(data) {
94
+ return new this().map(data);
95
+ }
96
+ /**
97
+ * Creates a new entity instance with the provided data.
98
+ *
99
+ * @param {CreateShape<BaseEntityWithId, this>} data - The data to create the entity with
100
+ * @returns {this} The created entity instance
101
+ */
102
+ create(data) {
103
+ return Object.assign(this, transformRawDto(data, this));
104
+ }
105
+ /**
106
+ * Updates the entity instance with the provided data.
107
+ *
108
+ * @param {UpdateShape<BaseEntityWithId, this>} data - The data to update the entity with
109
+ * @returns {this} The updated entity instance
110
+ */
111
+ update(data) {
112
+ (0, import_core2.wrap)(this).assign(
113
+ (0, import_common.stripUndefinedProperties)(transformRawDto(data, this))
114
+ );
115
+ return this;
116
+ }
117
+ /**
118
+ * Reads the entity data as a plain object.
119
+ *
120
+ * @returns {EntityDTO<this> | this} The entity data as a plain object
121
+ */
122
+ read() {
123
+ if (typeof (0, import_core2.wrap)(this).toPOJO === "function") {
124
+ return (0, import_core2.wrap)(this).toPOJO();
125
+ }
126
+ return this;
127
+ }
128
+ /**
129
+ * Maps data to the entity instance.
130
+ *
131
+ * @param {Partial<EntityDTO<FromEntityType<this>>>} data - The data to map
132
+ * @returns {this} The entity instance with mapped data
133
+ */
134
+ map(data) {
135
+ (0, import_core2.wrap)(this).assign(data);
136
+ return this;
137
+ }
138
+ };
139
+
140
+ // src/persistence/collection.ts
141
+ function collection(items) {
142
+ return {
143
+ _collection: true,
144
+ items
145
+ };
146
+ }
147
+ // Annotate the CommonJS export names for ESM import in node:
148
+ 0 && (module.exports = {
149
+ BaseEntity,
150
+ collection
151
+ });
152
+ //# sourceMappingURL=index.js.map