@my-devkit/core 1.0.57 → 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.
- package/.eslintrc.js +15 -0
- package/.vscode/settings.json +7 -0
- package/{command.d.ts → dist/command.d.ts} +0 -0
- package/{command.js → dist/command.js} +0 -0
- package/{command.js.map → dist/command.js.map} +0 -0
- package/{date-helper.d.ts → dist/date-helper.d.ts} +0 -0
- package/{date-helper.js → dist/date-helper.js} +0 -0
- package/{date-helper.js.map → dist/date-helper.js.map} +0 -0
- package/{decorators → dist/decorators}/cacheable.decorator.d.ts +0 -0
- package/{decorators → dist/decorators}/cacheable.decorator.js +0 -0
- package/{decorators → dist/decorators}/cacheable.decorator.js.map +0 -0
- package/{decorators → dist/decorators}/index.d.ts +0 -0
- package/{decorators → dist/decorators}/index.js +0 -0
- package/{decorators → dist/decorators}/index.js.map +0 -0
- package/{decorators → dist/decorators}/retryable.decorator.d.ts +0 -0
- package/{decorators → dist/decorators}/retryable.decorator.js +0 -0
- package/{decorators → dist/decorators}/retryable.decorator.js.map +0 -0
- package/{document.d.ts → dist/document.d.ts} +0 -0
- package/{document.js → dist/document.js} +0 -0
- package/{document.js.map → dist/document.js.map} +0 -0
- package/{enum-helper.d.ts → dist/enum-helper.d.ts} +0 -0
- package/{enum-helper.js → dist/enum-helper.js} +0 -0
- package/{enum-helper.js.map → dist/enum-helper.js.map} +0 -0
- package/{errors → dist/errors}/bad-request-error.d.ts +0 -0
- package/{errors → dist/errors}/bad-request-error.js +0 -0
- package/{errors → dist/errors}/bad-request-error.js.map +0 -0
- package/{errors → dist/errors}/domain-error.d.ts +0 -0
- package/{errors → dist/errors}/domain-error.js +0 -0
- package/{errors → dist/errors}/domain-error.js.map +0 -0
- package/{errors → dist/errors}/error-base.d.ts +0 -0
- package/{errors → dist/errors}/error-base.js +0 -0
- package/{errors → dist/errors}/error-base.js.map +0 -0
- package/{errors → dist/errors}/forbidden-error.d.ts +0 -0
- package/{errors → dist/errors}/forbidden-error.js +0 -0
- package/{errors → dist/errors}/forbidden-error.js.map +0 -0
- package/{errors → dist/errors}/index.d.ts +0 -0
- package/{errors → dist/errors}/index.js +0 -0
- package/{errors → dist/errors}/index.js.map +0 -0
- package/{errors → dist/errors}/not-found-error.d.ts +0 -0
- package/{errors → dist/errors}/not-found-error.js +0 -0
- package/{errors → dist/errors}/not-found-error.js.map +0 -0
- package/{errors → dist/errors}/not-implemented-error.d.ts +0 -0
- package/{errors → dist/errors}/not-implemented-error.js +0 -0
- package/{errors → dist/errors}/not-implemented-error.js.map +0 -0
- package/{errors → dist/errors}/unauthorized-error.d.ts +0 -0
- package/{errors → dist/errors}/unauthorized-error.js +0 -0
- package/{errors → dist/errors}/unauthorized-error.js.map +0 -0
- package/{event.d.ts → dist/event.d.ts} +0 -0
- package/{event.js → dist/event.js} +0 -0
- package/{event.js.map → dist/event.js.map} +0 -0
- package/{guid → dist/guid}/index.d.ts +0 -0
- package/{guid → dist/guid}/index.js +0 -0
- package/{guid → dist/guid}/index.js.map +0 -0
- package/{index.d.ts → dist/index.d.ts} +0 -0
- package/{index.js → dist/index.js} +0 -0
- package/{index.js.map → dist/index.js.map} +0 -0
- package/{logger.d.ts → dist/logger.d.ts} +0 -0
- package/{logger.js → dist/logger.js} +0 -0
- package/{logger.js.map → dist/logger.js.map} +0 -0
- package/{maintenance-model.d.ts → dist/maintenance-model.d.ts} +0 -0
- package/{maintenance-model.js → dist/maintenance-model.js} +0 -0
- package/{maintenance-model.js.map → dist/maintenance-model.js.map} +0 -0
- package/{model.d.ts → dist/model.d.ts} +0 -0
- package/{model.js → dist/model.js} +0 -0
- package/{model.js.map → dist/model.js.map} +0 -0
- package/{release-model.d.ts → dist/release-model.d.ts} +0 -0
- package/{release-model.js → dist/release-model.js} +0 -0
- package/{release-model.js.map → dist/release-model.js.map} +0 -0
- package/{retry.d.ts → dist/retry.d.ts} +0 -0
- package/{retry.js → dist/retry.js} +0 -0
- package/{retry.js.map → dist/retry.js.map} +0 -0
- package/{serialize → dist/serialize}/deserialize.d.ts +0 -0
- package/{serialize → dist/serialize}/deserialize.js +0 -0
- package/{serialize → dist/serialize}/deserialize.js.map +0 -0
- package/{serialize → dist/serialize}/index.d.ts +0 -0
- package/{serialize → dist/serialize}/index.js +0 -0
- package/{serialize → dist/serialize}/index.js.map +0 -0
- package/{serialize → dist/serialize}/serializable.d.ts +0 -0
- package/{serialize → dist/serialize}/serializable.js +0 -0
- package/{serialize → dist/serialize}/serializable.js.map +0 -0
- package/{serialize → dist/serialize}/serialize.d.ts +0 -0
- package/{serialize → dist/serialize}/serialize.js +0 -0
- package/{serialize → dist/serialize}/serialize.js.map +0 -0
- package/{serialize → dist/serialize}/type-helper.d.ts +0 -0
- package/{serialize → dist/serialize}/type-helper.js +0 -0
- package/{serialize → dist/serialize}/type-helper.js.map +0 -0
- package/{sleep.d.ts → dist/sleep.d.ts} +0 -0
- package/{sleep.js → dist/sleep.js} +0 -0
- package/{sleep.js.map → dist/sleep.js.map} +0 -0
- package/{validators → dist/validators}/custom-validators/camel-case.d.ts +0 -0
- package/{validators → dist/validators}/custom-validators/camel-case.js +0 -0
- package/{validators → dist/validators}/custom-validators/camel-case.js.map +0 -0
- package/{validators → dist/validators}/custom-validators/equals-to.d.ts +0 -0
- package/{validators → dist/validators}/custom-validators/equals-to.js +0 -0
- package/{validators → dist/validators}/custom-validators/equals-to.js.map +0 -0
- package/{validators → dist/validators}/custom-validators/greater-or-equal-than.d.ts +0 -0
- package/{validators → dist/validators}/custom-validators/greater-or-equal-than.js +0 -0
- package/{validators → dist/validators}/custom-validators/greater-or-equal-than.js.map +0 -0
- package/{validators → dist/validators}/custom-validators/greater-than-date.d.ts +0 -0
- package/{validators → dist/validators}/custom-validators/greater-than-date.js +0 -0
- package/{validators → dist/validators}/custom-validators/greater-than-date.js.map +0 -0
- package/{validators → dist/validators}/custom-validators/index.d.ts +0 -0
- package/{validators → dist/validators}/custom-validators/index.js +0 -0
- package/{validators → dist/validators}/custom-validators/index.js.map +0 -0
- package/{validators → dist/validators}/custom-validators/is-not-in-relative-to.d.ts +0 -0
- package/{validators → dist/validators}/custom-validators/is-not-in-relative-to.js +0 -0
- package/{validators → dist/validators}/custom-validators/is-not-in-relative-to.js.map +0 -0
- package/{validators → dist/validators}/custom-validators/is-optional-if.d.ts +0 -0
- package/{validators → dist/validators}/custom-validators/is-optional-if.js +0 -0
- package/{validators → dist/validators}/custom-validators/is-optional-if.js.map +0 -0
- package/{validators → dist/validators}/custom-validators/pascal-case.d.ts +0 -0
- package/{validators → dist/validators}/custom-validators/pascal-case.js +0 -0
- package/{validators → dist/validators}/custom-validators/pascal-case.js.map +0 -0
- package/{validators → dist/validators}/index.d.ts +0 -0
- package/{validators → dist/validators}/index.js +0 -0
- package/{validators → dist/validators}/index.js.map +0 -0
- package/{validators → dist/validators}/validate.d.ts +0 -0
- package/{validators → dist/validators}/validate.js +0 -0
- package/{validators → dist/validators}/validate.js.map +0 -0
- package/{validators → dist/validators}/validation-error.d.ts +0 -0
- package/{validators → dist/validators}/validation-error.js +0 -0
- package/{validators → dist/validators}/validation-error.js.map +0 -0
- package/{vendors → dist/vendors}/index.d.ts +0 -0
- package/{vendors → dist/vendors}/index.js +0 -0
- package/{vendors → dist/vendors}/index.js.map +0 -0
- package/{vendors → dist/vendors}/lodash.d.ts +0 -0
- package/{vendors → dist/vendors}/lodash.js +0 -0
- package/{vendors → dist/vendors}/lodash.js.map +0 -0
- package/package.json +3 -3
- package/src/command.ts +9 -0
- package/src/date-helper.ts +26 -0
- package/src/decorators/cacheable.decorator.ts +20 -0
- package/src/decorators/index.ts +2 -0
- package/src/decorators/retryable.decorator.ts +11 -0
- package/src/document.ts +5 -0
- package/src/enum-helper.ts +17 -0
- package/src/errors/bad-request-error.ts +8 -0
- package/src/errors/domain-error.ts +8 -0
- package/src/errors/error-base.ts +3 -0
- package/src/errors/forbidden-error.ts +8 -0
- package/src/errors/index.ts +8 -0
- package/src/errors/not-found-error.ts +8 -0
- package/src/errors/not-implemented-error.ts +8 -0
- package/src/errors/unauthorized-error.ts +8 -0
- package/src/event.ts +32 -0
- package/src/guid/index.ts +3 -0
- package/src/index.ts +20 -0
- package/src/logger.ts +71 -0
- package/src/maintenance-model.ts +12 -0
- package/src/model.ts +15 -0
- package/src/release-model.ts +12 -0
- package/src/retry.ts +41 -0
- package/src/serialize/deserialize.ts +11 -0
- package/src/serialize/index.ts +6 -0
- package/src/serialize/serializable.ts +30 -0
- package/src/serialize/serialize.ts +7 -0
- package/src/serialize/type-helper.ts +167 -0
- package/src/sleep.ts +10 -0
- package/src/validators/custom-validators/camel-case.ts +18 -0
- package/src/validators/custom-validators/equals-to.ts +20 -0
- package/src/validators/custom-validators/greater-or-equal-than.ts +23 -0
- package/src/validators/custom-validators/greater-than-date.ts +28 -0
- package/src/validators/custom-validators/index.ts +7 -0
- package/src/validators/custom-validators/is-not-in-relative-to.ts +25 -0
- package/src/validators/custom-validators/is-optional-if.ts +21 -0
- package/src/validators/custom-validators/pascal-case.ts +18 -0
- package/src/validators/index.ts +24 -0
- package/src/validators/validate.ts +134 -0
- package/src/validators/validation-error.ts +27 -0
- package/src/vendors/index.ts +1 -0
- package/src/vendors/lodash.ts +62 -0
- package/tsconfig.json +20 -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
|
+
}
|
|
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
|
|
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,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@my-devkit/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.58",
|
|
4
4
|
"description": "My Devkit: common tools",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"typings": "index.d.ts",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"typings": "dist/index.d.ts",
|
|
7
7
|
"keywords": [],
|
|
8
8
|
"author": "Jean-Guy BUON",
|
|
9
9
|
"license": "MIT",
|
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,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
|
+
}
|
package/src/document.ts
ADDED
|
@@ -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
|
+
}
|
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
|
+
}
|
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';
|