@jmlq/logger-plugin-fs 0.1.0-alpha.7 → 0.1.0-alpha.9

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 (144) hide show
  1. package/README.md +6 -0
  2. package/dist/application/dto/index.d.ts +1 -3
  3. package/dist/application/dto/index.js +1 -3
  4. package/dist/application/dto/rotate-if-needed.request.d.ts +10 -0
  5. package/dist/application/factory/create-fs-datasource.factory.d.ts +14 -1
  6. package/dist/application/factory/create-fs-datasource.factory.js +45 -20
  7. package/dist/application/use-cases/append-log.use-case.d.ts +26 -8
  8. package/dist/application/use-cases/append-log.use-case.js +25 -12
  9. package/dist/application/use-cases/ensure-directory.use-case.d.ts +50 -3
  10. package/dist/application/use-cases/ensure-directory.use-case.js +44 -7
  11. package/dist/application/use-cases/find-logs-use-case.d.ts +17 -0
  12. package/dist/application/use-cases/find-logs-use-case.js +64 -0
  13. package/dist/application/use-cases/index.d.ts +1 -0
  14. package/dist/application/use-cases/index.js +1 -0
  15. package/dist/application/use-cases/persist-log.use-case.d.ts +86 -9
  16. package/dist/application/use-cases/persist-log.use-case.js +73 -15
  17. package/dist/application/use-cases/rotate-if-needed.use-case.d.ts +49 -11
  18. package/dist/application/use-cases/rotate-if-needed.use-case.js +41 -8
  19. package/dist/domain/model/index.d.ts +1 -0
  20. package/dist/{infrastructure/filesystem/value-objects → domain/model}/index.js +1 -1
  21. package/dist/domain/model/log-entry.model.d.ts +8 -0
  22. package/dist/domain/ports/file/file-path.port.d.ts +38 -0
  23. package/dist/domain/ports/file/file-rotator.port.d.ts +42 -0
  24. package/dist/{infrastructure/filesystem/ports → domain/ports/file}/index.d.ts +1 -0
  25. package/dist/{infrastructure/filesystem/ports → domain/ports/file}/index.js +1 -0
  26. package/dist/domain/ports/file/log-stream-writer.port.d.ts +70 -0
  27. package/dist/domain/ports/{fs-provider.port.d.ts → filesystem-provider.port.d.ts} +1 -1
  28. package/dist/domain/ports/index.d.ts +5 -4
  29. package/dist/domain/ports/index.js +5 -4
  30. package/dist/domain/ports/logs/find/index.d.ts +2 -0
  31. package/dist/domain/ports/logs/find/index.js +18 -0
  32. package/dist/domain/ports/logs/find/log-file-line-reader.port.d.ts +3 -0
  33. package/dist/domain/ports/logs/find/log-file-numerator.port.d.ts +3 -0
  34. package/dist/domain/ports/logs/index.d.ts +2 -0
  35. package/dist/domain/ports/logs/index.js +18 -0
  36. package/dist/domain/ports/logs/log-datasource.port.d.ts +10 -0
  37. package/dist/domain/ports/{clock.port.d.ts → system-clock.port.d.ts} +1 -1
  38. package/dist/domain/ports/system-clock.port.js +2 -0
  39. package/dist/domain/request/index.d.ts +2 -0
  40. package/dist/domain/request/index.js +18 -0
  41. package/dist/domain/request/log-filter.request.d.ts +9 -0
  42. package/dist/domain/request/log-filter.request.js +2 -0
  43. package/dist/domain/request/save-log.request.d.ts +7 -0
  44. package/dist/domain/request/save-log.request.js +2 -0
  45. package/dist/domain/response/index.d.ts +1 -0
  46. package/dist/{application/services → domain/response}/index.js +1 -1
  47. package/dist/domain/response/log.response.d.ts +8 -0
  48. package/dist/domain/response/log.response.js +2 -0
  49. package/dist/domain/types/fs-rotation-by.type.d.ts +8 -0
  50. package/dist/domain/types/fs-rotation-by.type.js +2 -0
  51. package/dist/domain/types/index.d.ts +1 -0
  52. package/dist/domain/types/index.js +17 -0
  53. package/dist/domain/value-objects/file-name-pattern.vo.d.ts +36 -0
  54. package/dist/domain/value-objects/file-name-pattern.vo.js +53 -0
  55. package/dist/domain/value-objects/file-path.vo.d.ts +73 -9
  56. package/dist/domain/value-objects/file-path.vo.js +54 -13
  57. package/dist/domain/value-objects/file-rotation-policy.vo.d.ts +51 -0
  58. package/dist/domain/value-objects/file-rotation-policy.vo.js +76 -0
  59. package/dist/domain/value-objects/file-size.vo.d.ts +61 -0
  60. package/dist/domain/value-objects/file-size.vo.js +57 -0
  61. package/dist/domain/value-objects/index.d.ts +3 -0
  62. package/dist/domain/value-objects/index.js +3 -0
  63. package/dist/domain/value-objects/log-level.vo.d.ts +8 -0
  64. package/dist/domain/value-objects/log-level.vo.js +13 -0
  65. package/dist/index.d.ts +3 -4
  66. package/dist/index.js +5 -11
  67. package/dist/infrastructure/adapters/file-rotator.adapter.d.ts +67 -8
  68. package/dist/infrastructure/adapters/file-rotator.adapter.js +133 -67
  69. package/dist/infrastructure/adapters/fileSystem-datasource.adapter.d.ts +26 -0
  70. package/dist/infrastructure/adapters/fileSystem-datasource.adapter.js +45 -0
  71. package/dist/infrastructure/adapters/filesystem-log-file-enumerator.adapter.d.ts +6 -0
  72. package/dist/infrastructure/adapters/filesystem-log-file-enumerator.adapter.js +54 -0
  73. package/dist/infrastructure/adapters/filesystem-log-file-line-reader.adapter.d.ts +4 -0
  74. package/dist/infrastructure/adapters/{fs-provider.adapter.js → filesystem-log-file-line-reader.adapter.js} +13 -37
  75. package/dist/infrastructure/adapters/filesystem-provider.adapter.d.ts +122 -0
  76. package/dist/infrastructure/adapters/filesystem-provider.adapter.js +182 -0
  77. package/dist/infrastructure/adapters/index.d.ts +7 -4
  78. package/dist/infrastructure/adapters/index.js +7 -4
  79. package/dist/infrastructure/adapters/log-stream-writer.adapter.d.ts +80 -0
  80. package/dist/infrastructure/adapters/log-stream-writer.adapter.js +163 -0
  81. package/dist/infrastructure/adapters/system-clock.adapter.d.ts +25 -0
  82. package/dist/infrastructure/adapters/system-clock.adapter.js +30 -0
  83. package/dist/infrastructure/adapters/system-file-path.adapter.d.ts +47 -0
  84. package/dist/infrastructure/adapters/system-file-path.adapter.js +141 -0
  85. package/dist/infrastructure/errors/file-operation.error.d.ts +28 -0
  86. package/dist/infrastructure/errors/file-operation.error.js +54 -0
  87. package/dist/infrastructure/errors/index.d.ts +1 -0
  88. package/dist/{shared → infrastructure}/errors/index.js +0 -2
  89. package/dist/infrastructure/errors/types/file-operation-error-options.type.d.ts +8 -0
  90. package/dist/infrastructure/errors/types/file-operation-error-options.type.js +2 -0
  91. package/dist/infrastructure/errors/types/file-operation.type.d.ts +1 -0
  92. package/dist/infrastructure/errors/types/file-operation.type.js +2 -0
  93. package/dist/infrastructure/errors/types/fs-error-scope.type.d.ts +1 -0
  94. package/dist/infrastructure/errors/types/fs-error-scope.type.js +2 -0
  95. package/dist/infrastructure/errors/types/index.d.ts +3 -0
  96. package/dist/infrastructure/errors/types/index.js +19 -0
  97. package/dist/infrastructure/filesystem/index.d.ts +0 -3
  98. package/dist/infrastructure/filesystem/index.js +0 -3
  99. package/dist/infrastructure/filesystem/types/filesystem-datasource-options.type.d.ts +2 -6
  100. package/dist/infrastructure/filesystem/types/filesystem-rotation.type.d.ts +2 -9
  101. package/dist/infrastructure/filesystem/types/index.d.ts +0 -1
  102. package/dist/infrastructure/filesystem/types/index.js +0 -1
  103. package/install.md +1 -1
  104. package/package.json +4 -6
  105. package/dist/application/dto/rotation-check.dto.d.ts +0 -5
  106. package/dist/application/dto/save-log.dto.d.ts +0 -4
  107. package/dist/application/dto/write-operation.dto.d.ts +0 -5
  108. package/dist/application/services/fs-datasource.service.d.ts +0 -11
  109. package/dist/application/services/fs-datasource.service.js +0 -19
  110. package/dist/application/services/index.d.ts +0 -1
  111. package/dist/domain/ports/file-path-adapter.port.d.ts +0 -33
  112. package/dist/domain/ports/stream-writer.port.d.ts +0 -42
  113. package/dist/infrastructure/adapters/fs-provider.adapter.d.ts +0 -17
  114. package/dist/infrastructure/adapters/fs-writer.adapter.d.ts +0 -13
  115. package/dist/infrastructure/adapters/fs-writer.adapter.js +0 -71
  116. package/dist/infrastructure/adapters/node-clock.adapter.d.ts +0 -4
  117. package/dist/infrastructure/adapters/node-clock.adapter.js +0 -9
  118. package/dist/infrastructure/adapters/node-file-path.adapter.d.ts +0 -16
  119. package/dist/infrastructure/adapters/node-file-path.adapter.js +0 -117
  120. package/dist/infrastructure/filesystem/polices/index.d.ts +0 -1
  121. package/dist/infrastructure/filesystem/polices/index.js +0 -5
  122. package/dist/infrastructure/filesystem/polices/rotation-policy.d.ts +0 -29
  123. package/dist/infrastructure/filesystem/polices/rotation-policy.js +0 -55
  124. package/dist/infrastructure/filesystem/ports/file-rotator.port.d.ts +0 -32
  125. package/dist/infrastructure/filesystem/types/filesystem-serializer.type.d.ts +0 -10
  126. package/dist/infrastructure/filesystem/value-objects/file-name-pattern.vo.d.ts +0 -22
  127. package/dist/infrastructure/filesystem/value-objects/file-name-pattern.vo.js +0 -37
  128. package/dist/infrastructure/filesystem/value-objects/index.d.ts +0 -1
  129. package/dist/shared/errors/file-operation.error.d.ts +0 -12
  130. package/dist/shared/errors/file-operation.error.js +0 -32
  131. package/dist/shared/errors/fs-plugin.error.d.ts +0 -4
  132. package/dist/shared/errors/fs-plugin.error.js +0 -11
  133. package/dist/shared/errors/index.d.ts +0 -3
  134. package/dist/shared/errors/rotation.error.d.ts +0 -10
  135. package/dist/shared/errors/rotation.error.js +0 -25
  136. /package/dist/application/dto/{rotation-check.dto.js → rotate-if-needed.request.js} +0 -0
  137. /package/dist/{application/dto/save-log.dto.js → domain/model/log-entry.model.js} +0 -0
  138. /package/dist/{application/dto/write-operation.dto.js → domain/ports/file/file-path.port.js} +0 -0
  139. /package/dist/{infrastructure/filesystem/ports → domain/ports/file}/file-rotator.port.js +0 -0
  140. /package/dist/domain/ports/{clock.port.js → file/log-stream-writer.port.js} +0 -0
  141. /package/dist/domain/ports/{file-path-adapter.port.js → filesystem-provider.port.js} +0 -0
  142. /package/dist/domain/ports/{fs-provider.port.js → logs/find/log-file-line-reader.port.js} +0 -0
  143. /package/dist/domain/ports/{stream-writer.port.js → logs/find/log-file-numerator.port.js} +0 -0
  144. /package/dist/{infrastructure/filesystem/types/filesystem-serializer.type.js → domain/ports/logs/log-datasource.port.js} +0 -0
