@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
package/.eslintrc.js ADDED
@@ -0,0 +1,15 @@
1
+ module.exports = {
2
+ parser: '@typescript-eslint/parser',
3
+ extends: [
4
+ 'plugin:@typescript-eslint/recommended'
5
+ ],
6
+ parserOptions: {
7
+ ecmaVersion: 2018,
8
+ sourceType: 'module'
9
+ },
10
+ rules: {
11
+ '@typescript-eslint/no-namespace': 'off',
12
+ '@typescript-eslint/no-explicit-any': 'off',
13
+ quotes: ['error', 'single', { avoidEscape: true, allowTemplateLiterals: true }]
14
+ }
15
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "typescript.tsdk": "./node_modules/typescript/lib",
3
+ "editor.tabSize": 4,
4
+ "files.exclude": {
5
+ "**/.vscode": true
6
+ }
7
+ }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@my-devkit/core",
3
- "version": "1.0.54",
3
+ "version": "1.0.58",
4
4
  "description": "My Devkit: common tools",
5
- "typings": "index.d.ts",
5
+ "main": "dist/index.js",
6
+ "typings": "dist/index.d.ts",
6
7
  "keywords": [],
7
8
  "author": "Jean-Guy BUON",
8
9
  "license": "MIT",
@@ -33,6 +34,5 @@
33
34
  "ts-cleaner": "1.0.5",
34
35
  "typescript": "^4.5.2",
35
36
  "rimraf": "3.0.2"
36
- },
37
- "module": "index.js"
37
+ }
38
38
  }
