tshex-cli 1.0.17 → 1.0.19

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tshex-cli",
3
- "version": "1.0.17",
3
+ "version": "1.0.19",
4
4
  "author": "https://github.com/virtualitems/",
5
5
  "description": "Typescript Hexagonal Architecture CLI",
6
6
  "type": "module",
@@ -26,25 +26,23 @@
26
26
  "bugs": {
27
27
  "url": "https://github.com/virtualitems/tshex-cli/issues"
28
28
  },
29
+ "types": "./source/index.d.ts",
29
30
  "files": [
30
31
  "./build",
31
32
  "./source",
32
33
  "./templates"
33
34
  ],
34
- "types": "./source/index.d.ts",
35
- "devDependencies": {
36
- "@types/node": "^22.5.4",
37
- "typescript": "^5.4.5"
35
+ "bin": {
36
+ "tshex": "./build/main.js"
38
37
  },
39
38
  "dependencies": {
40
39
  "commander": "^12.1.0"
41
40
  },
42
- "bin": {
43
- "tshex": "./build/main.js"
41
+ "devDependencies": {
42
+ "@types/node": "^22.5.4",
43
+ "typescript": "^5.4.5"
44
44
  },
45
45
  "scripts": {
46
- "examples": "tsc -p examples",
47
- "build": "tsc",
48
- "dev": "tsc -w"
46
+ "build": "tsc"
49
47
  }
50
48
  }
@@ -0,0 +1,15 @@
1
+ import { DataManager } from './managers.js'
2
+
3
+ /**
4
+ * @description Declares the connection contract with a data source driver.
5
+ * It connects to the source, returns an enabled data manager, and disconnects when the work is done.
6
+ * This declaration belongs to the application layer as a contract,
7
+ * while its concrete implementation belongs to the adapters layer.
8
+ */
9
+ export abstract class DriverAdapter<M extends DataManager = DataManager> {
10
+ [property: string]: unknown
11
+
12
+ public abstract connect(...args: unknown[]): Promise<M>
13
+
14
+ public abstract disconnect(): Promise<unknown>
15
+ } //:: class
@@ -0,0 +1,81 @@
1
+ /**
2
+ * @description Declares a filtering operation over plain source records.
3
+ */
4
+ export interface Filterable<S = Record<string, unknown>> {
5
+ filter(selector: S): Promise<Array<S>>
6
+ }
7
+
8
+ /**
9
+ * @description Declares a sorting operation over plain source records.
10
+ */
11
+ export interface Sortable<S = Record<string, unknown>> {
12
+ sort(selector: S): Promise<Array<S>>
13
+ }
14
+
15
+ /**
16
+ * @description Declares a creation operation for plain source records.
17
+ */
18
+ export interface Creatable<D = Record<string, unknown>> {
19
+ create(data: D): Promise<unknown>
20
+ }
21
+
22
+ /**
23
+ * @description Declares an update operation that selects source records and applies new plain data.
24
+ */
25
+ export interface Updatable<S = Record<string, unknown>, D = Record<string, unknown>> {
26
+ update(selector: S, data: D): Promise<unknown>
27
+ }
28
+
29
+ /**
30
+ * @description Declares a deletion operation over source records selected by plain criteria.
31
+ */
32
+ export interface Deletable<S = Record<string, unknown>> {
33
+ delete(selector: S): Promise<unknown>
34
+ }
35
+
36
+ /**
37
+ * @description Declares an aggregation operation over source records.
38
+ */
39
+ export interface Aggregatable<S = Record<string, unknown>> {
40
+ aggregate(selector: S): Promise<S>
41
+ }
42
+
43
+ /**
44
+ * @description Declares operations for selecting or preloading relationships from a data source.
45
+ */
46
+ export interface Relatable {
47
+ selectRelated(...args: unknown[]): unknown
48
+
49
+ prefetchRelated(...args: unknown[]): unknown
50
+ }
51
+
52
+ /**
53
+ * @description Operates on a data source using plain objects and arrays.
54
+ * It exposes the raw data without transforming it.
55
+ */
56
+ export abstract class DataManager<T = Record<string, unknown>> {
57
+ [property: string]: unknown
58
+
59
+ public none(): Array<T> {
60
+ return []
61
+ }
62
+
63
+ public abstract all(): Promise<Array<T>>
64
+ } //:: class
65
+
66
+ /**
67
+ * @description Extends a data manager with set operations over data collections.
68
+ */
69
+ export abstract class DatasetManager<T = Record<string, unknown>> extends DataManager<T> {
70
+ [property: string]: unknown
71
+
72
+ public abstract union(other: Array<T>): Promise<Array<T>>
73
+
74
+ public abstract intersection(other: Array<T>): Promise<Array<T>>
75
+
76
+ public abstract difference(other: Array<T>): Promise<Array<T>>
77
+
78
+ public abstract symmetricDifference(other: Array<T>): Promise<Array<T>>
79
+
80
+ public abstract complement(other: Array<T>): Promise<Array<T>>
81
+ } //:: class
@@ -0,0 +1,29 @@
1
+ import { type DataManager } from './managers.js'
2
+ import { type DriverAdapter } from './drivers.js'
3
+
4
+ /**
5
+ * @description Acts as an intermediary between plain source data and domain objects.
6
+ * It transforms records into domain representations and can translate them back when needed.
7
+ */
8
+ export abstract class Repository<
9
+ DataShape extends Record<string, unknown> = Record<string, unknown>,
10
+ EntityShape extends Record<string, unknown> = Record<string, unknown>
11
+ > {
12
+ [property: string]: unknown
13
+
14
+ public constructor(public readonly driver: DriverAdapter<DataManager<DataShape>>) {}
15
+
16
+ public async all(): Promise<Array<EntityShape>> {
17
+ const connection = await this.driver.connect()
18
+ const raw = await connection.all()
19
+ const entities = this.transformList(raw)
20
+ await this.driver.disconnect()
21
+ return entities
22
+ }
23
+
24
+ protected transformList(data: Array<DataShape>): Array<EntityShape> {
25
+ return data.map(this.transform)
26
+ }
27
+
28
+ protected abstract transform(data: DataShape): EntityShape
29
+ } //:: class
@@ -1,121 +1,35 @@
1
- // Libraries
2
-
3
- // Same Layer
4
-
5
- // Lower Layers
6
-
7
- // Types
8
-
9
- // Constants
10
-
11
1
  /**
12
- * @description
2
+ * @description Represents something that occurred in the application.
3
+ * It carries the event time and its plain details.
13
4
  */
14
5
  export abstract class Event {
15
6
  [property: string]: unknown
16
7
 
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
8
  public constructor(
32
9
  public readonly timestamp: number = Date.now(),
33
10
  public readonly details: Record<string, unknown> = {}
34
11
  ) {}
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
12
  } //:: class
48
13
 
49
14
  /**
50
- * @description
15
+ * @description Represents a reaction to an application event.
51
16
  */
52
17
  export abstract class EventHandler {
53
18
  [property: string]: unknown
54
19
 
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
20
  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
21
  } //:: class
83
22
 
84
23
  /**
85
- * @description
24
+ * @description Declares the interaction contract with an event bus.
25
+ * It subscribes handlers, removes subscriptions, and dispatches events.
86
26
  */
87
27
  export abstract class EventDispatcher {
88
28
  [property: string]: unknown
89
29
 
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
30
  public abstract subscribe(key: unknown, handler: EventHandler): void
107
31
 
108
32
  public abstract unsubscribe(key: unknown, handler: EventHandler): void
109
33
 
110
34
  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
35
  } //:: class
@@ -1,48 +1,35 @@
1
- // Libraries
2
-
3
- // Same Layer
4
-
5
- // Lower Layers
6
-
7
- // Types
8
-
9
- // Constants
10
-
11
1
  /**
12
2
  * @description
13
3
  */
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
4
+ export interface HttpRequest {}
38
5
 
39
- // protected METHODS
40
-
41
- // private METHODS
6
+ /**
7
+ * @description
8
+ */
9
+ export interface HttpResponse {}
42
10
 
43
- // public static METHODS
11
+ /**
12
+ * @description
13
+ */
14
+ export interface HttpResponseBody {
15
+ readonly data: Record<string, unknown> | null
16
+ readonly errors: string[] | null
17
+ readonly links: Record<string, URL> | null
18
+ }
44
19
 
45
- // protected static METHODS
20
+ /**
21
+ * @description
22
+ */
23
+ export interface HttpRequestHandler {
24
+ handle(request: HttpRequest): HttpResponse | Promise<HttpResponse>
25
+ }
46
26
 
47
- // private static METHODS
48
- } //:: class
27
+ /**
28
+ * @description
29
+ */
30
+ export interface HttpMiddleware {
31
+ process(
32
+ request: HttpRequest,
33
+ handler: HttpRequestHandler
34
+ ): HttpResponse | Promise<HttpResponse>
35
+ }
@@ -9,7 +9,8 @@ export const ERROR = 40
9
9
  export const CRITICAL = 50