@@ -0,0 +1,141 @@
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 __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
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.SystemFilePathAdapter = void 0;
37
+ const path = __importStar(require("path"));
38
+ const value_objects_1 = require("../../domain/value-objects");
39
+ /**
40
+ * SystemFilePathAdapter
41
+ * --------------------
42
+ * Adapter de infraestructura que implementa IFilePathPort usando el módulo `path`
43
+ * del entorno de ejecución (típicamente Node.js).
44
+ *
45
+ * Responsabilidad:
46
+ * - Aceptar rutas crudas (relativas o absolutas).
47
+ * - Normalizar y resolver siempre a una ruta absoluta.
48
+ * - Construir y transformar el Value Object FilePath de forma consistente.
49
+ *
50
+ * Nota de diseño:
51
+ * - Este adapter centraliza TODA la lógica "dependiente del sistema" (path/OS).
52
+ * - El dominio no debería usar `path.*` directamente.
53
+ */
54
+ class SystemFilePathAdapter {
55
+ // ---------------------------------------------------------------------------
56
+ // Creación: desde input crudo
57
+ // ---------------------------------------------------------------------------
58
+ /**
59
+ * Crea un FilePath desde una ruta cruda (relativa o absoluta).
60
+ * La implementación:
61
+ * - valida input
62
+ * - normaliza
63
+ * - resuelve a absoluta (path.resolve)
64
+ */
65
+ fromRaw(inputPath) {
66
+ // Validación de entrada: evita valores nulos, no-string o vacíos.
67
+ if (typeof inputPath !== "string") {
68
+ throw new Error("SystemFilePathAdapter.fromRaw: inputPath must be a string");
69
+ }
70
+ const trimmed = inputPath.trim();
71
+ if (!trimmed) {
72
+ throw new Error("SystemFilePathAdapter.fromRaw: inputPath cannot be empty or whitespace");
73
+ }
74
+ // Importante: NO resolvemos aquí y también en buildFromAnyPath.
75
+ // Reducimos redundancia: delegamos la normalización/resolución en un único helper.
76
+ return this.buildFromAnyPath(trimmed);
77
+ }
78
+ // ---------------------------------------------------------------------------
79
+ // Transformaciones: derivar nuevas rutas desde un FilePath existente
80
+ // ---------------------------------------------------------------------------
81
+ /**
82
+ * Une segmentos a la ruta base.
83
+ *
84
+ * Nota importante:
85
+ * - Aquí es clave definir semántica. Para evitar el caso raro:
86
+ * "/logs/app.log" + "x" -> "/logs/app.log/x"
87
+ * unimos los segmentos al DIRECTORIO del FilePath.
88
+ *
89
+ * Si tu intención era tratar FilePath como "basePath" que puede ser directorio,
90
+ * entonces tu VO debería representar directorios explícitamente.
91
+ */
92
+ join(filePath, ...segments) {
93
+ // Unimos respecto al directorio del archivo (semántica segura).
94
+ const fullPath = path.join(filePath.directory, ...segments);
95
+ return this.buildFromAnyPath(fullPath);
96
+ }
97
+ // ---------------------------------------------------------------------------
98
+ // Helper privado: construcción consistente de IFilePathProps
99
+ // ---------------------------------------------------------------------------
100
+ /**
101
+ * Construye un FilePath resolviendo y normalizando en UN SOLO lugar.
102
+ *
103
+ * Redundancia corregida:
104
+ * - Antes se hacía path.resolve() en métodos públicos y también en el builder.
105
+ * - Ahora todos pasan por este helper y aquí se aplica resolve/normalize.
106
+ */
107
+ buildFromAnyPath(anyPath) {
108
+ const raw = anyPath.trim();
109
+ const isDirHint = /[\\\/]$/.test(raw);
110
+ // Resolver a absoluto y normalizar (maneja ., .., separadores OS, etc.)
111
+ const normalized = path.resolve(anyPath);
112
+ if (isDirHint) {
113
+ // Representa directorio
114
+ return new value_objects_1.FilePath({
115
+ kind: "dir",
116
+ absolutePath: normalized,
117
+ directory: normalized, // para dirs, directory = sí mismo
118
+ filename: null,
119
+ extension: null,
120
+ basename: null,
121
+ });
122
+ }
123
+ // Derivar partes a partir de la ruta normalizada.
124
+ const directory = path.dirname(normalized);
125
+ const filename = path.basename(normalized);
126
+ const extension = path.extname(normalized);
127
+ const basename = path.basename(normalized, extension);
128
+ // Props canónicas del VO.
129
+ const props = {
130
+ kind: "file",
131
+ absolutePath: normalized,
132
+ directory,
133
+ filename,
134
+ extension,
135
+ basename,
136
+ };
137
+ // Crear VO: aquí el dominio puede validar invariantes adicionales si lo deseas.
138
+ return new value_objects_1.FilePath(props);
139
+ }
140
+ }
141
+ exports.SystemFilePathAdapter = SystemFilePathAdapter;
@@ -0,0 +1,28 @@
1
+ import { FileOperation, FileOperationErrorOptions, FsErrorScope } from "./types";
2
+ /**
3
+ * Error especializado para fallos de operaciones de filesystem.
4
+ *
5
+ * Encapsula errores de I/O (read, write, delete, mkdir, move) agregando
6
+ * contexto técnico relevante:
7
+ * - operation: operación de filesystem que falló.
8
+ * - filePath: ruta afectada (si aplica).
9
+ * - cause: error original que provocó el fallo.
10
+ * - scope: origen del error (por ejemplo, "fs-plugin").
11
+ *
12
+ * Su propósito es:
13
+ * - Normalizar errores de filesystem dentro del plugin FS.
14
+ * - Evitar el uso de Error genérico sin contexto.
15
+ * - Facilitar logging, debugging y traducción a errores de capas superiores.
16
+ *
17
+ * No representa errores de dominio ni de configuración; solo fallos de I/O.
18
+ */
19
+ export declare class FileOperationError extends Error {
20
+ readonly name = "FileOperationError";
21
+ readonly scope?: FsErrorScope;
22
+ readonly operation: FileOperation;
23
+ readonly filePath?: string;
24
+ readonly cause?: unknown;
25
+ constructor(opts: FileOperationErrorOptions);
26
+ static create(operation: FileOperation, filePath?: string, cause?: unknown): FileOperationError;
27
+ static fs(operation: FileOperation, filePath?: string, cause?: unknown): FileOperationError;
28
+ }
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileOperationError = void 0;
4
+ /**
5
+ * Error especializado para fallos de operaciones de filesystem.
6
+ *
7
+ * Encapsula errores de I/O (read, write, delete, mkdir, move) agregando
8
+ * contexto técnico relevante:
9
+ * - operation: operación de filesystem que falló.
10
+ * - filePath: ruta afectada (si aplica).
11
+ * - cause: error original que provocó el fallo.
12
+ * - scope: origen del error (por ejemplo, "fs-plugin").
13
+ *
14
+ * Su propósito es:
15
+ * - Normalizar errores de filesystem dentro del plugin FS.
16
+ * - Evitar el uso de Error genérico sin contexto.
17
+ * - Facilitar logging, debugging y traducción a errores de capas superiores.
18
+ *
19
+ * No representa errores de dominio ni de configuración; solo fallos de I/O.
20
+ */
21
+ class FileOperationError extends Error {
22
+ constructor(opts) {
23
+ const message = opts.message ??
24
+ buildDefaultMessage({
25
+ operation: opts.operation,
26
+ filePath: opts.filePath,
27
+ });
28
+ super(message);
29
+ this.name = "FileOperationError";
30
+ this.scope = opts.scope;
31
+ this.operation = opts.operation;
32
+ this.filePath = opts.filePath;
33
+ this.cause = opts.cause;
34
+ }
35
+ // ---------------------------------------------------------------------------
36
+ // Factories: I/O
37
+ // ---------------------------------------------------------------------------
38
+ static create(operation, filePath, cause) {
39
+ return new FileOperationError({ operation, filePath, cause });
40
+ }
41
+ static fs(operation, filePath, cause) {
42
+ return new FileOperationError({
43
+ scope: "fs-plugin",
44
+ operation,
45
+ filePath,
46
+ cause,
47
+ });
48
+ }
49
+ }
50
+ exports.FileOperationError = FileOperationError;
51
+ function buildDefaultMessage(opts) {
52
+ // I/O normal
53
+ return `Failed to ${opts.operation} file: ${opts.filePath ?? "(unknown)"}`;
54
+ }
@@ -0,0 +1 @@
1
+ export * from "./file-operation.error";
@@ -15,5 +15,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./file-operation.error"), exports);
18
- __exportStar(require("./fs-plugin.error"), exports);
19
- __exportStar(require("./rotation.error"), exports);
@@ -0,0 +1,8 @@
1
+ import { FileOperation, FsErrorScope } from ".";
2
+ export type FileOperationErrorOptions = {
3
+ scope?: FsErrorScope;
4
+ operation: FileOperation;
5
+ filePath?: string;
6
+ cause?: unknown;
7
+ message?: string;
8
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export type FileOperation = "read" | "write" | "delete" | "mkdir" | "move";
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export type FsErrorScope = "fs-plugin";
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ export * from "./file-operation.type";
2
+ export * from "./fs-error-scope.type";
3
+ export * from "./file-operation-error-options.type";
@@ -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("./file-operation.type"), exports);
18
+ __exportStar(require("./fs-error-scope.type"), exports);
19
+ __exportStar(require("./file-operation-error-options.type"), exports);
@@ -1,4 +1 @@
1
- export * from "./polices";
2
1
  export * from "./types";
