@zajno/common 1.4.17 → 1.4.18
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/coverage/clover.xml +25 -23
- package/coverage/coverage-final.json +2 -2
- package/coverage/lcov-report/index.html +15 -15
- package/coverage/lcov-report/src/__tests__/helpers/index.html +1 -1
- package/coverage/lcov-report/src/__tests__/helpers/main.ts.html +1 -1
- package/coverage/lcov-report/src/async/arrays.ts.html +1 -1
- package/coverage/lcov-report/src/async/index.html +1 -1
- package/coverage/lcov-report/src/async/timeout.ts.html +1 -1
- package/coverage/lcov-report/src/cache.ts.html +1 -1
- package/coverage/lcov-report/src/dates/calc.ts.html +1 -1
- package/coverage/lcov-report/src/dates/convert.ts.html +1 -1
- package/coverage/lcov-report/src/dates/datex.ts.html +1 -1
- package/coverage/lcov-report/src/dates/format.ts.html +1 -1
- package/coverage/lcov-report/src/dates/index.html +1 -1
- package/coverage/lcov-report/src/dates/index.ts.html +1 -1
- package/coverage/lcov-report/src/dates/parse.ts.html +1 -1
- package/coverage/lcov-report/src/dates/period.ts.html +1 -1
- package/coverage/lcov-report/src/dates/shift.ts.html +1 -1
- package/coverage/lcov-report/src/dates/types.ts.html +1 -1
- package/coverage/lcov-report/src/dates/yearDate.ts.html +1 -1
- package/coverage/lcov-report/src/disposer.ts.html +1 -1
- package/coverage/lcov-report/src/enumHelper.ts.html +1 -1
- package/coverage/lcov-report/src/event.ts.html +1 -1
- package/coverage/lcov-report/src/fields/index.html +1 -1
- package/coverage/lcov-report/src/fields/update.ts.html +1 -1
- package/coverage/lcov-report/src/functions.ts.html +1 -1
- package/coverage/lcov-report/src/index.html +1 -1
- package/coverage/lcov-report/src/lazy.light.ts.html +1 -1
- package/coverage/lcov-report/src/logger/batch.ts.html +1 -1
- package/coverage/lcov-report/src/logger/console.ts.html +1 -1
- package/coverage/lcov-report/src/logger/index.html +1 -1
- package/coverage/lcov-report/src/logger/index.ts.html +1 -1
- package/coverage/lcov-report/src/logger/named.ts.html +1 -1
- package/coverage/lcov-report/src/logger/proxy.ts.html +1 -1
- package/coverage/lcov-report/src/math/arrays.ts.html +1 -1
- package/coverage/lcov-report/src/math/calc.ts.html +1 -1
- package/coverage/lcov-report/src/math/distribution.ts.html +1 -1
- package/coverage/lcov-report/src/math/index.html +1 -1
- package/coverage/lcov-report/src/math/index.ts.html +1 -1
- package/coverage/lcov-report/src/observersMap.ts.html +1 -1
- package/coverage/lcov-report/src/observingCache.ts.html +1 -1
- package/coverage/lcov-report/src/tempoCache.ts.html +1 -1
- package/coverage/lcov-report/src/transitionObserver.ts.html +1 -1
- package/coverage/lcov-report/src/types.ts.html +1 -1
- package/coverage/lcov-report/src/validation/ValidationErrors.ts.html +1 -1
- package/coverage/lcov-report/src/validation/creditCard.ts.html +1 -1
- package/coverage/lcov-report/src/validation/helpers.ts.html +32 -38
- package/coverage/lcov-report/src/validation/index.html +14 -14
- package/coverage/lcov-report/src/validation/index.ts.html +1 -1
- package/coverage/lcov-report/src/validation/types.ts.html +13 -4
- package/coverage/lcov-report/src/validation/validators.ts.html +1 -1
- package/coverage/lcov-report/src/validation/wrappers.ts.html +1 -1
- package/coverage/lcov-report/src/viewModels/CommonModel.ts.html +1 -1
- package/coverage/lcov-report/src/viewModels/FlagModel.ts.html +1 -1
- package/coverage/lcov-report/src/viewModels/LoadingModel.ts.html +1 -1
- package/coverage/lcov-report/src/viewModels/MultiSelectModel.ts.html +1 -1
- package/coverage/lcov-report/src/viewModels/NumberModel.ts.html +1 -1
- package/coverage/lcov-report/src/viewModels/SelectModel.ts.html +1 -1
- package/coverage/lcov-report/src/viewModels/TextModel.ts.html +1 -1
- package/coverage/lcov-report/src/viewModels/Validatable.ts.html +1 -1
- package/coverage/lcov-report/src/viewModels/index.html +1 -1
- package/coverage/lcov-report/src/viewModels/wrappers.ts.html +1 -1
- package/coverage/lcov.info +39 -32
- package/lib/logger/file.d.ts +9 -8
- package/lib/logger/file.d.ts.map +1 -1
- package/lib/logger/file.js +44 -22
- package/lib/logger/file.js.map +1 -1
- package/lib/validation/helpers.d.ts +2 -6
- package/lib/validation/helpers.d.ts.map +1 -1
- package/lib/validation/helpers.js +6 -11
- package/lib/validation/helpers.js.map +1 -1
- package/lib/validation/types.d.ts +8 -2
- package/lib/validation/types.d.ts.map +1 -1
- package/lib/validation/types.js.map +1 -1
- package/lib/validation/wrappers.d.ts +3 -3
- package/package.json +1 -1
- package/src/logger/file.ts +46 -26
- package/src/validation/helpers.ts +16 -18
- package/src/validation/types.ts +5 -2
package/coverage/lcov.info
CHANGED
|
@@ -2941,11 +2941,11 @@ BRH:0
|
|
|
2941
2941
|
end_of_record
|
|
2942
2942
|
TN:
|
|
2943
2943
|
SF:src/validation/helpers.ts
|
|
2944
|
-
FN:
|
|
2945
|
-
FN:
|
|
2946
|
-
FN:
|
|
2947
|
-
FN:
|
|
2948
|
-
FN:
|
|
2944
|
+
FN:9,createShouldBeEqualTo
|
|
2945
|
+
FN:10,(anonymous_1)
|
|
2946
|
+
FN:13,throwNotOk
|
|
2947
|
+
FN:19,validateObject
|
|
2948
|
+
FN:27,(anonymous_4)
|
|
2949
2949
|
FNF:5
|
|
2950
2950
|
FNH:0
|
|
2951
2951
|
FNDA:0,createShouldBeEqualTo
|
|
@@ -2955,35 +2955,42 @@ FNDA:0,validateObject
|
|
|
2955
2955
|
FNDA:0,(anonymous_4)
|
|
2956
2956
|
DA:1,5
|
|
2957
2957
|
DA:2,5
|
|
2958
|
-
DA:
|
|
2959
|
-
DA:5,0
|
|
2960
|
-
DA:8,5
|
|
2961
|
-
DA:9,0
|
|
2958
|
+
DA:9,5
|
|
2962
2959
|
DA:10,0
|
|
2963
|
-
DA:
|
|
2964
|
-
DA:
|
|
2965
|
-
DA:
|
|
2966
|
-
DA:
|
|
2967
|
-
DA:23,0
|
|
2968
|
-
DA:24,0
|
|
2960
|
+
DA:13,5
|
|
2961
|
+
DA:14,0
|
|
2962
|
+
DA:15,0
|
|
2963
|
+
DA:19,5
|
|
2969
2964
|
DA:25,0
|
|
2965
|
+
DA:27,0
|
|
2970
2966
|
DA:28,0
|
|
2967
|
+
DA:29,0
|
|
2968
|
+
DA:30,0
|
|
2969
|
+
DA:31,0
|
|
2970
|
+
DA:34,0
|
|
2971
|
+
DA:35,0
|
|
2972
|
+
DA:36,0
|
|
2973
|
+
DA:39,0
|
|
2971
2974
|
DA:40,0
|
|
2972
2975
|
DA:41,0
|
|
2973
|
-
DA:
|
|
2974
|
-
|
|
2975
|
-
LF:19
|
|
2976
|
+
DA:45,0
|
|
2977
|
+
LF:21
|
|
2976
2978
|
LH:5
|
|
2977
|
-
BRDA:
|
|
2978
|
-
BRDA:
|
|
2979
|
-
BRDA:
|
|
2980
|
-
BRDA:
|
|
2981
|
-
BRDA:
|
|
2982
|
-
BRDA:
|
|
2983
|
-
BRDA:
|
|
2984
|
-
BRDA:
|
|
2985
|
-
BRDA:
|
|
2986
|
-
|
|
2979
|
+
BRDA:10,0,0,0
|
|
2980
|
+
BRDA:10,0,1,0
|
|
2981
|
+
BRDA:13,1,0,0
|
|
2982
|
+
BRDA:14,2,0,0
|
|
2983
|
+
BRDA:14,2,1,0
|
|
2984
|
+
BRDA:22,3,0,0
|
|
2985
|
+
BRDA:30,4,0,0
|
|
2986
|
+
BRDA:30,4,1,0
|
|
2987
|
+
BRDA:35,5,0,0
|
|
2988
|
+
BRDA:35,5,1,0
|
|
2989
|
+
BRDA:35,6,0,0
|
|
2990
|
+
BRDA:35,6,1,0
|
|
2991
|
+
BRDA:40,7,0,0
|
|
2992
|
+
BRDA:40,7,1,0
|
|
2993
|
+
BRF:14
|
|
2987
2994
|
BRH:0
|
|
2988
2995
|
end_of_record
|
|
2989
2996
|
TN:
|
|
@@ -3002,14 +3009,14 @@ BRH:0
|
|
|
3002
3009
|
end_of_record
|
|
3003
3010
|
TN:
|
|
3004
3011
|
SF:src/validation/types.ts
|
|
3005
|
-
FN:
|
|
3012
|
+
FN:14,(anonymous_0)
|
|
3006
3013
|
FNF:1
|
|
3007
3014
|
FNH:1
|
|
3008
3015
|
FNDA:2,(anonymous_0)
|
|
3009
|
-
DA:
|
|
3010
|
-
DA:9,2
|
|
3016
|
+
DA:11,5
|
|
3011
3017
|
DA:12,2
|
|
3012
|
-
DA:
|
|
3018
|
+
DA:15,2
|
|
3019
|
+
DA:16,2
|
|
3013
3020
|
LF:4
|
|
3014
3021
|
LH:4
|
|
3015
3022
|
BRF:0
|
package/lib/logger/file.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { ILogger } from './abstractions';
|
|
2
|
-
import { Getter } from '../types';
|
|
3
2
|
export declare class FileLoggerNode implements ILogger {
|
|
4
|
-
readonly
|
|
3
|
+
readonly extraLogger: ILogger;
|
|
4
|
+
readonly instantFlush: boolean;
|
|
5
5
|
private readonly _buffer;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
private _logFilePath;
|
|
7
|
+
constructor(extraLogger?: ILogger, instantFlush?: boolean);
|
|
8
|
+
setLogFilePath(path: string): this;
|
|
9
|
+
setLogName(name: string): this;
|
|
10
|
+
private append;
|
|
9
11
|
log: (...args: any[]) => void;
|
|
10
|
-
warn(...args: any[])
|
|
11
|
-
error(...args: any[])
|
|
12
|
+
warn: (...args: any[]) => void;
|
|
13
|
+
error: (...args: any[]) => void;
|
|
12
14
|
flush(): void;
|
|
13
|
-
private appendToFile;
|
|
14
15
|
}
|
|
15
16
|
//# sourceMappingURL=file.d.ts.map
|
package/lib/logger/file.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/logger/file.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/logger/file.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,qBAAa,cAAe,YAAW,OAAO;IAI9B,QAAQ,CAAC,WAAW,EAAE,OAAO;IAAY,QAAQ,CAAC,YAAY;IAH1E,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgB;IACxC,OAAO,CAAC,YAAY,CAAgB;gBAEf,WAAW,GAAE,OAAiB,EAAW,YAAY,UAAQ;IAIlF,cAAc,CAAC,IAAI,EAAE,MAAM;IAK3B,UAAU,CAAC,IAAI,EAAE,MAAM;IAMvB,OAAO,CAAC,MAAM;IAUd,GAAG,YAAa,GAAG,EAAE,UAGnB;IAEF,IAAI,YAAa,GAAG,EAAE,UAGpB;IAEF,KAAK,YAAa,GAAG,EAAE,UAGrB;IAEF,KAAK;CAaR"}
|
package/lib/logger/file.js
CHANGED
|
@@ -2,40 +2,62 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FileLoggerNode = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
/* eslint-disable no-console */
|
|
6
|
+
const Path = tslib_1.__importStar(require("path"));
|
|
5
7
|
const FS = tslib_1.__importStar(require("fs"));
|
|
6
8
|
const Util = tslib_1.__importStar(require("util"));
|
|
7
|
-
const types_1 = require("../types");
|
|
8
9
|
class FileLoggerNode {
|
|
9
|
-
constructor(
|
|
10
|
-
this.
|
|
10
|
+
constructor(extraLogger = console, instantFlush = false) {
|
|
11
|
+
this.extraLogger = extraLogger;
|
|
12
|
+
this.instantFlush = instantFlush;
|
|
13
|
+
this._buffer = [];
|
|
14
|
+
this._logFilePath = null;
|
|
11
15
|
this.log = (...args) => {
|
|
12
|
-
|
|
16
|
+
var _a;
|
|
17
|
+
(_a = this.extraLogger) === null || _a === void 0 ? void 0 : _a.log(...args);
|
|
18
|
+
this.append(...args);
|
|
13
19
|
};
|
|
14
|
-
this.
|
|
20
|
+
this.warn = (...args) => {
|
|
21
|
+
var _a;
|
|
22
|
+
(_a = this.extraLogger) === null || _a === void 0 ? void 0 : _a.warn(...args);
|
|
23
|
+
this.append(...args);
|
|
24
|
+
};
|
|
25
|
+
this.error = (...args) => {
|
|
26
|
+
var _a;
|
|
27
|
+
(_a = this.extraLogger) === null || _a === void 0 ? void 0 : _a.error(...args);
|
|
28
|
+
this.append(...args);
|
|
29
|
+
};
|
|
30
|
+
this.setLogName('');
|
|
31
|
+
}
|
|
32
|
+
setLogFilePath(path) {
|
|
33
|
+
this._logFilePath = path;
|
|
34
|
+
return this;
|
|
15
35
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
this
|
|
36
|
+
setLogName(name) {
|
|
37
|
+
const n = name ? `-${name}` : '';
|
|
38
|
+
this._logFilePath = Path.resolve(__dirname, `../run${n}.${new Date().toISOString()}.log`);
|
|
39
|
+
return this;
|
|
20
40
|
}
|
|
21
|
-
|
|
22
|
-
|
|
41
|
+
append(..._args) {
|
|
42
|
+
// @ts-ignore
|
|
43
|
+
const str = Util.format.apply(null, arguments) + '\n';
|
|
44
|
+
this._buffer.push(str);
|
|
45
|
+
if (this.instantFlush) {
|
|
46
|
+
this.flush();
|
|
47
|
+
}
|
|
23
48
|
}
|
|
24
49
|
flush() {
|
|
25
|
-
if (!this._buffer) {
|
|
50
|
+
if (!this._buffer.length) {
|
|
26
51
|
return;
|
|
27
52
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const str = Util.format.apply(null, arguments) + '\n';
|
|
34
|
-
if (this._buffer) {
|
|
35
|
-
this._buffer.push(str);
|
|
53
|
+
try {
|
|
54
|
+
FS.appendFileSync(this._logFilePath, this._buffer.join(''));
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
console.warn('Failed to flush file, error', err);
|
|
36
58
|
}
|
|
37
|
-
|
|
38
|
-
|
|
59
|
+
finally {
|
|
60
|
+
this._buffer.length = 0;
|
|
39
61
|
}
|
|
40
62
|
}
|
|
41
63
|
}
|
package/lib/logger/file.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../src/logger/file.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../src/logger/file.ts"],"names":[],"mappings":";;;;AACA,+BAA+B;AAC/B,mDAA6B;AAC7B,+CAAyB;AACzB,mDAA6B;AAI7B,MAAa,cAAc;IAIvB,YAAqB,cAAuB,OAAO,EAAW,eAAe,KAAK;QAA7D,gBAAW,GAAX,WAAW,CAAmB;QAAW,iBAAY,GAAZ,YAAY,CAAQ;QAHjE,YAAO,GAAa,EAAE,CAAC;QAChC,iBAAY,GAAW,IAAI,CAAC;QA2BpC,QAAG,GAAG,CAAC,GAAG,IAAW,EAAE,EAAE;;YACrB,MAAA,IAAI,CAAC,WAAW,0CAAE,GAAG,CAAC,GAAG,IAAI,EAAE;YAC/B,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC;QACzB,CAAC,CAAC;QAEF,SAAI,GAAG,CAAC,GAAG,IAAW,EAAE,EAAE;;YACtB,MAAA,IAAI,CAAC,WAAW,0CAAE,IAAI,CAAC,GAAG,IAAI,EAAE;YAChC,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC;QACzB,CAAC,CAAC;QAEF,UAAK,GAAG,CAAC,GAAG,IAAW,EAAE,EAAE;;YACvB,MAAA,IAAI,CAAC,WAAW,0CAAE,KAAK,CAAC,GAAG,IAAI,EAAE;YACjC,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC;QACzB,CAAC,CAAC;QArCE,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IACxB,CAAC;IAED,cAAc,CAAC,IAAY;QACvB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QACzB,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,UAAU,CAAC,IAAY;QACnB,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACjC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;QAC1F,OAAO,IAAI,CAAC;IAChB,CAAC;IAEO,MAAM,CAAC,GAAG,KAAY;QAC1B,aAAa;QACb,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,GAAG,IAAI,CAAC;QACtD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAEvB,IAAI,IAAI,CAAC,YAAY,EAAE;YACnB,IAAI,CAAC,KAAK,EAAE,CAAC;SAChB;IACL,CAAC;IAiBD,KAAK;QACD,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;YACtB,OAAO;SACV;QAED,IAAI;YACA,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;SAC/D;QAAC,OAAO,GAAG,EAAE;YACV,OAAO,CAAC,IAAI,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAC;SACpD;gBAAS;YACN,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;SAC3B;IACL,CAAC;CACJ;AAzDD,wCAyDC"}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import { ValidatorFunction } from './types';
|
|
2
1
|
import { ValidationErrors } from './ValidationErrors';
|
|
2
|
+
import { ValidationConfig, ValidationResults, ValidatorFunction } from './types';
|
|
3
3
|
export declare function createShouldBeEqualTo<T = string>(getter: () => T): ValidatorFunction<T>;
|
|
4
4
|
export declare function throwNotOk(result: ValidationErrors, message?: string): void;
|
|
5
|
-
export declare function validateObject<T>(obj: T, validators:
|
|
6
|
-
[P in keyof T]?: ValidatorFunction<T[P]>;
|
|
7
|
-
}): {
|
|
8
|
-
[P in keyof T]?: ValidationErrors;
|
|
9
|
-
};
|
|
5
|
+
export declare function validateObject<T, TErrors = ValidationErrors>(obj: T, validators: ValidationConfig<T, TErrors>, onlyTruethy?: boolean): ValidationResults<T, TErrors>;
|
|
10
6
|
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/validation/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/validation/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EACH,gBAAgB,EAEhB,iBAAiB,EACjB,iBAAiB,EACpB,MAAM,SAAS,CAAC;AAEjB,wBAAgB,qBAAqB,CAAC,CAAC,GAAG,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAEvF;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,gBAAgB,EAAE,OAAO,SAAqB,QAIhF;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,gBAAgB,EACxD,GAAG,EAAE,CAAC,EACN,UAAU,EAAE,gBAAgB,CAAC,CAAC,EAAE,OAAO,CAAC,EACxC,WAAW,UAAQ,GACpB,iBAAiB,CAAC,CAAC,EAAE,OAAO,CAAC,CAuB/B"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validateObject = exports.throwNotOk = exports.createShouldBeEqualTo = void 0;
|
|
4
|
-
const types_1 = require("./types");
|
|
5
4
|
const ValidationErrors_1 = require("./ValidationErrors");
|
|
5
|
+
const types_1 = require("./types");
|
|
6
6
|
function createShouldBeEqualTo(getter) {
|
|
7
7
|
return (val) => getter() === val ? ValidationErrors_1.ValidationErrors.None : ValidationErrors_1.ValidationErrors.ShouldBeEqualTo;
|
|
8
8
|
}
|
|
@@ -13,7 +13,7 @@ function throwNotOk(result, message = 'Validation error') {
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
exports.throwNotOk = throwNotOk;
|
|
16
|
-
function validateObject(obj, validators) {
|
|
16
|
+
function validateObject(obj, validators, onlyTruethy = false) {
|
|
17
17
|
const res = {};
|
|
18
18
|
Object.keys(obj).forEach(k => {
|
|
19
19
|
const kk = k;
|
|
@@ -22,15 +22,10 @@ function validateObject(obj, validators) {
|
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
24
|
const v = obj[k];
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// if (typeof v !== 'string') {
|
|
30
|
-
// return; // skip non-strings
|
|
31
|
-
// }
|
|
32
|
-
// str = v;
|
|
33
|
-
const err = validator(v);
|
|
25
|
+
if (onlyTruethy && !v) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const err = validator(v, obj);
|
|
34
29
|
if (err) {
|
|
35
30
|
res[kk] = err;
|
|
36
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/validation/helpers.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/validation/helpers.ts"],"names":[],"mappings":";;;AAAA,yDAAsD;AACtD,mCAKiB;AAEjB,SAAgB,qBAAqB,CAAa,MAAe;IAC7D,OAAO,CAAC,GAAM,EAAE,EAAE,CAAC,MAAM,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC,mCAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,mCAAgB,CAAC,eAAe,CAAC;AACnG,CAAC;AAFD,sDAEC;AAED,SAAgB,UAAU,CAAC,MAAwB,EAAE,OAAO,GAAG,kBAAkB;IAC7E,IAAI,MAAM,EAAE;QACR,MAAM,IAAI,uBAAe,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;KAC9C;AACL,CAAC;AAJD,gCAIC;AAED,SAAgB,cAAc,CAC1B,GAAM,EACN,UAAwC,EACxC,WAAW,GAAG,KAAK;IAGnB,MAAM,GAAG,GAAkC,EAAG,CAAC;IAE/C,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;QACzB,MAAM,EAAE,GAAG,CAAY,CAAC;QACxB,MAAM,SAAS,GAAgD,UAAU,CAAC,EAAE,CAAC,CAAC;QAC9E,IAAI,CAAC,SAAS,EAAE;YACZ,OAAO;SACV;QAED,MAAM,CAAC,GAAG,GAAG,CAAC,CAAY,CAAC,CAAC;QAC5B,IAAI,WAAW,IAAI,CAAC,CAAC,EAAE;YACnB,OAAO;SACV;QAED,MAAM,GAAG,GAAG,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;QAC9B,IAAI,GAAG,EAAE;YACL,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC;SACjB;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC;AACf,CAAC;AA3BD,wCA2BC"}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { ValidationErrors } from './ValidationErrors';
|
|
2
|
-
export declare type ValidatorFunction<T = string, TErrors = ValidationErrors> = (val: T) => TErrors;
|
|
3
|
-
export declare type ValidatorFunctionAsync<T = string, TErrors = ValidationErrors> = (val: T) => Promise<TErrors>;
|
|
2
|
+
export declare type ValidatorFunction<T = string, TErrors = ValidationErrors, TContext = any> = (val: T, ctx?: TContext) => TErrors;
|
|
3
|
+
export declare type ValidatorFunctionAsync<T = string, TErrors = ValidationErrors, TContext = any> = (val: T, ctx?: TContext) => Promise<TErrors>;
|
|
4
|
+
export declare type ValidationConfig<T, TErrors> = {
|
|
5
|
+
[P in keyof T]?: ValidatorFunction<T[P], TErrors, T>;
|
|
6
|
+
};
|
|
7
|
+
export declare type ValidationResults<T, TErrors> = {
|
|
8
|
+
[P in keyof T]?: TErrors;
|
|
9
|
+
};
|
|
4
10
|
export declare type WrapperFunction = (val: ValidatorFunction) => ValidatorFunction;
|
|
5
11
|
export declare class ValidationError<TErrors = ValidationErrors> extends Error {
|
|
6
12
|
readonly code: TErrors;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/validation/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,oBAAY,iBAAiB,CAAC,CAAC,GAAG,MAAM,EAAE,OAAO,GAAG,gBAAgB,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/validation/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,oBAAY,iBAAiB,CAAC,CAAC,GAAG,MAAM,EAAE,OAAO,GAAG,gBAAgB,EAAE,QAAQ,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,QAAQ,KAAK,OAAO,CAAC;AAC5H,oBAAY,sBAAsB,CAAC,CAAC,GAAG,MAAM,EAAE,OAAO,GAAG,gBAAgB,EAAE,QAAQ,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,QAAQ,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAE1I,oBAAY,gBAAgB,CAAC,CAAC,EAAE,OAAO,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;CAAE,CAAC;AACpG,oBAAY,iBAAiB,CAAC,CAAC,EAAE,OAAO,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO;CAAE,CAAC;AAEzE,oBAAY,eAAe,GAAG,CAAC,GAAG,EAAE,iBAAiB,KAAK,iBAAiB,CAAC;AAE5E,qBAAa,eAAe,CAAC,OAAO,GAAG,gBAAgB,CAAE,SAAQ,KAAK;IAClE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAQ;gBAElB,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO;CAI7C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/validation/types.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/validation/types.ts"],"names":[],"mappings":";;;AAUA,MAAa,eAA4C,SAAQ,KAAK;IAGlE,YAAY,OAAe,EAAE,IAAa;QACtC,KAAK,CAAC,OAAO,CAAC,CAAC;QAHV,SAAI,GAAY,IAAI,CAAC;QAI1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;CACJ;AAPD,0CAOC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ValidatorFunction } from './types';
|
|
2
2
|
import { ValidationErrors } from './ValidationErrors';
|
|
3
3
|
export declare const Wrappers: {
|
|
4
|
-
required<T = string>(validator: ValidatorFunction<T, ValidationErrors>): ValidatorFunction<T, ValidationErrors>;
|
|
5
|
-
notRequired<T_1 = string>(validator: ValidatorFunction<T_1, ValidationErrors>): ValidatorFunction<T_1, ValidationErrors>;
|
|
6
|
-
thrower<T_2 = string>(validator: ValidatorFunction<T_2, ValidationErrors>): (val: T_2) => void;
|
|
4
|
+
required<T = string>(validator: ValidatorFunction<T, ValidationErrors, any>): ValidatorFunction<T, ValidationErrors, any>;
|
|
5
|
+
notRequired<T_1 = string>(validator: ValidatorFunction<T_1, ValidationErrors, any>): ValidatorFunction<T_1, ValidationErrors, any>;
|
|
6
|
+
thrower<T_2 = string>(validator: ValidatorFunction<T_2, ValidationErrors, any>): (val: T_2) => void;
|
|
7
7
|
};
|
|
8
8
|
//# sourceMappingURL=wrappers.d.ts.map
|
package/package.json
CHANGED
package/src/logger/file.ts
CHANGED
|
@@ -1,46 +1,66 @@
|
|
|
1
|
+
|
|
2
|
+
/* eslint-disable no-console */
|
|
3
|
+
import * as Path from 'path';
|
|
1
4
|
import * as FS from 'fs';
|
|
2
5
|
import * as Util from 'util';
|
|
6
|
+
|
|
3
7
|
import { ILogger } from './abstractions';
|
|
4
|
-
import { Getter } from '../types';
|
|
5
8
|
|
|
6
9
|
export class FileLoggerNode implements ILogger {
|
|
7
|
-
private readonly _buffer: string[];
|
|
10
|
+
private readonly _buffer: string[] = [];
|
|
11
|
+
private _logFilePath: string = null;
|
|
12
|
+
|
|
13
|
+
constructor(readonly extraLogger: ILogger = console, readonly instantFlush = false) {
|
|
14
|
+
this.setLogName('');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
setLogFilePath(path: string) {
|
|
18
|
+
this._logFilePath = path;
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
8
21
|
|
|
9
|
-
|
|
10
|
-
|
|
22
|
+
setLogName(name: string) {
|
|
23
|
+
const n = name ? `-${name}` : '';
|
|
24
|
+
this._logFilePath = Path.resolve(__dirname, `../run${n}.${new Date().toISOString()}.log`);
|
|
25
|
+
return this;
|
|
11
26
|
}
|
|
12
27
|
|
|
13
|
-
|
|
14
|
-
|
|
28
|
+
private append(..._args: any[]) {
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
const str = Util.format.apply(null, arguments) + '\n';
|
|
31
|
+
this._buffer.push(str);
|
|
32
|
+
|
|
33
|
+
if (this.instantFlush) {
|
|
34
|
+
this.flush();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
15
37
|
|
|
16
38
|
log = (...args: any[]) => {
|
|
17
|
-
this.
|
|
39
|
+
this.extraLogger?.log(...args);
|
|
40
|
+
this.append(...args);
|
|
18
41
|
};
|
|
19
42
|
|
|
20
|
-
warn(...args: any[]) {
|
|
21
|
-
this.
|
|
22
|
-
|
|
43
|
+
warn = (...args: any[]) => {
|
|
44
|
+
this.extraLogger?.warn(...args);
|
|
45
|
+
this.append(...args);
|
|
46
|
+
};
|
|
23
47
|
|
|
24
|
-
error(...args: any[]) {
|
|
25
|
-
this.
|
|
26
|
-
|
|
48
|
+
error = (...args: any[]) => {
|
|
49
|
+
this.extraLogger?.error(...args);
|
|
50
|
+
this.append(...args);
|
|
51
|
+
};
|
|
27
52
|
|
|
28
|
-
|
|
29
|
-
if (!this._buffer) {
|
|
53
|
+
flush() {
|
|
54
|
+
if (!this._buffer.length) {
|
|
30
55
|
return;
|
|
31
56
|
}
|
|
32
57
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const str = Util.format.apply(null, arguments) + '\n';
|
|
40
|
-
if (this._buffer) {
|
|
41
|
-
this._buffer.push(str);
|
|
42
|
-
} else {
|
|
43
|
-
FS.appendFileSync(this.logFilePath, str);
|
|
58
|
+
try {
|
|
59
|
+
FS.appendFileSync(this._logFilePath, this._buffer.join(''));
|
|
60
|
+
} catch (err) {
|
|
61
|
+
console.warn('Failed to flush file, error', err);
|
|
62
|
+
} finally {
|
|
63
|
+
this._buffer.length = 0;
|
|
44
64
|
}
|
|
45
65
|
}
|
|
46
66
|
}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import { ValidationError, ValidatorFunction } from './types';
|
|
2
1
|
import { ValidationErrors } from './ValidationErrors';
|
|
2
|
+
import {
|
|
3
|
+
ValidationConfig,
|
|
4
|
+
ValidationError,
|
|
5
|
+
ValidationResults,
|
|
6
|
+
ValidatorFunction,
|
|
7
|
+
} from './types';
|
|
3
8
|
|
|
4
9
|
export function createShouldBeEqualTo<T = string>(getter: () => T): ValidatorFunction<T> {
|
|
5
10
|
return (val: T) => getter() === val ? ValidationErrors.None : ValidationErrors.ShouldBeEqualTo;
|
|
@@ -11,33 +16,27 @@ export function throwNotOk(result: ValidationErrors, message = 'Validation error
|
|
|
11
16
|
}
|
|
12
17
|
}
|
|
13
18
|
|
|
14
|
-
export function validateObject<T>(
|
|
19
|
+
export function validateObject<T, TErrors = ValidationErrors>(
|
|
15
20
|
obj: T,
|
|
16
|
-
validators:
|
|
17
|
-
|
|
21
|
+
validators: ValidationConfig<T, TErrors>,
|
|
22
|
+
onlyTruethy = false,
|
|
23
|
+
): ValidationResults<T, TErrors> {
|
|
18
24
|
|
|
19
|
-
const res:
|
|
25
|
+
const res: ValidationResults<T, TErrors> = { };
|
|
20
26
|
|
|
21
27
|
Object.keys(obj).forEach(k => {
|
|
22
28
|
const kk = k as keyof T;
|
|
23
|
-
const validator: ValidatorFunction<T[typeof kk]> = validators[kk];
|
|
29
|
+
const validator: ValidatorFunction<T[typeof kk], TErrors, T> = validators[kk];
|
|
24
30
|
if (!validator) {
|
|
25
31
|
return;
|
|
26
32
|
}
|
|
27
33
|
|
|
28
34
|
const v = obj[k as keyof T];
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
// }
|
|
33
|
-
|
|
34
|
-
// if (typeof v !== 'string') {
|
|
35
|
-
// return; // skip non-strings
|
|
36
|
-
// }
|
|
37
|
-
|
|
38
|
-
// str = v;
|
|
35
|
+
if (onlyTruethy && !v) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
39
38
|
|
|
40
|
-
const err = validator(v);
|
|
39
|
+
const err = validator(v, obj);
|
|
41
40
|
if (err) {
|
|
42
41
|
res[kk] = err;
|
|
43
42
|
}
|
|
@@ -45,4 +44,3 @@ export function validateObject<T>(
|
|
|
45
44
|
|
|
46
45
|
return res;
|
|
47
46
|
}
|
|
48
|
-
|
package/src/validation/types.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { ValidationErrors } from './ValidationErrors';
|
|
2
2
|
|
|
3
|
-
export type ValidatorFunction<T = string, TErrors = ValidationErrors> = (val: T) => TErrors;
|
|
4
|
-
export type ValidatorFunctionAsync<T = string, TErrors = ValidationErrors> = (val: T) => Promise<TErrors>;
|
|
3
|
+
export type ValidatorFunction<T = string, TErrors = ValidationErrors, TContext = any> = (val: T, ctx?: TContext) => TErrors;
|
|
4
|
+
export type ValidatorFunctionAsync<T = string, TErrors = ValidationErrors, TContext = any> = (val: T, ctx?: TContext) => Promise<TErrors>;
|
|
5
|
+
|
|
6
|
+
export type ValidationConfig<T, TErrors> = { [P in keyof T]?: ValidatorFunction<T[P], TErrors, T> };
|
|
7
|
+
export type ValidationResults<T, TErrors> = { [P in keyof T]?: TErrors };
|
|
5
8
|
|
|
6
9
|
export type WrapperFunction = (val: ValidatorFunction) => ValidatorFunction;
|
|
7
10
|
|