plutin 1.5.3 → 1.6.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 +108 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +39 -6
- package/dist/index.d.ts +39 -6
- package/dist/index.mjs +105 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +13 -1
- package/readme.md +6 -0
package/dist/index.d.ts
CHANGED
|
@@ -107,25 +107,25 @@ type CreateCommonDTO = {
|
|
|
107
107
|
updatedAt?: Date | null;
|
|
108
108
|
};
|
|
109
109
|
|
|
110
|
-
declare class
|
|
110
|
+
declare class UniqueObjectId {
|
|
111
111
|
private value;
|
|
112
112
|
constructor(value?: string);
|
|
113
113
|
toString(): string;
|
|
114
114
|
toValue(): string;
|
|
115
|
-
equals(id:
|
|
115
|
+
equals(id: UniqueObjectId): boolean;
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
type PropsWithCommonDTO$1<Props> = Props & CommonDTO;
|
|
119
119
|
declare abstract class EntityObject<Props> {
|
|
120
120
|
private _id;
|
|
121
121
|
protected props: PropsWithCommonDTO$1<Props>;
|
|
122
|
-
get id():
|
|
123
|
-
set id(id:
|
|
122
|
+
get id(): UniqueObjectId;
|
|
123
|
+
set id(id: UniqueObjectId);
|
|
124
124
|
get createdAt(): Date;
|
|
125
125
|
set createdAt(date: Date);
|
|
126
126
|
get updatedAt(): Date | undefined | null;
|
|
127
127
|
touch(): void;
|
|
128
|
-
protected constructor(props: PropsWithCommonDTO$1<Props>, id?:
|
|
128
|
+
protected constructor(props: PropsWithCommonDTO$1<Props>, id?: UniqueObjectId);
|
|
129
129
|
equals(entity: EntityObject<Props>): boolean;
|
|
130
130
|
}
|
|
131
131
|
|
|
@@ -269,13 +269,27 @@ declare const baseEnvSchema: z.ZodObject<{
|
|
|
269
269
|
SHOULD_NOTIFY_ERROR: z.ZodDefault<z.ZodBoolean>;
|
|
270
270
|
SENTRY_DSN: z.ZodOptional<z.ZodString>;
|
|
271
271
|
DISCORD_WEBHOOK_URL: z.ZodOptional<z.ZodString>;
|
|
272
|
+
LOG_LEVEL: z.ZodDefault<z.ZodEnum<["info", "error", "debug", "fatal", "warn"]>>;
|
|
273
|
+
OTEL_ENABLE: z.ZodDefault<z.ZodBoolean>;
|
|
274
|
+
OTEL_SERVICE_NAME: z.ZodOptional<z.ZodString>;
|
|
275
|
+
OTEL_SERVICE_VERSION: z.ZodOptional<z.ZodString>;
|
|
276
|
+
OTEL_OTLP_TRACES_EXPORTER_URL: z.ZodOptional<z.ZodString>;
|
|
277
|
+
OTEL_OTLP_LOGS_EXPORTER_URL: z.ZodOptional<z.ZodString>;
|
|
278
|
+
OTEL_OTLP_METRICS_EXPORTER_URL: z.ZodOptional<z.ZodString>;
|
|
272
279
|
}, "strip", z.ZodTypeAny, {
|
|
273
280
|
ENVIRONMENT: "test" | "development" | "production" | "staging";
|
|
274
281
|
SHOULD_NOTIFY_ERROR: boolean;
|
|
275
282
|
NODE_ENV: "test" | "development" | "production";
|
|
276
283
|
PORT: number;
|
|
284
|
+
LOG_LEVEL: "error" | "fatal" | "warn" | "info" | "debug";
|
|
285
|
+
OTEL_ENABLE: boolean;
|
|
277
286
|
SENTRY_DSN?: string | undefined;
|
|
278
287
|
DISCORD_WEBHOOK_URL?: string | undefined;
|
|
288
|
+
OTEL_SERVICE_NAME?: string | undefined;
|
|
289
|
+
OTEL_SERVICE_VERSION?: string | undefined;
|
|
290
|
+
OTEL_OTLP_TRACES_EXPORTER_URL?: string | undefined;
|
|
291
|
+
OTEL_OTLP_LOGS_EXPORTER_URL?: string | undefined;
|
|
292
|
+
OTEL_OTLP_METRICS_EXPORTER_URL?: string | undefined;
|
|
279
293
|
}, {
|
|
280
294
|
ENVIRONMENT?: "test" | "development" | "production" | "staging" | undefined;
|
|
281
295
|
SHOULD_NOTIFY_ERROR?: boolean | undefined;
|
|
@@ -283,6 +297,13 @@ declare const baseEnvSchema: z.ZodObject<{
|
|
|
283
297
|
PORT?: number | undefined;
|
|
284
298
|
SENTRY_DSN?: string | undefined;
|
|
285
299
|
DISCORD_WEBHOOK_URL?: string | undefined;
|
|
300
|
+
LOG_LEVEL?: "error" | "fatal" | "warn" | "info" | "debug" | undefined;
|
|
301
|
+
OTEL_ENABLE?: boolean | undefined;
|
|
302
|
+
OTEL_SERVICE_NAME?: string | undefined;
|
|
303
|
+
OTEL_SERVICE_VERSION?: string | undefined;
|
|
304
|
+
OTEL_OTLP_TRACES_EXPORTER_URL?: string | undefined;
|
|
305
|
+
OTEL_OTLP_LOGS_EXPORTER_URL?: string | undefined;
|
|
306
|
+
OTEL_OTLP_METRICS_EXPORTER_URL?: string | undefined;
|
|
286
307
|
}>;
|
|
287
308
|
|
|
288
309
|
type OptionsNotifications = 'console' | 'discord' | 'sentry';
|
|
@@ -308,6 +329,18 @@ declare class SentryNotifier implements IErrorNotifier {
|
|
|
308
329
|
notify(error: Error, context: ContextError): Promise<void>;
|
|
309
330
|
}
|
|
310
331
|
|
|
332
|
+
declare function Span(): MethodDecorator;
|
|
333
|
+
|
|
334
|
+
interface ITracerGateway {
|
|
335
|
+
addEvent(name: string, attributes?: Record<string, any>): void;
|
|
336
|
+
setAttribute(key: string, value: string | number | boolean): void;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
declare class TracerGatewayOpentelemetry implements ITracerGateway {
|
|
340
|
+
addEvent(name: string, attributes?: Record<string, any>): void;
|
|
341
|
+
setAttribute(key: string, value: string | number | boolean): void;
|
|
342
|
+
}
|
|
343
|
+
|
|
311
344
|
declare const logger: {
|
|
312
345
|
info: (...args: any[]) => void;
|
|
313
346
|
log: (...args: any[]) => void;
|
|
@@ -315,4 +348,4 @@ declare const logger: {
|
|
|
315
348
|
error: (...args: any[]) => void;
|
|
316
349
|
};
|
|
317
350
|
|
|
318
|
-
export { AggregateObjectRoot, AggregateRoot, BaseController, CommonDTO, ContextError, Controller, CreateCommonDTO, DependencyContainer, DiscordNotifier, DtoResponsePagination, Entity, EntityObject, ExpressAdapter, FastifyAdapter, GlobalErrorHandler, IErrorNotifier, IHealthCheckDB, IHttp, Inject, MethodType, MiddlewareFunction, NotPagination, NotificationErrorInMemory, NotificationFactory, Optional, Pagination, Replace, Request, RequestHttp, Response, SentryNotifier, UniqueEntityId,
|
|
351
|
+
export { AggregateObjectRoot, AggregateRoot, BaseController, CommonDTO, ContextError, Controller, CreateCommonDTO, DependencyContainer, DiscordNotifier, DtoResponsePagination, Entity, EntityObject, ExpressAdapter, FastifyAdapter, GlobalErrorHandler, IErrorNotifier, IHealthCheckDB, IHttp, ITracerGateway, Inject, MethodType, MiddlewareFunction, NotPagination, NotificationErrorInMemory, NotificationFactory, Optional, Pagination, Replace, Request, RequestHttp, Response, SentryNotifier, Span, TracerGatewayOpentelemetry, UniqueEntityId, UniqueObjectId, ValueObject, WatchedList, ZodSchema, baseEnvSchema, getTakeAndSkip, logger, zodValidator };
|
package/dist/index.mjs
CHANGED
|
@@ -743,9 +743,9 @@ __name(Controller, "Controller");
|
|
|
743
743
|
|
|
744
744
|
// src/core/entities/unique-object-id.ts
|
|
745
745
|
import { ObjectId } from "bson";
|
|
746
|
-
var
|
|
746
|
+
var UniqueObjectId = class {
|
|
747
747
|
static {
|
|
748
|
-
__name(this, "
|
|
748
|
+
__name(this, "UniqueObjectId");
|
|
749
749
|
}
|
|
750
750
|
value;
|
|
751
751
|
constructor(value) {
|
|
@@ -788,7 +788,7 @@ var EntityObject = class {
|
|
|
788
788
|
this.props.updatedAt = /* @__PURE__ */ new Date();
|
|
789
789
|
}
|
|
790
790
|
constructor(props, id) {
|
|
791
|
-
this._id = id ?? new
|
|
791
|
+
this._id = id ?? new UniqueObjectId(id);
|
|
792
792
|
this.props = props;
|
|
793
793
|
}
|
|
794
794
|
equals(entity) {
|
|
@@ -1456,6 +1456,91 @@ function zodValidator(schema) {
|
|
|
1456
1456
|
}
|
|
1457
1457
|
__name(zodValidator, "zodValidator");
|
|
1458
1458
|
|
|
1459
|
+
// src/infra/adapters/observability/otel/span-decorator.ts
|
|
1460
|
+
import opentelemetry, { SpanStatusCode } from "@opentelemetry/api";
|
|
1461
|
+
import "reflect-metadata";
|
|
1462
|
+
function Span() {
|
|
1463
|
+
return function(target, propertyKey, descriptor) {
|
|
1464
|
+
if (!process.env.OTEL_ENABLE) {
|
|
1465
|
+
return descriptor;
|
|
1466
|
+
}
|
|
1467
|
+
const originalMethod = descriptor.value;
|
|
1468
|
+
descriptor.value = function(...args) {
|
|
1469
|
+
const tracer = opentelemetry.trace.getTracer(process.env.OTEL_SERVICE_NAME, process.env.OTEL_SERVICE_VERSION);
|
|
1470
|
+
const className = target.constructor?.name || "UnknownClass";
|
|
1471
|
+
const methodName = String(propertyKey);
|
|
1472
|
+
const spanName = `${className}.${methodName}`;
|
|
1473
|
+
return tracer.startActiveSpan(spanName, async (span) => {
|
|
1474
|
+
try {
|
|
1475
|
+
const result = originalMethod.apply(this, args);
|
|
1476
|
+
if (result instanceof Promise) {
|
|
1477
|
+
try {
|
|
1478
|
+
const awaitedResult = await result;
|
|
1479
|
+
span.addEvent(`Method [${methodName}] executed successfully`);
|
|
1480
|
+
span.end();
|
|
1481
|
+
return awaitedResult;
|
|
1482
|
+
} catch (error) {
|
|
1483
|
+
handleSpanError(span, error);
|
|
1484
|
+
throw error;
|
|
1485
|
+
}
|
|
1486
|
+
} else {
|
|
1487
|
+
span.addEvent(`Method [${methodName}] executed successfully`);
|
|
1488
|
+
span.end();
|
|
1489
|
+
return result;
|
|
1490
|
+
}
|
|
1491
|
+
} catch (error) {
|
|
1492
|
+
handleSpanError(span, error);
|
|
1493
|
+
throw error;
|
|
1494
|
+
}
|
|
1495
|
+
});
|
|
1496
|
+
};
|
|
1497
|
+
return descriptor;
|
|
1498
|
+
};
|
|
1499
|
+
}
|
|
1500
|
+
__name(Span, "Span");
|
|
1501
|
+
function handleSpanError(span, error) {
|
|
1502
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1503
|
+
if (error instanceof Error) {
|
|
1504
|
+
span.recordException(error);
|
|
1505
|
+
} else {
|
|
1506
|
+
span.recordException(new Error(String(error)));
|
|
1507
|
+
}
|
|
1508
|
+
span.setStatus({
|
|
1509
|
+
code: SpanStatusCode.ERROR,
|
|
1510
|
+
message: errorMessage
|
|
1511
|
+
});
|
|
1512
|
+
span.end();
|
|
1513
|
+
}
|
|
1514
|
+
__name(handleSpanError, "handleSpanError");
|
|
1515
|
+
|
|
1516
|
+
// src/infra/adapters/observability/otel/tracer-gateway-opentelemetry.ts
|
|
1517
|
+
import opentelemetry2 from "@opentelemetry/api";
|
|
1518
|
+
var TracerGatewayOpentelemetry = class {
|
|
1519
|
+
static {
|
|
1520
|
+
__name(this, "TracerGatewayOpentelemetry");
|
|
1521
|
+
}
|
|
1522
|
+
addEvent(name, attributes) {
|
|
1523
|
+
if (!process.env.OTEL_ENABLE) {
|
|
1524
|
+
return;
|
|
1525
|
+
}
|
|
1526
|
+
const span = opentelemetry2.trace.getActiveSpan();
|
|
1527
|
+
if (span && attributes) {
|
|
1528
|
+
span.addEvent(name, attributes);
|
|
1529
|
+
} else if (span) {
|
|
1530
|
+
span.addEvent(name);
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
setAttribute(key, value) {
|
|
1534
|
+
if (!process.env.OTEL_ENABLE) {
|
|
1535
|
+
return;
|
|
1536
|
+
}
|
|
1537
|
+
const span = opentelemetry2.trace.getActiveSpan();
|
|
1538
|
+
if (span) {
|
|
1539
|
+
span.setAttribute(key, value);
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
};
|
|
1543
|
+
|
|
1459
1544
|
// src/infra/env/index.ts
|
|
1460
1545
|
import { z } from "zod";
|
|
1461
1546
|
|
|
@@ -1480,7 +1565,20 @@ var baseEnvSchema = z.object({
|
|
|
1480
1565
|
PORT: z.coerce.number().default(3333),
|
|
1481
1566
|
SHOULD_NOTIFY_ERROR: z.coerce.boolean().default(true),
|
|
1482
1567
|
SENTRY_DSN: z.string().optional(),
|
|
1483
|
-
DISCORD_WEBHOOK_URL: z.string().optional()
|
|
1568
|
+
DISCORD_WEBHOOK_URL: z.string().optional(),
|
|
1569
|
+
LOG_LEVEL: z.enum([
|
|
1570
|
+
"info",
|
|
1571
|
+
"error",
|
|
1572
|
+
"debug",
|
|
1573
|
+
"fatal",
|
|
1574
|
+
"warn"
|
|
1575
|
+
]).default("info"),
|
|
1576
|
+
OTEL_ENABLE: z.coerce.boolean().default(false),
|
|
1577
|
+
OTEL_SERVICE_NAME: z.string().optional(),
|
|
1578
|
+
OTEL_SERVICE_VERSION: z.string().optional(),
|
|
1579
|
+
OTEL_OTLP_TRACES_EXPORTER_URL: z.string().url().optional(),
|
|
1580
|
+
OTEL_OTLP_LOGS_EXPORTER_URL: z.string().url().optional(),
|
|
1581
|
+
OTEL_OTLP_METRICS_EXPORTER_URL: z.string().url().optional()
|
|
1484
1582
|
});
|
|
1485
1583
|
export {
|
|
1486
1584
|
AggregateObjectRoot,
|
|
@@ -1498,8 +1596,10 @@ export {
|
|
|
1498
1596
|
NotificationErrorInMemory,
|
|
1499
1597
|
NotificationFactory,
|
|
1500
1598
|
SentryNotifier,
|
|
1599
|
+
Span,
|
|
1600
|
+
TracerGatewayOpentelemetry,
|
|
1501
1601
|
UniqueEntityId,
|
|
1502
|
-
|
|
1602
|
+
UniqueObjectId,
|
|
1503
1603
|
ValueObject,
|
|
1504
1604
|
WatchedList,
|
|
1505
1605
|
baseEnvSchema,
|