tshex-cli 1.0.13 → 1.0.14

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 (38) hide show
  1. package/LICENSE +21 -21
  2. package/build/main.js +21 -46
  3. package/package.json +50 -52
  4. package/readme.md +75 -75
  5. package/source/main.ts +84 -145
  6. package/templates/ctx/index.ts +9 -9
  7. package/templates/lib/index.d.ts +1 -1
  8. package/templates/lib/main.ts +5 -5
  9. package/templates/lib/shared/application/databases.ts +81 -0
  10. package/templates/lib/shared/application/events.ts +121 -0
  11. package/templates/lib/shared/application/{Response.ts → http.ts} +48 -52
  12. package/templates/{cls.example → lib/shared/application/loggers.ts} +50 -50
  13. package/templates/lib/shared/application/{Service.ts → services.ts} +43 -47
  14. package/templates/lib/shared/domain/{Aggregate.ts → aggregates.ts} +44 -48
  15. package/templates/lib/shared/domain/{Entity.ts → entities.ts} +46 -50
  16. package/templates/lib/shared/{application/DataTransferObject.ts → domain/errors.ts} +46 -46
  17. package/templates/lib/shared/domain/value-objects.ts +194 -0
  18. package/templates/ctx/ports/.gitkeep +0 -0
  19. package/templates/lib/shared/adapters/.gitkeep +0 -0
  20. package/templates/lib/shared/application/Logger.ts +0 -54
  21. package/templates/lib/shared/application/data/DataManager.ts +0 -50
  22. package/templates/lib/shared/application/data/Repository.ts +0 -55
  23. package/templates/lib/shared/application/errors/.gitkeep +0 -0
  24. package/templates/lib/shared/application/events/Event.ts +0 -56
  25. package/templates/lib/shared/application/events/EventDispatcher.ts +0 -55
  26. package/templates/lib/shared/application/events/EventHandler.ts +0 -50
  27. package/templates/lib/shared/constants/.gitkeep +0 -0
  28. package/templates/lib/shared/domain/errors/ValueError.ts +0 -69
  29. package/templates/lib/shared/domain/utils/.gitkeep +0 -0
  30. package/templates/lib/shared/domain/value-objects/BooleanValueObject.ts +0 -87
  31. package/templates/lib/shared/domain/value-objects/DateValueObject.ts +0 -100
  32. package/templates/lib/shared/domain/value-objects/EmailValueObject.ts +0 -89
  33. package/templates/lib/shared/domain/value-objects/NullableBooleanValueObject.ts +0 -87
  34. package/templates/lib/shared/domain/value-objects/NumericValueObject.ts +0 -136
  35. package/templates/lib/shared/domain/value-objects/StringValueObject.ts +0 -87
  36. package/templates/lib/shared/domain/value-objects/SymbolValueObject.ts +0 -82
  37. package/templates/lib/shared/domain/value-objects/ValueObject.ts +0 -57
  38. package/templates/rfc.example +0 -42
