@my-devkit/core 1.0.121 → 1.0.122

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 (59) hide show
  1. package/.eslintrc.js +2 -4
  2. package/dist/date-helper.js +28 -20
  3. package/dist/date-helper.js.map +1 -1
  4. package/dist/decorators/cacheable.decorator.js.map +1 -1
  5. package/dist/enum-helper.js.map +1 -1
  6. package/dist/event.js +2 -1
  7. package/dist/event.js.map +1 -1
  8. package/dist/json-helper.js.map +1 -1
  9. package/dist/logger.js +4 -1
  10. package/dist/logger.js.map +1 -1
  11. package/dist/model.js.map +1 -1
  12. package/dist/retry.js.map +1 -1
  13. package/dist/serialize/deserialize.js +0 -1
  14. package/dist/serialize/deserialize.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 +28 -3
  18. package/dist/serialize/serialize-helper.js.map +1 -1
  19. package/dist/serialize/type-helper.d.ts +1 -1
  20. package/dist/serialize/type-helper.js +24 -11
  21. package/dist/serialize/type-helper.js.map +1 -1
  22. package/dist/sleep.js.map +1 -1
  23. package/dist/validators/custom-validators/greater-than-date.js.map +1 -1
  24. package/dist/validators/custom-validators/is-empty-if.js +4 -2
  25. package/dist/validators/custom-validators/is-empty-if.js.map +1 -1
  26. package/dist/validators/custom-validators/is-not-empty-if.js.map +1 -1
  27. package/dist/validators/custom-validators/is-not-in-relative-to.js +3 -1
  28. package/dist/validators/custom-validators/is-not-in-relative-to.js.map +1 -1
  29. package/dist/validators/custom-validators/is-optional-if.js +1 -2
  30. package/dist/validators/custom-validators/is-optional-if.js.map +1 -1
  31. package/dist/validators/index.js.map +1 -1
  32. package/dist/validators/validate.js +17 -5
  33. package/dist/validators/validate.js.map +1 -1
  34. package/dist/validators/validation-error.js.map +1 -1
  35. package/package.json +2 -2
  36. package/src/date-helper.ts +91 -64
  37. package/src/decorators/cacheable.decorator.ts +29 -13
  38. package/src/enum-helper.ts +4 -2
  39. package/src/event.ts +2 -1
  40. package/src/json-helper.ts +3 -1
  41. package/src/logger.ts +9 -2
  42. package/src/model.ts +4 -1
  43. package/src/retry.ts +8 -2
  44. package/src/serialize/deserialize.ts +0 -1
  45. package/src/serialize/index.ts +7 -2
  46. package/src/serialize/serializable.ts +3 -2
  47. package/src/serialize/serialize-helper.ts +40 -14
  48. package/src/serialize/type-helper.ts +39 -15
  49. package/src/sleep.ts +1 -1
  50. package/src/validators/custom-validators/greater-than-date.ts +5 -1
  51. package/src/validators/custom-validators/is-empty-if.ts +10 -3
  52. package/src/validators/custom-validators/is-not-empty-if.ts +4 -1
  53. package/src/validators/custom-validators/is-not-in-relative-to.ts +13 -3
  54. package/src/validators/custom-validators/is-optional-if.ts +5 -3
  55. package/src/validators/index.ts +65 -11
  56. package/src/validators/validate.ts +42 -10
  57. package/src/validators/validation-error.ts +2 -3
  58. package/src/vendors/lodash.ts +0 -1
  59. package/tsconfig.json +1 -3
@@ -1,4 +1,3 @@
1
- /* eslint-disable @typescript-eslint/ban-types */
2
1
  import { Deserialize, GenericDeserialize, Serialize, __TypeMap } from 'cerialize';
3
2
 
4
3
  import { _get, _isObjectLike, _keys, _trimEnd } from '../vendors/lodash';
@@ -8,8 +7,7 @@ export class TypeHelper {
8
7
  const serialized = Serialize(rawJson, classType);
9
8
  const deserialized = GenericDeserialize(serialized, classType);
10
9
 
11
- if ((new classType())['_type'] === classType.name)
12
- deserialized['_type'] = classType.name;
10
+ if (new classType()['_type'] === classType.name) deserialized['_type'] = classType.name;
13
11
 
14
12
  return deserialized;
15
13
  }
