tshex-cli 1.0.2

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 (39) hide show
  1. package/LICENSE +21 -0
  2. package/build/main.js +84 -0
  3. package/package.json +30 -0
  4. package/readme.md +53 -0
  5. package/source/index.d.ts +0 -0
  6. package/source/main.ts +137 -0
  7. package/templates/cls.example +50 -0
  8. package/templates/ctx/adapters/.gitkeep +0 -0
  9. package/templates/ctx/application/.gitkeep +0 -0
  10. package/templates/ctx/domain/.gitkeep +0 -0
  11. package/templates/ctx/index.ts +9 -0
  12. package/templates/ctx/ports/.gitkeep +0 -0
  13. package/templates/lib/index.d.ts +1 -0
  14. package/templates/lib/main.ts +5 -0
  15. package/templates/lib/shared/adapters/.gitkeep +0 -0
  16. package/templates/lib/shared/application/DataTransferObject.ts +46 -0
  17. package/templates/lib/shared/application/Facade.ts +47 -0
  18. package/templates/lib/shared/application/Logger.ts +54 -0
  19. package/templates/lib/shared/application/Response.ts +52 -0
  20. package/templates/lib/shared/application/data/DataManager.ts +50 -0
  21. package/templates/lib/shared/application/data/Repository.ts +55 -0
  22. package/templates/lib/shared/application/errors/.gitkeep +0 -0
  23. package/templates/lib/shared/application/events/Event.ts +56 -0
  24. package/templates/lib/shared/application/events/EventDispatcher.ts +55 -0
  25. package/templates/lib/shared/application/events/EventHandler.ts +50 -0
  26. package/templates/lib/shared/constants/.gitkeep +0 -0
  27. package/templates/lib/shared/domain/Entity.ts +50 -0
  28. package/templates/lib/shared/domain/Service.ts +48 -0
  29. package/templates/lib/shared/domain/errors/ValueError.ts +69 -0
  30. package/templates/lib/shared/domain/utils/.gitkeep +0 -0
  31. package/templates/lib/shared/domain/value-objects/BooleanValueObject.ts +87 -0
  32. package/templates/lib/shared/domain/value-objects/DateValueObject.ts +100 -0
  33. package/templates/lib/shared/domain/value-objects/EmailValueObject.ts +89 -0
  34. package/templates/lib/shared/domain/value-objects/NullableBooleanValueObject.ts +87 -0
  35. package/templates/lib/shared/domain/value-objects/NumericValueObject.ts +136 -0
  36. package/templates/lib/shared/domain/value-objects/StringValueObject.ts +87 -0
  37. package/templates/lib/shared/domain/value-objects/SymbolValueObject.ts +82 -0
  38. package/templates/lib/shared/domain/value-objects/ValueObject.ts +57 -0
  39. package/templates/rfc.example +42 -0
