@my-devkit/core 1.0.122 → 1.0.124

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.
Files changed (67) hide show
  1. package/.eslintrc.js +3 -3
  2. package/dist/date-helper.js +6 -12
  3. package/dist/date-helper.js.map +1 -1
  4. package/dist/decorators/cacheable.decorator.js +2 -2
  5. package/dist/decorators/cacheable.decorator.js.map +1 -1
  6. package/dist/enum-helper.js +1 -1
  7. package/dist/enum-helper.js.map +1 -1
  8. package/dist/event.js +1 -2
  9. package/dist/event.js.map +1 -1
  10. package/dist/json-helper.js.map +1 -1
  11. package/dist/logger.js +1 -1
  12. package/dist/logger.js.map +1 -1
  13. package/dist/promise-helper.js +3 -3
  14. package/dist/promise-helper.js.map +1 -1
  15. package/dist/serialize/index.js.map +1 -1
  16. package/dist/serialize/serializable.js.map +1 -1
  17. package/dist/serialize/serialize-helper.js +3 -3
  18. package/dist/serialize/serialize-helper.js.map +1 -1
  19. package/dist/serialize/type-helper.js +11 -25
  20. package/dist/serialize/type-helper.js.map +1 -1
  21. package/dist/sleep.js +1 -1
  22. package/dist/sleep.js.map +1 -1
  23. package/dist/validators/custom-validators/camel-case.js +2 -2
  24. package/dist/validators/custom-validators/equals-to.js +2 -2
  25. package/dist/validators/custom-validators/greater-or-equal-than.js +2 -2
  26. package/dist/validators/custom-validators/greater-than-date.js +2 -2
  27. package/dist/validators/custom-validators/greater-than-date.js.map +1 -1
  28. package/dist/validators/custom-validators/is-empty-if.js +4 -7
  29. package/dist/validators/custom-validators/is-empty-if.js.map +1 -1
  30. package/dist/validators/custom-validators/is-not-empty-if.js +2 -2
  31. package/dist/validators/custom-validators/is-not-empty-if.js.map +1 -1
  32. package/dist/validators/custom-validators/is-not-in-relative-to.js +4 -6
  33. package/dist/validators/custom-validators/is-not-in-relative-to.js.map +1 -1
  34. package/dist/validators/custom-validators/is-optional-if.js.map +1 -1
  35. package/dist/validators/custom-validators/pascal-case.js +2 -2
  36. package/dist/validators/index.d.ts +1 -1
  37. package/dist/validators/validate.js +5 -9
  38. package/dist/validators/validate.js.map +1 -1
  39. package/dist/vendors/lodash.d.ts +1 -1
  40. package/package.json +2 -2
  41. package/src/date-helper.ts +17 -29
  42. package/src/decorators/cacheable.decorator.ts +8 -23
  43. package/src/enum-helper.ts +2 -2
  44. package/src/event.ts +1 -2
  45. package/src/json-helper.ts +1 -3
  46. package/src/logger.ts +3 -7
  47. package/src/model.ts +1 -1
  48. package/src/promise-helper.ts +3 -3
  49. package/src/retry.ts +1 -1
  50. package/src/serialize/index.ts +1 -7
  51. package/src/serialize/serializable.ts +1 -3
  52. package/src/serialize/serialize-helper.ts +6 -11
  53. package/src/serialize/type-helper.ts +13 -39
  54. package/src/sleep.ts +1 -1
  55. package/src/validators/custom-validators/camel-case.ts +2 -2
  56. package/src/validators/custom-validators/equals-to.ts +2 -2
  57. package/src/validators/custom-validators/greater-or-equal-than.ts +2 -2
  58. package/src/validators/custom-validators/greater-than-date.ts +3 -7
  59. package/src/validators/custom-validators/is-empty-if.ts +5 -13
  60. package/src/validators/custom-validators/is-not-empty-if.ts +3 -6
  61. package/src/validators/custom-validators/is-not-in-relative-to.ts +6 -16
  62. package/src/validators/custom-validators/is-optional-if.ts +1 -4
  63. package/src/validators/custom-validators/pascal-case.ts +2 -2
  64. package/src/validators/index.ts +1 -1
  65. package/src/validators/validate.ts +9 -24
  66. package/src/validators/validation-error.ts +1 -1
  67. package/src/vendors/lodash.ts +1 -1
@@ -1,10 +1,7 @@
1
1
  import { registerDecorator, ValidationArguments, ValidationOptions } from 'class-validator';
2
2
  import { isNil } from 'lodash';
