plutin 1.1.0 → 1.1.2

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 (72) hide show
  1. package/dist/{base-controller-cec5714c.d.ts → base-controller-68008870.d.ts} +1 -1
  2. package/dist/core/decorators/controller-http-decorator.cjs.map +1 -1
  3. package/dist/core/decorators/controller-http-decorator.d.cts +1 -1
  4. package/dist/core/decorators/controller-http-decorator.d.ts +1 -1
  5. package/dist/core/decorators/controller-http-decorator.js.map +1 -1
  6. package/dist/core/decorators/dependency-container.cjs +3 -2
  7. package/dist/core/decorators/dependency-container.cjs.map +1 -1
  8. package/dist/core/decorators/dependency-container.d.cts +1 -1
  9. package/dist/core/decorators/dependency-container.d.ts +1 -1
  10. package/dist/core/decorators/dependency-container.js +2 -2
  11. package/dist/core/decorators/dependency-container.js.map +1 -1
  12. package/dist/core/entities/aggregate-root.cjs.map +1 -1
  13. package/dist/core/entities/aggregate-root.d.cts +2 -2
  14. package/dist/core/entities/aggregate-root.d.ts +2 -2
  15. package/dist/core/entities/aggregate-root.js.map +1 -1
  16. package/dist/core/entities/common-dto.cjs.map +1 -1
  17. package/dist/core/entities/common-dto.d.cts +2 -2
  18. package/dist/core/entities/common-dto.d.ts +2 -2
  19. package/dist/core/entities/entity.cjs.map +1 -1
  20. package/dist/core/entities/entity.d.cts +4 -3
  21. package/dist/core/entities/entity.d.ts +4 -3
  22. package/dist/core/entities/entity.js.map +1 -1
  23. package/dist/core/http/base-controller.cjs +5 -1
  24. package/dist/core/http/base-controller.cjs.map +1 -1
  25. package/dist/core/http/base-controller.d.cts +1 -1
  26. package/dist/core/http/base-controller.d.ts +1 -1
  27. package/dist/core/http/base-controller.js +1 -1
  28. package/dist/core/http/base-controller.js.map +1 -1
  29. package/dist/core/http/error-notifier.d.cts +1 -1
  30. package/dist/core/http/error-notifier.d.ts +1 -1
  31. package/dist/core/http/http.cjs.map +1 -1
  32. package/dist/core/http/http.d.cts +1 -1
  33. package/dist/core/http/http.d.ts +1 -1
  34. package/dist/index.cjs +23 -0
  35. package/dist/index.cjs.map +1 -1
  36. package/dist/index.d.cts +4 -2
  37. package/dist/index.d.ts +4 -2
  38. package/dist/index.js +19 -0
  39. package/dist/index.js.map +1 -1
  40. package/dist/infra/adapters/http/express-adapter.cjs.map +1 -1
  41. package/dist/infra/adapters/http/express-adapter.d.cts +1 -1
  42. package/dist/infra/adapters/http/express-adapter.d.ts +1 -1
  43. package/dist/infra/adapters/http/express-adapter.js.map +1 -1
  44. package/dist/infra/adapters/http/fastify-adapter.cjs.map +1 -1
  45. package/dist/infra/adapters/http/fastify-adapter.d.cts +1 -1
  46. package/dist/infra/adapters/http/fastify-adapter.d.ts +1 -1
  47. package/dist/infra/adapters/http/fastify-adapter.js.map +1 -1
  48. package/dist/infra/adapters/http/validate-controller-metadata.cjs.map +1 -1
  49. package/dist/infra/adapters/http/validate-controller-metadata.d.cts +1 -1
  50. package/dist/infra/adapters/http/validate-controller-metadata.d.ts +1 -1
  51. package/dist/infra/adapters/http/validate-controller-metadata.js.map +1 -1
  52. package/dist/infra/adapters/notifications/discord.cjs +5 -1
  53. package/dist/infra/adapters/notifications/discord.cjs.map +1 -1
  54. package/dist/infra/adapters/notifications/discord.d.cts +2 -2
  55. package/dist/infra/adapters/notifications/discord.d.ts +2 -2
  56. package/dist/infra/adapters/notifications/discord.js +1 -1
  57. package/dist/infra/adapters/notifications/discord.js.map +1 -1
  58. package/dist/infra/adapters/notifications/in-memory.cjs +5 -1
  59. package/dist/infra/adapters/notifications/in-memory.cjs.map +1 -1
  60. package/dist/infra/adapters/notifications/in-memory.d.cts +2 -2
  61. package/dist/infra/adapters/notifications/in-memory.d.ts +2 -2
  62. package/dist/infra/adapters/notifications/in-memory.js +1 -1
  63. package/dist/infra/adapters/notifications/in-memory.js.map +1 -1
  64. package/dist/infra/adapters/notifications/sentry.cjs.map +1 -1
  65. package/dist/infra/adapters/notifications/sentry.d.cts +1 -1
  66. package/dist/infra/adapters/notifications/sentry.d.ts +1 -1
  67. package/dist/infra/adapters/notifications/sentry.js.map +1 -1
  68. package/dist/infra/adapters/validators/zod/index.d.cts +1 -1
  69. package/dist/infra/adapters/validators/zod/index.d.ts +1 -1
  70. package/dist/infra/adapters/validators/zod/zod-validator.d.cts +1 -1
  71. package/dist/infra/adapters/validators/zod/zod-validator.d.ts +1 -1
  72. package/package.json +1 -1
@@ -43,4 +43,4 @@ declare abstract class BaseController {
43
43
  execute(request: Request): Promise<Response>;
44
44
  }
45
45
 
