@jmlq/logger-plugin-fs 0.1.0-alpha.4 → 0.1.0-alpha.6

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 (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +32 -45
  3. package/package.json +3 -2
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-2025 mlahuasi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the “Software”), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md CHANGED
@@ -15,47 +15,9 @@ npm i @jmlq/logger @jmlq/logger-plugin-fs
15
15
 
16
16
  Este plugin **depende** de [`@jmlq/logger`](https://www.npmjs.com/package/@jmlq/logger). Asegúrate de instalar ambos paquetes.
17
17
 
18
- ## 🧱 Estructura del paquete
19
-
20
- ### 📝 Resumen rápido
21
-
22
- > - **`src/domain/`** — Reglas del negocio del plugin (sin dependencias de Node).
23
- > > - **`contracts/`**
24
- > > > - `clock.contract.ts` — Puerto que abstrae el tiempo actual (`now()`), permite testear rotación sin depender de `Date.now()`.
25
- > > > - `file-rotator.port.ts` — Puerto para rotación: calcula path esperado, tamaño, índice, etc.
26
- > > > - `stream-writer.port.ts` — Puerto para escritura secuencial: `write`, `once("drain")`, `end`.
27
- > > - **`value-objects/`**
28
- > > > - `file-name-pattern.vo.ts` — VO que encapsula el patrón de nombres (`{yyyy}{MM}{dd}`) con validación.
29
- > > > - `rotation-policy.vo.ts` — VO que define estrategia de rotación (`none | day | size`) con invariantes (`maxSizeMB > 0`).
30
- > > - **`types/`**
31
- > > > - `options.type.ts` — Define `FsDatasourceOptions` y `IFsSerializer` (contrato de serialización de líneas).
32
-
33
- > - **`src/application/`** — Casos de uso (orquestan, no dependen de Node).
34
- > > - **`dto/`**
35
- > > > - `save-log.dto.ts` — DTO de entrada: `{ log: ILog }`.
36
- > > - **`use-cases/`**
37
- > > > - `rotate-if-needed.usecase.ts` — Decide si se rota: compara fecha/tamaño contra `RotationPolicy`.
38
- > > > - `append-log.usecase.ts` — Serializa y escribe línea; maneja backpressure (`write=false` → espera `drain`).
39
- > > > - `persist-log.usecase.ts` — Orquesta: asegura writer, rota si corresponde, escribe, dispara hooks.
40
- > > - **`services/`**
41
- > > > - `fs-datasource.service.ts` — Implementa `ILogDatasource` del core usando los UC anteriores.
42
-
43
- > - **`src/infrastructure/`** — Adaptadores técnicos (Node.js).
44
- > > - **`fs/`**
45
- > > > - `fs-provider.ts` — Wrapper de `fs`/`fs.promises` (mockeable en tests).
46
- > > > - `path-utils.ts` — Utilidades para `join`, `splitBaseExt`, `formatPattern` (UTC).
47
- > > > - `file-rotator.adapter.ts` — Implementa `IFileRotatorPort` usando `fs-provider` y `path-utils`.
48
- > > > - `fs-writer.adapter.ts` — Implementa `IStreamWriterPort` con `fs.createWriteStream`.
49
- > > > - `node-clock.adapter.ts` — Implementa `IClock` devolviendo `new Date()`.
50
-
51
- > - **`src/presentation/`** — API pública (cara del paquete).
52
- > > - **`factory/`**
53
- > > > - `create-fs-datasource.ts` — Ensambla VO + adaptadores + casos de uso y devuelve un `ILogDatasource`.
54
- > > - `index.ts` — Barrel: reexporta la factory y VO/contratos públicos (`RotationPolicy`, `FileNamePattern`).
55
-
56
18
  ---
57
19
 
58
- ### 🧩 Configuración
20
+ ## 🧩 Configuración
59
21
 
60
22
  ### 🔐 Variables de Entorno (.env)
61
23
 
@@ -81,11 +43,7 @@ LOGGER_LEVEL=info # trace|debug|info|warn|error|fatal
81
43
 
82
44
  ```tsx
83
45
  import { createLogger, LogLevel } from "@jmlq/logger";
84
- import {
85
- createFsDatasource,
86
- RotationPolicy,
87
- FileNamePattern,
88
- } from "@jmlq/logger-plugin-fs";
46
+ import { createFsDatasource } from "@jmlq/logger-plugin-fs";
89
47
 
90
48
  const ds = createFsDatasource({
91
49
  basePath: "./logs", // Carpeta destino
@@ -112,7 +70,32 @@ process.on("SIGTERM", async () => {
112
70
  });
113
71
  ```
114
72
 
115
- #### Opciones soportadas
73
+ También:
74
+
75
+ ```ts
76
+ import { createLogger, LogLevel } from "@jmlq/logger";
77
+ import {
78
+ createFsDatasource,
79
+ RotationPolicy,
80
+ FileNamePattern,
81
+ } from "@jmlq/logger-plugin-fs";
82
+
83
+ // Validación/invariantes tempranas con VO (throws si es inválido)
84
+ const pt = new FileNamePattern("app-{yyyy}{MM}{dd}.log");
85
+ const rt = new RotationPolicy("size", 50 /* maxSizeMB */);
86
+
87
+ const ds = createFsDatasource({
88
+ basePath: "./logs",
89
+ mkdir: true,
90
+ // La factory acepta primitives; usamos los VO arriba solo para validar/centrar la decisión
91
+ fileNamePattern: pt.pattern,
92
+ rotation: { by: rt.by, maxSizeMB: rotation.maxSizeMB },
93
+ });
94
+
95
+ const logger = createLogger(ds, { minLevel: LogLevel.INFO });
96
+ ```
97
+
98
+ #### ⚙️ Opciones soportadas
116
99
 
117
100
  > - `basePath: string` – carpeta donde se guardan los logs.
118
101
  > - `mkdir?: boolean` – crea la carpeta si no existe.
@@ -183,6 +166,10 @@ No out-of-the-box. Puedes implementar un **FileNamePattern** por hora (ej. `app-
183
166
 
184
167
  ---
185
168
 
169
+ #### [LEER MAS...](./ARQUITECTURA.md)
170
+
171
+ ---
172
+
186
173
  ## 📄 Licencia
187
174
 
188
175
  MIT © Mauricio Lahuasi
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@jmlq/logger-plugin-fs",
3
- "version": "0.1.0-alpha.4",
3
+ "version": "0.1.0-alpha.6",
4
4
  "author": "MLahuasi",
5
+ "license": "MIT",
5
6
  "main": "dist/index.js",
6
7
  "types": "dist/index.d.ts",
7
8
  "files": [
@@ -24,7 +25,7 @@
24
25
  "jest": "^30.1.3"
25
26
  },
26
27
  "dependencies": {
27
- "@jmlq/logger": "^0.1.0-alpha.2"
28
+ "@jmlq/logger": "^0.1.0-alpha.6"
28
29
  },
29
30
  "overrides": {
30
31
  "test-exclude": "^7.0.1",