3
- export * from "./value-objects";
4
- export * from "./ports";
@@ -14,7 +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("./polices"), exports);
18
17
  __exportStar(require("./types"), exports);
19
- __exportStar(require("./value-objects"), exports);
20
- __exportStar(require("./ports"), exports);
@@ -1,5 +1,5 @@
1
- import { IFileRotationConfig, IFsSerializer } from "..";
2
1
  import { FilePath } from "../../../domain/value-objects";
2
+ import { IFileSystemRotationConfig } from ".";
3
3
  /**
4
4
  * Opciones de configuración para la fuente de datos del sistema de archivos.
5
5
  * Es el objeto de configuración para un datasource de logs basado en filesystem
@@ -22,11 +22,7 @@ export interface IFilesystemDatasourceOptions {
22
22
  /**
23
23
  * Conecta con la política de rotación: "none" | "day" | "size", tamaño máximo, número de archivos, etc
24
24
  */
25
- rotation?: IFileRotationConfig;
26
- /**
27
- * Estrategia para serializar el log a string / buffer antes de escribir: JSON, texto plano, custom, etc
28
- */
29
- serializer?: IFsSerializer;
25
+ rotation?: IFileSystemRotationConfig;
30
26
  /**
31
27
  * Hook que se dispara cuando se rota un archivo de log. Útil para:
32
28
  * - Notificar a otro sistema.
@@ -1,18 +1,11 @@
1
- /**
2
- * Es un tipo discriminado que define cómo se realizará la rotación de logs dentro del sistema.
3
- * Los valores significan:
4
- * "none" → Sin rotación. El archivo crece indefinidamente.
5
- * "day" → Rotación diaria (por fecha).
6
- * "size" → Rotación por tamaño (normalmente basado en maxSizeMB).
7
- */
8
- export type FsRotationBy = "none" | "day" | "size";
1
+ import { FsRotationBy } from "../../../domain/types";
9
2
  /**
10
3
  * Representa la configuración que el sistema de log debe seguir para decidir cuándo rotar archivos.
11
4
  * by: Estrategia principal de rotación: "none", "day", "size".
12
5
  * maxSizeMB: Tamaño máximo del archivo antes de rotar (solo aplica si by === "size").
13
6
  * maxFiles: Cuántos archivos rotados se mantienen. Ejemplo: si maxFiles = 5, se mantienen:
14
7
  */
