@nu-art/ts-common 0.204.2 → 0.204.4
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/core/logger/LogClient_File.d.ts +11 -0
- package/core/logger/LogClient_File.js +80 -0
- package/core/logger/LogClient_MemBuffer.d.ts +3 -1
- package/core/logger/LogClient_MemBuffer.js +7 -2
- package/modules/CSVModule.js +24 -1
- package/modules/CSVModuleV3.js +24 -1
- package/modules/JSONCSVModule.js +24 -1
- package/package.json +1 -1
- package/utils/date-time-tools.js +8 -5
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { LogClient_BaseRotate } from './LogClient_BaseRotate';
|
|
2
|
+
export declare class LogClient_File extends LogClient_BaseRotate {
|
|
3
|
+
private pathToFolder;
|
|
4
|
+
private buffer;
|
|
5
|
+
constructor(name: string, pathToFolder: string, maxEntries?: number, maxSize?: number);
|
|
6
|
+
private getFileName;
|
|
7
|
+
protected printLogMessage(log: string): void;
|
|
8
|
+
protected rotateBuffer(fromIndex: number, toIndex: number): void;
|
|
9
|
+
protected cleanup(): void;
|
|
10
|
+
protected prepare(): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Permissions management system, define access level for each of
|
|
4
|
+
* your server apis, and restrict users by giving them access levels
|
|
5
|
+
*
|
|
6
|
+
* Copyright (C) 2020 Adam van der Kruk aka TacB0sS
|
|
7
|
+
*
|
|
8
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
* you may not use this file except in compliance with the License.
|
|
10
|
+
* You may obtain a copy of the License at
|
|
11
|
+
*
|
|
12
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
+
*
|
|
14
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
15
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
+
* See the License for the specific language governing permissions and
|
|
18
|
+
* limitations under the License.
|
|
19
|
+
*/
|
|
20
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
23
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
24
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
25
|
+
}
|
|
26
|
+
Object.defineProperty(o, k2, desc);
|
|
27
|
+
}) : (function(o, m, k, k2) {
|
|
28
|
+
if (k2 === undefined) k2 = k;
|
|
29
|
+
o[k2] = m[k];
|
|
30
|
+
}));
|
|
31
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
32
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
33
|
+
}) : function(o, v) {
|
|
34
|
+
o["default"] = v;
|
|
35
|
+
});
|
|
36
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
37
|
+
if (mod && mod.__esModule) return mod;
|
|
38
|
+
var result = {};
|
|
39
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
40
|
+
__setModuleDefault(result, mod);
|
|
41
|
+
return result;
|
|
42
|
+
};
|
|
43
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
+
exports.LogClient_File = void 0;
|
|
45
|
+
const fs = __importStar(require("fs"));
|
|
46
|
+
const LogClient_BaseRotate_1 = require("./LogClient_BaseRotate");
|
|
47
|
+
class LogClient_File extends LogClient_BaseRotate_1.LogClient_BaseRotate {
|
|
48
|
+
constructor(name, pathToFolder, maxEntries = 10, maxSize = 1024 * 1024) {
|
|
49
|
+
super(name, maxEntries, maxSize);
|
|
50
|
+
this.pathToFolder = pathToFolder;
|
|
51
|
+
if (!fs.existsSync(pathToFolder))
|
|
52
|
+
fs.mkdirSync(pathToFolder, { recursive: true });
|
|
53
|
+
const defaultLogfile = this.getFileName();
|
|
54
|
+
if (fs.existsSync(defaultLogfile))
|
|
55
|
+
this.bufferSize = fs.statSync(`${defaultLogfile}`).size;
|
|
56
|
+
this.prepare();
|
|
57
|
+
}
|
|
58
|
+
getFileName(index = 0) {
|
|
59
|
+
return `${this.pathToFolder}/${this.name}-${index}.txt`;
|
|
60
|
+
}
|
|
61
|
+
printLogMessage(log) {
|
|
62
|
+
this.buffer.write(log);
|
|
63
|
+
}
|
|
64
|
+
rotateBuffer(fromIndex, toIndex) {
|
|
65
|
+
if (fs.existsSync(this.getFileName(fromIndex))) {
|
|
66
|
+
console.log(`rotating ${fromIndex} => ${toIndex}`);
|
|
67
|
+
fs.renameSync(this.getFileName(fromIndex), this.getFileName(toIndex));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
cleanup() {
|
|
71
|
+
const fileName = this.getFileName(this.maxEntries - 1);
|
|
72
|
+
if (fs.existsSync(fileName))
|
|
73
|
+
fs.unlinkSync(fileName);
|
|
74
|
+
this.buffer.end();
|
|
75
|
+
}
|
|
76
|
+
prepare() {
|
|
77
|
+
this.buffer = fs.createWriteStream(this.getFileName(), { flags: 'a' });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.LogClient_File = LogClient_File;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { LogClient_BaseRotate } from
|
|
1
|
+
import { LogClient_BaseRotate } from './LogClient_BaseRotate';
|
|
2
2
|
export declare class LogClient_MemBuffer extends LogClient_BaseRotate {
|
|
3
3
|
readonly buffers: string[];
|
|
4
|
+
private onLogAppended?;
|
|
4
5
|
constructor(name: string, maxBuffers?: number, maxBufferSize?: number);
|
|
6
|
+
setLogAppendedListener(onLogAppended: VoidFunction): void;
|
|
5
7
|
protected printLogMessage(log: string): void;
|
|
6
8
|
protected cleanup(): void;
|
|
7
9
|
protected rotateBuffer(fromIndex: number, toIndex: number): void;
|
|
@@ -23,10 +23,15 @@ const LogClient_BaseRotate_1 = require("./LogClient_BaseRotate");
|
|
|
23
23
|
class LogClient_MemBuffer extends LogClient_BaseRotate_1.LogClient_BaseRotate {
|
|
24
24
|
constructor(name, maxBuffers = 10, maxBufferSize = 1024 * 1024) {
|
|
25
25
|
super(name, maxBuffers, maxBufferSize);
|
|
26
|
-
this.buffers = [
|
|
26
|
+
this.buffers = [''];
|
|
27
|
+
}
|
|
28
|
+
setLogAppendedListener(onLogAppended) {
|
|
29
|
+
this.onLogAppended = onLogAppended;
|
|
27
30
|
}
|
|
28
31
|
printLogMessage(log) {
|
|
32
|
+
var _a;
|
|
29
33
|
this.buffers[0] += log;
|
|
34
|
+
(_a = this.onLogAppended) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
30
35
|
}
|
|
31
36
|
cleanup() {
|
|
32
37
|
}
|
|
@@ -34,7 +39,7 @@ class LogClient_MemBuffer extends LogClient_BaseRotate_1.LogClient_BaseRotate {
|
|
|
34
39
|
this.buffers[toIndex] = this.buffers[fromIndex];
|
|
35
40
|
}
|
|
36
41
|
prepare() {
|
|
37
|
-
this.buffers[0] =
|
|
42
|
+
this.buffers[0] = '';
|
|
38
43
|
}
|
|
39
44
|
}
|
|
40
45
|
exports.LogClient_MemBuffer = LogClient_MemBuffer;
|
package/modules/CSVModule.js
CHANGED
|
@@ -16,6 +16,29 @@
|
|
|
16
16
|
* See the License for the specific language governing permissions and
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
20
|
+
if (k2 === undefined) k2 = k;
|
|
21
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
22
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
23
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
24
|
+
}
|
|
25
|
+
Object.defineProperty(o, k2, desc);
|
|
26
|
+
}) : (function(o, m, k, k2) {
|
|
27
|
+
if (k2 === undefined) k2 = k;
|
|
28
|
+
o[k2] = m[k];
|
|
29
|
+
}));
|
|
30
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
31
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
32
|
+
}) : function(o, v) {
|
|
33
|
+
o["default"] = v;
|
|
34
|
+
});
|
|
35
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
36
|
+
if (mod && mod.__esModule) return mod;
|
|
37
|
+
var result = {};
|
|
38
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
39
|
+
__setModuleDefault(result, mod);
|
|
40
|
+
return result;
|
|
41
|
+
};
|
|
19
42
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
43
|
exports.CSVModule = void 0;
|
|
21
44
|
/**
|
|
@@ -27,7 +50,7 @@ const module_1 = require("../core/module");
|
|
|
27
50
|
const stream_1 = require("stream");
|
|
28
51
|
const queue_1 = require("../utils/queue");
|
|
29
52
|
const csvParser = require("csv-parser");
|
|
30
|
-
const csv = require("fast-csv");
|
|
53
|
+
const csv = __importStar(require("fast-csv"));
|
|
31
54
|
const DefaultConfig = {
|
|
32
55
|
options: {
|
|
33
56
|
fieldSeparator: ',',
|
package/modules/CSVModuleV3.js
CHANGED
|
@@ -16,10 +16,33 @@
|
|
|
16
16
|
* See the License for the specific language governing permissions and
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
20
|
+
if (k2 === undefined) k2 = k;
|
|
21
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
22
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
23
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
24
|
+
}
|
|
25
|
+
Object.defineProperty(o, k2, desc);
|
|
26
|
+
}) : (function(o, m, k, k2) {
|
|
27
|
+
if (k2 === undefined) k2 = k;
|
|
28
|
+
o[k2] = m[k];
|
|
29
|
+
}));
|
|
30
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
31
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
32
|
+
}) : function(o, v) {
|
|
33
|
+
o["default"] = v;
|
|
34
|
+
});
|
|
35
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
36
|
+
if (mod && mod.__esModule) return mod;
|
|
37
|
+
var result = {};
|
|
38
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
39
|
+
__setModuleDefault(result, mod);
|
|
40
|
+
return result;
|
|
41
|
+
};
|
|
19
42
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
43
|
exports.CSVModuleV3 = exports.CSVModuleV3_Class = void 0;
|
|
21
44
|
const module_1 = require("../core/module");
|
|
22
|
-
const csv = require("fast-csv");
|
|
45
|
+
const csv = __importStar(require("fast-csv"));
|
|
23
46
|
class CSVModuleV3_Class extends module_1.Module {
|
|
24
47
|
constructor() {
|
|
25
48
|
super();
|
package/modules/JSONCSVModule.js
CHANGED
|
@@ -1,10 +1,33 @@
|
|
|
1
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 (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.JSONCSVModule_Class = void 0;
|
|
4
27
|
const CSVModuleV3_1 = require("./CSVModuleV3");
|
|
5
28
|
const object_tools_1 = require("../utils/object-tools");
|
|
6
29
|
const tools_1 = require("../utils/tools");
|
|
7
|
-
const csv = require("fast-csv");
|
|
30
|
+
const csv = __importStar(require("fast-csv"));
|
|
8
31
|
class JSONCSVModule_Class extends CSVModuleV3_1.CSVModuleV3_Class {
|
|
9
32
|
constructor(keysToStringify) {
|
|
10
33
|
super();
|
package/package.json
CHANGED
package/utils/date-time-tools.js
CHANGED
|
@@ -16,10 +16,13 @@
|
|
|
16
16
|
* See the License for the specific language governing permissions and
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
20
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
21
|
+
};
|
|
19
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
23
|
exports.deltaDays = exports.isSameDay = exports.DateTimeFormat_DDMMYYYY = exports.DateTimeFormat_yyyyMMDD = exports.DateTimeFormat_yyyyMMDDTHHmmss = exports.DateTimeFormat = exports.normalizeTimestamp = exports.parseTimeString = exports.formatTimestamp = exports.createReadableTimestampObject = exports.currentTimeMillisWithTimeZone = exports.currentLocalTimeMillis = exports.specificTimeTodayMillis = exports.currentTimeMillis = exports.auditBy = exports._clearInterval = exports._setInterval = exports._clearTimeout = exports._setTimeout = exports.sleep = exports.timeout = exports.Weekdays = exports.Format_YYYYMMDD_HHmmss = exports.Format_HHmmss_DDMMYYYY = exports.Month = exports.Year = exports.Week = exports.Day = exports.Hour = exports.Minute = exports.Second = void 0;
|
|
21
|
-
const
|
|
22
|
-
const
|
|
24
|
+
const moment_1 = __importDefault(require("moment"));
|
|
25
|
+
const moment_2 = require("moment");
|
|
23
26
|
exports.Second = 1000;
|
|
24
27
|
exports.Minute = exports.Second * 60;
|
|
25
28
|
exports.Hour = exports.Minute * 60;
|
|
@@ -104,13 +107,13 @@ exports.createReadableTimestampObject = createReadableTimestampObject;
|
|
|
104
107
|
*/
|
|
105
108
|
function formatTimestamp(pattern = exports.Format_HHmmss_DDMMYYYY, timestamp = currentTimeMillis(), timezone = Intl.DateTimeFormat()
|
|
106
109
|
.resolvedOptions().timeZone) {
|
|
107
|
-
const m = (0,
|
|
110
|
+
const m = (0, moment_2.utc)(timestamp);
|
|
108
111
|
m.utcOffset(-new Date().getTimezoneOffset());
|
|
109
112
|
return m.format(pattern);
|
|
110
113
|
}
|
|
111
114
|
exports.formatTimestamp = formatTimestamp;
|
|
112
115
|
function parseTimeString(timestamp, pattern = exports.Format_HHmmss_DDMMYYYY) {
|
|
113
|
-
return (0,
|
|
116
|
+
return (0, moment_2.utc)(timestamp, pattern).valueOf();
|
|
114
117
|
}
|
|
115
118
|
exports.parseTimeString = parseTimeString;
|
|
116
119
|
function normalizeTimestamp(timestamp, pattern) {
|
|
@@ -128,7 +131,7 @@ exports.DateTimeFormat_yyyyMMDDTHHmmss = (0, exports.DateTimeFormat)('YYYY-MM-DD
|
|
|
128
131
|
exports.DateTimeFormat_yyyyMMDD = (0, exports.DateTimeFormat)('YYYY-MM-DD');
|
|
129
132
|
exports.DateTimeFormat_DDMMYYYY = (0, exports.DateTimeFormat)('DD/MM/YYYY');
|
|
130
133
|
function isSameDay(date1, date2) {
|
|
131
|
-
return
|
|
134
|
+
return (0, moment_1.default)(date1).isSame(date2, 'day');
|
|
132
135
|
}
|
|
133
136
|
exports.isSameDay = isSameDay;
|
|
134
137
|
function deltaDays(d1, d2) {
|