package/src/command.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { autoserializeAs, serializable } from './serialize';
2
+
3
+ export abstract class Command implements serializable.SerializableObject {
4
+ @autoserializeAs(String) public _type: string = null;
5
+
6
+ constructor(commandType: string) {
7
+ this._type = commandType;
8
+ }
9
+ }
@@ -0,0 +1,26 @@
1
+ export class DateHelper {
2
+ public static getUTCTimestamp(): number {
3
+ const now = new Date;
4
+ return Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(),
5
+ now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds(), now.getUTCMilliseconds());
6
+ }
7
+
8
+ public static getElapsedTime(startDate: Date): number {
9
+ return (new Date()).getTime() - startDate.getTime();
10
+ }
11
+
12
+ public static getReadableElapsedTime(startDate: Date): string {
13
+ const elapsedTime = this.getElapsedTime(startDate);
14
+
15
+ const minutes = Math.floor(elapsedTime / 60000);
16
+ const seconds = Math.floor(elapsedTime / 1000) - 60000 * minutes;
17
+ const miliseconds = elapsedTime - 60000 * minutes - 1000 * seconds;
18
+
19
+ if (minutes) {
20
+ return `${minutes} min ${seconds} sec ${miliseconds} ms`;
21
+ } else if (seconds) {
22
+ return `${seconds} sec ${miliseconds} ms`;
23
+ }
24
+ return `${miliseconds} ms`;
25
+ }
26
+ }
@@ -0,0 +1,20 @@
1
+ import { guid } from '../guid';
2
+ import { Logger } from '../logger';
3
+
4
+ export function Cacheable(): MethodDecorator {
5
+ return (target, propertyKey, descriptor) => {
6
+ const originalMethod: any = descriptor.value;
7
+ const cachePropertyName = `__cache_${propertyKey.toString()}_${guid()}__`;
8
+ target[cachePropertyName] = new Map<string, any>();
9
+
10
+ (descriptor as any).value = (...args) => {
11
+ const cacheKey = JSON.stringify(args);
12
+ if (!target[cachePropertyName].has(cacheKey)) {
13
+ target[cachePropertyName].set(cacheKey, originalMethod.apply(this, args));
14
+ } else {
15
+ Logger.info(`Cacheable: ${target.constructor.name}.${propertyKey.toString()} result retrieved from cache`, { args });
16
+ }
17
+ return target[cachePropertyName].get(cacheKey);
18
+ };
19
+ };
20
+ }
@@ -0,0 +1,2 @@
1
+ export * from './cacheable.decorator';
2
+ export * from './retryable.decorator';
@@ -0,0 +1,11 @@
1
+ import { retry } from '../retry';
2
+
3
+ export function Retryable(options?: retry.Options): MethodDecorator {
4
+ return (_target, _propertyKey, descriptor) => {
5
+ const originalMethod: any = descriptor.value;
6
+
7
+ (descriptor as any).value = async function (...args) {
8
+ return retry(async () => await originalMethod.apply(this, args), options);
9
+ };
10
+ };
11
+ }
@@ -0,0 +1,5 @@
1
+ import { serializable } from './serialize';
2
+
3
+ export interface Document extends serializable.SerializableObject {
4
+ _path: string;
5
+ }
@@ -0,0 +1,17 @@
1
+ export class EnumHelper<T> {
2
+ constructor(private _name: string, private _members: T[]) {
3
+ }
4
+
5
+ public get name(): string {
6
+ return this._name;
7
+ }
8
+
9
+ public get members(): T[] {
10
+ return [...this._members];
11
+ }
12
+
13
+ public membersNotIn(excludedMembers: T[]): T[] {
14
+ const notExcludedMembers = this._members.filter(m => !excludedMembers.includes(m));
15
+ return [...notExcludedMembers];
16
+ }
17
+ }
@@ -0,0 +1,8 @@
1
+ import { ErrorBase } from './error-base';
2
+
3
+ export class BadRequestError extends Error implements ErrorBase {
4
+ constructor(public message: string) {
5
+ super(message);
6
+ this.name = 'BadRequestError';
7
+ }
8
+ }
@@ -0,0 +1,8 @@
1
+ import { ErrorBase } from './error-base';
2
+
3
+ export class DomainError extends Error implements ErrorBase {
4
+ constructor(public message: string) {
5
+ super(message);
6
+ this.name = 'DomainError';
7
+ }
8
+ }
@@ -0,0 +1,3 @@
1
+ export interface ErrorBase extends Error {
2
+ message: string;
3
+ }
@@ -0,0 +1,8 @@
1
+ import { ErrorBase } from './error-base';
2
+
3
+ export class ForbiddenError extends Error implements ErrorBase {
4
+ constructor(public message: string) {
5
+ super(message);
6
+ this.name = 'ForbiddenError';
7
+ }
8
+ }
@@ -0,0 +1,8 @@
1
+ export * from './error-base';
2
+
3
+ export * from './bad-request-error';
4
+ export * from './forbidden-error';
5
+ export * from './not-found-error';
6
+ export * from './not-implemented-error';
7
+ export * from './unauthorized-error';
8
+ export * from './domain-error';
@@ -0,0 +1,8 @@
1
+ import { ErrorBase } from './error-base';
2
+
3
+ export class NotFoundError extends Error implements ErrorBase {
4
+ constructor(public message: string) {
5
+ super(message);
6
+ this.name = 'NotFoundError';
7
+ }
8
+ }
@@ -0,0 +1,8 @@
1
+ import { ErrorBase } from './error-base';
2
+
3
+ export class NotImplementedError extends Error implements ErrorBase {
4
+ constructor(public message: string) {
5
+ super(message);
6
+ this.name = 'NotImplementedError';
7
+ }
8
+ }
@@ -0,0 +1,8 @@
1
+ import { ErrorBase } from './error-base';
2
+
3
+ export class UnauthorizedError extends Error implements ErrorBase {
4
+ constructor(public message: string) {
5
+ super(message);
6
+ this.name = 'UnauthorizedError';
7
+ }
8
+ }
package/src/event.ts ADDED
@@ -0,0 +1,32 @@
1
+ import { Document } from './document';
2
+ import { guid } from './guid';
3
+ import { autoserializeAs } from './serialize';
4
+
5
+ export abstract class Event implements Document {
6
+ public static counter = 0;
7
+ @autoserializeAs(String) public id: string = null;
8
+ @autoserializeAs(String) public _type: string = null;
9
+ @autoserializeAs(String) public _correlationId: string = null;
10
+ @autoserializeAs(String) public _aggregateType: string = null;
11
+ @autoserializeAs(String) public _aggregateId: string = null;
12
+ @autoserializeAs(String) public _publishedBy: string = null;
13
+ @autoserializeAs(String) private _publishedAt: string = null;
14
+
15
+ constructor() {
16
+ this.id = guid();
17
+ this._type = this.constructor.name;
18
+ }
19
+
20
+ public get _path(): string {
21
+ return `/events/${this.id}`;
22
+ }
23
+
24
+ public get publishedAt(): Date {
25
+ return new Date(this._publishedAt.substr(0, 23) + 'Z');
26
+ }
27
+
28
+ public set publishedAt(date: Date) {
29
+ Event.counter++;
30
+ this._publishedAt = date.toISOString().replace('Z', '.' + (('0'.repeat(9) + Event.counter).slice(-9))) + 'Z';
31
+ }
32
+ }
@@ -0,0 +1,3 @@
1
+ import { v4 } from 'uuid';
2
+
3
+ export const guid = v4;
package/src/index.ts ADDED
@@ -0,0 +1,20 @@
1
+ import * as validators from './validators';
2
+
3
+ export * from './decorators';
4
+ export * from './document';
5
+ export * from './command';
6
+ export * from './event';
7
+ export * from './date-helper';
8
+ export * from './enum-helper';
9
+ export * from './errors';
10
+ export * from './guid';
11
+ export * from './logger';
12
+ export * from './model';
13
+ export * from './maintenance-model';
14
+ export * from './release-model';
15
+ export * from './serialize';
16
+ export * from './retry';
17
+ export * from './sleep';
18
+ export * from './vendors';
19
+ export const Validators = validators;
20
+ export { ValidationError } from './validators/validation-error';