15
- export interface IFileRotationConfig {
8
+ export interface IFileSystemRotationConfig {
16
9
  by: FsRotationBy;
17
10
  maxSizeMB?: number;
18
11
  maxFiles?: number;
@@ -1,3 +1,2 @@
1
1
  export * from "./filesystem-datasource-options.type";
2
2
  export * from "./filesystem-rotation.type";
3
- export * from "./filesystem-serializer.type";
@@ -16,4 +16,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./filesystem-datasource-options.type"), exports);
18
18
  __exportStar(require("./filesystem-rotation.type"), exports);
19
- __exportStar(require("./filesystem-serializer.type"), exports);
package/install.md CHANGED
@@ -14,7 +14,7 @@ El plugin se integra como un datasource del logger principal, permitiendo escrib
14
14
  npm install @jmlq/logger @jmlq/logger-plugin-fs
15
15
  ```
16
16
 
17
- ### Dependencias de Peer
17
+ ### Dependencias
18
18
 
19
19
  El plugin requiere como peer dependency:
20
20
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jmlq/logger-plugin-fs",
3
3
  "description": "Filesystem plugin for JMLQ Logger implementing Clean Architecture principles.",
4
- "version": "0.1.0-alpha.7",
4
+ "version": "0.1.0-alpha.9",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {
@@ -14,12 +14,10 @@
14
14
  "example:help": "tsx examples/index.example.ts help",
15
15
  "example:all": "tsx examples/index.example.ts",
16
16
  "example:value-objects": "tsx examples/index.example.ts value-objects",
17
- "example:infrastructure-policies": "tsx examples/index.example.ts infrastructure-policies",
18
17
  "example:infrastructure-adapters": "tsx examples/index.example.ts infrastructure-adapters",
19
18
  "example:application-use-cases": "tsx examples/index.example.ts application-use-cases",
20
19
  "example:application-services": "tsx examples/index.example.ts application-services",
21
- "example:application-factories": "tsx examples/index.example.ts application-factories",
22
- "example:filesize": "tsx examples/filesize.example.ts"
20
+ "example:application-factories": "tsx examples/index.example.ts application-factories"
23
21
  },
24
22
  "keywords": [
25
23
  "logger",
@@ -46,7 +44,7 @@
46
44
  "architecture.md",
47
45
  "install.md"
48
46
  ],
49
- "peerDependencies": {
50
- "@jmlq/logger": ">=0.1.0-alpha.12"
47
+ "dependencies": {
48
+ "@jmlq/logger": "^0.1.0-alpha.18"
51
49
  }
52
50
  }
@@ -1,5 +0,0 @@
1
- export interface IRotationCheckDto {
2
- currentPath: string;
3
- currentDate: Date;
4
- currentSizeBytes: number;
5
- }
@@ -1,4 +0,0 @@
1
- import { ILogProps } from "@jmlq/logger";
2
- export interface ISaveLogDto {
3
- log: ILogProps;
4
- }
@@ -1,5 +0,0 @@
1
- export interface IWriteOperationDto {
2
- data: string;
3
- targetPath: string;
4
- append?: boolean;
5
- }
@@ -1,11 +0,0 @@
1
- import { ILogProps, ILogDatasource } from "@jmlq/logger";
2
- import { IPersistLogUseCase } from "../use-cases";
3
- import { IStreamWriterPort } from "../../domain/ports";
4
- export declare class FsDatasourceService implements ILogDatasource {
5
- private readonly persistLogUseCase;
6
- private readonly streamWriterPort;
7
- constructor(persistLogUseCase: IPersistLogUseCase, streamWriterPort: IStreamWriterPort);
8
- save(log: ILogProps): Promise<void>;
9
- flush(): Promise<void>;
10
- dispose(): Promise<void>;
11
- }
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FsDatasourceService = void 0;
4
- class FsDatasourceService {
5
- constructor(persistLogUseCase, streamWriterPort) {
6
- this.persistLogUseCase = persistLogUseCase;
7
- this.streamWriterPort = streamWriterPort;
8
- }
9
- async save(log) {
10
- await this.persistLogUseCase.execute({ log });
11
- }
12
- async flush() {
13
- await this.streamWriterPort.flush();
14
- }
15
- async dispose() {
16
- await this.streamWriterPort.close();
17
- }
18
- }
19
- exports.FsDatasourceService = FsDatasourceService;
@@ -1 +0,0 @@
1
- export * from "./fs-datasource.service";
@@ -1,33 +0,0 @@
1
- import { FilePath } from "../value-objects";
2
- export interface IFilePathAdapterPort {
3
- /**
4
- * Crea un FilePath a partir de una ruta cruda (relativa o absoluta).
5
- * La implementación se encarga de normalizar y resolver a absoluta.
6
- */
7
- fromRaw(inputPath: string): FilePath;
8
- /**
9
- * Crea un FilePath a partir de (directorio, basename, extensión).
10
- */
11
- fromBasename(directory: string, basename: string, extension: string): FilePath;
12
- /**
13
- * Devuelve un nuevo FilePath con la misma ruta pero otra extensión.
14
- */
15
- withExtension(filePath: FilePath, newExtension: string): FilePath;
16
- /**
17
- * Devuelve un nuevo FilePath con el mismo directorio y extensión,
18
- * pero con otro basename.
19
- */
20
- withBasename(filePath: FilePath, newBasename: string): FilePath;
21
- /**
22
- * Une segmentos a la ruta actual.
23
- */
24
- join(filePath: FilePath, ...segments: string[]): FilePath;
25
- /**
26
- * Resuelve segmentos relativos respecto al FilePath actual.
27
- */
28
- resolve(filePath: FilePath, ...segments: string[]): FilePath;
29
- /**
30
- * Obtiene la ruta relativa desde basePath hacia el FilePath.
31
- */
32
- relativeTo(basePath: string, filePath: FilePath): string;
33
- }
@@ -1,42 +0,0 @@
1
- import { FilePath } from "../value-objects";
2
- /**
3
- * Es una abstracción de un writer basado en stream, típicamente usado para escribir logs de forma eficiente sin reabrir archivos por cada línea.
4
- * Es un Outbound Port del dominio hacia una implementación de infraestructura
5
- */
6
- export interface IStreamWriterPort {
7
- /**
8
- * Escritura directa de datos al stream
9
- * @param data Datos a escribir
10
- * @return Retorna true si la escritura fue exitosa, false si el buffer está lleno y se debe esperar a que se vacíe antes de escribir más
11
- */
12
- write(data: string): Promise<boolean>;
13
- /**
14
- * Abre un stream para un archivo específico.
15
- * @param filePath Ruta del archivo a abrir para escritura como FilePath
16
- */
17
- open(filePath: FilePath): Promise<void>;
18
- /**
19
- * Cierra el stream sin finalizar el archivo, dejando posibilidad de reabrirlo o rotarlo
20
- * @return Promise que se resuelve cuando el stream ha sido cerrado
21
- */
22
- close(): Promise<void>;
23
- /**
24
- * Buffer pendiente (si la implementación usa buffering).
25
- * Asegura que todos los datos en el buffer hayan sido escritos al archivo
26
- */
27
- flush(): Promise<void>;
28
- /**
29
- * Permite saber si el stream está listo para aceptar escritura
30
- * @return true si el stream está abierto y listo, false si está cerrado o no disponible
31
- */
32
- isOpen(): boolean;
33
- /**
34
- * Permite al dominio saber qué archivo está actualmente siendo usado para escribir
35
- * @return FilePath del archivo actualmente abierto, o null si no hay ninguno abierto
36
- */
37
- getCurrentPath(): FilePath | null;
38
- /**
39
- * Finaliza el stream
40
- */
41
- end(): Promise<void>;
42
- }
@@ -1,17 +0,0 @@
1
- import { IFsProviderPort } from "../../domain/ports";
2
- export declare class FsProviderAdapter implements IFsProviderPort {
3
- exists(path: string): Promise<boolean>;
4
- mkdir(path: string, options?: {
5
- recursive?: boolean;
6
- }): Promise<void>;
7
- readFile(path: string): Promise<Buffer>;
8
- writeFile(path: string, data: string | Buffer): Promise<void>;
9
- appendFile(path: string, data: string | Buffer): Promise<void>;
10
- stat(path: string): Promise<{
11
- size: number;
12
- mtime: Date;
13
- }>;
14
- readdir(path: string): Promise<string[]>;
15
- unlink(path: string): Promise<void>;
16
- rename(oldPath: string, newPath: string): Promise<void>;
17
- }
@@ -1,13 +0,0 @@
1
- import { IStreamWriterPort } from "../../domain/ports";
2
- import { FilePath } from "../../domain/value-objects";
3
- export declare class FsWriterAdapter implements IStreamWriterPort {
4
- private stream;
5
- private currentPath;
6
- write(data: string): Promise<boolean>;
7
- open(path: FilePath): Promise<void>;
8
- close(): Promise<void>;
9
- end(): Promise<void>;
10
- flush(): Promise<void>;
11
- isOpen(): boolean;
12
- getCurrentPath(): FilePath | null;
13
- }
@@ -1,71 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FsWriterAdapter = void 0;
4
- const fs_1 = require("fs");
5
- const errors_1 = require("../../shared/errors");
6
- class FsWriterAdapter {
7
- constructor() {
8
- this.stream = null;
9
- this.currentPath = null;
10
- }
11
- async write(data) {
12
- if (!this.stream) {
13
- throw new errors_1.FsPluginError("Stream not opened");
14
- }
15
- return new Promise((resolve, reject) => {
16
- const success = this.stream.write(data);
17
- if (!success) {
18
- this.stream.once("drain", () => resolve(true));
19
- this.stream.once("error", reject);
20
- }
21
- else {
22
- resolve(true);
23
- }
24
- });
25
- }
26
- async open(path) {
27
- if (this.stream) {
28
- await this.close();
29
- }
30
- const pathString = path.absolutePath;
31
- this.stream = (0, fs_1.createWriteStream)(pathString, { flags: "a" });
32
- this.currentPath = path;
33
- return new Promise((resolve, reject) => {
34
- this.stream.once("open", () => resolve());
35
- this.stream.once("error", reject);
36
- });
37
- }
38
- async close() {
39
- if (!this.stream)
40
- return;
41
- return new Promise((resolve) => {
42
- this.stream.end(() => {
43
- this.stream = null;
44
- this.currentPath = null;
45
- resolve();
46
- });
47
- });
48
- }
49
- async end() {
50
- return this.close();
51
- }
52
- async flush() {
53
- if (!this.stream)
54
- return;
55
- return new Promise((resolve) => {
56
- if (this.stream.writableNeedDrain) {
57
- this.stream.once("drain", () => resolve());
58
- }
59
- else {
60
- resolve();
61
- }
62
- });
63
- }
64
- isOpen() {
65
- return this.stream !== null;
66
- }
67
- getCurrentPath() {
68
- return this.currentPath;
69
- }
70
- }
71
- exports.FsWriterAdapter = FsWriterAdapter;
@@ -1,4 +0,0 @@
1
- import { IClockPort } from "../../domain/ports";
2
- export declare class NodeClockAdapter implements IClockPort {
3
- now(): Date;
4
- }
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NodeClockAdapter = void 0;
4
- class NodeClockAdapter {
5
- now() {
6
- return new Date();
7
- }
8
- }
9
- exports.NodeClockAdapter = NodeClockAdapter;