3
3
 
4
- export function IsEmptyIf<T>(
5
- condition: (object: T) => boolean,
6
- validationOptions?: ValidationOptions
7
- ) {
4
+ export function IsEmptyIf<T>(condition: (object: T) => boolean, validationOptions?: ValidationOptions) {
8
5
  return function (object: Record<string, any>, propertyName: string): void {
9
6
  registerDecorator({
10
7
  name: 'isEmpty',
@@ -17,20 +14,15 @@ export function IsEmptyIf<T>(
17
14
  const [relatedCondition] = args.constraints;
18
15
  const cond = relatedCondition(args.object);
19
16
 
20
- if (
21
- cond &&
22
- Array.isArray(value) &&
23
- validationOptions &&
24
- validationOptions.each
25
- ) {
26
- return value.every(v => isNil(v));
17
+ if (cond && Array.isArray(value) && validationOptions && validationOptions.each) {
18
+ return value.every((v) => isNil(v));
27
19
  } else if (cond) {
28
20
  return isNil(value);
29
21
  }
30
22
 
31
23
  return true;
32
- }
33
- }
24
+ },
25
+ },
34
26
  });
35
27
  };
36
28
  }
@@ -1,10 +1,7 @@
1
1
  import { registerDecorator, ValidationArguments, ValidationOptions } from 'class-validator';
2
2
  import { isNil } from 'lodash';
3
3
 
4
- export function IsNotEmptyIf<T>(
5
- condition: (object: T) => boolean,
6
- validationOptions?: ValidationOptions
7
- ) {
4
+ export function IsNotEmptyIf<T>(condition: (object: T) => boolean, validationOptions?: ValidationOptions) {
8
5
  return function (object: Record<string, any>, propertyName: string): void {
9
6
  registerDecorator({
10
7
  name: 'isNotEmpty',
@@ -17,8 +14,8 @@ export function IsNotEmptyIf<T>(
17
14
  const [relatedCondition] = args.constraints;
18
15
  const cond = relatedCondition(args.object);
19
16
  return cond ? !isNil(value) : true;
20
- }
21
- }
17
+ },
18
+ },
22
19
  });
23
20
  };
24
21
  }
@@ -1,33 +1,23 @@
1
- import {
2
- isNotIn,
3
- registerDecorator,
4
- ValidationArguments,
5
- ValidationOptions
6
- } from 'class-validator';
1
+ import { isNotIn, registerDecorator, ValidationArguments, ValidationOptions } from 'class-validator';
7
2
 
8
- export function IsNotInRelativeTo<T, S>(
9
- excludedValuesCallback: (object: T) => S[],
10
- validationOptions?: ValidationOptions
11
- ) {
3
+ export function IsNotInRelativeTo<T, S>(excludedValuesCallback: (object: T) => S[], validationOptions?: ValidationOptions) {
12
4
  return function (object: Record<string, any>, propertyName: string): void {
13
5
  registerDecorator({
14
6
  name: 'isNotInRelativeTo',
15
7
  target: object.constructor,
16
8
  propertyName: propertyName,
17
- constraints: [
18
- { name: 'isNotInRelativeTo', relativeValueCallback: excludedValuesCallback }
19
- ],
9
+ constraints: [{ name: 'isNotInRelativeTo', relativeValueCallback: excludedValuesCallback }],
20
10
  options: validationOptions,
21
11
  validator: {
22
12
  validate(value: any, args: ValidationArguments) {
23
13
  const excludedValues = args.constraints[0].relativeValueCallback(args.object);
24
14
  if (Array.isArray(value) && validationOptions && validationOptions.each) {
25
- return value.every(v => isNotIn(v, excludedValues));
15
+ return value.every((v) => isNotIn(v, excludedValues));
26
16
  } else {
27
17
  return isNotIn(value, excludedValues);
28
18
  }
29
- }
30
- }
19
+ },
20
+ },
31
21
  });
32
22
  };
33
23
  }
@@ -3,10 +3,7 @@ import { ValidateIf, ValidationOptions } from 'class-validator';
3
3
  /**
4
4
  * Checks if value is missing and if so, ignores all validators.
5
5
  **/
