backlib 0.5.0-SNAPSHOT.1 → 0.5.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.
- package/dist/log-file-writer.d.ts +0 -1
- package/dist/log-file-writer.js +0 -4
- package/dist/log-file-writer.js.map +1 -1
- package/dist/log.d.ts +2 -2
- package/dist/log.js +18 -6
- package/dist/log.js.map +1 -1
- package/package.json +1 -1
- package/src/log-file-writer.ts +0 -4
- package/src/log.ts +5 -6
package/dist/log-file-writer.js
CHANGED
|
@@ -4,7 +4,6 @@ import * as Path from "path";
|
|
|
4
4
|
import { isString } from 'utils-min';
|
|
5
5
|
export class FileWriter {
|
|
6
6
|
constructor(opts) {
|
|
7
|
-
this.name = 'to-deprecate'; // TODO: to deprecate
|
|
8
7
|
this._init = false;
|
|
9
8
|
this._rev = 0;
|
|
10
9
|
this.count = 0;
|
|
@@ -44,7 +43,6 @@ export class FileWriter {
|
|
|
44
43
|
this.count = this.count + 1;
|
|
45
44
|
// if we are above the count, we upload
|
|
46
45
|
if (this.count > this.maxCount) {
|
|
47
|
-
console.log(`->> rev ${this.name} because count ${this.count} > maxCount ${this.maxCount}`);
|
|
48
46
|
await this.endFile();
|
|
49
47
|
}
|
|
50
48
|
// if still below the count, but do not have this.nextUpload, schedule one
|
|
@@ -55,7 +53,6 @@ export class FileWriter {
|
|
|
55
53
|
setTimeout(async () => {
|
|
56
54
|
// perform only if this.nextUpload match the scheduled nextUpload (otherwise, was already processed and this schedule is outdated)
|
|
57
55
|
if (this.nextUpload === nextUpload) {
|
|
58
|
-
console.log(`->> rev ${this.name} because maxTimeMs ${maxTimeMs}`);
|
|
59
56
|
await this.endFile();
|
|
60
57
|
}
|
|
61
58
|
}, maxTimeMs);
|
|
@@ -70,7 +67,6 @@ export class FileWriter {
|
|
|
70
67
|
if (exists) {
|
|
71
68
|
if (this.onFileCompleted) {
|
|
72
69
|
try {
|
|
73
|
-
console.log(`->> endFile processing ${this.name} `);
|
|
74
70
|
await this.onFileCompleted(file);
|
|
75
71
|
}
|
|
76
72
|
catch (ex) {
|
|
@@ -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,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AA0BrC,MAAM,OAAO,UAAU;
|
|
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,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AA0BrC,MAAM,OAAO,UAAU;IAiBrB,YAAY,IAA0B;QAR9B,UAAK,GAAG,KAAK,CAAC;QACd,SAAI,GAAG,CAAC,CAAC;QACT,UAAK,GAAG,CAAC,CAAC;QACV,eAAU,GAAkB,IAAI,CAAC,CAAC,+BAA+B;QAMvE,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC9B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC5B,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;QACpB,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,IAAI,uBAAuB,CAAC;QACzE,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;QAC5C,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,gBAAgB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E,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;IACzB,CAAC;CAEF;AAED,yBAAyB;AAEzB,SAAS,iBAAiB,CAAI,GAAM;IAClC,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;AACnD,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/dist/log.d.ts
CHANGED
|
@@ -2,10 +2,10 @@ export interface LogOptions<R> {
|
|
|
2
2
|
writers: LogWriter<R>[];
|
|
3
3
|
}
|
|
4
4
|
/**
|
|
5
|
-
* Base Log class that handle the
|
|
5
|
+
* Base Log class that handle the log management logic and call `writer.writeRec` on the registered logWriters
|
|
6
6
|
*/
|
|
7
7
|
export declare class BaseLog<R> {
|
|
8
|
-
private
|
|
8
|
+
#private;
|
|
9
9
|
constructor(opts: LogOptions<R>);
|
|
10
10
|
log(rec: R): Promise<void>;
|
|
11
11
|
}
|
package/dist/log.js
CHANGED
|
@@ -1,25 +1,37 @@
|
|
|
1
1
|
// const { pathExists, mkdirs, appendFile, rename } = (await import('fs-extra')).default;
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _BaseLog_logWriters;
|
|
2
14
|
/**
|
|
3
|
-
* Base Log class that handle the
|
|
15
|
+
* Base Log class that handle the log management logic and call `writer.writeRec` on the registered logWriters
|
|
4
16
|
*/
|
|
5
17
|
export class BaseLog {
|
|
6
18
|
constructor(opts) {
|
|
7
|
-
this
|
|
8
|
-
this
|
|
19
|
+
_BaseLog_logWriters.set(this, []);
|
|
20
|
+
__classPrivateFieldSet(this, _BaseLog_logWriters, [...opts.writers], "f");
|
|
9
21
|
}
|
|
10
22
|
async log(rec) {
|
|
11
|
-
|
|
12
|
-
for (const writer of this.logWriters) {
|
|
23
|
+
for (const writer of __classPrivateFieldGet(this, _BaseLog_logWriters, "f")) {
|
|
13
24
|
if (writer.writeRec) {
|
|
14
25
|
try {
|
|
15
26
|
await writer.writeRec(rec);
|
|
16
27
|
}
|
|
17
28
|
catch (ex) {
|
|
18
29
|
// here log console.log, no choise
|
|
19
|
-
console.log(`ERROR - BACKLIB - Log exception when writeRec on logWriter ${writer}. ${ex}`);
|
|
30
|
+
console.log(`ERROR - BACKLIB - Log exception when calling writeRec on logWriter ${writer}. ${ex}`);
|
|
20
31
|
}
|
|
21
32
|
}
|
|
22
33
|
}
|
|
23
34
|
}
|
|
24
35
|
}
|
|
36
|
+
_BaseLog_logWriters = new WeakMap();
|
|
25
37
|
//# sourceMappingURL=log.js.map
|
package/dist/log.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.js","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AACA,yFAAyF
|
|
1
|
+
{"version":3,"file":"log.js","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AACA,yFAAyF;;;;;;;;;;;;;AAQzF;;GAEG;AACH,MAAM,OAAO,OAAO;IAGnB,YAAY,IAAmB;QAF/B,8BAA8B,EAAE,EAAC;QAGhC,uBAAA,IAAI,uBAAe,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,MAAA,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAM;QAEf,KAAK,MAAM,MAAM,IAAI,uBAAA,IAAI,2BAAY,EAAE;YACtC,IAAI,MAAM,CAAC,QAAQ,EAAE;gBACpB,IAAI;oBACH,MAAM,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;iBAC3B;gBAAC,OAAO,EAAE,EAAE;oBACZ,kCAAkC;oBAClC,OAAO,CAAC,GAAG,CAAC,sEAAsE,MAAM,KAAK,EAAE,EAAE,CAAC,CAAC;iBACnG;aACD;SACD;IAEF,CAAC;CAED"}
|
package/package.json
CHANGED
package/src/log-file-writer.ts
CHANGED
|
@@ -28,7 +28,6 @@ export interface FileWriterOptions<R> {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
export class FileWriter<R> implements LogWriter<R> {
|
|
31
|
-
readonly name = 'to-deprecate'; // TODO: to deprecate
|
|
32
31
|
private dir: string;
|
|
33
32
|
private maxCount: number;
|
|
34
33
|
private maxTime: number;
|
|
@@ -91,7 +90,6 @@ export class FileWriter<R> implements LogWriter<R> {
|
|
|
91
90
|
|
|
92
91
|
// if we are above the count, we upload
|
|
93
92
|
if (this.count > this.maxCount) {
|
|
94
|
-
console.log(`->> rev ${this.name} because count ${this.count} > maxCount ${this.maxCount}`);
|
|
95
93
|
await this.endFile();
|
|
96
94
|
}
|
|
97
95
|
// if still below the count, but do not have this.nextUpload, schedule one
|
|
@@ -104,7 +102,6 @@ export class FileWriter<R> implements LogWriter<R> {
|
|
|
104
102
|
setTimeout(async () => {
|
|
105
103
|
// perform only if this.nextUpload match the scheduled nextUpload (otherwise, was already processed and this schedule is outdated)
|
|
106
104
|
if (this.nextUpload === nextUpload) {
|
|
107
|
-
console.log(`->> rev ${this.name} because maxTimeMs ${maxTimeMs}`);
|
|
108
105
|
await this.endFile();
|
|
109
106
|
}
|
|
110
107
|
}, maxTimeMs);
|
|
@@ -122,7 +119,6 @@ export class FileWriter<R> implements LogWriter<R> {
|
|
|
122
119
|
if (exists) {
|
|
123
120
|
if (this.onFileCompleted) {
|
|
124
121
|
try {
|
|
125
|
-
console.log(`->> endFile processing ${this.name} `);
|
|
126
122
|
await this.onFileCompleted(file);
|
|
127
123
|
} catch (ex: any) {
|
|
128
124
|
console.log(`LOG PROCESSING ERROR - processing file '${file}' caused the following error: ${ex}`);
|
package/src/log.ts
CHANGED
|
@@ -8,25 +8,24 @@ export interface LogOptions<R> {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* Base Log class that handle the
|
|
11
|
+
* Base Log class that handle the log management logic and call `writer.writeRec` on the registered logWriters
|
|
12
12
|
*/
|
|
13
13
|
export class BaseLog<R> {
|
|
14
|
-
|
|
14
|
+
#logWriters: LogWriter<R>[] = [];
|
|
15
15
|
|
|
16
16
|
constructor(opts: LogOptions<R>) {
|
|
17
|
-
this
|
|
17
|
+
this.#logWriters = [...opts.writers];
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
async log(rec: R) {
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
for (const writer of this.logWriters) {
|
|
22
|
+
for (const writer of this.#logWriters) {
|
|
24
23
|
if (writer.writeRec) {
|
|
25
24
|
try {
|
|
26
25
|
await writer.writeRec(rec);
|
|
27
26
|
} catch (ex) {
|
|
28
27
|
// here log console.log, no choise
|
|
29
|
-
console.log(`ERROR - BACKLIB - Log exception when writeRec on logWriter ${writer}. ${ex}`);
|
|
28
|
+
console.log(`ERROR - BACKLIB - Log exception when calling writeRec on logWriter ${writer}. ${ex}`);
|
|
30
29
|
}
|
|
31
30
|
}
|
|
32
31
|
}
|