plutin 1.3.0 → 1.3.1

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 (240) hide show
  1. package/dist/index.d.cts +286 -28
  2. package/dist/index.d.ts +286 -28
  3. package/dist/{index.js → index.mjs} +1 -1
  4. package/package.json +5 -4
  5. package/dist/base-controller-68008870.d.ts +0 -46
  6. package/dist/core/decorators/controller-http-decorator.cjs +0 -310
  7. package/dist/core/decorators/controller-http-decorator.cjs.map +0 -1
  8. package/dist/core/decorators/controller-http-decorator.d.cts +0 -13
  9. package/dist/core/decorators/controller-http-decorator.d.ts +0 -13
  10. package/dist/core/decorators/controller-http-decorator.js +0 -285
  11. package/dist/core/decorators/controller-http-decorator.js.map +0 -1
  12. package/dist/core/decorators/dependency-container.cjs +0 -95
  13. package/dist/core/decorators/dependency-container.cjs.map +0 -1
  14. package/dist/core/decorators/dependency-container.d.cts +0 -22
  15. package/dist/core/decorators/dependency-container.d.ts +0 -22
  16. package/dist/core/decorators/dependency-container.js +0 -71
  17. package/dist/core/decorators/dependency-container.js.map +0 -1
  18. package/dist/core/entities/aggregate-root.cjs +0 -99
  19. package/dist/core/entities/aggregate-root.cjs.map +0 -1
  20. package/dist/core/entities/aggregate-root.d.cts +0 -8
  21. package/dist/core/entities/aggregate-root.d.ts +0 -8
  22. package/dist/core/entities/aggregate-root.js +0 -74
  23. package/dist/core/entities/aggregate-root.js.map +0 -1
  24. package/dist/core/entities/common-dto.cjs +0 -19
  25. package/dist/core/entities/common-dto.cjs.map +0 -1
  26. package/dist/core/entities/common-dto.d.cts +0 -10
  27. package/dist/core/entities/common-dto.d.ts +0 -10
  28. package/dist/core/entities/common-dto.js +0 -1
  29. package/dist/core/entities/common-dto.js.map +0 -1
  30. package/dist/core/entities/domain-event.cjs +0 -19
  31. package/dist/core/entities/domain-event.cjs.map +0 -1
  32. package/dist/core/entities/domain-event.d.cts +0 -6
  33. package/dist/core/entities/domain-event.d.ts +0 -6
  34. package/dist/core/entities/domain-event.js +0 -1
  35. package/dist/core/entities/domain-event.js.map +0 -1
  36. package/dist/core/entities/entity.cjs +0 -92
  37. package/dist/core/entities/entity.cjs.map +0 -1
  38. package/dist/core/entities/entity.d.cts +0 -18
  39. package/dist/core/entities/entity.d.ts +0 -18
  40. package/dist/core/entities/entity.js +0 -67
  41. package/dist/core/entities/entity.js.map +0 -1
  42. package/dist/core/entities/optional.cjs +0 -19
  43. package/dist/core/entities/optional.cjs.map +0 -1
  44. package/dist/core/entities/optional.d.cts +0 -3
  45. package/dist/core/entities/optional.d.ts +0 -3
  46. package/dist/core/entities/optional.js +0 -1
  47. package/dist/core/entities/optional.js.map +0 -1
  48. package/dist/core/entities/replace.cjs +0 -19
  49. package/dist/core/entities/replace.cjs.map +0 -1
  50. package/dist/core/entities/replace.d.cts +0 -5
  51. package/dist/core/entities/replace.d.ts +0 -5
  52. package/dist/core/entities/replace.js +0 -1
  53. package/dist/core/entities/replace.js.map +0 -1
  54. package/dist/core/entities/unique-entity-id.cjs +0 -50
  55. package/dist/core/entities/unique-entity-id.cjs.map +0 -1
  56. package/dist/core/entities/unique-entity-id.d.cts +0 -9
  57. package/dist/core/entities/unique-entity-id.d.ts +0 -9
  58. package/dist/core/entities/unique-entity-id.js +0 -27
  59. package/dist/core/entities/unique-entity-id.js.map +0 -1
  60. package/dist/core/entities/value-object.cjs +0 -40
  61. package/dist/core/entities/value-object.cjs.map +0 -1
  62. package/dist/core/entities/value-object.d.cts +0 -6
  63. package/dist/core/entities/value-object.d.ts +0 -6
  64. package/dist/core/entities/value-object.js +0 -17
  65. package/dist/core/entities/value-object.js.map +0 -1
  66. package/dist/core/entities/watched-list.cjs +0 -121
  67. package/dist/core/entities/watched-list.cjs.map +0 -1
  68. package/dist/core/entities/watched-list.d.cts +0 -27
  69. package/dist/core/entities/watched-list.d.ts +0 -27
  70. package/dist/core/entities/watched-list.js +0 -98
  71. package/dist/core/entities/watched-list.js.map +0 -1
  72. package/dist/core/entities/watched-list.test.cjs +0 -186
  73. package/dist/core/entities/watched-list.test.cjs.map +0 -1
  74. package/dist/core/entities/watched-list.test.d.cts +0 -2
  75. package/dist/core/entities/watched-list.test.d.ts +0 -2
  76. package/dist/core/entities/watched-list.test.js +0 -185
  77. package/dist/core/entities/watched-list.test.js.map +0 -1
  78. package/dist/core/errors/api-common-error.cjs +0 -38
  79. package/dist/core/errors/api-common-error.cjs.map +0 -1
  80. package/dist/core/errors/api-common-error.d.cts +0 -28
  81. package/dist/core/errors/api-common-error.d.ts +0 -28
  82. package/dist/core/errors/api-common-error.js +0 -13
  83. package/dist/core/errors/api-common-error.js.map +0 -1
  84. package/dist/core/errors/application-error.cjs +0 -54
  85. package/dist/core/errors/application-error.cjs.map +0 -1
  86. package/dist/core/errors/application-error.d.cts +0 -8
  87. package/dist/core/errors/application-error.d.ts +0 -8
  88. package/dist/core/errors/application-error.js +0 -33
  89. package/dist/core/errors/application-error.js.map +0 -1
  90. package/dist/core/errors/conflict-error.cjs +0 -56
  91. package/dist/core/errors/conflict-error.cjs.map +0 -1
  92. package/dist/core/errors/conflict-error.d.cts +0 -13
  93. package/dist/core/errors/conflict-error.d.ts +0 -13
  94. package/dist/core/errors/conflict-error.js +0 -35
  95. package/dist/core/errors/conflict-error.js.map +0 -1
  96. package/dist/core/errors/domain-error.cjs +0 -54
  97. package/dist/core/errors/domain-error.cjs.map +0 -1
  98. package/dist/core/errors/domain-error.d.cts +0 -8
  99. package/dist/core/errors/domain-error.d.ts +0 -8
  100. package/dist/core/errors/domain-error.js +0 -33
  101. package/dist/core/errors/domain-error.js.map +0 -1
  102. package/dist/core/errors/http-client-error.cjs +0 -54
  103. package/dist/core/errors/http-client-error.cjs.map +0 -1
  104. package/dist/core/errors/http-client-error.d.cts +0 -8
  105. package/dist/core/errors/http-client-error.d.ts +0 -8
  106. package/dist/core/errors/http-client-error.js +0 -33
  107. package/dist/core/errors/http-client-error.js.map +0 -1
  108. package/dist/core/errors/infra-error.cjs +0 -54
  109. package/dist/core/errors/infra-error.cjs.map +0 -1
  110. package/dist/core/errors/infra-error.d.cts +0 -8
  111. package/dist/core/errors/infra-error.d.ts +0 -8
  112. package/dist/core/errors/infra-error.js +0 -33
  113. package/dist/core/errors/infra-error.js.map +0 -1
  114. package/dist/core/errors/validation-error.cjs +0 -55
  115. package/dist/core/errors/validation-error.cjs.map +0 -1
  116. package/dist/core/errors/validation-error.d.cts +0 -8
  117. package/dist/core/errors/validation-error.d.ts +0 -8
  118. package/dist/core/errors/validation-error.js +0 -34
  119. package/dist/core/errors/validation-error.js.map +0 -1
  120. package/dist/core/http/base-controller.cjs +0 -295
  121. package/dist/core/http/base-controller.cjs.map +0 -1
  122. package/dist/core/http/base-controller.d.cts +0 -1
  123. package/dist/core/http/base-controller.d.ts +0 -1
  124. package/dist/core/http/base-controller.js +0 -270
  125. package/dist/core/http/base-controller.js.map +0 -1
  126. package/dist/core/http/dto-response.cjs +0 -19
  127. package/dist/core/http/dto-response.cjs.map +0 -1
  128. package/dist/core/http/dto-response.d.cts +0 -10
  129. package/dist/core/http/dto-response.d.ts +0 -10
  130. package/dist/core/http/dto-response.js +0 -1
  131. package/dist/core/http/dto-response.js.map +0 -1
  132. package/dist/core/http/error-notifier.cjs +0 -19
  133. package/dist/core/http/error-notifier.cjs.map +0 -1
  134. package/dist/core/http/error-notifier.d.cts +0 -1
  135. package/dist/core/http/error-notifier.d.ts +0 -1
  136. package/dist/core/http/error-notifier.js +0 -1
  137. package/dist/core/http/error-notifier.js.map +0 -1
  138. package/dist/core/http/get-take-and-skip.cjs +0 -40
  139. package/dist/core/http/get-take-and-skip.cjs.map +0 -1
  140. package/dist/core/http/get-take-and-skip.d.cts +0 -6
  141. package/dist/core/http/get-take-and-skip.d.ts +0 -6
  142. package/dist/core/http/get-take-and-skip.js +0 -17
  143. package/dist/core/http/get-take-and-skip.js.map +0 -1
  144. package/dist/core/http/health-connections.cjs +0 -42
  145. package/dist/core/http/health-connections.cjs.map +0 -1
  146. package/dist/core/http/health-connections.d.cts +0 -16
  147. package/dist/core/http/health-connections.d.ts +0 -16
  148. package/dist/core/http/health-connections.js +0 -23
  149. package/dist/core/http/health-connections.js.map +0 -1
  150. package/dist/core/http/http.cjs +0 -19
  151. package/dist/core/http/http.cjs.map +0 -1
  152. package/dist/core/http/http.d.cts +0 -10
  153. package/dist/core/http/http.d.ts +0 -10
  154. package/dist/core/http/http.js +0 -1
  155. package/dist/core/http/http.js.map +0 -1
  156. package/dist/core/http/pagination.cjs +0 -19
  157. package/dist/core/http/pagination.cjs.map +0 -1
  158. package/dist/core/http/pagination.d.cts +0 -9
  159. package/dist/core/http/pagination.d.ts +0 -9
  160. package/dist/core/http/pagination.js +0 -1
  161. package/dist/core/http/pagination.js.map +0 -1
  162. package/dist/core/http/validator.cjs +0 -19
  163. package/dist/core/http/validator.cjs.map +0 -1
  164. package/dist/core/http/validator.d.cts +0 -11
  165. package/dist/core/http/validator.d.ts +0 -11
  166. package/dist/core/http/validator.js +0 -1
  167. package/dist/core/http/validator.js.map +0 -1
  168. package/dist/infra/adapters/http/express-adapter.cjs +0 -139
  169. package/dist/infra/adapters/http/express-adapter.cjs.map +0 -1
  170. package/dist/infra/adapters/http/express-adapter.d.cts +0 -15
  171. package/dist/infra/adapters/http/express-adapter.d.ts +0 -15
  172. package/dist/infra/adapters/http/express-adapter.js +0 -106
  173. package/dist/infra/adapters/http/express-adapter.js.map +0 -1
  174. package/dist/infra/adapters/http/fastify-adapter.cjs +0 -124
  175. package/dist/infra/adapters/http/fastify-adapter.cjs.map +0 -1
  176. package/dist/infra/adapters/http/fastify-adapter.d.cts +0 -14
  177. package/dist/infra/adapters/http/fastify-adapter.d.ts +0 -14
  178. package/dist/infra/adapters/http/fastify-adapter.js +0 -91
  179. package/dist/infra/adapters/http/fastify-adapter.js.map +0 -1
  180. package/dist/infra/adapters/http/response-error-code.cjs +0 -35
  181. package/dist/infra/adapters/http/response-error-code.cjs.map +0 -1
  182. package/dist/infra/adapters/http/response-error-code.d.cts +0 -6
  183. package/dist/infra/adapters/http/response-error-code.d.ts +0 -6
  184. package/dist/infra/adapters/http/response-error-code.js +0 -10
  185. package/dist/infra/adapters/http/response-error-code.js.map +0 -1
  186. package/dist/infra/adapters/http/validate-controller-metadata.cjs +0 -42
  187. package/dist/infra/adapters/http/validate-controller-metadata.cjs.map +0 -1
  188. package/dist/infra/adapters/http/validate-controller-metadata.d.cts +0 -11
  189. package/dist/infra/adapters/http/validate-controller-metadata.d.ts +0 -11
  190. package/dist/infra/adapters/http/validate-controller-metadata.js +0 -19
  191. package/dist/infra/adapters/http/validate-controller-metadata.js.map +0 -1
  192. package/dist/infra/adapters/notifications/discord.cjs +0 -90
  193. package/dist/infra/adapters/notifications/discord.cjs.map +0 -1
  194. package/dist/infra/adapters/notifications/discord.d.cts +0 -14
  195. package/dist/infra/adapters/notifications/discord.d.ts +0 -14
  196. package/dist/infra/adapters/notifications/discord.js +0 -65
  197. package/dist/infra/adapters/notifications/discord.js.map +0 -1
  198. package/dist/infra/adapters/notifications/in-memory.cjs +0 -44
  199. package/dist/infra/adapters/notifications/in-memory.cjs.map +0 -1
  200. package/dist/infra/adapters/notifications/in-memory.d.cts +0 -8
  201. package/dist/infra/adapters/notifications/in-memory.d.ts +0 -8
  202. package/dist/infra/adapters/notifications/in-memory.js +0 -21
  203. package/dist/infra/adapters/notifications/in-memory.js.map +0 -1
  204. package/dist/infra/adapters/notifications/notification-factory.cjs +0 -219
  205. package/dist/infra/adapters/notifications/notification-factory.cjs.map +0 -1
  206. package/dist/infra/adapters/notifications/notification-factory.d.cts +0 -18
  207. package/dist/infra/adapters/notifications/notification-factory.d.ts +0 -18
  208. package/dist/infra/adapters/notifications/notification-factory.js +0 -184
  209. package/dist/infra/adapters/notifications/notification-factory.js.map +0 -1
  210. package/dist/infra/adapters/notifications/sentry.cjs +0 -129
  211. package/dist/infra/adapters/notifications/sentry.cjs.map +0 -1
  212. package/dist/infra/adapters/notifications/sentry.d.cts +0 -13
  213. package/dist/infra/adapters/notifications/sentry.d.ts +0 -13
  214. package/dist/infra/adapters/notifications/sentry.js +0 -96
  215. package/dist/infra/adapters/notifications/sentry.js.map +0 -1
  216. package/dist/infra/adapters/validators/zod/index.cjs +0 -179
  217. package/dist/infra/adapters/validators/zod/index.cjs.map +0 -1
  218. package/dist/infra/adapters/validators/zod/index.d.cts +0 -19
  219. package/dist/infra/adapters/validators/zod/index.d.ts +0 -19
  220. package/dist/infra/adapters/validators/zod/index.js +0 -154
  221. package/dist/infra/adapters/validators/zod/index.js.map +0 -1
  222. package/dist/infra/adapters/validators/zod/zod-map-error.cjs +0 -79
  223. package/dist/infra/adapters/validators/zod/zod-map-error.cjs.map +0 -1
  224. package/dist/infra/adapters/validators/zod/zod-map-error.d.cts +0 -15
  225. package/dist/infra/adapters/validators/zod/zod-map-error.d.ts +0 -15
  226. package/dist/infra/adapters/validators/zod/zod-map-error.js +0 -60
  227. package/dist/infra/adapters/validators/zod/zod-map-error.js.map +0 -1
  228. package/dist/infra/adapters/validators/zod/zod-validator.cjs +0 -178
  229. package/dist/infra/adapters/validators/zod/zod-validator.cjs.map +0 -1
  230. package/dist/infra/adapters/validators/zod/zod-validator.d.cts +0 -13
  231. package/dist/infra/adapters/validators/zod/zod-validator.d.ts +0 -13
  232. package/dist/infra/adapters/validators/zod/zod-validator.js +0 -153
  233. package/dist/infra/adapters/validators/zod/zod-validator.js.map +0 -1
  234. package/dist/infra/env/index.cjs +0 -467
  235. package/dist/infra/env/index.cjs.map +0 -1
  236. package/dist/infra/env/index.d.cts +0 -26
  237. package/dist/infra/env/index.d.ts +0 -26
  238. package/dist/infra/env/index.js +0 -452
  239. package/dist/infra/env/index.js.map +0 -1
  240. /package/dist/{index.js.map → index.mjs.map} +0 -0
