@jmlq/logger-plugin-fs 0.1.0-alpha.0

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.
@@ -0,0 +1,11 @@
1
+ import { ILogDatasource, Log } from "@jmlq/logger";
2
+ export declare class FileSystemDatasource implements ILogDatasource {
3
+ private readonly opts;
4
+ private fd?;
5
+ constructor(opts: {
6
+ filePath: string;
7
+ });
8
+ private ensureOpen;
9
+ save(log: Log): Promise<void>;
10
+ dispose(): Promise<void>;
11
+ }
package/dist/index.js ADDED
@@ -0,0 +1,63 @@
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.FileSystemDatasource = void 0;
37
+ const fs_1 = require("fs");
38
+ const path = __importStar(require("path"));
39
+ class FileSystemDatasource {
40
+ constructor(opts) {
41
+ this.opts = opts;
42
+ }
43
+ async ensureOpen() {
44
+ if (!this.fd) {
45
+ await fs_1.promises.mkdir(path.dirname(this.opts.filePath), { recursive: true });
46
+ this.fd = await fs_1.promises
47
+ .open(this.opts.filePath, "a")
48
+ .then((f) => f.fd);
49
+ }
50
+ }
51
+ async save(log) {
52
+ await this.ensureOpen();
53
+ const line = JSON.stringify(log) + "\n";
54
+ await fs_1.promises.appendFile(this.opts.filePath, line, "utf8");
55
+ }
56
+ async dispose() {
57
+ if (this.fd) {
58
+ await fs_1.promises.close(this.fd);
59
+ this.fd = undefined;
60
+ }
61
+ }
62
+ }
63
+ exports.FileSystemDatasource = FileSystemDatasource;
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@jmlq/logger-plugin-fs",
3
+ "version": "0.1.0-alpha.0",
4
+ "author": "MLahuasi",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "scripts": {
11
+ "build": "tsc -p tsconfig.json",
12
+ "prepublishOnly": "pnpm build"
13
+ },
14
+ "devDependencies": {
15
+ "@types/node": "^24.3.0",
16
+ "tsx": "^4.20.5",
17
+ "typescript": "^5.9.2"
18
+ },
19
+ "peerDependencies": {
20
+ "@jmlq/logger": "^0.1.0-alpha.0"
21
+ }
22
+ }