@my-devkit/core 1.0.54 → 1.0.58

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 (173) hide show
  1. package/.eslintrc.js +15 -0
  2. package/.vscode/settings.json +7 -0
  3. package/{command.d.ts → dist/command.d.ts} +0 -0
  4. package/{command.js → dist/command.js} +0 -0
  5. package/{command.js.map → dist/command.js.map} +0 -0
  6. package/{date-helper.d.ts → dist/date-helper.d.ts} +0 -0
  7. package/{date-helper.js → dist/date-helper.js} +0 -0
  8. package/{date-helper.js.map → dist/date-helper.js.map} +0 -0
  9. package/{decorators → dist/decorators}/cacheable.decorator.d.ts +0 -0
  10. package/{decorators → dist/decorators}/cacheable.decorator.js +0 -0
  11. package/{decorators → dist/decorators}/cacheable.decorator.js.map +0 -0
  12. package/{decorators → dist/decorators}/index.d.ts +0 -0
  13. package/{decorators → dist/decorators}/index.js +0 -0
  14. package/{decorators → dist/decorators}/index.js.map +0 -0
  15. package/{decorators → dist/decorators}/retryable.decorator.d.ts +0 -0
  16. package/{decorators → dist/decorators}/retryable.decorator.js +0 -0
  17. package/{decorators → dist/decorators}/retryable.decorator.js.map +0 -0
  18. package/{document.d.ts → dist/document.d.ts} +0 -0
  19. package/{document.js → dist/document.js} +0 -0
  20. package/{document.js.map → dist/document.js.map} +0 -0
  21. package/{enum-helper.d.ts → dist/enum-helper.d.ts} +0 -0
  22. package/{enum-helper.js → dist/enum-helper.js} +0 -0
  23. package/{enum-helper.js.map → dist/enum-helper.js.map} +0 -0
  24. package/{errors → dist/errors}/bad-request-error.d.ts +0 -0
  25. package/{errors → dist/errors}/bad-request-error.js +0 -0
  26. package/{errors → dist/errors}/bad-request-error.js.map +0 -0
  27. package/{errors → dist/errors}/domain-error.d.ts +0 -0
  28. package/{errors → dist/errors}/domain-error.js +0 -0
  29. package/{errors → dist/errors}/domain-error.js.map +0 -0
  30. package/{errors → dist/errors}/error-base.d.ts +0 -0
  31. package/{errors → dist/errors}/error-base.js +0 -0
  32. package/{errors → dist/errors}/error-base.js.map +0 -0
  33. package/{errors → dist/errors}/forbidden-error.d.ts +0 -0
  34. package/{errors → dist/errors}/forbidden-error.js +0 -0
  35. package/{errors → dist/errors}/forbidden-error.js.map +0 -0
  36. package/{errors → dist/errors}/index.d.ts +0 -0
  37. package/{errors → dist/errors}/index.js +0 -0
  38. package/{errors → dist/errors}/index.js.map +0 -0
  39. package/{errors → dist/errors}/not-found-error.d.ts +0 -0
  40. package/{errors → dist/errors}/not-found-error.js +0 -0
  41. package/{errors → dist/errors}/not-found-error.js.map +0 -0
  42. package/{errors → dist/errors}/not-implemented-error.d.ts +0 -0
  43. package/{errors → dist/errors}/not-implemented-error.js +0 -0
  44. package/{errors → dist/errors}/not-implemented-error.js.map +0 -0
  45. package/{errors → dist/errors}/unauthorized-error.d.ts +0 -0
  46. package/{errors → dist/errors}/unauthorized-error.js +0 -0
  47. package/{errors → dist/errors}/unauthorized-error.js.map +0 -0
  48. package/{event.d.ts → dist/event.d.ts} +0 -0
  49. package/{event.js → dist/event.js} +0 -0
  50. package/{event.js.map → dist/event.js.map} +0 -0
  51. package/{guid → dist/guid}/index.d.ts +0 -0
  52. package/{guid → dist/guid}/index.js +0 -0
  53. package/{guid → dist/guid}/index.js.map +0 -0
  54. package/{index.d.ts → dist/index.d.ts} +0 -0
  55. package/{index.js → dist/index.js} +0 -0
  56. package/{index.js.map → dist/index.js.map} +0 -0
  57. package/{logger.d.ts → dist/logger.d.ts} +0 -0
  58. package/{logger.js → dist/logger.js} +0 -0
  59. package/{logger.js.map → dist/logger.js.map} +0 -0
  60. package/{maintenance-model.d.ts → dist/maintenance-model.d.ts} +0 -0
  61. package/{maintenance-model.js → dist/maintenance-model.js} +0 -0
  62. package/{maintenance-model.js.map → dist/maintenance-model.js.map} +0 -0
  63. package/{model.d.ts → dist/model.d.ts} +0 -0
  64. package/{model.js → dist/model.js} +0 -0
  65. package/{model.js.map → dist/model.js.map} +0 -0
  66. package/{release-model.d.ts → dist/release-model.d.ts} +0 -0
  67. package/{release-model.js → dist/release-model.js} +0 -0
  68. package/{release-model.js.map → dist/release-model.js.map} +0 -0
  69. package/{retry.d.ts → dist/retry.d.ts} +0 -0
  70. package/{retry.js → dist/retry.js} +0 -0
  71. package/{retry.js.map → dist/retry.js.map} +0 -0
  72. package/{serialize → dist/serialize}/deserialize.d.ts +0 -0
  73. package/{serialize → dist/serialize}/deserialize.js +0 -0
  74. package/{serialize → dist/serialize}/deserialize.js.map +0 -0
  75. package/{serialize → dist/serialize}/index.d.ts +0 -0
  76. package/{serialize → dist/serialize}/index.js +0 -0
  77. package/{serialize → dist/serialize}/index.js.map +0 -0
  78. package/{serialize → dist/serialize}/serializable.d.ts +0 -0
  79. package/{serialize → dist/serialize}/serializable.js +0 -0
  80. package/{serialize → dist/serialize}/serializable.js.map +0 -0
  81. package/{serialize → dist/serialize}/serialize.d.ts +0 -0
  82. package/{serialize → dist/serialize}/serialize.js +0 -0
  83. package/{serialize → dist/serialize}/serialize.js.map +0 -0
  84. package/{serialize → dist/serialize}/type-helper.d.ts +0 -0
  85. package/{serialize → dist/serialize}/type-helper.js +0 -0
  86. package/{serialize → dist/serialize}/type-helper.js.map +0 -0
  87. package/{sleep.d.ts → dist/sleep.d.ts} +0 -0
  88. package/{sleep.js → dist/sleep.js} +0 -0
  89. package/{sleep.js.map → dist/sleep.js.map} +0 -0
  90. package/{validators → dist/validators}/custom-validators/camel-case.d.ts +0 -0
  91. package/{validators → dist/validators}/custom-validators/camel-case.js +0 -0
  92. package/{validators → dist/validators}/custom-validators/camel-case.js.map +0 -0
  93. package/{validators → dist/validators}/custom-validators/equals-to.d.ts +0 -0
  94. package/{validators → dist/validators}/custom-validators/equals-to.js +0 -0
  95. package/{validators → dist/validators}/custom-validators/equals-to.js.map +0 -0
  96. package/{validators → dist/validators}/custom-validators/greater-or-equal-than.d.ts +0 -0
  97. package/{validators → dist/validators}/custom-validators/greater-or-equal-than.js +0 -0
  98. package/{validators → dist/validators}/custom-validators/greater-or-equal-than.js.map +0 -0
  99. package/{validators → dist/validators}/custom-validators/greater-than-date.d.ts +0 -0
  100. package/{validators → dist/validators}/custom-validators/greater-than-date.js +0 -0
  101. package/{validators → dist/validators}/custom-validators/greater-than-date.js.map +0 -0
  102. package/{validators → dist/validators}/custom-validators/index.d.ts +0 -0
  103. package/{validators → dist/validators}/custom-validators/index.js +0 -0
  104. package/{validators → dist/validators}/custom-validators/index.js.map +0 -0
  105. package/{validators → dist/validators}/custom-validators/is-not-in-relative-to.d.ts +0 -0
  106. package/{validators → dist/validators}/custom-validators/is-not-in-relative-to.js +0 -0
  107. package/{validators → dist/validators}/custom-validators/is-not-in-relative-to.js.map +0 -0
  108. package/{validators → dist/validators}/custom-validators/is-optional-if.d.ts +0 -0
  109. package/{validators → dist/validators}/custom-validators/is-optional-if.js +0 -0
  110. package/{validators → dist/validators}/custom-validators/is-optional-if.js.map +0 -0
  111. package/{validators → dist/validators}/custom-validators/pascal-case.d.ts +0 -0
  112. package/{validators → dist/validators}/custom-validators/pascal-case.js +0 -0
  113. package/{validators → dist/validators}/custom-validators/pascal-case.js.map +0 -0
  114. package/{validators → dist/validators}/index.d.ts +0 -0
  115. package/{validators → dist/validators}/index.js +0 -0
  116. package/{validators → dist/validators}/index.js.map +0 -0
  117. package/{validators → dist/validators}/validate.d.ts +0 -0
  118. package/{validators → dist/validators}/validate.js +0 -0
  119. package/{validators → dist/validators}/validate.js.map +0 -0
  120. package/{validators → dist/validators}/validation-error.d.ts +0 -0
  121. package/{validators → dist/validators}/validation-error.js +0 -0
  122. package/{validators → dist/validators}/validation-error.js.map +0 -0
  123. package/{vendors → dist/vendors}/index.d.ts +0 -0
  124. package/{vendors → dist/vendors}/index.js +0 -0
  125. package/{vendors → dist/vendors}/index.js.map +0 -0
  126. package/{vendors → dist/vendors}/lodash.d.ts +0 -0
  127. package/{vendors → dist/vendors}/lodash.js +0 -0
  128. package/{vendors → dist/vendors}/lodash.js.map +0 -0
  129. package/package.json +4 -4
  130. package/src/command.ts +9 -0
  131. package/src/date-helper.ts +26 -0
  132. package/src/decorators/cacheable.decorator.ts +20 -0
  133. package/src/decorators/index.ts +2 -0
  134. package/src/decorators/retryable.decorator.ts +11 -0
  135. package/src/document.ts +5 -0
  136. package/src/enum-helper.ts +17 -0
  137. package/src/errors/bad-request-error.ts +8 -0
  138. package/src/errors/domain-error.ts +8 -0
  139. package/src/errors/error-base.ts +3 -0
  140. package/src/errors/forbidden-error.ts +8 -0
  141. package/src/errors/index.ts +8 -0
  142. package/src/errors/not-found-error.ts +8 -0
  143. package/src/errors/not-implemented-error.ts +8 -0
  144. package/src/errors/unauthorized-error.ts +8 -0
  145. package/src/event.ts +32 -0
  146. package/src/guid/index.ts +3 -0
  147. package/src/index.ts +20 -0
  148. package/src/logger.ts +71 -0
  149. package/src/maintenance-model.ts +12 -0
  150. package/src/model.ts +15 -0
  151. package/src/release-model.ts +12 -0
  152. package/src/retry.ts +41 -0
  153. package/src/serialize/deserialize.ts +11 -0
  154. package/src/serialize/index.ts +6 -0
  155. package/src/serialize/serializable.ts +30 -0
  156. package/src/serialize/serialize.ts +7 -0
  157. package/src/serialize/type-helper.ts +167 -0
  158. package/src/sleep.ts +10 -0
  159. package/src/validators/custom-validators/camel-case.ts +18 -0
  160. package/src/validators/custom-validators/equals-to.ts +20 -0
  161. package/src/validators/custom-validators/greater-or-equal-than.ts +23 -0
  162. package/src/validators/custom-validators/greater-than-date.ts +28 -0
  163. package/src/validators/custom-validators/index.ts +7 -0
  164. package/src/validators/custom-validators/is-not-in-relative-to.ts +25 -0
  165. package/src/validators/custom-validators/is-optional-if.ts +21 -0
  166. package/src/validators/custom-validators/pascal-case.ts +18 -0
  167. package/src/validators/index.ts +24 -0
  168. package/src/validators/validate.ts +134 -0
  169. package/src/validators/validation-error.ts +27 -0
  170. package/src/vendors/index.ts +1 -0
  171. package/src/vendors/lodash.ts +62 -0
  172. package/tsconfig.json +20 -0
  173. package/my-devkit-core-1.0.54.tgz +0 -0