@@ -1,46 +1,46 @@
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 DataTransferObject
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
- // protected METHODS
37
-
38
- // private METHODS
39
-
40
- // public static METHODS
41
-
42
- // protected static METHODS
43
-
44
- // private static METHODS
45
-
46
- } //:: class
1
+ // Libraries
2
+
3
+ // Same Layer
4
+
5
+ // Lower Layers
6
+
7
+ // Types
8
+
9
+ // Constants
10
+
11
+ /**
12
+ * @description
13
+ */
14
+ export class ValueError extends Error {
15
+ [property: string]: unknown
16
+
17
+ // public ATTRIBUTES
18
+
19
+ // protected ATTRIBUTES
20
+
21
+ // private ATTRIBUTES
22
+
23
+ // public static ATTRIBUTES
24
+
25
+ // protected static ATTRIBUTES
26
+
27
+ // private static ATTRIBUTES
28
+
29
+ // Constructor, Getters, Setters
30
+
31
+ public constructor(received: string, expected: string) {
32
+ super(`Invalid value ${received} for ${expected}.`)
33
+ }
34
+
35
+ // public METHODS
36
+
37
+ // protected METHODS
38
+
39
+ // private METHODS
40
+
41
+ // public static METHODS
42
+
43
+ // protected static METHODS
44
+
45
+ // private static METHODS
46
+ } //:: class
@@ -0,0 +1,194 @@
1
+ // Libraries
2
+
3
+ // Same Layer
4
+
5
+ import { ValueError } from './errors.js'
6
+
7
+ // Lower Layers
8
+
9
+ // Types
10
+
11
+ // Constants
12
+
13
+ /**
14
+ * @see https://emailregex.com/
15
+ */
16
+ const VALID_EMAIL_REGEX =
17
+ /^(([^<>()\[\]\\.,;:\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,}))$/
18
+
19
+ /**
20
+ * @description
21
+ */
22
+ export abstract class ValueObject<T = unknown> {
23
+ [property: string]: unknown
24
+
25
+ // public ATTRIBUTES
26
+
27
+ public abstract readonly value: T
28
+
29
+ // protected ATTRIBUTES
30
+
31
+ // private ATTRIBUTES
32
+
33
+ // public static ATTRIBUTES
34
+
35
+ // protected static ATTRIBUTES
36
+
37
+ // private static ATTRIBUTES
38
+
39
+ // Constructor, Getters, Setters
40
+
41
+ // public METHODS
42
+
43
+ public toString(): string {
44
+ return String(this.value)
45
+ }
46
+
47
+ public abstract equals(other: ValueObject<T> | null | undefined): boolean
48
+
49
+ // protected METHODS
50
+
51
+ // private METHODS
52
+
53
+ // public static METHODS
54
+
55
+ public static isValid(value: unknown): boolean {
56
+ return (
57
+ value !== null &&
58
+ value !== undefined &&
59
+ Object.is(value, NaN) === false
60
+ )
61
+ }
62
+
63
+ // protected static METHODS
64
+
65
+ // private static METHODS
66
+ } //:: class
67
+
68
+ /**
69
+ * @description
70
+ */
71
+ export class NullableBoolean extends ValueObject<boolean | null> {
72
+ [property: string]: unknown
73
+
74
+ // public ATTRIBUTES
75
+
76
+ public override readonly value: boolean | null
77
+
78
+ // protected ATTRIBUTES
79
+
80
+ // private ATTRIBUTES
81
+
82
+ // public static ATTRIBUTES
83
+
84
+ // protected static ATTRIBUTES
85
+
86
+ // private static ATTRIBUTES
87
+
88
+ // Constructor, Getters, Setters
89
+
90
+ protected constructor(value: boolean | null) {
91
+ super()
92
+ this.value = value
93
+ }
94
+
95
+ // public METHODS
96
+
97
+ public override equals(other: NullableBoolean | null | undefined): boolean {
98
+ if (other === null || other === undefined) return false
99
+ return this.value === other.value
100
+ }
101
+
102
+ public isIndeterminate(): boolean {
103
+ return this.value === null
104
+ }
105
+
106
+ // protected METHODS
107
+
108
+ // private METHODS
109
+
110
+ // public static METHODS
111
+
112
+ public static from(value: boolean | null): NullableBoolean {
113
+ return new this(value)
114
+ }
115
+
116
+ // protected static METHODS
117
+
118
+ // private static METHODS
119
+ } //:: class
120
+
121
+ /**
122
+ * @description
123
+ */
124
+ export class Email extends ValueObject<string> {
125
+ [property: string]: unknown
126
+
127
+ // public ATTRIBUTES
128
+
129
+ public override readonly value: string
130
+
131
+ // protected ATTRIBUTES
132
+
133
+ // private ATTRIBUTES
134
+
135
+ // public static ATTRIBUTES
136
+
137
+ // protected static ATTRIBUTES
138
+
139
+ // private static ATTRIBUTES
140
+
141
+ // Constructor, Getters, Setters
142
+
143
+ protected constructor(value: string) {
144
+ super()
145
+ this.value = value
146
+ }
147
+
148
+ get username(): string | undefined {
149
+ return this.value.split('@').shift()
150
+ }
151
+
152
+ get domain(): string | undefined {
153
+ return this.value.split('@').pop()
154
+ }
155
+
156
+ get tld(): string | undefined {
157
+ return this.domain?.split('.').pop()
158
+ }
159
+
160
+ // public METHODS
161
+
162
+ public override equals(other: Email | null | undefined): boolean {
163
+ if (other === null || other === undefined) {
164
+ return false
165
+ }
166
+
167
+ return this.value === other.value
168
+ }
169
+
170
+ // protected METHODS
171
+
172
+ // private METHODS
173
+
174
+ // public static METHODS
175
+
176
+ public static override isValid(value: unknown): boolean {
177
+ if (super.isValid(value) === false) return false
178
+
179
+ return (
180
+ 'string' === typeof value && VALID_EMAIL_REGEX.test(value as string)
181
+ )
182
+ }
183
+
184
+ public static from(value: string): Email {
185
+ if (this.isValid(value) === false)
186
+ throw new ValueError(value, this.name)
187
+
188
+ return new this(value)
189
+ }
190
+
191
+ // protected static METHODS
192
+
193
+ // private static METHODS
194
+ } //:: class
File without changes
File without changes
@@ -1,54 +0,0 @@
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 Logger
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 debug(message: string): void;
37
-
38
- public abstract info(message: string): void;
39
-
40
- public abstract warning(message: string): void;
41
-
42
- public abstract error(message: string): void;
43
-
44
- // protected METHODS
45
-
46
- // private METHODS
47
-
48
- // public static METHODS
49
-
50
- // protected static METHODS
51
-
52
- // private static METHODS
53
-
54
- } //:: class
@@ -1,50 +0,0 @@
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 DataManager
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 connect(...args: unknown[]): Promise<unknown>;
37
-
38
- public abstract disconnect(): Promise<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
@@ -1,55 +0,0 @@
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
File without changes
@@ -1,56 +0,0 @@
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
@@ -1,55 +0,0 @@
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
@@ -1,50 +0,0 @@
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
@@ -1,69 +0,0 @@
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