@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
@@ -93,7 +93,8 @@ function recursiveGetErrors(validationErrors, errors = [], propertyName = '', pr
93
93
  return null;
94
94
  }
95
95
  if (validationError.constraints) {
96
- const containsNestedValidation = Object.keys(validationError.constraints).some(v => v === 'nestedValidation') && validationError.children.length > 0;
96
+ const containsNestedValidation = Object.keys(validationError.constraints).some(v => v === 'nestedValidation') &&
97
+ validationError.children.length > 0;
97
98
  const validations = Object.keys(validationError.constraints);
98
99
  const constraintName = validationPriorities.find(cm => validations.some(cs => cs.split('-')[0] === cm));
99
100
  let domainErrorCode;
@@ -102,18 +103,29 @@ function recursiveGetErrors(validationErrors, errors = [], propertyName = '', pr
102
103
  domainErrorCode = validations.find(vp => vp.split('-')[0] === validationPriorities[i]);
103
104
  i++;
104
105
  }
105
- if (validationError.contexts && validationError.contexts[domainErrorCode] && validationError.contexts[domainErrorCode].domainErrorCodes) {
106
+ if (validationError.contexts &&
107
+ validationError.contexts[domainErrorCode] &&
108
+ validationError.contexts[domainErrorCode].domainErrorCodes) {
106
109
  domainErrorCode = validationError.contexts[domainErrorCode].domainErrorCodes;
107
110
  }
108
- const domainErrorProperty = propertyName ? (containsNestedValidation ? propertyName : `${propertyName}.${validationError.property}`) : validationError.property;
111
+ const domainErrorProperty = propertyName
112
+ ? containsNestedValidation
113
+ ? propertyName
114
+ : `${propertyName}.${validationError.property}`
115
+ : validationError.property;
109
116
  errors.push(new validation_error_1.ValidationError(domainErrorProperty, validationError.value, constraintName, null));
110
117
  }
111
118
  if (validationError.children && validationError.children.length) {
112
119
  let childName = validationError.property;
113
120
  if (propertyName) {
114
- childName = previousValueWasArray ? `${propertyName}[${validationError.property}]` : `${propertyName}.${validationError.property}`;
121
+ childName = previousValueWasArray
122
+ ? `${propertyName}[${validationError.property}]`
123
+ : `${propertyName}.${validationError.property}`;
115
124
  }
116
- errors = recursiveGetErrors(validationError.children.filter(ve => ve.constraints ? !Object.keys(ve.constraints).includes('nestedValidation') || ve.children.length === 0 : true), errors, childName, Array.isArray(validationError.value));
125
+ errors = recursiveGetErrors(validationError.children.filter(ve => ve.constraints
126
+ ? !Object.keys(ve.constraints).includes('nestedValidation') ||
127
+ ve.children.length === 0
128
+ : true), errors, childName, Array.isArray(validationError.value));
117
129
  }
118
130
  }
119
131
  return errors;
