plutin 1.3.0 → 1.3.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.
- package/dist/index.d.cts +286 -28
- package/dist/index.d.ts +286 -28
- package/dist/{index.js → index.mjs} +1 -1
- package/package.json +4 -3
- package/dist/base-controller-68008870.d.ts +0 -46
- package/dist/core/decorators/controller-http-decorator.cjs +0 -310
- package/dist/core/decorators/controller-http-decorator.cjs.map +0 -1
- package/dist/core/decorators/controller-http-decorator.d.cts +0 -13
- package/dist/core/decorators/controller-http-decorator.d.ts +0 -13
- package/dist/core/decorators/controller-http-decorator.js +0 -285
- package/dist/core/decorators/controller-http-decorator.js.map +0 -1
- package/dist/core/decorators/dependency-container.cjs +0 -95
- package/dist/core/decorators/dependency-container.cjs.map +0 -1
- package/dist/core/decorators/dependency-container.d.cts +0 -22
- package/dist/core/decorators/dependency-container.d.ts +0 -22
- package/dist/core/decorators/dependency-container.js +0 -71
- package/dist/core/decorators/dependency-container.js.map +0 -1
- package/dist/core/entities/aggregate-root.cjs +0 -99
- package/dist/core/entities/aggregate-root.cjs.map +0 -1
- package/dist/core/entities/aggregate-root.d.cts +0 -8
- package/dist/core/entities/aggregate-root.d.ts +0 -8
- package/dist/core/entities/aggregate-root.js +0 -74
- package/dist/core/entities/aggregate-root.js.map +0 -1
- package/dist/core/entities/common-dto.cjs +0 -19
- package/dist/core/entities/common-dto.cjs.map +0 -1
- package/dist/core/entities/common-dto.d.cts +0 -10
- package/dist/core/entities/common-dto.d.ts +0 -10
- package/dist/core/entities/common-dto.js +0 -1
- package/dist/core/entities/common-dto.js.map +0 -1
- package/dist/core/entities/domain-event.cjs +0 -19
- package/dist/core/entities/domain-event.cjs.map +0 -1
- package/dist/core/entities/domain-event.d.cts +0 -6
- package/dist/core/entities/domain-event.d.ts +0 -6
- package/dist/core/entities/domain-event.js +0 -1
- package/dist/core/entities/domain-event.js.map +0 -1
- package/dist/core/entities/entity.cjs +0 -92
- package/dist/core/entities/entity.cjs.map +0 -1
- package/dist/core/entities/entity.d.cts +0 -18
- package/dist/core/entities/entity.d.ts +0 -18
- package/dist/core/entities/entity.js +0 -67
- package/dist/core/entities/entity.js.map +0 -1
- package/dist/core/entities/optional.cjs +0 -19
- package/dist/core/entities/optional.cjs.map +0 -1
- package/dist/core/entities/optional.d.cts +0 -3
- package/dist/core/entities/optional.d.ts +0 -3
- package/dist/core/entities/optional.js +0 -1
- package/dist/core/entities/optional.js.map +0 -1
- package/dist/core/entities/replace.cjs +0 -19
- package/dist/core/entities/replace.cjs.map +0 -1
- package/dist/core/entities/replace.d.cts +0 -5
- package/dist/core/entities/replace.d.ts +0 -5
- package/dist/core/entities/replace.js +0 -1
- package/dist/core/entities/replace.js.map +0 -1
- package/dist/core/entities/unique-entity-id.cjs +0 -50
- package/dist/core/entities/unique-entity-id.cjs.map +0 -1
- package/dist/core/entities/unique-entity-id.d.cts +0 -9
- package/dist/core/entities/unique-entity-id.d.ts +0 -9
- package/dist/core/entities/unique-entity-id.js +0 -27
- package/dist/core/entities/unique-entity-id.js.map +0 -1
- package/dist/core/entities/value-object.cjs +0 -40
- package/dist/core/entities/value-object.cjs.map +0 -1
- package/dist/core/entities/value-object.d.cts +0 -6
- package/dist/core/entities/value-object.d.ts +0 -6
- package/dist/core/entities/value-object.js +0 -17
- package/dist/core/entities/value-object.js.map +0 -1
- package/dist/core/entities/watched-list.cjs +0 -121
- package/dist/core/entities/watched-list.cjs.map +0 -1
- package/dist/core/entities/watched-list.d.cts +0 -27
- package/dist/core/entities/watched-list.d.ts +0 -27
- package/dist/core/entities/watched-list.js +0 -98
- package/dist/core/entities/watched-list.js.map +0 -1
- package/dist/core/entities/watched-list.test.cjs +0 -186
- package/dist/core/entities/watched-list.test.cjs.map +0 -1
- package/dist/core/entities/watched-list.test.d.cts +0 -2
- package/dist/core/entities/watched-list.test.d.ts +0 -2
- package/dist/core/entities/watched-list.test.js +0 -185
- package/dist/core/entities/watched-list.test.js.map +0 -1
- package/dist/core/errors/api-common-error.cjs +0 -38
- package/dist/core/errors/api-common-error.cjs.map +0 -1
- package/dist/core/errors/api-common-error.d.cts +0 -28
- package/dist/core/errors/api-common-error.d.ts +0 -28
- package/dist/core/errors/api-common-error.js +0 -13
- package/dist/core/errors/api-common-error.js.map +0 -1
- package/dist/core/errors/application-error.cjs +0 -54
- package/dist/core/errors/application-error.cjs.map +0 -1
- package/dist/core/errors/application-error.d.cts +0 -8
- package/dist/core/errors/application-error.d.ts +0 -8
- package/dist/core/errors/application-error.js +0 -33
- package/dist/core/errors/application-error.js.map +0 -1
- package/dist/core/errors/conflict-error.cjs +0 -56
- package/dist/core/errors/conflict-error.cjs.map +0 -1
- package/dist/core/errors/conflict-error.d.cts +0 -13
- package/dist/core/errors/conflict-error.d.ts +0 -13
- package/dist/core/errors/conflict-error.js +0 -35
- package/dist/core/errors/conflict-error.js.map +0 -1
- package/dist/core/errors/domain-error.cjs +0 -54
- package/dist/core/errors/domain-error.cjs.map +0 -1
- package/dist/core/errors/domain-error.d.cts +0 -8
- package/dist/core/errors/domain-error.d.ts +0 -8
- package/dist/core/errors/domain-error.js +0 -33
- package/dist/core/errors/domain-error.js.map +0 -1
- package/dist/core/errors/http-client-error.cjs +0 -54
- package/dist/core/errors/http-client-error.cjs.map +0 -1
- package/dist/core/errors/http-client-error.d.cts +0 -8
- package/dist/core/errors/http-client-error.d.ts +0 -8
- package/dist/core/errors/http-client-error.js +0 -33
- package/dist/core/errors/http-client-error.js.map +0 -1
- package/dist/core/errors/infra-error.cjs +0 -54
- package/dist/core/errors/infra-error.cjs.map +0 -1
- package/dist/core/errors/infra-error.d.cts +0 -8
- package/dist/core/errors/infra-error.d.ts +0 -8
- package/dist/core/errors/infra-error.js +0 -33
- package/dist/core/errors/infra-error.js.map +0 -1
- package/dist/core/errors/validation-error.cjs +0 -55
- package/dist/core/errors/validation-error.cjs.map +0 -1
- package/dist/core/errors/validation-error.d.cts +0 -8
- package/dist/core/errors/validation-error.d.ts +0 -8
- package/dist/core/errors/validation-error.js +0 -34
- package/dist/core/errors/validation-error.js.map +0 -1
- package/dist/core/http/base-controller.cjs +0 -295
- package/dist/core/http/base-controller.cjs.map +0 -1
- package/dist/core/http/base-controller.d.cts +0 -1
- package/dist/core/http/base-controller.d.ts +0 -1
- package/dist/core/http/base-controller.js +0 -270
- package/dist/core/http/base-controller.js.map +0 -1
- package/dist/core/http/dto-response.cjs +0 -19
- package/dist/core/http/dto-response.cjs.map +0 -1
- package/dist/core/http/dto-response.d.cts +0 -10
- package/dist/core/http/dto-response.d.ts +0 -10
- package/dist/core/http/dto-response.js +0 -1
- package/dist/core/http/dto-response.js.map +0 -1
- package/dist/core/http/error-notifier.cjs +0 -19
- package/dist/core/http/error-notifier.cjs.map +0 -1
- package/dist/core/http/error-notifier.d.cts +0 -1
- package/dist/core/http/error-notifier.d.ts +0 -1
- package/dist/core/http/error-notifier.js +0 -1
- package/dist/core/http/error-notifier.js.map +0 -1
- package/dist/core/http/get-take-and-skip.cjs +0 -40
- package/dist/core/http/get-take-and-skip.cjs.map +0 -1
- package/dist/core/http/get-take-and-skip.d.cts +0 -6
- package/dist/core/http/get-take-and-skip.d.ts +0 -6
- package/dist/core/http/get-take-and-skip.js +0 -17
- package/dist/core/http/get-take-and-skip.js.map +0 -1
- package/dist/core/http/health-connections.cjs +0 -42
- package/dist/core/http/health-connections.cjs.map +0 -1
- package/dist/core/http/health-connections.d.cts +0 -16
- package/dist/core/http/health-connections.d.ts +0 -16
- package/dist/core/http/health-connections.js +0 -23
- package/dist/core/http/health-connections.js.map +0 -1
- package/dist/core/http/http.cjs +0 -19
- package/dist/core/http/http.cjs.map +0 -1
- package/dist/core/http/http.d.cts +0 -10
- package/dist/core/http/http.d.ts +0 -10
- package/dist/core/http/http.js +0 -1
- package/dist/core/http/http.js.map +0 -1
- package/dist/core/http/pagination.cjs +0 -19
- package/dist/core/http/pagination.cjs.map +0 -1
- package/dist/core/http/pagination.d.cts +0 -9
- package/dist/core/http/pagination.d.ts +0 -9
- package/dist/core/http/pagination.js +0 -1
- package/dist/core/http/pagination.js.map +0 -1
- package/dist/core/http/validator.cjs +0 -19
- package/dist/core/http/validator.cjs.map +0 -1
- package/dist/core/http/validator.d.cts +0 -11
- package/dist/core/http/validator.d.ts +0 -11
- package/dist/core/http/validator.js +0 -1
- package/dist/core/http/validator.js.map +0 -1
- package/dist/infra/adapters/http/express-adapter.cjs +0 -139
- package/dist/infra/adapters/http/express-adapter.cjs.map +0 -1
- package/dist/infra/adapters/http/express-adapter.d.cts +0 -15
- package/dist/infra/adapters/http/express-adapter.d.ts +0 -15
- package/dist/infra/adapters/http/express-adapter.js +0 -106
- package/dist/infra/adapters/http/express-adapter.js.map +0 -1
- package/dist/infra/adapters/http/fastify-adapter.cjs +0 -124
- package/dist/infra/adapters/http/fastify-adapter.cjs.map +0 -1
- package/dist/infra/adapters/http/fastify-adapter.d.cts +0 -14
- package/dist/infra/adapters/http/fastify-adapter.d.ts +0 -14
- package/dist/infra/adapters/http/fastify-adapter.js +0 -91
- package/dist/infra/adapters/http/fastify-adapter.js.map +0 -1
- package/dist/infra/adapters/http/response-error-code.cjs +0 -35
- package/dist/infra/adapters/http/response-error-code.cjs.map +0 -1
- package/dist/infra/adapters/http/response-error-code.d.cts +0 -6
- package/dist/infra/adapters/http/response-error-code.d.ts +0 -6
- package/dist/infra/adapters/http/response-error-code.js +0 -10
- package/dist/infra/adapters/http/response-error-code.js.map +0 -1
- package/dist/infra/adapters/http/validate-controller-metadata.cjs +0 -42
- package/dist/infra/adapters/http/validate-controller-metadata.cjs.map +0 -1
- package/dist/infra/adapters/http/validate-controller-metadata.d.cts +0 -11
- package/dist/infra/adapters/http/validate-controller-metadata.d.ts +0 -11
- package/dist/infra/adapters/http/validate-controller-metadata.js +0 -19
- package/dist/infra/adapters/http/validate-controller-metadata.js.map +0 -1
- package/dist/infra/adapters/notifications/discord.cjs +0 -90
- package/dist/infra/adapters/notifications/discord.cjs.map +0 -1
- package/dist/infra/adapters/notifications/discord.d.cts +0 -14
- package/dist/infra/adapters/notifications/discord.d.ts +0 -14
- package/dist/infra/adapters/notifications/discord.js +0 -65
- package/dist/infra/adapters/notifications/discord.js.map +0 -1
- package/dist/infra/adapters/notifications/in-memory.cjs +0 -44
- package/dist/infra/adapters/notifications/in-memory.cjs.map +0 -1
- package/dist/infra/adapters/notifications/in-memory.d.cts +0 -8
- package/dist/infra/adapters/notifications/in-memory.d.ts +0 -8
- package/dist/infra/adapters/notifications/in-memory.js +0 -21
- package/dist/infra/adapters/notifications/in-memory.js.map +0 -1
- package/dist/infra/adapters/notifications/notification-factory.cjs +0 -219
- package/dist/infra/adapters/notifications/notification-factory.cjs.map +0 -1
- package/dist/infra/adapters/notifications/notification-factory.d.cts +0 -18
- package/dist/infra/adapters/notifications/notification-factory.d.ts +0 -18
- package/dist/infra/adapters/notifications/notification-factory.js +0 -184
- package/dist/infra/adapters/notifications/notification-factory.js.map +0 -1
- package/dist/infra/adapters/notifications/sentry.cjs +0 -129
- package/dist/infra/adapters/notifications/sentry.cjs.map +0 -1
- package/dist/infra/adapters/notifications/sentry.d.cts +0 -13
- package/dist/infra/adapters/notifications/sentry.d.ts +0 -13
- package/dist/infra/adapters/notifications/sentry.js +0 -96
- package/dist/infra/adapters/notifications/sentry.js.map +0 -1
- package/dist/infra/adapters/validators/zod/index.cjs +0 -179
- package/dist/infra/adapters/validators/zod/index.cjs.map +0 -1
- package/dist/infra/adapters/validators/zod/index.d.cts +0 -19
- package/dist/infra/adapters/validators/zod/index.d.ts +0 -19
- package/dist/infra/adapters/validators/zod/index.js +0 -154
- package/dist/infra/adapters/validators/zod/index.js.map +0 -1
- package/dist/infra/adapters/validators/zod/zod-map-error.cjs +0 -79
- package/dist/infra/adapters/validators/zod/zod-map-error.cjs.map +0 -1
- package/dist/infra/adapters/validators/zod/zod-map-error.d.cts +0 -15
- package/dist/infra/adapters/validators/zod/zod-map-error.d.ts +0 -15
- package/dist/infra/adapters/validators/zod/zod-map-error.js +0 -60
- package/dist/infra/adapters/validators/zod/zod-map-error.js.map +0 -1
- package/dist/infra/adapters/validators/zod/zod-validator.cjs +0 -178
- package/dist/infra/adapters/validators/zod/zod-validator.cjs.map +0 -1
- package/dist/infra/adapters/validators/zod/zod-validator.d.cts +0 -13
- package/dist/infra/adapters/validators/zod/zod-validator.d.ts +0 -13
- package/dist/infra/adapters/validators/zod/zod-validator.js +0 -153
- package/dist/infra/adapters/validators/zod/zod-validator.js.map +0 -1
- package/dist/infra/env/index.cjs +0 -467
- package/dist/infra/env/index.cjs.map +0 -1
- package/dist/infra/env/index.d.cts +0 -26
- package/dist/infra/env/index.d.ts +0 -26
- package/dist/infra/env/index.js +0 -452
- package/dist/infra/env/index.js.map +0 -1
- /package/dist/{index.js.map → index.mjs.map} +0 -0
package/dist/index.d.cts
CHANGED
|
@@ -1,28 +1,286 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "plutin",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "Plutin lib",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
9
9
|
"exports": {
|
|
10
|
-
"
|
|
10
|
+
"import": "./dist/index.mjs",
|
|
11
|
+
"require": "./dist/index.cjs"
|
|
11
12
|
},
|
|
12
13
|
"type": "module",
|
|
13
14
|
"main": "./dist/index.js",
|
|
@@ -19,7 +20,7 @@
|
|
|
19
20
|
"author": "Pablo",
|
|
20
21
|
"license": "ISC",
|
|
21
22
|
"scripts": {
|
|
22
|
-
"build": "tsup
|
|
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",
|