plutin 1.2.3 → 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 (235) hide show
  1. package/dist/index.cjs.map +1 -1
  2. package/dist/index.d.cts +286 -27
  3. package/dist/index.d.ts +286 -27
  4. package/dist/{index.js → index.mjs} +1 -1
  5. package/package.json +5 -4
  6. package/dist/base-controller-68008870.d.ts +0 -46
  7. package/dist/core/decorators/controller-http-decorator.cjs +0 -310
  8. package/dist/core/decorators/controller-http-decorator.cjs.map +0 -1
  9. package/dist/core/decorators/controller-http-decorator.d.cts +0 -13
  10. package/dist/core/decorators/controller-http-decorator.d.ts +0 -13
  11. package/dist/core/decorators/controller-http-decorator.js +0 -285
  12. package/dist/core/decorators/controller-http-decorator.js.map +0 -1
  13. package/dist/core/decorators/dependency-container.cjs +0 -95
  14. package/dist/core/decorators/dependency-container.cjs.map +0 -1
  15. package/dist/core/decorators/dependency-container.d.cts +0 -22
  16. package/dist/core/decorators/dependency-container.d.ts +0 -22
  17. package/dist/core/decorators/dependency-container.js +0 -71
  18. package/dist/core/decorators/dependency-container.js.map +0 -1
  19. package/dist/core/entities/aggregate-root.cjs +0 -99
  20. package/dist/core/entities/aggregate-root.cjs.map +0 -1
  21. package/dist/core/entities/aggregate-root.d.cts +0 -8
  22. package/dist/core/entities/aggregate-root.d.ts +0 -8
  23. package/dist/core/entities/aggregate-root.js +0 -74
  24. package/dist/core/entities/aggregate-root.js.map +0 -1
  25. package/dist/core/entities/common-dto.cjs +0 -19
  26. package/dist/core/entities/common-dto.cjs.map +0 -1
  27. package/dist/core/entities/common-dto.d.cts +0 -10
  28. package/dist/core/entities/common-dto.d.ts +0 -10
  29. package/dist/core/entities/common-dto.js +0 -1
  30. package/dist/core/entities/common-dto.js.map +0 -1
  31. package/dist/core/entities/domain-event.cjs +0 -19
  32. package/dist/core/entities/domain-event.cjs.map +0 -1
  33. package/dist/core/entities/domain-event.d.cts +0 -6
  34. package/dist/core/entities/domain-event.d.ts +0 -6
  35. package/dist/core/entities/domain-event.js +0 -1
  36. package/dist/core/entities/domain-event.js.map +0 -1
  37. package/dist/core/entities/entity.cjs +0 -92
  38. package/dist/core/entities/entity.cjs.map +0 -1
  39. package/dist/core/entities/entity.d.cts +0 -18
  40. package/dist/core/entities/entity.d.ts +0 -18
  41. package/dist/core/entities/entity.js +0 -67
  42. package/dist/core/entities/entity.js.map +0 -1
  43. package/dist/core/entities/optional.cjs +0 -19
  44. package/dist/core/entities/optional.cjs.map +0 -1
  45. package/dist/core/entities/optional.d.cts +0 -3
  46. package/dist/core/entities/optional.d.ts +0 -3
  47. package/dist/core/entities/optional.js +0 -1
  48. package/dist/core/entities/optional.js.map +0 -1
  49. package/dist/core/entities/unique-entity-id.cjs +0 -50
  50. package/dist/core/entities/unique-entity-id.cjs.map +0 -1
  51. package/dist/core/entities/unique-entity-id.d.cts +0 -9
  52. package/dist/core/entities/unique-entity-id.d.ts +0 -9
  53. package/dist/core/entities/unique-entity-id.js +0 -27
  54. package/dist/core/entities/unique-entity-id.js.map +0 -1
  55. package/dist/core/entities/value-object.cjs +0 -40
  56. package/dist/core/entities/value-object.cjs.map +0 -1
  57. package/dist/core/entities/value-object.d.cts +0 -6
  58. package/dist/core/entities/value-object.d.ts +0 -6
  59. package/dist/core/entities/value-object.js +0 -17
  60. package/dist/core/entities/value-object.js.map +0 -1
  61. package/dist/core/entities/watched-list.cjs +0 -121
  62. package/dist/core/entities/watched-list.cjs.map +0 -1
  63. package/dist/core/entities/watched-list.d.cts +0 -27
  64. package/dist/core/entities/watched-list.d.ts +0 -27
  65. package/dist/core/entities/watched-list.js +0 -98
  66. package/dist/core/entities/watched-list.js.map +0 -1
  67. package/dist/core/entities/watched-list.test.cjs +0 -186
  68. package/dist/core/entities/watched-list.test.cjs.map +0 -1
  69. package/dist/core/entities/watched-list.test.d.cts +0 -2
  70. package/dist/core/entities/watched-list.test.d.ts +0 -2
  71. package/dist/core/entities/watched-list.test.js +0 -185
  72. package/dist/core/entities/watched-list.test.js.map +0 -1
  73. package/dist/core/errors/api-common-error.cjs +0 -38
  74. package/dist/core/errors/api-common-error.cjs.map +0 -1
  75. package/dist/core/errors/api-common-error.d.cts +0 -28
  76. package/dist/core/errors/api-common-error.d.ts +0 -28
  77. package/dist/core/errors/api-common-error.js +0 -13
  78. package/dist/core/errors/api-common-error.js.map +0 -1
  79. package/dist/core/errors/application-error.cjs +0 -54
  80. package/dist/core/errors/application-error.cjs.map +0 -1
  81. package/dist/core/errors/application-error.d.cts +0 -8
  82. package/dist/core/errors/application-error.d.ts +0 -8
  83. package/dist/core/errors/application-error.js +0 -33
  84. package/dist/core/errors/application-error.js.map +0 -1
  85. package/dist/core/errors/conflict-error.cjs +0 -56
  86. package/dist/core/errors/conflict-error.cjs.map +0 -1
  87. package/dist/core/errors/conflict-error.d.cts +0 -13
  88. package/dist/core/errors/conflict-error.d.ts +0 -13
  89. package/dist/core/errors/conflict-error.js +0 -35
  90. package/dist/core/errors/conflict-error.js.map +0 -1
  91. package/dist/core/errors/domain-error.cjs +0 -54
  92. package/dist/core/errors/domain-error.cjs.map +0 -1
  93. package/dist/core/errors/domain-error.d.cts +0 -8
  94. package/dist/core/errors/domain-error.d.ts +0 -8
  95. package/dist/core/errors/domain-error.js +0 -33
  96. package/dist/core/errors/domain-error.js.map +0 -1
  97. package/dist/core/errors/http-client-error.cjs +0 -54
  98. package/dist/core/errors/http-client-error.cjs.map +0 -1
  99. package/dist/core/errors/http-client-error.d.cts +0 -8
  100. package/dist/core/errors/http-client-error.d.ts +0 -8
  101. package/dist/core/errors/http-client-error.js +0 -33
  102. package/dist/core/errors/http-client-error.js.map +0 -1
  103. package/dist/core/errors/infra-error.cjs +0 -54
  104. package/dist/core/errors/infra-error.cjs.map +0 -1
  105. package/dist/core/errors/infra-error.d.cts +0 -8
  106. package/dist/core/errors/infra-error.d.ts +0 -8
  107. package/dist/core/errors/infra-error.js +0 -33
  108. package/dist/core/errors/infra-error.js.map +0 -1
  109. package/dist/core/errors/validation-error.cjs +0 -55
  110. package/dist/core/errors/validation-error.cjs.map +0 -1
  111. package/dist/core/errors/validation-error.d.cts +0 -8
  112. package/dist/core/errors/validation-error.d.ts +0 -8
  113. package/dist/core/errors/validation-error.js +0 -34
  114. package/dist/core/errors/validation-error.js.map +0 -1
  115. package/dist/core/http/base-controller.cjs +0 -295
  116. package/dist/core/http/base-controller.cjs.map +0 -1
  117. package/dist/core/http/base-controller.d.cts +0 -1
  118. package/dist/core/http/base-controller.d.ts +0 -1
  119. package/dist/core/http/base-controller.js +0 -270
  120. package/dist/core/http/base-controller.js.map +0 -1
  121. package/dist/core/http/dto-response.cjs +0 -19
  122. package/dist/core/http/dto-response.cjs.map +0 -1
  123. package/dist/core/http/dto-response.d.cts +0 -10
  124. package/dist/core/http/dto-response.d.ts +0 -10
  125. package/dist/core/http/dto-response.js +0 -1
  126. package/dist/core/http/dto-response.js.map +0 -1
  127. package/dist/core/http/error-notifier.cjs +0 -19
  128. package/dist/core/http/error-notifier.cjs.map +0 -1
  129. package/dist/core/http/error-notifier.d.cts +0 -1
  130. package/dist/core/http/error-notifier.d.ts +0 -1
  131. package/dist/core/http/error-notifier.js +0 -1
  132. package/dist/core/http/error-notifier.js.map +0 -1
  133. package/dist/core/http/get-take-and-skip.cjs +0 -40
  134. package/dist/core/http/get-take-and-skip.cjs.map +0 -1
  135. package/dist/core/http/get-take-and-skip.d.cts +0 -6
  136. package/dist/core/http/get-take-and-skip.d.ts +0 -6
  137. package/dist/core/http/get-take-and-skip.js +0 -17
  138. package/dist/core/http/get-take-and-skip.js.map +0 -1
  139. package/dist/core/http/health-connections.cjs +0 -42
  140. package/dist/core/http/health-connections.cjs.map +0 -1
  141. package/dist/core/http/health-connections.d.cts +0 -16
  142. package/dist/core/http/health-connections.d.ts +0 -16
  143. package/dist/core/http/health-connections.js +0 -23
  144. package/dist/core/http/health-connections.js.map +0 -1
  145. package/dist/core/http/http.cjs +0 -19
  146. package/dist/core/http/http.cjs.map +0 -1
  147. package/dist/core/http/http.d.cts +0 -10
  148. package/dist/core/http/http.d.ts +0 -10
  149. package/dist/core/http/http.js +0 -1
  150. package/dist/core/http/http.js.map +0 -1
  151. package/dist/core/http/pagination.cjs +0 -19
  152. package/dist/core/http/pagination.cjs.map +0 -1
  153. package/dist/core/http/pagination.d.cts +0 -9
  154. package/dist/core/http/pagination.d.ts +0 -9
  155. package/dist/core/http/pagination.js +0 -1
  156. package/dist/core/http/pagination.js.map +0 -1
  157. package/dist/core/http/validator.cjs +0 -19
  158. package/dist/core/http/validator.cjs.map +0 -1
  159. package/dist/core/http/validator.d.cts +0 -11
  160. package/dist/core/http/validator.d.ts +0 -11
  161. package/dist/core/http/validator.js +0 -1
  162. package/dist/core/http/validator.js.map +0 -1
  163. package/dist/infra/adapters/http/express-adapter.cjs +0 -139
  164. package/dist/infra/adapters/http/express-adapter.cjs.map +0 -1
  165. package/dist/infra/adapters/http/express-adapter.d.cts +0 -15
  166. package/dist/infra/adapters/http/express-adapter.d.ts +0 -15
  167. package/dist/infra/adapters/http/express-adapter.js +0 -106
  168. package/dist/infra/adapters/http/express-adapter.js.map +0 -1
  169. package/dist/infra/adapters/http/fastify-adapter.cjs +0 -124
  170. package/dist/infra/adapters/http/fastify-adapter.cjs.map +0 -1
  171. package/dist/infra/adapters/http/fastify-adapter.d.cts +0 -14
  172. package/dist/infra/adapters/http/fastify-adapter.d.ts +0 -14
  173. package/dist/infra/adapters/http/fastify-adapter.js +0 -91
  174. package/dist/infra/adapters/http/fastify-adapter.js.map +0 -1
  175. package/dist/infra/adapters/http/response-error-code.cjs +0 -35
  176. package/dist/infra/adapters/http/response-error-code.cjs.map +0 -1
  177. package/dist/infra/adapters/http/response-error-code.d.cts +0 -6
  178. package/dist/infra/adapters/http/response-error-code.d.ts +0 -6
  179. package/dist/infra/adapters/http/response-error-code.js +0 -10
  180. package/dist/infra/adapters/http/response-error-code.js.map +0 -1
  181. package/dist/infra/adapters/http/validate-controller-metadata.cjs +0 -42
  182. package/dist/infra/adapters/http/validate-controller-metadata.cjs.map +0 -1
  183. package/dist/infra/adapters/http/validate-controller-metadata.d.cts +0 -11
  184. package/dist/infra/adapters/http/validate-controller-metadata.d.ts +0 -11
  185. package/dist/infra/adapters/http/validate-controller-metadata.js +0 -19
  186. package/dist/infra/adapters/http/validate-controller-metadata.js.map +0 -1
  187. package/dist/infra/adapters/notifications/discord.cjs +0 -90
  188. package/dist/infra/adapters/notifications/discord.cjs.map +0 -1
  189. package/dist/infra/adapters/notifications/discord.d.cts +0 -14
  190. package/dist/infra/adapters/notifications/discord.d.ts +0 -14
  191. package/dist/infra/adapters/notifications/discord.js +0 -65
  192. package/dist/infra/adapters/notifications/discord.js.map +0 -1
  193. package/dist/infra/adapters/notifications/in-memory.cjs +0 -44
  194. package/dist/infra/adapters/notifications/in-memory.cjs.map +0 -1
  195. package/dist/infra/adapters/notifications/in-memory.d.cts +0 -8
  196. package/dist/infra/adapters/notifications/in-memory.d.ts +0 -8
  197. package/dist/infra/adapters/notifications/in-memory.js +0 -21
  198. package/dist/infra/adapters/notifications/in-memory.js.map +0 -1
  199. package/dist/infra/adapters/notifications/notification-factory.cjs +0 -219
  200. package/dist/infra/adapters/notifications/notification-factory.cjs.map +0 -1
  201. package/dist/infra/adapters/notifications/notification-factory.d.cts +0 -18
  202. package/dist/infra/adapters/notifications/notification-factory.d.ts +0 -18
  203. package/dist/infra/adapters/notifications/notification-factory.js +0 -184
  204. package/dist/infra/adapters/notifications/notification-factory.js.map +0 -1
  205. package/dist/infra/adapters/notifications/sentry.cjs +0 -129
  206. package/dist/infra/adapters/notifications/sentry.cjs.map +0 -1
  207. package/dist/infra/adapters/notifications/sentry.d.cts +0 -13
  208. package/dist/infra/adapters/notifications/sentry.d.ts +0 -13
  209. package/dist/infra/adapters/notifications/sentry.js +0 -96
  210. package/dist/infra/adapters/notifications/sentry.js.map +0 -1
  211. package/dist/infra/adapters/validators/zod/index.cjs +0 -179
  212. package/dist/infra/adapters/validators/zod/index.cjs.map +0 -1
  213. package/dist/infra/adapters/validators/zod/index.d.cts +0 -19
  214. package/dist/infra/adapters/validators/zod/index.d.ts +0 -19
  215. package/dist/infra/adapters/validators/zod/index.js +0 -154
  216. package/dist/infra/adapters/validators/zod/index.js.map +0 -1
  217. package/dist/infra/adapters/validators/zod/zod-map-error.cjs +0 -79
  218. package/dist/infra/adapters/validators/zod/zod-map-error.cjs.map +0 -1
  219. package/dist/infra/adapters/validators/zod/zod-map-error.d.cts +0 -15
  220. package/dist/infra/adapters/validators/zod/zod-map-error.d.ts +0 -15
  221. package/dist/infra/adapters/validators/zod/zod-map-error.js +0 -60
  222. package/dist/infra/adapters/validators/zod/zod-map-error.js.map +0 -1
  223. package/dist/infra/adapters/validators/zod/zod-validator.cjs +0 -178
  224. package/dist/infra/adapters/validators/zod/zod-validator.cjs.map +0 -1
  225. package/dist/infra/adapters/validators/zod/zod-validator.d.cts +0 -13
  226. package/dist/infra/adapters/validators/zod/zod-validator.d.ts +0 -13
  227. package/dist/infra/adapters/validators/zod/zod-validator.js +0 -153
  228. package/dist/infra/adapters/validators/zod/zod-validator.js.map +0 -1
  229. package/dist/infra/env/index.cjs +0 -467
  230. package/dist/infra/env/index.cjs.map +0 -1
  231. package/dist/infra/env/index.d.cts +0 -26
  232. package/dist/infra/env/index.d.ts +0 -26
  233. package/dist/infra/env/index.js +0 -452
  234. package/dist/infra/env/index.js.map +0 -1
  235. /package/dist/{index.js.map → index.mjs.map} +0 -0
