@my-devkit/core 1.0.40 → 1.0.44
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/{dist/command.d.ts → command.d.ts} +0 -0
- package/{dist/command.js → command.js} +0 -0
- package/{dist/command.js.map → command.js.map} +0 -0
- package/{dist/date-helper.d.ts → date-helper.d.ts} +0 -0
- package/{dist/date-helper.js → date-helper.js} +0 -0
- package/{dist/date-helper.js.map → date-helper.js.map} +0 -0
- package/{dist/decorators → decorators}/cacheable.decorator.d.ts +0 -0
- package/{dist/decorators → decorators}/cacheable.decorator.js +0 -0
- package/{dist/decorators → decorators}/cacheable.decorator.js.map +0 -0
- package/{dist/decorators → decorators}/index.d.ts +0 -0
- package/{dist/decorators → decorators}/index.js +0 -0
- package/{dist/decorators → decorators}/index.js.map +0 -0
- package/{dist/decorators → decorators}/retryable.decorator.d.ts +0 -0
- package/{dist/decorators → decorators}/retryable.decorator.js +0 -0
- package/{dist/decorators → decorators}/retryable.decorator.js.map +0 -0
- package/{dist/document.d.ts → document.d.ts} +0 -0
- package/{dist/document.js → document.js} +0 -0
- package/{dist/document.js.map → document.js.map} +0 -0
- package/{dist/enum-helper.d.ts → enum-helper.d.ts} +0 -0
- package/{dist/enum-helper.js → enum-helper.js} +0 -0
- package/{dist/enum-helper.js.map → enum-helper.js.map} +0 -0
- package/{dist/errors → errors}/bad-request-error.d.ts +0 -0
- package/{dist/errors → errors}/bad-request-error.js +0 -0
- package/{dist/errors → errors}/bad-request-error.js.map +0 -0
- package/{dist/errors → errors}/domain-error.d.ts +0 -0
- package/{dist/errors → errors}/domain-error.js +0 -0
- package/{dist/errors → errors}/domain-error.js.map +0 -0
- package/{dist/errors → errors}/error-base.d.ts +0 -0
- package/{dist/errors → errors}/error-base.js +0 -0
- package/{dist/errors → errors}/error-base.js.map +0 -0
- package/{dist/errors → errors}/forbidden-error.d.ts +0 -0
- package/{dist/errors → errors}/forbidden-error.js +0 -0
- package/{dist/errors → errors}/forbidden-error.js.map +0 -0
- package/{dist/errors → errors}/index.d.ts +0 -0
- package/{dist/errors → errors}/index.js +0 -0
- package/{dist/errors → errors}/index.js.map +0 -0
- package/{dist/errors → errors}/not-found-error.d.ts +0 -0
- package/{dist/errors → errors}/not-found-error.js +0 -0
- package/{dist/errors → errors}/not-found-error.js.map +0 -0
- package/{dist/errors → errors}/not-implemented-error.d.ts +0 -0
- package/{dist/errors → errors}/not-implemented-error.js +0 -0
- package/{dist/errors → errors}/not-implemented-error.js.map +0 -0
- package/{dist/errors → errors}/unauthorized-error.d.ts +0 -0
- package/{dist/errors → errors}/unauthorized-error.js +0 -0
- package/{dist/errors → errors}/unauthorized-error.js.map +0 -0
- package/{dist/event.d.ts → event.d.ts} +0 -0
- package/{dist/event.js → event.js} +0 -0
- package/{dist/event.js.map → event.js.map} +0 -0
- package/{dist/guid → guid}/index.d.ts +0 -0
- package/{dist/guid → guid}/index.js +0 -0
- package/{dist/guid → guid}/index.js.map +0 -0
- package/{dist/index.d.ts → index.d.ts} +0 -0
- package/{dist/index.js → index.js} +0 -0
- package/{dist/index.js.map → index.js.map} +0 -0
- package/{dist/logger.d.ts → logger.d.ts} +0 -0
- package/{dist/logger.js → logger.js} +0 -0
- package/{dist/logger.js.map → logger.js.map} +0 -0
- package/{dist/maintenance-model.d.ts → maintenance-model.d.ts} +0 -0
- package/{dist/maintenance-model.js → maintenance-model.js} +0 -0
- package/{dist/maintenance-model.js.map → maintenance-model.js.map} +0 -0
- package/{dist/model.d.ts → model.d.ts} +0 -0
- package/{dist/model.js → model.js} +0 -0
- package/{dist/model.js.map → model.js.map} +0 -0
- package/my-devkit-core-1.0.44.tgz +0 -0
- package/package.json +7 -7
- package/{dist/release-model.d.ts → release-model.d.ts} +0 -0
- package/{dist/release-model.js → release-model.js} +0 -0
- package/{dist/release-model.js.map → release-model.js.map} +0 -0
- package/{dist/retry.d.ts → retry.d.ts} +0 -0
- package/{dist/retry.js → retry.js} +0 -0
- package/{dist/retry.js.map → retry.js.map} +0 -0
- package/{dist/serialize → serialize}/deserialize.d.ts +0 -0
- package/{dist/serialize → serialize}/deserialize.js +0 -0
- package/{dist/serialize → serialize}/deserialize.js.map +0 -0
- package/{dist/serialize → serialize}/index.d.ts +0 -0
- package/{dist/serialize → serialize}/index.js +0 -0
- package/{dist/serialize → serialize}/index.js.map +0 -0
- package/{dist/serialize → serialize}/serializable.d.ts +0 -0
- package/{dist/serialize → serialize}/serializable.js +0 -0
- package/{dist/serialize → serialize}/serializable.js.map +0 -0
- package/{dist/serialize → serialize}/serialize.d.ts +0 -0
- package/{dist/serialize → serialize}/serialize.js +0 -0
- package/{dist/serialize → serialize}/serialize.js.map +0 -0
- package/{dist/serialize → serialize}/type-helper.d.ts +0 -0
- package/{dist/serialize → serialize}/type-helper.js +0 -0
- package/{dist/serialize → serialize}/type-helper.js.map +0 -0
- package/{dist/sleep.d.ts → sleep.d.ts} +0 -0
- package/{dist/sleep.js → sleep.js} +0 -0
- package/{dist/sleep.js.map → sleep.js.map} +0 -0
- package/{dist/validators → validators}/custom-validators/camel-case.d.ts +0 -0
- package/{dist/validators → validators}/custom-validators/camel-case.js +0 -0
- package/{dist/validators → validators}/custom-validators/camel-case.js.map +0 -0
- package/{dist/validators → validators}/custom-validators/equals-to.d.ts +0 -0
- package/{dist/validators → validators}/custom-validators/equals-to.js +0 -0
- package/{dist/validators → validators}/custom-validators/equals-to.js.map +0 -0
- package/{dist/validators → validators}/custom-validators/greater-or-equal-than.d.ts +0 -0
- package/{dist/validators → validators}/custom-validators/greater-or-equal-than.js +0 -0
- package/{dist/validators → validators}/custom-validators/greater-or-equal-than.js.map +0 -0
- package/{dist/validators → validators}/custom-validators/greater-than-date.d.ts +0 -0
- package/{dist/validators → validators}/custom-validators/greater-than-date.js +0 -0
- package/{dist/validators → validators}/custom-validators/greater-than-date.js.map +0 -0
- package/{dist/validators → validators}/custom-validators/index.d.ts +0 -0
- package/{dist/validators → validators}/custom-validators/index.js +0 -0
- package/{dist/validators → validators}/custom-validators/index.js.map +0 -0
- package/{dist/validators → validators}/custom-validators/is-not-in-relative-to.d.ts +0 -0
- package/{dist/validators → validators}/custom-validators/is-not-in-relative-to.js +0 -0
- package/{dist/validators → validators}/custom-validators/is-not-in-relative-to.js.map +0 -0
- package/{dist/validators → validators}/custom-validators/is-optional-if.d.ts +0 -0
- package/{dist/validators → validators}/custom-validators/is-optional-if.js +0 -0
- package/{dist/validators → validators}/custom-validators/is-optional-if.js.map +0 -0
- package/{dist/validators → validators}/custom-validators/pascal-case.d.ts +0 -0
- package/{dist/validators → validators}/custom-validators/pascal-case.js +0 -0
- package/{dist/validators → validators}/custom-validators/pascal-case.js.map +0 -0
- package/{dist/validators → validators}/index.d.ts +0 -0
- package/{dist/validators → validators}/index.js +0 -0
- package/{dist/validators → validators}/index.js.map +0 -0
- package/{dist/validators → validators}/validate.d.ts +0 -0
- package/{dist/validators → validators}/validate.js +0 -0
- package/{dist/validators → validators}/validate.js.map +0 -0
- package/{dist/validators → validators}/validation-error.d.ts +0 -0
- package/{dist/validators → validators}/validation-error.js +0 -0
- package/{dist/validators → validators}/validation-error.js.map +0 -0
- package/{dist/vendors → vendors}/index.d.ts +0 -0
- package/{dist/vendors → vendors}/index.js +0 -0
- package/{dist/vendors → vendors}/index.js.map +0 -0
- package/{dist/vendors → vendors}/lodash.d.ts +0 -0
- package/{dist/vendors → vendors}/lodash.js +0 -0
- package/{dist/vendors → vendors}/lodash.js.map +0 -0
- package/.eslintrc.js +0 -15
- package/.vscode/settings.json +0 -7
- package/dist/package.json +0 -39
- package/my-devkit-core-1.0.40.tgz +0 -0
- package/src/command.ts +0 -9
- package/src/date-helper.ts +0 -26
- package/src/decorators/cacheable.decorator.ts +0 -20
- package/src/decorators/index.ts +0 -2
- package/src/decorators/retryable.decorator.ts +0 -11
- package/src/document.ts +0 -5
- package/src/enum-helper.ts +0 -17
- package/src/errors/bad-request-error.ts +0 -8
- package/src/errors/domain-error.ts +0 -8
- package/src/errors/error-base.ts +0 -3
- package/src/errors/forbidden-error.ts +0 -8
- package/src/errors/index.ts +0 -8
- package/src/errors/not-found-error.ts +0 -8
- package/src/errors/not-implemented-error.ts +0 -8
- package/src/errors/unauthorized-error.ts +0 -8
- package/src/event.ts +0 -32
- package/src/guid/index.ts +0 -3
- package/src/index.ts +0 -20
- package/src/logger.ts +0 -71
- package/src/maintenance-model.ts +0 -12
- package/src/model.ts +0 -15
- package/src/release-model.ts +0 -12
- package/src/retry.ts +0 -41
- package/src/serialize/deserialize.ts +0 -11
- package/src/serialize/index.ts +0 -6
- package/src/serialize/serializable.ts +0 -30
- package/src/serialize/serialize.ts +0 -7
- package/src/serialize/type-helper.ts +0 -167
- package/src/sleep.ts +0 -10
- package/src/validators/custom-validators/camel-case.ts +0 -18
- package/src/validators/custom-validators/equals-to.ts +0 -20
- package/src/validators/custom-validators/greater-or-equal-than.ts +0 -23
- package/src/validators/custom-validators/greater-than-date.ts +0 -28
- package/src/validators/custom-validators/index.ts +0 -7
- package/src/validators/custom-validators/is-not-in-relative-to.ts +0 -25
- package/src/validators/custom-validators/is-optional-if.ts +0 -21
- package/src/validators/custom-validators/pascal-case.ts +0 -18
- package/src/validators/index.ts +0 -24
- package/src/validators/validate.ts +0 -134
- package/src/validators/validation-error.ts +0 -27
- package/src/vendors/index.ts +0 -1
- package/src/vendors/lodash.ts +0 -62
- package/tsconfig.json +0 -20
package/src/event.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
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/guid/index.ts
DELETED
package/src/index.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
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';
|
package/src/logger.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { DateHelper } from './date-helper';
|
|
2
|
-
|
|
3
|
-
export class Logger {
|
|
4
|
-
private static implementations: Logger.Implementation[] = [];
|
|
5
|
-
|
|
6
|
-
public static registerLogger(logger: Logger.Implementation): void {
|
|
7
|
-
this.implementations.push(logger);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
public static debug(message: string, meta?: Logger.LogMetaData): void {
|
|
11
|
-
for (const implementation of this.implementations) {
|
|
12
|
-
implementation.debug(message, meta);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
public static info(message: string, meta?: Logger.LogMetaData): void {
|
|
17
|
-
for (const implementation of this.implementations) {
|
|
18
|
-
implementation.info(message, meta);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
public static infoWithElapesedTime(message: string, startDate: Date, meta?: Logger.LogMetaData): void {
|
|
23
|
-
this.info(message, {
|
|
24
|
-
...meta,
|
|
25
|
-
elpasedTime: { ms: DateHelper.getElapsedTime(startDate), readable: DateHelper.getReadableElapsedTime(startDate) }
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
public static warn(message: string, meta?: Logger.LogMetaData): void {
|
|
30
|
-
for (const implementation of this.implementations) {
|
|
31
|
-
implementation.warn(message, meta);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public static error(message: string, meta?: Logger.LogMetaData): void {
|
|
36
|
-
for (const implementation of this.implementations) {
|
|
37
|
-
implementation.error(message, meta);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export namespace Logger {
|
|
43
|
-
export interface LogMetaData {
|
|
44
|
-
[key: string]: any;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export interface Implementation {
|
|
48
|
-
debug(message: string, data: LogMetaData): void;
|
|
49
|
-
info(message: string, data: LogMetaData): void;
|
|
50
|
-
warn(message: string, data: LogMetaData): void;
|
|
51
|
-
error(message: string, data: LogMetaData): void;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export class ConsoleImplementation implements Implementation {
|
|
55
|
-
public debug(message: string): void {
|
|
56
|
-
console.debug(`debug: ${message}`);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
public info(message: string): void {
|
|
60
|
-
console.info(`info: ${message}`);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
public warn(message: string): void {
|
|
64
|
-
console.warn(`warn: ${message}`);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
public error(message: string): void {
|
|
68
|
-
console.error(`error: ${message}`);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
package/src/maintenance-model.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Model } from './model';
|
|
2
|
-
import { autoserializeAs, inheritSerialization, serializable } from './serialize';
|
|
3
|
-
|
|
4
|
-
@serializable
|
|
5
|
-
@inheritSerialization(Model)
|
|
6
|
-
export class MaintenanceModel extends Model {
|
|
7
|
-
@autoserializeAs(Boolean) public status: boolean = null;
|
|
8
|
-
|
|
9
|
-
constructor() {
|
|
10
|
-
super('MaintenanceModel', () => `/continuous-integration/maintenance`);
|
|
11
|
-
}
|
|
12
|
-
}
|
package/src/model.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { autoserializeAs } from 'cerialize';
|
|
2
|
-
|
|
3
|
-
import { Document } from './document';
|
|
4
|
-
|
|
5
|
-
export abstract class Model implements Document {
|
|
6
|
-
@autoserializeAs(String) public _type: string = null;
|
|
7
|
-
|
|
8
|
-
constructor(modelType: string, private pathCallback: () => string) {
|
|
9
|
-
this._type = modelType;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
public get _path(): string {
|
|
13
|
-
return this.pathCallback();
|
|
14
|
-
}
|
|
15
|
-
}
|
package/src/release-model.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Model } from './model';
|
|
2
|
-
import { autoserializeAs, inheritSerialization, serializable } from './serialize';
|
|
3
|
-
|
|
4
|
-
@serializable
|
|
5
|
-
@inheritSerialization(Model)
|
|
6
|
-
export class ReleaseModel extends Model {
|
|
7
|
-
@autoserializeAs(String) public version: string = null;
|
|
8
|
-
|
|
9
|
-
constructor() {
|
|
10
|
-
super('ReleaseModel', () => `/continuous-integration/release`);
|
|
11
|
-
}
|
|
12
|
-
}
|
package/src/retry.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { Logger } from './logger';
|
|
2
|
-
import { sleep } from './sleep';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Retry operation
|
|
6
|
-
* @param operation
|
|
7
|
-
* @param options
|
|
8
|
-
*/
|
|
9
|
-
export async function retry<T>(operation: () => Promise<T>, options?: retry.Options): Promise<T> {
|
|
10
|
-
options = { maxAttempts: 6, exponential: false, condition: () => true, ...options };
|
|
11
|
-
|
|
12
|
-
let continueTrying = true;
|
|
13
|
-
let retryCount = 0;
|
|
14
|
-
do {
|
|
15
|
-
try {
|
|
16
|
-
return await operation();
|
|
17
|
-
} catch (e) {
|
|
18
|
-
continueTrying = retryCount < options.maxAttempts && options.condition(e);
|
|
19
|
-
if (!continueTrying) {
|
|
20
|
-
throw e;
|
|
21
|
-
}
|
|
22
|
-
if (options.exponential) {
|
|
23
|
-
await sleep(Math.pow(2, retryCount) * 1000 + Math.round(Math.random() * 1000));
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
retryCount++;
|
|
27
|
-
Logger.info(`Retry: retrying... ${retryCount}/${options.maxAttempts}`);
|
|
28
|
-
}
|
|
29
|
-
} while (continueTrying)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export namespace retry {
|
|
33
|
-
export interface Options {
|
|
34
|
-
/**
|
|
35
|
-
* Condition callback
|
|
36
|
-
*/
|
|
37
|
-
condition?: (error: any) => boolean;
|
|
38
|
-
maxAttempts?: number;
|
|
39
|
-
exponential?: boolean;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Deserialize } from 'cerialize';
|
|
2
|
-
|
|
3
|
-
import { serializable } from './serializable';
|
|
4
|
-
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
6
|
-
export function deserialize<T>(object: any, type?: new () => T): T {
|
|
7
|
-
if (type) {
|
|
8
|
-
return Deserialize(object, type);
|
|
9
|
-
}
|
|
10
|
-
return Deserialize(object, serializable.getConstructor(object));
|
|
11
|
-
}
|
package/src/serialize/index.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export function serializable<T>(type: new (...args: any[]) => T): void {
|
|
2
|
-
serializable.register(type as any);
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export namespace serializable {
|
|
6
|
-
|
|
7
|
-
const types = new Map<string, new () => any>();
|
|
8
|
-
|
|
9
|
-
export function register<T extends SerializableObject>(type: new (...args: any[]) => T): void {
|
|
10
|
-
types.set(new type()._type, type);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function getConstructor<T extends SerializableObject>(object: T): new () => T {
|
|
14
|
-
if (!object) {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
if (!object._type) {
|
|
18
|
-
throw new Error(`SerializeHelper: property _type is missing in ${JSON.stringify(object)}`);
|
|
19
|
-
}
|
|
20
|
-
const type = types.get(object._type);
|
|
21
|
-
if (!type) {
|
|
22
|
-
throw new Error(`SerializeHelper: no type registered for ${object._type}`);
|
|
23
|
-
}
|
|
24
|
-
return type;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface SerializableObject {
|
|
28
|
-
_type: string;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import { __TypeMap, Deserialize } from 'cerialize';
|
|
2
|
-
|
|
3
|
-
import { _trimEnd } from '../vendors/lodash';
|
|
4
|
-
|
|
5
|
-
export class TypeHelper {
|
|
6
|
-
public static getProperties<T>(type: new () => T): TypeHelper.Property[] {
|
|
7
|
-
const metaData = this.getMetaData(type);
|
|
8
|
-
const result: TypeHelper.Property[] = [];
|
|
9
|
-
|
|
10
|
-
const remaining = metaData.map(m => ({ parent: null, m }));
|
|
11
|
-
while (remaining.length > 0) {
|
|
12
|
-
const property = remaining.shift();
|
|
13
|
-
const path = property.parent ? `${property.parent}.${property.m.name}` : property.m.name;
|
|
14
|
-
result.push({
|
|
15
|
-
parent: property.parent ? _trimEnd(property.parent, '[]') : null,
|
|
16
|
-
path,
|
|
17
|
-
name: property.m.name,
|
|
18
|
-
isArray: property.m.isArray,
|
|
19
|
-
type: property.m.type,
|
|
20
|
-
enumName: property.m.enumName
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
if (property.m.type === TypeHelper.Type.Object) {
|
|
24
|
-
const parent = property.m.isArray ? `${path}[]` : path;
|
|
25
|
-
remaining.push(...property.m.objectMetadata.map(m => ({ parent, m })))
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return result;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
public static getMetaData<T>(type: new () => T): TypeHelper.MetaData[] {
|
|
32
|
-
const metaDataList = __TypeMap.get(type);
|
|
33
|
-
if (!metaDataList) {
|
|
34
|
-
return [];
|
|
35
|
-
}
|
|
36
|
-
const instance = Deserialize({}, type);
|
|
37
|
-
return metaDataList.map(m => {
|
|
38
|
-
const metaDataType = TypeHelper.getMetaDataType(m.deserializedType);
|
|
39
|
-
const metadata: TypeHelper.MetaData = {
|
|
40
|
-
name: m.keyName,
|
|
41
|
-
serializedKey: (m.serializedKey ? m.serializedKey : m.keyName),
|
|
42
|
-
deserializedKey: (m.deserializedKey ? m.deserializedKey : m.keyName),
|
|
43
|
-
type: metaDataType,
|
|
44
|
-
enumName: metaDataType === TypeHelper.Type.Enum ? this.getEnumName(m.deserializedType) : null,
|
|
45
|
-
isArray: Array.isArray(instance[m.keyName]),
|
|
46
|
-
arrayLength: Array.isArray(instance[m.keyName]) ? instance[m.keyName].length : null,
|
|
47
|
-
objectName: metaDataType === TypeHelper.Type.Object ? m.deserializedType.name : [],
|
|
48
|
-
objectMetadata: metaDataType === TypeHelper.Type.Object ? this.getMetaData(m.deserializedType) : [],
|
|
49
|
-
enumValues: metaDataType === TypeHelper.Type.Enum ? this.getEnumValues(m.deserializedType) : []
|
|
50
|
-
};
|
|
51
|
-
return metadata;
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
private static getMetaDataType(propType: any): TypeHelper.Type {
|
|
56
|
-
if (this.isString(propType)) {
|
|
57
|
-
return TypeHelper.Type.String;
|
|
58
|
-
}
|
|
59
|
-
if (this.isNumber(propType)) {
|
|
60
|
-
return TypeHelper.Type.Number;
|
|
61
|
-
}
|
|
62
|
-
if (this.isBoolean(propType)) {
|
|
63
|
-
return TypeHelper.Type.Boolean;
|
|
64
|
-
}
|
|
65
|
-
if (this.isDate(propType)) {
|
|
66
|
-
return TypeHelper.Type.Date;
|
|
67
|
-
}
|
|
68
|
-
if (this.isEnum(propType)) {
|
|
69
|
-
return TypeHelper.Type.Enum;
|
|
70
|
-
}
|
|
71
|
-
if (this.isAny(propType)) {
|
|
72
|
-
return TypeHelper.Type.Any;
|
|
73
|
-
}
|
|
74
|
-
return TypeHelper.Type.Object;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
private static getEnumValues(type: any): any[] {
|
|
78
|
-
return type.helper ? type.helper.members : [];
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
private static getEnumName(type: any): string {
|
|
82
|
-
return type.helper ? type.helper.name : 'UnkownEnum';
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
private static isEnum(propType: any) {
|
|
86
|
-
if (!propType) {
|
|
87
|
-
return false;
|
|
88
|
-
} else if (propType.Deserialize) {
|
|
89
|
-
return false;
|
|
90
|
-
} else if (!propType.prototype) {
|
|
91
|
-
return true;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
private static isDate(propType: any): boolean {
|
|
96
|
-
if (propType === Date) {
|
|
97
|
-
return true;
|
|
98
|
-
} else if (propType === Date.prototype.constructor) {
|
|
99
|
-
return true;
|
|
100
|
-
} else if (propType && propType.Deserialize && propType.Deserialize.name === 'Date') {
|
|
101
|
-
return true;
|
|
102
|
-
}
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
private static isString(propType: any) {
|
|
107
|
-
if (propType && propType.Deserialize && propType.Deserialize.name.replace('deserialize', '') === 'String') {
|
|
108
|
-
return true;
|
|
109
|
-
}
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
private static isBoolean(propType: any) {
|
|
114
|
-
if (propType && propType.Deserialize && propType.Deserialize.name.replace('deserialize', '') === 'Boolean') {
|
|
115
|
-
return true;
|
|
116
|
-
}
|
|
117
|
-
return false;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
private static isNumber(propType: any) {
|
|
121
|
-
if (propType && propType.Deserialize && propType.Deserialize.name.replace('deserialize', '') === 'Number') {
|
|
122
|
-
return true;
|
|
123
|
-
}
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
private static isAny(propType: any) {
|
|
128
|
-
if (!propType) {
|
|
129
|
-
return true;
|
|
130
|
-
}
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export namespace TypeHelper {
|
|
136
|
-
export class Property {
|
|
137
|
-
public path: string;
|
|
138
|
-
public parent: string;
|
|
139
|
-
public name: string;
|
|
140
|
-
public type: Type;
|
|
141
|
-
public enumName: string = null;
|
|
142
|
-
public isArray: boolean = null;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export class MetaData {
|
|
146
|
-
public name: string = null;
|
|
147
|
-
public serializedKey: string = null;
|
|
148
|
-
public deserializedKey: string = null;
|
|
149
|
-
public type: Type = null;
|
|
150
|
-
public enumName: string = null;
|
|
151
|
-
public isArray: boolean = null;
|
|
152
|
-
public arrayLength: number = null;
|
|
153
|
-
public objectName: string = null;
|
|
154
|
-
public objectMetadata: MetaData[] = null;
|
|
155
|
-
public enumValues: string[] = null;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
export enum Type {
|
|
159
|
-
String = <any>'String',
|
|
160
|
-
Number = <any>'Number',
|
|
161
|
-
Date = <any>'Date',
|
|
162
|
-
Boolean = <any>'Boolean',
|
|
163
|
-
Enum = <any>'Enum',
|
|
164
|
-
Object = <any>'Object',
|
|
165
|
-
Any = <any>'Any'
|
|
166
|
-
}
|
|
167
|
-
}
|
package/src/sleep.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Logger } from './logger';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Wait specified miliseconds
|
|
5
|
-
* @param miliseconds
|
|
6
|
-
*/
|
|
7
|
-
export const sleep = async (miliseconds: number): Promise<void> => {
|
|
8
|
-
Logger.info(`Sleeping ${miliseconds} ms`);
|
|
9
|
-
return new Promise<void>(resolve => setTimeout(() => resolve(), miliseconds));
|
|
10
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { registerDecorator, ValidationOptions } from 'class-validator';
|
|
2
|
-
|
|
3
|
-
export function CamelCase(validationOptions?: ValidationOptions) {
|
|
4
|
-
return function (object: Record<string, any>, propertyName: string): void {
|
|
5
|
-
registerDecorator({
|
|
6
|
-
name: 'camelCase',
|
|
7
|
-
target: object.constructor,
|
|
8
|
-
propertyName: propertyName,
|
|
9
|
-
constraints: [{ name: 'camelCase' }],
|
|
10
|
-
options: validationOptions,
|
|
11
|
-
validator: {
|
|
12
|
-
validate(value: any) {
|
|
13
|
-
return /^[a-z]+((\d)|([A-Z0-9]{1,3}[a-z0-9]+))*([A-Z])?$/.test(value);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
};
|
|
18
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { registerDecorator, ValidationArguments, ValidationOptions } from 'class-validator';
|
|
2
|
-
|
|
3
|
-
export function EqualsTo(property: string, validationOptions?: ValidationOptions) {
|
|
4
|
-
return function (object: Record<string, any>, propertyName: string): void {
|
|
5
|
-
registerDecorator({
|
|
6
|
-
name: 'equalsTo',
|
|
7
|
-
target: object.constructor,
|
|
8
|
-
propertyName: propertyName,
|
|
9
|
-
constraints: [{ name: 'equalsTo', property }],
|
|
10
|
-
options: validationOptions,
|
|
11
|
-
validator: {
|
|
12
|
-
validate(value: any, args: ValidationArguments) {
|
|
13
|
-
const relatedPropertyName = args.constraints[0].property;
|
|
14
|
-
const relatedValue = (args.object as any)[relatedPropertyName];
|
|
15
|
-
return value === relatedValue;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { registerDecorator, ValidationArguments, ValidationOptions } from 'class-validator';
|
|
2
|
-
|
|
3
|
-
export function GreaterOrEqualThan(property: string, validationOptions?: ValidationOptions) {
|
|
4
|
-
return function (object: Record<string, any>, propertyName: string): void {
|
|
5
|
-
registerDecorator({
|
|
6
|
-
name: 'greaterOrEqualThan',
|
|
7
|
-
target: object.constructor,
|
|
8
|
-
propertyName: propertyName,
|
|
9
|
-
constraints: [{ name: 'greaterOrEqualThan', property }],
|
|
10
|
-
options: validationOptions,
|
|
11
|
-
validator: {
|
|
12
|
-
validate(value: any, args: ValidationArguments) {
|
|
13
|
-
const relatedPropertyName = args.constraints[0].property;
|
|
14
|
-
const relatedValue = (args.object as any)[relatedPropertyName];
|
|
15
|
-
if (typeof value === 'number' && typeof relatedValue === 'number') {
|
|
16
|
-
return value >= relatedValue;
|
|
17
|
-
}
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { registerDecorator, ValidationArguments, ValidationOptions } from 'class-validator';
|
|
2
|
-
|
|
3
|
-
export function GreaterThanDate(property: string, milliSecondsOffset?: number, validationOptions?: ValidationOptions) {
|
|
4
|
-
return function (object: Record<string, any>, propertyName: string): void {
|
|
5
|
-
registerDecorator({
|
|
6
|
-
name: 'greaterThanDate',
|
|
7
|
-
target: object.constructor,
|
|
8
|
-
propertyName: propertyName,
|
|
9
|
-
constraints: [{ name: 'greaterThanDate', property }],
|
|
10
|
-
options: validationOptions,
|
|
11
|
-
validator: {
|
|
12
|
-
validate(value: any, args: ValidationArguments) {
|
|
13
|
-
const relatedPropertyName = args.constraints[0].property;
|
|
14
|
-
let relatedValue = (args.object as any)[relatedPropertyName];
|
|
15
|
-
if (value instanceof Date && relatedValue instanceof Date) {
|
|
16
|
-
if (milliSecondsOffset) {
|
|
17
|
-
const date = new Date();
|
|
18
|
-
date.setTime(relatedValue.getTime() + milliSecondsOffset);
|
|
19
|
-
relatedValue = date;
|
|
20
|
-
}
|
|
21
|
-
return value > relatedValue;
|
|
22
|
-
}
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { registerDecorator, ValidationArguments, ValidationOptions, Validator } from 'class-validator';
|
|
2
|
-
|
|
3
|
-
const globalValidator = new Validator();
|
|
4
|
-
|
|
5
|
-
export function IsNotInRelativeTo<T, S>(excludedValuesCallback: (object: T) => S[], validationOptions?: ValidationOptions) {
|
|
6
|
-
return function (object: Record<string, any>, propertyName: string): void {
|
|
7
|
-
registerDecorator({
|
|
8
|
-
name: 'isNotInRelativeTo',
|
|
9
|
-
target: object.constructor,
|
|
10
|
-
propertyName: propertyName,
|
|
11
|
-
constraints: [{ name: 'isNotInRelativeTo', relativeValueCallback: excludedValuesCallback }],
|
|
12
|
-
options: validationOptions,
|
|
13
|
-
validator: {
|
|
14
|
-
validate(value: any, args: ValidationArguments) {
|
|
15
|
-
const excludedValues = args.constraints[0].relativeValueCallback(args.object);
|
|
16
|
-
if (Array.isArray(value) && validationOptions && validationOptions.each) {
|
|
17
|
-
return value.every(v => globalValidator.isNotIn(v, excludedValues));
|
|
18
|
-
} else {
|
|
19
|
-
return globalValidator.isNotIn(value, excludedValues);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { getFromContainer, MetadataStorage, ValidationOptions, ValidationTypes } from 'class-validator';
|
|
2
|
-
import { ValidationMetadata } from 'class-validator/metadata/ValidationMetadata';
|
|
3
|
-
import { ValidationMetadataArgs } from 'class-validator/metadata/ValidationMetadataArgs';
|
|
4
|
-
|
|
5
|
-
export function IsOptionalIf(condition: (object: any, value: any) => boolean, validationOptions?: ValidationOptions) {
|
|
6
|
-
return function (object: Record<string, any>, propertyName: string): void {
|
|
7
|
-
const args: ValidationMetadataArgs = {
|
|
8
|
-
type: ValidationTypes.CONDITIONAL_VALIDATION,
|
|
9
|
-
target: object.constructor,
|
|
10
|
-
propertyName: propertyName,
|
|
11
|
-
constraints: [(cobject: any, value: any) => {
|
|
12
|
-
if (condition(cobject, value)) {
|
|
13
|
-
return cobject[propertyName] !== '' && cobject[propertyName] !== null && cobject[propertyName] !== undefined;
|
|
14
|
-
}
|
|
15
|
-
return true;
|
|
16
|
-
}],
|
|
17
|
-
validationOptions: validationOptions
|
|
18
|
-
};
|
|
19
|
-
getFromContainer(MetadataStorage).addValidationMetadata(new ValidationMetadata(args));
|
|
20
|
-
};
|
|
21
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { registerDecorator, ValidationOptions } from 'class-validator';
|
|
2
|
-
|
|
3
|
-
export function PascalCase(validationOptions?: ValidationOptions) {
|
|
4
|
-
return function (object: Record<string, any>, propertyName: string): void {
|
|
5
|
-
registerDecorator({
|
|
6
|
-
name: 'pascalCase',
|
|
7
|
-
target: object.constructor,
|
|
8
|
-
propertyName: propertyName,
|
|
9
|
-
constraints: [{ name: 'pascalCase' }],
|
|
10
|
-
options: validationOptions,
|
|
11
|
-
validator: {
|
|
12
|
-
validate(value: any) {
|
|
13
|
-
return /^([A-Z]{1,3}[a-z0-9]*)+$/.test(value);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
};
|
|
18
|
-
}
|
package/src/validators/index.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export * from './custom-validators';
|
|
2
|
-
|
|
3
|
-
export {
|
|
4
|
-
IsOptional,
|
|
5
|
-
IsDefined, Equals, NotEquals, IsEmpty, IsNotEmpty, IsIn, IsNotIn,
|
|
6
|
-
// type validation methods
|
|
7
|
-
IsArray, IsBoolean, IsDate, IsString, IsNumber, IsInt, IsEnum,
|
|
8
|
-
// number validation methods
|
|
9
|
-
IsDivisibleBy, IsPositive, IsNegative, Max, Min,
|
|
10
|
-
// date validation methods
|
|
11
|
-
MinDate, MaxDate,
|
|
12
|
-
// string-type validation methods
|
|
13
|
-
IsBooleanString, IsNumberString,
|
|
14
|
-
// string validation methods
|
|
15
|
-
Contains, NotContains, IsAlpha, IsAlphanumeric, IsAscii, IsBase64, IsByteLength,
|
|
16
|
-
IsCreditCard, IsCurrency, IsEmail, IsFQDN, IsFullWidth, IsHalfWidth, IsVariableWidth,
|
|
17
|
-
IsHexColor, IsHexadecimal, IsIP, IsISBN, IsISIN, IsISO8601, IsJSON, IsLowercase, IsMobilePhone,
|
|
18
|
-
IsMongoId, IsMultibyte, IsSurrogatePair, IsUrl, IsUUID, IsUppercase, Length, MinLength,
|
|
19
|
-
MaxLength, Matches, IsMilitaryTime,
|
|
20
|
-
// array validation methods
|
|
21
|
-
ArrayContains, ArrayNotContains, ArrayNotEmpty, ArrayMinSize, ArrayMaxSize, ArrayUnique
|
|
22
|
-
} from 'class-validator';
|
|
23
|
-
|
|
24
|
-
export { validate } from './validate';
|