@@ -1 +1 @@
1
- {"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/validators/validate.ts"],"names":[],"mappings":";;AAKA,4BAGC;AARD,qDAAiG;AAGjG,yDAAqD;AAErD,SAAgB,QAAQ,CAAC,IAAa;IAClC,MAAM,MAAM,GAAG,IAAA,8BAAY,EAAC,IAAI,EAAE,EAAE,mBAAmB,EAAE,KAAK,EAAE,CAAC,CAAC;IAClE,OAAO,kBAAkB,CAAC,MAAM,CAAC,CAAC;AACtC,CAAC;AAED,MAAM,oBAAoB,GAAG;IACzB,4BAA4B;IAC5B,WAAW;IACX,QAAQ;IACR,WAAW;IACX,SAAS;IACT,YAAY;IACZ,MAAM;IACN,SAAS;IACT,0BAA0B;IAC1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;gBACb,OAAO,oBAAoB,CAAC;YAChC,KAAK,WAAW;gBACZ,OAAO,yCAAyC,CAAC;YACrD,KAAK,YAAY;gBACb,OAAO,0CAA0C,CAAC;YACtD;gBACI,OAAO,IAAI,CAAC,IAAI,CAAC;QACzB,CAAC;IACL,CAAC;CACJ;AAxBD,0CAwBC"}
1
+ {"version":3,"file":"validation-error.js","sourceRoot":"","sources":["../../src/validators/validation-error.ts"],"names":[],"mappings":";;;AAEA,MAAa,eAAe;IACxB,YACoB,QAAgB,EAChB,KAAa,EACb,IAAY,EACZ,OAAyD;QAHzD,aAAQ,GAAR,QAAQ,CAAQ;QAChB,UAAK,GAAL,KAAK,CAAQ;QACb,SAAI,GAAJ,IAAI,CAAQ;QACZ,YAAO,GAAP,OAAO,CAAkD;IAC1E,CAAC;IAEG,eAAe;QAClB,IAAI,IAAI,CAAC,OAAO,IAAI,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;YACnD,OAAO,IAAI,CAAC,OAAO,CAAC;QACxB,CAAC;QACD,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;YAChB,KAAK,YAAY;gBACb,OAAO,oBAAoB,CAAC;YAChC,KAAK,WAAW;gBACZ,OAAO,yCAAyC,CAAC;YACrD,KAAK,YAAY;gBACb,OAAO,0CAA0C,CAAC;YACtD;gBACI,OAAO,IAAI,CAAC,IAAI,CAAC;QACzB,CAAC;IACL,CAAC;CACJ;AAvBD,0CAuBC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@my-devkit/core",
3
- "version": "1.0.121",
3
+ "version": "1.0.122",
4
4
  "description": "My Devkit: common tools",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -23,7 +23,7 @@
23
23
  "uuid": "13.0.0"
24
24
  },
