tshex-cli 1.0.13 → 1.0.15

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 +205 -76
  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
package/source/main.ts CHANGED
@@ -1,145 +1,84 @@
1
- #!/usr/bin/env node
2
-
3
- // NPM LIBRARIES
4
-
5
- import { program } from 'commander';
6
-
7
-
8
- // NODE LIBRARIES
9
-
10
- import fs from 'fs';
11
- import path from 'path';
12
-
13
- // Read package.json
14
- const packageJson = JSON.parse(
15
- fs.readFileSync(
16
- path.join(import.meta.dirname, '..', 'package.json'),
17
- 'utf-8'
18
- )
19
- );
20
-
21
-
22
- // COMMANDER SETUP
23
-
24
- program
25
- .name('tshex')
26
- .version(packageJson.version)
27
- .option('--lib <name>', 'creates a new library with it\'s shared directory')
28
- .option('--ctx <name>', 'creates a new context')
29
- .option('--cls <name>', 'creates a new class')
30
- .option('--rfc <name>', 'creates a new react functional component')
31
- .option('--dir <path>', 'sets the directory to create the new item')
32
- .parse(process.argv);
33
-
34
-
35
- // FUNCTIONS
36
-
37
- function executeCreateLib(templatesDir: string, libraryDir: string)
38
- {
39
- try {
40
- fs.cpSync(
41
- path.join(templatesDir, 'lib'),
42
- libraryDir,
43
- {
44
- recursive: true,
45
- filter: (src) => (!src.endsWith('.gitkeep'))
46
- },
47
- );
48
- console.log('Library created successfully');
49
- }
50
- catch (err) {
51
- console.error(err);
52
- }
53
- }
54
-
55
-
56
- function executeCreateContext(templatesDir: string, contextDir: string)
57
- {
58
- try {
59
- fs.cpSync(
60
- path.join(templatesDir, 'ctx'),
61
- contextDir,
62
- {
63
- recursive: true,
64
- filter: (src) => (!src.endsWith('.gitkeep'))
65
- },
66
- );
67
- console.log('Context created successfully');
68
- }
69
- catch (err) {
70
- console.error(err);
71
- }
72
- }
73
-
74
-
75
- function executeCreateClass(templatesDir: string, classDir: string)
76
- {
77
- try {
78
- fs.cpSync(
79
- path.join(templatesDir, 'cls.example'),
80
- classDir,
81
- {},
82
- );
83
- console.log('Class created successfully');
84
- } catch (err) {
85
- console.error(err);
86
- }
87
- }
88
-
89
-
90
- function executeCreateReactFunctionalComponent(templatesDir: string, classDir: string)
91
- {
92
- try {
93
- fs.cpSync(
94
- path.join(templatesDir, 'rfc.example'),
95
- classDir,
96
- {},
97
- );
98
- console.log('React component created successfully');
99
- } catch (err) {
100
- console.error(err);
101
- }
102
- }
103
-
104
-
105
- // CLIENT CODE
106
-
107
- (function ()
108
- {
109
-
110
- const templatesDir = path.join(import.meta.dirname, '..', 'templates');
111
-
112
- const options = program.opts();
113
-
114
- let targetDir = path.resolve(options.dir ?? process.cwd());
115
-
116
- if (Object.keys(options).length === 0) {
117
- program.help();
118
- return;
119
- }
120
-
121
- if (!fs.existsSync(targetDir)) {
122
- fs.mkdirSync(targetDir, { recursive: true });
123
- }
124
-
125
- if (options.lib !== undefined) {
126
- targetDir = path.join(targetDir, options.lib);
127
- executeCreateLib(templatesDir, targetDir);
128
- }
129
-
130
- if (options.ctx !== undefined) {
131
- targetDir = path.join(targetDir, options.ctx);
132
- executeCreateContext(templatesDir, targetDir);
133
- }
134
-
135
- if (options.cls !== undefined) {
136
- const target = path.join(targetDir, options.cls + '.ts');
137
- executeCreateClass(templatesDir, target);
138
- }
139
-
140
- if (options.rfc !== undefined) {
141
- const target = path.join(targetDir, options.rfc + '.tsx');
142
- executeCreateReactFunctionalComponent(templatesDir, target);
143
- }
144
-
145
- })();
1
+ #!/usr/bin/env node
2
+
3
+ // NPM LIBRARIES
4
+
5
+ import { program } from 'commander'
6
+
7
+ // NODE LIBRARIES
8
+
9
+ import fs from 'node:fs'
10
+ import path from 'node:path'
11
+
12
+ // FUNCTIONS
13
+
14
+ function readPackageJson() {
15
+ return JSON.parse(
16
+ fs.readFileSync(
17
+ path.join(import.meta.dirname, '..', 'package.json'),
18
+ 'utf-8'
19
+ )
20
+ )
21
+ }
22
+
23
+ function executeCreateLib(templatesDir: string, libraryDir: string) {
24
+ try {
25
+ fs.cpSync(path.join(templatesDir, 'lib'), libraryDir, {
26
+ recursive: true,
27
+ filter: (src) => !src.endsWith('.gitkeep')
28
+ })
29
+ console.log('Library created successfully')
30
+ } catch (err) {
31
+ console.error(err)
32
+ }
33
+ }
34
+
35
+ function executeCreateContext(templatesDir: string, contextDir: string) {
36
+ try {
37
+ fs.cpSync(path.join(templatesDir, 'ctx'), contextDir, {
38
+ recursive: true,
39
+ filter: (src) => !src.endsWith('.gitkeep')
40
+ })
41
+ console.log('Context created successfully')
42
+ } catch (err) {
43
+ console.error(err)
44
+ }
45
+ }
46
+
47
+ function main(program: typeof import('commander').program) {
48
+ const templatesDir = path.join(import.meta.dirname, '..', 'templates')
49
+
50
+ const options = program.opts()
51
+
52
+ let targetDir = path.resolve(options.dir ?? process.cwd())
53
+
54
+ if (Object.keys(options).length === 0) {
55
+ program.help()
56
+ return
57
+ }
58
+
59
+ if (!fs.existsSync(targetDir)) {
60
+ fs.mkdirSync(targetDir, { recursive: true })
61
+ }
62
+
63
+ if (options.lib !== undefined) {
64
+ targetDir = path.join(targetDir, options.lib)
65
+ executeCreateLib(templatesDir, targetDir)
66
+ }
67
+
68
+ if (options.ctx !== undefined) {
69
+ targetDir = path.join(targetDir, options.ctx)
70
+ executeCreateContext(templatesDir, targetDir)
71
+ }
72
+ }
73
+
74
+ const packageJson = readPackageJson()
75
+
76
+ program
77
+ .name('tshex')
78
+ .version(packageJson.version)
79
+ .option('--lib <name>', "creates a new library with it's shared directory")
80
+ .option('--ctx <name>', 'creates a new context')
81
+ .option('--dir <path>', 'sets the directory to create the new item')
82
+ .parse(process.argv)
83
+
84
+ main(program)
@@ -1,9 +1,9 @@
1
- // Ports layer
2
-
3
- // Adapters layer
4
-
5
- // Application layer
6
-
7
- // Domain layer
8
-
9
- // Constants
1
+ // Ports layer
2
+
3
+ // Adapters layer
4
+
5
+ // Application layer
6
+
7
+ // Domain layer
8
+
9
+ // Constants
@@ -1 +1 @@
1
- type Generic<T=unknown> = Record<string, T>;
1
+ type Generic<T=unknown> = Record<string, T>;
@@ -1,5 +1,5 @@
1
- /**
2
- * @fileoverview This file is used only for exporting the main components of the library.
3
- */
4
-
5
- throw new Error('Not implemented yet');
1
+ /**
2
+ * @fileoverview This file is used only for exporting the main components of the library.
3
+ */
4
+
5
+ throw new Error('Not implemented yet');
@@ -0,0 +1,81 @@
1
+ // Libraries
2
+
3
+ // Same Layer
4
+
5
+ // Lower Layers
6
+
7
+ // Types
8
+
9
+ // Constants
10
+
11
+ /**
12
+ * @description
13
+ */
14
+ export abstract class DataManager {
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 Methods
32
+
33
+ public abstract connect(...args: unknown[]): Promise<unknown>
34
+
35
+ public abstract disconnect(): Promise<unknown>
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
47
+
48
+ /**
49
+ * @description Represents a data source.
50
+ */
51
+ export abstract class Repository<Manager extends DataManager> {
52
+ [property: string]: unknown
53
+
54
+ // Public Attributes
55
+
56
+ // Protected Attributes
57
+
58
+ // Private Attributes
59
+
60
+ // Public Static Attributes
61
+
62
+ // Protected Static Attributes
63
+
64
+ // Private Static Attributes
65
+
66
+ // Constructor, Getters, Setters
67
+
68
+ public constructor(public readonly manager: Manager) {}
69
+
70
+ // Public Methods
71
+
72
+ // Protected Methods
73
+
74
+ // Private Methods
75
+
76
+ // Public Static Methods
77
+
78
+ // Protected Static Methods
79
+
80
+ // Private Static Methods
81
+ } //:: class
@@ -0,0 +1,121 @@
1
+ // Libraries
2
+
3
+ // Same Layer
4
+
5
+ // Lower Layers
6
+
7
+ // Types
8
+
9
+ // Constants
10
+
11
+ /**
12
+ * @description
13
+ */
14
+ export abstract class Event {
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(
32
+ public readonly timestamp: number = Date.now(),
33
+ public readonly details: Record<string, unknown> = {}
34
+ ) {}
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
+ } //:: class
48
+
49
+ /**
50
+ * @description
51
+ */
52
+ export abstract class EventHandler {
53
+ [property: string]: unknown
54
+
55
+ // public ATTRIBUTES
56
+
57
+ // protected ATTRIBUTES
58
+
59
+ // private ATTRIBUTES
60
+
61
+ // public static ATTRIBUTES
62
+
63
+ // protected static ATTRIBUTES
64
+
65
+ // private static ATTRIBUTES
66
+
67
+ // Constructor, Getters, Setters
68
+
69
+ // public METHODS
70
+
71
+ public abstract handle(event: Event): Promise<void>
72
+
73
+ // protected METHODS
74
+
75
+ // private METHODS
76
+
77
+ // public static METHODS
78
+
79
+ // protected static METHODS
80
+
81
+ // private static METHODS
82
+ } //:: class
83
+
84
+ /**
85
+ * @description
86
+ */
87
+ export abstract class EventDispatcher {
88
+ [property: string]: unknown
89
+
90
+ // public ATTRIBUTES
91
+
92
+ // protected ATTRIBUTES
93
+
94
+ // private ATTRIBUTES
95
+
96
+ // public static ATTRIBUTES
97
+
98
+ // protected static ATTRIBUTES
99
+
100
+ // private static ATTRIBUTES
101
+
102
+ // Constructor, Getters, Setters
103
+
104
+ // public METHODS
105
+
106
+ public abstract subscribe(key: unknown, handler: EventHandler): void
107
+
108
+ public abstract unsubscribe(key: unknown, handler: EventHandler): void
109
+
110
+ public abstract dispatch(event: Event): void
111
+
112
+ // protected METHODS
113
+
114
+ // private METHODS
115
+
116
+ // public static METHODS
117
+
118
+ // protected static METHODS
119
+
120
+ // private static METHODS
121
+ } //:: class
@@ -1,52 +1,48 @@
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 Response
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(
35
- public readonly data: unknown,
36
- public readonly error: unknown,
37
- public readonly message: unknown,
38
- ) { }
39
-
40
- // public METHODS
41
-
42
- // protected METHODS
43
-
44
- // private METHODS
45
-
46
- // public static METHODS
47
-
48
- // protected static METHODS
49
-
50
- // private static METHODS
51
-
52
- } //:: 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 HttpResponseBody {
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(
32
+ public readonly data: Record<string, unknown> | null = null,
33
+ public readonly errors: string[] | null = null,
34
+ public readonly links: Record<string, URL> | null = null
35
+ ) {}
36
+
37
+ // public METHODS
38
+
39
+ // protected METHODS
40
+
41
+ // private METHODS
42
+
43
+ // public static METHODS
44
+
45
+ // protected static METHODS
46
+
47
+ // private static METHODS
48
+ } //:: class
@@ -1,50 +1,50 @@
1
- // Libraries
2
-
3
- // Shared Module
4
-
5
- // Other Modules
6
-
7
- // Same Layer
8
-
9
- // Lower Layers
10
-
11
- // Types
12
-
13
- // Constants
14
-
15
-
16
- /**
17
- * @description
18
- */
19
- export default class __CLASS__ extends __DECLARE_FIRST__OVERRIDE_SECOND__ABSTRACT_LAST__
20
- {
21
-
22
- [property: string]: unknown;
23
-
24
- // public ATTRIBUTES
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
- // 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
+ // Libraries
2
+
3
+ // Same Layer
4
+
5
+ // Lower Layers
6
+
7
+ // Types
8
+
9
+ // Constants
10
+
11
+ /**
12
+ * @description
13
+ */
14
+ export abstract class Logger {
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 METHODS
32
+
33
+ public abstract debug(data: unknown): void
34
+
35
+ public abstract info(data: unknown): void
36
+
37
+ public abstract warning(data: unknown): void
38
+
39
+ public abstract error(data: unknown): void
40
+
41
+ // protected METHODS
42
+
43
+ // private METHODS
44
+
45
+ // public static METHODS
46
+
47
+ // protected static METHODS
48
+
49
+ // private static METHODS
50
+ } //:: class