package/dist/index.d.cts CHANGED
@@ -1,28 +1,286 @@
1
- export { Controller } from './core/decorators/controller-http-decorator.cjs';
2
- export { DependencyContainer, Inject } from './core/decorators/dependency-container.cjs';
3
- export { AggregateRoot } from './core/entities/aggregate-root.cjs';
4
- export { CommonDTO, CreateCommonDTO } from './core/entities/common-dto.cjs';
5
- export { Entity } from './core/entities/entity.cjs';
6
- export { Optional } from './core/entities/optional.cjs';
7
- export { Replace } from './core/entities/replace.cjs';
8
- export { UniqueEntityId } from './core/entities/unique-entity-id.cjs';
9
- export { ValueObject } from './core/entities/value-object.cjs';
10
- export { WatchedList } from './core/entities/watched-list.cjs';
11
- export { B as BaseController, C as ContextError, I as IErrorNotifier, R as Request, a as Response } from './base-controller-68008870.js';
12
- export { DtoResponsePagination } from './core/http/dto-response.cjs';
13
- export { getTakeAndSkip } from './core/http/get-take-and-skip.cjs';
14
- export { ICheckDB, IHealthCheck } from './core/http/health-connections.cjs';
15
- export { NotPagination, Pagination } from './core/http/pagination.cjs';
16
- export { RequestHttp } from './core/http/validator.cjs';
17
- export { ExpressAdapter } from './infra/adapters/http/express-adapter.cjs';
18
- export { FastifyAdapter } from './infra/adapters/http/fastify-adapter.cjs';
19
- export { DiscordNotifier } from './infra/adapters/notifications/discord.cjs';
20
- export { NotificationErrorInMemory } from './infra/adapters/notifications/in-memory.cjs';
21
- export { NotificationFactory } from './infra/adapters/notifications/notification-factory.cjs';
22
- export { SentryNotifier } from './infra/adapters/notifications/sentry.cjs';
23
- export { MiddlewareFunction, ZodSchema, zodValidator } from './infra/adapters/validators/zod/zod-validator.cjs';
24
- export { baseEnvSchema } from './infra/env/index.cjs';
25
- import './core/http/http.cjs';
26
- import 'express';
27
- import 'fastify';
28
- import 'zod';
1
+ import { z } from 'zod';
2
+ import { Express } from 'express';
3
+ import { FastifyInstance } from 'fastify';
4
+
5
+ interface IErrorNotifier {
6
+ notify(error: Error, context: ContextError): Promise<void>;
7
+ }
8
+
9
+ type AnyObject = Record<string, any>;
10
+ type Request = {
11
+ body: AnyObject;
12
+ params: AnyObject;
13
+ headers: AnyObject;
14
+ query: AnyObject;
15
+ };
16
+ type Response = {
17
+ code: number;
18
+ data: any;
19
+ };
20
+ type ContextError = {
21
+ env: string;
22
+ user?: {
23
+ id?: string;
24
+ name?: string;
25
+ email?: string;
26
+ };
27
+ request?: {
28
+ method?: string;
29
+ requestId?: string;
30
+ url?: string;
31
+ headers?: any;
32
+ query?: any;
33
+ body?: any;
34
+ params?: any;
35
+ };
36
+ };
37
+ declare abstract class BaseController {
38
+ protected readonly errorNotifier: IErrorNotifier;
39
+ abstract handle<T>(request: T | Request): Promise<Response>;
40
+ constructor();
41
+ protected success<T>(dto?: T): Response;
42
+ protected noContent(): Response;
43
+ protected created<T>(dto?: T): Response;
44
+ protected paginated<T>(dto?: T): Response;
45
+ protected buildContextError(request: Request): ContextError;
46
+ failure(error: Error, context: ContextError): Promise<Response>;
47
+ execute(request: Request): Promise<Response>;
48
+ }
49
+
50
+ type ZodSchema = z.ZodObject<{
51
+ headers: z.ZodObject<Record<string, any>>;
52
+ params: z.ZodObject<Record<string, any>>;
53
+ query: z.ZodObject<Record<string, any>>;
54
+ body: z.ZodObject<Record<string, any>> | z.ZodEffects<z.ZodObject<Record<string, any>>>;
55
+ }>;
56
+ type MiddlewareFunction = (request: Request) => Promise<Request>;
57
+ declare function zodValidator(schema: ZodSchema): MiddlewareFunction;
58
+
59
+ type MethodType = 'get' | 'post' | 'delete' | 'put' | 'patch';
60
+ interface IHttp {
61
+ registerRoute(controller: BaseController): void;
62
+ startServer(port: number): Promise<void>;
63
+ closeServer(): Promise<void>;
64
+ }
65
+
66
+ type Props$1 = {
67
+ method: MethodType;
68
+ path: string;
69
+ middlewares?: MiddlewareFunction[];
70
+ };
71
+ declare function Controller({ method, path, middlewares, }: Props$1): ClassDecorator;
72
+
73
+ type Class<T = any> = new (...args: any[]) => T;
74
+ type Registration = {
75
+ type: 'class';
76
+ myClass: Class;
77
+ singleton: boolean;
78
+ } | {
79
+ type: 'value';
80
+ value: any;
81
+ };
82
+ declare class DependencyContainer {
83
+ static registry: Map<string, Registration>;
84
+ static singletons: Map<string, any>;
85
+ static register<T>(token: string, myClass: Class<T>, options: {
86
+ singleton: boolean;
87
+ }): void;
88
+ static registerValue<T>(token: string, value: T): void;
89
+ static resolve<T>(target: Class<T>): T;
90
+ static resolveToken(token: string): any;
91
+ }
92
+ declare function Inject(token: string): ParameterDecorator;
93
+
94
+ type CommonDTO = {
95
+ createdAt: Date;
96
+ updatedAt: Date | null;
97
+ };
98
+ type CreateCommonDTO = {
99
+ createdAt?: Date;
100
+ updatedAt?: Date | null;
101
+ };
102
+
103
+ declare class UniqueEntityId {
104
+ private value;
105
+ constructor(value?: string);
106
+ toString(): string;
107
+ toValue(): string;
108
+ equals(id: UniqueEntityId): boolean;
109
+ }
110
+
111
+ type PropsWithCommonDTO<Props> = Props & CommonDTO;
112
+ declare abstract class Entity<Props> {
113
+ private _id;
114
+ protected props: PropsWithCommonDTO<Props>;
115
+ get id(): UniqueEntityId;
116
+ set id(id: UniqueEntityId);
117
+ get createdAt(): Date;
118
+ set createdAt(date: Date);
119
+ get updatedAt(): Date | undefined | null;
120
+ touch(): void;
121
+ protected constructor(props: PropsWithCommonDTO<Props>, id?: UniqueEntityId);
122
+ equals(entity: Entity<any>): boolean;
123
+ }
124
+
125
+ declare abstract class AggregateRoot<Props> extends Entity<Props> {
126
+ }
127
+
128
+ type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
129
+
130
+ type Replace<T, K extends {
131
+ [P in keyof T]?: any;
132
+ }> = Omit<T, keyof K> & K;
133
+
134
+ declare abstract class ValueObject<Props> {
135
+ protected props: Props;
136
+ protected constructor(props: Props);
137
+ }
138
+
139
+ declare abstract class WatchedList<T> {
140
+ currentItems: T[];
141
+ private initial;
142
+ private new;
143
+ private removed;
144
+ private updated;
145
+ constructor(initialItems?: T[]);
146
+ abstract compareItems(a: T, b: T): boolean;
147
+ getItems(): T[];
148
+ getNewItems(): T[];
149
+ getRemovedItems(): T[];
150
+ getUpdatedItems(): T[];
151
+ addUpdatedItem(item: T): number;
152
+ private isCurrentItem;
153
+ private isNewItem;
154
+ private isRemovedItem;
155
+ private removeFromNew;
156
+ private removeFromCurrent;
157
+ private removeFromRemoved;
158
+ private wasAddedInitially;
159
+ exists(item: T): boolean;
160
+ add(item: T): void;
161
+ remove(item: T): void;
162
+ update(items: T[]): void;
163
+ }
164
+
165
+ type DtoResponsePagination = {
166
+ count: number;
167
+ query: {
168
+ page: string;
169
+ size: string;
170
+ };
171
+ withPagination: boolean;
172
+ };
173
+
174
+ declare function getTakeAndSkip(size: string, page: string): {
175
+ take: number;
176
+ skip: number;
177
+ };
178
+
179
+ type HealthCheckOutput = {
180
+ dbIsOnline: boolean;
181
+ };
182
+ interface IHealthCheck {
183
+ check(): Promise<HealthCheckOutput>;
184
+ }
185
+ interface ICheckDB {
186
+ dbIsOnline(): Promise<boolean>;
187
+ }
188
+
189
+ type Pagination<T> = {
190
+ data: T[];
191
+ count?: number;
192
+ };
193
+ type NotPagination<T> = {
194
+ data: T[];
195
+ };
196
+
197
+ type RequestHttp = {
198
+ body: Record<string, any>;
199
+ params: Record<string, any>;
200
+ headers: Record<string, any>;
201
+ query: Record<string, any>;
202
+ };
203
+
204
+ declare class ExpressAdapter implements IHttp {
205
+ readonly env: Record<string, any>;
206
+ readonly instance: Express;
207
+ private server;
208
+ constructor(env: Record<string, any>);
209
+ registerRoute(controllerClass: BaseController): void;
210
+ startServer(port: number): Promise<void>;
211
+ closeServer(): Promise<void>;
212
+ }
213
+
214
+ declare class FastifyAdapter implements IHttp {
215
+ readonly env: Record<string, any>;
216
+ readonly instance: FastifyInstance;
217
+ constructor(env: Record<string, any>);
218
+ registerRoute(controllerClass: BaseController): void;
219
+ startServer(port: number): Promise<void>;
220
+ closeServer(): Promise<void>;
221
+ }
222
+
223
+ type DiscordOptions = {
224
+ url: string;
225
+ env: string;
226
+ };
227
+ declare class DiscordNotifier implements IErrorNotifier {
228
+ private readonly options;
229
+ private webhook;
230
+ constructor(options: DiscordOptions);
231
+ notify(error: Error, context: ContextError): Promise<void>;
232
+ }
233
+
234
+ declare class NotificationErrorInMemory implements IErrorNotifier {
235
+ errors: any[];
236
+ notify(error: Error, context?: ContextError): Promise<void>;
237
+ }
238
+
239
+ declare const baseEnvSchema: z.ZodObject<{
240
+ NODE_ENV: z.ZodDefault<z.ZodEnum<["test", "development", "production"]>>;
241
+ ENVIRONMENT: z.ZodDefault<z.ZodEnum<["test", "development", "staging", "production"]>>;
242
+ PORT: z.ZodDefault<z.ZodNumber>;
243
+ SHOULD_NOTIFY_ERROR: z.ZodDefault<z.ZodBoolean>;
244
+ SENTRY_DSN: z.ZodOptional<z.ZodString>;
245
+ DISCORD_WEBHOOK_URL: z.ZodOptional<z.ZodString>;
246
+ }, "strip", z.ZodTypeAny, {
247
+ ENVIRONMENT: "test" | "development" | "production" | "staging";
248
+ SHOULD_NOTIFY_ERROR: boolean;
249
+ NODE_ENV: "test" | "development" | "production";
250
+ PORT: number;
251
+ SENTRY_DSN?: string | undefined;
252
+ DISCORD_WEBHOOK_URL?: string | undefined;
253
+ }, {
254
+ ENVIRONMENT?: "test" | "development" | "production" | "staging" | undefined;
255
+ SHOULD_NOTIFY_ERROR?: boolean | undefined;
256
+ NODE_ENV?: "test" | "development" | "production" | undefined;
257
+ PORT?: number | undefined;
258
+ SENTRY_DSN?: string | undefined;
259
+ DISCORD_WEBHOOK_URL?: string | undefined;
260
+ }>;
261
+
262
+ type OptionsNotifications = 'console' | 'discord' | 'sentry';
263
+ type EnvironmentEnum = z.infer<typeof baseEnvSchema>['ENVIRONMENT'];
264
+ type Props = {
265
+ local?: OptionsNotifications;
266
+ test?: OptionsNotifications;
267
+ development?: OptionsNotifications;
268
+ staging?: OptionsNotifications;
269
+ production?: OptionsNotifications;
270
+ };
271
+ declare class NotificationFactory {
272
+ static define(env: EnvironmentEnum, definitions?: Props): any;
273
+ private static defineProvider;
274
+ }
275
+
276
+ type SentryOptions = {
277
+ dsn: string;
278
+ environment: string;
279
+ };
280
+ declare class SentryNotifier implements IErrorNotifier {
281
+ private readonly options;
282
+ constructor(options: SentryOptions);
283
+ notify(error: Error, context: ContextError): Promise<void>;
284
+ }
285
+
286
+ export { AggregateRoot, BaseController, CommonDTO, ContextError, Controller, CreateCommonDTO, DependencyContainer, DiscordNotifier, DtoResponsePagination, Entity, ExpressAdapter, FastifyAdapter, ICheckDB, IErrorNotifier, IHealthCheck, Inject, MiddlewareFunction, NotPagination, NotificationErrorInMemory, NotificationFactory, Optional, Pagination, Replace, Request, RequestHttp, Response, SentryNotifier, UniqueEntityId, ValueObject, WatchedList, ZodSchema, baseEnvSchema, getTakeAndSkip, zodValidator };
package/dist/index.d.ts CHANGED
@@ -1,28 +1,286 @@
1
- export { Controller } from './core/decorators/controller-http-decorator.js';
2
- export { DependencyContainer, Inject } from './core/decorators/dependency-container.js';
3
- export { AggregateRoot } from './core/entities/aggregate-root.js';
4
- export { CommonDTO, CreateCommonDTO } from './core/entities/common-dto.js';
5
- export { Entity } from './core/entities/entity.js';
6
- export { Optional } from './core/entities/optional.js';
7
- export { Replace } from './core/entities/replace.js';
8
- export { UniqueEntityId } from './core/entities/unique-entity-id.js';
9
- export { ValueObject } from './core/entities/value-object.js';
10
- export { WatchedList } from './core/entities/watched-list.js';
11
- export { B as BaseController, C as ContextError, I as IErrorNotifier, R as Request, a as Response } from './base-controller-68008870.js';
12
- export { DtoResponsePagination } from './core/http/dto-response.js';
13
- export { getTakeAndSkip } from './core/http/get-take-and-skip.js';
14
- export { ICheckDB, IHealthCheck } from './core/http/health-connections.js';
15
- export { NotPagination, Pagination } from './core/http/pagination.js';
16
- export { RequestHttp } from './core/http/validator.js';
17
- export { ExpressAdapter } from './infra/adapters/http/express-adapter.js';
18
- export { FastifyAdapter } from './infra/adapters/http/fastify-adapter.js';
19
- export { DiscordNotifier } from './infra/adapters/notifications/discord.js';
20
- export { NotificationErrorInMemory } from './infra/adapters/notifications/in-memory.js';
21
- export { NotificationFactory } from './infra/adapters/notifications/notification-factory.js';
22
- export { SentryNotifier } from './infra/adapters/notifications/sentry.js';
23
- export { MiddlewareFunction, ZodSchema, zodValidator } from './infra/adapters/validators/zod/zod-validator.js';
24
- export { baseEnvSchema } from './infra/env/index.js';
25
- import './core/http/http.js';
26
- import 'express';
27
- import 'fastify';
28
- import 'zod';
1
+ import { z } from 'zod';
2
+ import { Express } from 'express';
3
+ import { FastifyInstance } from 'fastify';
4
+
5
+ interface IErrorNotifier {
6
+ notify(error: Error, context: ContextError): Promise<void>;
7
+ }
8
+
9
+ type AnyObject = Record<string, any>;
10
+ type Request = {
11
+ body: AnyObject;
12
+ params: AnyObject;
13
+ headers: AnyObject;
14
+ query: AnyObject;
15
+ };
16
+ type Response = {
17
+ code: number;
18
+ data: any;
19
+ };
20
+ type ContextError = {
21
+ env: string;
22
+ user?: {
23
+ id?: string;
24
+ name?: string;
25
+ email?: string;
26
+ };
27
+ request?: {
28
+ method?: string;
29
+ requestId?: string;
30
+ url?: string;
31
+ headers?: any;
32
+ query?: any;
33
+ body?: any;
34
+ params?: any;
35
+ };
36
+ };
37
+ declare abstract class BaseController {
38
+ protected readonly errorNotifier: IErrorNotifier;
39
+ abstract handle<T>(request: T | Request): Promise<Response>;
40
+ constructor();
41
+ protected success<T>(dto?: T): Response;
42
+ protected noContent(): Response;
43
+ protected created<T>(dto?: T): Response;
44
+ protected paginated<T>(dto?: T): Response;
45
+ protected buildContextError(request: Request): ContextError;
46
+ failure(error: Error, context: ContextError): Promise<Response>;
47
+ execute(request: Request): Promise<Response>;
48
+ }
49
+
50
+ type ZodSchema = z.ZodObject<{
51
+ headers: z.ZodObject<Record<string, any>>;
52
+ params: z.ZodObject<Record<string, any>>;
53
+ query: z.ZodObject<Record<string, any>>;
54
+ body: z.ZodObject<Record<string, any>> | z.ZodEffects<z.ZodObject<Record<string, any>>>;
55
+ }>;
56
+ type MiddlewareFunction = (request: Request) => Promise<Request>;
57
+ declare function zodValidator(schema: ZodSchema): MiddlewareFunction;
58
+
59
+ type MethodType = 'get' | 'post' | 'delete' | 'put' | 'patch';
60
+ interface IHttp {
61
+ registerRoute(controller: BaseController): void;
62
+ startServer(port: number): Promise<void>;
63
+ closeServer(): Promise<void>;
64
+ }
65
+
66
+ type Props$1 = {
67
+ method: MethodType;
68
+ path: string;
69
+ middlewares?: MiddlewareFunction[];
70
+ };
71
+ declare function Controller({ method, path, middlewares, }: Props$1): ClassDecorator;
72
+
73
+ type Class<T = any> = new (...args: any[]) => T;
74
+ type Registration = {
75
+ type: 'class';
76
+ myClass: Class;
77
+ singleton: boolean;
78
+ } | {
79
+ type: 'value';
80
+ value: any;
81
+ };
82
+ declare class DependencyContainer {
83
+ static registry: Map<string, Registration>;
84
+ static singletons: Map<string, any>;
85
+ static register<T>(token: string, myClass: Class<T>, options: {
86
+ singleton: boolean;
87
+ }): void;
88
+ static registerValue<T>(token: string, value: T): void;
89
+ static resolve<T>(target: Class<T>): T;
90
+ static resolveToken(token: string): any;
91
+ }
92
+ declare function Inject(token: string): ParameterDecorator;
93
+
94
+ type CommonDTO = {
95
+ createdAt: Date;
96
+ updatedAt: Date | null;
97
+ };
98
+ type CreateCommonDTO = {
99
+ createdAt?: Date;
100
+ updatedAt?: Date | null;
101
+ };
102
+
103
+ declare class UniqueEntityId {
104
+ private value;
105
+ constructor(value?: string);
106
+ toString(): string;
107
+ toValue(): string;
108
+ equals(id: UniqueEntityId): boolean;
109
+ }
110
+
111
+ type PropsWithCommonDTO<Props> = Props & CommonDTO;
112
+ declare abstract class Entity<Props> {
113
+ private _id;
114
+ protected props: PropsWithCommonDTO<Props>;
115
+ get id(): UniqueEntityId;
116
+ set id(id: UniqueEntityId);
117
+ get createdAt(): Date;
118
+ set createdAt(date: Date);
119
+ get updatedAt(): Date | undefined | null;
120
+ touch(): void;
121
+ protected constructor(props: PropsWithCommonDTO<Props>, id?: UniqueEntityId);
122
+ equals(entity: Entity<any>): boolean;
123
+ }
124
+
125
+ declare abstract class AggregateRoot<Props> extends Entity<Props> {
126
+ }
127
+
128
+ type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
129
+
130
+ type Replace<T, K extends {
131
+ [P in keyof T]?: any;
132
+ }> = Omit<T, keyof K> & K;
133
+
134
+ declare abstract class ValueObject<Props> {
135
+ protected props: Props;
136
+ protected constructor(props: Props);
137
+ }
138
+
139
+ declare abstract class WatchedList<T> {
140
+ currentItems: T[];
141
+ private initial;
142
+ private new;
143
+ private removed;
144
+ private updated;
145
+ constructor(initialItems?: T[]);
146
+ abstract compareItems(a: T, b: T): boolean;
147
+ getItems(): T[];
148
+ getNewItems(): T[];
149
+ getRemovedItems(): T[];
150
+ getUpdatedItems(): T[];
151
+ addUpdatedItem(item: T): number;
152
+ private isCurrentItem;
153
+ private isNewItem;
154
+ private isRemovedItem;
155
+ private removeFromNew;
156
+ private removeFromCurrent;
157
+ private removeFromRemoved;
158
+ private wasAddedInitially;
159
+ exists(item: T): boolean;
160
+ add(item: T): void;
161
+ remove(item: T): void;
162
+ update(items: T[]): void;
163
+ }
164
+
165
+ type DtoResponsePagination = {
166
+ count: number;
167
+ query: {
168
+ page: string;
169
+ size: string;
170
+ };
171
+ withPagination: boolean;
172
+ };
173
+
174
+ declare function getTakeAndSkip(size: string, page: string): {
175
+ take: number;
176
+ skip: number;
177
+ };
178
+
179
+ type HealthCheckOutput = {
180
+ dbIsOnline: boolean;
181
+ };
182
+ interface IHealthCheck {
183
+ check(): Promise<HealthCheckOutput>;
184
+ }
185
+ interface ICheckDB {
186
+ dbIsOnline(): Promise<boolean>;
187
+ }
188
+
189
+ type Pagination<T> = {
190
+ data: T[];
191
+ count?: number;
192
+ };
193
+ type NotPagination<T> = {
194
+ data: T[];
195
+ };
196
+
197
+ type RequestHttp = {
198
+ body: Record<string, any>;
199
+ params: Record<string, any>;
200
+ headers: Record<string, any>;
201
+ query: Record<string, any>;
202
+ };
203
+
204
+ declare class ExpressAdapter implements IHttp {
205
+ readonly env: Record<string, any>;
206
+ readonly instance: Express;
207
+ private server;
208
+ constructor(env: Record<string, any>);
209
+ registerRoute(controllerClass: BaseController): void;
210
+ startServer(port: number): Promise<void>;
211
+ closeServer(): Promise<void>;
212
+ }
213
+
214
+ declare class FastifyAdapter implements IHttp {
215
+ readonly env: Record<string, any>;
216
+ readonly instance: FastifyInstance;
217
+ constructor(env: Record<string, any>);
218
+ registerRoute(controllerClass: BaseController): void;
219
+ startServer(port: number): Promise<void>;
220
+ closeServer(): Promise<void>;
221
+ }
222
+
223
+ type DiscordOptions = {
224
+ url: string;
225
+ env: string;
226
+ };
227
+ declare class DiscordNotifier implements IErrorNotifier {
228
+ private readonly options;
229
+ private webhook;
230
+ constructor(options: DiscordOptions);
231
+ notify(error: Error, context: ContextError): Promise<void>;
232
+ }
233
+
234
+ declare class NotificationErrorInMemory implements IErrorNotifier {
235
+ errors: any[];
236
+ notify(error: Error, context?: ContextError): Promise<void>;
237
+ }
238
+
239
+ declare const baseEnvSchema: z.ZodObject<{
240
+ NODE_ENV: z.ZodDefault<z.ZodEnum<["test", "development", "production"]>>;
241
+ ENVIRONMENT: z.ZodDefault<z.ZodEnum<["test", "development", "staging", "production"]>>;
242
+ PORT: z.ZodDefault<z.ZodNumber>;
243
+ SHOULD_NOTIFY_ERROR: z.ZodDefault<z.ZodBoolean>;
244
+ SENTRY_DSN: z.ZodOptional<z.ZodString>;
245
+ DISCORD_WEBHOOK_URL: z.ZodOptional<z.ZodString>;
246
+ }, "strip", z.ZodTypeAny, {
247
+ ENVIRONMENT: "test" | "development" | "production" | "staging";
248
+ SHOULD_NOTIFY_ERROR: boolean;
249
+ NODE_ENV: "test" | "development" | "production";
250
+ PORT: number;
251
+ SENTRY_DSN?: string | undefined;
252
+ DISCORD_WEBHOOK_URL?: string | undefined;
253
+ }, {
254
+ ENVIRONMENT?: "test" | "development" | "production" | "staging" | undefined;
255
+ SHOULD_NOTIFY_ERROR?: boolean | undefined;
256
+ NODE_ENV?: "test" | "development" | "production" | undefined;
257
+ PORT?: number | undefined;
258
+ SENTRY_DSN?: string | undefined;
259
+ DISCORD_WEBHOOK_URL?: string | undefined;
260
+ }>;
261
+
262
+ type OptionsNotifications = 'console' | 'discord' | 'sentry';
263
+ type EnvironmentEnum = z.infer<typeof baseEnvSchema>['ENVIRONMENT'];
264
+ type Props = {
265
+ local?: OptionsNotifications;
266
+ test?: OptionsNotifications;
267
+ development?: OptionsNotifications;
268
+ staging?: OptionsNotifications;
269
+ production?: OptionsNotifications;
270
+ };
271
+ declare class NotificationFactory {
272
+ static define(env: EnvironmentEnum, definitions?: Props): any;
273
+ private static defineProvider;
274
+ }
275
+
276
+ type SentryOptions = {
277
+ dsn: string;
278
+ environment: string;
279
+ };
280
+ declare class SentryNotifier implements IErrorNotifier {
281
+ private readonly options;
282
+ constructor(options: SentryOptions);
283
+ notify(error: Error, context: ContextError): Promise<void>;
284
+ }
285
+
286
+ export { AggregateRoot, BaseController, CommonDTO, ContextError, Controller, CreateCommonDTO, DependencyContainer, DiscordNotifier, DtoResponsePagination, Entity, ExpressAdapter, FastifyAdapter, ICheckDB, IErrorNotifier, IHealthCheck, Inject, MiddlewareFunction, NotPagination, NotificationErrorInMemory, NotificationFactory, Optional, Pagination, Replace, Request, RequestHttp, Response, SentryNotifier, UniqueEntityId, ValueObject, WatchedList, ZodSchema, baseEnvSchema, getTakeAndSkip, zodValidator };
@@ -1384,4 +1384,4 @@ export {
1384
1384
  getTakeAndSkip,
1385
1385
  zodValidator
1386
1386
  };
1387
- //# sourceMappingURL=index.js.map
1387
+ //# sourceMappingURL=index.mjs.map
package/package.json CHANGED
@@ -1,17 +1,18 @@
1
1
  {
2
2
  "name": "plutin",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "Plutin lib",
5
5
  "private": false,
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
9
9
  "exports": {
10
- ".": "./dist/index.js"
10
+ "import": "./dist/esm/index.js",
11
+ "require": "./dist/cjs/index.js"
11
12
  },
12
13
  "type": "module",
13
14
  "main": "./dist/index.js",
14
- "types": "./dist/index.d.ts",
15
+ "types": "./dist/esm/index.d.ts",
15
16
  "files": [
16
17
  "dist"
17
18
  ],
@@ -19,7 +20,7 @@
19
20
  "author": "Pablo",
20
21
  "license": "ISC",
21
22
  "scripts": {
22
- "build": "tsup src --format cjs,esm --dts",
23
+ "build": "tsup",
23
24
  "prepare:husky": "husky install",
24
25
  "eslint:fix": "npx eslint --fix src/**/*.ts",
25
26
  "prettier:format": "prettier --write src/**/*.ts",