scheduler-node-models 1.2.6 → 1.2.8
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/general/index.d.ts +1 -0
- package/general/index.js +1 -0
- package/general/logger.d.ts +1 -0
- package/general/logger.js +8 -1
- package/general/logs.d.ts +58 -0
- package/general/logs.js +83 -0
- package/package.json +1 -1
package/general/index.d.ts
CHANGED
package/general/index.js
CHANGED
package/general/logger.d.ts
CHANGED
package/general/logger.js
CHANGED
|
@@ -46,12 +46,14 @@ class Logger {
|
|
|
46
46
|
this.interval = setInterval(() => this.flush(), flushInterval);
|
|
47
47
|
}
|
|
48
48
|
log(message) {
|
|
49
|
-
|
|
49
|
+
const now = new Date();
|
|
50
|
+
this.buffer.push(`${now.getTime()}\t${message}`);
|
|
50
51
|
}
|
|
51
52
|
flush() {
|
|
52
53
|
if (this.buffer.length > 0) {
|
|
53
54
|
const logLines = this.buffer.join('\n') + '\n';
|
|
54
55
|
this.logFile = this.logFile.replaceAll(' ', '_');
|
|
56
|
+
this.createDirIfNotExists(this.logFile);
|
|
55
57
|
try {
|
|
56
58
|
const tf = fs.open(this.logFile, (err) => {
|
|
57
59
|
if (err) {
|
|
@@ -86,5 +88,10 @@ class Logger {
|
|
|
86
88
|
clearInterval(this.interval);
|
|
87
89
|
this.flush();
|
|
88
90
|
}
|
|
91
|
+
createDirIfNotExists(directoryPath) {
|
|
92
|
+
if (!fs.existsSync(directoryPath)) {
|
|
93
|
+
fs.mkdirSync(directoryPath, { recursive: true });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
89
96
|
}
|
|
90
97
|
exports.Logger = Logger;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This interface will provide the requirements of a log entry
|
|
3
|
+
*/
|
|
4
|
+
export interface ILogEntry {
|
|
5
|
+
date: Date;
|
|
6
|
+
entry: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* This class definition implements the log entry interface as an object
|
|
10
|
+
* which can be sorted in order.
|
|
11
|
+
*/
|
|
12
|
+
export declare class LogEntry implements ILogEntry {
|
|
13
|
+
date: Date;
|
|
14
|
+
entry: string;
|
|
15
|
+
constructor(entry?: ILogEntry);
|
|
16
|
+
/**
|
|
17
|
+
* This method will be used in sorting and comparisons in general
|
|
18
|
+
* @param other (optional) a log entry object used in comparision
|
|
19
|
+
* @returns a numeric value to indicate whether this log entry is before
|
|
20
|
+
* or after based on log entry date.
|
|
21
|
+
*/
|
|
22
|
+
compareTo(other?: LogEntry): number;
|
|
23
|
+
/**
|
|
24
|
+
* This method will provide a string value from this entry.
|
|
25
|
+
* @returns a string value having the date/time - entry value.
|
|
26
|
+
*/
|
|
27
|
+
toString(): string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* This interface will define the requirements for a log with name and entry
|
|
31
|
+
*/
|
|
32
|
+
export interface ILog {
|
|
33
|
+
name: string;
|
|
34
|
+
entries: ILogEntry[];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* This class implements the log containing a name and a series of entries. The
|
|
38
|
+
* entries are sorted in reverse order with newest first.
|
|
39
|
+
*/
|
|
40
|
+
export declare class Log implements ILog {
|
|
41
|
+
name: string;
|
|
42
|
+
entries: LogEntry[];
|
|
43
|
+
constructor(log?: ILog);
|
|
44
|
+
/**
|
|
45
|
+
* This method is used to compare this object with another one.
|
|
46
|
+
* @param other (optional) the log object to use in comparision
|
|
47
|
+
* @returns a numeric value to indicate whether this log is before or after
|
|
48
|
+
* by name.
|
|
49
|
+
*/
|
|
50
|
+
compareTo(other?: Log): number;
|
|
51
|
+
}
|
|
52
|
+
export interface ILogList {
|
|
53
|
+
logs: ILog[];
|
|
54
|
+
}
|
|
55
|
+
export declare class LogList implements ILogList {
|
|
56
|
+
logs: Log[];
|
|
57
|
+
constructor(ls?: ILogList);
|
|
58
|
+
}
|
package/general/logs.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LogList = exports.Log = exports.LogEntry = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* This class definition implements the log entry interface as an object
|
|
6
|
+
* which can be sorted in order.
|
|
7
|
+
*/
|
|
8
|
+
class LogEntry {
|
|
9
|
+
date;
|
|
10
|
+
entry;
|
|
11
|
+
constructor(entry) {
|
|
12
|
+
this.date = (entry) ? new Date(entry.date) : new Date();
|
|
13
|
+
this.entry = (entry) ? entry.entry : '';
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* This method will be used in sorting and comparisons in general
|
|
17
|
+
* @param other (optional) a log entry object used in comparision
|
|
18
|
+
* @returns a numeric value to indicate whether this log entry is before
|
|
19
|
+
* or after based on log entry date.
|
|
20
|
+
*/
|
|
21
|
+
compareTo(other) {
|
|
22
|
+
if (other) {
|
|
23
|
+
return (this.date.getTime() < other.date.getTime()) ? -1 : 1;
|
|
24
|
+
}
|
|
25
|
+
return -1;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* This method will provide a string value from this entry.
|
|
29
|
+
* @returns a string value having the date/time - entry value.
|
|
30
|
+
*/
|
|
31
|
+
toString() {
|
|
32
|
+
const formatter = new Intl.DateTimeFormat('en-US', {
|
|
33
|
+
dateStyle: 'short',
|
|
34
|
+
timeStyle: 'short'
|
|
35
|
+
});
|
|
36
|
+
return `${formatter.format(this.date)} - ${this.entry}`;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.LogEntry = LogEntry;
|
|
40
|
+
/**
|
|
41
|
+
* This class implements the log containing a name and a series of entries. The
|
|
42
|
+
* entries are sorted in reverse order with newest first.
|
|
43
|
+
*/
|
|
44
|
+
class Log {
|
|
45
|
+
name;
|
|
46
|
+
entries;
|
|
47
|
+
constructor(log) {
|
|
48
|
+
this.name = (log) ? log.name : '';
|
|
49
|
+
this.entries = [];
|
|
50
|
+
if (log && log.entries.length > 0) {
|
|
51
|
+
log.entries.forEach(entry => {
|
|
52
|
+
this.entries.push(new LogEntry(entry));
|
|
53
|
+
});
|
|
54
|
+
this.entries.sort((a, b) => b.compareTo(a));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* This method is used to compare this object with another one.
|
|
59
|
+
* @param other (optional) the log object to use in comparision
|
|
60
|
+
* @returns a numeric value to indicate whether this log is before or after
|
|
61
|
+
* by name.
|
|
62
|
+
*/
|
|
63
|
+
compareTo(other) {
|
|
64
|
+
if (other) {
|
|
65
|
+
return (this.name.toLowerCase() < other.name.toLowerCase()) ? -1 : 1;
|
|
66
|
+
}
|
|
67
|
+
return -1;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.Log = Log;
|
|
71
|
+
class LogList {
|
|
72
|
+
logs;
|
|
73
|
+
constructor(ls) {
|
|
74
|
+
this.logs = [];
|
|
75
|
+
if (ls && ls.logs.length > 0) {
|
|
76
|
+
ls.logs.forEach(lg => {
|
|
77
|
+
this.logs.push(new Log(lg));
|
|
78
|
+
});
|
|
79
|
+
this.logs.sort((a, b) => a.compareTo(b));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.LogList = LogList;
|