6
- export function IsOptionalIf<T>(
7
- condition: (object: T, value: any) => boolean,
8
- validationOptions?: ValidationOptions
9
- ) {
6
+ export function IsOptionalIf<T>(condition: (object: T, value: any) => boolean, validationOptions?: ValidationOptions) {
10
7
  return ValidateIf((object: T, value: any) => {
11
8
  const valueIsNil = value === '' || value === null || value === undefined;
12
9
  return !valueIsNil || !condition(object, value);
@@ -11,8 +11,8 @@ export function PascalCase(validationOptions?: ValidationOptions) {
11
11
  validator: {
12
12
  validate(value: any) {
13
13
  return /^([A-Z]{1,3}[a-z0-9]*)+$/.test(value);
14
- }
15
- }
14
+ },
15
+ },
16
16
  });
17
17
  };
18
18
  }
@@ -69,7 +69,7 @@ export {
69
69
  MinLength,
70
70
  NotContains,
71
71
  NotEquals,
72
- ValidateNested
72
+ ValidateNested,
73
73
  } from 'class-validator';
74
74
  export * from './custom-validators';
75
75
  export { validate } from './validate';
@@ -86,14 +86,14 @@ const validationPriorities = [
86
86
  'greaterThanDate',
87
87
  'isNotInRelativeTo',
88
88
  'isOptionalIf',
89
- 'pascalCase'
89
+ 'pascalCase',
90
90
  ];
91
91
 
92
92
  function recursiveGetErrors(
93
93
  validationErrors: ClassValidatorValidationError[],
94
94
  errors: ValidationError[] = [],
95
95
  propertyName = '',
96
- previousValueWasArray = false
96
+ previousValueWasArray = false,
97
97
  ): ValidationError[] {
98
98
  for (const validationError of validationErrors) {
99
99
  if (!validationError) {
@@ -102,20 +102,15 @@ function recursiveGetErrors(
102
102
 
103
103
  if (validationError.constraints) {
104
104
  const containsNestedValidation =
105
- Object.keys(validationError.constraints).some(v => v === 'nestedValidation') &&
106
- validationError.children.length > 0;
105
+ Object.keys(validationError.constraints).some((v) => v === 'nestedValidation') && validationError.children.length > 0;
107
106
  const validations = Object.keys(validationError.constraints);
108
107
 
109
- const constraintName = validationPriorities.find(cm =>
110
- validations.some(cs => cs.split('-')[0] === cm)
111
- );
108
+ const constraintName = validationPriorities.find((cm) => validations.some((cs) => cs.split('-')[0] === cm));
112
109
 
113
110
  let domainErrorCode: string;
114
111
  let i = 0;
115
112
  while (!domainErrorCode) {
116
- domainErrorCode = validations.find(
117
- vp => vp.split('-')[0] === validationPriorities[i]
118
- );
113
+ domainErrorCode = validations.find((vp) => vp.split('-')[0] === validationPriorities[i]);
119
114
  i++;
120
115
  }
121
116
 
@@ -133,14 +128,7 @@ function recursiveGetErrors(
133
128
  : `${propertyName}.${validationError.property}`
134
129
  : validationError.property;
135
130
 
136
- errors.push(
137
- new ValidationError(
138
- domainErrorProperty,
139
- validationError.value,
140
- constraintName,
141
- null
142
- )
143
- );
131
+ errors.push(new ValidationError(domainErrorProperty, validationError.value, constraintName, null));
144
132
  }
145
133
 
146
134
  if (validationError.children && validationError.children.length) {
@@ -152,15 +140,12 @@ function recursiveGetErrors(
152
140
  }
153
141
 
154
142
  errors = recursiveGetErrors(
155
- validationError.children.filter(ve =>
156
- ve.constraints
157
- ? !Object.keys(ve.constraints).includes('nestedValidation') ||
158
- ve.children.length === 0
159
- : true
143
+ validationError.children.filter((ve) =>
144
+ ve.constraints ? !Object.keys(ve.constraints).includes('nestedValidation') || ve.children.length === 0 : true,
160
145
  ),
161
146
  errors,
162
147
  childName,
163
- Array.isArray(validationError.value)
148
+ Array.isArray(validationError.value),
164
149
  );
165
150
  }
166
151
  }
@@ -5,7 +5,7 @@ export class ValidationError {
5
5
  public readonly property: string,
6
6
  public readonly value: string,
7
7
  public readonly type: string,
8
- public readonly message: string | ((args: ValidationArguments) => string)
8
+ public readonly message: string | ((args: ValidationArguments) => string),
9
9
  ) {}
10
10
 
11
11
  public getErrorMessage(): string {
@@ -39,5 +39,5 @@ export {
39
39
  uniqBy as _uniqBy,
40
40
  upperFirst as _upperFirst,
41
41
  values as _values,
42
- words as _words
42
+ words as _words,
43
43
  } from 'lodash';