@nu-art/ts-common 0.105.0 → 0.105.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/consts/consts.d.ts +1 -0
- package/consts/consts.js +22 -0
- package/consts/consts.js.map +1 -0
- package/core/application.d.ts +5 -0
- package/core/application.js +55 -0
- package/core/application.js.map +1 -0
- package/core/debug-flags.d.ts +25 -0
- package/core/debug-flags.js +87 -0
- package/core/debug-flags.js.map +1 -0
- package/core/dispatcher.d.ts +18 -0
- package/core/dispatcher.js +132 -0
- package/core/dispatcher.js.map +1 -0
- package/core/error-handling.d.ts +14 -0
- package/core/error-handling.js +38 -0
- package/core/error-handling.js.map +1 -0
- package/core/exceptions.d.ts +118 -0
- package/core/exceptions.js +214 -0
- package/core/exceptions.js.map +1 -0
- package/core/logger/BeLogged.d.ts +14 -0
- package/core/logger/BeLogged.js +61 -0
- package/core/logger/BeLogged.js.map +1 -0
- package/core/logger/LogClient.d.ts +14 -0
- package/core/logger/LogClient.js +67 -0
- package/core/logger/LogClient.js.map +1 -0
- package/core/logger/LogClient_BaseRotate.d.ts +19 -0
- package/core/logger/LogClient_BaseRotate.js +80 -0
- package/core/logger/LogClient_BaseRotate.js.map +1 -0
- package/core/logger/LogClient_Browser.d.ts +9 -0
- package/core/logger/LogClient_Browser.js +101 -0
- package/core/logger/LogClient_Browser.js.map +1 -0
- package/core/logger/LogClient_Function.d.ts +8 -0
- package/core/logger/LogClient_Function.js +75 -0
- package/core/logger/LogClient_Function.js.map +1 -0
- package/core/logger/LogClient_MemBuffer.d.ts +9 -0
- package/core/logger/LogClient_MemBuffer.js +61 -0
- package/core/logger/LogClient_MemBuffer.js.map +1 -0
- package/core/logger/LogClient_Terminal.d.ts +9 -0
- package/core/logger/LogClient_Terminal.js +75 -0
- package/core/logger/LogClient_Terminal.js.map +1 -0
- package/core/logger/Logger.d.ts +38 -0
- package/core/logger/Logger.js +216 -0
- package/core/logger/Logger.js.map +1 -0
- package/core/logger/types.d.ts +10 -0
- package/core/logger/types.js +36 -0
- package/core/logger/types.js.map +1 -0
- package/core/logger/utils.d.ts +5 -0
- package/core/logger/utils.js +80 -0
- package/core/logger/utils.js.map +1 -0
- package/core/module-manager.d.ts +18 -0
- package/core/module-manager.js +112 -0
- package/core/module-manager.js.map +1 -0
- package/core/module.d.ts +32 -0
- package/core/module.js +126 -0
- package/core/module.js.map +1 -0
- package/csv.d.ts +1 -0
- package/csv.js +35 -0
- package/csv.js.map +1 -0
- package/index.d.ts +43 -0
- package/index.js +77 -0
- package/index.js.map +1 -0
- package/modules/CSVModule.d.ts +32 -0
- package/modules/CSVModule.js +165 -0
- package/modules/CSVModule.js.map +1 -0
- package/modules/CliParamsModule.d.ts +27 -0
- package/modules/CliParamsModule.js +94 -0
- package/modules/CliParamsModule.js.map +1 -0
- package/modules/csv-serializer.d.ts +11 -0
- package/modules/csv-serializer.js +50 -0
- package/modules/csv-serializer.js.map +1 -0
- package/package.json +3 -6
- package/permissions/permission-group.d.ts +8 -0
- package/permissions/permission-group.js +37 -0
- package/permissions/permission-group.js.map +1 -0
- package/test-index.d.ts +2 -0
- package/test-index.js +19 -0
- package/test-index.js.map +1 -0
- package/testing/consts.d.ts +5 -0
- package/testing/consts.js +74 -0
- package/testing/consts.js.map +1 -0
- package/testing/types.d.ts +16 -0
- package/testing/types.js +20 -0
- package/testing/types.js.map +1 -0
- package/tools/Replacer.d.ts +24 -0
- package/tools/Replacer.js +172 -0
- package/tools/Replacer.js.map +1 -0
- package/tools/get-log-style.d.ts +14 -0
- package/tools/get-log-style.js +43 -0
- package/tools/get-log-style.js.map +1 -0
- package/utils/array-tools.d.ts +85 -0
- package/utils/array-tools.js +302 -0
- package/utils/array-tools.js.map +1 -0
- package/utils/crypto-tools.d.ts +4 -0
- package/utils/crypto-tools.js +36 -0
- package/utils/crypto-tools.js.map +1 -0
- package/utils/date-time-tools.d.ts +28 -0
- package/utils/date-time-tools.js +180 -0
- package/utils/date-time-tools.js.map +1 -0
- package/utils/db-object-tools.d.ts +3 -0
- package/utils/db-object-tools.js +9 -0
- package/utils/db-object-tools.js.map +1 -0
- package/utils/filter-tools.d.ts +137 -0
- package/utils/filter-tools.js +217 -0
- package/utils/filter-tools.js.map +1 -0
- package/utils/hash-tools.d.ts +8 -0
- package/utils/hash-tools.js +60 -0
- package/utils/hash-tools.js.map +1 -0
- package/utils/merge-tools.d.ts +3 -0
- package/utils/merge-tools.js +71 -0
- package/utils/merge-tools.js.map +1 -0
- package/utils/mimetype-tools.d.ts +8 -0
- package/utils/mimetype-tools.js +29 -0
- package/utils/mimetype-tools.js.map +1 -0
- package/utils/number-tools.d.ts +1 -0
- package/utils/number-tools.js +26 -0
- package/utils/number-tools.js.map +1 -0
- package/utils/object-tools.d.ts +13 -0
- package/utils/object-tools.js +129 -0
- package/utils/object-tools.js.map +1 -0
- package/utils/query-params.d.ts +5 -0
- package/utils/query-params.js +24 -0
- package/utils/query-params.js.map +1 -0
- package/utils/queue.d.ts +16 -0
- package/utils/queue.js +166 -0
- package/utils/queue.js.map +1 -0
- package/utils/random-tools.d.ts +2 -0
- package/utils/random-tools.js +35 -0
- package/utils/random-tools.js.map +1 -0
- package/utils/storage-capacity-tools.d.ts +6 -0
- package/utils/storage-capacity-tools.js +27 -0
- package/utils/storage-capacity-tools.js.map +1 -0
- package/utils/string-tools.d.ts +10 -0
- package/utils/string-tools.js +100 -0
- package/utils/string-tools.js.map +1 -0
- package/utils/tools.d.ts +13 -0
- package/utils/tools.js +103 -0
- package/utils/tools.js.map +1 -0
- package/utils/types.d.ts +92 -0
- package/utils/types.js +23 -0
- package/utils/types.js.map +1 -0
- package/utils/version-tools.d.ts +10 -0
- package/utils/version-tools.js +51 -0
- package/utils/version-tools.js.map +1 -0
- package/validator/type-validators.d.ts +29 -0
- package/validator/type-validators.js +211 -0
- package/validator/type-validators.js.map +1 -0
- package/validator/validator-core.d.ts +36 -0
- package/validator/validator-core.js +144 -0
- package/validator/validator-core.js.map +1 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* ts-common is the basic building blocks of our typescript projects
|
|
4
|
+
*
|
|
5
|
+
* Copyright (C) 2020 Adam van der Kruk aka TacB0sS
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
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
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
35
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
36
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
37
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
38
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
39
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
40
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
44
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
45
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
46
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
47
|
+
function step(op) {
|
|
48
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
49
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
50
|
+
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;
|
|
51
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
52
|
+
switch (op[0]) {
|
|
53
|
+
case 0: case 1: t = op; break;
|
|
54
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
55
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
56
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
57
|
+
default:
|
|
58
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
59
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
60
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
61
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
62
|
+
if (t[2]) _.ops.pop();
|
|
63
|
+
_.trys.pop(); continue;
|
|
64
|
+
}
|
|
65
|
+
op = body.call(thisArg, _);
|
|
66
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
67
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
71
|
+
exports.CSVModule = void 0;
|
|
72
|
+
/**
|
|
73
|
+
* Created by tacb0ss on 07/05/2018.
|
|
74
|
+
*/
|
|
75
|
+
var export_to_csv_1 = require("export-to-csv");
|
|
76
|
+
var fs_1 = require("fs");
|
|
77
|
+
var module_1 = require("../core/module");
|
|
78
|
+
var stream_1 = require("stream");
|
|
79
|
+
var csvParser = require("csv-parser");
|
|
80
|
+
var DefaultConfig = {
|
|
81
|
+
options: {
|
|
82
|
+
fieldSeparator: ',',
|
|
83
|
+
quoteStrings: '"',
|
|
84
|
+
decimalSeparator: '.',
|
|
85
|
+
showLabels: true,
|
|
86
|
+
showTitle: true,
|
|
87
|
+
title: 'Paired List CSV',
|
|
88
|
+
useTextFile: false,
|
|
89
|
+
useBom: true,
|
|
90
|
+
useKeysAsHeaders: true,
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
var CSVModule_Class = /** @class */ (function (_super) {
|
|
94
|
+
__extends(CSVModule_Class, _super);
|
|
95
|
+
function CSVModule_Class() {
|
|
96
|
+
var _this = _super.call(this) || this;
|
|
97
|
+
_this.setDefaultConfig(DefaultConfig);
|
|
98
|
+
return _this;
|
|
99
|
+
}
|
|
100
|
+
CSVModule_Class.prototype.init = function () {
|
|
101
|
+
this.csvExporter = CSVModule_Class.createExporter(this.config.options);
|
|
102
|
+
};
|
|
103
|
+
CSVModule_Class.createExporter = function (options) {
|
|
104
|
+
return new export_to_csv_1.ExportToCsv(options);
|
|
105
|
+
};
|
|
106
|
+
CSVModule_Class.prototype.export = function (items, returnCsv) {
|
|
107
|
+
if (returnCsv === void 0) { returnCsv = true; }
|
|
108
|
+
return this.csvExporter.generateCsv(items, returnCsv);
|
|
109
|
+
};
|
|
110
|
+
CSVModule_Class.prototype.saveToFile = function (outputFile, items, columnsToProps) {
|
|
111
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
112
|
+
var csv;
|
|
113
|
+
return __generator(this, function (_a) {
|
|
114
|
+
csv = this.csvExporter.generateCsv(items, true);
|
|
115
|
+
return [2 /*return*/, fs_1.promises.writeFile(outputFile, csv, { encoding: 'utf8' })];
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
CSVModule_Class.prototype.readCsvFromFile = function (inputFile, columnsToProps) {
|
|
120
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
121
|
+
var stream;
|
|
122
|
+
return __generator(this, function (_a) {
|
|
123
|
+
stream = (0, fs_1.createReadStream)(inputFile, { encoding: 'utf8' });
|
|
124
|
+
return [2 /*return*/, this.readCsvFromStream(stream, columnsToProps)];
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
CSVModule_Class.prototype.readCsvFromBuffer = function (buffer, columnsToProps) {
|
|
129
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
130
|
+
var stream;
|
|
131
|
+
return __generator(this, function (_a) {
|
|
132
|
+
stream = stream_1.Readable.from(buffer.toString('utf-8'), { encoding: 'utf8' });
|
|
133
|
+
return [2 /*return*/, this.readCsvFromStream(stream, columnsToProps)];
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
CSVModule_Class.prototype.readCsvFromStream = function (stream, columnsToProps) {
|
|
138
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
139
|
+
var _this = this;
|
|
140
|
+
return __generator(this, function (_a) {
|
|
141
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
142
|
+
var results = [];
|
|
143
|
+
stream
|
|
144
|
+
.pipe(csvParser(_this.createReadParserOptions(columnsToProps)))
|
|
145
|
+
.on('data', function (instance) {
|
|
146
|
+
delete instance['undefined'];
|
|
147
|
+
results.push(instance);
|
|
148
|
+
})
|
|
149
|
+
.on('error', function (err) { return reject(err); })
|
|
150
|
+
.on('end', function () { return resolve(results); });
|
|
151
|
+
})];
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
CSVModule_Class.prototype.createReadParserOptions = function (columnsToProps) {
|
|
156
|
+
return {
|
|
157
|
+
mapHeaders: function (args) {
|
|
158
|
+
return (columnsToProps === null || columnsToProps === void 0 ? void 0 : columnsToProps[args.header]) || args.header;
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
return CSVModule_Class;
|
|
163
|
+
}(module_1.Module));
|
|
164
|
+
exports.CSVModule = new CSVModule_Class();
|
|
165
|
+
//# sourceMappingURL=CSVModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CSVModule.js","sourceRoot":"","sources":["../../src/main/modules/CSVModule.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH;;GAEG;AAEH,+CAAmD;AACnD,yBAAoD;AAEpD,yCAAsC;AACtC,iCAAgC;AAChC,sCAAyC;AAOzC,IAAM,aAAa,GAAG;IACrB,OAAO,EAAE;QACR,cAAc,EAAE,GAAG;QACnB,YAAY,EAAE,GAAG;QACjB,gBAAgB,EAAE,GAAG;QACrB,UAAU,EAAE,IAAI;QAChB,SAAS,EAAE,IAAI;QACf,KAAK,EAAE,iBAAiB;QACxB,WAAW,EAAE,KAAK;QAClB,MAAM,EAAE,IAAI;QACZ,gBAAgB,EAAE,IAAI;KACtB;CACD,CAAC;AASF;IACS,mCAAc;IAItB;QAAA,YACC,iBAAO,SAGP;QADA,KAAI,CAAC,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;;;gBACvG,sBAAO,IAAI,OAAO,CAAM,UAAC,OAAO,EAAE,MAAM;wBACvC,IAAM,OAAO,GAAQ,EAAE,CAAC;wBAExB,MAAM;6BACJ,IAAI,CAAC,SAAS,CAAC,KAAI,CAAC,uBAAuB,CAAC,cAAc,CAAC,CAAC,CAAC;6BAC7D,EAAE,CAAC,MAAM,EAAE,UAAC,QAAQ;4BACpB,OAAO,QAAQ,CAAC,WAAW,CAAC,CAAC;4BAC7B,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;wBACxB,CAAC,CAAC;6BACD,EAAE,CAAC,OAAO,EAAE,UAAC,GAAG,IAAK,OAAA,MAAM,CAAC,GAAG,CAAC,EAAX,CAAW,CAAC;6BACjC,EAAE,CAAC,KAAK,EAAE,cAAM,OAAA,OAAO,CAAC,OAAO,CAAC,EAAhB,CAAgB,CAAC,CAAC;oBACrC,CAAC,CAAC,EAAC;;;KACH;IAEO,iDAAuB,GAA/B,UAAqD,cAAgC;QACpF,OAAO;YACN,UAAU,EAAE,UAAC,IAAwB;gBACpC,OAAO,CAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAG,IAAI,CAAC,MAAM,CAAW,KAAI,IAAI,CAAC,MAAM,CAAC;YAC/D,CAAC;SACD,CAAC;IACH,CAAC;IACF,sBAAC;AAAD,CAAC,AA5DD,CACS,eAAM,GA2Dd;AAEY,QAAA,SAAS,GAAG,IAAI,eAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Module } from '../core/module';
|
|
2
|
+
import { TypedMap } from '../utils/types';
|
|
3
|
+
export type CliParam<K, T extends string | string[] = string> = {
|
|
4
|
+
keys: string[];
|
|
5
|
+
name: string;
|
|
6
|
+
keyName: K;
|
|
7
|
+
optional?: true;
|
|
8
|
+
options?: string[];
|
|
9
|
+
defaultValue?: T;
|
|
10
|
+
isArray?: T extends string[] ? true : never;
|
|
11
|
+
process?: (value: T) => T;
|
|
12
|
+
};
|
|
13
|
+
type Param = CliParam<string> | CliParam<string, string[]>;
|
|
14
|
+
type Config = {
|
|
15
|
+
params: Param[];
|
|
16
|
+
};
|
|
17
|
+
declare class CliParamsModule_Class extends Module<Config> {
|
|
18
|
+
private paramsValue;
|
|
19
|
+
init(): TypedMap<string | string[] | undefined>;
|
|
20
|
+
getParam<T extends string | string[]>(param: CliParam<string, T>, args?: string[]): T;
|
|
21
|
+
private extractParam;
|
|
22
|
+
printHowTo: (params: Param[]) => void;
|
|
23
|
+
private printFoundArgs;
|
|
24
|
+
getParams: () => TypedMap<string | string[] | undefined>;
|
|
25
|
+
}
|
|
26
|
+
export declare const CliParamsModule: CliParamsModule_Class;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* ts-common is the basic building blocks of our typescript projects
|
|
4
|
+
*
|
|
5
|
+
* Copyright (C) 2020 Adam van der Kruk aka TacB0sS
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.CliParamsModule = void 0;
|
|
36
|
+
var module_1 = require("../core/module");
|
|
37
|
+
var exceptions_1 = require("../core/exceptions");
|
|
38
|
+
var __1 = require("..");
|
|
39
|
+
var CliParamsModule_Class = /** @class */ (function (_super) {
|
|
40
|
+
__extends(CliParamsModule_Class, _super);
|
|
41
|
+
function CliParamsModule_Class() {
|
|
42
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
43
|
+
_this.paramsValue = {};
|
|
44
|
+
_this.printHowTo = function (params) {
|
|
45
|
+
var missingParams = params.filter(function (param) { return !_this.paramsValue[param.keyName] && !param.optional; });
|
|
46
|
+
var foundParams = params.filter(function (param) { return _this.paramsValue[param.keyName]; });
|
|
47
|
+
_this.printFoundArgs('Found Args', foundParams, _this.paramsValue);
|
|
48
|
+
if (missingParams.length === 0)
|
|
49
|
+
return;
|
|
50
|
+
_this.printFoundArgs('Missing Args', missingParams, _this.paramsValue);
|
|
51
|
+
throw new exceptions_1.ImplementationMissingException('Missing cli params');
|
|
52
|
+
};
|
|
53
|
+
_this.getParams = function () {
|
|
54
|
+
return _this.paramsValue;
|
|
55
|
+
};
|
|
56
|
+
return _this;
|
|
57
|
+
}
|
|
58
|
+
CliParamsModule_Class.prototype.init = function () {
|
|
59
|
+
var _this = this;
|
|
60
|
+
this.config.params.forEach(function (param) { return _this.paramsValue[param.keyName] = _this.getParam(param); });
|
|
61
|
+
this.printHowTo(this.config.params);
|
|
62
|
+
return this.paramsValue;
|
|
63
|
+
};
|
|
64
|
+
CliParamsModule_Class.prototype.getParam = function (param, args) {
|
|
65
|
+
if (args === void 0) { args = process.argv.slice(2, process.argv.length); }
|
|
66
|
+
if (!this.config.params.find(function (_param) { return _param.keyName === param.keyName; }))
|
|
67
|
+
throw new exceptions_1.BadImplementationException('Requested not existing param');
|
|
68
|
+
var value = this.extractParam(param, args);
|
|
69
|
+
if (!value)
|
|
70
|
+
value = param.defaultValue;
|
|
71
|
+
if (!value)
|
|
72
|
+
return value;
|
|
73
|
+
return (param.process ? param.process(value) : value);
|
|
74
|
+
};
|
|
75
|
+
CliParamsModule_Class.prototype.extractParam = function (param, argv) {
|
|
76
|
+
if (param.isArray)
|
|
77
|
+
return param.keys.reduce(function (values, key) {
|
|
78
|
+
values.push.apply(values, (0, __1.filterInstances)(argv.map(function (arg) { var _a; return (_a = arg.match(new RegExp("".concat(key, "=(.*)")))) === null || _a === void 0 ? void 0 : _a[1]; })));
|
|
79
|
+
return values;
|
|
80
|
+
}, []);
|
|
81
|
+
var find = param.keys.map(function (key) { return argv.map(function (arg) { var _a; return (_a = arg.match(new RegExp("".concat(key, "=(.*)")))) === null || _a === void 0 ? void 0 : _a[1]; }); });
|
|
82
|
+
return (0, __1.flatArray)(find).find(function (k) { return k; });
|
|
83
|
+
};
|
|
84
|
+
CliParamsModule_Class.prototype.printFoundArgs = function (title, params, foundArgs) {
|
|
85
|
+
var _this = this;
|
|
86
|
+
if (params.length)
|
|
87
|
+
return;
|
|
88
|
+
this.logInfoBold(" ".concat(title, ":"));
|
|
89
|
+
params.forEach(function (param) { return _this.logInfo(" ".concat(param.keys[0], "=").concat(foundArgs[param.keyName] || "<".concat(param.name, ">"))); });
|
|
90
|
+
};
|
|
91
|
+
return CliParamsModule_Class;
|
|
92
|
+
}(module_1.Module));
|
|
93
|
+
exports.CliParamsModule = new CliParamsModule_Class();
|
|
94
|
+
//# sourceMappingURL=CliParamsModule.js.map
|
|
@@ -0,0 +1 @@
|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MAAM,CAAC;YACf,CAAC,EAAE,EAAE,CAAC,CAAC;QAER,IAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,UAAA,GAAG,IAAI,OAAA,IAAI,CAAC,GAAG,CAAC,UAAA,GAAG,YAAI,OAAA,MAAA,GAAG,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,UAAG,GAAG,UAAO,CAAC,CAAC,0CAAG,CAAC,CAAC,CAAA,EAAA,CAAC,EAA1D,CAA0D,CAAC,CAAC;QAC/F,OAAO,IAAA,aAAS,EAAC,IAAI,CAAC,CAAC,IAAI,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,EAAD,CAAC,CAAC,CAAC;IACrC,CAAC;IAcO,8CAAc,GAAtB,UAAuB,KAAa,EAAE,MAAe,EAAE,SAAoB;QAA3E,iBAMC;QALA,IAAI,MAAM,CAAC,MAAM;YAChB,OAAO;QAER,IAAI,CAAC,WAAW,CAAC,YAAK,KAAK,MAAG,CAAC,CAAC;QAChC,MAAM,CAAC,OAAO,CAAC,UAAC,KAAK,IAAK,OAAA,KAAI,CAAC,OAAO,CAAC,cAAO,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,cAAI,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,WAAI,KAAK,CAAC,IAAI,MAAG,CAAE,CAAC,EAArF,CAAqF,CAAC,CAAC;IAClH,CAAC;IAKF,4BAAC;AAAD,CAAC,AA3DD,CACS,eAAM,GA0Dd;AAEY,QAAA,eAAe,GAAG,IAAI,qBAAqB,EAAE,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TS_Object } from '../utils/types';
|
|
2
|
+
export type CSVProps<T extends TS_Object = TS_Object> = {
|
|
3
|
+
decimalSeparator?: string;
|
|
4
|
+
withHeaders?: boolean;
|
|
5
|
+
fieldWrapper?: string;
|
|
6
|
+
lineSeparator?: string;
|
|
7
|
+
fieldSeparator?: string;
|
|
8
|
+
columnNames?: ((key: keyof T) => string);
|
|
9
|
+
columns: (keyof T)[];
|
|
10
|
+
};
|
|
11
|
+
export declare function csvSerializer<T extends TS_Object = TS_Object>(items: T[], _csvProps: CSVProps<T>): string;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* ts-common is the basic building blocks of our typescript projects
|
|
4
|
+
*
|
|
5
|
+
* Copyright (C) 2020 Adam van der Kruk aka TacB0sS
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
exports.csvSerializer = void 0;
|
|
32
|
+
function csvSerializer(items, _csvProps) {
|
|
33
|
+
var csvProps = __assign({ decimalSeparator: '.', withHeaders: true, fieldWrapper: '"', lineSeparator: '\n', fieldSeparator: ',', columnNames: function (k) { return k.toString(); } }, _csvProps);
|
|
34
|
+
function processValue(value) {
|
|
35
|
+
var escapedValue = (value.toString() || '').replace(csvProps.fieldWrapper, "\\".concat(csvProps.fieldWrapper));
|
|
36
|
+
if (escapedValue.includes(csvProps.lineSeparator) || escapedValue.includes(csvProps.fieldSeparator))
|
|
37
|
+
escapedValue = "".concat(csvProps.fieldWrapper).concat(escapedValue).concat(csvProps.fieldWrapper);
|
|
38
|
+
return "".concat(escapedValue).concat(csvProps.fieldSeparator);
|
|
39
|
+
}
|
|
40
|
+
var outputRows = [];
|
|
41
|
+
var columnsByOrder = csvProps.columns.map(function (c) { return c.toString(); });
|
|
42
|
+
var headersLine = columnsByOrder.reduce(function (output, header) { return "".concat(output).concat(processValue(csvProps.columnNames(header))); }, '').slice(0, -1);
|
|
43
|
+
if (csvProps.withHeaders)
|
|
44
|
+
outputRows.push(headersLine);
|
|
45
|
+
var rowsData = items.map(function (row) { return columnsByOrder.reduce(function (output, header) { return "".concat(output).concat(processValue(row[header])); }, '').slice(0, -1); });
|
|
46
|
+
outputRows.push.apply(outputRows, rowsData);
|
|
47
|
+
return outputRows.reduce(function (content, row) { return "".concat(content).concat(row).concat(csvProps.lineSeparator); }, '').slice(0, -1);
|
|
48
|
+
}
|
|
49
|
+
exports.csvSerializer = csvSerializer;
|
|
50
|
+
//# sourceMappingURL=csv-serializer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csv-serializer.js","sourceRoot":"","sources":["../../src/main/modules/csv-serializer.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;;;;;;;;;;;;AAeH,SAAgB,aAAa,CAAkC,KAAU,EAAE,SAAsB;IAChG,IAAM,QAAQ,cACb,gBAAgB,EAAE,GAAG,EACrB,WAAW,EAAE,IAAI,EACjB,YAAY,EAAE,GAAG,EACjB,aAAa,EAAE,IAAI,EACnB,cAAc,EAAE,GAAG,EACnB,WAAW,EAAE,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,QAAQ,EAAE,EAAZ,CAAY,IAC7B,SAA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C,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAnG,CAAmG,CAAC,CAAC;IACzI,UAAU,CAAC,IAAI,OAAf,UAAU,EAAS,QAAQ,EAAE;IAE7B,OAAO,UAAU,CAAC,MAAM,CAAC,UAAC,OAAO,EAAE,GAAG,IAAK,OAAA,UAAG,OAAO,SAAG,GAAG,SAAG,QAAQ,CAAC,aAAa,CAAE,EAA3C,CAA2C,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAC1G,CAAC;AA9BD,sCA8BC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nu-art/ts-common",
|
|
3
|
-
"version": "0.105.
|
|
3
|
+
"version": "0.105.1",
|
|
4
4
|
"description": "js and ts infra",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"TacB0sS",
|
|
@@ -18,13 +18,10 @@
|
|
|
18
18
|
"type": "git",
|
|
19
19
|
"url": "git+ssh://git@github.com:nu-art-js/ts-common.git"
|
|
20
20
|
},
|
|
21
|
-
"files": [
|
|
22
|
-
"dist"
|
|
23
|
-
],
|
|
24
21
|
"license": "Apache-2.0",
|
|
25
22
|
"author": "TacB0sS",
|
|
26
|
-
"main": "
|
|
27
|
-
"types": "
|
|
23
|
+
"main": "index.js",
|
|
24
|
+
"types": "index.d.ts",
|
|
28
25
|
"scripts": {
|
|
29
26
|
"build": "tsc",
|
|
30
27
|
"typedocs": "typedoc --options typedoc.json",
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare class PermissionCategory<P extends number> {
|
|
2
|
+
readonly key: string;
|
|
3
|
+
readonly levels: string[];
|
|
4
|
+
readonly permissionsEnum: any;
|
|
5
|
+
readonly defaultValue: P;
|
|
6
|
+
constructor(key: string, permissionsEnum: any, defaultValue: P);
|
|
7
|
+
getClosestMatch(permission: number): string | undefined;
|
|
8
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PermissionCategory = void 0;
|
|
4
|
+
/*
|
|
5
|
+
* ts-common is the basic building blocks of our typescript projects
|
|
6
|
+
*
|
|
7
|
+
* Copyright (C) 2020 Adam van der Kruk aka TacB0sS
|
|
8
|
+
*
|
|
9
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
+
* you may not use this file except in compliance with the License.
|
|
11
|
+
* You may obtain a copy of the License at
|
|
12
|
+
*
|
|
13
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
+
*
|
|
15
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
16
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
+
* See the License for the specific language governing permissions and
|
|
19
|
+
* limitations under the License.
|
|
20
|
+
*/
|
|
21
|
+
var index_1 = require("../index");
|
|
22
|
+
var PermissionCategory = /** @class */ (function () {
|
|
23
|
+
function PermissionCategory(key, permissionsEnum, defaultValue) {
|
|
24
|
+
this.key = key;
|
|
25
|
+
this.permissionsEnum = permissionsEnum;
|
|
26
|
+
this.defaultValue = defaultValue;
|
|
27
|
+
var _levels = Object.keys(permissionsEnum).filter(function (value) { return isNaN(parseInt(value)); });
|
|
28
|
+
this.levels = (0, index_1.sortArray)(_levels, function (_key) { return permissionsEnum[_key]; }).reverse();
|
|
29
|
+
}
|
|
30
|
+
PermissionCategory.prototype.getClosestMatch = function (permission) {
|
|
31
|
+
var _this = this;
|
|
32
|
+
return (0, index_1.deepClone)(this.levels).reverse().find((function (level) { return _this.permissionsEnum[level] <= permission; }));
|
|
33
|
+
};
|
|
34
|
+
return PermissionCategory;
|
|
35
|
+
}());
|
|
36
|
+
exports.PermissionCategory = PermissionCategory;
|
|
37
|
+
//# sourceMappingURL=permission-group.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permission-group.js","sourceRoot":"","sources":["../../src/main/permissions/permission-group.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,kCAGkB;AAElB;IAMC,4BAAY,GAAW,EAAE,eAAoB,EAAE,YAAe;QAC7D,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QAEjC,IAAM,OAAO,GAAa,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAtB,CAAsB,CAAC,CAAC;QAC/F,IAAI,CAAC,MAAM,GAAG,IAAA,iBAAS,EAAC,OAAO,EAAE,UAAC,IAAY,IAAK,OAAA,eAAe,CAAC,IAAI,CAAC,EAArB,CAAqB,CAAC,CAAC,OAAO,EAAE,CAAC;IACrF,CAAC;IAED,4CAAe,GAAf,UAAgB,UAAkB;QAAlC,iBAEC;QADA,OAAO,IAAA,iBAAS,EAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC,UAAC,KAAa,IAAK,OAAA,KAAI,CAAC,eAAe,CAAC,KAAK,CAAC,IAAI,UAAU,EAAzC,CAAyC,CAAC,CAAC,CAAA;IAC7G,CAAC;IACF,yBAAC;AAAD,CAAC,AAlBD,IAkBC;AAlBY,gDAAkB"}
|
package/test-index.d.ts
ADDED
package/test-index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./testing/types"), exports);
|
|
18
|
+
__exportStar(require("./testing/consts"), exports);
|
|
19
|
+
//# sourceMappingURL=test-index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-index.js","sourceRoot":"","sources":["../src/main/test-index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,mDAAiC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="chai" />
|
|
2
|
+
/// <reference types="chai-as-promised" />
|
|
3
|
+
import { TestSuite } from './types';
|
|
4
|
+
export declare const testSuiteTester: <Input, ExpectedResult>(testSuit: TestSuite<Input, ExpectedResult>) => void;
|
|
5
|
+
export declare const expectFailAsync: (action: () => Promise<void>) => Promise<Chai.Assertion>;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.expectFailAsync = exports.testSuiteTester = void 0;
|
|
40
|
+
var chai_1 = require("chai");
|
|
41
|
+
var __1 = require("..");
|
|
42
|
+
var testSuiteTester = function (testSuit) {
|
|
43
|
+
describe(testSuit.label, function () {
|
|
44
|
+
//Run pre-process
|
|
45
|
+
if (testSuit.preProcessor) {
|
|
46
|
+
it("".concat(testSuit.label, " - Preprocessing"), testSuit.preProcessor);
|
|
47
|
+
}
|
|
48
|
+
testSuit.testcases.forEach(function (testCase) {
|
|
49
|
+
it(testCase.description, function () { return testSuit.processor(testCase); });
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
exports.testSuiteTester = testSuiteTester;
|
|
54
|
+
var expectFailAsync = function (action) { return __awaiter(void 0, void 0, void 0, function () {
|
|
55
|
+
var e_1;
|
|
56
|
+
return __generator(this, function (_a) {
|
|
57
|
+
switch (_a.label) {
|
|
58
|
+
case 0:
|
|
59
|
+
_a.trys.push([0, 2, , 3]);
|
|
60
|
+
return [4 /*yield*/, action()];
|
|
61
|
+
case 1:
|
|
62
|
+
_a.sent();
|
|
63
|
+
return [2 /*return*/, (0, chai_1.expect)(__1.voidFunction)];
|
|
64
|
+
case 2:
|
|
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
|
+
}); };
|
|
73
|
+
exports.expectFailAsync = expectFailAsync;
|
|
74
|
+
//# sourceMappingURL=consts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../../src/main/testing/consts.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,6BAA4B;AAC5B,wBAAgC;AAEzB,IAAM,eAAe,GAAG,UAAwB,QAA0C;IAChG,QAAQ,CAAC,QAAQ,CAAC,KAAK,EAAE;QACxB,iBAAiB;QACjB,IAAI,QAAQ,CAAC,YAAY,EAAE;YAC1B,EAAE,CAAC,UAAG,QAAQ,CAAC,KAAK,qBAAkB,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;SAC/D;QAED,QAAQ,CAAC,SAAS,CAAC,OAAO,CAAC,UAAA,QAAQ;YAClC,EAAE,CAAC,QAAQ,CAAC,WAAW,EAAG,cAAM,OAAA,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAC,EAA5B,CAA4B,CAAC,CAAC;QAC/D,CAAC,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC;AAXW,QAAA,eAAe,mBAW1B;AAEK,IAAM,eAAe,GAAG,UAAO,MAA2B;;;;;;gBAE/D,qBAAM,MAAM,EAAE,EAAA;;gBAAd,SAAc,CAAC;gBACf,sBAAO,IAAA,aAAM,EAAC,gBAAY,CAAC,EAAC;;;gBAE5B,sBAAO,IAAA,aAAM,EAAC;wBACb,MAAM,GAAC,CAAC;oBACT,CAAC,CAAC,EAAC;;;;KAEJ,CAAC;AATW,QAAA,eAAe,mBAS1B"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type Types<Input, Result> = {
|
|
2
|
+
expected?: Result;
|
|
3
|
+
input: Input;
|
|
4
|
+
};
|
|
5
|
+
export type TestModel<Input, ExpectedResult> = {
|
|
6
|
+
description: string;
|
|
7
|
+
result: ExpectedResult;
|
|
8
|
+
input: Input;
|
|
9
|
+
};
|
|
10
|
+
export type TestProcessor<Input, ExpectedResult> = (input: TestModel<Input, ExpectedResult>) => void | Promise<void>;
|
|
11
|
+
export type TestSuite<Input, ExpectedResult> = {
|
|
12
|
+
preProcessor?: () => (void | Promise<void>);
|
|
13
|
+
processor: TestProcessor<Input, ExpectedResult>;
|
|
14
|
+
testcases: TestModel<Input, ExpectedResult>[];
|
|
15
|
+
label: string;
|
|
16
|
+
};
|
package/testing/types.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* ts-common is the basic building blocks of our typescript projects
|
|
4
|
+
*
|
|
5
|
+
* Copyright (C) 2020 Adam van der Kruk aka TacB0sS
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/main/testing/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Logger } from '../core/logger/Logger';
|
|
2
|
+
import { KeyValue, TS_Object } from '../utils/types';
|
|
3
|
+
export declare class Replacer extends Logger {
|
|
4
|
+
private strictMode;
|
|
5
|
+
private static RuntimeParam;
|
|
6
|
+
private static Indicator_RuntimeParam;
|
|
7
|
+
private static Regexp_paramGroup;
|
|
8
|
+
private static Regexp_param;
|
|
9
|
+
private static Regexp_forLoopGroupStart;
|
|
10
|
+
private static Regexp_forLoopParam;
|
|
11
|
+
private input;
|
|
12
|
+
private aliases;
|
|
13
|
+
private fallbackReplacer?;
|
|
14
|
+
constructor();
|
|
15
|
+
setFallbackReplacer(fallbackReplacer?: Replacer): this;
|
|
16
|
+
setNotStrict(): this;
|
|
17
|
+
getInput(): TS_Object;
|
|
18
|
+
setInput(input: TS_Object, aliases?: KeyValue[]): this;
|
|
19
|
+
replace(_content?: string, runtime?: TS_Object): string;
|
|
20
|
+
private replaceParams;
|
|
21
|
+
private resolveParam;
|
|
22
|
+
private replaceLoops;
|
|
23
|
+
private resolveParamValue;
|
|
24
|
+
}
|