plutin 1.3.8 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +86 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +33 -8
- package/dist/index.d.ts +33 -8
- package/dist/index.mjs +84 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/dist/index.d.cts
CHANGED
|
@@ -2,10 +2,6 @@ import { z } from 'zod';
|
|
|
2
2
|
import { Express } from 'express';
|
|
3
3
|
import { FastifyInstance } from 'fastify';
|
|
4
4
|
|
|
5
|
-
interface IErrorNotifier {
|
|
6
|
-
notify(error: Error, context: ContextError): Promise<void>;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
5
|
type AnyObject = Record<string, any>;
|
|
10
6
|
type Request = {
|
|
11
7
|
body: AnyObject;
|
|
@@ -47,6 +43,17 @@ declare abstract class BaseController {
|
|
|
47
43
|
execute(request: Request): Promise<Response>;
|
|
48
44
|
}
|
|
49
45
|
|
|
46
|
+
interface IErrorNotifier {
|
|
47
|
+
notify(error: Error, context: ContextError): Promise<void>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
declare class GlobalErrorHandler {
|
|
51
|
+
readonly env: Record<string, any>;
|
|
52
|
+
protected readonly errorNotifier: IErrorNotifier;
|
|
53
|
+
constructor(env: Record<string, any>);
|
|
54
|
+
register(): void;
|
|
55
|
+
}
|
|
56
|
+
|
|
50
57
|
type ZodSchema = z.ZodObject<{
|
|
51
58
|
headers: z.ZodObject<Record<string, any>>;
|
|
52
59
|
params: z.ZodObject<Record<string, any>>;
|
|
@@ -108,23 +115,41 @@ declare class UniqueEntityId {
|
|
|
108
115
|
equals(id: UniqueEntityId): boolean;
|
|
109
116
|
}
|
|
110
117
|
|
|
111
|
-
type PropsWithCommonDTO<Props> = Props & CommonDTO;
|
|
118
|
+
type PropsWithCommonDTO$1<Props> = Props & CommonDTO;
|
|
112
119
|
declare abstract class Entity<Props> {
|
|
113
120
|
private _id;
|
|
114
|
-
protected props: PropsWithCommonDTO<Props>;
|
|
121
|
+
protected props: PropsWithCommonDTO$1<Props>;
|
|
115
122
|
get id(): UniqueEntityId;
|
|
116
123
|
set id(id: UniqueEntityId);
|
|
117
124
|
get createdAt(): Date;
|
|
118
125
|
set createdAt(date: Date);
|
|
119
126
|
get updatedAt(): Date | undefined | null;
|
|
120
127
|
touch(): void;
|
|
121
|
-
protected constructor(props: PropsWithCommonDTO<Props>, id?: UniqueEntityId);
|
|
128
|
+
protected constructor(props: PropsWithCommonDTO$1<Props>, id?: UniqueEntityId);
|
|
122
129
|
equals(entity: Entity<any>): boolean;
|
|
123
130
|
}
|
|
124
131
|
|
|
125
132
|
declare abstract class AggregateRoot<Props> extends Entity<Props> {
|
|
126
133
|
}
|
|
127
134
|
|
|
135
|
+
declare class ObjectUniqueId {
|
|
136
|
+
private value;
|
|
137
|
+
constructor(value?: string);
|
|
138
|
+
toString(): string;
|
|
139
|
+
toValue(): string;
|
|
140
|
+
equals(id: ObjectUniqueId): boolean;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
type PropsWithCommonDTO<Props> = Props & CommonDTO;
|
|
144
|
+
declare abstract class EntityObject<Props> {
|
|
145
|
+
private _id;
|
|
146
|
+
protected props: PropsWithCommonDTO<Props>;
|
|
147
|
+
get id(): ObjectUniqueId;
|
|
148
|
+
set id(id: ObjectUniqueId);
|
|
149
|
+
protected constructor(props: PropsWithCommonDTO<Props>, id?: ObjectUniqueId);
|
|
150
|
+
equals(entity: EntityObject<Props>): boolean;
|
|
151
|
+
}
|
|
152
|
+
|
|
128
153
|
type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
|
|
129
154
|
|
|
130
155
|
type Replace<T, K extends {
|
|
@@ -289,4 +314,4 @@ declare const logger: {
|
|
|
289
314
|
error: (...args: any[]) => void;
|
|
290
315
|
};
|
|
291
316
|
|
|
292
|
-
export { AggregateRoot, BaseController, CommonDTO, ContextError, Controller, CreateCommonDTO, DependencyContainer, DiscordNotifier, DtoResponsePagination, Entity, ExpressAdapter, FastifyAdapter, ICheckDB, IErrorNotifier, IHealthCheck, IHttp, Inject, MethodType, MiddlewareFunction, NotPagination, NotificationErrorInMemory, NotificationFactory, Optional, Pagination, Replace, Request, RequestHttp, Response, SentryNotifier, UniqueEntityId, ValueObject, WatchedList, ZodSchema, baseEnvSchema, getTakeAndSkip, logger, zodValidator };
|
|
317
|
+
export { AggregateRoot, BaseController, CommonDTO, ContextError, Controller, CreateCommonDTO, DependencyContainer, DiscordNotifier, DtoResponsePagination, Entity, EntityObject, ExpressAdapter, FastifyAdapter, GlobalErrorHandler, ICheckDB, IErrorNotifier, IHealthCheck, IHttp, Inject, MethodType, MiddlewareFunction, NotPagination, NotificationErrorInMemory, NotificationFactory, Optional, Pagination, Replace, Request, RequestHttp, Response, SentryNotifier, UniqueEntityId, ValueObject, WatchedList, ZodSchema, baseEnvSchema, getTakeAndSkip, logger, zodValidator };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,10 +2,6 @@ import { z } from 'zod';
|
|
|
2
2
|
import { Express } from 'express';
|
|
3
3
|
import { FastifyInstance } from 'fastify';
|
|
4
4
|
|
|
5
|
-
interface IErrorNotifier {
|
|
6
|
-
notify(error: Error, context: ContextError): Promise<void>;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
5
|
type AnyObject = Record<string, any>;
|
|
10
6
|
type Request = {
|
|
11
7
|
body: AnyObject;
|
|
@@ -47,6 +43,17 @@ declare abstract class BaseController {
|
|
|
47
43
|
execute(request: Request): Promise<Response>;
|
|
48
44
|
}
|
|
49
45
|
|
|
46
|
+
interface IErrorNotifier {
|
|
47
|
+
notify(error: Error, context: ContextError): Promise<void>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
declare class GlobalErrorHandler {
|
|
51
|
+
readonly env: Record<string, any>;
|
|
52
|
+
protected readonly errorNotifier: IErrorNotifier;
|
|
53
|
+
constructor(env: Record<string, any>);
|
|
54
|
+
register(): void;
|
|
55
|
+
}
|
|
56
|
+
|
|
50
57
|
type ZodSchema = z.ZodObject<{
|
|
51
58
|
headers: z.ZodObject<Record<string, any>>;
|
|
52
59
|
params: z.ZodObject<Record<string, any>>;
|
|
@@ -108,23 +115,41 @@ declare class UniqueEntityId {
|
|
|
108
115
|
equals(id: UniqueEntityId): boolean;
|
|
109
116
|
}
|
|
110
117
|
|
|
111
|
-
type PropsWithCommonDTO<Props> = Props & CommonDTO;
|
|
118
|
+
type PropsWithCommonDTO$1<Props> = Props & CommonDTO;
|
|
112
119
|
declare abstract class Entity<Props> {
|
|
113
120
|
private _id;
|
|
114
|
-
protected props: PropsWithCommonDTO<Props>;
|
|
121
|
+
protected props: PropsWithCommonDTO$1<Props>;
|
|
115
122
|
get id(): UniqueEntityId;
|
|
116
123
|
set id(id: UniqueEntityId);
|
|
117
124
|
get createdAt(): Date;
|
|
118
125
|
set createdAt(date: Date);
|
|
119
126
|
get updatedAt(): Date | undefined | null;
|
|
120
127
|
touch(): void;
|
|
121
|
-
protected constructor(props: PropsWithCommonDTO<Props>, id?: UniqueEntityId);
|
|
128
|
+
protected constructor(props: PropsWithCommonDTO$1<Props>, id?: UniqueEntityId);
|
|
122
129
|
equals(entity: Entity<any>): boolean;
|
|
123
130
|
}
|
|
124
131
|
|
|
125
132
|
declare abstract class AggregateRoot<Props> extends Entity<Props> {
|
|
126
133
|
}
|
|
127
134
|
|
|
135
|
+
declare class ObjectUniqueId {
|
|
136
|
+
private value;
|
|
137
|
+
constructor(value?: string);
|
|
138
|
+
toString(): string;
|
|
139
|
+
toValue(): string;
|
|
140
|
+
equals(id: ObjectUniqueId): boolean;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
type PropsWithCommonDTO<Props> = Props & CommonDTO;
|
|
144
|
+
declare abstract class EntityObject<Props> {
|
|
145
|
+
private _id;
|
|
146
|
+
protected props: PropsWithCommonDTO<Props>;
|
|
147
|
+
get id(): ObjectUniqueId;
|
|
148
|
+
set id(id: ObjectUniqueId);
|
|
149
|
+
protected constructor(props: PropsWithCommonDTO<Props>, id?: ObjectUniqueId);
|
|
150
|
+
equals(entity: EntityObject<Props>): boolean;
|
|
151
|
+
}
|
|
152
|
+
|
|
128
153
|
type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
|
|
129
154
|
|
|
130
155
|
type Replace<T, K extends {
|
|
@@ -289,4 +314,4 @@ declare const logger: {
|
|
|
289
314
|
error: (...args: any[]) => void;
|
|
290
315
|
};
|
|
291
316
|
|
|
292
|
-
export { AggregateRoot, BaseController, CommonDTO, ContextError, Controller, CreateCommonDTO, DependencyContainer, DiscordNotifier, DtoResponsePagination, Entity, ExpressAdapter, FastifyAdapter, ICheckDB, IErrorNotifier, IHealthCheck, IHttp, Inject, MethodType, MiddlewareFunction, NotPagination, NotificationErrorInMemory, NotificationFactory, Optional, Pagination, Replace, Request, RequestHttp, Response, SentryNotifier, UniqueEntityId, ValueObject, WatchedList, ZodSchema, baseEnvSchema, getTakeAndSkip, logger, zodValidator };
|
|
317
|
+
export { AggregateRoot, BaseController, CommonDTO, ContextError, Controller, CreateCommonDTO, DependencyContainer, DiscordNotifier, DtoResponsePagination, Entity, EntityObject, ExpressAdapter, FastifyAdapter, GlobalErrorHandler, ICheckDB, IErrorNotifier, IHealthCheck, IHttp, Inject, MethodType, MiddlewareFunction, NotPagination, NotificationErrorInMemory, NotificationFactory, Optional, Pagination, Replace, Request, RequestHttp, Response, SentryNotifier, UniqueEntityId, ValueObject, WatchedList, ZodSchema, baseEnvSchema, getTakeAndSkip, logger, zodValidator };
|
package/dist/index.mjs
CHANGED
|
@@ -484,6 +484,39 @@ function Inject(token) {
|
|
|
484
484
|
}
|
|
485
485
|
__name(Inject, "Inject");
|
|
486
486
|
|
|
487
|
+
// src/core/configs/global-error-handler.ts
|
|
488
|
+
var GlobalErrorHandler = class {
|
|
489
|
+
static {
|
|
490
|
+
__name(this, "GlobalErrorHandler");
|
|
491
|
+
}
|
|
492
|
+
env;
|
|
493
|
+
errorNotifier;
|
|
494
|
+
constructor(env) {
|
|
495
|
+
this.env = env;
|
|
496
|
+
this.errorNotifier = DependencyContainer.resolveToken("IErrorNotifier");
|
|
497
|
+
}
|
|
498
|
+
register() {
|
|
499
|
+
process.on("uncaughtException", (err) => {
|
|
500
|
+
this.errorNotifier.notify(err, {
|
|
501
|
+
env: this.env.ENVIRONMENT
|
|
502
|
+
});
|
|
503
|
+
process.exit(1);
|
|
504
|
+
});
|
|
505
|
+
process.on("unhandledRejection", (reason) => {
|
|
506
|
+
if (reason instanceof Error) {
|
|
507
|
+
this.errorNotifier.notify(reason, {
|
|
508
|
+
env: this.env.ENVIRONMENT
|
|
509
|
+
});
|
|
510
|
+
} else {
|
|
511
|
+
this.errorNotifier.notify(new Error(String(reason)), {
|
|
512
|
+
env: this.env.ENVIRONMENT
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
process.exit(1);
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
|
|
487
520
|
// src/core/errors/api-common-error.ts
|
|
488
521
|
var ApiErrorEnum = /* @__PURE__ */ function(ApiErrorEnum2) {
|
|
489
522
|
ApiErrorEnum2["DOMAIN"] = "ERR001";
|
|
@@ -776,6 +809,55 @@ var AggregateRoot = class extends Entity {
|
|
|
776
809
|
}
|
|
777
810
|
};
|
|
778
811
|
|
|
812
|
+
// src/core/entities/object-id.ts
|
|
813
|
+
import { ObjectId } from "bson";
|
|
814
|
+
var ObjectUniqueId = class {
|
|
815
|
+
static {
|
|
816
|
+
__name(this, "ObjectUniqueId");
|
|
817
|
+
}
|
|
818
|
+
value;
|
|
819
|
+
constructor(value) {
|
|
820
|
+
this.value = new ObjectId(value);
|
|
821
|
+
}
|
|
822
|
+
toString() {
|
|
823
|
+
return this.value.toString();
|
|
824
|
+
}
|
|
825
|
+
toValue() {
|
|
826
|
+
return this.value.toString();
|
|
827
|
+
}
|
|
828
|
+
equals(id) {
|
|
829
|
+
return id.toValue() === this.toValue();
|
|
830
|
+
}
|
|
831
|
+
};
|
|
832
|
+
|
|
833
|
+
// src/core/entities/entity-object.ts
|
|
834
|
+
var EntityObject = class {
|
|
835
|
+
static {
|
|
836
|
+
__name(this, "EntityObject");
|
|
837
|
+
}
|
|
838
|
+
_id;
|
|
839
|
+
props;
|
|
840
|
+
get id() {
|
|
841
|
+
return this._id;
|
|
842
|
+
}
|
|
843
|
+
set id(id) {
|
|
844
|
+
this._id = id;
|
|
845
|
+
}
|
|
846
|
+
constructor(props, id) {
|
|
847
|
+
this._id = id ?? new ObjectUniqueId(id);
|
|
848
|
+
this.props = props;
|
|
849
|
+
}
|
|
850
|
+
equals(entity) {
|
|
851
|
+
if (entity === this) {
|
|
852
|
+
return true;
|
|
853
|
+
}
|
|
854
|
+
if (entity.id === this._id) {
|
|
855
|
+
return true;
|
|
856
|
+
}
|
|
857
|
+
return false;
|
|
858
|
+
}
|
|
859
|
+
};
|
|
860
|
+
|
|
779
861
|
// src/core/entities/value-object.ts
|
|
780
862
|
var ValueObject = class {
|
|
781
863
|
static {
|
|
@@ -1388,8 +1470,10 @@ export {
|
|
|
1388
1470
|
DependencyContainer,
|
|
1389
1471
|
DiscordNotifier,
|
|
1390
1472
|
Entity,
|
|
1473
|
+
EntityObject,
|
|
1391
1474
|
ExpressAdapter,
|
|
1392
1475
|
FastifyAdapter,
|
|
1476
|
+
GlobalErrorHandler,
|
|
1393
1477
|
Inject,
|
|
1394
1478
|
NotificationErrorInMemory,
|
|
1395
1479
|
NotificationFactory,
|