25
25
  "devDependencies": {
26
- "@my-devkit/cli": "2.1.6",
26
+ "@my-devkit/cli": "2.1.7",
27
27
  "@types/lodash": "4.17.20",
28
28
  "@types/node": "22.18.6",
29
29
  "@typescript-eslint/eslint-plugin": "8.46.2",
@@ -2,9 +2,16 @@ import { _compact, _sumBy } from './vendors';
2
2
 
3
3
  export class DateHelper {
4
4
  public static getUTCTimestamp(): number {
5
- const now = new Date;
6
- return Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(),
7
- now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds(), now.getUTCMilliseconds());
5
+ const now = new Date();
6
+ return Date.UTC(
7
+ now.getUTCFullYear(),
8
+ now.getUTCMonth(),
9
+ now.getUTCDate(),
10
+ now.getUTCHours(),
11
+ now.getUTCMinutes(),
12
+ now.getUTCSeconds(),
13
+ now.getUTCMilliseconds()
14
+ );
8
15
  }
9
16
 
10
17
  public static getElapsedTime(startDate: Date, endDate = new Date()): number {
@@ -15,29 +22,37 @@ export class DateHelper {
15
22
  return this.getElapsedTime(startDate, endDate) / 1000 / 60 / 60 / 24;
16
23
  }
17
24
 
18
- public static getReadableElapsedTime(startDate: Date, endDate = new Date(), short = false): string {
25
+ public static getReadableElapsedTime(
26
+ startDate: Date,
27
+ endDate = new Date(),
28
+ short = false
29
+ ): string {
19
30
  const elapsedTime = this.getElapsedTime(startDate, endDate);
20
31
  return this.getReadableDuration(elapsedTime, short);
21
32
  }
22
33
 
23
34
  public static getReadableDuration(durationInMiliseconds: number, short = false): string {
24
35
  const days = Math.floor(durationInMiliseconds / (24 * 60 * 60 * 1000));
25
- durationInMiliseconds -= (24 * 60 * 60 * 1000) * days;
36
+ durationInMiliseconds -= 24 * 60 * 60 * 1000 * days;
26
37
  const hours = Math.floor(durationInMiliseconds / (60 * 60 * 1000));
27
- durationInMiliseconds -= (60 * 60 * 1000) * hours;
38
+ durationInMiliseconds -= 60 * 60 * 1000 * hours;
28
39
  const minutes = Math.floor(durationInMiliseconds / (60 * 1000));
29
- durationInMiliseconds -= (60 * 1000) * minutes;
40
+ durationInMiliseconds -= 60 * 1000 * minutes;
30
41
  const seconds = Math.floor(durationInMiliseconds / 1000);
31
42
  const miliseconds = durationInMiliseconds - 1000 * seconds;
32
43
 
33
44
  const daysUnit = days > 1 ? 'days' : 'day';
34
45
 
35
46
  if (days) {
36
- return short ? `${days} ${daysUnit}` : `${days} ${daysUnit} ${hours} h ${minutes} min ${seconds} sec ${miliseconds} ms`;
47
+ return short
48
+ ? `${days} ${daysUnit}`
49
+ : `${days} ${daysUnit} ${hours} h ${minutes} min ${seconds} sec ${miliseconds} ms`;
37
50
  }
38
51
 
39
52
  if (hours) {
40
- return short ? `${hours} h` : `${hours} h ${minutes} min ${seconds} sec ${miliseconds} ms`;
53
+ return short
54
+ ? `${hours} h`
55
+ : `${hours} h ${minutes} min ${seconds} sec ${miliseconds} ms`;
41
56
  }
42
57
 
43
58
  if (minutes) {
@@ -78,13 +93,12 @@ export class DateHelper {
78
93
  case /^\d{4}-(0[1-9]|1[0-2])$/.test(formatedDate):
79
94
  return 'month';
80
95
  default:
81
- null;
96
+ return null;
82
97
  }
83
98
  }
84
99
 
85
100
  public static getAverage(...dates: Date[]): Date {
86
- if (dates.length === 0)
87
- return null;
101
+ if (dates.length === 0) return null;
88
102
 
89
103
  const averageTime = _sumBy(dates, d => d.getTime()) / dates.length;
90
104
 
@@ -92,40 +106,45 @@ export class DateHelper {
92
106
  }
93
107
 
94
108
  public static addYears(startDate: Date, numberOfYears: number): Date {
95
- return new Date(Date.UTC(
96
- startDate.getUTCFullYear() + numberOfYears,
97
- startDate.getUTCMonth(),
98
- startDate.getUTCDate(),
99
- startDate.getUTCHours(),
100
- startDate.getUTCMinutes(),
101
- startDate.getUTCSeconds(),
102
- startDate.getUTCMilliseconds()
103
- ));
109
+ return new Date(
110
+ Date.UTC(
111
+ startDate.getUTCFullYear() + numberOfYears,
112
+ startDate.getUTCMonth(),
113
+ startDate.getUTCDate(),
114
+ startDate.getUTCHours(),
115
+ startDate.getUTCMinutes(),
116
+ startDate.getUTCSeconds(),
117
+ startDate.getUTCMilliseconds()
118
+ )
119
+ );
104
120
  }
105
121
 
106
-
107
122
  public static addMonths(startDate: Date, numberOfMonths: number): Date {
108
- return new Date(Date.UTC(
109
- startDate.getUTCFullYear(),
110
- startDate.getUTCMonth() + numberOfMonths,
111
- startDate.getUTCDate(),
112
- startDate.getUTCHours(),
113
- startDate.getUTCMinutes(),
114
- startDate.getUTCSeconds(),
115
- startDate.getUTCMilliseconds()
116
- ));
123
+ return new Date(
124
+ Date.UTC(
125
+ startDate.getUTCFullYear(),
126
+ startDate.getUTCMonth() + numberOfMonths,
127
+ startDate.getUTCDate(),
128
+ startDate.getUTCHours(),
129
+ startDate.getUTCMinutes(),
130
+ startDate.getUTCSeconds(),
131
+ startDate.getUTCMilliseconds()
132
+ )
133
+ );
117
134
  }
118
135
 
119
136
  public static addDays(startDate: Date, numberOfDays: number): Date {
120
- return new Date(Date.UTC(
121
- startDate.getUTCFullYear(),
122
- startDate.getUTCMonth(),
123
- startDate.getUTCDate() + numberOfDays,
124
- startDate.getUTCHours(),
125
- startDate.getUTCMinutes(),
126
- startDate.getUTCSeconds(),
127
- startDate.getUTCMilliseconds()
128
- ));
137
+ return new Date(
138
+ Date.UTC(
139
+ startDate.getUTCFullYear(),
140
+ startDate.getUTCMonth(),
141
+ startDate.getUTCDate() + numberOfDays,
142
+ startDate.getUTCHours(),
143
+ startDate.getUTCMinutes(),
144
+ startDate.getUTCSeconds(),
145
+ startDate.getUTCMilliseconds()
146
+ )
147
+ );
129
148
  }
130
149
 
131
150
  public static addHours(startDate: Date, numberOfHours: number): Date {
@@ -141,15 +160,17 @@ export class DateHelper {
141
160
  }
142
161
 
143
162
  public static addMiliseconds(startDate: Date, numberOfMiliseconds: number): Date {
144
- return new Date(Date.UTC(
145
- startDate.getUTCFullYear(),
146
- startDate.getUTCMonth(),
147
- startDate.getUTCDate(),
148
- startDate.getUTCHours(),
149
- startDate.getUTCMinutes(),
150
- startDate.getUTCSeconds(),
151
- startDate.getUTCMilliseconds() + numberOfMiliseconds
152
- ));
163
+ return new Date(
164
+ Date.UTC(
165
+ startDate.getUTCFullYear(),
166
+ startDate.getUTCMonth(),
167
+ startDate.getUTCDate(),
168
+ startDate.getUTCHours(),
169
+ startDate.getUTCMinutes(),
170
+ startDate.getUTCSeconds(),
171
+ startDate.getUTCMilliseconds() + numberOfMiliseconds
172
+ )
173
+ );
153
174
  }
154
175
 
155
176
  public static getDay(date: Date): string {
@@ -177,7 +198,9 @@ export class DateHelper {
177
198
  const oneHourMs = 60 * oneMinMs;
178
199
  const oneDayMs = 24 * oneHourMs;
179
200
 
180
- const diffDays = Math.floor((startOfDay(reference).getTime() - startOfDay(date).getTime()) / oneDayMs);
201
+ const diffDays = Math.floor(
202
+ (startOfDay(reference).getTime() - startOfDay(date).getTime()) / oneDayMs
203
+ );
181
204
 
182
205
  const diffMs = reference.getTime() - date.getTime();
183
206
 
@@ -190,24 +213,28 @@ export class DateHelper {
190
213
  const relativeTime = _compact([
191
214
  hours > 0 ? `${hours} hour${hours > 1 ? 's' : ''}` : null,
192
215
  minutes > 0 ? `${minutes} min${minutes > 1 ? 's' : ''}` : null,
193
- seconds > 0 && hours === 0 && minutes === 0 ? `${seconds} sec${seconds > 1 ? 's' : ''}` : null,
194
- ]).slice(0, 2).join(', ');
195
-
196
- const timeFormatter = new Intl.DateTimeFormat("en-GB", {
197
- hour: "numeric",
198
- minute: "2-digit",
199
- hour12: false,
216
+ seconds > 0 && hours === 0 && minutes === 0
217
+ ? `${seconds} sec${seconds > 1 ? 's' : ''}`
218
+ : null
219
+ ])
220
+ .slice(0, 2)
221
+ .join(', ');
222
+
223
+ const timeFormatter = new Intl.DateTimeFormat('en-GB', {
224
+ hour: 'numeric',
225
+ minute: '2-digit',
226
+ hour12: false
200
227
  });
201
228
 
202
- const fullDateFormatter = new Intl.DateTimeFormat("en-GB", {
203
- year: "numeric",
204
- month: "short",
205
- day: "numeric",
206
- hour: "numeric",
207
- minute: "2-digit",
229
+ const fullDateFormatter = new Intl.DateTimeFormat('en-GB', {
230
+ year: 'numeric',
231
+ month: 'short',
232
+ day: 'numeric',
233
+ hour: 'numeric',
234
+ minute: '2-digit',
208
235
  hour12: false
209
236
  });
210
- const weekday = new Intl.DateTimeFormat("en-GB", { weekday: "long" }).format(date);
237
+ const weekday = new Intl.DateTimeFormat('en-GB', { weekday: 'long' }).format(date);
211
238
 
212
239
  switch (true) {
213
240
  case absoluteDiffMs < oneSecMs:
@@ -11,7 +11,10 @@ export function Cacheable(): MethodDecorator {
11
11
  if (!Cacheable.hasCache(instance, propertyKey, args)) {
12
12
  Cacheable.setCache(instance, propertyKey, args, callback());
13
13
  } else {
14
- Logger.info(`Cacheable: ${target.constructor.name}.${propertyKey.toString()} result retrieved from cache`, ...args);
14
+ Logger.info(
15
+ `Cacheable: ${target.constructor.name}.${propertyKey.toString()} result retrieved from cache`,
16
+ ...args
17
+ );
15
18
  }
16
19
  return Cacheable.getCache(instance, propertyKey, args);
17
20
  },
@@ -19,9 +22,14 @@ export function Cacheable(): MethodDecorator {
19
22
  if (!Cacheable.hasCache(instance, propertyKey, args)) {
20
23
  Cacheable.setCache(instance, propertyKey, args, await callback());
21
24
  } else {
22
- Logger.info(`Cacheable: ${target.constructor.name}.${propertyKey.toString()} result retrieved from cache`, ...args);
25
+ Logger.info(
26
+ `Cacheable: ${target.constructor.name}.${propertyKey.toString()} result retrieved from cache`,
27
+ ...args
28
+ );
23
29
  }
24
- return PromiseHelper.fromFaster(Cacheable.getCache(instance, propertyKey, args));
30
+ return PromiseHelper.fromFaster(
31
+ Cacheable.getCache(instance, propertyKey, args)
32
+ );
25
33
  }
26
34
  };
27
35
  };
@@ -29,7 +37,9 @@ export function Cacheable(): MethodDecorator {
29
37
  if (typeof originalMethod === 'function') {
30
38
  if (originalMethod.constructor.name === 'AsyncFunction') {
31
39
  (descriptor as any).value = async function (...args) {
32
- return getCache(this, args).getAsync(async () => await originalMethod.apply(this, args));
40
+ return getCache(this, args).getAsync(
41
+ async () => await originalMethod.apply(this, args)
42
+ );
33
43
  };
34
44
  } else {
35
45
  (descriptor as any).value = function (...args) {
@@ -43,21 +53,27 @@ export function Cacheable(): MethodDecorator {
43
53
  }
44
54
 
45
55
  export namespace Cacheable {
46
-
47
56
  export function getMethodCacheKey<T>(instance: T, propertyKey: keyof T): string {
48
57
  return `__cache_${propertyKey.toString()}__`;
49
58
  }
50
59
 
51
60
  export function getArgsCacheKey(args: any[]): string {
52
- return JSON.stringify(Array.from(args).map(arg => {
53
- if (typeof arg === 'function') {
54
- return `function => class ${arg.name}`;
55
- }
56
- return arg;
57
- }));
61
+ return JSON.stringify(
62
+ Array.from(args).map(arg => {
63
+ if (typeof arg === 'function') {
64
+ return `function => class ${arg.name}`;
65
+ }
66
+ return arg;
67
+ })
68
+ );
58
69
  }
59
70
 
60
- export function setCache<T, R>(instance: T, propertyKey: keyof T, args: any[], result: R): void {
71
+ export function setCache<T, R>(
72
+ instance: T,
73
+ propertyKey: keyof T,
74
+ args: any[],
75
+ result: R
76
+ ): void {
61
77
  const cachePropertyName = getMethodCacheKey(instance, propertyKey);
62
78
  if (!instance.hasOwnProperty(cachePropertyName)) {
63
79
  instance[cachePropertyName] = new Map<string, any>();
@@ -80,7 +96,7 @@ export namespace Cacheable {
80
96
  export function getCache<T, R>(instance: T, propertyKey: keyof T, args: any[]): R {
81
97
  const cachePropertyName = getMethodCacheKey(instance, propertyKey);
82
98
  if (!hasCache(instance, propertyKey, args)) {
83
- throw new Error(`Cacheable: No cache found for ${propertyKey.toString()}`)
99
+ throw new Error(`Cacheable: No cache found for ${propertyKey.toString()}`);
84
100
  }
85
101
 
86
102
  const cacheKey = getArgsCacheKey(args);
@@ -1,6 +1,8 @@
1
1
  export class EnumHelper<T> {
2
- constructor(private _name: string, private _members: T[]) {
3
- }
2
+ constructor(
3
+ private _name: string,
4
+ private _members: T[]
5
+ ) {}
4
6
 
5
7
  public get name(): string {
6
8
  return this._name;
package/src/event.ts CHANGED
@@ -30,6 +30,7 @@ export abstract class Event implements Document {
30
30
 
31
31
  public set publishedAt(date: Date) {
32
32
  Event.counter++;
33
- this._publishedAt = date.toISOString().replace('Z', '.' + (('0'.repeat(9) + Event.counter).slice(-9))) + 'Z';
33
+ this._publishedAt =
34
+ date.toISOString().replace('Z', '.' + ('0'.repeat(9) + Event.counter).slice(-9)) + 'Z';
34
35
  }
35
36
  }
@@ -28,6 +28,8 @@ export class JsonHelper {
28
28
  }
29
29
 
30
30
  private static isISODateString(date: string): boolean {
31
- return /^(?:\d{4})-(?:\d{2})-(?:\d{2})T(?:\d{2}):(?:\d{2}):(?:\d{2}(?:\.\d*)?)(?:(?:-(?:\d{2}):(?:\d{2})|Z)?)$/.test(date);
31
+ return /^(?:\d{4})-(?:\d{2})-(?:\d{2})T(?:\d{2}):(?:\d{2}):(?:\d{2}(?:\.\d*)?)(?:(?:-(?:\d{2}):(?:\d{2})|Z)?)$/.test(
32
+ date
33
+ );
32
34
  }
33
35
  }
package/src/logger.ts CHANGED
@@ -19,10 +19,17 @@ export class Logger {
19
19
  }
20
20
  }
21
21
 
22
- public static infoWithElapesedTime(message: string, startDate: Date, meta?: Logger.LogMetaData): void {
22
+ public static infoWithElapesedTime(
23
+ message: string,
24
+ startDate: Date,
25
+ meta?: Logger.LogMetaData
26
+ ): void {
23
27
  this.info(message, {
24
28
  ...meta,
25
- elpasedTime: { ms: DateHelper.getElapsedTime(startDate), readable: DateHelper.getReadableElapsedTime(startDate) }
29
+ elpasedTime: {
30
+ ms: DateHelper.getElapsedTime(startDate),
31
+ readable: DateHelper.getReadableElapsedTime(startDate)
32
+ }
26
33
  });
27
34
  }
28
35
 
package/src/model.ts CHANGED
@@ -5,7 +5,10 @@ import { Document } from './document';
5
5
  export abstract class Model implements Document {
6
6
  @autoserializeAs(String) public _type?: string = null;
7
7
 
8
- constructor(modelType: string, private pathCallback: () => string) {
8
+ constructor(
9
+ modelType: string,
10
+ private pathCallback: () => string
11
+ ) {
9
12
  this._type = modelType;
10
13
  }
11
14
 
package/src/retry.ts CHANGED
@@ -7,7 +7,13 @@ import { sleep } from './sleep';
7
7
  * @param options
8
8
  */
9
9
  export async function retry<T>(operation: () => Promise<T>, options?: retry.Options): Promise<T> {
10
- options = { maxAttempts: 6, exponential: false, condition: () => true, continueWithoutError: false, ...options };
10
+ options = {
11
+ maxAttempts: 6,
12
+ exponential: false,
13
+ condition: () => true,
14
+ continueWithoutError: false,
15
+ ...options
16
+ };
11
17
 
12
18
  let continueTrying = true;
13
19
  let retryCount = 0;
@@ -29,7 +35,7 @@ export async function retry<T>(operation: () => Promise<T>, options?: retry.Opti
29
35
  retryCount++;
30
36
  Logger.info(`Retry: retrying... ${retryCount}/${options.maxAttempts}`);
31
37
  }
32
- } while (continueTrying)
38
+ } while (continueTrying);
33
39
  }
34
40
 
35
41
  export namespace retry {
@@ -2,7 +2,6 @@ import { Deserialize } from 'cerialize';
2
2
 
3
3
  import { serializable } from './serializable';
4
4
 
5
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
6
5
  export function deserialize<T>(object: any, type?: new () => T): T {
7
6
  if (type) {
8
7
  return Deserialize(object, type);
@@ -4,5 +4,10 @@ export * from './serialize';
4
4
  export * from './serialize-helper';
5
5
  export * from './type-helper';
6
6
 
7
- export { autoserialize, autoserializeAs, deserializeAs, inheritSerialization, serializeAs } from 'cerialize';
8
-
7
+ export {
8
+ autoserialize,
9
+ autoserializeAs,
10
+ deserializeAs,
11
+ inheritSerialization,
12
+ serializeAs
13
+ } from 'cerialize';
@@ -3,7 +3,6 @@ export function serializable<T>(type: new (...args: any[]) => T): void {
3
3
  }
4
4
 
5
5
  export namespace serializable {
6
-
7
6
  const types = new Map<string, new () => any>();
8
7
 
9
8
  export function register<T extends SerializableObject>(type: new (...args: any[]) => T): void {
@@ -15,7 +14,9 @@ export namespace serializable {
15
14
  return null;
16
15
  }
17
16
  if (!object._type) {
18
- throw new Error(`SerializeHelper: property _type is missing in ${JSON.stringify(object)}`);
17
+ throw new Error(
18
+ `SerializeHelper: property _type is missing in ${JSON.stringify(object)}`
19
+ );
19
20
  }
20
21
  const type = types.get(object._type);
21
22
  if (!type) {
@@ -1,24 +1,52 @@
1
1
  import { words as _words, compact, deburr, uniq } from 'lodash';
2
2
 
3
3
  export class SerializeHelper {
4
- public static getSearchKeyWords(criterias: (string | number)[], smartSearchCriterias: string[] = []): string[] {
4
+ public static getSearchKeyWords(
5
+ criterias: (string | number)[],
6
+ smartSearchCriterias: string[] = []
7
+ ): string[] {
5
8
  const smartSearchWords = this.getSmartSearchKeyWords(smartSearchCriterias);
6
9
  return compact(uniq(this.getWords([...criterias, ...smartSearchWords]))).sort();
7
10
  }
8
11
 
9
12
  private static getSmartSearchKeyWords(criterias: string[]): string[] {
10
- return this.getWords(criterias)
11
- .flatMap(word => {
12
- const result: string[] = [word];
13
- for (let length = 2; length < word.length; length++)
14
- result.push(word.substring(0, length));
15
-
16
- return result;
17
- });
13
+ return this.getWords(criterias).flatMap(word => {
14
+ const result: string[] = [word];
15
+ for (let length = 2; length < word.length; length++)
16
+ result.push(word.substring(0, length));
17
+
18
+ return result;
19
+ });
18
20
  }
19
21
 
20
22
  private static getWords(criterias: (string | number)[]): string[] {
21
- const excapedCharacters = ['(', ')', '[', ']', '{', '}', ',', '!', '?', ':', '...', '. ', '=', '+', '-', '*', '%', '\'', '"', '`', '\\', '/', '|', '_', '#'];
23
+ const excapedCharacters = [
24
+ '(',
25
+ ')',
26
+ '[',
27
+ ']',
28
+ '{',
29
+ '}',
30
+ ',',
31
+ '!',
32
+ '?',
33
+ ':',
34
+ '...',
35
+ '. ',
36
+ '=',
37
+ '+',
38
+ '-',
39
+ '*',
40
+ '%',
41
+ "'",
42
+ '"',
43
+ '`',
44
+ '\\',
45
+ '/',
46
+ '|',
47
+ '_',
48
+ '#'
49
+ ];
22
50
 
23
51
  let phrase = deburr(_words(criterias.join(' ')).join(' ')).toLowerCase();
24
52
  for (const excapedCharacter of excapedCharacters)
@@ -28,12 +56,10 @@ export class SerializeHelper {
28
56
  const result = [word];
29
57
 
30
58
  // Remove leading zeros 00012345 => 12345
31
- if (word.match(/^[0-9]{5,}$/g))
32
- result.push(word.replace(/^0+/, ''));
59
+ if (word.match(/^[0-9]{5,}$/g)) result.push(word.replace(/^0+/, ''));
33
60
 
34
61
  // Remove trailing s (to get singular word)
35
- if (word.match(/^.{3,}[^S]{1}[S]{1}$/g))
36
- result.push(word.replace(/[S]{1}$/, ''));
62
+ if (word.match(/^.{3,}[^S]{1}[S]{1}$/g)) result.push(word.replace(/[S]{1}$/, ''));
37
63
 
38
64
  return result;
39
65
  });