package/dist/index.d.cts CHANGED
@@ -1,27 +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 { UniqueEntityId } from './core/entities/unique-entity-id.cjs';
8
- export { ValueObject } from './core/entities/value-object.cjs';
9
- export { WatchedList } from './core/entities/watched-list.cjs';
10
- export { B as BaseController, C as ContextError, I as IErrorNotifier, R as Request, a as Response } from './base-controller-68008870.js';
11
- export { DtoResponsePagination } from './core/http/dto-response.cjs';
12
- export { getTakeAndSkip } from './core/http/get-take-and-skip.cjs';
13
- export { ICheckDB, IHealthCheck } from './core/http/health-connections.cjs';
14
- export { NotPagination, Pagination } from './core/http/pagination.cjs';
15
- export { RequestHttp } from './core/http/validator.cjs';
16
- export { ExpressAdapter } from './infra/adapters/http/express-adapter.cjs';
17
- export { FastifyAdapter } from './infra/adapters/http/fastify-adapter.cjs';
18
- export { DiscordNotifier } from './infra/adapters/notifications/discord.cjs';
19
- export { NotificationErrorInMemory } from './infra/adapters/notifications/in-memory.cjs';
20
- export { NotificationFactory } from './infra/adapters/notifications/notification-factory.cjs';
21
- export { SentryNotifier } from './infra/adapters/notifications/sentry.cjs';
22
- export { MiddlewareFunction, ZodSchema, zodValidator } from './infra/adapters/validators/zod/zod-validator.cjs';
23
- export { baseEnvSchema } from './infra/env/index.cjs';
24
- import './core/http/http.cjs';
25
- import 'express';
26
- import 'fastify';
27
- 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,27 +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 { UniqueEntityId } from './core/entities/unique-entity-id.js';
8
- export { ValueObject } from './core/entities/value-object.js';
9
- export { WatchedList } from './core/entities/watched-list.js';
10
- export { B as BaseController, C as ContextError, I as IErrorNotifier, R as Request, a as Response } from './base-controller-68008870.js';
11
- export { DtoResponsePagination } from './core/http/dto-response.js';
12
- export { getTakeAndSkip } from './core/http/get-take-and-skip.js';
13
- export { ICheckDB, IHealthCheck } from './core/http/health-connections.js';
14
- export { NotPagination, Pagination } from './core/http/pagination.js';
15
- export { RequestHttp } from './core/http/validator.js';
16
- export { ExpressAdapter } from './infra/adapters/http/express-adapter.js';
17
- export { FastifyAdapter } from './infra/adapters/http/fastify-adapter.js';
18
- export { DiscordNotifier } from './infra/adapters/notifications/discord.js';
19
- export { NotificationErrorInMemory } from './infra/adapters/notifications/in-memory.js';
20
- export { NotificationFactory } from './infra/adapters/notifications/notification-factory.js';
21
- export { SentryNotifier } from './infra/adapters/notifications/sentry.js';
22
- export { MiddlewareFunction, ZodSchema, zodValidator } from './infra/adapters/validators/zod/zod-validator.js';
23
- export { baseEnvSchema } from './infra/env/index.js';
24
- import './core/http/http.js';
25
- import 'express';
26
- import 'fastify';
27
- 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.2.3",
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",