@@ -0,0 +1,134 @@
1
+ import { getFromContainer, MetadataStorage, validateSync, ValidationError as ClassValidatorValidationError } from 'class-validator';
2
+ import { ValidationMetadata } from 'class-validator/metadata/ValidationMetadata';
3
+
4
+ import { Logger } from '../logger';
5
+ import { ValidationError } from './validation-error';
6
+
7
+ export function validate(data: unknown): ValidationError[] {
8
+ const errors = validateSync(data);
9
+ return recursiveGetErrors(errors);
10
+ }
11
+
12
+ const validationPriorities = [
13
+ // common validation methods
14
+ 'isDefined',
15
+ 'equals',
16
+ 'notEquals',
17
+ 'isEmpty',
18
+ 'isNotEmpty',
19
+ 'isIn',
20
+ 'isNotIn',
21
+ // type validation methods
22
+ 'isArray',
23
+ 'isBoolean',
24
+ 'isDate',
25
+ 'isString',
26
+ 'isNumber',
27
+ 'isInt',
28
+ 'isEnum',
29
+ // number validation methods
30
+ 'isDivisibleBy',
31
+ 'isPositive',
32
+ 'isNegative',
33
+ 'max',
34
+ 'min',
35
+ // date validation methods
36
+ 'minDate',
37
+ 'maxDate',
38
+ // string-type validation methods
39
+ 'isBooleanString',
40
+ 'isNumberString',
41
+ // string validation methods
42
+ 'contains',
43
+ 'notContains',
44
+ 'isAlpha',
45
+ 'isAlphanumeric',
46
+ 'isAscii',
47
+ 'isBase64',
48
+ 'isByteLength',
49
+ 'isCreditCard',
50
+ 'isCurrency',
51
+ 'isEmail',
52
+ 'isFQDN',
53
+ 'isFullWidth',
54
+ 'isHalfWidth',
55
+ 'isVariableWidth',
56
+ 'isHexColor',
57
+ 'isHexadecimal',
58
+ 'isIP',
59
+ 'isISBN',
60
+ 'isISIN',
61
+ 'isISO8601',
62
+ 'isJSON',
63
+ 'isLowercase',
64
+ 'isMobilePhone',
65
+ 'isMongoId',
66
+ 'isMultibyte',
67
+ 'isSurrogatePair',
68
+ 'isUrl',
69
+ 'isUUID',
70
+ 'isUppercase',
71
+ 'length',
72
+ 'minLength',
73
+ 'maxLength',
74
+ 'matches',
75
+ 'isMilitaryTime',
76
+ // array validation methods
77
+ 'arrayContains',
78
+ 'arrayNotContains',
79
+ 'arrayNotEmpty',
80
+ 'arrayMinSize',
81
+ 'arrayMaxSize',
82
+ 'arrayUnique',
83
+ // custom
84
+ 'camelCase',
85
+ 'equalsTo',
86
+ 'greaterOrEqualThan',
87
+ 'greaterThanDate',
88
+ 'isNotInRelativeTo',
89
+ 'isOptionalIf',
90
+ 'pascalCase'
91
+ ];
92
+
93
+ function getMetadatas(validationError: ClassValidatorValidationError, constraintName: string): ValidationMetadata {
94
+ const metadatas = getFromContainer(MetadataStorage);
95
+ const validationMetadatas: ValidationMetadata[] = (metadatas as any).validationMetadatas;
96
+ const filteredMetadatas = validationMetadatas
97
+ .filter(vmd => vmd.target === validationError.target.constructor
98
+ && vmd.propertyName === validationError.property
99
+ && (vmd.type === constraintName || (vmd.type === 'customValidation' && vmd.constraints[0] && vmd.constraints[0].name === constraintName)));
100
+ return filteredMetadatas[0];
101
+ }
102
+
103
+ function recursiveGetErrors(validationErrors: ClassValidatorValidationError[], errors: ValidationError[] = [],
104
+ propertyName = '', previousValueWasArray = false): ValidationError[] {
105
+ validationErrors.forEach(validationError => {
106
+ let actualPropertyName = propertyName;
107
+ let actualPreviousValueWasArray = previousValueWasArray;
108
+ if (validationError.children.length > 0) {
109
+ if (actualPreviousValueWasArray) {
110
+ actualPropertyName = `${actualPropertyName}[${validationError.property}]`;
111
+ } else {
112
+ actualPropertyName =
113
+ actualPropertyName ? `${actualPropertyName}.${validationError.property}` : validationError.property;
114
+ }
115
+
116
+ actualPreviousValueWasArray = Array.isArray(validationError.value);
117
+ validationErrors = validationError.children;
118
+
119
+ errors = recursiveGetErrors(validationErrors, errors, actualPropertyName, actualPreviousValueWasArray);
120
+ } else {
121
+ actualPropertyName = actualPropertyName ? `${actualPropertyName}.${validationError.property}` : validationError.property;
122
+
123
+ const constraintName = validationPriorities.find(cm => Object.keys(validationError.constraints).some(cs => cs === cm));
124
+ if (!constraintName) {
125
+ Logger.warn(`validate: Constraint not found for ${actualPropertyName}`);
126
+ } else {
127
+ const metadatas = getMetadatas(validationError, constraintName);
128
+ errors.push(new ValidationError(actualPropertyName, validationError.value, constraintName, metadatas ? metadatas.message : null));
129
+ }
130
+
131
+ }
132
+ });
133
+ return errors;
134
+ }
@@ -0,0 +1,27 @@
1
+ import { ValidationArguments } from 'class-validator';
2
+
3
+ export class ValidationError {
4
+ constructor(
5
+ public readonly property: string,
6
+ public readonly value: string,
7
+ public readonly type: string,
8
+ public readonly message: string | ((args: ValidationArguments) => string)) {
9
+
10
+ }
11
+
12
+ public getErrorMessage(): string {
13
+ if (this.message && typeof this.message === 'string') {
14
+ return this.message;
15
+ }
16
+ switch (this.type) {
17
+ case 'isNotEmpty':
18
+ return 'Value is mandatory';
19
+ case 'camelCase':
20
+ return 'Value should be camel case (ex: fooBar)';
21
+ case 'pascalCase':
22
+ return 'Value should be pascal case (ex: FooBar)';
23
+ default:
24
+ return this.type;
25
+ }
26
+ }
27
+ }
@@ -0,0 +1 @@
1
+ export * from './lodash';
@@ -0,0 +1,62 @@
1
+ /* eslint-disable @typescript-eslint/ban-types */
2
+ import {
3
+ cloneDeep,
4
+ deburr,
5
+ first,
6
+ flatten,
7
+ flattenDeep,
8
+ groupBy,
9
+ isEqual,
10
+ kebabCase,
11
+ last,
12
+ maxBy,
13
+ minBy,
14
+ shuffle,
15
+ sum,
16
+ sumBy,
17
+ trim,
18
+ trimEnd,
19
+ trimStart,
20
+ uniq,
21
+ words,
22
+ } from 'lodash';
23
+
24
+ // Define type (not exported)
25
+ type List<T> = ArrayLike<T>;
26
+ interface Dictionary<T> { [index: string]: T; }
27
+ type NotVoid = unknown;
28
+ type PropertyName = string | number | symbol;
29
+ type PartialShallow<T> = { [P in keyof T]?: T[P] extends object ? object : T[P] };
30
+ type IterateeShorthand<T> = PropertyName | [PropertyName, any] | PartialShallow<T>;
31
+ type Many<T> = T | ReadonlyArray<T>;
32
+ type ValueIteratee<T> = ((value: T) => NotVoid) | IterateeShorthand<T>;
33
+ type RecursiveArray<T> = Array<T | RecursiveArray<T>>;
34
+ type ListOfRecursiveArraysOrValues<T> = List<T | RecursiveArray<T>>;
35
+ type Flat<T> = T extends string ? T : (T extends List<any> ? never : T);
36
+
37
+ // Export functions with proper type
38
+ export const _uniq: <T>(array: List<T> | null | undefined) => T[] = uniq;
39
+ export const _flatten: <T>(array: List<Many<T>>) => T[] = flatten;
40
+ export const _flattenDeep: <T>(array: ListOfRecursiveArraysOrValues<T>) => Flat<T>[] = flattenDeep;
41
+ export const _sumBy: <T>(collection: List<T>, iteratee?: string | ((value: T) => number)) => number = sumBy;
42
+ export const _sum: (collection: List<any>) => number = sum;
43
+ export const _words: {
44
+ (string?: string, pattern?: string | RegExp): string[];
45
+ (string: string, index: string | number, guard: object): string[];
46
+ } = words;
47
+ export const _isEqual: (value: any, other: any) => boolean = isEqual;
48
+ export const _deburr: (string?: string) => string = deburr;
49
+ export const _kebabCase: (string?: string) => string = kebabCase;
50
+ export const _shuffle: {
51
+ <T>(collection: List<T>): T[];
52
+ <T extends object>(collection: T): T[keyof T][];
53
+ } = shuffle;
54
+ export const _groupBy: <T>(collection: List<T>, iteratee?: ValueIteratee<T>) => Dictionary<T[]> = groupBy;
55
+ export const _cloneDeep: <T>(value: T) => T = cloneDeep;
56
+ export const _maxBy: <T>(collection: List<T>, iteratee?: ValueIteratee<T>) => T = maxBy;
57
+ export const _minBy: <T>(collection: List<T>, iteratee?: ValueIteratee<T>) => T = minBy;
58
+ export const _first: <T>(array: List<T>) => T = first;
59
+ export const _last: <T>(array: List<T>) => T = last;
60
+ export const _trim: (string?: string, chars?: string) => string = trim;
61
+ export const _trimStart: (string?: string, chars?: string) => string = trimStart;
62
+ export const _trimEnd: (string?: string, chars?: string) => string = trimEnd;
package/tsconfig.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "compileOnSave": false,
3
+ "compilerOptions": {
4
+ "target": "es5",
5
+ "lib": [
6
+ "es2016",
7
+ "dom"
8
+ ],
9
+ "outDir": "./dist",
10
+ "baseUrl": "src",
11
+ "sourceMap": true,
12
+ "declaration": true,
13
+ "moduleResolution": "node",
14
+ "emitDecoratorMetadata": true,
15
+ "experimentalDecorators": true,
16
+ "typeRoots": [
17
+ "node_modules/@types"
18
+ ]
19
+ }
20
+ }
Binary file