@@ -21,7 +19,9 @@ export class TypeHelper {
21
19
  const remaining = metaData.map(m => ({ parent: null, m }));
22
20
  while (remaining.length > 0) {
23
21
  const property = remaining.shift();
24
- const path = property.parent ? `${property.parent}.${property.m.name}` : property.m.name;
22
+ const path = property.parent
23
+ ? `${property.parent}.${property.m.name}`
24
+ : property.m.name;
25
25
  result.push({
26
26
  parent: property.parent ? _trimEnd(property.parent, '[]') : null,
27
27
  path,
@@ -33,7 +33,7 @@ export class TypeHelper {
33
33
 
34
34
  if (property.m.type === TypeHelper.Type.Object) {
35
35
  const parent = property.m.isArray ? `${path}[]` : path;
36
- remaining.push(...property.m.objectMetadata.map(m => ({ parent, m })))
36
+ remaining.push(...property.m.objectMetadata.map(m => ({ parent, m })));
37
37
  }
38
38
  }
39
39
  return result;
@@ -49,15 +49,24 @@ export class TypeHelper {
49
49
  const metaDataType = TypeHelper.getMetaDataType(m.deserializedType);
50
50
  const metadata: TypeHelper.MetaData = {
51
51
  name: m.keyName,
52
- serializedKey: (m.serializedKey ? m.serializedKey : m.keyName),
53
- deserializedKey: (m.deserializedKey ? m.deserializedKey : m.keyName),
52
+ serializedKey: m.serializedKey ? m.serializedKey : m.keyName,
53
+ deserializedKey: m.deserializedKey ? m.deserializedKey : m.keyName,
54
54
  type: metaDataType,
55
- enumName: metaDataType === TypeHelper.Type.Enum ? this.getEnumName(m.deserializedType) : null,
55
+ enumName:
56
+ metaDataType === TypeHelper.Type.Enum
57
+ ? this.getEnumName(m.deserializedType)
58
+ : null,
56
59
  isArray: Array.isArray(instance[m.keyName]),
57
60
  arrayLength: Array.isArray(instance[m.keyName]) ? instance[m.keyName].length : null,
58
61
  objectName: metaDataType === TypeHelper.Type.Object ? m.deserializedType.name : [],
59
- objectMetadata: metaDataType === TypeHelper.Type.Object ? this.getMetaData(m.deserializedType) : [],
60
- enumValues: metaDataType === TypeHelper.Type.Enum ? this.getEnumValues(m.deserializedType) : []
62
+ objectMetadata:
63
+ metaDataType === TypeHelper.Type.Object
64
+ ? this.getMetaData(m.deserializedType)
65
+ : [],
66
+ enumValues:
67
+ metaDataType === TypeHelper.Type.Enum
68
+ ? this.getEnumValues(m.deserializedType)
69
+ : []
61
70
  };
62
71
  return metadata;
63
72
  });
@@ -132,21 +141,33 @@ export class TypeHelper {
132
141
  }
133
142
 
134
143
  private static isString(propType: any) {
135
- if (propType && propType.Deserialize && propType.Deserialize.name.replace('deserialize', '') === 'String') {
144
+ if (
145
+ propType &&
146
+ propType.Deserialize &&
147
+ propType.Deserialize.name.replace('deserialize', '') === 'String'
148
+ ) {
136
149
  return true;
137
150
  }
138
151
  return false;
139
152
  }
140
153
 
141
154
  private static isBoolean(propType: any) {
142
- if (propType && propType.Deserialize && propType.Deserialize.name.replace('deserialize', '') === 'Boolean') {
155
+ if (
156
+ propType &&
157
+ propType.Deserialize &&
158
+ propType.Deserialize.name.replace('deserialize', '') === 'Boolean'
159
+ ) {
143
160
  return true;
144
161
  }
145
162
  return false;
146
163
  }
147
164
 
148
165
  private static isNumber(propType: any) {
149
- if (propType && propType.Deserialize && propType.Deserialize.name.replace('deserialize', '') === 'Number') {
166
+ if (
167
+ propType &&
168
+ propType.Deserialize &&
169
+ propType.Deserialize.name.replace('deserialize', '') === 'Number'
170
+ ) {
150
171
  return true;
151
172
  }
152
173
  return false;
@@ -194,8 +215,11 @@ export namespace TypeHelper {
194
215
  }
195
216
 
196
217
  type NonFunctionPropertyNames<T> = {
197
- [K in keyof T]: T[K] extends Function ? never : K
218
+ [K in keyof T]: T[K] extends (...args: any[]) => any ? never : K;
198
219
  }[keyof T];
199
220
 
200
- export type ClassProperties<T> = Omit<Pick<T, NonFunctionPropertyNames<T>>, '_path' | 'publishedAt' | 'publishedAt'>;
221
+ export type ClassProperties<T> = Omit<
222
+ Pick<T, NonFunctionPropertyNames<T>>,
223
+ '_path' | 'publishedAt' | 'publishedAt'
224
+ >;
201
225
  }
package/src/sleep.ts CHANGED
@@ -7,4 +7,4 @@ import { Logger } from './logger';
7
7
  export const sleep = async (miliseconds: number): Promise<void> => {
8
8
  Logger.info(`Sleeping ${miliseconds} ms`);
9
9
  return new Promise<void>(resolve => setTimeout(() => resolve(), miliseconds));
10
- }
10
+ };
@@ -1,6 +1,10 @@
1
1
  import { registerDecorator, ValidationArguments, ValidationOptions } from 'class-validator';
2
2
 
3
- export function GreaterThanDate(property: string, milliSecondsOffset?: number, validationOptions?: ValidationOptions) {
3
+ export function GreaterThanDate(
4
+ property: string,
5
+ milliSecondsOffset?: number,
6
+ validationOptions?: ValidationOptions
7
+ ) {
4
8
  return function (object: Record<string, any>, propertyName: string): void {
5
9
  registerDecorator({
6
10
  name: 'greaterThanDate',
@@ -1,8 +1,10 @@
1
- // eslint-disable-next-line no-restricted-imports
2
1
  import { registerDecorator, ValidationArguments, ValidationOptions } from 'class-validator';
3
2
  import { isNil } from 'lodash';
4
3
 
5
- export function IsEmptyIf<T>(condition: (object: T) => boolean, validationOptions?: ValidationOptions) {
4
+ export function IsEmptyIf<T>(
5
+ condition: (object: T) => boolean,
6
+ validationOptions?: ValidationOptions
7
+ ) {
6
8
  return function (object: Record<string, any>, propertyName: string): void {
7
9
  registerDecorator({
8
10
  name: 'isEmpty',
@@ -15,7 +17,12 @@ export function IsEmptyIf<T>(condition: (object: T) => boolean, validationOption
15
17
  const [relatedCondition] = args.constraints;
16
18
  const cond = relatedCondition(args.object);
17
19
 
18
- if (cond && Array.isArray(value) && validationOptions && validationOptions.each) {
20
+ if (
21
+ cond &&
22
+ Array.isArray(value) &&
23
+ validationOptions &&
24
+ validationOptions.each
25
+ ) {
19
26
  return value.every(v => isNil(v));
20
27
  } else if (cond) {
21
28
  return isNil(value);
@@ -1,7 +1,10 @@
1
1
  import { registerDecorator, ValidationArguments, ValidationOptions } from 'class-validator';
2
2
  import { isNil } from 'lodash';
3
3
 
4
- export function IsNotEmptyIf<T>(condition: (object: T) => boolean, validationOptions?: ValidationOptions) {
4
+ export function IsNotEmptyIf<T>(
5
+ condition: (object: T) => boolean,
6
+ validationOptions?: ValidationOptions
7
+ ) {
5
8
  return function (object: Record<string, any>, propertyName: string): void {
6
9
  registerDecorator({
7
10
  name: 'isNotEmpty',
@@ -1,12 +1,22 @@
1
- import { isNotIn, registerDecorator, ValidationArguments, ValidationOptions } from 'class-validator';
1
+ import {
2
+ isNotIn,
3
+ registerDecorator,
4
+ ValidationArguments,
5
+ ValidationOptions
6
+ } from 'class-validator';
2
7
 
3
- export function IsNotInRelativeTo<T, S>(excludedValuesCallback: (object: T) => S[], validationOptions?: ValidationOptions) {
8
+ export function IsNotInRelativeTo<T, S>(
9
+ excludedValuesCallback: (object: T) => S[],
10
+ validationOptions?: ValidationOptions
11
+ ) {
4
12
  return function (object: Record<string, any>, propertyName: string): void {
5
13
  registerDecorator({
6
14
  name: 'isNotInRelativeTo',
7
15
  target: object.constructor,
8
16
  propertyName: propertyName,
9
- constraints: [{ name: 'isNotInRelativeTo', relativeValueCallback: excludedValuesCallback }],
17
+ constraints: [
18
+ { name: 'isNotInRelativeTo', relativeValueCallback: excludedValuesCallback }
19
+ ],
10
20
  options: validationOptions,
11
21
  validator: {
12
22
  validate(value: any, args: ValidationArguments) {
@@ -1,12 +1,14 @@
1
- // eslint-disable-next-line no-restricted-imports
2
1
  import { ValidateIf, ValidationOptions } from 'class-validator';
3
2
 
4
3
  /**
5
4
  * Checks if value is missing and if so, ignores all validators.
6
5
  **/
7
- export function IsOptionalIf<T>(condition: (object: T, value: any) => boolean, validationOptions?: ValidationOptions) {
6
+ export function IsOptionalIf<T>(
7
+ condition: (object: T, value: any) => boolean,
8
+ validationOptions?: ValidationOptions
9
+ ) {
8
10
  return ValidateIf((object: T, value: any) => {
9
- const valueIsNil = (value === '' || value === null || value === undefined);
11
+ const valueIsNil = value === '' || value === null || value === undefined;
10
12
  return !valueIsNil || !condition(object, value);
11
13
  }, validationOptions);
12
14
  }
@@ -1,21 +1,75 @@
1
1
  export {
2
2
  // array validation methods
3
- ArrayContains, ArrayMaxSize, ArrayMinSize, ArrayNotContains, ArrayNotEmpty, ArrayUnique,
3
+ ArrayContains,
4
+ ArrayMaxSize,
5
+ ArrayMinSize,
6
+ ArrayNotContains,
7
+ ArrayNotEmpty,
8
+ ArrayUnique,
4
9
  // string validation methods
5
- Contains, Equals, IsAlpha, IsAlphanumeric,
10
+ Contains,
11
+ Equals,
12
+ IsAlpha,
13
+ IsAlphanumeric,
6
14
  // type validation methods
7
- IsArray, IsAscii, IsBase64, IsBoolean,
15
+ IsArray,
16
+ IsAscii,
17
+ IsBase64,
18
+ IsBoolean,
8
19
  // string-type validation methods
9
- IsBooleanString, IsByteLength,
10
- IsCreditCard, IsCurrency, IsDate, IsDefined,
20
+ IsBooleanString,
21
+ IsByteLength,
22
+ IsCreditCard,
23
+ IsCurrency,
24
+ IsDate,
25
+ IsDefined,
11
26
  // number validation methods
12
- IsDivisibleBy, IsEmail, IsEmpty, IsEnum, IsFQDN, IsFullWidth, IsHalfWidth, IsHexColor, IsHexadecimal, IsIP, IsISBN, IsISIN, IsISO8601, IsIn, IsInt, IsJSON, IsLowercase, IsMilitaryTime, IsMobilePhone,
13
- IsMongoId, IsMultibyte, IsNegative, IsNotEmpty, IsNotIn, IsNumber, IsNumberString, IsOptional, IsPositive, IsString, IsSurrogatePair, IsUUID, IsUppercase, IsUrl, IsVariableWidth, Length, Matches, Max, MaxDate, MaxLength, Min,
27
+ IsDivisibleBy,
28
+ IsEmail,
29
+ IsEmpty,
30
+ IsEnum,
31
+ IsFQDN,
32
+ IsFullWidth,
33
+ IsHalfWidth,
34
+ IsHexColor,
35
+ IsHexadecimal,
36
+ IsIP,
37
+ IsISBN,
38
+ IsISIN,
39
+ IsISO8601,
40
+ IsIn,
41
+ IsInt,
42
+ IsJSON,
43
+ IsLowercase,
44
+ IsMilitaryTime,
45
+ IsMobilePhone,
46
+ IsMongoId,
47
+ IsMultibyte,
48
+ IsNegative,
49
+ IsNotEmpty,
50
+ IsNotIn,
51
+ IsNumber,
52
+ IsNumberString,
53
+ IsOptional,
54
+ IsPositive,
55
+ IsString,
56
+ IsSurrogatePair,
57
+ IsUUID,
58
+ IsUppercase,
59
+ IsUrl,
60
+ IsVariableWidth,
61
+ Length,
62
+ Matches,
63
+ Max,
64
+ MaxDate,
65
+ MaxLength,
66
+ Min,
14
67
  // date validation methods
15
- MinDate, MinLength, NotContains, NotEquals, ValidateNested
68
+ MinDate,
69
+ MinLength,
70
+ NotContains,
71
+ NotEquals,
72
+ ValidateNested
16
73
  } from 'class-validator';
17
74
  export * from './custom-validators';
18
75
  export { validate } from './validate';
19
-
20
-
21
-
@@ -89,43 +89,75 @@ const validationPriorities = [
89
89
  'pascalCase'
90
90
  ];
91
91
 
92
- function recursiveGetErrors(validationErrors: ClassValidatorValidationError[], errors: ValidationError[] = [],
93
- propertyName = '', previousValueWasArray = false): ValidationError[] {
92
+ function recursiveGetErrors(
93
+ validationErrors: ClassValidatorValidationError[],
94
+ errors: ValidationError[] = [],
95
+ propertyName = '',
96
+ previousValueWasArray = false
97
+ ): ValidationError[] {
94
98
  for (const validationError of validationErrors) {
95
99
  if (!validationError) {
96
100
  return null;
97
101
  }
98
102
 
99
103
  if (validationError.constraints) {
100
- const containsNestedValidation = Object.keys(validationError.constraints).some(v => v === 'nestedValidation') && validationError.children.length > 0;
104
+ const containsNestedValidation =
105
+ Object.keys(validationError.constraints).some(v => v === 'nestedValidation') &&
106
+ validationError.children.length > 0;
101
107
  const validations = Object.keys(validationError.constraints);
102
108
 
103
- const constraintName = validationPriorities.find(cm => validations.some(cs => cs.split('-')[0] === cm));
109
+ const constraintName = validationPriorities.find(cm =>
110
+ validations.some(cs => cs.split('-')[0] === cm)
111
+ );
104
112
 
105
113
  let domainErrorCode: string;
106
114
  let i = 0;
107
115
  while (!domainErrorCode) {
108
- domainErrorCode = validations.find(vp => vp.split('-')[0] === validationPriorities[i]);
116
+ domainErrorCode = validations.find(
117
+ vp => vp.split('-')[0] === validationPriorities[i]
118
+ );
109
119
  i++;
110
120
  }
111
121
 
112
- if (validationError.contexts && validationError.contexts[domainErrorCode] && validationError.contexts[domainErrorCode].domainErrorCodes) {
122
+ if (
123
+ validationError.contexts &&
124
+ validationError.contexts[domainErrorCode] &&
125
+ validationError.contexts[domainErrorCode].domainErrorCodes
126
+ ) {
113
127
  domainErrorCode = validationError.contexts[domainErrorCode].domainErrorCodes;
114
128
  }
115
129
 
116
- const domainErrorProperty = propertyName ? (containsNestedValidation ? propertyName : `${propertyName}.${validationError.property}`) : validationError.property;
130
+ const domainErrorProperty = propertyName
131
+ ? containsNestedValidation
132
+ ? propertyName
133
+ : `${propertyName}.${validationError.property}`
134
+ : validationError.property;
117
135
 
118
- errors.push(new ValidationError(domainErrorProperty, validationError.value, constraintName, null));
136
+ errors.push(
137
+ new ValidationError(
138
+ domainErrorProperty,
139
+ validationError.value,
140
+ constraintName,
141
+ null
142
+ )
143
+ );
119
144
  }
120
145
 
121
146
  if (validationError.children && validationError.children.length) {
122
147
  let childName = validationError.property;
123
148
  if (propertyName) {
124
- childName = previousValueWasArray ? `${propertyName}[${validationError.property}]` : `${propertyName}.${validationError.property}`;
149
+ childName = previousValueWasArray
150
+ ? `${propertyName}[${validationError.property}]`
151
+ : `${propertyName}.${validationError.property}`;
125
152
  }
126
153
 
127
154
  errors = recursiveGetErrors(
128
- validationError.children.filter(ve => ve.constraints ? !Object.keys(ve.constraints).includes('nestedValidation') || ve.children.length === 0 : true),
155
+ validationError.children.filter(ve =>
156
+ ve.constraints
157
+ ? !Object.keys(ve.constraints).includes('nestedValidation') ||
158
+ ve.children.length === 0
159
+ : true
160
+ ),
129
161
  errors,
130
162
  childName,
131
163
  Array.isArray(validationError.value)
@@ -5,9 +5,8 @@ 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)) {
9
-
10
- }
8
+ public readonly message: string | ((args: ValidationArguments) => string)
9
+ ) {}
11
10
 
12
11
  public getErrorMessage(): string {
13
12
  if (this.message && typeof this.message === 'string') {
@@ -41,4 +41,3 @@ export {
41
41
  values as _values,
42
42
  words as _words
43
43
  } from 'lodash';
44
-
package/tsconfig.json CHANGED
@@ -10,8 +10,6 @@
10
10
  "declaration": true,
11
11
  "emitDecoratorMetadata": true,
12
12
  "experimentalDecorators": true,
13
- "lib": [
14
- "ES2021"
15
- ]
13
+ "lib": ["ES2021"]
16
14
  }
17
15
  }