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,87 +0,0 @@
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
@@ -1,100 +0,0 @@
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
@@ -1,89 +0,0 @@
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
@@ -1,87 +0,0 @@
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 | null;
14
-
15
- // Constants
16
-
17
-
18
- /**
19
- * @description
20
- */
21
- export default class NullableBooleanValueObject 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: NullableBooleanValueObject | 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 isIndeterminate(): boolean
60
- {
61
- return this.value === null;
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 (value === null) || (value === true) || (value === false);
73
- }
74
-
75
- public static from(value: T): NullableBooleanValueObject
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
@@ -1,136 +0,0 @@
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 = number;
14
-
15
- // Constants
16
-
17
-
18
- /**
19
- * @description
20
- */
21
- export default class NumericValueObject 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: NumericValueObject | 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 isInteger(): boolean
60
- {
61
- return Number.isInteger(this.value);
62
- }
63
-
64
- public isZero(): boolean
65
- {
66
- return this.value === 0;
67
- }
68
-
69
- public isPositive(): boolean
70
- {
71
- return this.value > 0;
72
- }
73
-
74
- public isNegative(): boolean
75
- {
76
- return this.value < 0;
77
- }
78
-
79
- public isOdd(): boolean
80
- {
81
- return (this.value & 1) === 1;
82
- }
83
-
84
- public isEven(): boolean
85
- {
86
- return (this.value & 1) === 0;
87
- }
88
-
89
- public isBetween(min: T, max: T, inclusiveMin = true, inclusiveMax = true): boolean
90
- {
91
-
92
- if (inclusiveMin && inclusiveMax) {
93
- return this.value >= min && this.value <= max;
94
- }
95
-
96
- if (inclusiveMin) {
97
- return this.value >= min && this.value < max;
98
- }
99
-
100
- if (inclusiveMax) {
101
- return this.value > min && this.value <= max;
102
- }
103
-
104
- return this.value > min && this.value < max;
105
-
106
- }
107
-
108
- // protected METHODS
109
-
110
- // private METHODS
111
-
112
- // public static METHODS
113
-
114
- public static override isValid(value: unknown): boolean
115
- {
116
- return (
117
- 'number' === typeof value
118
- && !Object.is(value, NaN)
119
- && !Object.is(value, Infinity)
120
- && !Object.is(value, -Infinity)
121
- );
122
- }
123
-
124
- public static from(value: T): NumericValueObject
125
- {
126
- if (!this.isValid(value)) {
127
- throw new ValueError(value, this.name);
128
- }
129
- return new this(value);
130
- }
131
-
132
- // protected static METHODS
133
-
134
- // private static METHODS
135
-
136
- } //:: class
@@ -1,87 +0,0 @@
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 = string;
14
-
15
- // Constants
16
-
17
-
18
- /**
19
- * @description
20
- */
21
- export default class StringValueObject 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: StringValueObject | 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 isEmpty(): boolean
60
- {
61
- return 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 ('string' === typeof value);
73
- }
74
-
75
- public static from(value: T): StringValueObject
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
@@ -1,82 +0,0 @@
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 = symbol;
14
-
15
- // Constants
16
-
17
-
18
- /**
19
- * @description
20
- */
21
- export default class SymbolValueObject 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: SymbolValueObject | null | undefined): boolean
51
- {
52
- if (other === null || other === undefined) {
53
- return false;
54
- }
55
-
56
- return this.value === other.value;
57
- }
58
-
59
- // protected METHODS
60
-
61
- // private METHODS
62
-
63
- // public static METHODS
64
-
65
- public static override isValid(value: unknown): boolean
66
- {
67
- return ('symbol' === typeof value);
68
- }
69
-
70
- public static from(value: T): SymbolValueObject
71
- {
72
- if (!this.isValid(value)) {
73
- throw new ValueError(value, this.name);
74
- }
75
- return new this(value);
76
- }
77
-
78
- // protected static METHODS
79
-
80
- // private static METHODS
81
-
82
- } //:: class
@@ -1,57 +0,0 @@
1
- // Libraries
2
-
3
- // Same Layer
4
-
5
- // Lower Layers
6
-
7
- // Types
8
-
9
- type TValue = string | symbol | number | bigint | boolean | object | null;
10
-
11
- // Constants
12
-
13
-
14
- /**
15
- * @description
16
- */
17
- export default abstract class ValueObject
18
- {
19
-
20
- [property: string]: unknown;
21
-
22
- // public ATTRIBUTES
23
-
24
- public abstract readonly value: TValue;
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 METHODS
39
-
40
- public abstract equals(other: ValueObject | null | undefined): boolean;
41
-
42
- // protected METHODS
43
-
44
- // private METHODS
45
-
46
- // public static METHODS
47
-
48
- public static isValid(value: unknown): boolean
49
- {
50
- return value !== null && value !== undefined && !Object.is(value, NaN);
51
- }
52
-
53
- // protected static METHODS
54
-
55
- // private static METHODS
56
-
57
- } //:: class