@jmlq/logger-plugin-fs 0.1.0-alpha.6 → 0.1.0-alpha.7
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 +165 -117
- package/architecture.md +426 -0
- package/dist/application/dto/index.d.ts +2 -0
- package/dist/application/dto/index.js +2 -0
- package/dist/application/dto/rotation-check.dto.d.ts +5 -0
- package/dist/application/dto/save-log.dto.d.ts +3 -3
- package/dist/application/dto/write-operation.dto.d.ts +5 -0
- package/dist/application/factory/create-fs-datasource.factory.d.ts +3 -0
- package/dist/application/factory/create-fs-datasource.factory.js +26 -0
- package/dist/application/factory/index.d.ts +1 -0
- package/dist/{presentation → application}/factory/index.js +1 -1
- package/dist/application/services/fs-datasource.service.d.ts +7 -5
- package/dist/application/services/fs-datasource.service.js +6 -9
- package/dist/application/use-cases/append-log.use-case.d.ts +12 -0
- package/dist/application/use-cases/append-log.use-case.js +26 -0
- package/dist/application/use-cases/ensure-directory.use-case.d.ts +11 -0
- package/dist/application/use-cases/ensure-directory.use-case.js +27 -0
- package/dist/application/use-cases/index.d.ts +4 -3
- package/dist/application/use-cases/index.js +4 -3
- package/dist/application/use-cases/persist-log.use-case.d.ts +19 -0
- package/dist/application/use-cases/persist-log.use-case.js +47 -0
- package/dist/application/use-cases/rotate-if-needed.use-case.d.ts +17 -0
- package/dist/application/use-cases/rotate-if-needed.use-case.js +28 -0
- package/dist/domain/ports/clock.port.d.ts +8 -0
- package/dist/domain/ports/file-path-adapter.port.d.ts +33 -0
- package/dist/domain/ports/fs-provider.port.d.ts +61 -0
- package/dist/domain/ports/fs-provider.port.js +2 -0
- package/dist/domain/ports/index.d.ts +4 -0
- package/dist/domain/{contracts → ports}/index.js +3 -3
- package/dist/domain/ports/stream-writer.port.d.ts +42 -0
- package/dist/domain/ports/stream-writer.port.js +2 -0
- package/dist/domain/value-objects/file-path.vo.d.ts +27 -0
- package/dist/domain/value-objects/file-path.vo.js +59 -0
- package/dist/domain/value-objects/file-size.vo.d.ts +14 -0
- package/dist/domain/value-objects/file-size.vo.js +57 -0
- package/dist/domain/value-objects/index.d.ts +2 -2
- package/dist/domain/value-objects/index.js +2 -2
- package/dist/index.d.ts +4 -3
- package/dist/index.js +14 -5
- package/dist/infrastructure/adapters/file-rotator.adapter.d.ts +20 -0
- package/dist/infrastructure/adapters/file-rotator.adapter.js +105 -0
- package/dist/infrastructure/adapters/fs-provider.adapter.d.ts +17 -0
- package/dist/infrastructure/{fs/fs-provider.js → adapters/fs-provider.adapter.js} +41 -19
- package/dist/infrastructure/adapters/fs-writer.adapter.d.ts +13 -0
- package/dist/infrastructure/adapters/fs-writer.adapter.js +71 -0
- package/dist/infrastructure/{fs → adapters}/index.d.ts +2 -2
- package/dist/infrastructure/{fs → adapters}/index.js +2 -2
- package/dist/infrastructure/adapters/node-clock.adapter.d.ts +4 -0
- package/dist/infrastructure/{fs → adapters}/node-clock.adapter.js +0 -1
- package/dist/infrastructure/adapters/node-file-path.adapter.d.ts +16 -0
- package/dist/infrastructure/adapters/node-file-path.adapter.js +117 -0
- package/dist/infrastructure/filesystem/index.d.ts +4 -0
- package/dist/infrastructure/filesystem/index.js +20 -0
- package/dist/infrastructure/filesystem/polices/index.d.ts +1 -0
- package/dist/infrastructure/filesystem/polices/index.js +5 -0
- package/dist/infrastructure/filesystem/polices/rotation-policy.d.ts +29 -0
- package/dist/infrastructure/filesystem/polices/rotation-policy.js +55 -0
- package/dist/infrastructure/filesystem/ports/file-rotator.port.d.ts +32 -0
- package/dist/infrastructure/filesystem/ports/file-rotator.port.js +2 -0
- package/dist/infrastructure/filesystem/ports/index.d.ts +1 -0
- package/dist/{domain/types → infrastructure/filesystem/ports}/index.js +1 -1
- package/dist/infrastructure/filesystem/types/filesystem-datasource-options.type.d.ts +49 -0
- package/dist/infrastructure/filesystem/types/filesystem-datasource-options.type.js +2 -0
- package/dist/infrastructure/filesystem/types/filesystem-rotation.type.d.ts +19 -0
- package/dist/infrastructure/filesystem/types/filesystem-rotation.type.js +2 -0
- package/dist/infrastructure/filesystem/types/filesystem-serializer.type.d.ts +10 -0
- package/dist/infrastructure/filesystem/types/filesystem-serializer.type.js +2 -0
- package/dist/infrastructure/filesystem/types/index.d.ts +3 -0
- package/dist/infrastructure/filesystem/types/index.js +19 -0
- package/dist/infrastructure/filesystem/value-objects/file-name-pattern.vo.d.ts +22 -0
- package/dist/infrastructure/filesystem/value-objects/file-name-pattern.vo.js +37 -0
- package/dist/infrastructure/filesystem/value-objects/index.d.ts +1 -0
- package/dist/infrastructure/{datasources → filesystem/value-objects}/index.js +1 -1
- package/dist/shared/errors/file-operation.error.d.ts +12 -0
- package/dist/shared/errors/file-operation.error.js +32 -0
- package/dist/shared/errors/fs-plugin.error.d.ts +4 -0
- package/dist/shared/errors/fs-plugin.error.js +11 -0
- package/dist/shared/errors/index.d.ts +3 -0
- package/dist/shared/errors/index.js +19 -0
- package/dist/shared/errors/rotation.error.d.ts +10 -0
- package/dist/shared/errors/rotation.error.js +25 -0
- package/install.md +520 -0
- package/package.json +39 -22
- package/LICENSE +0 -21
- package/dist/application/use-cases/append-log.usecase.d.ts +0 -7
- package/dist/application/use-cases/append-log.usecase.js +0 -19
- package/dist/application/use-cases/persist-log.usecase.d.ts +0 -23
- package/dist/application/use-cases/persist-log.usecase.js +0 -74
- package/dist/application/use-cases/rotate-if-needed.usecase.d.ts +0 -10
- package/dist/application/use-cases/rotate-if-needed.usecase.js +0 -39
- package/dist/domain/contracts/clock.contract.d.ts +0 -3
- package/dist/domain/contracts/file-rotator.contract.d.ts +0 -7
- package/dist/domain/contracts/index.d.ts +0 -4
- package/dist/domain/contracts/serializer.contract.d.ts +0 -3
- package/dist/domain/contracts/stream-writer.port.d.ts +0 -6
- package/dist/domain/types/index.d.ts +0 -1
- package/dist/domain/types/options.type.d.ts +0 -11
- package/dist/domain/types/options.type.js +0 -5
- package/dist/domain/value-objects/file-name-pattern.vo.d.ts +0 -4
- package/dist/domain/value-objects/file-name-pattern.vo.js +0 -14
- package/dist/domain/value-objects/rotation-policy.vo.d.ts +0 -7
- package/dist/domain/value-objects/rotation-policy.vo.js +0 -20
- package/dist/infrastructure/datasources/fs.datasource.d.ts +0 -17
- package/dist/infrastructure/datasources/fs.datasource.js +0 -84
- package/dist/infrastructure/datasources/index.d.ts +0 -1
- package/dist/infrastructure/fs/file-rotator.adapter.d.ts +0 -22
- package/dist/infrastructure/fs/file-rotator.adapter.js +0 -51
- package/dist/infrastructure/fs/fs-provider.d.ts +0 -15
- package/dist/infrastructure/fs/fs-writer.adapter.d.ts +0 -10
- package/dist/infrastructure/fs/fs-writer.adapter.js +0 -26
- package/dist/infrastructure/fs/node-clock.adapter.d.ts +0 -4
- package/dist/infrastructure/fs/path-utils.d.ts +0 -6
- package/dist/infrastructure/fs/path-utils.js +0 -26
- package/dist/presentation/factory/create-fs-datasource.d.ts +0 -15
- package/dist/presentation/factory/create-fs-datasource.js +0 -39
- package/dist/presentation/factory/index.d.ts +0 -1
- /package/dist/{domain/contracts/clock.contract.js → application/dto/rotation-check.dto.js} +0 -0
- /package/dist/{domain/contracts/file-rotator.contract.js → application/dto/write-operation.dto.js} +0 -0
- /package/dist/domain/{contracts/serializer.contract.js → ports/clock.port.js} +0 -0
- /package/dist/domain/{contracts/stream-writer.port.js → ports/file-path-adapter.port.js} +0 -0
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Utilidades puras de path y formateo de nombre.
|
|
3
|
-
// Cambiamos a getters UTC para evitar desfaces por huso horario.
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.formatPattern = formatPattern;
|
|
6
|
-
exports.splitBaseExt = splitBaseExt;
|
|
7
|
-
exports.joinBase = joinBase;
|
|
8
|
-
const path_1 = require("path");
|
|
9
|
-
function formatPattern(pattern, now) {
|
|
10
|
-
// Usar UTC para que "2025-09-09T00:00:00Z" siga siendo 2025-09-09
|
|
11
|
-
const yyyy = now.getUTCFullYear().toString();
|
|
12
|
-
const MM = String(now.getUTCMonth() + 1).padStart(2, "0");
|
|
13
|
-
const dd = String(now.getUTCDate()).padStart(2, "0");
|
|
14
|
-
return pattern
|
|
15
|
-
.replace("{yyyy}", yyyy)
|
|
16
|
-
.replace("{MM}", MM)
|
|
17
|
-
.replace("{dd}", dd);
|
|
18
|
-
}
|
|
19
|
-
function splitBaseExt(fileName) {
|
|
20
|
-
const ext = (0, path_1.extname)(fileName);
|
|
21
|
-
const base = ext ? (0, path_1.basename)(fileName, ext) : fileName;
|
|
22
|
-
return { base, ext };
|
|
23
|
-
}
|
|
24
|
-
function joinBase(basePath, fileName) {
|
|
25
|
-
return (0, path_1.join)(basePath, fileName);
|
|
26
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { FsDatasourceService } from "../../application/services";
|
|
2
|
-
import type { IFsSerializer } from "../../domain/contracts";
|
|
3
|
-
export declare function createFsDatasource(input: {
|
|
4
|
-
basePath: string;
|
|
5
|
-
mkdir?: boolean;
|
|
6
|
-
fileNamePattern?: string;
|
|
7
|
-
rotation?: {
|
|
8
|
-
by: "none" | "day" | "size";
|
|
9
|
-
maxSizeMB?: number;
|
|
10
|
-
maxFiles?: number;
|
|
11
|
-
};
|
|
12
|
-
serializer?: IFsSerializer;
|
|
13
|
-
onRotate?: (oldPath: string, newPath: string) => void | Promise<void>;
|
|
14
|
-
onError?: (err: unknown) => void | Promise<void>;
|
|
15
|
-
}): FsDatasourceService;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Ensambla el servicio de aplicación (que implementa ILogDatasource)
|
|
3
|
-
// con los adaptadores de infraestructura. Aquí no hay lógica de negocio,
|
|
4
|
-
// sólo wiring + defaults.
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createFsDatasource = createFsDatasource;
|
|
7
|
-
const services_1 = require("../../application/services");
|
|
8
|
-
const use_cases_1 = require("../../application/use-cases");
|
|
9
|
-
const value_objects_1 = require("../../domain/value-objects");
|
|
10
|
-
const fs_1 = require("../../infrastructure/fs");
|
|
11
|
-
function createFsDatasource(input) {
|
|
12
|
-
// 1) Defaults de VO y opciones
|
|
13
|
-
const pattern = new value_objects_1.FileNamePattern(input.fileNamePattern ?? "app-{yyyy}{MM}{dd}.log");
|
|
14
|
-
const rotation = input.rotation
|
|
15
|
-
? new value_objects_1.RotationPolicy(input.rotation.by, input.rotation.maxSizeMB, input.rotation.maxFiles)
|
|
16
|
-
: new value_objects_1.RotationPolicy("day");
|
|
17
|
-
const opts = {
|
|
18
|
-
basePath: input.basePath,
|
|
19
|
-
mkdir: !!input.mkdir,
|
|
20
|
-
pattern,
|
|
21
|
-
rotation,
|
|
22
|
-
serializer: input.serializer ?? { serialize: (x) => JSON.stringify(x) },
|
|
23
|
-
onRotate: input.onRotate,
|
|
24
|
-
onError: input.onError,
|
|
25
|
-
};
|
|
26
|
-
// 2) Adapters de infraestructura
|
|
27
|
-
const fs = (0, fs_1.createFsProvider)();
|
|
28
|
-
const clock = new fs_1.NodeClockAdapter();
|
|
29
|
-
const rotator = new fs_1.FileRotatorAdapter(fs, opts.basePath, clock, opts.pattern, !!opts.mkdir);
|
|
30
|
-
// 3) Casos de uso (application)
|
|
31
|
-
const rotateUC = new use_cases_1.RotateIfNeededUseCase(opts.rotation, rotator, clock);
|
|
32
|
-
const appendUC = new use_cases_1.AppendLogUseCase(opts.serializer);
|
|
33
|
-
// 4) Factory para abrir writers en el path que diga el rotator
|
|
34
|
-
const openWriter = (path) => new fs_1.FsWriterAdapter(fs, path);
|
|
35
|
-
// 5) Orquestador principal (application) que usará core: ILogDatasource
|
|
36
|
-
const persistUC = new use_cases_1.PersistLogUseCase(rotateUC, appendUC, rotator, openWriter, opts.onRotate, opts.onError);
|
|
37
|
-
// 6) Servicio que implementa ILogDatasource (core)
|
|
38
|
-
return new services_1.FsDatasourceService(persistUC);
|
|
39
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./create-fs-datasource";
|
|
File without changes
|
/package/dist/{domain/contracts/file-rotator.contract.js → application/dto/write-operation.dto.js}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|