tshex-cli 1.0.28 → 1.0.30
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/build/main.js +1 -158
- package/docs/context-ports.md +66 -28
- package/docs/generated-file-reference.md +2 -1
- package/docs/library-structure.md +22 -6
- package/docs/shared/application/data.md +188 -106
- package/docs/shared/application/services.md +90 -87
- package/docs/shared/domain/aggregates.md +22 -131
- package/docs/shared/domain/entities.md +96 -51
- package/package.json +7 -8
- package/source/main.ts +34 -11
- package/templates/ctx/example-ports.ts +1 -0
- package/templates/lib/shared/application/data/capabilities.ts +60 -0
- package/templates/lib/shared/application/data/drivers.ts +2 -2
- package/templates/lib/shared/application/data/managers.ts +5 -62
- package/templates/lib/shared/application/data/repositories.ts +7 -19
- package/templates/lib/shared/application/events.ts +1 -1
- package/templates/lib/shared/application/http/errors.ts +2 -0
- package/templates/lib/shared/application/loggers.ts +0 -21
- package/templates/lib/shared/domain/entities.ts +1 -1
- package/templates/lib/shared/application/http/handlers.ts +0 -13
- package/templates/lib/shared/application/http/json-api.ts +0 -611
- package/templates/lib/shared/application/http/json-web-token.ts +0 -980
- package/templates/lib/shared/application/http/opengraph.ts +0 -533
|
@@ -1,29 +1,17 @@
|
|
|
1
1
|
import { type DataManager } from './managers.js'
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
type Generic = Record<string, unknown>
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* @description Acts as an intermediary between plain source data and domain objects.
|
|
6
7
|
* It transforms records into domain representations and can translate them back when needed.
|
|
7
8
|
*/
|
|
8
|
-
export abstract class Repository<
|
|
9
|
-
DataShape extends Record<string, unknown> = Record<string, unknown>,
|
|
10
|
-
EntityShape extends Record<string, unknown> = Record<string, unknown>
|
|
11
|
-
> {
|
|
9
|
+
export abstract class Repository<RawDataShape = Generic, EntityShape = Generic, M extends DataManager<RawDataShape> = DataManager<RawDataShape>> {
|
|
12
10
|
[property: string]: unknown
|
|
13
11
|
|
|
14
|
-
public constructor(
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
}
|
|
12
|
+
public constructor(
|
|
13
|
+
public readonly manager: M
|
|
14
|
+
) {}
|
|
27
15
|
|
|
28
|
-
protected abstract transform(data:
|
|
16
|
+
protected abstract transform(data: RawDataShape, ...args: unknown[]): EntityShape
|
|
29
17
|
} //:: class
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
* @description HTTP error with a specific status code and message.
|
|
3
3
|
*/
|
|
4
4
|
export class HttpError extends Error {
|
|
5
|
+
[property: string]: unknown
|
|
6
|
+
|
|
5
7
|
public static readonly messages: { [code: number]: string } = Object.freeze({
|
|
6
8
|
400: 'Bad Request',
|
|
7
9
|
401: 'Unauthorized',
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { type TimeZone } from '../../types/timezones'
|
|
2
|
-
import { type Locale } from '../../types/locales'
|
|
3
|
-
|
|
4
1
|
export const DEBUG = 10
|
|
5
2
|
|
|
6
3
|
export const INFO = 20
|
|
@@ -22,20 +19,6 @@ export abstract class Logger {
|
|
|
22
19
|
|
|
23
20
|
public level: number = 0
|
|
24
21
|
|
|
25
|
-
public datetimeLocales: Locale[] = ['en-GB']
|
|
26
|
-
|
|
27
|
-
public datetimeFormatOptions: Intl.DateTimeFormatOptions & { timeZone: TimeZone } = {
|
|
28
|
-
timeZone: 'UTC',
|
|
29
|
-
year: 'numeric',
|
|
30
|
-
month: '2-digit',
|
|
31
|
-
day: '2-digit',
|
|
32
|
-
hour: '2-digit',
|
|
33
|
-
minute: '2-digit',
|
|
34
|
-
second: '2-digit',
|
|
35
|
-
fractionalSecondDigits: 3,
|
|
36
|
-
hourCycle: 'h23'
|
|
37
|
-
}
|
|
38
|
-
|
|
39
22
|
public abstract debug(data: unknown): void
|
|
40
23
|
|
|
41
24
|
public abstract info(data: unknown): void
|
|
@@ -45,8 +28,4 @@ export abstract class Logger {
|
|
|
45
28
|
public abstract error(data: unknown): void
|
|
46
29
|
|
|
47
30
|
public abstract critical(data: unknown): void
|
|
48
|
-
|
|
49
|
-
protected getCurrentDatetime(): string {
|
|
50
|
-
return new Date().toLocaleString(this.datetimeLocales, this.datetimeFormatOptions)
|
|
51
|
-
}
|
|
52
31
|
} //:: class
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description Http request handler to process incoming requests and generate responses.
|
|
3
|
-
*/
|
|
4
|
-
export interface HttpRequestHandler {
|
|
5
|
-
handle(request: Request): Response | Promise<Response>
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @description An HTTP middleware that pipes requests through handlers.
|
|
10
|
-
*/
|
|
11
|
-
export interface HttpMiddleware {
|
|
12
|
-
process(request: Request, handler: HttpRequestHandler): Response | Promise<Response>
|
|
13
|
-
}
|