@jmlq/logger 0.1.0-alpha.2 → 0.1.0-alpha.20
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/README.md +247 -0
- package/architecture.md +171 -0
- package/dist/application/factory/index.d.ts +1 -0
- package/dist/{config → application/factory}/index.js +1 -2
- package/dist/application/factory/logger.factory.d.ts +10 -0
- package/dist/application/factory/logger.factory.js +71 -0
- package/dist/application/index.d.ts +2 -0
- package/dist/{presentation → application}/index.js +1 -0
- package/dist/application/use-cases/flush-buffers.use-case.d.ts +6 -0
- package/dist/application/use-cases/flush-buffers.use-case.js +13 -0
- package/dist/application/use-cases/get-logs.use-case.d.ts +8 -0
- package/dist/application/use-cases/get-logs.use-case.js +24 -0
- package/dist/application/use-cases/index.d.ts +3 -0
- package/dist/application/use-cases/index.js +19 -0
- package/dist/application/use-cases/save-log/index.d.ts +1 -0
- package/dist/application/use-cases/save-log/index.js +17 -0
- package/dist/application/use-cases/save-log/save-log.props.d.ts +7 -0
- package/dist/{config/interfaces/index.js → application/use-cases/save-log/save-log.props.js} +0 -1
- package/dist/application/use-cases/save-log.use-case.d.ts +8 -0
- package/dist/application/use-cases/save-log.use-case.js +27 -0
- package/dist/domain/index.d.ts +7 -0
- package/dist/domain/index.js +7 -0
- package/dist/domain/model/index.d.ts +3 -0
- package/dist/domain/model/index.js +19 -0
- package/dist/domain/model/log-entry.model.d.ts +8 -0
- package/dist/domain/model/log-entry.model.js +2 -0
- package/dist/domain/model/pii-options.model.d.ts +8 -0
- package/dist/domain/model/pii-options.model.js +2 -0
- package/dist/domain/model/pii-replacement-rule.d.ts +5 -0
- package/dist/domain/model/pii-replacement-rule.js +2 -0
- package/dist/domain/ports/create-logger-options.port.d.ts +7 -0
- package/dist/domain/ports/create-logger-options.port.js +2 -0
- package/dist/domain/ports/index.d.ts +5 -0
- package/dist/domain/ports/index.js +22 -0
- package/dist/domain/ports/log-datasource.port.d.ts +10 -0
- package/dist/domain/ports/log-datasource.port.js +2 -0
- package/dist/domain/ports/logger-factory-config.port.d.ts +28 -0
- package/dist/domain/ports/logger-factory-config.port.js +2 -0
- package/dist/domain/ports/logger.port.d.ts +15 -0
- package/dist/domain/ports/logger.port.js +2 -0
- package/dist/domain/ports/pii-redactor.port.d.ts +5 -0
- package/dist/domain/ports/pii-redactor.port.js +2 -0
- package/dist/domain/request/index.d.ts +1 -0
- package/dist/domain/request/index.js +17 -0
- package/dist/domain/request/log-filter.request.d.ts +9 -0
- package/dist/domain/request/log-filter.request.js +2 -0
- package/dist/domain/response/index.d.ts +1 -0
- package/dist/domain/response/index.js +17 -0
- package/dist/domain/response/log.response.d.ts +8 -0
- package/dist/domain/response/log.response.js +2 -0
- package/dist/domain/services/index.d.ts +1 -1
- package/dist/domain/services/index.js +1 -1
- package/dist/domain/services/pii-redactor.service.d.ts +10 -0
- package/dist/domain/services/pii-redactor.service.js +68 -0
- package/dist/domain/types/index.d.ts +1 -0
- package/dist/domain/types/index.js +17 -0
- package/dist/domain/types/log-message.type.d.ts +1 -0
- package/dist/domain/types/log-message.type.js +2 -0
- package/dist/domain/utils/index.d.ts +3 -0
- package/dist/domain/utils/index.js +19 -0
- package/dist/domain/utils/normalize-message.util.d.ts +3 -0
- package/dist/domain/utils/normalize-message.util.js +8 -0
- package/dist/domain/utils/parse-log-level.util.d.ts +2 -0
- package/dist/domain/utils/parse-log-level.util.js +27 -0
- package/dist/domain/utils/pii-regex.util.d.ts +2 -0
- package/dist/domain/utils/pii-regex.util.js +13 -0
- package/dist/domain/value-objects/index.d.ts +1 -0
- package/dist/domain/value-objects/index.js +17 -0
- package/dist/domain/value-objects/log-level.vo.d.ts +8 -0
- package/dist/domain/value-objects/log-level.vo.js +13 -0
- package/dist/index.d.ts +8 -4
- package/dist/index.js +32 -7
- package/dist/infrastructure/index.d.ts +1 -0
- package/dist/infrastructure/index.js +17 -0
- package/dist/infrastructure/services/datasource.service.d.ts +18 -0
- package/dist/infrastructure/services/datasource.service.js +102 -0
- package/dist/infrastructure/services/index.d.ts +1 -0
- package/dist/infrastructure/services/index.js +17 -0
- package/dist/infrastructure/types/index.d.ts +1 -0
- package/dist/infrastructure/types/index.js +17 -0
- package/dist/infrastructure/types/on-data-source-error.type.d.ts +5 -0
- package/dist/infrastructure/types/on-data-source-error.type.js +2 -0
- package/install.md +632 -0
- package/package.json +37 -11
- package/dist/Composite/index.d.ts +0 -9
- package/dist/Composite/index.js +0 -54
- package/dist/Factory/index.d.ts +0 -5
- package/dist/Factory/index.js +0 -23
- package/dist/config/index.d.ts +0 -2
- package/dist/config/interfaces/index.d.ts +0 -67
- package/dist/config/types/index.d.ts +0 -10
- package/dist/config/types/index.js +0 -13
- package/dist/domain/services/pii-redactor.d.ts +0 -27
- package/dist/domain/services/pii-redactor.js +0 -139
- package/dist/interfaces/index.d.ts +0 -35
- package/dist/interfaces/index.js +0 -13
- package/dist/presentation/factory/index.d.ts +0 -2
- package/dist/presentation/factory/index.js +0 -74
- package/dist/presentation/index.d.ts +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./services";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./services"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { OnDataSourceError } from "../types";
|
|
2
|
+
import { ILogDatasource } from "../../domain/ports";
|
|
3
|
+
import { LogFilterRequest } from "../../domain/request";
|
|
4
|
+
import { ILogResponse } from "../../domain/response";
|
|
5
|
+
import { LogEntry } from "../../domain/model";
|
|
6
|
+
export declare class DataSourceService implements ILogDatasource {
|
|
7
|
+
private readonly targets;
|
|
8
|
+
private readonly onError?;
|
|
9
|
+
readonly name = "composite";
|
|
10
|
+
private logs;
|
|
11
|
+
private nextId;
|
|
12
|
+
constructor(targets: ILogDatasource[], onError?: OnDataSourceError | undefined);
|
|
13
|
+
private handleError;
|
|
14
|
+
save(log: LogEntry): Promise<void>;
|
|
15
|
+
find(filter?: LogFilterRequest): Promise<ILogResponse[]>;
|
|
16
|
+
flush(): Promise<void>;
|
|
17
|
+
dispose(): Promise<void>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DataSourceService = void 0;
|
|
4
|
+
class DataSourceService {
|
|
5
|
+
constructor(targets, onError) {
|
|
6
|
+
this.targets = targets;
|
|
7
|
+
this.onError = onError;
|
|
8
|
+
this.name = "composite";
|
|
9
|
+
this.logs = [];
|
|
10
|
+
this.nextId = 1;
|
|
11
|
+
this.targets = (targets ?? []).filter(Boolean);
|
|
12
|
+
}
|
|
13
|
+
handleError(op, i, reason) {
|
|
14
|
+
const datasourceName = this.targets[i]?.name ?? "unknown";
|
|
15
|
+
if (this.onError) {
|
|
16
|
+
this.onError({
|
|
17
|
+
operation: op,
|
|
18
|
+
datasourceName,
|
|
19
|
+
reason,
|
|
20
|
+
});
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
// fallback por simplicidad
|
|
24
|
+
console.warn(`[DataSourceService] ${op} error in ds#${i} (${datasourceName})`, reason);
|
|
25
|
+
}
|
|
26
|
+
async save(log) {
|
|
27
|
+
// 1) Fan-out a todos los datasources
|
|
28
|
+
const results = await Promise.allSettled(this.targets.map((ds) => ds.save(log)));
|
|
29
|
+
results.forEach((r, i) => {
|
|
30
|
+
if (r.status === "rejected") {
|
|
31
|
+
this.handleError("save", i, r.reason);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
// 2) Indexar en memoria para soportar find() con filtros/paginación
|
|
35
|
+
this.logs.push({
|
|
36
|
+
...log,
|
|
37
|
+
id: this.nextId++,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
async find(filter) {
|
|
41
|
+
// Si hay logs indexados en memoria, usamos ese índice
|
|
42
|
+
if (this.logs.length > 0) {
|
|
43
|
+
let result = [...this.logs];
|
|
44
|
+
// Orden ASC por timestamp
|
|
45
|
+
result.sort((a, b) => a.timestamp - b.timestamp);
|
|
46
|
+
if (filter) {
|
|
47
|
+
const { levelMin, since, until, query, offset = 0, limit } = filter;
|
|
48
|
+
if (levelMin !== undefined) {
|
|
49
|
+
result = result.filter((l) => l.level >= levelMin);
|
|
50
|
+
}
|
|
51
|
+
if (since !== undefined) {
|
|
52
|
+
result = result.filter((l) => l.timestamp >= since);
|
|
53
|
+
}
|
|
54
|
+
if (until !== undefined) {
|
|
55
|
+
result = result.filter((l) => l.timestamp <= until);
|
|
56
|
+
}
|
|
57
|
+
if (query) {
|
|
58
|
+
const q = query.toLowerCase();
|
|
59
|
+
result = result.filter((l) => {
|
|
60
|
+
const msg = typeof l.message === "string" ? l.message.toLowerCase() : "";
|
|
61
|
+
return msg.includes(q);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
const start = offset;
|
|
65
|
+
const end = limit != null ? start + limit : undefined;
|
|
66
|
+
result = result.slice(start, end);
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
// Si NO hay logs en memoria, delegamos en los datasources
|
|
71
|
+
const results = await Promise.allSettled(this.targets.map((ds) => ds.find?.(filter)));
|
|
72
|
+
const logs = [];
|
|
73
|
+
results.forEach((r, i) => {
|
|
74
|
+
if (r.status === "fulfilled" && Array.isArray(r.value)) {
|
|
75
|
+
logs.push(...r.value);
|
|
76
|
+
}
|
|
77
|
+
else if (r.status === "rejected") {
|
|
78
|
+
this.handleError("find", i, r.reason);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
// Orden ASC también aquí, para cumplir el test
|
|
82
|
+
logs.sort((a, b) => a.timestamp - b.timestamp);
|
|
83
|
+
return logs;
|
|
84
|
+
}
|
|
85
|
+
async flush() {
|
|
86
|
+
const results = await Promise.allSettled(this.targets.map((ds) => ds.flush?.()));
|
|
87
|
+
results.forEach((r, i) => {
|
|
88
|
+
if (r.status === "rejected") {
|
|
89
|
+
this.handleError("flush", i, r.reason);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
async dispose() {
|
|
94
|
+
const results = await Promise.allSettled(this.targets.map((ds) => ds.dispose?.()));
|
|
95
|
+
results.forEach((r, i) => {
|
|
96
|
+
if (r.status === "rejected") {
|
|
97
|
+
this.handleError("dispose", i, r.reason);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.DataSourceService = DataSourceService;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./datasource.service";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./datasource.service"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./on-data-source-error.type";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./on-data-source-error.type"), exports);
|