@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
|
@@ -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
|
|
|
@@ -4,6 +4,10 @@ export class LoadingModel extends NumberModel {
|
|
|
4
4
|
|
|
5
5
|
public get isLoading() { return this.value > 0; }
|
|
6
6
|
|
|
7
|
+
public async useLoading<T>(cb: () => (T | Promise<T>)): Promise<T>;
|
|
8
|
+
public async useLoading<T>(cb: () => (T | Promise<T>), exclusive: false): Promise<T>;
|
|
9
|
+
public async useLoading<T>(cb: () => (T | Promise<T>), exclusive: true | 'throw'): Promise<T | false>;
|
|
10
|
+
|
|
7
11
|
public async useLoading<T>(cb: () => (T | Promise<T>), exclusive: boolean | 'throw' = false): Promise<T | false> {
|
|
8
12
|
if (exclusive && this.isLoading) {
|
|
9
13
|
if (exclusive === 'throw') {
|