@@ -0,0 +1,55 @@
1
+ // Libraries
2
+
3
+ // Same Layer
4
+
5
+ import type DataManager from './DataManager.js';
6
+
7
+ // Lower Layers
8
+
9
+ // Types
10
+
11
+ // Constants
12
+
13
+
14
+ /**
15
+ * @description Represents a data source.
16
+ */
17
+ export default abstract class Repository<M extends DataManager>
18
+ {
19
+
20
+ [property: string]: unknown;
21
+
22
+ // Public Attributes
23
+
24
+ public manager: M;
25
+
26
+ // Protected Attributes
27
+
28
+ // Private Attributes
29
+
30
+ // Public Static Attributes
31
+
32
+ // Protected Static Attributes
33
+
34
+ // Private Static Attributes
35
+
36
+ // Constructor, Getters, Setters
37
+
38
+ public constructor(manager: M)
39
+ {
40
+ this.manager = manager;
41
+ }
42
+
43
+ // Public Methods
44
+
45
+ // Protected Methods
46
+
47
+ // Private Methods
48
+
49
+ // Public Static Methods
50
+
51
+ // Protected Static Methods
52
+
53
+ // Private Static Methods
54
+
55
+ } //:: class
@@ -0,0 +1,56 @@
1
+ // Libraries
2
+
3
+ // Same Layer
4
+
5
+ // Lower Layers
6
+
7
+ // Types
8
+
9
+ // Constants
10
+
11
+
12
+ /**
13
+ * @description
14
+ */
15
+ export default abstract class Event
16
+ {
17
+
18
+ [property: string]: unknown;
19
+
20
+ // public ATTRIBUTES
21
+
22
+ public readonly timestamp: number;
23
+
24
+ public readonly details?: Record<string, unknown>;
25
+
26
+ // protected ATTRIBUTES
27
+
28
+ // private ATTRIBUTES
29
+
30
+ // public static ATTRIBUTES
31
+
32
+ // protected static ATTRIBUTES
33
+
34
+ // private static ATTRIBUTES
35
+
36
+ // Constructor, Getters, Setters
37
+
38
+ public constructor(timestamp: number, details?: Record<string, unknown>)
39
+ {
40
+ this.timestamp = timestamp;
41
+ this.details = details;
42
+ }
43
+
44
+ // public METHODS
45
+
46
+ // protected METHODS
47
+
48
+ // private METHODS
49
+
50
+ // public static METHODS
51
+
52
+ // protected static METHODS
53
+
54
+ // private static METHODS
55
+
56
+ } //:: class
@@ -0,0 +1,55 @@
1
+ // Libraries
2
+
3
+ // Same Layer
4
+
5
+ import type Event from './Event.js';
6
+ import type EventHandler from './EventHandler.js';
7
+
8
+ // Lower Layers
9
+
10
+ // Types
11
+
12
+ // Constants
13
+
14
+
15
+ /**
16
+ * @description
17
+ */
18
+ export default abstract class EventDispatcher
19
+ {
20
+
21
+ [property: string]: unknown;
22
+
23
+ // public ATTRIBUTES
24
+
25
+ // protected ATTRIBUTES
26
+
27
+ // private ATTRIBUTES
28
+
29
+ // public static ATTRIBUTES
30
+
31
+ // protected static ATTRIBUTES
32
+
33
+ // private static ATTRIBUTES
34
+
35
+ // Constructor, Getters, Setters
36
+
37
+ // public METHODS
38
+
39
+ public abstract subscribe(key: unknown, handler: EventHandler): void;
40
+
41
+ public abstract unsubscribe(key: unknown, handler: EventHandler): void;
42
+
43
+ public abstract dispatch(event: Event): void;
44
+
45
+ // protected METHODS
46
+
47
+ // private METHODS
48
+
49
+ // public static METHODS
50
+
51
+ // protected static METHODS
52
+
53
+ // private static METHODS
54
+
55
+ } //:: class
@@ -0,0 +1,50 @@
1
+ // Libraries
2
+
3
+ // Same Layer
4
+
5
+ import type Event from './Event.js';
6
+
7
+ // Lower Layers
8
+
9
+ // Types
10
+
11
+ // Constants
12
+
13
+
14
+ /**
15
+ * @description
16
+ */
17
+ export default abstract class EventHandler
18
+ {
19
+
20
+ [property: string]: unknown;
21
+
22
+ // public ATTRIBUTES
23
+
24
+ // protected ATTRIBUTES
25
+
26
+ // private ATTRIBUTES
27
+
28
+ // public static ATTRIBUTES
29
+
30
+ // protected static ATTRIBUTES
31
+
32
+ // private static ATTRIBUTES
33
+
34
+ // Constructor, Getters, Setters
35
+
36
+ // public METHODS
37
+
38
+ public abstract handle(event: Event): Promise<void>;
39
+
40
+ // protected METHODS
41
+
42
+ // private METHODS
43
+
44
+ // public static METHODS
45
+
46
+ // protected static METHODS
47
+
48
+ // private static METHODS
49
+
50
+ } //:: class
File without changes
@@ -0,0 +1,50 @@
1
+ // Libraries
2
+
3
+ // Same Layer
4
+
5
+ // Lower Layers
6
+
7
+ // Types
8
+
9
+ // Constants
10
+
11
+
12
+ /**
13
+ * @description An Entity is a class that represents a domain concept or element.
14
+ */
15
+ export default abstract class Entity
16
+ {
17
+
18
+ [property: string]: unknown;
19
+
20
+ // public ATTRIBUTES
21
+
22
+ // protected ATTRIBUTES
23
+
24
+ // private ATTRIBUTES
25
+
26
+ // public static ATTRIBUTES
27
+
28
+ // protected static ATTRIBUTES
29
+
30
+ // private static ATTRIBUTES
31
+
32
+ // Constructor, Getters, Setters
33
+
34
+ // public METHODS
35
+
36
+ public abstract equals(other: Entity): boolean;
37
+
38
+ public abstract flatten(): Record<string, unknown>;
39
+
40
+ // protected METHODS
41
+
42
+ // private METHODS
43
+
44
+ // public static METHODS
45
+
46
+ // protected static METHODS
47
+
48
+ // private static METHODS
49
+
50
+ } //:: class
@@ -0,0 +1,48 @@
1
+ // Libraries
2
+
3
+ // Same Layer
4
+
5
+ // Lower Layers
6
+
7
+ // Types
8
+
9
+ // Constants
10
+
11
+
12
+ /**
13
+ * @description A service is a class that contains business logic that doesn't belong to any entity.
14
+ * It is used to perform operations that don't fit into an entity or involve multiple entities.
15
+ * Normally, method arguments are entities.
16
+ */
17
+ export default abstract class Service
18
+ {
19
+
20
+ [property: string]: unknown;
21
+
22
+ // public ATTRIBUTES
23
+
24
+ // protected ATTRIBUTES
25
+
26
+ // private ATTRIBUTES
27
+
28
+ // public static ATTRIBUTES
29
+
30
+ // protected static ATTRIBUTES
31
+
32
+ // private static ATTRIBUTES
33
+
34
+ // Constructor, Getters, Setters
35
+
36
+ // public METHODS
37
+
38
+ // protected METHODS
39
+
40
+ // private METHODS
41
+
42
+ // public static METHODS
43
+
44
+ // protected static METHODS
45
+
46
+ // private static METHODS
47
+
48
+ } //:: class
@@ -0,0 +1,69 @@
1
+ // Libraries
2
+
3
+ // Same Layer
4
+
5
+ // Lower Layers
6
+
7
+ // Types
8
+
9
+ // Constants
10
+
11
+
12
+ /**
13
+ * @description
14
+ */
15
+ export default class ValueError extends Error
16
+ {
17
+
18
+ [property: string]: unknown;
19
+
20
+ // public ATTRIBUTES
21
+
22
+ // protected ATTRIBUTES
23
+
24
+ // private ATTRIBUTES
25
+
26
+ // public static ATTRIBUTES
27
+
28
+ // protected static ATTRIBUTES
29
+
30
+ // private static ATTRIBUTES
31
+
32
+ // Constructor, Getters, Setters
33
+
34
+ public constructor(value: unknown, expected: string)
35
+ {
36
+ let valueRepr: string;
37
+
38
+ if (value === undefined) {
39
+ valueRepr = 'undefined';
40
+ }
41
+
42
+ else if (value === null) {
43
+ valueRepr = 'null';
44
+ }
45
+
46
+ else if (Object.is(value, NaN)) {
47
+ valueRepr = 'NaN';
48
+ }
49
+
50
+ else {
51
+ valueRepr = `${value.constructor.name}(${value.toString()})`;
52
+ }
53
+
54
+ super(`Invalid value ${valueRepr} for ${expected}.`);
55
+ }
56
+
57
+ // public METHODS
58
+
59
+ // protected METHODS
60
+
61
+ // private METHODS
62
+
63
+ // public static METHODS
64
+
65
+ // protected static METHODS
66
+
67
+ // private static METHODS
68
+
69
+ } //:: class
File without changes
@@ -0,0 +1,87 @@
1
+ // Libraries
2
+
3
+ // Same Layer
4
+
5
+ import ValueObject from './ValueObject.js';
6
+
7
+ import ValueError from '../errors/ValueError.js';
8
+
9
+ // Lower Layers
10
+
11
+ // Types
12
+
13
+ type T = boolean;
14
+
15
+ // Constants
16
+
17
+
18
+ /**
19
+ * @description
20
+ */
21
+ export default class BooleanValueObject extends ValueObject
22
+ {
23
+
24
+ [property: string]: unknown;
25
+
26
+ // public ATTRIBUTES
27
+
28
+ public override readonly value: T;
29
+
30
+ // protected ATTRIBUTES
31
+
32
+ // private ATTRIBUTES
33
+
34
+ // public static ATTRIBUTES
35
+
36
+ // protected static ATTRIBUTES
37
+
38
+ // private static ATTRIBUTES
39
+
40
+ // Constructor, Getters, Setters
41
+
42
+ protected constructor(value: T)
43
+ {
44
+ super();
45
+ this.value = value;
46
+ }
47
+
48
+ // public METHODS
49
+
50
+ public override equals(other: BooleanValueObject | null | undefined): boolean
51
+ {
52
+ if (other === null || other === undefined) {
53
+ return false;
54
+ }
55
+
56
+ return this.value === other.value;
57
+ }
58
+
59
+ public toggle(): BooleanValueObject
60
+ {
61
+ return new BooleanValueObject(!this.value);
62
+ }
63
+
64
+ // protected METHODS
65
+
66
+ // private METHODS
67
+
68
+ // public static METHODS
69
+
70
+ public static override isValid(value: unknown): boolean
71
+ {
72
+ return ('boolean' === typeof value);
73
+ }
74
+
75
+ public static from(value: T): BooleanValueObject
76
+ {
77
+ if (!this.isValid(value)) {
78
+ throw new ValueError(value, this.name);
79
+ }
80
+ return new this(value);
81
+ }
82
+
83
+ // protected static METHODS
84
+
85
+ // private static METHODS
86
+
87
+ } //:: class
@@ -0,0 +1,100 @@
1
+ // Libraries
2
+
3
+ // Same Layer
4
+
5
+ import ValueObject from './ValueObject.js';
6
+
7
+ import ValueError from '../errors/ValueError.js';
8
+
9
+ // Lower Layers
10
+
11
+ // Types
12
+
13
+ type T = Date;
14
+
15
+ // Constants
16
+
17
+
18
+ /**
19
+ * @description
20
+ */
21
+ export default class DateValueObject extends ValueObject
22
+ {
23
+
24
+ [property: string]: unknown;
25
+
26
+ // public ATTRIBUTES
27
+
28
+ public override readonly value: T;
29
+
30
+ // protected ATTRIBUTES
31
+
32
+ // private ATTRIBUTES
33
+
34
+ // public static ATTRIBUTES
35
+
36
+ // protected static ATTRIBUTES
37
+
38
+ // private static ATTRIBUTES
39
+
40
+ // Constructor, Getters, Setters
41
+
42
+ protected constructor(value: T)
43
+ {
44
+ super();
45
+ this.value = value;
46
+ }
47
+
48
+ // public METHODS
49
+
50
+ public override equals(other: DateValueObject | null | undefined): boolean
51
+ {
52
+ if (other === null || other === undefined) {
53
+ return false;
54
+ }
55
+
56
+ return this.value.getTime() === other.value.getTime();
57
+ }
58
+
59
+ public isAfter(other: DateValueObject): boolean
60
+ {
61
+ return this.value > other.value;
62
+ }
63
+
64
+ public isBefore(other: DateValueObject): boolean
65
+ {
66
+ return this.value < other.value;
67
+ }
68
+
69
+ // protected METHODS
70
+
71
+ // private METHODS
72
+
73
+ // public static METHODS
74
+
75
+ public static override isValid(value: unknown): boolean
76
+ {
77
+ if (value === null || value === undefined) {
78
+ return false;
79
+ }
80
+
81
+ if (!(value instanceof Date)) {
82
+ return false;
83
+ }
84
+
85
+ return !isNaN(value.getTime());
86
+ }
87
+
88
+ public static from(value: T): DateValueObject
89
+ {
90
+ if (!this.isValid(value)) {
91
+ throw new ValueError(value, this.name);
92
+ }
93
+ return new this(value);
94
+ }
95
+
96
+ // protected static METHODS
97
+
98
+ // private static METHODS
99
+
100
+ } //:: class
@@ -0,0 +1,89 @@
1
+ // Libraries
2
+
3
+ // Same Layer
4
+
5
+ import StringValueObject from './StringValueObject.js';
6
+
7
+ import ValueError from '../errors/ValueError.js';
8
+
9
+ // Lower Layers
10
+
11
+ // Types
12
+
13
+ type T = string;
14
+
15
+ // Constants
16
+
17
+
18
+ /**
19
+ * @description
20
+ */
21
+ export default class EmailValueObject extends StringValueObject
22
+ {
23
+
24
+ [property: string]: unknown;
25
+
26
+ // public ATTRIBUTES
27
+
28
+ // protected ATTRIBUTES
29
+
30
+ // private ATTRIBUTES
31
+
32
+ // public static ATTRIBUTES
33
+
34
+ // protected static ATTRIBUTES
35
+
36
+ // private static ATTRIBUTES
37
+
38
+ // Constructor, Getters, Setters
39
+
40
+ get username(): string | undefined
41
+ {
42
+ return this.value.split('@').shift();
43
+ }
44
+
45
+ get domain(): string | undefined
46
+ {
47
+ return this.value.split('@').pop();
48
+ }
49
+
50
+ get tld(): string | undefined
51
+ {
52
+ return this.domain?.split('.').pop();
53
+ }
54
+
55
+ // public METHODS
56
+
57
+ // protected METHODS
58
+
59
+ // private METHODS
60
+
61
+ // public static METHODS
62
+
63
+ /**
64
+ * @see https://emailregex.com/
65
+ */
66
+ public static override isValid(value: unknown): boolean
67
+ {
68
+ const regex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
69
+
70
+ if (!super.isValid(value)) {
71
+ return false;
72
+ }
73
+
74
+ return regex.test(value as string);
75
+ }
76
+
77
+ public static override from(value: T): EmailValueObject
78
+ {
79
+ if (!this.isValid(value)) {
80
+ throw new ValueError(value, this.name);
81
+ }
82
+ return new this(value);
83
+ }
84
+
85
+ // protected static METHODS
86
+
87
+ // private static METHODS
88
+
89
+ } //:: class