10
10
 
11
11
  /**
12
- * @description
12
+ * @description Declares the logging contract used by the application layer.
13
+ * Adapters implement this abstraction to send logs to external systems.
13
14
  */
14
15
  export abstract class Logger {
15
16
  [property: string]: unknown
@@ -1,43 +1,7 @@
1
- // Libraries
2
-
3
- // Same Layer
4
-
5
- // Lower Layers
6
-
7
- // Types
8
-
9
- // Constants
10
-
11
1
  /**
12
- * @description
13
- * function arguments are Entity
2
+ * @description Represents an application use case.
3
+ * A service coordinates domain capabilities and collaborators to complete a process that fulfills a system purpose.
14
4
  */
15
5
  export abstract class Service {
16
6
  [property: string]: unknown
17
-
18
- // public ATTRIBUTES
19
-
20
- // protected ATTRIBUTES
21
-
22
- // private ATTRIBUTES
23
-
24
- // public static ATTRIBUTES
25
-
26
- // protected static ATTRIBUTES
27
-
28
- // private static ATTRIBUTES
29
-
30
- // Constructor, Getters, Setters
31
-
32
- // public METHODS
33
-
34
- // protected METHODS
35
-
36
- // private METHODS
37
-
38
- // public static METHODS
39
-
40
- // protected static METHODS
41
-
42
- // private static METHODS
43
7
  } //:: class
@@ -2,9 +2,5 @@
2
2
  * @description
3
3
  */
4
4
  export interface Validatable {
5
- [property: string]: unknown
6
-
7
5
  isValid(): boolean
8
-
9
- validate(): unknown
10
6
  }
@@ -1,44 +1,7 @@
1
- // Libraries
2
-
3
- // Same Layer
4
-
5
- // Lower Layers
6
-
7
- // Types
8
-
9
- // Constants
10
-
11
1
  /**
12
- * @description An Aggregate is a class that contains business logic that doesn't belong to any entity.
13
- * It is used to perform operations that don't fit into an entity or involve multiple entities.
14
- * Normally, method arguments are entities.
2
+ * @description Represents a logical unit that groups multiple entities.
3
+ * Its operations depend on the identities and collaboration of the entities that compose that unit.
15
4
  */
16
5
  export abstract class Aggregate {
17
6
  [property: string]: unknown
18
-
19
- // public ATTRIBUTES
20
-
21
- // protected ATTRIBUTES
22
-
23
- // private ATTRIBUTES
24
-
25
- // public static ATTRIBUTES
26
-
27
- // protected static ATTRIBUTES
28
-
29
- // private static ATTRIBUTES
30
-
31
- // Constructor, Getters, Setters
32
-
33
- // public METHODS
34
-
35
- // protected METHODS
36
-
37
- // private METHODS
38
-
39
- // public static METHODS
40
-
41
- // protected static METHODS
42
-
43
- // private static METHODS
44
7
  } //:: class
@@ -1,46 +1,17 @@
1
- // Libraries
2
-
3
- // Same Layer
4
-
5
- // Lower Layers
6
-
7
- // Types
8
-
9
- // Constants
10
-
11
1
  /**
12
- * @description An Entity is a class that represents a domain concept or element.
2
+ * @description Represents a domain concept with its own identity.
3
+ * Two instances describe the same element when they share that identity.
13
4
  */
14
5
  export abstract class Entity {
15
6
  [property: string]: unknown
16
7
 
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
8
  public abstract equals(other: Entity): boolean
34
9
 
35
- public abstract toJSON(): Record<string, unknown>
36
-
37
- // protected METHODS
38
-
39
- // private METHODS
40
-
41
- // public static METHODS
42
-
43
- // protected static METHODS
10
+ public toJSON(): Record<string, unknown> {
11
+ return this
12
+ }
44
13
 
45
- // private static METHODS
14
+ public toString(): string {
15
+ return String(this.constructor.name)
16
+ }
46
17
  } //:: class
@@ -1,46 +1,10 @@
1
- // Libraries
2
-
3
- // Same Layer
4
-
5
- // Lower Layers
6
-
7
- // Types
8
-
9
- // Constants
10
-
11
1
  /**
12
- * @description
2
+ * @description Represents a received value that does not satisfy the rule expected by a domain concept.
13
3
  */
14
4
  export class ValueError extends Error {
15
5
  [property: string]: unknown
16
6
 
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
7
  public constructor(received: string, expected: string) {
32
8
  super(`Invalid value ${received} for ${expected}.`)
33
9
  }
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
10
  } //:: class