@nu-art/ts-common 0.200.22 → 0.200.24
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/consts/consts.js +0 -1
- package/core/application.js +12 -31
- package/core/debug-flags.js +32 -38
- package/core/dispatcher.js +30 -92
- package/core/error-handling.js +1 -2
- package/core/exceptions.js +47 -84
- package/core/logger/BeLogged.js +19 -26
- package/core/logger/LogClient.js +14 -16
- package/core/logger/LogClient_BaseRotate.js +20 -42
- package/core/logger/LogClient_Browser.js +16 -36
- package/core/logger/LogClient_Function.js +14 -34
- package/core/logger/LogClient_MemBuffer.js +14 -35
- package/core/logger/LogClient_Terminal.js +12 -34
- package/core/logger/Logger.js +67 -152
- package/core/logger/types.js +0 -1
- package/core/logger/utils.js +16 -18
- package/core/module-manager.js +33 -61
- package/core/module.js +43 -65
- package/csv.js +0 -1
- package/index.js +0 -1
- package/modules/CSVModule.js +50 -110
- package/modules/CliParamsModule.js +32 -54
- package/modules/csv-serializer.js +10 -22
- package/package.json +8 -18
- package/permissions/permission-group.js +9 -12
- package/test-index.js +0 -1
- package/testing/consts.js +18 -54
- package/testing/types.js +0 -1
- package/tools/Replacer.js +71 -96
- package/tools/get-log-style.js +5 -10
- package/utils/array-tools.js +63 -127
- package/utils/crypto-tools.js +1 -2
- package/utils/date-time-tools.js +19 -75
- package/utils/db-object-tools.js +0 -1
- package/utils/filter-tools.js +37 -43
- package/utils/hash-tools.js +4 -8
- package/utils/merge-tools.js +4 -5
- package/utils/mimetype-tools.js +0 -1
- package/utils/number-tools.js +3 -4
- package/utils/object-tools.js +16 -20
- package/utils/query-params.js +8 -11
- package/utils/queue.js +47 -115
- package/utils/random-tools.js +2 -3
- package/utils/storage-capacity-tools.js +0 -1
- package/utils/string-tools.js +16 -18
- package/utils/tools.js +11 -42
- package/utils/types.js +1 -2
- package/utils/ui-tools.js +8 -15
- package/utils/version-tools.js +6 -7
- package/validator/type-validators.js +65 -84
- package/validator/validator-core.js +34 -58
- package/consts/consts.js.map +0 -1
- package/core/application.js.map +0 -1
- package/core/debug-flags.js.map +0 -1
- package/core/dispatcher.js.map +0 -1
- package/core/error-handling.js.map +0 -1
- package/core/exceptions.js.map +0 -1
- package/core/logger/BeLogged.js.map +0 -1
- package/core/logger/LogClient.js.map +0 -1
- package/core/logger/LogClient_BaseRotate.js.map +0 -1
- package/core/logger/LogClient_Browser.js.map +0 -1
- package/core/logger/LogClient_Function.js.map +0 -1
- package/core/logger/LogClient_MemBuffer.js.map +0 -1
- package/core/logger/LogClient_Terminal.js.map +0 -1
- package/core/logger/Logger.js.map +0 -1
- package/core/logger/types.js.map +0 -1
- package/core/logger/utils.js.map +0 -1
- package/core/module-manager.js.map +0 -1
- package/core/module.js.map +0 -1
- package/csv.js.map +0 -1
- package/index.js.map +0 -1
- package/modules/CSVModule.js.map +0 -1
- package/modules/CliParamsModule.js.map +0 -1
- package/modules/csv-serializer.js.map +0 -1
- package/permissions/permission-group.js.map +0 -1
- package/test-index.js.map +0 -1
- package/testing/consts.js.map +0 -1
- package/testing/types.js.map +0 -1
- package/tools/Replacer.js.map +0 -1
- package/tools/get-log-style.js.map +0 -1
- package/utils/array-tools.js.map +0 -1
- package/utils/crypto-tools.js.map +0 -1
- package/utils/date-time-tools.js.map +0 -1
- package/utils/db-object-tools.js.map +0 -1
- package/utils/filter-tools.js.map +0 -1
- package/utils/hash-tools.js.map +0 -1
- package/utils/merge-tools.js.map +0 -1
- package/utils/mimetype-tools.js.map +0 -1
- package/utils/number-tools.js.map +0 -1
- package/utils/object-tools.js.map +0 -1
- package/utils/query-params.js.map +0 -1
- package/utils/queue.js.map +0 -1
- package/utils/random-tools.js.map +0 -1
- package/utils/storage-capacity-tools.js.map +0 -1
- package/utils/string-tools.js.map +0 -1
- package/utils/tools.js.map +0 -1
- package/utils/types.js.map +0 -1
- package/utils/ui-tools.js.map +0 -1
- package/utils/version-tools.js.map +0 -1
- package/validator/type-validators.js.map +0 -1
- package/validator/validator-core.js.map +0 -1
|
@@ -16,79 +16,57 @@
|
|
|
16
16
|
* See the License for the specific language governing permissions and
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
|
-
var __extends = (this && this.__extends) || (function () {
|
|
20
|
-
var extendStatics = function (d, b) {
|
|
21
|
-
extendStatics = Object.setPrototypeOf ||
|
|
22
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
23
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
24
|
-
return extendStatics(d, b);
|
|
25
|
-
};
|
|
26
|
-
return function (d, b) {
|
|
27
|
-
if (typeof b !== "function" && b !== null)
|
|
28
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
29
|
-
extendStatics(d, b);
|
|
30
|
-
function __() { this.constructor = d; }
|
|
31
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
32
|
-
};
|
|
33
|
-
})();
|
|
34
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
20
|
exports.CliParamsModule = void 0;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
_this.printFoundArgs('Found Args', foundParams, _this.paramsValue);
|
|
21
|
+
const module_1 = require("../core/module");
|
|
22
|
+
const exceptions_1 = require("../core/exceptions");
|
|
23
|
+
const __1 = require("..");
|
|
24
|
+
class CliParamsModule_Class extends module_1.Module {
|
|
25
|
+
constructor() {
|
|
26
|
+
super(...arguments);
|
|
27
|
+
this.paramsValue = {};
|
|
28
|
+
this.printHowTo = (params) => {
|
|
29
|
+
const missingParams = params.filter((param) => !this.paramsValue[param.keyName] && !param.optional);
|
|
30
|
+
const foundParams = params.filter((param) => this.paramsValue[param.keyName]);
|
|
31
|
+
this.printFoundArgs('Found Args', foundParams, this.paramsValue);
|
|
48
32
|
if (missingParams.length === 0)
|
|
49
33
|
return;
|
|
50
|
-
|
|
34
|
+
this.printFoundArgs('Missing Args', missingParams, this.paramsValue);
|
|
51
35
|
throw new exceptions_1.ImplementationMissingException('Missing cli params');
|
|
52
36
|
};
|
|
53
|
-
|
|
54
|
-
return
|
|
37
|
+
this.getParams = () => {
|
|
38
|
+
return this.paramsValue;
|
|
55
39
|
};
|
|
56
|
-
return _this;
|
|
57
40
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
this.config.params.forEach(function (param) { return _this.paramsValue[param.keyName] = _this.getParam(param); });
|
|
41
|
+
init() {
|
|
42
|
+
this.config.params.forEach((param) => this.paramsValue[param.keyName] = this.getParam(param));
|
|
61
43
|
this.printHowTo(this.config.params);
|
|
62
44
|
return this.paramsValue;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (
|
|
66
|
-
if (!this.config.params.find(function (_param) { return _param.keyName === param.keyName; }))
|
|
45
|
+
}
|
|
46
|
+
getParam(param, args = process.argv.slice(2, process.argv.length)) {
|
|
47
|
+
if (!this.config.params.find(_param => _param.keyName === param.keyName))
|
|
67
48
|
throw new exceptions_1.BadImplementationException('Requested not existing param');
|
|
68
|
-
|
|
49
|
+
let value = this.extractParam(param, args);
|
|
69
50
|
if (!value)
|
|
70
51
|
value = param.defaultValue;
|
|
71
52
|
if (!value)
|
|
72
53
|
return value;
|
|
73
54
|
return (param.process ? param.process(value) : value);
|
|
74
|
-
}
|
|
75
|
-
|
|
55
|
+
}
|
|
56
|
+
extractParam(param, argv) {
|
|
76
57
|
if (param.isArray)
|
|
77
|
-
return param.keys.reduce(
|
|
78
|
-
values.push
|
|
58
|
+
return param.keys.reduce((values, key) => {
|
|
59
|
+
values.push(...(0, __1.filterInstances)(argv.map(arg => { var _a; return (_a = arg.match(new RegExp(`${key}=(.*)`))) === null || _a === void 0 ? void 0 : _a[1]; })));
|
|
79
60
|
return values;
|
|
80
61
|
}, []);
|
|
81
|
-
|
|
82
|
-
return (0, __1.flatArray)(find).find(
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
var _this = this;
|
|
62
|
+
const find = param.keys.map(key => argv.map(arg => { var _a; return (_a = arg.match(new RegExp(`${key}=(.*)`))) === null || _a === void 0 ? void 0 : _a[1]; }));
|
|
63
|
+
return (0, __1.flatArray)(find).find(k => k);
|
|
64
|
+
}
|
|
65
|
+
printFoundArgs(title, params, foundArgs) {
|
|
86
66
|
if (params.length)
|
|
87
67
|
return;
|
|
88
|
-
this.logInfoBold(
|
|
89
|
-
params.forEach(
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
}(module_1.Module));
|
|
68
|
+
this.logInfoBold(` ${title}:`);
|
|
69
|
+
params.forEach((param) => this.logInfo(` ${param.keys[0]}=${foundArgs[param.keyName] || `<${param.name}>`}`));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
93
72
|
exports.CliParamsModule = new CliParamsModule_Class();
|
|
94
|
-
//# sourceMappingURL=CliParamsModule.js.map
|
|
@@ -16,35 +16,23 @@
|
|
|
16
16
|
* See the License for the specific language governing permissions and
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
|
-
var __assign = (this && this.__assign) || function () {
|
|
20
|
-
__assign = Object.assign || function(t) {
|
|
21
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
22
|
-
s = arguments[i];
|
|
23
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
24
|
-
t[p] = s[p];
|
|
25
|
-
}
|
|
26
|
-
return t;
|
|
27
|
-
};
|
|
28
|
-
return __assign.apply(this, arguments);
|
|
29
|
-
};
|
|
30
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
20
|
exports.csvSerializer = void 0;
|
|
32
21
|
function csvSerializer(items, _csvProps) {
|
|
33
|
-
|
|
22
|
+
const csvProps = Object.assign({ decimalSeparator: '.', withHeaders: true, fieldWrapper: '"', lineSeparator: '\n', fieldSeparator: ',', columnNames: (k) => k.toString() }, _csvProps);
|
|
34
23
|
function processValue(value) {
|
|
35
|
-
|
|
24
|
+
let escapedValue = (value.toString() || '').replace(csvProps.fieldWrapper, `\\${csvProps.fieldWrapper}`);
|
|
36
25
|
if (escapedValue.includes(csvProps.lineSeparator) || escapedValue.includes(csvProps.fieldSeparator))
|
|
37
|
-
escapedValue =
|
|
38
|
-
return
|
|
26
|
+
escapedValue = `${csvProps.fieldWrapper}${escapedValue}${csvProps.fieldWrapper}`;
|
|
27
|
+
return `${escapedValue}${csvProps.fieldSeparator}`;
|
|
39
28
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
29
|
+
const outputRows = [];
|
|
30
|
+
const columnsByOrder = csvProps.columns.map(c => c.toString());
|
|
31
|
+
const headersLine = columnsByOrder.reduce((output, header) => `${output}${processValue(csvProps.columnNames(header))}`, '').slice(0, -1);
|
|
43
32
|
if (csvProps.withHeaders)
|
|
44
33
|
outputRows.push(headersLine);
|
|
45
|
-
|
|
46
|
-
outputRows.push
|
|
47
|
-
return outputRows.reduce(
|
|
34
|
+
const rowsData = items.map((row) => columnsByOrder.reduce((output, header) => `${output}${processValue(row[header])}`, '').slice(0, -1));
|
|
35
|
+
outputRows.push(...rowsData);
|
|
36
|
+
return outputRows.reduce((content, row) => `${content}${row}${csvProps.lineSeparator}`, '').slice(0, -1);
|
|
48
37
|
}
|
|
49
38
|
exports.csvSerializer = csvSerializer;
|
|
50
|
-
//# sourceMappingURL=csv-serializer.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nu-art/ts-common",
|
|
3
|
-
"version": "0.200.
|
|
3
|
+
"version": "0.200.24",
|
|
4
4
|
"description": "js and ts infra",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"TacB0sS",
|
|
@@ -18,6 +18,10 @@
|
|
|
18
18
|
"type": "git",
|
|
19
19
|
"url": "git+ssh://git@github.com:nu-art-js/ts-common.git"
|
|
20
20
|
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"directory": "dist",
|
|
23
|
+
"linkDirectory": true
|
|
24
|
+
},
|
|
21
25
|
"license": "Apache-2.0",
|
|
22
26
|
"author": "TacB0sS",
|
|
23
27
|
"main": "index.js",
|
|
@@ -31,26 +35,12 @@
|
|
|
31
35
|
"export-to-csv": "^0.2.1",
|
|
32
36
|
"moment": "^2.24.0",
|
|
33
37
|
"node-forge": "^1.2.1",
|
|
34
|
-
"uuid": "^9.0.0"
|
|
38
|
+
"uuid": "^9.0.0",
|
|
39
|
+
"csv-parser": "^2.3.3"
|
|
35
40
|
},
|
|
36
41
|
"devDependencies": {
|
|
37
|
-
"@types/chai": "^4.3.4",
|
|
38
|
-
"@types/chai-as-promised": "^7.1.5",
|
|
39
42
|
"@types/minimatch": "^5.1.2",
|
|
40
|
-
"@types/
|
|
41
|
-
"@types/node-forge": "^1.0.0",
|
|
42
|
-
"@typescript-eslint/eslint-plugin": "^5.8.0",
|
|
43
|
-
"chai": "^4.3.7",
|
|
44
|
-
"chai-as-promised": "^7.1.1",
|
|
45
|
-
"csv-parser": "^2.3.3",
|
|
46
|
-
"eslint": "^6.8.0",
|
|
47
|
-
"mocha": "^10.2.0",
|
|
48
|
-
"ts-mocha": "^10.0.0",
|
|
49
|
-
"ts-node": "^8.6.2",
|
|
50
|
-
"tsdoc": "^0.0.4",
|
|
51
|
-
"typedoc": "^0.22.18",
|
|
52
|
-
"typedoc-theme-yaf": "^0.0.3",
|
|
53
|
-
"typescript": "^4.5.0"
|
|
43
|
+
"@types/node-forge": "^1.0.0"
|
|
54
44
|
},
|
|
55
45
|
"_moduleAliases": {
|
|
56
46
|
"@main": "dist/main/ts",
|
|
@@ -18,20 +18,17 @@ exports.PermissionCategory = void 0;
|
|
|
18
18
|
* See the License for the specific language governing permissions and
|
|
19
19
|
* limitations under the License.
|
|
20
20
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
const index_1 = require("../index");
|
|
22
|
+
class PermissionCategory {
|
|
23
|
+
constructor(key, permissionsEnum, defaultValue) {
|
|
24
24
|
this.key = key;
|
|
25
25
|
this.permissionsEnum = permissionsEnum;
|
|
26
26
|
this.defaultValue = defaultValue;
|
|
27
|
-
|
|
28
|
-
this.levels = (0, index_1.sortArray)(_levels,
|
|
27
|
+
const _levels = Object.keys(permissionsEnum).filter(value => isNaN(parseInt(value)));
|
|
28
|
+
this.levels = (0, index_1.sortArray)(_levels, (_key) => permissionsEnum[_key]).reverse();
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return PermissionCategory;
|
|
35
|
-
}());
|
|
30
|
+
getClosestMatch(permission) {
|
|
31
|
+
return (0, index_1.deepClone)(this.levels).reverse().find(((level) => this.permissionsEnum[level] <= permission));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
36
34
|
exports.PermissionCategory = PermissionCategory;
|
|
37
|
-
//# sourceMappingURL=permission-group.js.map
|
package/test-index.js
CHANGED
|
@@ -16,4 +16,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./testing/types"), exports);
|
|
18
18
|
__exportStar(require("./testing/consts"), exports);
|
|
19
|
-
//# sourceMappingURL=test-index.js.map
|
package/testing/consts.js
CHANGED
|
@@ -8,67 +8,31 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
12
|
exports.expectFailAsync = exports.testSuiteTester = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
describe(testSuit.label,
|
|
13
|
+
const chai_1 = require("chai");
|
|
14
|
+
const __1 = require("..");
|
|
15
|
+
const testSuiteTester = (testSuit) => {
|
|
16
|
+
describe(testSuit.label, () => {
|
|
44
17
|
//Run pre-process
|
|
45
18
|
if (testSuit.preProcessor) {
|
|
46
|
-
it(
|
|
19
|
+
it(`${testSuit.label} - Preprocessing`, testSuit.preProcessor);
|
|
47
20
|
}
|
|
48
|
-
testSuit.testcases.forEach(
|
|
49
|
-
it(testCase.description,
|
|
21
|
+
testSuit.testcases.forEach(testCase => {
|
|
22
|
+
it(testCase.description, () => testSuit.processor(testCase));
|
|
50
23
|
});
|
|
51
24
|
});
|
|
52
25
|
};
|
|
53
26
|
exports.testSuiteTester = testSuiteTester;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
e_1 = _a.sent();
|
|
66
|
-
return [2 /*return*/, (0, chai_1.expect)(function () {
|
|
67
|
-
throw e_1;
|
|
68
|
-
})];
|
|
69
|
-
case 3: return [2 /*return*/];
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
}); };
|
|
27
|
+
const expectFailAsync = (action) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
+
try {
|
|
29
|
+
yield action();
|
|
30
|
+
return (0, chai_1.expect)(__1.voidFunction);
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
return (0, chai_1.expect)(() => {
|
|
34
|
+
throw e;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
});
|
|
73
38
|
exports.expectFailAsync = expectFailAsync;
|
|
74
|
-
//# sourceMappingURL=consts.js.map
|
package/testing/types.js
CHANGED
package/tools/Replacer.js
CHANGED
|
@@ -16,119 +16,96 @@
|
|
|
16
16
|
* See the License for the specific language governing permissions and
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
|
-
var __extends = (this && this.__extends) || (function () {
|
|
20
|
-
var extendStatics = function (d, b) {
|
|
21
|
-
extendStatics = Object.setPrototypeOf ||
|
|
22
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
23
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
24
|
-
return extendStatics(d, b);
|
|
25
|
-
};
|
|
26
|
-
return function (d, b) {
|
|
27
|
-
if (typeof b !== "function" && b !== null)
|
|
28
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
29
|
-
extendStatics(d, b);
|
|
30
|
-
function __() { this.constructor = d; }
|
|
31
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
32
|
-
};
|
|
33
|
-
})();
|
|
34
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
20
|
exports.Replacer = void 0;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
_this.aliases = [];
|
|
45
|
-
return _this;
|
|
21
|
+
const Logger_1 = require("../core/logger/Logger");
|
|
22
|
+
const validator_core_1 = require("../validator/validator-core");
|
|
23
|
+
class Replacer extends Logger_1.Logger {
|
|
24
|
+
constructor() {
|
|
25
|
+
super();
|
|
26
|
+
this.strictMode = true;
|
|
27
|
+
this.input = {};
|
|
28
|
+
this.aliases = [];
|
|
46
29
|
// this.setMinLevel(LogLevel.Error);
|
|
47
30
|
}
|
|
48
|
-
|
|
31
|
+
setFallbackReplacer(fallbackReplacer) {
|
|
49
32
|
this.fallbackReplacer = fallbackReplacer;
|
|
50
33
|
return this;
|
|
51
|
-
}
|
|
52
|
-
|
|
34
|
+
}
|
|
35
|
+
setNotStrict() {
|
|
53
36
|
this.strictMode = false;
|
|
54
37
|
return this;
|
|
55
|
-
}
|
|
56
|
-
|
|
38
|
+
}
|
|
39
|
+
getInput() {
|
|
57
40
|
return this.input;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (aliases === void 0) { aliases = []; }
|
|
41
|
+
}
|
|
42
|
+
setInput(input, aliases = []) {
|
|
61
43
|
this.input = input;
|
|
62
44
|
this.aliases = aliases;
|
|
63
45
|
return this;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
var content = this.replaceLoops(_content, runtime);
|
|
46
|
+
}
|
|
47
|
+
replace(_content = '', runtime) {
|
|
48
|
+
let content = this.replaceLoops(_content, runtime);
|
|
68
49
|
content = this.replaceParams(content, runtime);
|
|
69
50
|
if (_content !== content)
|
|
70
51
|
content = this.replace(content, runtime);
|
|
71
52
|
return content;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
var matches = content.match(Replacer.Regexp_paramGroup);
|
|
77
|
-
return (matches === null || matches === void 0 ? void 0 : matches.reduce(function (toRet, match) {
|
|
53
|
+
}
|
|
54
|
+
replaceParams(content = '', runtime) {
|
|
55
|
+
const matches = content.match(Replacer.Regexp_paramGroup);
|
|
56
|
+
return (matches === null || matches === void 0 ? void 0 : matches.reduce((toRet, match) => {
|
|
78
57
|
var _a;
|
|
79
|
-
|
|
58
|
+
let param = match;
|
|
80
59
|
while (Replacer.Regexp_param.test(param))
|
|
81
60
|
param = (_a = param.match(Replacer.Regexp_param)) === null || _a === void 0 ? void 0 : _a[1];
|
|
82
61
|
if (param === undefined)
|
|
83
62
|
return toRet;
|
|
84
|
-
|
|
63
|
+
const value = this.resolveParam(param, toRet, runtime);
|
|
85
64
|
return toRet.replace(match, value);
|
|
86
65
|
}, content)) || content;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
66
|
+
}
|
|
67
|
+
resolveParam(param, toRet, runtime) {
|
|
68
|
+
const value = this.resolveParamValue(param, runtime);
|
|
90
69
|
if (this.fallbackReplacer && (value === undefined || value === ''))
|
|
91
70
|
return this.fallbackReplacer.resolveParam(param, toRet, runtime);
|
|
92
71
|
return value;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
var loopArray;
|
|
113
|
-
var iterableProp = "".concat(iterator);
|
|
72
|
+
}
|
|
73
|
+
replaceLoops(content = '', runtime) {
|
|
74
|
+
const matches = content.match(Replacer.Regexp_forLoopGroupStart);
|
|
75
|
+
return (matches === null || matches === void 0 ? void 0 : matches.reduce((toRet, match) => {
|
|
76
|
+
const varsMatch = match.match(Replacer.Regexp_forLoopParam);
|
|
77
|
+
const string = varsMatch[0];
|
|
78
|
+
const iterable = varsMatch[1];
|
|
79
|
+
const iterator = varsMatch[2];
|
|
80
|
+
const endMatch = `{{/foreach ${iterator}}}`;
|
|
81
|
+
const indexOfEnd = toRet.indexOf(endMatch);
|
|
82
|
+
const fullOriginLoopText = toRet.substring(toRet.indexOf(string), indexOfEnd + endMatch.length);
|
|
83
|
+
const loopText = toRet.substring(toRet.indexOf(string) + string.length, indexOfEnd);
|
|
84
|
+
this.logDebug(`indexOfEnd: ${endMatch} ${indexOfEnd}`);
|
|
85
|
+
this.logDebug(`string: ${string} ${toRet.indexOf(string)}`);
|
|
86
|
+
this.logDebug(`iterable: ${iterable}`);
|
|
87
|
+
this.logDebug(`iterator: ${iterator}`);
|
|
88
|
+
this.logDebug(`loopText: ${loopText}`);
|
|
89
|
+
let loopArray;
|
|
90
|
+
const iterableProp = `${iterator}`;
|
|
114
91
|
try {
|
|
115
|
-
loopArray =
|
|
92
|
+
loopArray = this.resolveParamValue(iterableProp, runtime);
|
|
116
93
|
}
|
|
117
94
|
catch (e) {
|
|
118
|
-
throw new validator_core_1.ValidationException(
|
|
95
|
+
throw new validator_core_1.ValidationException(`Error while looping on variable for parts: `, iterableProp, this.input, e);
|
|
119
96
|
}
|
|
120
97
|
if (!Array.isArray(loopArray))
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
return _toRet +
|
|
98
|
+
this.logWarning(`Loop object is not an array.. found:`, loopArray);
|
|
99
|
+
const replacement = loopArray.reduce((_toRet, value) => {
|
|
100
|
+
return _toRet + this.replace(loopText, { property: value });
|
|
124
101
|
}, '');
|
|
125
|
-
|
|
102
|
+
const s = toRet.replace(fullOriginLoopText, replacement);
|
|
126
103
|
return s;
|
|
127
104
|
}, content)) || content;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
105
|
+
}
|
|
106
|
+
resolveParamValue(_param, runtime) {
|
|
107
|
+
let param = _param;
|
|
108
|
+
const alias = this.aliases.find(alias => alias.key === param);
|
|
132
109
|
if (alias) {
|
|
133
110
|
this.logInfo('using alias: ', alias);
|
|
134
111
|
param = alias.value || param;
|
|
@@ -137,36 +114,34 @@ var Replacer = /** @class */ (function (_super) {
|
|
|
137
114
|
if (param.endsWith('.'))
|
|
138
115
|
param = param.substring(0, param.length - 1);
|
|
139
116
|
if (param.startsWith(Replacer.Indicator_RuntimeParam))
|
|
140
|
-
param =
|
|
141
|
-
|
|
142
|
-
|
|
117
|
+
param = `${Replacer.RuntimeParam}.${param.substring(Replacer.Indicator_RuntimeParam.length)}`;
|
|
118
|
+
const parts = param.split('\.');
|
|
119
|
+
let value;
|
|
143
120
|
try {
|
|
144
121
|
if (runtime)
|
|
145
|
-
value = parts.reduce(
|
|
122
|
+
value = parts.reduce((value, key) => value === null || value === void 0 ? void 0 : value[key], runtime);
|
|
146
123
|
if (value === undefined)
|
|
147
|
-
value = parts.reduce(
|
|
124
|
+
value = parts.reduce((value, key) => value[key], this.input);
|
|
148
125
|
}
|
|
149
126
|
catch (e) {
|
|
150
127
|
this.logWarning('input', this.input);
|
|
151
|
-
throw new validator_core_1.ValidationException(
|
|
128
|
+
throw new validator_core_1.ValidationException(`Error while resolving runtime variable for parts ${param}`, param, this.input, e);
|
|
152
129
|
}
|
|
153
130
|
if (value === undefined) {
|
|
154
131
|
this.logWarning('input', this.input);
|
|
155
132
|
if (this.strictMode)
|
|
156
|
-
throw new validator_core_1.ValidationException(
|
|
133
|
+
throw new validator_core_1.ValidationException(`Cannot resolve runtime variable for parts ${param}`, param, this.input);
|
|
157
134
|
}
|
|
158
135
|
return value;
|
|
159
136
|
// this.logDebug(`Input:`, this.input);
|
|
160
137
|
// this.logDebug(`Param: ${param}`, 'Parts: ', parts);
|
|
161
138
|
// this.logDebug(value);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}(Logger_1.Logger));
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
Replacer.RuntimeParam = '__runtime';
|
|
142
|
+
Replacer.Indicator_RuntimeParam = '__';
|
|
143
|
+
Replacer.Regexp_paramGroup = /\$\{(\{?.*?\}?)\}/g;
|
|
144
|
+
Replacer.Regexp_param = /\$\{(\{?.*?\}?)\}/;
|
|
145
|
+
Replacer.Regexp_forLoopGroupStart = /\{\{foreach (.*?) in (.*?)\}\}/g;
|
|
146
|
+
Replacer.Regexp_forLoopParam = /\{\{foreach (.*?) in (.*?)\}\}/;
|
|
171
147
|
exports.Replacer = Replacer;
|
|
172
|
-
//# sourceMappingURL=Replacer.js.map
|
package/tools/get-log-style.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
exports.getLogStyle = void 0;
|
|
21
|
-
|
|
21
|
+
const object_tools_1 = require("../utils/object-tools");
|
|
22
22
|
/**
|
|
23
23
|
* Returns a style string for console.log()
|
|
24
24
|
* To log with style, make sure to add '%c' at the start of the log.
|
|
@@ -26,18 +26,13 @@ var object_tools_1 = require("../utils/object-tools");
|
|
|
26
26
|
*
|
|
27
27
|
* @param styleObj - one or more style objects defining the log style
|
|
28
28
|
*/
|
|
29
|
-
function getLogStyle() {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
var style = '';
|
|
35
|
-
styleObj.forEach(function (obj) {
|
|
36
|
-
var _arr = (0, object_tools_1._keys)(obj).map(function (key) { return "".concat(key, ": ").concat(obj[key]); });
|
|
29
|
+
function getLogStyle(...styleObj) {
|
|
30
|
+
let style = '';
|
|
31
|
+
styleObj.forEach(obj => {
|
|
32
|
+
const _arr = (0, object_tools_1._keys)(obj).map(key => `${key}: ${obj[key]}`);
|
|
37
33
|
style += _arr.join(';');
|
|
38
34
|
style += ';';
|
|
39
35
|
});
|
|
40
36
|
return style;
|
|
41
37
|
}
|
|
42
38
|
exports.getLogStyle = getLogStyle;
|
|
43
|
-
//# sourceMappingURL=get-log-style.js.map
|