@jmlq/logger 0.1.0-alpha.2 → 0.1.0-alpha.21

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 (102) hide show
  1. package/README.md +639 -0
  2. package/architecture.md +193 -0
  3. package/assets/mongo-log.png +0 -0
  4. package/assets/pg-log.png +0 -0
  5. package/dist/application/factory/index.d.ts +1 -0
  6. package/dist/{config → application/factory}/index.js +1 -2
  7. package/dist/application/factory/logger.factory.d.ts +11 -0
  8. package/dist/application/factory/logger.factory.js +71 -0
  9. package/dist/application/index.d.ts +2 -0
  10. package/dist/{presentation → application}/index.js +1 -0
  11. package/dist/application/types/index.d.ts +1 -0
  12. package/dist/application/types/index.js +17 -0
  13. package/dist/application/types/logger-factory-config.type.d.ts +28 -0
  14. package/dist/{config/interfaces/index.js → application/types/logger-factory-config.type.js} +0 -1
  15. package/dist/application/use-cases/flush-buffers.use-case.d.ts +6 -0
  16. package/dist/application/use-cases/flush-buffers.use-case.js +13 -0
  17. package/dist/application/use-cases/get-logs.use-case.d.ts +8 -0
  18. package/dist/application/use-cases/get-logs.use-case.js +24 -0
  19. package/dist/application/use-cases/index.d.ts +3 -0
  20. package/dist/application/use-cases/index.js +19 -0
  21. package/dist/application/use-cases/save-log/index.d.ts +1 -0
  22. package/dist/application/use-cases/save-log/index.js +17 -0
  23. package/dist/application/use-cases/save-log/save-log.props.d.ts +7 -0
  24. package/dist/application/use-cases/save-log/save-log.props.js +2 -0
  25. package/dist/application/use-cases/save-log.use-case.d.ts +8 -0
  26. package/dist/application/use-cases/save-log.use-case.js +27 -0
  27. package/dist/domain/index.d.ts +7 -0
  28. package/dist/domain/index.js +7 -0
  29. package/dist/domain/model/index.d.ts +3 -0
  30. package/dist/domain/model/index.js +19 -0
  31. package/dist/domain/model/log-entry.model.d.ts +8 -0
  32. package/dist/domain/model/log-entry.model.js +2 -0
  33. package/dist/domain/model/pii-options.model.d.ts +8 -0
  34. package/dist/domain/model/pii-options.model.js +2 -0
  35. package/dist/domain/model/pii-replacement-rule.d.ts +5 -0
  36. package/dist/domain/model/pii-replacement-rule.js +2 -0
  37. package/dist/domain/ports/create-logger-options.port.d.ts +7 -0
  38. package/dist/domain/ports/create-logger-options.port.js +2 -0
  39. package/dist/domain/ports/index.d.ts +4 -0
  40. package/dist/domain/ports/index.js +20 -0
  41. package/dist/domain/ports/log-datasource.port.d.ts +10 -0
  42. package/dist/domain/ports/log-datasource.port.js +2 -0
  43. package/dist/domain/ports/logger.port.d.ts +15 -0
  44. package/dist/domain/ports/logger.port.js +2 -0
  45. package/dist/domain/ports/pii-redactor.port.d.ts +5 -0
  46. package/dist/domain/ports/pii-redactor.port.js +2 -0
  47. package/dist/domain/request/index.d.ts +1 -0
  48. package/dist/domain/request/index.js +17 -0
  49. package/dist/domain/request/log-filter.request.d.ts +9 -0
  50. package/dist/domain/request/log-filter.request.js +2 -0
  51. package/dist/domain/response/index.d.ts +1 -0
  52. package/dist/domain/response/index.js +17 -0
  53. package/dist/domain/response/log.response.d.ts +8 -0
  54. package/dist/domain/response/log.response.js +2 -0
  55. package/dist/domain/services/index.d.ts +1 -1
  56. package/dist/domain/services/index.js +1 -1
  57. package/dist/domain/services/pii-redactor.service.d.ts +10 -0
  58. package/dist/domain/services/pii-redactor.service.js +68 -0
  59. package/dist/domain/types/index.d.ts +1 -0
  60. package/dist/domain/types/index.js +17 -0
  61. package/dist/domain/types/log-message.type.d.ts +1 -0
  62. package/dist/domain/types/log-message.type.js +2 -0
  63. package/dist/domain/utils/index.d.ts +3 -0
  64. package/dist/domain/utils/index.js +19 -0
  65. package/dist/domain/utils/normalize-message.util.d.ts +3 -0
  66. package/dist/domain/utils/normalize-message.util.js +8 -0
  67. package/dist/domain/utils/parse-log-level.util.d.ts +2 -0
  68. package/dist/domain/utils/parse-log-level.util.js +27 -0
  69. package/dist/domain/utils/pii-regex.util.d.ts +2 -0
  70. package/dist/domain/utils/pii-regex.util.js +13 -0
  71. package/dist/domain/value-objects/index.d.ts +1 -0
  72. package/dist/domain/value-objects/index.js +17 -0
  73. package/dist/domain/value-objects/log-level.vo.d.ts +8 -0
  74. package/dist/domain/value-objects/log-level.vo.js +13 -0
  75. package/dist/index.d.ts +9 -4
  76. package/dist/index.js +32 -7
  77. package/dist/infrastructure/index.d.ts +1 -0
  78. package/dist/infrastructure/index.js +17 -0
  79. package/dist/infrastructure/services/datasource.service.d.ts +18 -0
  80. package/dist/infrastructure/services/datasource.service.js +102 -0
  81. package/dist/infrastructure/services/index.d.ts +1 -0
  82. package/dist/infrastructure/services/index.js +17 -0
  83. package/dist/infrastructure/types/index.d.ts +1 -0
  84. package/dist/infrastructure/types/index.js +17 -0
  85. package/dist/infrastructure/types/on-data-source-error.type.d.ts +5 -0
  86. package/dist/infrastructure/types/on-data-source-error.type.js +2 -0
  87. package/package.json +37 -11
  88. package/dist/Composite/index.d.ts +0 -9
  89. package/dist/Composite/index.js +0 -54
  90. package/dist/Factory/index.d.ts +0 -5
  91. package/dist/Factory/index.js +0 -23
  92. package/dist/config/index.d.ts +0 -2
  93. package/dist/config/interfaces/index.d.ts +0 -67
  94. package/dist/config/types/index.d.ts +0 -10
  95. package/dist/config/types/index.js +0 -13
  96. package/dist/domain/services/pii-redactor.d.ts +0 -27
  97. package/dist/domain/services/pii-redactor.js +0 -139
  98. package/dist/interfaces/index.d.ts +0 -35
  99. package/dist/interfaces/index.js +0 -13
  100. package/dist/presentation/factory/index.d.ts +0 -2
  101. package/dist/presentation/factory/index.js +0 -74
  102. package/dist/presentation/index.d.ts +0 -1
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,15 @@
1
+ import { LogFilterRequest } from "../request";
2
+ import { ILogResponse } from "../response";
3
+ import { LogMessage } from "../types";
4
+ import { LogLevel } from "../value-objects";
5
+ export interface ILogger {
6
+ log(level: LogLevel, message: LogMessage, meta?: unknown): Promise<void>;
7
+ trace(message: LogMessage, meta?: unknown): Promise<void>;
8
+ debug(message: LogMessage, meta?: unknown): Promise<void>;
9
+ info(message: LogMessage, meta?: unknown): Promise<void>;
10
+ warn(message: LogMessage, meta?: unknown): Promise<void>;
11
+ error(message: LogMessage, meta?: unknown): Promise<void>;
12
+ fatal(message: LogMessage, meta?: unknown): Promise<void>;
13
+ getLogs(filter?: LogFilterRequest): Promise<ILogResponse[]>;
14
+ flush(): Promise<void>;
15
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ import { PiiOptions } from "../model";
2
+ export interface IPiiRedactor {
3
+ redact<T = unknown>(value: T): T;
4
+ updateOptions?(opts: PiiOptions): void;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export * from "./log-filter.request";
@@ -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("./log-filter.request"), exports);
@@ -0,0 +1,9 @@
1
+ import { LogLevel } from "../value-objects";
2
+ export interface LogFilterRequest {
3
+ levelMin?: LogLevel;
4
+ since?: number;
5
+ until?: number;
6
+ limit?: number;
7
+ offset?: number;
8
+ query?: string;
9
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export * from "./log.response";
@@ -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("./log.response"), exports);
@@ -0,0 +1,8 @@
1
+ import { LogLevel } from "../value-objects";
2
+ export interface ILogResponse {
3
+ source: string;
4
+ level: LogLevel;
5
+ message: string | Record<string, unknown>;
6
+ meta?: unknown;
7
+ timestamp: number;
8
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1 @@
1
- export * from "./pii-redactor";
1
+ export * from "./pii-redactor.service";
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./pii-redactor"), exports);
17
+ __exportStar(require("./pii-redactor.service"), exports);
@@ -0,0 +1,10 @@
1
+ import { IPiiRedactor } from "../ports";
2
+ import { PiiOptions } from "../model";
3
+ export declare class PiiRedactor implements IPiiRedactor {
4
+ private props;
5
+ constructor(props?: PiiOptions);
6
+ updateOptions(opts: PiiOptions): void;
7
+ redact<T = unknown>(value: T): T;
8
+ private applyPatterns;
9
+ private redactDeep;
10
+ }
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PiiRedactor = void 0;
4
+ const utils_1 = require("../utils");
5
+ class PiiRedactor {
6
+ constructor(props = {}) {
7
+ this.props = props;
8
+ }
9
+ updateOptions(opts) {
10
+ // merge superficial de opciones; no muta referencias externas
11
+ this.props = { ...this.props, ...opts };
12
+ }
13
+ redact(value) {
14
+ if (!this.props.enabled)
15
+ return value; // early exit si PII apagado
16
+ if (value == null)
17
+ return value;
18
+ // Si es string → aplicar patrones
19
+ if (typeof value === "string") {
20
+ return this.applyPatterns(value);
21
+ }
22
+ // Si es objeto/array → redacción profunda si corresponde
23
+ if (typeof value === "object") {
24
+ return this.redactDeep(value);
25
+ }
26
+ // Otros tipos (number, boolean, function) no se redactan
27
+ return value;
28
+ }
29
+ applyPatterns(input) {
30
+ const patterns = this.props.patterns ?? [];
31
+ let out = input;
32
+ for (const p of patterns) {
33
+ const rx = (0, utils_1.toPiiRegex)(p);
34
+ // replace con patrón RegExp
35
+ out = out.replace(rx, p.replaceWith);
36
+ }
37
+ return out;
38
+ }
39
+ redactDeep(obj) {
40
+ // Evita mutar el objeto original → copia superficial
41
+ const clone = Array.isArray(obj)
42
+ ? [...obj]
43
+ : { ...obj };
44
+ const { whitelistKeys = [], blacklistKeys = [], deep = true } = this.props;
45
+ for (const key of Object.keys(clone)) {
46
+ const val = clone[key];
47
+ // Si está en whitelist, se respeta siempre
48
+ if (whitelistKeys.includes(key))
49
+ continue;
50
+ // Si está en blacklist y es string → reemplazar completamente
51
+ if (blacklistKeys.includes(key)) {
52
+ clone[key] = "[REDACTED]"; // fuerza redacción total de claves sensibles
53
+ continue;
54
+ }
55
+ // Para strings comunes → aplicar patrones
56
+ if (typeof val === "string") {
57
+ clone[key] = this.applyPatterns(val);
58
+ continue;
59
+ }
60
+ // Para objetos/arrays y deep===true → recursión
61
+ if (deep && val && typeof val === "object") {
62
+ clone[key] = this.redactDeep(val);
63
+ }
64
+ }
65
+ return clone;
66
+ }
67
+ }
68
+ exports.PiiRedactor = PiiRedactor;
@@ -0,0 +1 @@
1
+ export * from "./log-message.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("./log-message.type"), exports);
@@ -0,0 +1 @@
1
+ export type LogMessage = string | Record<string, unknown> | (() => string | Record<string, unknown>);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ export * from "./parse-log-level.util";
2
+ export * from "./normalize-message.util";
3
+ export * from "./pii-regex.util";
@@ -0,0 +1,19 @@
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("./parse-log-level.util"), exports);
18
+ __exportStar(require("./normalize-message.util"), exports);
19
+ __exportStar(require("./pii-regex.util"), exports);
@@ -0,0 +1,3 @@
1
+ import { IPiiRedactor } from "../ports";
2
+ import { LogMessage } from "../types";
3
+ export declare function normalizeMessage(message: LogMessage, redactor: IPiiRedactor): string | Record<string, unknown>;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeMessage = normalizeMessage;
4
+ // Normaliza el mensaje: si es función, la evalúa; si es objeto, se redacta; si es string, se redacta
5
+ function normalizeMessage(message, redactor) {
6
+ const resolved = typeof message === "function" ? message() : message; // eval laziness
7
+ return redactor.redact(resolved);
8
+ }
@@ -0,0 +1,2 @@
1
+ import { LogLevel } from "../value-objects";
2
+ export declare function parseLogLevel(input: string | number | undefined, fallback?: LogLevel): LogLevel;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseLogLevel = parseLogLevel;
4
+ const value_objects_1 = require("../value-objects");
5
+ // Convierte string a LogLevel con fallback seguro
6
+ function parseLogLevel(input, fallback = value_objects_1.LogLevel.INFO) {
7
+ if (typeof input === "number")
8
+ return (Object.values(value_objects_1.LogLevel).includes(input) ? input : fallback);
9
+ if (!input)
10
+ return fallback;
11
+ switch (String(input).toLowerCase()) {
12
+ case "trace":
13
+ return value_objects_1.LogLevel.TRACE;
14
+ case "debug":
15
+ return value_objects_1.LogLevel.DEBUG;
16
+ case "info":
17
+ return value_objects_1.LogLevel.INFO;
18
+ case "warn":
19
+ return value_objects_1.LogLevel.WARN;
20
+ case "error":
21
+ return value_objects_1.LogLevel.ERROR;
22
+ case "fatal":
23
+ return value_objects_1.LogLevel.FATAL;
24
+ default:
25
+ return fallback; // evita lanzar excepción por valores inesperados
26
+ }
27
+ }
@@ -0,0 +1,2 @@
1
+ import { PiiReplacementRule } from "../model";
2
+ export declare function toPiiRegex(props: PiiReplacementRule): RegExp;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toPiiRegex = toPiiRegex;
4
+ // Convierte un patrón PII declarativo a un RegExp seguro
5
+ function toPiiRegex(props) {
6
+ try {
7
+ return new RegExp(props.pattern, props.flags ?? "g");
8
+ }
9
+ catch {
10
+ // fallback: RegExp imposible que nunca hace match
11
+ return /$a/;
12
+ }
13
+ }
@@ -0,0 +1 @@
1
+ export * from "./log-level.vo";
@@ -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("./log-level.vo"), exports);
@@ -0,0 +1,8 @@
1
+ export declare enum LogLevel {
2
+ TRACE = 10,
3
+ DEBUG = 20,
4
+ INFO = 30,
5
+ WARN = 40,
6
+ ERROR = 50,
7
+ FATAL = 60
8
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LogLevel = void 0;
4
+ var LogLevel;
5
+ (function (LogLevel) {
6
+ // Orden creciente permite comparar por severidad (trace < debug < ...)
7
+ LogLevel[LogLevel["TRACE"] = 10] = "TRACE";
8
+ LogLevel[LogLevel["DEBUG"] = 20] = "DEBUG";
9
+ LogLevel[LogLevel["INFO"] = 30] = "INFO";
10
+ LogLevel[LogLevel["WARN"] = 40] = "WARN";
11
+ LogLevel[LogLevel["ERROR"] = 50] = "ERROR";
12
+ LogLevel[LogLevel["FATAL"] = 60] = "FATAL";
13
+ })(LogLevel || (exports.LogLevel = LogLevel = {}));
package/dist/index.d.ts CHANGED
@@ -1,4 +1,9 @@
1
- export * from "./composite";
2
- export * from "./domain";
3
- export * from "./presentation";
4
- export * from "./config";
1
+ export { createLogger } from "./application/factory";
2
+ export type { ILoggerFactoryConfig } from "./application/types";
3
+ export type { ILogger, ILogDatasource } from "./domain/ports";
4
+ export { LogLevel } from "./domain/value-objects";
5
+ export type { LogFilterRequest as LogSearchRequest } from "./domain/request";
6
+ export type { ILogResponse as LogRecord } from "./domain/response";
7
+ export type { PiiOptions as PiiRedactorOptions, LogEntry, } from "./domain/model";
8
+ export { PiiRedactor } from "./domain/services/pii-redactor.service";
9
+ export * as LoggerUtils from "./domain/utils";
package/dist/index.js CHANGED
@@ -10,11 +10,36 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
10
10
  if (k2 === undefined) k2 = k;
11
11
  o[k2] = m[k];
12
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
- };
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
16
35
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./composite"), exports);
18
- __exportStar(require("./domain"), exports);
19
- __exportStar(require("./presentation"), exports);
20
- __exportStar(require("./config"), exports);
36
+ exports.LoggerUtils = exports.PiiRedactor = exports.LogLevel = exports.createLogger = void 0;
37
+ var factory_1 = require("./application/factory");
38
+ Object.defineProperty(exports, "createLogger", { enumerable: true, get: function () { return factory_1.createLogger; } });
39
+ // 3) Tipos de dominio útiles
40
+ var value_objects_1 = require("./domain/value-objects");
41
+ Object.defineProperty(exports, "LogLevel", { enumerable: true, get: function () { return value_objects_1.LogLevel; } });
42
+ var pii_redactor_service_1 = require("./domain/services/pii-redactor.service");
43
+ Object.defineProperty(exports, "PiiRedactor", { enumerable: true, get: function () { return pii_redactor_service_1.PiiRedactor; } });
44
+ // 5) Utils públicos
45
+ exports.LoggerUtils = __importStar(require("./domain/utils"));
@@ -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);
@@ -0,0 +1,5 @@
1
+ export type OnDataSourceError = (info: {
2
+ operation: "save" | "find" | "flush" | "dispose";
3
+ datasourceName: string;
4
+ reason: any;
5
+ }) => void;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });