backlib 0.5.0 → 0.5.2-SNAPSHOT.1
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/dist/log-file-writer.d.ts +10 -3
- package/dist/log-file-writer.js +33 -7
- package/dist/log-file-writer.js.map +1 -1
- package/package.json +1 -1
- package/src/log-file-writer.ts +46 -11
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { LogWriter } from './index.js';
|
|
2
|
-
export declare type OnFileCompleted = (file: string) => Promise<void>;
|
|
3
2
|
export declare type FileNameProvider = (rev: number) => string;
|
|
3
|
+
export declare type FileHeaderProvider = () => string | null;
|
|
4
|
+
export declare type OnFileCompleted = (file: string) => Promise<void>;
|
|
4
5
|
/** Record serializer to string, which will be appended to the file. If null, record will be skipped */
|
|
5
6
|
export declare type RecordSerializer<R> = (rec: R) => string | null;
|
|
6
7
|
export interface FileWriterOptions<R> {
|
|
@@ -12,7 +13,11 @@ export interface FileWriterOptions<R> {
|
|
|
12
13
|
maxTime: number;
|
|
13
14
|
/** Optional fileName generator for the new log file name (MUST BE UNIQUE for this dir) */
|
|
14
15
|
fileNameProvider?: FileNameProvider;
|
|
16
|
+
/** Called when the log file is first created (useful to create the csv header for csv format) */
|
|
17
|
+
fileHeaderProvider?: FileHeaderProvider;
|
|
18
|
+
/** Optional recordSerializer to file. By default, JSON.serializer() (new line json) */
|
|
15
19
|
recordSerializer?: RecordSerializer<R>;
|
|
20
|
+
/** Called when a log file is completed (i.e., new entries will go to another file) */
|
|
16
21
|
onFileCompleted?: OnFileCompleted;
|
|
17
22
|
}
|
|
18
23
|
export declare class FileWriter<R> implements LogWriter<R> {
|
|
@@ -20,6 +25,7 @@ export declare class FileWriter<R> implements LogWriter<R> {
|
|
|
20
25
|
private maxCount;
|
|
21
26
|
private maxTime;
|
|
22
27
|
private fileNameProvider;
|
|
28
|
+
private fileHeaderProvider;
|
|
23
29
|
private recordSerializer;
|
|
24
30
|
private onFileCompleted?;
|
|
25
31
|
private _init;
|
|
@@ -27,10 +33,11 @@ export declare class FileWriter<R> implements LogWriter<R> {
|
|
|
27
33
|
private count;
|
|
28
34
|
private nextUpload;
|
|
29
35
|
private lastUpload?;
|
|
30
|
-
private
|
|
36
|
+
private filePath?;
|
|
37
|
+
private fileHandle?;
|
|
31
38
|
constructor(opts: FileWriterOptions<R>);
|
|
32
39
|
private init;
|
|
33
|
-
/** Update the revision file */
|
|
40
|
+
/** Update the revision file and create the new file and call onFileStart */
|
|
34
41
|
private rev;
|
|
35
42
|
/** IMPLEMENTATION of the FileWriter interface */
|
|
36
43
|
writeRec(rec: R): Promise<void>;
|
package/dist/log-file-writer.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { appendFileSync, openSync } from 'fs';
|
|
1
2
|
import { pathExists } from 'fs-aux';
|
|
2
|
-
import { appendFile, mkdir, rename } from 'fs/promises';
|
|
3
|
+
import { appendFile, mkdir, open, rename } from 'fs/promises';
|
|
3
4
|
import * as Path from "path";
|
|
4
5
|
import { isString } from 'utils-min';
|
|
5
6
|
export class FileWriter {
|
|
@@ -12,6 +13,7 @@ export class FileWriter {
|
|
|
12
13
|
this.maxTime = opts.maxTime;
|
|
13
14
|
this.dir = opts.dir;
|
|
14
15
|
this.fileNameProvider = opts.fileNameProvider ?? defaultFileNameProvider;
|
|
16
|
+
this.fileHeaderProvider = opts.fileHeaderProvider ?? defaultFileHeaderProvider;
|
|
15
17
|
this.onFileCompleted = opts.onFileCompleted;
|
|
16
18
|
this.recordSerializer = opts.recordSerializer ?? defaultSerializer;
|
|
17
19
|
}
|
|
@@ -22,12 +24,28 @@ export class FileWriter {
|
|
|
22
24
|
this._init = true;
|
|
23
25
|
}
|
|
24
26
|
}
|
|
25
|
-
/** Update the revision file */
|
|
26
|
-
rev() {
|
|
27
|
+
/** Update the revision file and create the new file and call onFileStart */
|
|
28
|
+
async rev() {
|
|
27
29
|
this.count = 0;
|
|
28
30
|
this._rev = this._rev + 1;
|
|
31
|
+
// make sure to reset the file info
|
|
32
|
+
this.filePath = undefined;
|
|
33
|
+
this.fileHandle = undefined;
|
|
34
|
+
// -- CREATE the new file
|
|
29
35
|
const fileName = this.fileNameProvider(this._rev);
|
|
30
|
-
this.
|
|
36
|
+
this.filePath = Path.join(this.dir, fileName);
|
|
37
|
+
// create and add the content Sync to make sure header is always first
|
|
38
|
+
let fd = openSync(this.filePath, 'a');
|
|
39
|
+
let fileHeader = this.fileHeaderProvider();
|
|
40
|
+
if (fileHeader != null) {
|
|
41
|
+
appendFileSync(fd, fileHeader);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
// make sure it is created (might not be needed)
|
|
45
|
+
appendFileSync(fd, '');
|
|
46
|
+
}
|
|
47
|
+
// -- CREATE the file handler
|
|
48
|
+
this.fileHandle = await open(this.filePath, 'a');
|
|
31
49
|
}
|
|
32
50
|
/** IMPLEMENTATION of the FileWriter interface */
|
|
33
51
|
async writeRec(rec) {
|
|
@@ -37,7 +55,7 @@ export class FileWriter {
|
|
|
37
55
|
const str = this.recordSerializer(rec);
|
|
38
56
|
if (str != null) {
|
|
39
57
|
const strWithNl = str + '\n'; // add the new line
|
|
40
|
-
await appendFile(this.
|
|
58
|
+
await appendFile(this.fileHandle, strWithNl);
|
|
41
59
|
}
|
|
42
60
|
// add count
|
|
43
61
|
this.count = this.count + 1;
|
|
@@ -59,12 +77,15 @@ export class FileWriter {
|
|
|
59
77
|
}
|
|
60
78
|
}
|
|
61
79
|
async endFile() {
|
|
62
|
-
const file = this.
|
|
80
|
+
const file = this.filePath;
|
|
81
|
+
const fileHandle = this.fileHandle;
|
|
63
82
|
// we rev just before to make sure other logs will happen on new files
|
|
64
|
-
this.rev();
|
|
83
|
+
await this.rev();
|
|
84
|
+
// process old file
|
|
65
85
|
try {
|
|
66
86
|
const exists = await pathExists(file);
|
|
67
87
|
if (exists) {
|
|
88
|
+
await fileHandle?.close();
|
|
68
89
|
if (this.onFileCompleted) {
|
|
69
90
|
try {
|
|
70
91
|
await this.onFileCompleted(file);
|
|
@@ -92,6 +113,11 @@ export class FileWriter {
|
|
|
92
113
|
function defaultSerializer(rec) {
|
|
93
114
|
return isString(rec) ? rec : JSON.stringify(rec);
|
|
94
115
|
}
|
|
116
|
+
function defaultFileHeaderProvider() {
|
|
117
|
+
// Return null, meaning, no header
|
|
118
|
+
return null;
|
|
119
|
+
// For CSV, custom onFileStart will need to set the header
|
|
120
|
+
}
|
|
95
121
|
function defaultFileNameProvider(rev) {
|
|
96
122
|
const date = new Date().toISOString().replace(/[T:.]/g, "-").slice(0, -1);
|
|
97
123
|
const revStr = `${rev}`.padStart(5, '0');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log-file-writer.js","sourceRoot":"","sources":["../src/log-file-writer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"log-file-writer.js","sourceRoot":"","sources":["../src/log-file-writer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,UAAU,EAAc,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AA6BrC,MAAM,OAAO,UAAU;IAmBrB,YAAY,IAA0B;QAT9B,UAAK,GAAG,KAAK,CAAC;QACd,SAAI,GAAG,CAAC,CAAC;QACT,UAAK,GAAG,CAAC,CAAC;QACV,eAAU,GAAkB,IAAI,CAAC,CAAC,+BAA+B;QAOvE,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC9B,IAAI,CAAC,OAAO,GAAG,IAAI,CAA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;AACnD,CAAC;AAED,SAAS,yBAAyB;IAChC,kCAAkC;IAClC,OAAO,IAAI,CAAC;IAEZ,0DAA0D;AAC5D,CAAC;AAED,SAAS,uBAAuB,CAAC,GAAW;IAC1C,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC1E,MAAM,MAAM,GAAG,GAAG,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACzC,OAAO,YAAY,IAAI,IAAI,MAAM,MAAM,CAAC;AAC1C,CAAC"}
|
package/package.json
CHANGED
package/src/log-file-writer.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
import { appendFileSync, openSync } from 'fs';
|
|
1
2
|
import { pathExists } from 'fs-aux';
|
|
2
|
-
import { appendFile, mkdir, rename } from 'fs/promises';
|
|
3
|
+
import { appendFile, FileHandle, mkdir, open, rename } from 'fs/promises';
|
|
3
4
|
import * as Path from "path";
|
|
4
5
|
import { isString } from 'utils-min';
|
|
5
6
|
import { LogWriter } from './index.js';
|
|
6
7
|
|
|
7
|
-
export type OnFileCompleted = (file: string) => Promise<void>;
|
|
8
8
|
export type FileNameProvider = (rev: number) => string;
|
|
9
|
+
export type FileHeaderProvider = () => string | null; // must be sync
|
|
10
|
+
export type OnFileCompleted = (file: string) => Promise<void>;
|
|
9
11
|
|
|
10
12
|
/** Record serializer to string, which will be appended to the file. If null, record will be skipped */
|
|
11
13
|
export type RecordSerializer<R> = (rec: R) => string | null;
|
|
@@ -20,9 +22,11 @@ export interface FileWriterOptions<R> {
|
|
|
20
22
|
|
|
21
23
|
/** Optional fileName generator for the new log file name (MUST BE UNIQUE for this dir) */
|
|
22
24
|
fileNameProvider?: FileNameProvider,
|
|
23
|
-
|
|
25
|
+
/** Called when the log file is first created (useful to create the csv header for csv format) */
|
|
26
|
+
fileHeaderProvider?: FileHeaderProvider;
|
|
27
|
+
/** Optional recordSerializer to file. By default, JSON.serializer() (new line json) */
|
|
24
28
|
recordSerializer?: RecordSerializer<R>;
|
|
25
|
-
|
|
29
|
+
/** Called when a log file is completed (i.e., new entries will go to another file) */
|
|
26
30
|
onFileCompleted?: OnFileCompleted;
|
|
27
31
|
|
|
28
32
|
}
|
|
@@ -33,6 +37,7 @@ export class FileWriter<R> implements LogWriter<R> {
|
|
|
33
37
|
private maxTime: number;
|
|
34
38
|
|
|
35
39
|
private fileNameProvider: FileNameProvider;
|
|
40
|
+
private fileHeaderProvider: FileHeaderProvider;
|
|
36
41
|
private recordSerializer: RecordSerializer<R>;
|
|
37
42
|
private onFileCompleted?: OnFileCompleted;
|
|
38
43
|
|
|
@@ -42,13 +47,15 @@ export class FileWriter<R> implements LogWriter<R> {
|
|
|
42
47
|
private nextUpload: number | null = null; // null means nothing scheduled
|
|
43
48
|
private lastUpload?: number;
|
|
44
49
|
|
|
45
|
-
private
|
|
50
|
+
private filePath?: string;
|
|
51
|
+
private fileHandle?: FileHandle;
|
|
46
52
|
|
|
47
53
|
constructor(opts: FileWriterOptions<R>) {
|
|
48
54
|
this.maxCount = opts.maxCount;
|
|
49
55
|
this.maxTime = opts.maxTime;
|
|
50
56
|
this.dir = opts.dir;
|
|
51
57
|
this.fileNameProvider = opts.fileNameProvider ?? defaultFileNameProvider;
|
|
58
|
+
this.fileHeaderProvider = opts.fileHeaderProvider ?? defaultFileHeaderProvider;
|
|
52
59
|
this.onFileCompleted = opts.onFileCompleted;
|
|
53
60
|
this.recordSerializer = opts.recordSerializer ?? defaultSerializer;
|
|
54
61
|
}
|
|
@@ -61,14 +68,31 @@ export class FileWriter<R> implements LogWriter<R> {
|
|
|
61
68
|
}
|
|
62
69
|
}
|
|
63
70
|
|
|
64
|
-
/** Update the revision file */
|
|
65
|
-
private rev() {
|
|
71
|
+
/** Update the revision file and create the new file and call onFileStart */
|
|
72
|
+
private async rev() {
|
|
66
73
|
this.count = 0;
|
|
67
74
|
this._rev = this._rev + 1;
|
|
68
75
|
|
|
76
|
+
// make sure to reset the file info
|
|
77
|
+
this.filePath = undefined;
|
|
78
|
+
this.fileHandle = undefined;
|
|
79
|
+
|
|
80
|
+
// -- CREATE the new file
|
|
69
81
|
const fileName = this.fileNameProvider(this._rev);
|
|
82
|
+
this.filePath = Path.join(this.dir, fileName);
|
|
83
|
+
|
|
84
|
+
// create and add the content Sync to make sure header is always first
|
|
85
|
+
let fd = openSync(this.filePath, 'a');
|
|
86
|
+
let fileHeader = this.fileHeaderProvider();
|
|
87
|
+
if (fileHeader != null) {
|
|
88
|
+
appendFileSync(fd, fileHeader);
|
|
89
|
+
} else {
|
|
90
|
+
// make sure it is created (might not be needed)
|
|
91
|
+
appendFileSync(fd, '');
|
|
92
|
+
}
|
|
70
93
|
|
|
71
|
-
|
|
94
|
+
// -- CREATE the file handler
|
|
95
|
+
this.fileHandle = await open(this.filePath, 'a');
|
|
72
96
|
}
|
|
73
97
|
|
|
74
98
|
|
|
@@ -82,7 +106,7 @@ export class FileWriter<R> implements LogWriter<R> {
|
|
|
82
106
|
const str = this.recordSerializer(rec);
|
|
83
107
|
if (str != null) {
|
|
84
108
|
const strWithNl = str + '\n'; // add the new line
|
|
85
|
-
await appendFile(this.
|
|
109
|
+
await appendFile(this.fileHandle!, strWithNl);
|
|
86
110
|
}
|
|
87
111
|
|
|
88
112
|
// add count
|
|
@@ -110,13 +134,17 @@ export class FileWriter<R> implements LogWriter<R> {
|
|
|
110
134
|
}
|
|
111
135
|
|
|
112
136
|
private async endFile() {
|
|
113
|
-
const file = this.
|
|
137
|
+
const file = this.filePath!;
|
|
138
|
+
const fileHandle = this.fileHandle;
|
|
139
|
+
|
|
114
140
|
// we rev just before to make sure other logs will happen on new files
|
|
115
|
-
this.rev();
|
|
141
|
+
await this.rev();
|
|
116
142
|
|
|
143
|
+
// process old file
|
|
117
144
|
try {
|
|
118
145
|
const exists = await pathExists(file);
|
|
119
146
|
if (exists) {
|
|
147
|
+
await fileHandle?.close();
|
|
120
148
|
if (this.onFileCompleted) {
|
|
121
149
|
try {
|
|
122
150
|
await this.onFileCompleted(file);
|
|
@@ -148,6 +176,13 @@ function defaultSerializer<R>(rec: R): string {
|
|
|
148
176
|
return isString(rec) ? rec : JSON.stringify(rec);
|
|
149
177
|
}
|
|
150
178
|
|
|
179
|
+
function defaultFileHeaderProvider(): string | null {
|
|
180
|
+
// Return null, meaning, no header
|
|
181
|
+
return null;
|
|
182
|
+
|
|
183
|
+
// For CSV, custom onFileStart will need to set the header
|
|
184
|
+
}
|
|
185
|
+
|
|
151
186
|
function defaultFileNameProvider(rev: number): string {
|
|
152
187
|
const date = new Date().toISOString().replace(/[T:.]/g, "-").slice(0, -1);
|
|
153
188
|
const revStr = `${rev}`.padStart(5, '0');
|