@zajno/common 1.4.15 → 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 +56 -42
- package/coverage/coverage-final.json +5 -4
- package/coverage/lcov-report/index.html +25 -25
- 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 +12 -12
- 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 +24 -9
- 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 +134 -0
- 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 +14 -2
- 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-report/tempoCache.ts.html +134 -0
- package/coverage/lcov-report/timer.ts.html +200 -0
- package/coverage/lcov.info +97 -64
- 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/tempoCache.d.ts +10 -0
- package/lib/tempoCache.d.ts.map +1 -0
- package/lib/tempoCache.js +21 -0
- package/lib/tempoCache.js.map +1 -0
- package/lib/timeHelper.d.ts +0 -7
- package/lib/timeHelper.d.ts.map +1 -1
- package/lib/timeHelper.js +3 -19
- package/lib/timeHelper.js.map +1 -1
- package/lib/timer.d.ts +15 -0
- package/lib/timer.d.ts.map +1 -0
- package/lib/timer.js +36 -0
- package/lib/timer.js.map +1 -0
- 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/lib/viewModels/LoadingModel.d.ts +3 -1
- package/lib/viewModels/LoadingModel.d.ts.map +1 -1
- package/lib/viewModels/LoadingModel.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/tempoCache.test.ts +31 -0
- package/src/logger/file.ts +46 -26
- package/src/tempoCache.ts +18 -0
- package/src/timeHelper.ts +3 -18
- package/src/timer.ts +40 -0
- package/src/validation/helpers.ts +16 -18
- package/src/validation/types.ts +5 -2
- package/src/viewModels/LoadingModel.ts +4 -0
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"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class TempoCache<T> {
|
|
2
|
+
readonly factory: () => T;
|
|
3
|
+
readonly lifetimeMs: number;
|
|
4
|
+
private _expiringAt;
|
|
5
|
+
private _current;
|
|
6
|
+
constructor(factory: () => T, lifetimeMs: number);
|
|
7
|
+
get isExpired(): boolean;
|
|
8
|
+
get current(): T;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=tempoCache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tempoCache.d.ts","sourceRoot":"","sources":["../src/tempoCache.ts"],"names":[],"mappings":"AACA,qBAAa,UAAU,CAAC,CAAC;IAKT,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAE,QAAQ,CAAC,UAAU,EAAE,MAAM;IAHlE,OAAO,CAAC,WAAW,CAAa;IAChC,OAAO,CAAC,QAAQ,CAAgB;gBAEX,OAAO,EAAE,MAAM,CAAC,EAAW,UAAU,EAAE,MAAM;IAElE,IAAW,SAAS,YAA6C;IAEjE,IAAW,OAAO,MAMjB;CACJ"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TempoCache = void 0;
|
|
4
|
+
class TempoCache {
|
|
5
|
+
constructor(factory, lifetimeMs) {
|
|
6
|
+
this.factory = factory;
|
|
7
|
+
this.lifetimeMs = lifetimeMs;
|
|
8
|
+
this._expiringAt = 0; // already expired
|
|
9
|
+
this._current = undefined;
|
|
10
|
+
}
|
|
11
|
+
get isExpired() { return Date.now() >= this._expiringAt; }
|
|
12
|
+
get current() {
|
|
13
|
+
if (this.isExpired) {
|
|
14
|
+
this._current = this.factory();
|
|
15
|
+
this._expiringAt = Date.now() + this.lifetimeMs;
|
|
16
|
+
}
|
|
17
|
+
return this._current;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.TempoCache = TempoCache;
|
|
21
|
+
//# sourceMappingURL=tempoCache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tempoCache.js","sourceRoot":"","sources":["../src/tempoCache.ts"],"names":[],"mappings":";;;AACA,MAAa,UAAU;IAKnB,YAAqB,OAAgB,EAAW,UAAkB;QAA7C,YAAO,GAAP,OAAO,CAAS;QAAW,eAAU,GAAV,UAAU,CAAQ;QAH1D,gBAAW,GAAW,CAAC,CAAC,CAAC,kBAAkB;QAC3C,aAAQ,GAAM,SAAS,CAAC;IAEsC,CAAC;IAEvE,IAAW,SAAS,KAAK,OAAO,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;IAEjE,IAAW,OAAO;QACd,IAAI,IAAI,CAAC,SAAS,EAAE;YAChB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;YAC/B,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC;SACnD;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;CACJ;AAhBD,gCAgBC"}
|
package/lib/timeHelper.d.ts
CHANGED
|
@@ -4,11 +4,4 @@ export declare function formatMS(ms: number): string;
|
|
|
4
4
|
export declare function formatTime(n: number): string;
|
|
5
5
|
/** @deprecated */
|
|
6
6
|
export declare function secToFormattedMin(totalSec: number): string;
|
|
7
|
-
declare class Time {
|
|
8
|
-
private _now;
|
|
9
|
-
constructor();
|
|
10
|
-
get now(): number;
|
|
11
|
-
}
|
|
12
|
-
export declare const TimeHelper: Time;
|
|
13
|
-
export {};
|
|
14
7
|
//# sourceMappingURL=timeHelper.d.ts.map
|
package/lib/timeHelper.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeHelper.d.ts","sourceRoot":"","sources":["../src/timeHelper.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"timeHelper.d.ts","sourceRoot":"","sources":["../src/timeHelper.ts"],"names":[],"mappings":"AAIA,kBAAkB;AAClB,wBAAgB,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAU3C;AAED,kBAAkB;AAClB,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAM5C;AAED,kBAAkB;AAClB,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAW1D"}
|
package/lib/timeHelper.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
exports.secToFormattedMin = exports.formatTime = exports.formatMS = void 0;
|
|
4
|
+
// eslint-disable-next-line no-console
|
|
5
|
+
console.warn('"timeHelper" module is deprecated. Please use "dates" one.');
|
|
6
6
|
/** @deprecated */
|
|
7
7
|
function formatMS(ms) {
|
|
8
8
|
if (!ms && ms !== 0) {
|
|
@@ -34,20 +34,4 @@ function secToFormattedMin(totalSec) {
|
|
|
34
34
|
return res;
|
|
35
35
|
}
|
|
36
36
|
exports.secToFormattedMin = secToFormattedMin;
|
|
37
|
-
class Time {
|
|
38
|
-
constructor() {
|
|
39
|
-
this._now = new Date().getTime();
|
|
40
|
-
mobx_1.makeObservable(this);
|
|
41
|
-
// Update _now once an hour
|
|
42
|
-
setInterval(() => { this._now = new Date().getTime(); }, 1000 * 3600);
|
|
43
|
-
}
|
|
44
|
-
get now() {
|
|
45
|
-
return this._now;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
tslib_1.__decorate([
|
|
49
|
-
mobx_1.observable,
|
|
50
|
-
tslib_1.__metadata("design:type", Number)
|
|
51
|
-
], Time.prototype, "_now", void 0);
|
|
52
|
-
exports.TimeHelper = new Time();
|
|
53
37
|
//# sourceMappingURL=timeHelper.js.map
|
package/lib/timeHelper.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeHelper.js","sourceRoot":"","sources":["../src/timeHelper.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"timeHelper.js","sourceRoot":"","sources":["../src/timeHelper.ts"],"names":[],"mappings":";;;AACA,sCAAsC;AACtC,OAAO,CAAC,IAAI,CAAC,4DAA4D,CAAC,CAAC;AAE3E,kBAAkB;AAClB,SAAgB,QAAQ,CAAC,EAAU;IAC/B,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,EAAE;QACjB,OAAO,EAAE,CAAC;KACb;IAED,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IACzC,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;IAChD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;IAEvD,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;AACpG,CAAC;AAVD,4BAUC;AAED,kBAAkB;AAClB,SAAgB,UAAU,CAAC,CAAS;IAChC,IAAI,CAAC,GAAG,EAAE,EAAE;QACR,OAAO,GAAG,GAAG,CAAC,CAAC;KAClB;IAED,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC;AACxB,CAAC;AAND,gCAMC;AAED,kBAAkB;AAClB,SAAgB,iBAAiB,CAAC,QAAgB;IAC9C,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;IACtC,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;IAC5C,IAAI,GAAG,GAAG,GAAG,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;IAE/B,IAAI,GAAG,EAAE;QACL,GAAG,IAAI,GAAG,CAAC;QACX,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;KACtC;IAED,OAAO,GAAG,CAAC;AACf,CAAC;AAXD,8CAWC"}
|
package/lib/timer.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { IDisposable } from './disposer';
|
|
2
|
+
import { EventHandler, IEvent } from './event';
|
|
3
|
+
export declare class Timer implements IDisposable, IEvent<number> {
|
|
4
|
+
readonly interval: number;
|
|
5
|
+
private readonly _event;
|
|
6
|
+
private _now;
|
|
7
|
+
private _handle;
|
|
8
|
+
constructor(interval?: number);
|
|
9
|
+
get now(): number;
|
|
10
|
+
on(handler: EventHandler<number>): () => void;
|
|
11
|
+
off(handler: EventHandler<number>): void;
|
|
12
|
+
restart(): void;
|
|
13
|
+
dispose(): void;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=timer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timer.d.ts","sourceRoot":"","sources":["../src/timer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAS,YAAY,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEtD,qBAAa,KAAM,YAAW,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC;IAMzC,QAAQ,CAAC,QAAQ;IAL7B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuB;IAE9C,OAAO,CAAC,IAAI,CAAsB;IAClC,OAAO,CAAC,OAAO,CAAQ;gBAEF,QAAQ,SAAc;IAI3C,IAAI,GAAG,WAEN;IAED,EAAE,CAAC,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC,GAAG,MAAM,IAAI;IAI7C,GAAG,CAAC,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC,GAAG,IAAI;IAIjC,OAAO;IAUP,OAAO,IAAI,IAAI;CAIzB"}
|
package/lib/timer.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Timer = void 0;
|
|
4
|
+
const event_1 = require("./event");
|
|
5
|
+
class Timer {
|
|
6
|
+
constructor(interval = 3600 * 1000) {
|
|
7
|
+
this.interval = interval;
|
|
8
|
+
this._event = new event_1.Event();
|
|
9
|
+
this._now = Date.now();
|
|
10
|
+
this._handle = null;
|
|
11
|
+
this.restart();
|
|
12
|
+
}
|
|
13
|
+
get now() {
|
|
14
|
+
return this._now;
|
|
15
|
+
}
|
|
16
|
+
on(handler) {
|
|
17
|
+
return this._event.on(handler);
|
|
18
|
+
}
|
|
19
|
+
off(handler) {
|
|
20
|
+
return this._event.off(handler);
|
|
21
|
+
}
|
|
22
|
+
restart() {
|
|
23
|
+
this.dispose();
|
|
24
|
+
// Update _now once an hour
|
|
25
|
+
this._handle = setInterval(() => {
|
|
26
|
+
this._now = Date.now();
|
|
27
|
+
this._event.trigger(this._now);
|
|
28
|
+
}, this.interval);
|
|
29
|
+
}
|
|
30
|
+
dispose() {
|
|
31
|
+
clearInterval(this._handle);
|
|
32
|
+
this._handle = null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.Timer = Timer;
|
|
36
|
+
//# sourceMappingURL=timer.js.map
|
package/lib/timer.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timer.js","sourceRoot":"","sources":["../src/timer.ts"],"names":[],"mappings":";;;AACA,mCAAsD;AAEtD,MAAa,KAAK;IAMd,YAAqB,WAAW,IAAI,GAAG,IAAI;QAAtB,aAAQ,GAAR,QAAQ,CAAc;QAL1B,WAAM,GAAG,IAAI,aAAK,EAAU,CAAC;QAEtC,SAAI,GAAW,IAAI,CAAC,GAAG,EAAE,CAAC;QAC1B,YAAO,GAAG,IAAI,CAAC;QAGnB,IAAI,CAAC,OAAO,EAAE,CAAC;IACnB,CAAC;IAED,IAAI,GAAG;QACH,OAAO,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IAED,EAAE,CAAC,OAA6B;QAC5B,OAAO,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;IAED,GAAG,CAAC,OAA6B;QAC7B,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;IAEM,OAAO;QACV,IAAI,CAAC,OAAO,EAAE,CAAC;QAEf,2BAA2B;QAC3B,IAAI,CAAC,OAAO,GAAG,WAAW,CAAC,GAAG,EAAE;YAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YACvB,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnC,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IACtB,CAAC;IAEM,OAAO;QACV,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC5B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;IACxB,CAAC;CACJ;AApCD,sBAoCC"}
|
|
@@ -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
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { NumberModel } from './NumberModel';
|
|
2
2
|
export declare class LoadingModel extends NumberModel {
|
|
3
3
|
get isLoading(): boolean;
|
|
4
|
-
useLoading<T>(cb: () => (T | Promise<T>)
|
|
4
|
+
useLoading<T>(cb: () => (T | Promise<T>)): Promise<T>;
|
|
5
|
+
useLoading<T>(cb: () => (T | Promise<T>), exclusive: false): Promise<T>;
|
|
6
|
+
useLoading<T>(cb: () => (T | Promise<T>), exclusive: true | 'throw'): Promise<T | false>;
|
|
5
7
|
}
|
|
6
8
|
//# sourceMappingURL=LoadingModel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LoadingModel.d.ts","sourceRoot":"","sources":["../../src/viewModels/LoadingModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,qBAAa,YAAa,SAAQ,WAAW;IAEzC,IAAW,SAAS,YAA6B;IAEpC,UAAU,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"LoadingModel.d.ts","sourceRoot":"","sources":["../../src/viewModels/LoadingModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,qBAAa,YAAa,SAAQ,WAAW;IAEzC,IAAW,SAAS,YAA6B;IAEpC,UAAU,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IACrD,UAAU,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC;IACvE,UAAU,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,GAAG,OAAO,GAAG,OAAO,CAAC,CAAC,GAAG,KAAK,CAAC;CAmBxG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LoadingModel.js","sourceRoot":"","sources":["../../src/viewModels/LoadingModel.ts"],"names":[],"mappings":";;;AAAA,+CAA4C;AAE5C,MAAa,YAAa,SAAQ,yBAAW;IAEzC,IAAW,SAAS,KAAK,OAAO,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"LoadingModel.js","sourceRoot":"","sources":["../../src/viewModels/LoadingModel.ts"],"names":[],"mappings":";;;AAAA,+CAA4C;AAE5C,MAAa,YAAa,SAAQ,yBAAW;IAEzC,IAAW,SAAS,KAAK,OAAO,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;IAM1C,KAAK,CAAC,UAAU,CAAI,EAA0B,EAAE,YAA+B,KAAK;QACvF,IAAI,SAAS,IAAI,IAAI,CAAC,SAAS,EAAE;YAC7B,IAAI,SAAS,KAAK,OAAO,EAAE;gBACvB,MAAM,IAAI,KAAK,CAAC,yEAAyE,CAAC,CAAC;aAC9F;YACD,OAAO,KAAK,CAAC;SAChB;QAED,IAAI,CAAC,SAAS,EAAE,CAAC;QAEjB,IAAI;YACA,MAAM,GAAG,GAAG,MAAM,EAAE,EAAE,CAAC;YACvB,OAAO,GAAG,CAAC;SACd;gBAAS;YACN,IAAI,CAAC,SAAS,EAAE,CAAC;SACpB;IACL,CAAC;CACJ;AAzBD,oCAyBC"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { TempoCache } from '../tempoCache';
|
|
2
|
+
import { setTimeoutAsync } from '../async/timeout';
|
|
3
|
+
|
|
4
|
+
describe('TempoCache', () => {
|
|
5
|
+
it('just works', async () => {
|
|
6
|
+
let incrementer = 1;
|
|
7
|
+
|
|
8
|
+
const example = new TempoCache(() => Promise.resolve(incrementer++), 199);
|
|
9
|
+
|
|
10
|
+
expect(await example.current).toBe(1);
|
|
11
|
+
await expect(example.current).resolves.toBe(1);
|
|
12
|
+
|
|
13
|
+
await setTimeoutAsync(100);
|
|
14
|
+
|
|
15
|
+
await expect(example.current).resolves.toBe(1);
|
|
16
|
+
|
|
17
|
+
await setTimeoutAsync(200);
|
|
18
|
+
|
|
19
|
+
await expect(example.current).resolves.toBe(2);
|
|
20
|
+
|
|
21
|
+
await setTimeoutAsync(100);
|
|
22
|
+
|
|
23
|
+
await expect(example.current).resolves.toBe(2);
|
|
24
|
+
await expect(example.current).resolves.toBe(2);
|
|
25
|
+
|
|
26
|
+
await setTimeoutAsync(300);
|
|
27
|
+
|
|
28
|
+
await expect(example.current).resolves.toBe(3);
|
|
29
|
+
await expect(example.current).resolves.toBe(3);
|
|
30
|
+
});
|
|
31
|
+
});
|
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
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
export class TempoCache<T> {
|
|
3
|
+
|
|
4
|
+
private _expiringAt: number = 0; // already expired
|
|
5
|
+
private _current: T = undefined;
|
|
6
|
+
|
|
7
|
+
constructor(readonly factory: () => T, readonly lifetimeMs: number) { }
|
|
8
|
+
|
|
9
|
+
public get isExpired() { return Date.now() >= this._expiringAt; }
|
|
10
|
+
|
|
11
|
+
public get current() {
|
|
12
|
+
if (this.isExpired) {
|
|
13
|
+
this._current = this.factory();
|
|
14
|
+
this._expiringAt = Date.now() + this.lifetimeMs;
|
|
15
|
+
}
|
|
16
|
+
return this._current;
|
|
17
|
+
}
|
|
18
|
+
}
|
package/src/timeHelper.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
// eslint-disable-next-line no-console
|
|
3
|
+
console.warn('"timeHelper" module is deprecated. Please use "dates" one.');
|
|
2
4
|
|
|
3
5
|
/** @deprecated */
|
|
4
6
|
export function formatMS(ms: number): string {
|
|
@@ -35,20 +37,3 @@ export function secToFormattedMin(totalSec: number): string {
|
|
|
35
37
|
|
|
36
38
|
return res;
|
|
37
39
|
}
|
|
38
|
-
|
|
39
|
-
class Time {
|
|
40
|
-
@observable
|
|
41
|
-
private _now: number = new Date().getTime();
|
|
42
|
-
|
|
43
|
-
constructor() {
|
|
44
|
-
makeObservable(this);
|
|
45
|
-
// Update _now once an hour
|
|
46
|
-
setInterval(() => { this._now = new Date().getTime(); }, 1000 * 3600);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
get now() {
|
|
50
|
-
return this._now;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export const TimeHelper = new Time();
|
package/src/timer.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { IDisposable } from './disposer';
|
|
2
|
+
import { Event, EventHandler, IEvent } from './event';
|
|
3
|
+
|
|
4
|
+
export class Timer implements IDisposable, IEvent<number> {
|
|
5
|
+
private readonly _event = new Event<number>();
|
|
6
|
+
|
|
7
|
+
private _now: number = Date.now();
|
|
8
|
+
private _handle = null;
|
|
9
|
+
|
|
10
|
+
constructor(readonly interval = 3600 * 1000) {
|
|
11
|
+
this.restart();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
get now() {
|
|
15
|
+
return this._now;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
on(handler: EventHandler<number>): () => void {
|
|
19
|
+
return this._event.on(handler);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
off(handler: EventHandler<number>): void {
|
|
23
|
+
return this._event.off(handler);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public restart() {
|
|
27
|
+
this.dispose();
|
|
28
|
+
|
|
29
|
+
// Update _now once an hour
|
|
30
|
+
this._handle = setInterval(() => {
|
|
31
|
+
this._now = Date.now();
|
|
32
|
+
this._event.trigger(this._now);
|
|
33
|
+
}, this.interval);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public dispose(): void {
|
|
37
|
+
clearInterval(this._handle);
|
|
38
|
+
this._handle = null;
|
|
39
|
+
}
|
|
40
|
+
}
|