46
- export { AnyObject as A, BaseController as B, ContextError as C, IErrorNotifier as I, Request as R, Response as a };
46
+ export { BaseController as B, ContextError as C, IErrorNotifier as I, Request as R, Response as a };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/core/decorators/controller-http-decorator.ts","../../../src/core/http/base-controller.ts","../../../src/core/decorators/dependency-container.ts","../../../src/core/errors/api-common-error.ts","../../../src/core/errors/application-error.ts","../../../src/core/errors/conflict-error.ts","../../../src/core/errors/domain-error.ts","../../../src/core/errors/infra-error.ts","../../../src/core/errors/validation-error.ts"],"sourcesContent":["import { MiddlewareFunction } from '../../infra/adapters/validators/zod/zod-validator'\nimport BaseController from '../http/base-controller'\nimport type { MethodType } from '../http/http'\n\ntype Props = {\n method: MethodType\n path: string\n middlewares?: MiddlewareFunction[]\n}\n\nexport function Controller({\n method,\n path,\n middlewares = [],\n}: Props): ClassDecorator {\n return (target: any) => {\n if (!(target.prototype instanceof BaseController)) {\n throw new Error(\n `The class ${target.name} should extends abstract class BaseController`\n )\n }\n\n Reflect.defineMetadata(\n 'route',\n { method, path: `/api/${path}`, middlewares },\n target\n )\n }\n}\n","import 'reflect-metadata'\n\nimport DependencyContainer from '../../core/decorators/dependency-container'\nimport ApplicationError from '../../core/errors/application-error'\nimport ConflictError from '../../core/errors/conflict-error'\nimport DomainError from '../../core/errors/domain-error'\nimport InfraError from '../../core/errors/infra-error'\nimport ValidationError from '../../core/errors/validation-error'\nimport { MiddlewareFunction } from '../../infra/adapters/validators/zod/zod-validator'\nimport IErrorNotifier from './error-notifier'\n\nexport type AnyObject = Record<string, any>\n\nexport type Request = {\n body: AnyObject\n params: AnyObject\n headers: AnyObject\n query: AnyObject\n}\n\nexport type Response = {\n code: number\n data: any\n}\n\nexport type ContextError = {\n env: string\n user?: {\n id?: string\n name?: string\n email?: string\n }\n request?: {\n method?: string\n requestId?: string\n url?: string\n headers?: any\n query?: any\n body?: any\n params?: any\n }\n}\n\nexport default abstract class BaseController {\n protected readonly errorNotifier: IErrorNotifier\n\n abstract handle<T>(request: T | Request): Promise<Response>\n\n constructor() {\n this.errorNotifier = DependencyContainer.resolveToken('IErrorNotifier')\n }\n\n protected success<T>(dto?: T): Response {\n return {\n code: 200,\n data: { data: dto },\n }\n }\n\n protected noContent(): Response {\n return {\n code: 204,\n data: undefined,\n }\n }\n\n protected created<T>(dto?: T): Response {\n return {\n code: 201,\n data: dto ? { data: dto } : undefined,\n }\n }\n\n protected paginated<T>(dto?: T): Response {\n return {\n code: 200,\n data: dto,\n }\n }\n\n protected buildContextError(request: Request): ContextError {\n return {\n env: process.env.ENVIRONMENT as string,\n request: {\n body: request.body,\n headers: request.headers,\n params: request.params,\n query: request.query,\n },\n }\n }\n\n public async failure(error: Error, context: ContextError): Promise<Response> {\n if (error instanceof ConflictError) {\n return {\n code: error.props.code,\n data: {\n message: error.message,\n errorCode: error.props.errorCode,\n occurredAt: error.props.occurredAt,\n items: Array.isArray(error.conflictProps)\n ? error.conflictProps\n : [error.conflictProps],\n },\n }\n }\n\n if (\n error instanceof DomainError ||\n error instanceof ApplicationError ||\n error instanceof InfraError\n ) {\n return {\n code: error.props.code,\n data: {\n message: error.message,\n errorCode: error.props.errorCode,\n occurredAt: error.props.occurredAt,\n },\n }\n }\n\n if (error instanceof ValidationError) {\n return {\n code: error.props.code,\n data: {\n message: error.props.message,\n errorCode: error.props.errorCode,\n occurredAt: error.props.occurredAt,\n errors: error.props.errors,\n },\n }\n }\n\n if (process.env.SHOULD_NOTIFY_ERROR) {\n await this.errorNotifier.notify(error, context)\n }\n\n return {\n code: 500,\n data: {\n code: 500,\n message: 'Server failed. Contact the administrator!',\n },\n }\n }\n\n public async execute(request: Request): Promise<Response> {\n const routeMetadata = Reflect.getMetadata('route', this.constructor)\n\n if (!routeMetadata) {\n throw new InfraError('Route metadata not found.')\n }\n\n const middlewares: MiddlewareFunction[] = routeMetadata.middlewares || []\n\n let processedRequest = request\n\n if (middlewares.length) {\n for (const middleware of middlewares) {\n processedRequest = await middleware(processedRequest)\n }\n }\n\n return await this.handle(processedRequest)\n }\n}\n","import 'reflect-metadata'\n\ntype Class<T = any> = new (...args: any[]) => T\n\ntype Registration =\n | { type: 'class'; myClass: Class; singleton: boolean }\n | { type: 'value'; value: any }\n\nexport default class DependencyContainer {\n static registry = new Map<string, Registration>()\n static singletons = new Map<string, any>()\n\n static register<T>(\n token: string,\n myClass: Class<T>,\n options: { singleton: boolean }\n ) {\n this.registry.set(token, {\n type: 'class',\n myClass,\n singleton: options.singleton,\n })\n }\n\n static registerValue<T>(token: string, value: T) {\n this.registry.set(token, { type: 'value', value })\n }\n\n static resolve<T>(target: Class<T>): T {\n const paramTypes = Reflect.getMetadata('design:paramtypes', target) || []\n\n const injectMetadata: Record<number, string> =\n Reflect.getOwnMetadata('inject:params', target) || {}\n\n const params = paramTypes.map((_: any, index: number) => {\n const token = injectMetadata[index]\n\n if (!token) {\n throw new Error(\n `Missing @Inject token for parameter index ${index} in ${target.name}`\n )\n }\n\n return this.resolveToken(token)\n })\n\n return new target(...params)\n }\n\n static resolveToken(token: string): any {\n const registration = this.registry.get(token)\n\n if (!registration) {\n throw new Error(\n `\"${token}\" not registered. Please register it in the container.`\n )\n }\n\n if (registration.type === 'value') {\n return registration.value\n }\n\n const { myClass, singleton } = registration\n\n if (singleton) {\n if (!this.singletons.has(token)) {\n const instance = this.resolve(myClass)\n this.singletons.set(token, instance)\n }\n return this.singletons.get(token)\n }\n\n return this.resolve(myClass)\n }\n}\n\nexport function Inject(token: string): ParameterDecorator {\n return (\n target: object,\n _propertyKey: string | symbol | undefined,\n parameterIndex: number\n ): void => {\n const constructor =\n typeof target === 'function' ? target : target.constructor\n\n const existingInjectedParams: Record<number, string> =\n Reflect.getOwnMetadata('inject:params', constructor) || {}\n\n existingInjectedParams[parameterIndex] = token\n\n Reflect.defineMetadata('inject:params', existingInjectedParams, constructor)\n }\n}\n","export type PropertiesError = {\n receivedValue?: any\n type: string\n message: string\n property: string | number | undefined\n propertyType?: string\n path?: string\n}\n\nexport type CommonError = {\n location: string\n propertyErrors?: PropertiesError[]\n}\n\nexport type ApiCommonError = {\n code: number\n occurredAt: Date\n message: string\n errorCode: string\n errors?: CommonError[]\n}\n\nexport enum ApiErrorEnum {\n DOMAIN = 'ERR001',\n APPLICATION = 'ERR002',\n INFRA = 'ERR003',\n HTTP_CLIENT = 'ERR004',\n VALIDATOR = 'ERR005',\n}\n","import { type ApiCommonError, ApiErrorEnum } from './api-common-error'\n\nexport default class ApplicationError extends Error {\n props: ApiCommonError\n\n constructor(message: string) {\n super(message)\n this.props = {\n code: 400,\n errorCode: ApiErrorEnum.APPLICATION,\n message,\n occurredAt: new Date(),\n }\n }\n}\n","import { type ApiCommonError, ApiErrorEnum } from './api-common-error'\n\ntype ConflictProps = { id: string; [key: string]: unknown }\n\nexport default class ConflictError<T extends ConflictProps> extends Error {\n props: ApiCommonError\n conflictProps: T | T[]\n\n constructor(conflictProps: T | T[]) {\n super('Resource already exists.')\n this.conflictProps = conflictProps\n this.props = {\n code: 409,\n errorCode: ApiErrorEnum.APPLICATION,\n message: this.message,\n occurredAt: new Date(),\n }\n }\n}\n","import { type ApiCommonError, ApiErrorEnum } from './api-common-error'\n\nexport default class DomainError extends Error {\n props: ApiCommonError\n\n constructor(message: string) {\n super(message)\n this.props = {\n code: 400,\n errorCode: ApiErrorEnum.DOMAIN,\n message,\n occurredAt: new Date(),\n }\n }\n}\n","import { type ApiCommonError, ApiErrorEnum } from './api-common-error'\n\nexport default class InfraError extends Error {\n props: ApiCommonError\n\n constructor(message: string) {\n super(message)\n this.props = {\n code: 400,\n errorCode: ApiErrorEnum.INFRA,\n message,\n occurredAt: new Date(),\n }\n }\n}\n","import {\n type ApiCommonError,\n ApiErrorEnum,\n type CommonError,\n} from './api-common-error'\n\nexport default class ValidationError extends Error {\n props: ApiCommonError\n\n constructor(errors: CommonError[]) {\n super('Validation Error')\n this.props = {\n code: 400,\n errorCode: ApiErrorEnum.VALIDATOR,\n message: 'Validation Error',\n occurredAt: new Date(),\n errors,\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA;;;;;;;ACDA,IAAAA,2BAAO;;;ACAP,8BAAO;AAQP,IAAqBC,sBAArB,MAAqBA;EARrB,OAQqBA;;;EACnB,OAAOC,WAAW,oBAAIC,IAAAA;EACtB,OAAOC,aAAa,oBAAID,IAAAA;EAExB,OAAOE,SACLC,OACAC,SACAC,SACA;AACA,SAAKN,SAASO,IAAIH,OAAO;MACvBI,MAAM;MACNH;MACAI,WAAWH,QAAQG;IACrB,CAAA;EACF;EAEA,OAAOC,cAAiBN,OAAeO,OAAU;AAC/C,SAAKX,SAASO,IAAIH,OAAO;MAAEI,MAAM;MAASG;IAAM,CAAA;EAClD;EAEA,OAAOC,QAAWC,QAAqB;AACrC,UAAMC,aAAaC,QAAQC,YAAY,qBAAqBH,MAAAA,KAAW,CAAA;AAEvE,UAAMI,iBACJF,QAAQG,eAAe,iBAAiBL,MAAAA,KAAW,CAAC;AAEtD,UAAMM,SAASL,WAAWM,IAAI,CAACC,GAAQC,UAAAA;AACrC,YAAMlB,QAAQa,eAAeK,KAAAA;AAE7B,UAAI,CAAClB,OAAO;AACV,cAAM,IAAImB,MACR,6CAA6CD,KAAAA,OAAYT,OAAOW,IAAI,EAAE;MAE1E;AAEA,aAAO,KAAKC,aAAarB,KAAAA;IAC3B,CAAA;AAEA,WAAO,IAAIS,OAAAA,GAAUM,MAAAA;EACvB;EAEA,OAAOM,aAA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BAAiB;AACjD,YAAM,IAAIC,MACR,aAAaH,OAAOI,IAAI,+CAA+C;IAE3E;AAEAC,YAAQC,eACN,SACA;MAAET;MAAQC,MAAM,QAAQA,IAAAA;MAAQC;IAAY,GAC5CC,MAAAA;EAEJ;AACF;AAlBgBJ;","names":["import_reflect_metadata","DependencyContainer","registry","Map","singletons","register","token","myClass","options","set","type","singleton","registerValue","value","resolve","target","paramTypes","Reflect","getMetadata","injectMetadata","getOwnMetadata","params","map","_","index","Error","name","resolveToken","registration","get","has","instance","ApiErrorEnum","ApplicationError","Error","props","constructor","message","code","errorCode","ApiErrorEnum","APPLICATION","occurredAt","Date","ConflictError","Error","props","conflictProps","constructor","code","errorCode","ApiErrorEnum","APPLICATION","message","occurredAt","Date","DomainError","Error","props","constructor","message","code","errorCode","ApiErrorEnum","DOMAIN","occurredAt","Date","InfraError","Error","props","constructor","message","code","errorCode","ApiErrorEnum","INFRA","occurredAt","Date","ValidationError","Error","props","constructor","errors","code","errorCode","ApiErrorEnum","VALIDATOR","message","occurredAt","Date","BaseController","errorNotifier","constructor","DependencyContainer","resolveToken","success","dto","code","data","noContent","undefined","created","paginated","buildContextError","request","env","process","ENVIRONMENT","body","headers","params","query","failure","error","context","ConflictError","props","message","errorCode","occurredAt","items","Array","isArray","conflictProps","DomainError","ApplicationError","InfraError","ValidationError","errors","SHOULD_NOTIFY_ERROR","notify","execute","routeMetadata","Reflect","getMetadata","middlewares","processedRequest","length","middleware","handle","Controller","method","path","middlewares","target","prototype","BaseController","Error","name","Reflect","defineMetadata"]}
1
+ {"version":3,"sources":["../../../src/core/decorators/controller-http-decorator.ts","../../../src/core/http/base-controller.ts","../../../src/core/decorators/dependency-container.ts","../../../src/core/errors/api-common-error.ts","../../../src/core/errors/application-error.ts","../../../src/core/errors/conflict-error.ts","../../../src/core/errors/domain-error.ts","../../../src/core/errors/infra-error.ts","../../../src/core/errors/validation-error.ts"],"sourcesContent":["import { MiddlewareFunction } from '../../infra/adapters/validators/zod/zod-validator'\nimport { BaseController } from '../http/base-controller'\nimport type { MethodType } from '../http/http'\n\ntype Props = {\n method: MethodType\n path: string\n middlewares?: MiddlewareFunction[]\n}\n\nexport function Controller({\n method,\n path,\n middlewares = [],\n}: Props): ClassDecorator {\n return (target: any) => {\n if (!(target.prototype instanceof BaseController)) {\n throw new Error(\n `The class ${target.name} should extends abstract class BaseController`\n )\n }\n\n Reflect.defineMetadata(\n 'route',\n { method, path: `/api/${path}`, middlewares },\n target\n )\n }\n}\n","import 'reflect-metadata'\n\nimport { DependencyContainer } from '../../core/decorators/dependency-container'\nimport ApplicationError from '../../core/errors/application-error'\nimport ConflictError from '../../core/errors/conflict-error'\nimport DomainError from '../../core/errors/domain-error'\nimport InfraError from '../../core/errors/infra-error'\nimport ValidationError from '../../core/errors/validation-error'\nimport { MiddlewareFunction } from '../../infra/adapters/validators/zod/zod-validator'\nimport IErrorNotifier from './error-notifier'\n\ntype AnyObject = Record<string, any>\n\nexport type Request = {\n body: AnyObject\n params: AnyObject\n headers: AnyObject\n query: AnyObject\n}\n\nexport type Response = {\n code: number\n data: any\n}\n\nexport type ContextError = {\n env: string\n user?: {\n id?: string\n name?: string\n email?: string\n }\n request?: {\n method?: string\n requestId?: string\n url?: string\n headers?: any\n query?: any\n body?: any\n params?: any\n }\n}\n\nexport abstract class BaseController {\n protected readonly errorNotifier: IErrorNotifier\n\n abstract handle<T>(request: T | Request): Promise<Response>\n\n constructor() {\n this.errorNotifier = DependencyContainer.resolveToken('IErrorNotifier')\n }\n\n protected success<T>(dto?: T): Response {\n return {\n code: 200,\n data: { data: dto },\n }\n }\n\n protected noContent(): Response {\n return {\n code: 204,\n data: undefined,\n }\n }\n\n protected created<T>(dto?: T): Response {\n return {\n code: 201,\n data: dto ? { data: dto } : undefined,\n }\n }\n\n protected paginated<T>(dto?: T): Response {\n return {\n code: 200,\n data: dto,\n }\n }\n\n protected buildContextError(request: Request): ContextError {\n return {\n env: process.env.ENVIRONMENT as string,\n request: {\n body: request.body,\n headers: request.headers,\n params: request.params,\n query: request.query,\n },\n }\n }\n\n public async failure(error: Error, context: ContextError): Promise<Response> {\n if (error instanceof ConflictError) {\n return {\n code: error.props.code,\n data: {\n message: error.message,\n errorCode: error.props.errorCode,\n occurredAt: error.props.occurredAt,\n items: Array.isArray(error.conflictProps)\n ? error.conflictProps\n : [error.conflictProps],\n },\n }\n }\n\n if (\n error instanceof DomainError ||\n error instanceof ApplicationError ||\n error instanceof InfraError\n ) {\n return {\n code: error.props.code,\n data: {\n message: error.message,\n errorCode: error.props.errorCode,\n occurredAt: error.props.occurredAt,\n },\n }\n }\n\n if (error instanceof ValidationError) {\n return {\n code: error.props.code,\n data: {\n message: error.props.message,\n errorCode: error.props.errorCode,\n occurredAt: error.props.occurredAt,\n errors: error.props.errors,\n },\n }\n }\n\n if (process.env.SHOULD_NOTIFY_ERROR) {\n await this.errorNotifier.notify(error, context)\n }\n\n return {\n code: 500,\n data: {\n code: 500,\n message: 'Server failed. Contact the administrator!',\n },\n }\n }\n\n public async execute(request: Request): Promise<Response> {\n const routeMetadata = Reflect.getMetadata('route', this.constructor)\n\n if (!routeMetadata) {\n throw new InfraError('Route metadata not found.')\n }\n\n const middlewares: MiddlewareFunction[] = routeMetadata.middlewares || []\n\n let processedRequest = request\n\n if (middlewares.length) {\n for (const middleware of middlewares) {\n processedRequest = await middleware(processedRequest)\n }\n }\n\n return await this.handle(processedRequest)\n }\n}\n","import 'reflect-metadata'\n\ntype Class<T = any> = new (...args: any[]) => T\n\ntype Registration =\n | { type: 'class'; myClass: Class; singleton: boolean }\n | { type: 'value'; value: any }\n\nexport class DependencyContainer {\n static registry = new Map<string, Registration>()\n static singletons = new Map<string, any>()\n\n static register<T>(\n token: string,\n myClass: Class<T>,\n options: { singleton: boolean }\n ) {\n this.registry.set(token, {\n type: 'class',\n myClass,\n singleton: options.singleton,\n })\n }\n\n static registerValue<T>(token: string, value: T) {\n this.registry.set(token, { type: 'value', value })\n }\n\n static resolve<T>(target: Class<T>): T {\n const paramTypes = Reflect.getMetadata('design:paramtypes', target) || []\n\n const injectMetadata: Record<number, string> =\n Reflect.getOwnMetadata('inject:params', target) || {}\n\n const params = paramTypes.map((_: any, index: number) => {\n const token = injectMetadata[index]\n\n if (!token) {\n throw new Error(\n `Missing @Inject token for parameter index ${index} in ${target.name}`\n )\n }\n\n return this.resolveToken(token)\n })\n\n return new target(...params)\n }\n\n static resolveToken(token: string): any {\n const registration = this.registry.get(token)\n\n if (!registration) {\n throw new Error(\n `\"${token}\" not registered. Please register it in the container.`\n )\n }\n\n if (registration.type === 'value') {\n return registration.value\n }\n\n const { myClass, singleton } = registration\n\n if (singleton) {\n if (!this.singletons.has(token)) {\n const instance = this.resolve(myClass)\n this.singletons.set(token, instance)\n }\n return this.singletons.get(token)\n }\n\n return this.resolve(myClass)\n }\n}\n\nexport function Inject(token: string): ParameterDecorator {\n return (\n target: object,\n _propertyKey: string | symbol | undefined,\n parameterIndex: number\n ): void => {\n const constructor =\n typeof target === 'function' ? target : target.constructor\n\n const existingInjectedParams: Record<number, string> =\n Reflect.getOwnMetadata('inject:params', constructor) || {}\n\n existingInjectedParams[parameterIndex] = token\n\n Reflect.defineMetadata('inject:params', existingInjectedParams, constructor)\n }\n}\n","export type PropertiesError = {\n receivedValue?: any\n type: string\n message: string\n property: string | number | undefined\n propertyType?: string\n path?: string\n}\n\nexport type CommonError = {\n location: string\n propertyErrors?: PropertiesError[]\n}\n\nexport type ApiCommonError = {\n code: number\n occurredAt: Date\n message: string\n errorCode: string\n errors?: CommonError[]\n}\n\nexport enum ApiErrorEnum {\n DOMAIN = 'ERR001',\n APPLICATION = 'ERR002',\n INFRA = 'ERR003',\n HTTP_CLIENT = 'ERR004',\n VALIDATOR = 'ERR005',\n}\n","import { type ApiCommonError, ApiErrorEnum } from './api-common-error'\n\nexport default class ApplicationError extends Error {\n props: ApiCommonError\n\n constructor(message: string) {\n super(message)\n this.props = {\n code: 400,\n errorCode: ApiErrorEnum.APPLICATION,\n message,\n occurredAt: new Date(),\n }\n }\n}\n","import { type ApiCommonError, ApiErrorEnum } from './api-common-error'\n\ntype ConflictProps = { id: string; [key: string]: unknown }\n\nexport default class ConflictError<T extends ConflictProps> extends Error {\n props: ApiCommonError\n conflictProps: T | T[]\n\n constructor(conflictProps: T | T[]) {\n super('Resource already exists.')\n this.conflictProps = conflictProps\n this.props = {\n code: 409,\n errorCode: ApiErrorEnum.APPLICATION,\n message: this.message,\n occurredAt: new Date(),\n }\n }\n}\n","import { type ApiCommonError, ApiErrorEnum } from './api-common-error'\n\nexport default class DomainError extends Error {\n props: ApiCommonError\n\n constructor(message: string) {\n super(message)\n this.props = {\n code: 400,\n errorCode: ApiErrorEnum.DOMAIN,\n message,\n occurredAt: new Date(),\n }\n }\n}\n","import { type ApiCommonError, ApiErrorEnum } from './api-common-error'\n\nexport default class InfraError extends Error {\n props: ApiCommonError\n\n constructor(message: string) {\n super(message)\n this.props = {\n code: 400,\n errorCode: ApiErrorEnum.INFRA,\n message,\n occurredAt: new Date(),\n }\n }\n}\n","import {\n type ApiCommonError,\n ApiErrorEnum,\n type CommonError,\n} from './api-common-error'\n\nexport default class ValidationError extends Error {\n props: ApiCommonError\n\n constructor(errors: CommonError[]) {\n super('Validation Error')\n this.props = {\n code: 400,\n errorCode: ApiErrorEnum.VALIDATOR,\n message: 'Validation Error',\n occurredAt: new Date(),\n errors,\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA;;;;;;;ACDA,IAAAA,2BAAO;;;ACAP,8BAAO;AAQA,IAAMC,sBAAN,MAAMA;EARb,OAQaA;;;EACX,OAAOC,WAAW,oBAAIC,IAAAA;EACtB,OAAOC,aAAa,oBAAID,IAAAA;EAExB,OAAOE,SACLC,OACAC,SACAC,SACA;AACA,SAAKN,SAASO,IAAIH,OAAO;MACvBI,MAAM;MACNH;MACAI,WAAWH,QAAQG;IACrB,CAAA;EACF;EAEA,OAAOC,cAAiBN,OAAeO,OAAU;AAC/C,SAAKX,SAASO,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;EAEA,MAAac,QAAQ3B,SAAqC;AACxD,UAAM4B,gBAAgBC,QAAQC,YAAY,SAAS,KAAK1C,WAAW;AAEnE,QAAI,CAACwC,eAAe;AAClB,YAAM,IAAIN,WAAW,2BAAA;IACvB;AAEA,UAAMS,cAAoCH,cAAcG,eAAe,CAAA;AAEvE,QAAIC,mBAAmBhC;AAEvB,QAAI+B,YAAYE,QAAQ;AACtB,iBAAWC,cAAcH,aAAa;AACpCC,2BAAmB,MAAME,WAAWF,gBAAAA;MACtC;IACF;AAEA,WAAO,MAAM,KAAKG,OAAOH,gBAAAA;EAC3B;AACF;;;AD5JO,SAASI,WAAW,EACzBC,QACAC,MACAC,cAAc,CAAA,EAAE,GACV;AACN,SAAO,CAACC,WAAAA;AACN,QAAI,EAAEA,OAAOC,qBAAqBC,iBAAiB;AACjD,YAAM,IAAIC,MACR,aAAaH,OAAOI,IAAI,+CAA+C;IAE3E;AAEAC,YAAQC,eACN,SACA;MAAET;MAAQC,MAAM,QAAQA,IAAAA;MAAQC;IAAY,GAC5CC,MAAAA;EAEJ;AACF;AAlBgBJ;","names":["import_reflect_metadata","DependencyContainer","registry","Map","singletons","register","token","myClass","options","set","type","singleton","registerValue","value","resolve","target","paramTypes","Reflect","getMetadata","injectMetadata","getOwnMetadata","params","map","_","index","Error","name","resolveToken","registration","get","has","instance","ApiErrorEnum","ApplicationError","Error","props","constructor","message","code","errorCode","ApiErrorEnum","APPLICATION","occurredAt","Date","ConflictError","Error","props","conflictProps","constructor","code","errorCode","ApiErrorEnum","APPLICATION","message","occurredAt","Date","DomainError","Error","props","constructor","message","code","errorCode","ApiErrorEnum","DOMAIN","occurredAt","Date","InfraError","Error","props","constructor","message","code","errorCode","ApiErrorEnum","INFRA","occurredAt","Date","ValidationError","Error","props","constructor","errors","code","errorCode","ApiErrorEnum","VALIDATOR","message","occurredAt","Date","BaseController","errorNotifier","constructor","DependencyContainer","resolveToken","success","dto","code","data","noContent","undefined","created","paginated","buildContextError","request","env","process","ENVIRONMENT","body","headers","params","query","failure","error","context","ConflictError","props","message","errorCode","occurredAt","items","Array","isArray","conflictProps","DomainError","ApplicationError","InfraError","ValidationError","errors","SHOULD_NOTIFY_ERROR","notify","execute","routeMetadata","Reflect","getMetadata","middlewares","processedRequest","length","middleware","handle","Controller","method","path","middlewares","target","prototype","BaseController","Error","name","Reflect","defineMetadata"]}
@@ -1,7 +1,7 @@
1
1
  import { MiddlewareFunction } from '../../infra/adapters/validators/zod/zod-validator.cjs';
2
2
  import { MethodType } from '../http/http.cjs';
3
3
  import 'zod';
4
- import '../../base-controller-cec5714c.js';
4
+ import '../../base-controller-68008870.js';
5
5
 
6
6
  type Props = {
7
7
  method: MethodType;
@@ -1,7 +1,7 @@
1
1
  import { MiddlewareFunction } from '../../infra/adapters/validators/zod/zod-validator.js';
2
2
  import { MethodType } from '../http/http.js';
3
3
  import 'zod';
4
- import '../../base-controller-cec5714c.js';
4
+ import '../../base-controller-68008870.js';
5
5
 
6
6
  type Props = {
7
7
  method: MethodType;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/core/http/base-controller.ts","../../../src/core/decorators/dependency-container.ts","../../../src/core/errors/api-common-error.ts","../../../src/core/errors/application-error.ts","../../../src/core/errors/conflict-error.ts","../../../src/core/errors/domain-error.ts","../../../src/core/errors/infra-error.ts","../../../src/core/errors/validation-error.ts","../../../src/core/decorators/controller-http-decorator.ts"],"sourcesContent":["import 'reflect-metadata'\n\nimport DependencyContainer from '../../core/decorators/dependency-container'\nimport ApplicationError from '../../core/errors/application-error'\nimport ConflictError from '../../core/errors/conflict-error'\nimport DomainError from '../../core/errors/domain-error'\nimport InfraError from '../../core/errors/infra-error'\nimport ValidationError from '../../core/errors/validation-error'\nimport { MiddlewareFunction } from '../../infra/adapters/validators/zod/zod-validator'\nimport IErrorNotifier from './error-notifier'\n\nexport type AnyObject = Record<string, any>\n\nexport type Request = {\n body: AnyObject\n params: AnyObject\n headers: AnyObject\n query: AnyObject\n}\n\nexport type Response = {\n code: number\n data: any\n}\n\nexport type ContextError = {\n env: string\n user?: {\n id?: string\n name?: string\n email?: string\n }\n request?: {\n method?: string\n requestId?: string\n url?: string\n headers?: any\n query?: any\n body?: any\n params?: any\n }\n}\n\nexport default abstract class BaseController {\n protected readonly errorNotifier: IErrorNotifier\n\n abstract handle<T>(request: T | Request): Promise<Response>\n\n constructor() {\n this.errorNotifier = DependencyContainer.resolveToken('IErrorNotifier')\n }\n\n protected success<T>(dto?: T): Response {\n return {\n code: 200,\n data: { data: dto },\n }\n }\n\n protected noContent(): Response {\n return {\n code: 204,\n data: undefined,\n }\n }\n\n protected created<T>(dto?: T): Response {\n return {\n code: 201,\n data: dto ? { data: dto } : undefined,\n }\n }\n\n protected paginated<T>(dto?: T): Response {\n return {\n code: 200,\n data: dto,\n }\n }\n\n protected buildContextError(request: Request): ContextError {\n return {\n env: process.env.ENVIRONMENT as string,\n request: {\n body: request.body,\n headers: request.headers,\n params: request.params,\n query: request.query,\n },\n }\n }\n\n public async failure(error: Error, context: ContextError): Promise<Response> {\n if (error instanceof ConflictError) {\n return {\n code: error.props.code,\n data: {\n message: error.message,\n errorCode: error.props.errorCode,\n occurredAt: error.props.occurredAt,\n items: Array.isArray(error.conflictProps)\n ? error.conflictProps\n : [error.conflictProps],\n },\n }\n }\n\n if (\n error instanceof DomainError ||\n error instanceof ApplicationError ||\n error instanceof InfraError\n ) {\n return {\n code: error.props.code,\n data: {\n message: error.message,\n errorCode: error.props.errorCode,\n occurredAt: error.props.occurredAt,\n },\n }\n }\n\n if (error instanceof ValidationError) {\n return {\n code: error.props.code,\n data: {\n message: error.props.message,\n errorCode: error.props.errorCode,\n occurredAt: error.props.occurredAt,\n errors: error.props.errors,\n },\n }\n }\n\n if (process.env.SHOULD_NOTIFY_ERROR) {\n await this.errorNotifier.notify(error, context)\n }\n\n return {\n code: 500,\n data: {\n code: 500,\n message: 'Server failed. Contact the administrator!',\n },\n }\n }\n\n public async execute(request: Request): Promise<Response> {\n const routeMetadata = Reflect.getMetadata('route', this.constructor)\n\n if (!routeMetadata) {\n throw new InfraError('Route metadata not found.')\n }\n\n const middlewares: MiddlewareFunction[] = routeMetadata.middlewares || []\n\n let processedRequest = request\n\n if (middlewares.length) {\n for (const middleware of middlewares) {\n processedRequest = await middleware(processedRequest)\n }\n }\n\n return await this.handle(processedRequest)\n }\n}\n","import 'reflect-metadata'\n\ntype Class<T = any> = new (...args: any[]) => T\n\ntype Registration =\n | { type: 'class'; myClass: Class; singleton: boolean }\n | { type: 'value'; value: any }\n\nexport default class DependencyContainer {\n static registry = new Map<string, Registration>()\n static singletons = new Map<string, any>()\n\n static register<T>(\n token: string,\n myClass: Class<T>,\n options: { singleton: boolean }\n ) {\n this.registry.set(token, {\n type: 'class',\n myClass,\n singleton: options.singleton,\n })\n }\n\n static registerValue<T>(token: string, value: T) {\n this.registry.set(token, { type: 'value', value })\n }\n\n static resolve<T>(target: Class<T>): T {\n const paramTypes = Reflect.getMetadata('design:paramtypes', target) || []\n\n const injectMetadata: Record<number, string> =\n Reflect.getOwnMetadata('inject:params', target) || {}\n\n const params = paramTypes.map((_: any, index: number) => {\n const token = injectMetadata[index]\n\n if (!token) {\n throw new Error(\n `Missing @Inject token for parameter index ${index} in ${target.name}`\n )\n }\n\n return this.resolveToken(token)\n })\n\n return new target(...params)\n }\n\n static resolveToken(token: string): any {\n const registration = this.registry.get(token)\n\n if (!registration) {\n throw new Error(\n `\"${token}\" not registered. Please register it in the container.`\n )\n }\n\n if (registration.type === 'value') {\n return registration.value\n }\n\n const { myClass, singleton } = registration\n\n if (singleton) {\n if (!this.singletons.has(token)) {\n const instance = this.resolve(myClass)\n this.singletons.set(token, instance)\n }\n return this.singletons.get(token)\n }\n\n return this.resolve(myClass)\n }\n}\n\nexport function Inject(token: string): ParameterDecorator {\n return (\n target: object,\n _propertyKey: string | symbol | undefined,\n parameterIndex: number\n ): void => {\n const constructor =\n typeof target === 'function' ? target : target.constructor\n\n const existingInjectedParams: Record<number, string> =\n Reflect.getOwnMetadata('inject:params', constructor) || {}\n\n existingInjectedParams[parameterIndex] = token\n\n Reflect.defineMetadata('inject:params', existingInjectedParams, constructor)\n }\n}\n","export type PropertiesError = {\n receivedValue?: any\n type: string\n message: string\n property: string | number | undefined\n propertyType?: string\n path?: string\n}\n\nexport type CommonError = {\n location: string\n propertyErrors?: PropertiesError[]\n}\n\nexport type ApiCommonError = {\n code: number\n occurredAt: Date\n message: string\n errorCode: string\n errors?: CommonError[]\n}\n\nexport enum ApiErrorEnum {\n DOMAIN = 'ERR001',\n APPLICATION = 'ERR002',\n INFRA = 'ERR003',\n HTTP_CLIENT = 'ERR004',\n VALIDATOR = 'ERR005',\n}\n","import { type ApiCommonError, ApiErrorEnum } from './api-common-error'\n\nexport default class ApplicationError extends Error {\n props: ApiCommonError\n\n constructor(message: string) {\n super(message)\n this.props = {\n code: 400,\n errorCode: ApiErrorEnum.APPLICATION,\n message,\n occurredAt: new Date(),\n }\n }\n}\n","import { type ApiCommonError, ApiErrorEnum } from './api-common-error'\n\ntype ConflictProps = { id: string; [key: string]: unknown }\n\nexport default class ConflictError<T extends ConflictProps> extends Error {\n props: ApiCommonError\n conflictProps: T | T[]\n\n constructor(conflictProps: T | T[]) {\n super('Resource already exists.')\n this.conflictProps = conflictProps\n this.props = {\n code: 409,\n errorCode: ApiErrorEnum.APPLICATION,\n message: this.message,\n occurredAt: new Date(),\n }\n }\n}\n","import { type ApiCommonError, ApiErrorEnum } from './api-common-error'\n\nexport default class DomainError extends Error {\n props: ApiCommonError\n\n constructor(message: string) {\n super(message)\n this.props = {\n code: 400,\n errorCode: ApiErrorEnum.DOMAIN,\n message,\n occurredAt: new Date(),\n }\n }\n}\n","import { type ApiCommonError, ApiErrorEnum } from './api-common-error'\n\nexport default class InfraError extends Error {\n props: ApiCommonError\n\n constructor(message: string) {\n super(message)\n this.props = {\n code: 400,\n errorCode: ApiErrorEnum.INFRA,\n message,\n occurredAt: new Date(),\n }\n }\n}\n","import {\n type ApiCommonError,\n ApiErrorEnum,\n type CommonError,\n} from './api-common-error'\n\nexport default class ValidationError extends Error {\n props: ApiCommonError\n\n constructor(errors: CommonError[]) {\n super('Validation Error')\n this.props = {\n code: 400,\n errorCode: ApiErrorEnum.VALIDATOR,\n message: 'Validation Error',\n occurredAt: new Date(),\n errors,\n }\n }\n}\n","import { MiddlewareFunction } from '../../infra/adapters/validators/zod/zod-validator'\nimport BaseController from '../http/base-controller'\nimport type { MethodType } from '../http/http'\n\ntype Props = {\n method: MethodType\n path: string\n middlewares?: MiddlewareFunction[]\n}\n\nexport function Controller({\n method,\n path,\n middlewares = [],\n}: Props): ClassDecorator {\n return (target: any) => {\n if (!(target.prototype instanceof BaseController)) {\n throw new Error(\n `The class ${target.name} should extends abstract class BaseController`\n )\n }\n\n Reflect.defineMetadata(\n 'route',\n { method, path: `/api/${path}`, middlewares },\n target\n )\n }\n}\n"],"mappings":";;;;AAAA,OAAO;;;ACAP,OAAO;AAQP,IAAqBA,sBAArB,MAAqBA;EARrB,OAQqBA;;;EACnB,OAAOC,WAAW,oBAAIC,IAAAA;EACtB,OAAOC,aAAa,oBAAID,IAAAA;EAExB,OAAOE,SACLC,OACAC,SACAC,SACA;AACA,SAAKN,SAASO,IAAIH,OAAO;MACvBI,MAAM;MACNH;MACAI,WAAWH,QAAQG;IACrB,CAAA;EACF;EAEA,OAAOC,cAAiBN,OAAeO,OAAU;AAC/C,SAAKX,SAASO,IAAIH,OAAO;MAAEI,MAAM;MAASG;IAAM,CAAA;EAClD;EAEA,OAAOC,QAAWC,QAAqB;AACrC,UAAMC,aAAaC,QAAQC,YAAY,qBAAqBH,MAAAA,KAAW,CAAA;AAEvE,UAAMI,iBACJF,QAAQG,eAAe,iBAAiBL,MAAAA,KAAW,CAAC;AAEtD,UAAMM,SAASL,WAAWM,IAAI,CAACC,GAAQC,UAAAA;AACrC,YAAMlB,QAAQa,eAAeK,KAAAA;AAE7B,UAAI,CAAClB,OAAO;AACV,cAAM,IAAImB,MACR,6CAA6CD,K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AAOH,gBAAAA;EAC3B;AACF;;;AQ5JO,SAASI,WAAW,EACzBC,QACAC,MACAC,cAAc,CAAA,EAAE,GACV;AACN,SAAO,CAACC,WAAAA;AACN,QAAI,EAAEA,OAAOC,qBAAqBC,iBAAiB;AACjD,YAAM,IAAIC,MACR,aAAaH,OAAOI,IAAI,+CAA+C;IAE3E;AAEAC,YAAQC,eACN,SACA;MAAET;MAAQC,MAAM,QAAQA,IAAAA;MAAQC;IAAY,GAC5CC,MAAAA;EAEJ;AACF;AAlBgBJ;","names":["DependencyContainer","registry","Map","singletons","register","token","myClass","options","set","type","singleton","registerValue","value","resolve","target","paramTypes","Reflect","getMetadata","injectMetadata","getOwnMetadata","params","map","_","index","Error","name","resolveToken","registration","get","has","instance","ApiErrorEnum","ApplicationError","Error","props","constructor","message","code","errorCode","ApiErrorEnum","APPLICATION","occurredAt","Date","ConflictError","Error","props","conflictProps","constructor","code","errorCode","ApiErrorEnum","APPLICATION","message","occurredAt","Date","DomainError","Error","props","constructor","message","code","errorCode","ApiErrorEnum","DOMAIN","occurredAt","Date","InfraError","Error","props","constructor","message","code","errorCode","ApiErrorEnum","INFRA","occurredAt","Date","ValidationError","Error","props","constructor","errors","code","errorCode","ApiErrorEnum","VALIDATOR","message","occurredAt","Date","BaseController","errorNotifier","constructor","DependencyContainer","resolveToken","success","dto","code","data","noContent","undefined","created","paginated","buildContextError","request","env","process","ENVIRONMENT","body","headers","params","query","failure","error","context","ConflictError","props","message","errorCode","occurredAt","items","Array","isArray","conflictProps","DomainError","ApplicationError","InfraError","ValidationError","errors","SHOULD_NOTIFY_ERROR","notify","execute","routeMetadata","Reflect","getMetadata","middlewares","processedRequest","length","middleware","handle","Controller","method","path","middlewares","target","prototype","BaseController","Error","name","Reflect","defineMetadata"]}
1
+ {"version":3,"sources":["../../../src/core/http/base-controller.ts","../../../src/core/decorators/dependency-container.ts","../../../src/core/errors/api-common-error.ts","../../../src/core/errors/application-error.ts","../../../src/core/errors/conflict-error.ts","../../../src/core/errors/domain-error.ts","../../../src/core/errors/infra-error.ts","../../../src/core/errors/validation-error.ts","../../../src/core/decorators/controller-http-decorator.ts"],"sourcesContent":["import 'reflect-metadata'\n\nimport { DependencyContainer } from '../../core/decorators/dependency-container'\nimport ApplicationError from '../../core/errors/application-error'\nimport ConflictError from '../../core/errors/conflict-error'\nimport DomainError from '../../core/errors/domain-error'\nimport InfraError from '../../core/errors/infra-error'\nimport ValidationError from '../../core/errors/validation-error'\nimport { MiddlewareFunction } from '../../infra/adapters/validators/zod/zod-validator'\nimport IErrorNotifier from './error-notifier'\n\ntype AnyObject = Record<string, any>\n\nexport type Request = {\n body: AnyObject\n params: AnyObject\n headers: AnyObject\n query: AnyObject\n}\n\nexport type Response = {\n code: number\n data: any\n}\n\nexport type ContextError = {\n env: string\n user?: {\n id?: string\n name?: string\n email?: string\n }\n request?: {\n method?: string\n requestId?: string\n url?: string\n headers?: any\n query?: any\n body?: any\n params?: any\n }\n}\n\nexport abstract class BaseController {\n protected readonly errorNotifier: IErrorNotifier\n\n abstract handle<T>(request: T | Request): Promise<Response>\n\n constructor() {\n this.errorNotifier = DependencyContainer.resolveToken('IErrorNotifier')\n }\n\n protected success<T>(dto?: T): Response {\n return {\n code: 200,\n data: { data: dto },\n }\n }\n\n protected noContent(): Response {\n return {\n code: 204,\n data: undefined,\n }\n }\n\n protected created<T>(dto?: T): Response {\n return {\n code: 201,\n data: dto ? { data: dto } : undefined,\n }\n }\n\n protected paginated<T>(dto?: T): Response {\n return {\n code: 200,\n data: dto,\n }\n }\n\n protected buildContextError(request: Request): ContextError {\n return {\n env: process.env.ENVIRONMENT as string,\n request: {\n body: request.body,\n headers: request.headers,\n params: request.params,\n query: request.query,\n },\n }\n }\n\n public async failure(error: Error, context: ContextError): Promise<Response> {\n if (error instanceof ConflictError) {\n return {\n code: error.props.code,\n data: {\n message: error.message,\n errorCode: error.props.errorCode,\n occurredAt: error.props.occurredAt,\n items: Array.isArray(error.conflictProps)\n ? error.conflictProps\n : [error.conflictProps],\n },\n }\n }\n\n if (\n error instanceof DomainError ||\n error instanceof ApplicationError ||\n error instanceof InfraError\n ) {\n return {\n code: error.props.code,\n data: {\n message: error.message,\n errorCode: error.props.errorCode,\n occurredAt: error.props.occurredAt,\n },\n }\n }\n\n if (error instanceof ValidationError) {\n return {\n code: error.props.code,\n data: {\n message: error.props.message,\n errorCode: error.props.errorCode,\n occurredAt: error.props.occurredAt,\n errors: error.props.errors,\n },\n }\n }\n\n if (process.env.SHOULD_NOTIFY_ERROR) {\n await this.errorNotifier.notify(error, context)\n }\n\n return {\n code: 500,\n data: {\n code: 500,\n message: 'Server failed. Contact the administrator!',\n },\n }\n }\n\n public async execute(request: Request): Promise<Response> {\n const routeMetadata = Reflect.getMetadata('route', this.constructor)\n\n if (!routeMetadata) {\n throw new InfraError('Route metadata not found.')\n }\n\n const middlewares: MiddlewareFunction[] = routeMetadata.middlewares || []\n\n let processedRequest = request\n\n if (middlewares.length) {\n for (const middleware of middlewares) {\n processedRequest = await middleware(processedRequest)\n }\n }\n\n return await this.handle(processedRequest)\n }\n}\n","import 'reflect-metadata'\n\ntype Class<T = any> = new (...args: any[]) => T\n\ntype Registration =\n | { type: 'class'; myClass: Class; singleton: boolean }\n | { type: 'value'; value: any }\n\nexport class DependencyContainer {\n static registry = new Map<string, Registration>()\n static singletons = new Map<string, any>()\n\n static register<T>(\n token: string,\n myClass: Class<T>,\n options: { singleton: boolean }\n ) {\n this.registry.set(token, {\n type: 'class',\n myClass,\n singleton: options.singleton,\n })\n }\n\n static registerValue<T>(token: string, value: T) {\n this.registry.set(token, { type: 'value', value })\n }\n\n static resolve<T>(target: Class<T>): T {\n const paramTypes = Reflect.getMetadata('design:paramtypes', target) || []\n\n const injectMetadata: Record<number, string> =\n Reflect.getOwnMetadata('inject:params', target) || {}\n\n const params = paramTypes.map((_: any, index: number) => {\n const token = injectMetadata[index]\n\n if (!token) {\n throw new Error(\n `Missing @Inject token for parameter index ${index} in ${target.name}`\n )\n }\n\n return this.resolveToken(token)\n })\n\n return new target(...params)\n }\n\n static resolveToken(token: string): any {\n const registration = this.registry.get(token)\n\n if (!registration) {\n throw new Error(\n `\"${token}\" not registered. Please register it in the container.`\n )\n }\n\n if (registration.type === 'value') {\n return registration.value\n }\n\n const { myClass, singleton } = registration\n\n if (singleton) {\n if (!this.singletons.has(token)) {\n const instance = this.resolve(myClass)\n this.singletons.set(token, instance)\n }\n return this.singletons.get(token)\n }\n\n return this.resolve(myClass)\n }\n}\n\nexport function Inject(token: string): ParameterDecorator {\n return (\n target: object,\n _propertyKey: string | symbol | undefined,\n parameterIndex: number\n ): void => {\n const constructor =\n typeof target === 'function' ? target : target.constructor\n\n const existingInjectedParams: Record<number, string> =\n Reflect.getOwnMetadata('inject:params', constructor) || {}\n\n existingInjectedParams[parameterIndex] = token\n\n Reflect.defineMetadata('inject:params', existingInjectedParams, constructor)\n }\n}\n","export type PropertiesError = {\n receivedValue?: any\n type: string\n message: string\n property: string | number | undefined\n propertyType?: string\n path?: string\n}\n\nexport type CommonError = {\n location: string\n propertyErrors?: PropertiesError[]\n}\n\nexport type ApiCommonError = {\n code: number\n occurredAt: Date\n message: string\n errorCode: string\n errors?: CommonError[]\n}\n\nexport enum ApiErrorEnum {\n DOMAIN = 'ERR001',\n APPLICATION = 'ERR002',\n INFRA = 'ERR003',\n HTTP_CLIENT = 'ERR004',\n VALIDATOR = 'ERR005',\n}\n","import { type ApiCommonError, ApiErrorEnum } from './api-common-error'\n\nexport default class ApplicationError extends Error {\n props: ApiCommonError\n\n constructor(message: string) {\n super(message)\n this.props = {\n code: 400,\n errorCode: ApiErrorEnum.APPLICATION,\n message,\n occurredAt: new Date(),\n }\n }\n}\n","import { type ApiCommonError, ApiErrorEnum } from './api-common-error'\n\ntype ConflictProps = { id: string; [key: string]: unknown }\n\nexport default class ConflictError<T extends ConflictProps> extends Error {\n props: ApiCommonError\n conflictProps: T | T[]\n\n constructor(conflictProps: T | T[]) {\n super('Resource already exists.')\n this.conflictProps = conflictProps\n this.props = {\n code: 409,\n errorCode: ApiErrorEnum.APPLICATION,\n message: this.message,\n occurredAt: new Date(),\n }\n }\n}\n","import { type ApiCommonError, ApiErrorEnum } from './api-common-error'\n\nexport default class DomainError extends Error {\n props: ApiCommonError\n\n constructor(message: string) {\n super(message)\n this.props = {\n code: 400,\n errorCode: ApiErrorEnum.DOMAIN,\n message,\n occurredAt: new Date(),\n }\n }\n}\n","import { type ApiCommonError, ApiErrorEnum } from './api-common-error'\n\nexport default class InfraError extends Error {\n props: ApiCommonError\n\n constructor(message: string) {\n super(message)\n this.props = {\n code: 400,\n errorCode: ApiErrorEnum.INFRA,\n message,\n occurredAt: new Date(),\n }\n }\n}\n","import {\n type ApiCommonError,\n ApiErrorEnum,\n type CommonError,\n} from './api-common-error'\n\nexport default class ValidationError extends Error {\n props: ApiCommonError\n\n constructor(errors: CommonError[]) {\n super('Validation Error')\n this.props = {\n code: 400,\n errorCode: ApiErrorEnum.VALIDATOR,\n message: 'Validation Error',\n occurredAt: new Date(),\n errors,\n }\n }\n}\n","import { MiddlewareFunction } from '../../infra/adapters/validators/zod/zod-validator'\nimport { BaseController } from '../http/base-controller'\nimport type { MethodType } from '../http/http'\n\ntype Props = {\n method: MethodType\n path: string\n middlewares?: MiddlewareFunction[]\n}\n\nexport function Controller({\n method,\n path,\n middlewares = [],\n}: Props): ClassDecorator {\n return (target: any) => {\n if (!(target.prototype instanceof BaseController)) {\n throw new Error(\n `The class ${target.name} should extends abstract class BaseController`\n )\n }\n\n Reflect.defineMetadata(\n 'route',\n { method, path: `/api/${path}`, middlewares },\n target\n )\n }\n}\n"],"mappings":";;;;AAAA,OAAO;;;ACAP,OAAO;AAQA,IAAMA,sBAAN,MAAMA;EARb,OAQaA;;;EACX,OAAOC,WAAW,oBAAIC,IAAAA;EACtB,OAAOC,aAAa,oBAAID,IAAAA;EAExB,OAAOE,SACLC,OACAC,SACAC,SACA;AACA,SAAKN,SAASO,IAAIH,OAAO;MACvBI,MAAM;M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,OAAOC,OAAAA;IACzC;AAEA,WAAO;MACLjB,MAAM;MACNC,MAAM;QACJD,MAAM;QACNoB,SAAS;MACX;IACF;EACF;EAEA,MAAac,QAAQ3B,SAAqC;AACxD,UAAM4B,gBAAgBC,QAAQC,YAAY,SAAS,KAAK1C,WAAW;AAEnE,QAAI,CAACwC,eAAe;AAClB,YAAM,IAAIN,WAAW,2BAAA;IACvB;AAEA,UAAMS,cAAoCH,cAAcG,eAAe,CAAA;AAEvE,QAAIC,mBAAmBhC;AAEvB,QAAI+B,YAAYE,QAAQ;AACtB,iBAAWC,cAAcH,aAAa;AACpCC,2BAAmB,MAAME,WAAWF,gBAAAA;MACtC;IACF;AAEA,WAAO,MAAM,KAAKG,OAAOH,gBAAAA;EAC3B;AACF;;;AQ5JO,SAASI,WAAW,EACzBC,QACAC,MACAC,cAAc,CAAA,EAAE,GACV;AACN,SAAO,CAACC,WAAAA;AACN,QAAI,EAAEA,OAAOC,qBAAqBC,iBAAiB;AACjD,YAAM,IAAIC,MACR,aAAaH,OAAOI,IAAI,+CAA+C;IAE3E;AAEAC,YAAQC,eACN,SACA;MAAET;MAAQC,MAAM,QAAQA,IAAAA;MAAQC;IAAY,GAC5CC,MAAAA;EAEJ;AACF;AAlBgBJ;","names":["DependencyContainer","registry","Map","singletons","register","token","myClass","options","set","type","singleton","registerValue","value","resolve","target","paramTypes","Reflect","getMetadata","injectMetadata","getOwnMetadata","params","map","_","index","Error","name","resolveToken","registration","get","has","instance","ApiErrorEnum","ApplicationError","Error","props","constructor","message","code","errorCode","ApiErrorEnum","APPLICATION","occurredAt","Date","ConflictError","Error","props","conflictProps","constructor","code","errorCode","ApiErrorEnum","APPLICATION","message","occurredAt","Date","DomainError","Error","props","constructor","message","code","errorCode","ApiErrorEnum","DOMAIN","occurredAt","Date","InfraError","Error","props","constructor","message","code","errorCode","ApiErrorEnum","INFRA","occurredAt","Date","ValidationError","Error","props","constructor","errors","code","errorCode","ApiErrorEnum","VALIDATOR","message","occurredAt","Date","BaseController","errorNotifier","constructor","DependencyContainer","resolveToken","success","dto","code","data","noContent","undefined","created","paginated","buildContextError","request","env","process","ENVIRONMENT","body","headers","params","query","failure","error","context","ConflictError","props","message","errorCode","occurredAt","items","Array","isArray","conflictProps","DomainError","ApplicationError","InfraError","ValidationError","errors","SHOULD_NOTIFY_ERROR","notify","execute","routeMetadata","Reflect","getMetadata","middlewares","processedRequest","length","middleware","handle","Controller","method","path","middlewares","target","prototype","BaseController","Error","name","Reflect","defineMetadata"]}
@@ -21,8 +21,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  // src/core/decorators/dependency-container.ts
22
22
  var dependency_container_exports = {};
23
23
  __export(dependency_container_exports, {
24
- Inject: () => Inject,
25
- default: () => DependencyContainer
24
+ DependencyContainer: () => DependencyContainer,
25
+ Inject: () => Inject
26
26
  });
27
27
  module.exports = __toCommonJS(dependency_container_exports);
28
28
  var import_reflect_metadata = require("reflect-metadata");
@@ -87,6 +87,7 @@ function Inject(token) {
87
87
  __name(Inject, "Inject");
88
88
  // Annotate the CommonJS export names for ESM import in node:
89
89
  0 && (module.exports = {
90
+ DependencyContainer,
90
91
  Inject
91
92
  });
92
93
  //# sourceMappingURL=dependency-container.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/core/decorators/dependency-container.ts"],"sourcesContent":["import 'reflect-metadata'\n\ntype Class<T = any> = new (...args: any[]) => T\n\ntype Registration =\n | { type: 'class'; myClass: Class; singleton: boolean }\n | { type: 'value'; value: any }\n\nexport default class DependencyContainer {\n static registry = new Map<string, Registration>()\n static singletons = new Map<string, any>()\n\n static register<T>(\n token: string,\n myClass: Class<T>,\n options: { singleton: boolean }\n ) {\n this.registry.set(token, {\n type: 'class',\n myClass,\n singleton: options.singleton,\n })\n }\n\n static registerValue<T>(token: string, value: T) {\n this.registry.set(token, { type: 'value', value })\n }\n\n static resolve<T>(target: Class<T>): T {\n const paramTypes = Reflect.getMetadata('design:paramtypes', target) || []\n\n const injectMetadata: Record<number, string> =\n Reflect.getOwnMetadata('inject:params', target) || {}\n\n const params = paramTypes.map((_: any, index: number) => {\n const token = injectMetadata[index]\n\n if (!token) {\n throw new Error(\n `Missing @Inject token for parameter index ${index} in ${target.name}`\n )\n }\n\n return this.resolveToken(token)\n })\n\n return new target(...params)\n }\n\n static resolveToken(token: string): any {\n const registration = this.registry.get(token)\n\n if (!registration) {\n throw new Error(\n `\"${token}\" not registered. Please register it in the container.`\n )\n }\n\n if (registration.type === 'value') {\n return registration.value\n }\n\n const { myClass, singleton } = registration\n\n if (singleton) {\n if (!this.singletons.has(token)) {\n const instance = this.resolve(myClass)\n this.singletons.set(token, instance)\n }\n return this.singletons.get(token)\n }\n\n return this.resolve(myClass)\n }\n}\n\nexport function Inject(token: string): ParameterDecorator {\n return (\n target: object,\n _propertyKey: string | symbol | undefined,\n parameterIndex: number\n ): void => {\n const constructor =\n typeof target === 'function' ? target : target.constructor\n\n const existingInjectedParams: Record<number, string> =\n Reflect.getOwnMetadata('inject:params', constructor) || {}\n\n existingInjectedParams[parameterIndex] = token\n\n Reflect.defineMetadata('inject:params', existingInjectedParams, constructor)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;8BAAO;AAQP,IAAqBA,sBAArB,MAAqBA;EARrB,OAQqBA;;;EACnB,OAAOC,WAAW,oBAAIC,IAAAA;EACtB,OAAOC,aAAa,oBAAID,IAAAA;EAExB,OAAOE,SACLC,OACAC,SACAC,SACA;AACA,SAAKN,SAASO,IAAIH,OAAO;MACvBI,MAAM;MACNH;MACAI,WAAWH,QAAQG;IACrB,CAAA;EACF;EAEA,OAAOC,cAAiBN,OAAeO,OAAU;AAC/C,SAAKX,SAASO,IAAIH,OAAO;MAAEI,MAAM;MAASG;IAAM,CAAA;EAClD;EAEA,OAAOC,QAAWC,QAAqB;AACrC,UAAMC,aAAaC,QAAQC,YAAY,qBAAqBH,MAAAA,KAAW,CAAA;AAEvE,UAAMI,iBACJF,QAAQG,eAAe,iBAAiBL,MAAAA,KAAW,CAAC;AAEtD,UAAMM,SAASL,WAAWM,IAAI,CAACC,GAAQC,UAAAA;AACrC,YAAMlB,QAAQa,eAAeK,KAAAA;AAE7B,UAAI,CAAClB,OAAO;AACV,cAAM,IAAImB,MACR,6CAA6CD,KAAAA,OAAYT,OAAOW,IAAI,EAAE;MAE1E;AAEA,aAAO,KAAKC,aAAarB,KAAAA;IAC3B,CAAA;AAEA,WAAO,IAAIS,OAAAA,GAAUM,MAAAA;EACvB;EAEA,OAAOM,aAAarB,OAAoB;AACtC,UAAMsB,eAAe,KAAK1B,SAAS2B,IAAIvB,KAAAA;AAEvC,QAAI,CAACsB,cAAc;AACjB,YAAM,IAAIH,MACR,IAAInB,KAAAA,wDAA6D;IAErE;AAEA,QAAIsB,aAAalB,SAAS,SAAS;AACjC,aAAOkB,aAAaf;IACtB;AAEA,UAAM,EAAEN,SAASI,UAAS,IAAKiB;AAE/B,QAAIjB,WAAW;AACb,UAAI,CAAC,KAAKP,WAAW0B,IAAIxB,KAAAA,GAAQ;AAC/B,cAAMyB,WAAW,KAAKjB,QAAQP,OAAAA;AAC9B,aAAKH,WAAWK,IAAIH,OAAOyB,QAAAA;MAC7B;AACA,aAAO,KAAK3B,WAAWyB,IAAIvB,KAAAA;IAC7B;AAEA,WAAO,KAAKQ,QAAQP,OAAAA;EACtB;AACF;AAEO,SAASyB,OAAO1B,OAAa;AAClC,SAAO,CACLS,QACAkB,cACAC,mBAAAA;AAEA,UAAMC,cACJ,OAAOpB,WAAW,aAAaA,SAASA,OAAOoB;AAEjD,UAAMC,yBACJnB,QAAQG,eAAe,iBAAiBe,WAAAA,KAAgB,CAAC;AAE3DC,2BAAuBF,cAAAA,IAAkB5B;AAEzCW,YAAQoB,eAAe,iBAAiBD,wBAAwBD,WAAAA;EAClE;AACF;AAhBgBH;","names":["DependencyContainer","registry","Map","singletons","register","token","myClass","options","set","type","singleton","registerValue","value","resolve","target","paramTypes","Reflect","getMetadata","injectMetadata","getOwnMetadata","params","map","_","index","Error","name","resolveToken","registration","get","has","instance","Inject","_propertyKey","parameterIndex","constructor","existingInjectedParams","defineMetadata"]}
1
+ {"version":3,"sources":["../../../src/core/decorators/dependency-container.ts"],"sourcesContent":["import 'reflect-metadata'\n\ntype Class<T = any> = new (...args: any[]) => T\n\ntype Registration =\n | { type: 'class'; myClass: Class; singleton: boolean }\n | { type: 'value'; value: any }\n\nexport class DependencyContainer {\n static registry = new Map<string, Registration>()\n static singletons = new Map<string, any>()\n\n static register<T>(\n token: string,\n myClass: Class<T>,\n options: { singleton: boolean }\n ) {\n this.registry.set(token, {\n type: 'class',\n myClass,\n singleton: options.singleton,\n })\n }\n\n static registerValue<T>(token: string, value: T) {\n this.registry.set(token, { type: 'value', value })\n }\n\n static resolve<T>(target: Class<T>): T {\n const paramTypes = Reflect.getMetadata('design:paramtypes', target) || []\n\n const injectMetadata: Record<number, string> =\n Reflect.getOwnMetadata('inject:params', target) || {}\n\n const params = paramTypes.map((_: any, index: number) => {\n const token = injectMetadata[index]\n\n if (!token) {\n throw new Error(\n `Missing @Inject token for parameter index ${index} in ${target.name}`\n )\n }\n\n return this.resolveToken(token)\n })\n\n return new target(...params)\n }\n\n static resolveToken(token: string): any {\n const registration = this.registry.get(token)\n\n if (!registration) {\n throw new Error(\n `\"${token}\" not registered. Please register it in the container.`\n )\n }\n\n if (registration.type === 'value') {\n return registration.value\n }\n\n const { myClass, singleton } = registration\n\n if (singleton) {\n if (!this.singletons.has(token)) {\n const instance = this.resolve(myClass)\n this.singletons.set(token, instance)\n }\n return this.singletons.get(token)\n }\n\n return this.resolve(myClass)\n }\n}\n\nexport function Inject(token: string): ParameterDecorator {\n return (\n target: object,\n _propertyKey: string | symbol | undefined,\n parameterIndex: number\n ): void => {\n const constructor =\n typeof target === 'function' ? target : target.constructor\n\n const existingInjectedParams: Record<number, string> =\n Reflect.getOwnMetadata('inject:params', constructor) || {}\n\n existingInjectedParams[parameterIndex] =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yB,WAAW,KAAKjB,QAAQP,OAAAA;AAC9B,aAAKH,WAAWK,IAAIH,OAAOyB,QAAAA;MAC7B;AACA,aAAO,KAAK3B,WAAWyB,IAAIvB,KAAAA;IAC7B;AAEA,WAAO,KAAKQ,QAAQP,OAAAA;EACtB;AACF;AAEO,SAASyB,OAAO1B,OAAa;AAClC,SAAO,CACLS,QACAkB,cACAC,mBAAAA;AAEA,UAAMC,cACJ,OAAOpB,WAAW,aAAaA,SAASA,OAAOoB;AAEjD,UAAMC,yBACJnB,QAAQG,eAAe,iBAAiBe,WAAAA,KAAgB,CAAC;AAE3DC,2BAAuBF,cAAAA,IAAkB5B;AAEzCW,YAAQoB,eAAe,iBAAiBD,wBAAwBD,WAAAA;EAClE;AACF;AAhBgBH;","names":["DependencyContainer","registry","Map","singletons","register","token","myClass","options","set","type","singleton","registerValue","value","resolve","target","paramTypes","Reflect","getMetadata","injectMetadata","getOwnMetadata","params","map","_","index","Error","name","resolveToken","registration","get","has","instance","Inject","_propertyKey","parameterIndex","constructor","existingInjectedParams","defineMetadata"]}
@@ -19,4 +19,4 @@ declare class DependencyContainer {
19
19
  }
20
20
  declare function Inject(token: string): ParameterDecorator;
21
21
 
22
- export { Inject, DependencyContainer as default };
22
+ export { DependencyContainer, Inject };
@@ -19,4 +19,4 @@ declare class DependencyContainer {
19
19
  }
20
20
  declare function Inject(token: string): ParameterDecorator;
21
21
 
22
- export { Inject, DependencyContainer as default };
22
+ export { DependencyContainer, Inject };
@@ -63,7 +63,7 @@ function Inject(token) {
63
63
  }
64
64
  __name(Inject, "Inject");
65
65
  export {
66
- Inject,
67
- DependencyContainer as default
66
+ DependencyContainer,
67
+ Inject
68
68
  };
69
69
  //# sourceMappingURL=dependency-container.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/core/decorators/dependency-container.ts"],"sourcesContent":["import 'reflect-metadata'\n\ntype Class<T = any> = new (...args: any[]) => T\n\ntype Registration =\n | { type: 'class'; myClass: Class; singleton: boolean }\n | { type: 'value'; value: any }\n\nexport default class DependencyContainer {\n static registry = new Map<string, Registration>()\n static singletons = new Map<string, any>()\n\n static register<T>(\n token: string,\n myClass: Class<T>,\n options: { singleton: boolean }\n ) {\n this.registry.set(token, {\n type: 'class',\n myClass,\n singleton: options.singleton,\n })\n }\n\n static registerValue<T>(token: string, value: T) {\n this.registry.set(token, { type: 'value', value })\n }\n\n static resolve<T>(target: Class<T>): T {\n const paramTypes = Reflect.getMetadata('design:paramtypes', target) || []\n\n const injectMetadata: Record<number, string> =\n Reflect.getOwnMetadata('inject:params', target) || {}\n\n const params = paramTypes.map((_: any, index: number) => {\n const token = injectMetadata[index]\n\n if (!token) {\n throw new Error(\n `Missing @Inject token for parameter index ${index} in ${target.name}`\n )\n }\n\n return this.resolveToken(token)\n })\n\n return new target(...params)\n }\n\n static resolveToken(token: string): any {\n const registration = this.registry.get(token)\n\n if (!registration) {\n throw new Error(\n `\"${token}\" not registered. Please register it in the container.`\n )\n }\n\n if (registration.type === 'value') {\n return registration.value\n }\n\n const { myClass, singleton } = registration\n\n if (singleton) {\n if (!this.singletons.has(token)) {\n const instance = this.resolve(myClass)\n this.singletons.set(token, instance)\n }\n return this.singletons.get(token)\n }\n\n return this.resolve(myClass)\n }\n}\n\nexport function Inject(token: string): ParameterDecorator {\n return (\n target: object,\n _propertyKey: string | symbol | undefined,\n parameterIndex: number\n ): void => {\n const constructor =\n typeof target === 'function' ? target : target.constructor\n\n const existingInjectedParams: Record<number, string> =\n Reflect.getOwnMetadata('inject:params', constructor) || {}\n\n existingInjectedParams[parameterIndex] = token\n\n Reflect.defineMetadata('inject:params', existingInjectedParams, constructor)\n }\n}\n"],"mappings":";;;;AAAA,OAAO;AAQP,IAAqBA,sBAArB,MAAqBA;EARrB,OAQqBA;;;EACnB,OAAOC,WAAW,oBAAIC,IAAAA;EACtB,OAAOC,aAAa,oBAAID,IAAAA;EAExB,OAAOE,SACLC,OACAC,SACAC,SACA;AACA,SAAKN,SAASO,IAAIH,OA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AW,aAAaA,SAASA,OAAOoB;AAEjD,UAAMC,yBACJnB,QAAQG,eAAe,iBAAiBe,WAAAA,KAAgB,CAAC;AAE3DC,2BAAuBF,cAAAA,IAAkB5B;AAEzCW,YAAQoB,eAAe,iBAAiBD,wBAAwBD,WAAAA;EAClE;AACF;AAhBgBH;","names":["DependencyContainer","registry","Map","singletons","register","token","myClass","options","set","type","singleton","registerValue","value","resolve","target","paramTypes","Reflect","getMetadata","injectMetadata","getOwnMetadata","params","map","_","index","Error","name","resolveToken","registration","get","has","instance","Inject","_propertyKey","parameterIndex","constructor","existingInjectedParams","defineMetadata"]}
1
+ {"version":3,"sources":["../../../src/core/decorators/dependency-container.ts"],"sourcesContent":["import 'reflect-metadata'\n\ntype Class<T = any> = new (...args: any[]) => T\n\ntype Registration =\n | { type: 'class'; myClass: Class; singleton: boolean }\n | { type: 'value'; value: any }\n\nexport class DependencyContainer {\n static registry = new Map<string, Registration>()\n static singletons = new Map<string, any>()\n\n static register<T>(\n token: string,\n myClass: Class<T>,\n options: { singleton: boolean }\n ) {\n this.registry.set(token, {\n type: 'class',\n myClass,\n singleton: options.singleton,\n })\n }\n\n static registerValue<T>(token: string, value: T) {\n this.registry.set(token, { type: 'value', value })\n }\n\n static resolve<T>(target: Class<T>): T {\n const paramTypes = Reflect.getMetadata('design:paramtypes', target) || []\n\n const injectMetadata: Record<number, string> =\n Reflect.getOwnMetadata('inject:params', target) || {}\n\n const params = paramTypes.map((_: any, index: number) => {\n const token = injectMetadata[index]\n\n if (!token) {\n throw new Error(\n `Missing @Inject token for parameter index ${index} in ${target.name}`\n )\n }\n\n return this.resolveToken(token)\n })\n\n return new target(...params)\n }\n\n static resolveToken(token: string): any {\n const registration = this.registry.get(token)\n\n if (!registration) {\n throw new Error(\n `\"${token}\" not registered. Please register it in the container.`\n )\n }\n\n if (registration.type === 'value') {\n return registration.value\n }\n\n const { myClass, singleton } = registration\n\n if (singleton) {\n if (!this.singletons.has(token)) {\n const instance = this.resolve(myClass)\n this.singletons.set(token, instance)\n }\n return this.singletons.get(token)\n }\n\n return this.resolve(myClass)\n }\n}\n\nexport function Inject(token: string): ParameterDecorator {\n return (\n target: object,\n _propertyKey: string | symbol | undefined,\n parameterIndex: number\n ): void => {\n const constructor =\n typeof target === 'function' ? target : target.constructor\n\n const existingInjectedParams: Record<number, string> =\n Reflect.getOwnMetadata('inject:params', constructor) || {}\n\n existingInjectedParams[parameterIndex] = token\n\n Reflect.defineMetadata('inject:params', existingInjectedParams, constructor)\n }\n}\n"],"mappings":";;;;AAAA,OAAO;AAQA,IAAMA,sBAAN,MAAMA;EARb,OAQaA;;;EACX,OAAOC,WAAW,oBAAIC,IAAAA;EACtB,OAAOC,aAAa,oBAAID,IAAAA;EAExB,OAAOE,SACLC,OACAC,SACAC,SACA;AACA,SAAKN,SAASO,IAAIH,OAAO;MACvBI,MAAM;MACNH;MACAI,WAAWH,QAAQG;IACrB,CAAA;EACF;EAEA,OAAOC,cAAiBN,OAAeO,OAAU;AAC/C,SAAKX,SAASO,IAAIH,OAAO;MAAEI,MAAM;MAASG;IAAM,CAAA;EAClD;EAEA,OAAOC,QAAWC,QAAqB;AACrC,UAAMC,aAAaC,QAAQC,YAAY,qBAAqBH,MAAAA,KAAW,CAAA;AAEvE,UAAMI,iBACJF,QAAQG,eAAe,iBAAiBL,MAAAA,KAAW,CAAC;AAEtD,UAAMM,SAASL,WAAWM,IAAI,CAACC,GAAQC,UAAAA;AACrC,YAAMlB,QAAQa,eAAeK,KAAAA;AAE7B,UAAI,CAAClB,OAAO;AACV,cAAM,IAAImB,MACR,6CAA6CD,KAAAA,OAAYT,OAAOW,IAAI,EAAE;MAE1E;AAEA,aAAO,KAAKC,aAAarB,KAAAA;IAC3B,CAAA;AAEA,WAAO,IAAIS,OAAAA,GAAUM,MAAAA;EACvB;EAEA,OAAOM,aAAarB,OAAoB;AACtC,UAAMsB,eAAe,KAAK1B,SAAS2B,IAAIvB,KAAAA;AAEvC,QAAI,CAACsB,cAAc;AACjB,YAAM,IAAIH,MACR,IAAInB,KAAAA,wDAA6D;IAErE;AAEA,QAAIsB,aAAalB,SAAS,SAAS;AACjC,aAAOkB,aAAaf;IACtB;AAEA,UAAM,EAAEN,SAASI,UAAS,IAAKiB;AAE/B,QAAIjB,WAAW;AACb,UAAI,CAAC,KAAKP,WAAW0B,IAAIxB,KAAAA,GAAQ;AAC/B,cAAMyB,WAAW,KAAKjB,QAAQP,OAAAA;AAC9B,aAAKH,WAAWK,IAAIH,OAAOyB,QAAAA;MAC7B;AACA,aAAO,KAAK3B,WAAWyB,IAAIvB,KAAAA;IAC7B;AAEA,WAAO,KAAKQ,QAAQP,OAAAA;EACtB;AACF;AAEO,SAASyB,OAAO1B,OAAa;AAClC,SAAO,CACLS,QACAkB,cACAC,mBAAAA;AAEA,UAAMC,cACJ,OAAOpB,WAAW,aAAaA,SAASA,OAAOoB;AAEjD,UAAMC,yBACJnB,QAAQG,eAAe,iBAAiBe,WAAAA,KAAgB,CAAC;AAE3DC,2BAAuBF,cAAAA,IAAkB5B;AAEzCW,YAAQoB,eAAe,iBAAiBD,wBAAwBD,WAAAA;EAClE;AACF;AAhBgBH;","names":["DependencyContainer","registry","Map","singletons","register","token","myClass","options","set","type","singleton","registerValue","value","resolve","target","paramTypes","Reflect","getMetadata","injectMetadata","getOwnMetadata","params","map","_","index","Error","name","resolveToken","registration","get","has","instance","Inject","_propertyKey","parameterIndex","constructor","existingInjectedParams","defineMetadata"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/core/entities/aggregate-root.ts","../../../src/core/entities/unique-entity-id.ts","../../../src/core/entities/entity.ts"],"sourcesContent":["import { CommonDTO } from './common-dto'\nimport { Entity } from './entity'\n\nexport abstract class AggregateRoot<\n Props extends CommonDTO,\n> extends Entity<Props> {}\n","import { randomUUID } from 'node:crypto'\n\nexport class UniqueEntityId {\n private value: string\n\n constructor(value?: string) {\n this.value = value ?? randomUUID()\n }\n\n toString() {\n return this.value\n }\n\n toValue() {\n return this.value\n }\n\n public equals(id: UniqueEntityId) {\n return id.toValue() === this.toValue()\n }\n}\n","import { CommonDTO } from './common-dto'\nimport { UniqueEntityId } from './unique-entity-id'\n\nexport abstract class Entity<Props extends CommonDTO> {\n private _id: UniqueEntityId\n protected props: Props\n\n get id() {\n return this._id\n }\n\n set id(id: UniqueEntityId) {\n this._id = id\n }\n\n get createdAt() {\n return this.props.createdAt\n }\n\n set createdAt(date: Date) {\n this.props.createdAt = date\n }\n\n get updatedAt(): Date | undefined | null {\n return this.props.updatedAt\n }\n\n public touch() {\n this.props.updatedAt = new Date()\n }\n\n protected constructor(props: Props, id?: UniqueEntityId) {\n this._id = id ?? new UniqueEntityId(id)\n this.props = props\n }\n\n public equals(entity: Entity<any>) {\n if (entity === this) {\n return true\n }\n\n if (entity.id === this._id) {\n return true\n }\n\n return false\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA;;;;;;;ACDA,yBAA2B;AAEpB,IAAMA,iBAAN,MAAMA;EAFb,OAEaA;;;EACHC;EAERC,YAAYD,OAAgB;AAC1B,SAAKA,QAAQA,aAASE,+BAAAA;EACxB;EAEAC,WAAW;AACT,WAAO,KAAKH;EACd;EAEAI,UAAU;AACR,WAAO,KAAKJ;EACd;EAEOK,OAAOC,IAAoB;AAChC,WAAOA,GAAGF,QAAO,MAAO,KAAKA,QAAO;EACtC;AACF;;;ACjBO,IAAeG,SAAf,MAAeA;EAFtB,OAEsBA;;;EACZC;EACEC;EAEV,IAAIC,KAAK;AACP,WAAO,KAAKF;EACd;EAEA,IAAIE,GAAGA,IAAoB;AACzB,SAAKF,MAAME;EACb;EAEA,IAAIC,YAAY;AACd,WAAO,KAAKF,MAAME;EACpB;EAEA,IAAIA,UAAUC,MAAY;AACxB,SAAKH,MAAME,YAAYC;EACzB;EAEA,IAAIC,YAAqC;AACvC,WAAO,KAAKJ,MAAMI;EACpB;EAEOC,QAAQ;AACb,SAAKL,MAAMI,YAAY,oBAAIE,KAAAA;EAC7B;EAEA,YAAsBN,OAAcC,IAAqB;AACvD,SAAKF,MAAME,MAAM,IAAIM,eAAeN,EAAAA;AACpC,SAAKD,QAAQA;EACf;EAEOQ,OAAOC,QAAqB;AACjC,QAAIA,WAAW,MAAM;AACnB,aAAO;IACT;AAEA,QAAIA,OAAOR,OAAO,KAAKF,KAAK;AAC1B,aAAO;IACT;AAEA,WAAO;EACT;AACF;;;AF5CO,IAAeW,gBAAf,cAEGC,OAAAA;EAJV,OAIUA;;;AAAe;","names":["UniqueEntityId","value","constructor","randomUUID","toString","toValue","equals","id","Entity","_id","props","id","createdAt","date","updatedAt","touch","Date","UniqueEntityId","equals","entity","AggregateRoot","Entity"]}
1
+ {"version":3,"sources":["../../../src/core/entities/aggregate-root.ts","../../../src/core/entities/unique-entity-id.ts","../../../src/core/entities/entity.ts"],"sourcesContent":["import { Entity } from './entity'\n\nexport abstract class AggregateRoot<Props> extends Entity<Props> {}\n","import { randomUUID } from 'node:crypto'\n\nexport class UniqueEntityId {\n private value: string\n\n constructor(value?: string) {\n this.value = value ?? randomUUID()\n }\n\n toString() {\n return this.value\n }\n\n toValue() {\n return this.value\n }\n\n public equals(id: UniqueEntityId) {\n return id.toValue() === this.toValue()\n }\n}\n","import { CommonDTO } from './common-dto'\nimport { UniqueEntityId } from './unique-entity-id'\n\ntype PropsWithCommonDTO<Props> = Props & CommonDTO\n\nexport abstract class Entity<Props> {\n private _id: UniqueEntityId\n protected props: PropsWithCommonDTO<Props>\n\n get id() {\n return this._id\n }\n\n set id(id: UniqueEntityId) {\n this._id = id\n }\n\n get createdAt() {\n return this.props.createdAt\n }\n\n set createdAt(date: Date) {\n this.props.createdAt = date\n }\n\n get updatedAt(): Date | undefined | null {\n return this.props.updatedAt\n }\n\n public touch() {\n this.props.updatedAt = new Date()\n }\n\n protected constructor(props: PropsWithCommonDTO<Props>, id?: UniqueEntityId) {\n this._id = id ?? new UniqueEntityId(id)\n this.props = props\n }\n\n public equals(entity: Entity<any>) {\n if (entity === this) {\n return true\n }\n\n if (entity.id === this._id) {\n return true\n }\n\n return false\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACAA,yBAA2B;AAEpB,IAAMA,iBAAN,MAAMA;EAFb,OAEaA;;;EACHC;EAERC,YAAYD,OAAgB;AAC1B,SAAKA,QAAQA,aAASE,+BAAAA;EACxB;EAEAC,WAAW;AACT,WAAO,KAAKH;EACd;EAEAI,UAAU;AACR,WAAO,KAAKJ;EACd;EAEOK,OAAOC,IAAoB;AAChC,WAAOA,GAAGF,QAAO,MAAO,KAAKA,QAAO;EACtC;AACF;;;ACfO,IAAeG,SAAf,MAAeA;EAJtB,OAIsBA;;;EACZC;EACEC;EAEV,IAAIC,KAAK;AACP,WAAO,KAAKF;EACd;EAEA,IAAIE,GAAGA,IAAoB;AACzB,SAAKF,MAAME;EACb;EAEA,IAAIC,YAAY;AACd,WAAO,KAAKF,MAAME;EACpB;EAEA,IAAIA,UAAUC,MAAY;AACxB,SAAKH,MAAME,YAAYC;EACzB;EAEA,IAAIC,YAAqC;AACvC,WAAO,KAAKJ,MAAMI;EACpB;EAEOC,QAAQ;AACb,SAAKL,MAAMI,YAAY,oBAAIE,KAAAA;EAC7B;EAEA,YAAsBN,OAAkCC,IAAqB;AAC3E,SAAKF,MAAME,MAAM,IAAIM,eAAeN,EAAAA;AACpC,SAAKD,QAAQA;EACf;EAEOQ,OAAOC,QAAqB;AACjC,QAAIA,WAAW,MAAM;AACnB,aAAO;IACT;AAEA,QAAIA,OAAOR,OAAO,KAAKF,KAAK;AAC1B,aAAO;IACT;AAEA,WAAO;EACT;AACF;;;AF/CO,IAAeW,gBAAf,cAA4CC,OAAAA;EAFnD,OAEmDA;;;AAAe;","names":["UniqueEntityId","value","constructor","randomUUID","toString","toValue","equals","id","Entity","_id","props","id","createdAt","date","updatedAt","touch","Date","UniqueEntityId","equals","entity","AggregateRoot","Entity"]}
@@ -1,8 +1,8 @@
1
- import { CommonDTO } from './common-dto.cjs';
2
1
  import { Entity } from './entity.cjs';
2
+ import './common-dto.cjs';
3
3
  import './unique-entity-id.cjs';
4
4
 
5
- declare abstract class AggregateRoot<Props extends CommonDTO> extends Entity<Props> {
5
+ declare abstract class AggregateRoot<Props> extends Entity<Props> {
6
6
  }
7
7
 
8
8
  export { AggregateRoot };
@@ -1,8 +1,8 @@
1
- import { CommonDTO } from './common-dto.js';
2
1
  import { Entity } from './entity.js';
2
+ import './common-dto.js';
3
3
  import './unique-entity-id.js';
4
4
 
5
- declare abstract class AggregateRoot<Props extends CommonDTO> extends Entity<Props> {
5
+ declare abstract class AggregateRoot<Props> extends Entity<Props> {
6
6
  }
7
7
 
8
8
  export { AggregateRoot };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/core/entities/unique-entity-id.ts","../../../src/core/entities/entity.ts","../../../src/core/entities/aggregate-root.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto'\n\nexport class UniqueEntityId {\n private value: string\n\n constructor(value?: string) {\n this.value = value ?? randomUUID()\n }\n\n toString() {\n return this.value\n }\n\n toValue() {\n return this.value\n }\n\n public equals(id: UniqueEntityId) {\n return id.toValue() === this.toValue()\n }\n}\n","import { CommonDTO } from './common-dto'\nimport { UniqueEntityId } from './unique-entity-id'\n\nexport abstract class Entity<Props extends CommonDTO> {\n private _id: UniqueEntityId\n protected props: Props\n\n get id() {\n return this._id\n }\n\n set id(id: UniqueEntityId) {\n this._id = id\n }\n\n get createdAt() {\n return this.props.createdAt\n }\n\n set createdAt(date: Date) {\n this.props.createdAt = date\n }\n\n get updatedAt(): Date | undefined | null {\n return this.props.updatedAt\n }\n\n public touch() {\n this.props.updatedAt = new Date()\n }\n\n protected constructor(props: Props, id?: UniqueEntityId) {\n this._id = id ?? new UniqueEntityId(id)\n this.props = props\n }\n\n public equals(entity: Entity<any>) {\n if (entity === this) {\n return true\n }\n\n if (entity.id === this._id) {\n return true\n }\n\n return false\n }\n}\n","import { CommonDTO } from './common-dto'\nimport { Entity } from './entity'\n\nexport abstract class AggregateRoot<\n Props extends CommonDTO,\n> extends Entity<Props> {}\n"],"mappings":";;;;AAAA,SAASA,kBAAkB;AAEpB,IAAMC,iBAAN,MAAMA;EAFb,OAEaA;;;EACHC;EAERC,YAAYD,OAAgB;AAC1B,SAAKA,QAAQA,SAASE,WAAAA;EACxB;EAEAC,WAAW;AACT,WAAO,KAAKH;EACd;EAEAI,UAAU;AACR,WAAO,KAAKJ;EACd;EAEOK,OAAOC,IAAoB;AAChC,WAAOA,GAAGF,QAAO,MAAO,KAAKA,QAAO;EACtC;AACF;;;ACjBO,IAAeG,SAAf,MAAeA;EAFtB,OAEsBA;;;EACZC;EACEC;EAEV,IAAIC,KAAK;AACP,WAAO,KAAKF;EACd;EAEA,IAAIE,GAAGA,IAAoB;AACzB,SAAKF,MAAME;EACb;EAEA,IAAIC,YAAY;AACd,WAAO,KAAKF,MAAME;EACpB;EAEA,IAAIA,UAAUC,MAAY;AACxB,SAAKH,MAAME,YAAYC;EACzB;EAEA,IAAIC,YAAqC;AACvC,WAAO,KAAKJ,MAAMI;EACpB;EAEOC,QAAQ;AACb,SAAKL,MAAMI,YAAY,oBAAIE,KAAAA;EAC7B;EAEA,YAAsBN,OAAcC,IAAqB;AACvD,SAAKF,MAAME,MAAM,IAAIM,eAAeN,EAAAA;AACpC,SAAKD,QAAQA;EACf;EAEOQ,OAAOC,QAAqB;AACjC,QAAIA,WAAW,MAAM;AACnB,aAAO;IACT;AAEA,QAAIA,OAAOR,OAAO,KAAKF,KAAK;AAC1B,aAAO;IACT;AAEA,WAAO;EACT;AACF;;;AC5CO,IAAeW,gBAAf,cAEGC,OAAAA;EAJV,OAIUA;;;AAAe;","names":["randomUUID","UniqueEntityId","value","constructor","randomUUID","toString","toValue","equals","id","Entity","_id","props","id","createdAt","date","updatedAt","touch","Date","UniqueEntityId","equals","entity","AggregateRoot","Entity"]}
1
+ {"version":3,"sources":["../../../src/core/entities/unique-entity-id.ts","../../../src/core/entities/entity.ts","../../../src/core/entities/aggregate-root.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto'\n\nexport class UniqueEntityId {\n private value: string\n\n constructor(value?: string) {\n this.value = value ?? randomUUID()\n }\n\n toString() {\n return this.value\n }\n\n toValue() {\n return this.value\n }\n\n public equals(id: UniqueEntityId) {\n return id.toValue() === this.toValue()\n }\n}\n","import { CommonDTO } from './common-dto'\nimport { UniqueEntityId } from './unique-entity-id'\n\ntype PropsWithCommonDTO<Props> = Props & CommonDTO\n\nexport abstract class Entity<Props> {\n private _id: UniqueEntityId\n protected props: PropsWithCommonDTO<Props>\n\n get id() {\n return this._id\n }\n\n set id(id: UniqueEntityId) {\n this._id = id\n }\n\n get createdAt() {\n return this.props.createdAt\n }\n\n set createdAt(date: Date) {\n this.props.createdAt = date\n }\n\n get updatedAt(): Date | undefined | null {\n return this.props.updatedAt\n }\n\n public touch() {\n this.props.updatedAt = new Date()\n }\n\n protected constructor(props: PropsWithCommonDTO<Props>, id?: UniqueEntityId) {\n this._id = id ?? new UniqueEntityId(id)\n this.props = props\n }\n\n public equals(entity: Entity<any>) {\n if (entity === this) {\n return true\n }\n\n if (entity.id === this._id) {\n return true\n }\n\n return false\n }\n}\n","import { Entity } from './entity'\n\nexport abstract class AggregateRoot<Props> extends Entity<Props> {}\n"],"mappings":";;;;AAAA,SAASA,kBAAkB;AAEpB,IAAMC,iBAAN,MAAMA;EAFb,OAEaA;;;EACHC;EAERC,YAAYD,OAAgB;AAC1B,SAAKA,QAAQA,SAASE,WAAAA;EACxB;EAEAC,WAAW;AACT,WAAO,KAAKH;EACd;EAEAI,UAAU;AACR,WAAO,KAAKJ;EACd;EAEOK,OAAOC,IAAoB;AAChC,WAAOA,GAAGF,QAAO,MAAO,KAAKA,QAAO;EACtC;AACF;;;ACfO,IAAeG,SAAf,MAAeA;EAJtB,OAIsBA;;;EACZC;EACEC;EAEV,IAAIC,KAAK;AACP,WAAO,KAAKF;EACd;EAEA,IAAIE,GAAGA,IAAoB;AACzB,SAAKF,MAAME;EACb;EAEA,IAAIC,YAAY;AACd,WAAO,KAAKF,MAAME;EACpB;EAEA,IAAIA,UAAUC,MAAY;AACxB,SAAKH,MAAME,YAAYC;EACzB;EAEA,IAAIC,YAAqC;AACvC,WAAO,KAAKJ,MAAMI;EACpB;EAEOC,QAAQ;AACb,SAAKL,MAAMI,YAAY,oBAAIE,KAAAA;EAC7B;EAEA,YAAsBN,OAAkCC,IAAqB;AAC3E,SAAKF,MAAME,MAAM,IAAIM,eAAeN,EAAAA;AACpC,SAAKD,QAAQA;EACf;EAEOQ,OAAOC,QAAqB;AACjC,QAAIA,WAAW,MAAM;AACnB,aAAO;IACT;AAEA,QAAIA,OAAOR,OAAO,KAAKF,KAAK;AAC1B,aAAO;IACT;AAEA,WAAO;EACT;AACF;;;AC/CO,IAAeW,gBAAf,cAA4CC,OAAAA;EAFnD,OAEmDA;;;AAAe;","names":["randomUUID","UniqueEntityId","value","constructor","randomUUID","toString","toValue","equals","id","Entity","_id","props","id","createdAt","date","updatedAt","touch","Date","UniqueEntityId","equals","entity","AggregateRoot","Entity"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/core/entities/common-dto.ts"],"sourcesContent":["export type CommonDTO = {\n createdAt: Date\n updatedAt?: Date | null\n}\n\nexport type CreateCommonDTO = {\n createdAt?: Date\n updatedAt?: Date\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAKA;;","names":[]}
1
+ {"version":3,"sources":["../../../src/core/entities/common-dto.ts"],"sourcesContent":["export type CommonDTO = {\n createdAt: Date\n updatedAt: Date | null\n}\n\nexport type CreateCommonDTO = {\n createdAt?: Date\n updatedAt?: Date | null\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAKA;;","names":[]}
@@ -1,10 +1,10 @@
1
1
  type CommonDTO = {
2
2
  createdAt: Date;
3
- updatedAt?: Date | null;
3
+ updatedAt: Date | null;
4
4
  };
5
5
  type CreateCommonDTO = {
6
6
  createdAt?: Date;
7
- updatedAt?: Date;
7
+ updatedAt?: Date | null;
8
8
  };
9
9
 
10
10
  export { CommonDTO, CreateCommonDTO };
@@ -1,10 +1,10 @@
1
1
  type CommonDTO = {
2
2
  createdAt: Date;
3
- updatedAt?: Date | null;
3
+ updatedAt: Date | null;
4
4
  };
5
5
  type CreateCommonDTO = {
6
6
  createdAt?: Date;
7
- updatedAt?: Date;
7
+ updatedAt?: Date | null;
8
8
  };
9
9
 
10
10
  export { CommonDTO, CreateCommonDTO };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/core/entities/entity.ts","../../../src/core/entities/unique-entity-id.ts"],"sourcesContent":["import { CommonDTO } from './common-dto'\nimport { UniqueEntityId } from './unique-entity-id'\n\nexport abstract class Entity<Props extends CommonDTO> {\n private _id: UniqueEntityId\n protected props: Props\n\n get id() {\n return this._id\n }\n\n set id(id: UniqueEntityId) {\n this._id = id\n }\n\n get createdAt() {\n return this.props.createdAt\n }\n\n set createdAt(date: Date) {\n this.props.createdAt = date\n }\n\n get updatedAt(): Date | undefined | null {\n return this.props.updatedAt\n }\n\n public touch() {\n this.props.updatedAt = new Date()\n }\n\n protected constructor(props: Props, id?: UniqueEntityId) {\n this._id = id ?? new UniqueEntityId(id)\n this.props = props\n }\n\n public equals(entity: Entity<any>) {\n if (entity === this) {\n return true\n }\n\n if (entity.id === this._id) {\n return true\n }\n\n return false\n }\n}\n","import { randomUUID } from 'node:crypto'\n\nexport class UniqueEntityId {\n private value: string\n\n constructor(value?: string) {\n this.value = value ?? randomUUID()\n }\n\n toString() {\n return this.value\n }\n\n toValue() {\n return this.value\n }\n\n public equals(id: UniqueEntityId) {\n return id.toValue() === this.toValue()\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA;;;;;;;ACDA,yBAA2B;AAEpB,IAAMA,iBAAN,MAAMA;EAFb,OAEaA;;;EACHC;EAERC,YAAYD,OAAgB;AAC1B,SAAKA,QAAQA,aAASE,+BAAAA;EACxB;EAEAC,WAAW;AACT,WAAO,KAAKH;EACd;EAEAI,UAAU;AACR,WAAO,KAAKJ;EACd;EAEOK,OAAOC,IAAoB;AAChC,WAAOA,GAAGF,QAAO,MAAO,KAAKA,QAAO;EACtC;AACF;;;ADjBO,IAAeG,SAAf,MAAeA;EAFtB,OAEsBA;;;EACZC;EACEC;EAEV,IAAIC,KAAK;AACP,WAAO,KAAKF;EACd;EAEA,IAAIE,GAAGA,IAAoB;AACzB,SAAKF,MAAME;EACb;EAEA,IAAIC,YAAY;AACd,WAAO,KAAKF,MAAME;EACpB;EAEA,IAAIA,UAAUC,MAAY;AACxB,SAAKH,MAAME,YAAYC;EACzB;EAEA,IAAIC,YAAqC;AACvC,WAAO,KAAKJ,MAAMI;EACpB;EAEOC,QAAQ;AACb,SAAKL,MAAMI,YAAY,oBAAIE,KAAAA;EAC7B;EAEA,YAAsBN,OAAcC,IAAqB;AACvD,SAAKF,MAAME,MAAM,IAAIM,eAAeN,EAAAA;AACpC,SAAKD,QAAQA;EACf;EAEOQ,OAAOC,QAAqB;AACjC,QAAIA,WAAW,MAAM;AACnB,aAAO;IACT;AAEA,QAAIA,OAAOR,OAAO,KAAKF,KAAK;AAC1B,aAAO;IACT;AAEA,WAAO;EACT;AACF;","names":["UniqueEntityId","value","constructor","randomUUID","toString","toValue","equals","id","Entity","_id","props","id","createdAt","date","updatedAt","touch","Date","UniqueEntityId","equals","entity"]}
1
+ {"version":3,"sources":["../../../src/core/entities/entity.ts","../../../src/core/entities/unique-entity-id.ts"],"sourcesContent":["import { CommonDTO } from './common-dto'\nimport { UniqueEntityId } from './unique-entity-id'\n\ntype PropsWithCommonDTO<Props> = Props & CommonDTO\n\nexport abstract class Entity<Props> {\n private _id: UniqueEntityId\n protected props: PropsWithCommonDTO<Props>\n\n get id() {\n return this._id\n }\n\n set id(id: UniqueEntityId) {\n this._id = id\n }\n\n get createdAt() {\n return this.props.createdAt\n }\n\n set createdAt(date: Date) {\n this.props.createdAt = date\n }\n\n get updatedAt(): Date | undefined | null {\n return this.props.updatedAt\n }\n\n public touch() {\n this.props.updatedAt = new Date()\n }\n\n protected constructor(props: PropsWithCommonDTO<Props>, id?: UniqueEntityId) {\n this._id = id ?? new UniqueEntityId(id)\n this.props = props\n }\n\n public equals(entity: Entity<any>) {\n if (entity === this) {\n return true\n }\n\n if (entity.id === this._id) {\n return true\n }\n\n return false\n }\n}\n","import { randomUUID } from 'node:crypto'\n\nexport class UniqueEntityId {\n private value: string\n\n constructor(value?: string) {\n this.value = value ?? randomUUID()\n }\n\n toString() {\n return this.value\n }\n\n toValue() {\n return this.value\n }\n\n public equals(id: UniqueEntityId) {\n return id.toValue() === this.toValue()\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA;;;;;;;ACDA,yBAA2B;AAEpB,IAAMA,iBAAN,MAAMA;EAFb,OAEaA;;;EACHC;EAERC,YAAYD,OAAgB;AAC1B,SAAKA,QAAQA,aAASE,+BAAAA;EACxB;EAEAC,WAAW;AACT,WAAO,KAAKH;EACd;EAEAI,UAAU;AACR,WAAO,KAAKJ;EACd;EAEOK,OAAOC,IAAoB;AAChC,WAAOA,GAAGF,QAAO,MAAO,KAAKA,QAAO;EACtC;AACF;;;ADfO,IAAeG,SAAf,MAAeA;EAJtB,OAIsBA;;;EACZC;EACEC;EAEV,IAAIC,KAAK;AACP,WAAO,KAAKF;EACd;EAEA,IAAIE,GAAGA,IAAoB;AACzB,SAAKF,MAAME;EACb;EAEA,IAAIC,YAAY;AACd,WAAO,KAAKF,MAAME;EACpB;EAEA,IAAIA,UAAUC,MAAY;AACxB,SAAKH,MAAME,YAAYC;EACzB;EAEA,IAAIC,YAAqC;AACvC,WAAO,KAAKJ,MAAMI;EACpB;EAEOC,QAAQ;AACb,SAAKL,MAAMI,YAAY,oBAAIE,KAAAA;EAC7B;EAEA,YAAsBN,OAAkCC,IAAqB;AAC3E,SAAKF,MAAME,MAAM,IAAIM,eAAeN,EAAAA;AACpC,SAAKD,QAAQA;EACf;EAEOQ,OAAOC,QAAqB;AACjC,QAAIA,WAAW,MAAM;AACnB,aAAO;IACT;AAEA,QAAIA,OAAOR,OAAO,KAAKF,KAAK;AAC1B,aAAO;IACT;AAEA,WAAO;EACT;AACF;","names":["UniqueEntityId","value","constructor","randomUUID","toString","toValue","equals","id","Entity","_id","props","id","createdAt","date","updatedAt","touch","Date","UniqueEntityId","equals","entity"]}
@@ -1,16 +1,17 @@
1
1
  import { CommonDTO } from './common-dto.cjs';
2
2
  import { UniqueEntityId } from './unique-entity-id.cjs';
3
3
 
4
- declare abstract class Entity<Props extends CommonDTO> {
4
+ type PropsWithCommonDTO<Props> = Props & CommonDTO;
5
+ declare abstract class Entity<Props> {
5
6
  private _id;
6
- protected props: Props;
7
+ protected props: PropsWithCommonDTO<Props>;
7
8
  get id(): UniqueEntityId;
8
9
  set id(id: UniqueEntityId);
9
10
  get createdAt(): Date;
10
11
  set createdAt(date: Date);
11
12
  get updatedAt(): Date | undefined | null;
12
13
  touch(): void;
13
- protected constructor(props: Props, id?: UniqueEntityId);
14
+ protected constructor(props: PropsWithCommonDTO<Props>, id?: UniqueEntityId);
14
15
  equals(entity: Entity<any>): boolean;
15
16
  }
16
17
 
@@ -1,16 +1,17 @@
1
1
  import { CommonDTO } from './common-dto.js';
2
2
  import { UniqueEntityId } from './unique-entity-id.js';
3
3
 
4
- declare abstract class Entity<Props extends CommonDTO> {
4
+ type PropsWithCommonDTO<Props> = Props & CommonDTO;
5
+ declare abstract class Entity<Props> {
5
6
  private _id;
6
- protected props: Props;
7
+ protected props: PropsWithCommonDTO<Props>;
7
8
  get id(): UniqueEntityId;
8
9
  set id(id: UniqueEntityId);
9
10
  get createdAt(): Date;
10
11
  set createdAt(date: Date);
11
12
  get updatedAt(): Date | undefined | null;
12
13
  touch(): void;
13
- protected constructor(props: Props, id?: UniqueEntityId);
14
+ protected constructor(props: PropsWithCommonDTO<Props>, id?: UniqueEntityId);
14
15
  equals(entity: Entity<any>): boolean;
15
16
  }
16
17
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/core/entities/unique-entity-id.ts","../../../src/core/entities/entity.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto'\n\nexport class UniqueEntityId {\n private value: string\n\n constructor(value?: string) {\n this.value = value ?? randomUUID()\n }\n\n toString() {\n return this.value\n }\n\n toValue() {\n return this.value\n }\n\n public equals(id: UniqueEntityId) {\n return id.toValue() === this.toValue()\n }\n}\n","import { CommonDTO } from './common-dto'\nimport { UniqueEntityId } from './unique-entity-id'\n\nexport abstract class Entity<Props extends CommonDTO> {\n private _id: UniqueEntityId\n protected props: Props\n\n get id() {\n return this._id\n }\n\n set id(id: UniqueEntityId) {\n this._id = id\n }\n\n get createdAt() {\n return this.props.createdAt\n }\n\n set createdAt(date: Date) {\n this.props.createdAt = date\n }\n\n get updatedAt(): Date | undefined | null {\n return this.props.updatedAt\n }\n\n public touch() {\n this.props.updatedAt = new Date()\n }\n\n protected constructor(props: Props, id?: UniqueEntityId) {\n this._id = id ?? new UniqueEntityId(id)\n this.props = props\n }\n\n public equals(entity: Entity<any>) {\n if (entity === this) {\n return true\n }\n\n if (entity.id === this._id) {\n return true\n }\n\n return false\n }\n}\n"],"mappings":";;;;AAAA,SAASA,kBAAkB;AAEpB,IAAMC,iBAAN,MAAMA;EAFb,OAEaA;;;EACHC;EAERC,YAAYD,OAAgB;AAC1B,SAAKA,QAAQA,SAASE,WAAAA;EACxB;EAEAC,WAAW;AACT,WAAO,KAAKH;EACd;EAEAI,UAAU;AACR,WAAO,KAAKJ;EACd;EAEOK,OAAOC,IAAoB;AAChC,WAAOA,GAAGF,QAAO,MAAO,KAAKA,QAAO;EACtC;AACF;;;ACjBO,IAAeG,SAAf,MAAeA;EAFtB,OAEsBA;;;EACZC;EACEC;EAEV,IAAIC,KAAK;AACP,WAAO,KAAKF;EACd;EAEA,IAAIE,GAAGA,IAAoB;AACzB,SAAKF,MAAME;EACb;EAEA,IAAIC,YAAY;AACd,WAAO,KAAKF,MAAME;EACpB;EAEA,IAAIA,UAAUC,MAAY;AACxB,SAAKH,MAAME,YAAYC;EACzB;EAEA,IAAIC,YAAqC;AACvC,WAAO,KAAKJ,MAAMI;EACpB;EAEOC,QAAQ;AACb,SAAKL,MAAMI,YAAY,oBAAIE,KAAAA;EAC7B;EAEA,YAAsBN,OAAcC,IAAqB;AACvD,SAAKF,MAAME,MAAM,IAAIM,eAAeN,EAAAA;AACpC,SAAKD,QAAQA;EACf;EAEOQ,OAAOC,QAAqB;AACjC,QAAIA,WAAW,MAAM;AACnB,aAAO;IACT;AAEA,QAAIA,OAAOR,OAAO,KAAKF,KAAK;AAC1B,aAAO;IACT;AAEA,WAAO;EACT;AACF;","names":["randomUUID","UniqueEntityId","value","constructor","randomUUID","toString","toValue","equals","id","Entity","_id","props","id","createdAt","date","updatedAt","touch","Date","UniqueEntityId","equals","entity"]}
1
+ {"version":3,"sources":["../../../src/core/entities/unique-entity-id.ts","../../../src/core/entities/entity.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto'\n\nexport class UniqueEntityId {\n private value: string\n\n constructor(value?: string) {\n this.value = value ?? randomUUID()\n }\n\n toString() {\n return this.value\n }\n\n toValue() {\n return this.value\n }\n\n public equals(id: UniqueEntityId) {\n return id.toValue() === this.toValue()\n }\n}\n","import { CommonDTO } from './common-dto'\nimport { UniqueEntityId } from './unique-entity-id'\n\ntype PropsWithCommonDTO<Props> = Props & CommonDTO\n\nexport abstract class Entity<Props> {\n private _id: UniqueEntityId\n protected props: PropsWithCommonDTO<Props>\n\n get id() {\n return this._id\n }\n\n set id(id: UniqueEntityId) {\n this._id = id\n }\n\n get createdAt() {\n return this.props.createdAt\n }\n\n set createdAt(date: Date) {\n this.props.createdAt = date\n }\n\n get updatedAt(): Date | undefined | null {\n return this.props.updatedAt\n }\n\n public touch() {\n this.props.updatedAt = new Date()\n }\n\n protected constructor(props: PropsWithCommonDTO<Props>, id?: UniqueEntityId) {\n this._id = id ?? new UniqueEntityId(id)\n this.props = props\n }\n\n public equals(entity: Entity<any>) {\n if (entity === this) {\n return true\n }\n\n if (entity.id === this._id) {\n return true\n }\n\n return false\n }\n}\n"],"mappings":";;;;AAAA,SAASA,kBAAkB;AAEpB,IAAMC,iBAAN,MAAMA;EAFb,OAEaA;;;EACHC;EAERC,YAAYD,OAAgB;AAC1B,SAAKA,QAAQA,SAASE,WAAAA;EACxB;EAEAC,WAAW;AACT,WAAO,KAAKH;EACd;EAEAI,UAAU;AACR,WAAO,KAAKJ;EACd;EAEOK,OAAOC,IAAoB;AAChC,WAAOA,GAAGF,QAAO,MAAO,KAAKA,QAAO;EACtC;AACF;;;ACfO,IAAeG,SAAf,MAAeA;EAJtB,OAIsBA;;;EACZC;EACEC;EAEV,IAAIC,KAAK;AACP,WAAO,KAAKF;EACd;EAEA,IAAIE,GAAGA,IAAoB;AACzB,SAAKF,MAAME;EACb;EAEA,IAAIC,YAAY;AACd,WAAO,KAAKF,MAAME;EACpB;EAEA,IAAIA,UAAUC,MAAY;AACxB,SAAKH,MAAME,YAAYC;EACzB;EAEA,IAAIC,YAAqC;AACvC,WAAO,KAAKJ,MAAMI;EACpB;EAEOC,QAAQ;AACb,SAAKL,MAAMI,YAAY,oBAAIE,KAAAA;EAC7B;EAEA,YAAsBN,OAAkCC,IAAqB;AAC3E,SAAKF,MAAME,MAAM,IAAIM,eAAeN,EAAAA;AACpC,SAAKD,QAAQA;EACf;EAEOQ,OAAOC,QAAqB;AACjC,QAAIA,WAAW,MAAM;AACnB,aAAO;IACT;AAEA,QAAIA,OAAOR,OAAO,KAAKF,KAAK;AAC1B,aAAO;IACT;AAEA,WAAO;EACT;AACF;","names":["randomUUID","UniqueEntityId","value","constructor","randomUUID","toString","toValue","equals","id","Entity","_id","props","id","createdAt","date","updatedAt","touch","Date","UniqueEntityId","equals","entity"]}
@@ -21,7 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  // src/core/http/base-controller.ts
22
22
  var base_controller_exports = {};
23
23
  __export(base_controller_exports, {
24
- default: () => BaseController
24
+ BaseController: () => BaseController
25
25
  });
26
26
  module.exports = __toCommonJS(base_controller_exports);
27
27
  var import_reflect_metadata2 = require("reflect-metadata");
@@ -286,4 +286,8 @@ var BaseController = class {
286
286
  return await this.handle(processedRequest);
287
287
  }
288
288
  };
289
+ // Annotate the CommonJS export names for ESM import in node:
290
+ 0 && (module.exports = {
291
+ BaseController
292
+ });
289
293
  //# sourceMappingURL=base-controller.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/core/http/base-controller.ts","../../../src/core/decorators/dependency-container.ts","../../../src/core/errors/api-common-error.ts","../../../src/core/errors/application-error.ts","../../../src/core/errors/conflict-error.ts","../../../src/core/errors/domain-error.ts","../../../src/core/errors/infra-error.ts","../../../src/core/errors/validation-error.ts"],"sourcesContent":["import 'reflect-metadata'\n\nimport DependencyContainer from '../../core/decorators/dependency-container'\nimport ApplicationError from '../../core/errors/application-error'\nimport ConflictError from '../../core/errors/conflict-error'\nimport DomainError from '../../core/errors/domain-error'\nimport InfraError from '../../core/errors/infra-error'\nimport ValidationError from '../../core/errors/validation-error'\nimport { MiddlewareFunction } from '../../infra/adapters/validators/zod/zod-validator'\nimport IErrorNotifier from './error-notifier'\n\nexport type AnyObject = Record<string, any>\n\nexport type Request = {\n body: AnyObject\n params: AnyObject\n headers: AnyObject\n query: AnyObject\n}\n\nexport type Response = {\n code: number\n data: any\n}\n\nexport type ContextError = {\n env: string\n user?: {\n id?: string\n name?: string\n email?: string\n }\n request?: {\n method?: string\n requestId?: string\n url?: string\n headers?: any\n query?: any\n body?: any\n params?: any\n }\n}\n\nexport default abstract class BaseController {\n protected readonly errorNotifier: IErrorNotifier\n\n abstract handle<T>(request: T | Request): Promise<Response>\n\n constructor() {\n this.errorNotifier = DependencyContainer.resolveToken('IErrorNotifier')\n }\n\n protected success<T>(dto?: T): Response {\n return {\n code: 200,\n data: { data: dto },\n }\n }\n\n protected noContent(): Response {\n return {\n code: 204,\n data: undefined,\n }\n }\n\n protected created<T>(dto?: T): Response {\n return {\n code: 201,\n data: dto ? { data: dto } : undefined,\n }\n }\n\n protected paginated<T>(dto?: T): Response {\n return {\n code: 200,\n data: dto,\n }\n }\n\n protected buildContextError(request: Request): ContextError {\n return {\n env: process.env.ENVIRONMENT as string,\n request: {\n body: request.body,\n headers: request.headers,\n params: request.params,\n query: request.query,\n },\n }\n }\n\n public async failure(error: Error, context: ContextError): Promise<Response> {\n if (error instanceof ConflictError) {\n return {\n code: error.props.code,\n data: {\n message: error.message,\n errorCode: error.props.errorCode,\n occurredAt: error.props.occurredAt,\n items: Array.isArray(error.conflictProps)\n ? error.conflictProps\n : [error.conflictProps],\n },\n }\n }\n\n if (\n error instanceof DomainError ||\n error instanceof ApplicationError ||\n error instanceof InfraError\n ) {\n return {\n code: error.props.code,\n data: {\n message: error.message,\n errorCode: error.props.errorCode,\n occurredAt: error.props.occurredAt,\n },\n }\n }\n\n if (error instanceof ValidationError) {\n return {\n code: error.props.code,\n data: {\n message: error.props.message,\n errorCode: error.props.errorCode,\n occurredAt: error.props.occurredAt,\n errors: error.props.errors,\n },\n }\n }\n\n if (process.env.SHOULD_NOTIFY_ERROR) {\n await this.errorNotifier.notify(error, context)\n }\n\n return {\n code: 500,\n data: {\n code: 500,\n message: 'Server failed. Contact the administrator!',\n },\n }\n }\n\n public async execute(request: Request): Promise<Response> {\n const routeMetadata = Reflect.getMetadata('route', this.constructor)\n\n if (!routeMetadata) {\n throw new InfraError('Route metadata not found.')\n }\n\n const middlewares: MiddlewareFunction[] = routeMetadata.middlewares || []\n\n let processedRequest = request\n\n if (middlewares.length) {\n for (const middleware of middlewares) {\n processedRequest = await middleware(processedRequest)\n }\n }\n\n return await this.handle(processedRequest)\n }\n}\n","import 'reflect-metadata'\n\ntype Class<T = any> = new (...args: any[]) => T\n\ntype Registration =\n | { type: 'class'; myClass: Class; singleton: boolean }\n | { type: 'value'; value: any }\n\nexport default class DependencyContainer {\n static registry = new Map<string, Registration>()\n static singletons = new Map<string, any>()\n\n static register<T>(\n token: string,\n myClass: Class<T>,\n options: { singleton: boolean }\n ) {\n this.registry.set(token, {\n type: 'class',\n myClass,\n singleton: options.singleton,\n })\n }\n\n static registerValue<T>(token: string, value: T) {\n this.registry.set(token, { type: 'value', value })\n }\n\n static resolve<T>(target: Class<T>): T {\n const paramTypes = Reflect.getMetadata('design:paramtypes', target) || []\n\n const injectMetadata: Record<number, string> =\n Reflect.getOwnMetadata('inject:params', target) || {}\n\n const params = paramTypes.map((_: any, index: number) => {\n const token = injectMetadata[index]\n\n if (!token) {\n throw new Error(\n `Missing @Inject token for parameter index ${index} in ${target.name}`\n )\n }\n\n return this.resolveToken(token)\n })\n\n return new target(...params)\n }\n\n static resolveToken(token: string): any {\n const registration = this.registry.get(token)\n\n if (!registration) {\n throw new Error(\n `\"${token}\" not registered. Please register it in the container.`\n )\n }\n\n if (registration.type === 'value') {\n return registration.value\n }\n\n const { myClass, singleton } = registration\n\n if (singleton) {\n if (!this.singletons.has(token)) {\n const instance = this.resolve(myClass)\n this.singletons.set(token, instance)\n }\n return this.singletons.get(token)\n }\n\n return this.resolve(myClass)\n }\n}\n\nexport function Inject(token: string): ParameterDecorator {\n return (\n target: object,\n _propertyKey: string | symbol | undefined,\n parameterIndex: number\n ): void => {\n const constructor =\n typeof target === 'function' ? target : target.constructor\n\n const existingInjectedParams: Record<number, string> =\n Reflect.getOwnMetadata('inject:params', constructor) || {}\n\n existingInjectedParams[parameterIndex] = token\n\n Reflect.defineMetadata('inject:params', existingInjectedParams, constructor)\n }\n}\n","export type PropertiesError = {\n receivedValue?: any\n type: string\n message: string\n property: string | number | undefined\n propertyType?: string\n path?: string\n}\n\nexport type CommonError = {\n location: string\n propertyErrors?: PropertiesError[]\n}\n\nexport type ApiCommonError = {\n code: number\n occurredAt: Date\n message: string\n errorCode: string\n errors?: CommonError[]\n}\n\nexport enum ApiErrorEnum {\n DOMAIN = 'ERR001',\n APPLICATION = 'ERR002',\n INFRA = 'ERR003',\n HTTP_CLIENT = 'ERR004',\n VALIDATOR = 'ERR005',\n}\n","import { type ApiCommonError, ApiErrorEnum } from './api-common-error'\n\nexport default class ApplicationError extends Error {\n props: ApiCommonError\n\n constructor(message: string) {\n super(message)\n this.props = {\n code: 400,\n errorCode: ApiErrorEnum.APPLICATION,\n message,\n occurredAt: new Date(),\n }\n }\n}\n","import { type ApiCommonError, ApiErrorEnum } from './api-common-error'\n\ntype ConflictProps = { id: string; [key: string]: unknown }\n\nexport default class ConflictError<T extends ConflictProps> extends Error {\n props: ApiCommonError\n conflictProps: T | T[]\n\n constructor(conflictProps: T | T[]) {\n super('Resource already exists.')\n this.conflictProps = conflictProps\n this.props = {\n code: 409,\n errorCode: ApiErrorEnum.APPLICATION,\n message: this.message,\n occurredAt: new Date(),\n }\n }\n}\n","import { type ApiCommonError, ApiErrorEnum } from './api-common-error'\n\nexport default class DomainError extends Error {\n props: ApiCommonError\n\n constructor(message: string) {\n super(message)\n this.props = {\n code: 400,\n errorCode: ApiErrorEnum.DOMAIN,\n message,\n occurredAt: new Date(),\n }\n }\n}\n","import { type ApiCommonError, ApiErrorEnum } from './api-common-error'\n\nexport default class InfraError extends Error {\n props: ApiCommonError\n\n constructor(message: string) {\n super(message)\n this.props = {\n code: 400,\n errorCode: ApiErrorEnum.INFRA,\n message,\n occurredAt: new Date(),\n }\n }\n}\n","import {\n type ApiCommonError,\n ApiErrorEnum,\n type CommonError,\n} from './api-common-error'\n\nexport default class ValidationError extends Error {\n props: ApiCommonError\n\n constructor(errors: CommonError[]) {\n super('Validation Error')\n this.props = {\n code: 400,\n errorCode: ApiErrorEnum.VALIDATOR,\n message: 'Validation Error',\n occurredAt: new Date(),\n errors,\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;IAAAA,2BAAO;;;ACAP,8BAAO;AAQP,IAAqBC,sBAArB,MAAqBA;EARrB,OAQqBA;;;EACnB,OAAOC,WAAW,oBAAIC,IAAAA;EACtB,OAAOC,aAAa,oBAAID,IAAAA;EAExB,OAAOE,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AEA,QAAItB,QAAQD,IAAIwB,qBAAqB;AACnC,YAAM,KAAKtC,cAAcuC,OAAOjB,OAAOC,OAAAA;IACzC;AAEA,WAAO;MACLjB,MAAM;MACNC,MAAM;QACJD,MAAM;QACNoB,SAAS;MACX;IACF;EACF;EAEA,MAAac,QAAQ3B,SAAqC;AACxD,UAAM4B,gBAAgBC,QAAQC,YAAY,SAAS,KAAK1C,WAAW;AAEnE,QAAI,CAACwC,eAAe;AAClB,YAAM,IAAIN,WAAW,2BAAA;IACvB;AAEA,UAAMS,cAAoCH,cAAcG,eAAe,CAAA;AAEvE,QAAIC,mBAAmBhC;AAEvB,QAAI+B,YAAYE,QAAQ;AACtB,iBAAWC,cAAcH,aAAa;AACpCC,2BAAmB,MAAME,WAAWF,gBAAAA;MACtC;IACF;AAEA,WAAO,MAAM,KAAKG,OAAOH,gBAAAA;EAC3B;AACF;","names":["import_reflect_metadata","DependencyContainer","registry","Map","singletons","register","token","myClass","options","set","type","singleton","registerValue","value","resolve","target","paramTypes","Reflect","getMetadata","injectMetadata","getOwnMetadata","params","map","_","index","Error","name","resolveToken","registration","get","has","instance","ApiErrorEnum","ApplicationError","Error","props","constructor","message","code","errorCode","ApiErrorEnum","APPLICATION","occurredAt","Date","ConflictError","Error","props","conflictProps","constructor","code","errorCode","ApiErrorEnum","APPLICATION","message","occurredAt","Date","DomainError","Error","props","constructor","message","code","errorCode","ApiErrorEnum","DOMAIN","occurredAt","Date","InfraError","Error","props","constructor","message","code","errorCode","ApiErrorEnum","INFRA","occurredAt","Date","ValidationError","Error","props","constructor","errors","code","errorCode","ApiErrorEnum","VALIDATOR","message","occurredAt","Date","BaseController","errorNotifier","constructor","DependencyContainer","resolveToken","success","dto","code","data","noContent","undefined","created","paginated","buildContextError","request","env","process","ENVIRONMENT","body","headers","params","query","failure","error","context","ConflictError","props","message","errorCode","occurredAt","items","Array","isArray","conflictProps","DomainError","ApplicationError","InfraError","ValidationError","errors","SHOULD_NOTIFY_ERROR","notify","execute","routeMetadata","Reflect","getMetadata","middlewares","processedRequest","length","middleware","handle"]}
1
+ {"version":3,"sources":["../../../src/core/http/base-controller.ts","../../../src/core/decorators/dependency-container.ts","../../../src/core/errors/api-common-error.ts","../../../src/core/errors/application-error.ts","../../../src/core/errors/conflict-error.ts","../../../src/core/errors/domain-error.ts","../../../src/core/errors/infra-error.ts","../../../src/core/errors/validation-error.ts"],"sourcesContent":["import 'reflect-metadata'\n\nimport { DependencyContainer } from '../../core/decorators/dependency-container'\nimport ApplicationError from '../../core/errors/application-error'\nimport ConflictError from '../../core/errors/conflict-error'\nimport DomainError from '../../core/errors/domain-error'\nimport InfraError from '../../core/errors/infra-error'\nimport ValidationError from '../../core/errors/validation-error'\nimport { MiddlewareFunction } from '../../infra/adapters/validators/zod/zod-validator'\nimport IErrorNotifier from './error-notifier'\n\ntype AnyObject = Record<string, any>\n\nexport type Request = {\n body: AnyObject\n params: AnyObject\n headers: AnyObject\n query: AnyObject\n}\n\nexport type Response = {\n code: number\n data: any\n}\n\nexport type ContextError = {\n env: string\n user?: {\n id?: string\n name?: string\n email?: string\n }\n request?: {\n method?: string\n requestId?: string\n url?: string\n headers?: any\n query?: any\n body?: any\n params?: any\n }\n}\n\nexport abstract class BaseController {\n protected readonly errorNotifier: IErrorNotifier\n\n abstract handle<T>(request: T | Request): Promise<Response>\n\n constructor() {\n this.errorNotifier = DependencyContainer.resolveToken('IErrorNotifier')\n }\n\n protected success<T>(dto?: T): Response {\n return {\n code: 200,\n data: { data: dto },\n }\n }\n\n protected noContent(): Response {\n return {\n code: 204,\n data: undefined,\n }\n }\n\n protected created<T>(dto?: T): Response {\n return {\n code: 201,\n data: dto ? { data: dto } : undefined,\n }\n }\n\n protected paginated<T>(dto?: T): Response {\n return {\n code: 200,\n data: dto,\n }\n }\n\n protected buildContextError(request: Request): ContextError {\n return {\n env: process.env.ENVIRONMENT as string,\n request: {\n body: request.body,\n headers: request.headers,\n params: request.params,\n query: request.query,\n },\n }\n }\n\n public async failure(error: Error, context: ContextError): Promise<Response> {\n if (error instanceof ConflictError) {\n return {\n code: error.props.code,\n data: {\n message: error.message,\n errorCode: error.props.errorCode,\n occurredAt: error.props.occurredAt,\n items: Array.isArray(error.conflictProps)\n ? error.conflictProps\n : [error.conflictProps],\n },\n }\n }\n\n if (\n error instanceof DomainError ||\n error instanceof ApplicationError ||\n error instanceof InfraError\n ) {\n return {\n code: error.props.code,\n data: {\n message: error.message,\n errorCode: error.props.errorCode,\n occurredAt: error.props.occurredAt,\n },\n }\n }\n\n if (error instanceof ValidationError) {\n return {\n code: error.props.code,\n data: {\n message: error.props.message,\n errorCode: error.props.errorCode,\n occurredAt: error.props.occurredAt,\n errors: error.props.errors,\n },\n }\n }\n\n if (process.env.SHOULD_NOTIFY_ERROR) {\n await this.errorNotifier.notify(error, context)\n }\n\n return {\n code: 500,\n data: {\n code: 500,\n message: 'Server failed. Contact the administrator!',\n },\n }\n }\n\n public async execute(request: Request): Promise<Response> {\n const routeMetadata = Reflect.getMetadata('route', this.constructor)\n\n if (!routeMetadata) {\n throw new InfraError('Route metadata not found.')\n }\n\n const middlewares: MiddlewareFunction[] = routeMetadata.middlewares || []\n\n let processedRequest = request\n\n if (middlewares.length) {\n for (const middleware of middlewares) {\n processedRequest = await middleware(processedRequest)\n }\n }\n\n return await this.handle(processedRequest)\n }\n}\n","import 'reflect-metadata'\n\ntype Class<T = any> = new (...args: any[]) => T\n\ntype Registration =\n | { type: 'class'; myClass: Class; singleton: boolean }\n | { type: 'value'; value: any }\n\nexport class DependencyContainer {\n static registry = new Map<string, Registration>()\n static singletons = new Map<string, any>()\n\n static register<T>(\n token: string,\n myClass: Class<T>,\n options: { singleton: boolean }\n ) {\n this.registry.set(token, {\n type: 'class',\n myClass,\n singleton: options.singleton,\n })\n }\n\n static registerValue<T>(token: string, value: T) {\n this.registry.set(token, { type: 'value', value })\n }\n\n static resolve<T>(target: Class<T>): T {\n const paramTypes = Reflect.getMetadata('design:paramtypes', target) || []\n\n const injectMetadata: Record<number, string> =\n Reflect.getOwnMetadata('inject:params', target) || {}\n\n const params = paramTypes.map((_: any, index: number) => {\n const token = injectMetadata[index]\n\n if (!token) {\n throw new Error(\n `Missing @Inject token for parameter index ${index} in ${target.name}`\n )\n }\n\n return this.resolveToken(token)\n })\n\n return new target(...params)\n }\n\n static resolveToken(token: string): any {\n const registration = this.registry.get(token)\n\n if (!registration) {\n throw new Error(\n `\"${token}\" not registered. Please register it in the container.`\n )\n }\n\n if (registration.type === 'value') {\n return registration.value\n }\n\n const { myClass, singleton } = registration\n\n if (singleton) {\n if (!this.singletons.has(token)) {\n const instance = this.resolve(myClass)\n this.singletons.set(token, instance)\n }\n return this.singletons.get(token)\n }\n\n return this.resolve(myClass)\n }\n}\n\nexport function Inject(token: string): ParameterDecorator {\n return (\n target: object,\n _propertyKey: string | symbol | undefined,\n parameterIndex: number\n ): void => {\n const constructor =\n typeof target === 'function' ? target : target.constructor\n\n const existingInjectedParams: Record<number, string> =\n Reflect.getOwnMetadata('inject:params', constructor) || {}\n\n existingInjectedParams[parameterIndex] = token\n\n Reflect.defineMetadata('inject:params', existingInjectedParams, constructor)\n }\n}\n","export type PropertiesError = {\n receivedValue?: any\n type: string\n message: string\n property: string | number | undefined\n propertyType?: string\n path?: string\n}\n\nexport type CommonError = {\n location: string\n propertyErrors?: PropertiesError[]\n}\n\nexport type ApiCommonError = {\n code: number\n occurredAt: Date\n message: string\n errorCode: string\n errors?: CommonError[]\n}\n\nexport enum ApiErrorEnum {\n DOMAIN = 'ERR001',\n APPLICATION = 'ERR002',\n INFRA = 'ERR003',\n HTTP_CLIENT = 'ERR004',\n VALIDATOR = 'ERR005',\n}\n","import { type ApiCommonError, ApiErrorEnum } from './api-common-error'\n\nexport default class ApplicationError extends Error {\n props: ApiCommonError\n\n constructor(message: string) {\n super(message)\n this.props = {\n code: 400,\n errorCode: ApiErrorEnum.APPLICATION,\n message,\n occurredAt: new Date(),\n }\n }\n}\n","import { type ApiCommonError, ApiErrorEnum } from './api-common-error'\n\ntype ConflictProps = { id: string; [key: string]: unknown }\n\nexport default class ConflictError<T extends ConflictProps> extends Error {\n props: ApiCommonError\n conflictProps: T | T[]\n\n constructor(conflictProps: T | T[]) {\n super('Resource already exists.')\n this.conflictProps = conflictProps\n this.props = {\n code: 409,\n errorCode: ApiErrorEnum.APPLICATION,\n message: this.message,\n occurredAt: new Date(),\n }\n }\n}\n","import { type ApiCommonError, ApiErrorEnum } from './api-common-error'\n\nexport default class DomainError extends Error {\n props: ApiCommonError\n\n constructor(message: string) {\n super(message)\n this.props = {\n code: 400,\n errorCode: ApiErrorEnum.DOMAIN,\n message,\n occurredAt: new Date(),\n }\n }\n}\n","import { type ApiCommonError, ApiErrorEnum } from './api-common-error'\n\nexport default class InfraError extends Error {\n props: ApiCommonError\n\n constructor(message: string) {\n super(message)\n this.props = {\n code: 400,\n errorCode: ApiErrorEnum.INFRA,\n message,\n occurredAt: new Date(),\n }\n }\n}\n","import {\n type ApiCommonError,\n ApiErrorEnum,\n type CommonError,\n} from './api-common-error'\n\nexport default class ValidationError extends Error {\n props: ApiCommonError\n\n constructor(errors: CommonError[]) {\n super('Validation Error')\n this.props = {\n code: 400,\n errorCode: ApiErrorEnum.VALIDATOR,\n message: 'Validation Error',\n occurredAt: new Date(),\n errors,\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;IAAAA,2BAAO;;;ACAP,8BAAO;AAQA,IAAMC,sBAAN,MAAMA;EARb,OAQaA;;;EACX,OAAOC,WAAW,oBAAIC,IAAAA;EACtB,OAAOC,aAAa,oBAAID,IAAAA;EAExB,OAAOE,SACLC,OACAC,SACAC,SACA;AACA,SAAKN,SAASO,IAAIH,OAAO;MACvBI,MAAM;MACNH;MACAI,WAAWH,QAAQG;IACrB,CAAA;EACF;EAEA,OAAOC,cAAiBN,OAAeO,OAAU;AAC/C,SAAKX,SAASO,IAAIH,OAAO;MAAEI,MAAM;MAASG;IAAM,CAAA;EAClD;EAEA,OAA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,YAAY,SAAS,KAAK1C,WAAW;AAEnE,QAAI,CAACwC,eAAe;AAClB,YAAM,IAAIN,WAAW,2BAAA;IACvB;AAEA,UAAMS,cAAoCH,cAAcG,eAAe,CAAA;AAEvE,QAAIC,mBAAmBhC;AAEvB,QAAI+B,YAAYE,QAAQ;AACtB,iBAAWC,cAAcH,aAAa;AACpCC,2BAAmB,MAAME,WAAWF,gBAAAA;MACtC;IACF;AAEA,WAAO,MAAM,KAAKG,OAAOH,gBAAAA;EAC3B;AACF;","names":["import_reflect_metadata","DependencyContainer","registry","Map","singletons","register","token","myClass","options","set","type","singleton","registerValue","value","resolve","target","paramTypes","Reflect","getMetadata","injectMetadata","getOwnMetadata","params","map","_","index","Error","name","resolveToken","registration","get","has","instance","ApiErrorEnum","ApplicationError","Error","props","constructor","message","code","errorCode","ApiErrorEnum","APPLICATION","occurredAt","Date","ConflictError","Error","props","conflictProps","constructor","code","errorCode","ApiErrorEnum","APPLICATION","message","occurredAt","Date","DomainError","Error","props","constructor","message","code","errorCode","ApiErrorEnum","DOMAIN","occurredAt","Date","InfraError","Error","props","constructor","message","code","errorCode","ApiErrorEnum","INFRA","occurredAt","Date","ValidationError","Error","props","constructor","errors","code","errorCode","ApiErrorEnum","VALIDATOR","message","occurredAt","Date","BaseController","errorNotifier","constructor","DependencyContainer","resolveToken","success","dto","code","data","noContent","undefined","created","paginated","buildContextError","request","env","process","ENVIRONMENT","body","headers","params","query","failure","error","context","ConflictError","props","message","errorCode","occurredAt","items","Array","isArray","conflictProps","DomainError","ApplicationError","InfraError","ValidationError","errors","SHOULD_NOTIFY_ERROR","notify","execute","routeMetadata","Reflect","getMetadata","middlewares","processedRequest","length","middleware","handle"]}
@@ -1 +1 @@
1
- export { A as AnyObject, C as ContextError, R as Request, a as Response, B as default } from '../../base-controller-cec5714c.js';
1
+ export { B as BaseController, C as ContextError, R as Request, a as Response } from '../../base-controller-68008870.js';
@@ -1 +1 @@
1
- export { A as AnyObject, C as ContextError, R as Request, a as Response, B as default } from '../../base-controller-cec5714c.js';
1
+ export { B as BaseController, C as ContextError, R as Request, a as Response } from '../../base-controller-68008870.js';