@navios/core 1.0.0 → 2.0.0-alpha.0
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/CHANGELOG.md +97 -11
- package/README.md +67 -220
- package/lib/async-context-6pdlnNLA.d.mts +237 -0
- package/lib/async-context-6pdlnNLA.d.mts.map +1 -0
- package/lib/async-context-Dqk7pE-D.d.cts +237 -0
- package/lib/async-context-Dqk7pE-D.d.cts.map +1 -0
- package/lib/attribute-factory-B3VuYnp7.d.cts +70 -0
- package/lib/attribute-factory-B3VuYnp7.d.cts.map +1 -0
- package/lib/attribute-factory-mKOXoVnV.d.mts +70 -0
- package/lib/attribute-factory-mKOXoVnV.d.mts.map +1 -0
- package/lib/attribute-value-CjX9ZkLq.cjs +172 -0
- package/lib/attribute-value-CjX9ZkLq.cjs.map +1 -0
- package/lib/attribute-value-DMEA255r.mjs +119 -0
- package/lib/attribute-value-DMEA255r.mjs.map +1 -0
- package/lib/basic-execution-context-CeGuhMOz.mjs +246 -0
- package/lib/basic-execution-context-CeGuhMOz.mjs.map +1 -0
- package/lib/basic-execution-context-DSk5MNtc.cjs +281 -0
- package/lib/basic-execution-context-DSk5MNtc.cjs.map +1 -0
- package/lib/execution-context-BPD3FeFb.d.mts +71 -0
- package/lib/execution-context-BPD3FeFb.d.mts.map +1 -0
- package/lib/execution-context-BTJdHhbf.d.cts +71 -0
- package/lib/execution-context-BTJdHhbf.d.cts.map +1 -0
- package/lib/execution-context-token-BXUKB2hf.cjs +112 -0
- package/lib/execution-context-token-BXUKB2hf.cjs.map +1 -0
- package/lib/execution-context-token-CrXmTvk2.mjs +77 -0
- package/lib/execution-context-token-CrXmTvk2.mjs.map +1 -0
- package/lib/index.cjs +1687 -4409
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +838 -3
- package/lib/index.d.cts.map +1 -0
- package/lib/index.d.mts +838 -3
- package/lib/index.d.mts.map +1 -0
- package/lib/index.mjs +1573 -4219
- package/lib/index.mjs.map +1 -1
- package/lib/legacy-compat/index.cjs +72 -371
- package/lib/legacy-compat/index.cjs.map +1 -1
- package/lib/legacy-compat/index.d.cts +42 -382
- package/lib/legacy-compat/index.d.cts.map +1 -1
- package/lib/legacy-compat/index.d.mts +41 -382
- package/lib/legacy-compat/index.d.mts.map +1 -1
- package/lib/legacy-compat/index.mjs +51 -345
- package/lib/legacy-compat/index.mjs.map +1 -1
- package/lib/module-Bha7GER_.mjs +135 -0
- package/lib/module-Bha7GER_.mjs.map +1 -0
- package/lib/module-DZewk_2r.cjs +164 -0
- package/lib/module-DZewk_2r.cjs.map +1 -0
- package/lib/module-graph-DCP9MHG0.cjs +147 -0
- package/lib/module-graph-DCP9MHG0.cjs.map +1 -0
- package/lib/module-graph-xvVEykFM.mjs +142 -0
- package/lib/module-graph-xvVEykFM.mjs.map +1 -0
- package/lib/module-metadata-C8S92seK.cjs +95 -0
- package/lib/module-metadata-C8S92seK.cjs.map +1 -0
- package/lib/module-metadata-k3RTt20x.mjs +66 -0
- package/lib/module-metadata-k3RTt20x.mjs.map +1 -0
- package/lib/module-options-Dmse0gii.d.mts +51 -0
- package/lib/module-options-Dmse0gii.d.mts.map +1 -0
- package/lib/module-options-IuDO-p8u.d.cts +51 -0
- package/lib/module-options-IuDO-p8u.d.cts.map +1 -0
- package/lib/testing/index.cjs +96 -414
- package/lib/testing/index.cjs.map +1 -1
- package/lib/testing/index.d.cts +25 -385
- package/lib/testing/index.d.cts.map +1 -1
- package/lib/testing/index.d.mts +24 -385
- package/lib/testing/index.d.mts.map +1 -1
- package/lib/testing/index.mjs +94 -408
- package/lib/testing/index.mjs.map +1 -1
- package/lib/transport.cjs +25 -0
- package/lib/transport.d.cts +190 -0
- package/lib/transport.d.cts.map +1 -0
- package/lib/transport.d.mts +190 -0
- package/lib/transport.d.mts.map +1 -0
- package/lib/transport.mjs +7 -0
- package/package.json +37 -17
- package/docs/README.md +0 -316
- package/docs/adapters.md +0 -308
- package/docs/application-setup.md +0 -524
- package/docs/attributes.md +0 -689
- package/docs/controllers.md +0 -373
- package/docs/endpoints.md +0 -444
- package/docs/exceptions.md +0 -352
- package/docs/guards.md +0 -550
- package/docs/legacy-compat.md +0 -356
- package/docs/modules.md +0 -377
- package/docs/quick-start.md +0 -290
- package/docs/services.md +0 -427
- package/docs/testing.md +0 -827
- package/lib/index-C0Sg16Eb.d.cts +0 -3365
- package/lib/index-C0Sg16Eb.d.cts.map +0 -1
- package/lib/index-DySQ6Dpd.d.mts +0 -3365
- package/lib/index-DySQ6Dpd.d.mts.map +0 -1
- package/lib/navios.factory-CO5MB_OK.cjs +0 -4125
- package/lib/navios.factory-CO5MB_OK.cjs.map +0 -1
- package/lib/navios.factory-D6Y94P9B.mjs +0 -3828
- package/lib/navios.factory-D6Y94P9B.mjs.map +0 -1
- package/lib/tokens-4J9sredA.mjs +0 -100
- package/lib/tokens-4J9sredA.mjs.map +0 -1
- package/lib/tokens-CWw9kyeD.cjs +0 -196
- package/lib/tokens-CWw9kyeD.cjs.map +0 -1
- package/lib/use-guards.decorator-BecoQSmE.mjs +0 -339
- package/lib/use-guards.decorator-BecoQSmE.mjs.map +0 -1
- package/lib/use-guards.decorator-C4ml9XaT.cjs +0 -447
- package/lib/use-guards.decorator-C4ml9XaT.cjs.map +0 -1
- package/project.json +0 -66
- package/src/__tests__/attribute.factory.spec.mts +0 -300
- package/src/__tests__/config.service.spec.mts +0 -43
- package/src/__tests__/console-logger.service.spec.mts +0 -312
- package/src/__tests__/controller-resolver.spec.mts +0 -229
- package/src/__tests__/controller.spec.mts +0 -58
- package/src/__tests__/guard-runner.service.spec.mts +0 -399
- package/src/__tests__/logger.service.spec.mts +0 -147
- package/src/__tests__/responders.spec.mts +0 -340
- package/src/__tests__/testing-module.spec.mts +0 -459
- package/src/__tests__/unit-testing-module.spec.mts +0 -424
- package/src/attribute.factory.mts +0 -325
- package/src/config/config-service.interface.mts +0 -47
- package/src/config/config.provider.mts +0 -69
- package/src/config/config.service.mts +0 -176
- package/src/config/index.mts +0 -5
- package/src/config/types.mts +0 -58
- package/src/config/utils/helpers.mts +0 -23
- package/src/config/utils/index.mts +0 -1
- package/src/decorators/controller.decorator.mts +0 -81
- package/src/decorators/endpoint.decorator.mts +0 -181
- package/src/decorators/header.decorator.mts +0 -38
- package/src/decorators/http-code.decorator.mts +0 -38
- package/src/decorators/index.mts +0 -8
- package/src/decorators/module.decorator.mts +0 -106
- package/src/decorators/multipart.decorator.mts +0 -169
- package/src/decorators/stream.decorator.mts +0 -155
- package/src/decorators/use-guards.decorator.mts +0 -73
- package/src/exceptions/bad-request.exception.mts +0 -28
- package/src/exceptions/conflict.exception.mts +0 -31
- package/src/exceptions/forbidden.exception.mts +0 -30
- package/src/exceptions/http.exception.mts +0 -33
- package/src/exceptions/index.mts +0 -7
- package/src/exceptions/internal-server-error.exception.mts +0 -33
- package/src/exceptions/not-found.exception.mts +0 -33
- package/src/exceptions/unauthorized.exception.mts +0 -30
- package/src/factories/adapter.factory.mts +0 -20
- package/src/factories/endpoint-adapter.factory.mts +0 -21
- package/src/factories/http-adapter.factory.mts +0 -20
- package/src/factories/index.mts +0 -8
- package/src/factories/multipart-adapter.factory.mts +0 -21
- package/src/factories/reply.factory.mts +0 -21
- package/src/factories/request.factory.mts +0 -21
- package/src/factories/stream-adapter.factory.mts +0 -20
- package/src/factories/xml-stream-adapter.factory.mts +0 -20
- package/src/index.mts +0 -16
- package/src/interfaces/abstract-adapter.interface.mts +0 -32
- package/src/interfaces/abstract-execution-context.inteface.mts +0 -48
- package/src/interfaces/abstract-http-adapter.interface.mts +0 -79
- package/src/interfaces/abstract-http-cors-options.interface.mts +0 -59
- package/src/interfaces/abstract-http-handler-adapter.interface.mts +0 -127
- package/src/interfaces/abstract-http-listen-options.interface.mts +0 -4
- package/src/interfaces/adapter-environment.interface.mts +0 -74
- package/src/interfaces/can-activate.mts +0 -38
- package/src/interfaces/http-header.mts +0 -18
- package/src/interfaces/index.mts +0 -11
- package/src/interfaces/navios-module.mts +0 -28
- package/src/interfaces/plugin.interface.mts +0 -139
- package/src/legacy-compat/__type-tests__/legacy-decorators.spec-d.mts +0 -521
- package/src/legacy-compat/__type-tests__/tsconfig.json +0 -15
- package/src/legacy-compat/attribute.factory.mts +0 -351
- package/src/legacy-compat/decorators/controller.decorator.mts +0 -31
- package/src/legacy-compat/decorators/endpoint.decorator.mts +0 -73
- package/src/legacy-compat/decorators/header.decorator.mts +0 -43
- package/src/legacy-compat/decorators/http-code.decorator.mts +0 -39
- package/src/legacy-compat/decorators/index.mts +0 -11
- package/src/legacy-compat/decorators/module.decorator.mts +0 -37
- package/src/legacy-compat/decorators/multipart.decorator.mts +0 -72
- package/src/legacy-compat/decorators/stream.decorator.mts +0 -89
- package/src/legacy-compat/decorators/use-guards.decorator.mts +0 -80
- package/src/legacy-compat/index.mts +0 -57
- package/src/logger/README.md +0 -3
- package/src/logger/console-logger.service.mts +0 -714
- package/src/logger/index.mts +0 -6
- package/src/logger/log-levels.mts +0 -21
- package/src/logger/logger-service.interface.mts +0 -42
- package/src/logger/logger.service.mts +0 -113
- package/src/logger/logger.tokens.mts +0 -44
- package/src/logger/utils/cli-colors.util.mts +0 -17
- package/src/logger/utils/filter-log-levelts.util.mts +0 -29
- package/src/logger/utils/index.mts +0 -5
- package/src/logger/utils/is-log-level-enabled.mts +0 -33
- package/src/logger/utils/is-log-level.util.mts +0 -10
- package/src/logger/utils/shared.utils.mts +0 -51
- package/src/metadata/controller.metadata.mts +0 -72
- package/src/metadata/handler.metadata.mts +0 -80
- package/src/metadata/index.mts +0 -4
- package/src/metadata/module.metadata.mts +0 -108
- package/src/metadata/navios-managed.metadata.mts +0 -42
- package/src/navios.application.mts +0 -484
- package/src/navios.environment.mts +0 -42
- package/src/navios.factory.mts +0 -158
- package/src/responders/enums/framework-error.enum.mts +0 -38
- package/src/responders/enums/index.mts +0 -1
- package/src/responders/index.mts +0 -4
- package/src/responders/interfaces/error-responder.interface.mts +0 -42
- package/src/responders/interfaces/error-response.interface.mts +0 -22
- package/src/responders/interfaces/index.mts +0 -3
- package/src/responders/interfaces/problem-details.interface.mts +0 -34
- package/src/responders/services/error-response-producer.service.mts +0 -143
- package/src/responders/services/forbidden-responder.service.mts +0 -77
- package/src/responders/services/index.mts +0 -5
- package/src/responders/services/internal-server-error-responder.service.mts +0 -57
- package/src/responders/services/not-found-responder.service.mts +0 -76
- package/src/responders/services/validation-error-responder.service.mts +0 -78
- package/src/responders/tokens/index.mts +0 -1
- package/src/responders/tokens/responder.tokens.mts +0 -84
- package/src/services/abstract-handler-adapter.service.mts +0 -366
- package/src/services/guard-runner.service.mts +0 -152
- package/src/services/index.mts +0 -4
- package/src/services/instance-resolver.service.mts +0 -177
- package/src/services/module-loader.service.mts +0 -252
- package/src/stores/index.mts +0 -1
- package/src/stores/request-id.store.mts +0 -85
- package/src/testing/index.mts +0 -3
- package/src/testing/testing-module.mts +0 -393
- package/src/testing/unit-testing-module.mts +0 -298
- package/src/tokens/adapter.token.mts +0 -6
- package/src/tokens/endpoint-adapter.token.mts +0 -8
- package/src/tokens/execution-context.token.mts +0 -9
- package/src/tokens/http-adapter.token.mts +0 -8
- package/src/tokens/index.mts +0 -10
- package/src/tokens/multipart-adapter.token.mts +0 -8
- package/src/tokens/navios-options.token.mts +0 -6
- package/src/tokens/reply.token.mts +0 -3
- package/src/tokens/request.token.mts +0 -3
- package/src/tokens/stream-adapter.token.mts +0 -8
- package/src/tokens/xml-stream-adapter.token.mts +0 -8
- package/src/utils/adapter-supports.util.mts +0 -47
- package/src/utils/index.mts +0 -1
- package/tsconfig.json +0 -21
- package/tsconfig.lib.json +0 -8
- package/tsconfig.spec.json +0 -15
- package/tsdown.config.mts +0 -35
- package/vitest.config.mts +0 -15
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Available log levels in order of severity (lowest to highest).
|
|
3
|
-
*/
|
|
4
|
-
export const LOG_LEVELS = [
|
|
5
|
-
'verbose',
|
|
6
|
-
'debug',
|
|
7
|
-
'log',
|
|
8
|
-
'warn',
|
|
9
|
-
'error',
|
|
10
|
-
'fatal',
|
|
11
|
-
] as const satisfies string[]
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Log level type.
|
|
15
|
-
*
|
|
16
|
-
* Represents the severity level of a log message.
|
|
17
|
-
* Levels are: 'verbose', 'debug', 'log', 'warn', 'error', 'fatal'
|
|
18
|
-
*
|
|
19
|
-
* @publicApi
|
|
20
|
-
*/
|
|
21
|
-
export type LogLevel = (typeof LOG_LEVELS)[number]
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { LogLevel } from './log-levels.mjs'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @publicApi
|
|
5
|
-
*/
|
|
6
|
-
export interface LoggerService {
|
|
7
|
-
/**
|
|
8
|
-
* Write a 'log' level log.
|
|
9
|
-
*/
|
|
10
|
-
log(message: any, ...optionalParams: any[]): any
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Write an 'error' level log.
|
|
14
|
-
*/
|
|
15
|
-
error(message: any, ...optionalParams: any[]): any
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Write a 'warn' level log.
|
|
19
|
-
*/
|
|
20
|
-
warn(message: any, ...optionalParams: any[]): any
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Write a 'debug' level log.
|
|
24
|
-
*/
|
|
25
|
-
debug?(message: any, ...optionalParams: any[]): any
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Write a 'verbose' level log.
|
|
29
|
-
*/
|
|
30
|
-
verbose?(message: any, ...optionalParams: any[]): any
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Write a 'fatal' level log.
|
|
34
|
-
*/
|
|
35
|
-
fatal?(message: any, ...optionalParams: any[]): any
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Set log levels.
|
|
39
|
-
* @param levels log levels
|
|
40
|
-
*/
|
|
41
|
-
setLogLevels?(levels: LogLevel[]): any
|
|
42
|
-
}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { inject, Injectable } from '@navios/di'
|
|
2
|
-
|
|
3
|
-
import type { LoggerService } from './logger-service.interface.mjs'
|
|
4
|
-
import type { LoggerOptions } from './logger.tokens.mjs'
|
|
5
|
-
|
|
6
|
-
import { Logger, LoggerOutput } from './logger.tokens.mjs'
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Logger service instance that can be injected into services and controllers.
|
|
10
|
-
*
|
|
11
|
-
* Provides contextualized logging with automatic context injection.
|
|
12
|
-
* The context is set when the logger is injected using the `inject` function.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* @Injectable()
|
|
17
|
-
* export class UserService {
|
|
18
|
-
* private logger = inject(Logger, { context: UserService.name })
|
|
19
|
-
*
|
|
20
|
-
* async findUser(id: string) {
|
|
21
|
-
* this.logger.log(`Finding user ${id}`)
|
|
22
|
-
* // Logs with context: [UserService]
|
|
23
|
-
* }
|
|
24
|
-
* }
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
@Injectable({
|
|
28
|
-
token: Logger,
|
|
29
|
-
})
|
|
30
|
-
export class LoggerInstance implements LoggerService {
|
|
31
|
-
protected localInstance = inject(LoggerOutput)
|
|
32
|
-
|
|
33
|
-
protected context?: string
|
|
34
|
-
|
|
35
|
-
constructor(config: LoggerOptions = {}) {
|
|
36
|
-
this.context = config.context
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Write an 'error' level log.
|
|
41
|
-
*/
|
|
42
|
-
error(message: any, stack?: string, context?: string): void
|
|
43
|
-
error(message: any, ...optionalParams: [...any, string?, string?]): void
|
|
44
|
-
error(message: any, ...optionalParams: any[]) {
|
|
45
|
-
optionalParams = this.context
|
|
46
|
-
? (optionalParams.length ? optionalParams : [undefined]).concat(
|
|
47
|
-
this.context,
|
|
48
|
-
)
|
|
49
|
-
: optionalParams
|
|
50
|
-
|
|
51
|
-
this.localInstance?.error(message, ...optionalParams)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Write a 'log' level log.
|
|
56
|
-
*/
|
|
57
|
-
log(message: any, context?: string): void
|
|
58
|
-
log(message: any, ...optionalParams: [...any, string?]): void
|
|
59
|
-
log(message: any, ...optionalParams: any[]) {
|
|
60
|
-
optionalParams = this.context
|
|
61
|
-
? optionalParams.concat(this.context)
|
|
62
|
-
: optionalParams
|
|
63
|
-
this.localInstance?.log(message, ...optionalParams)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Write a 'warn' level log.
|
|
68
|
-
*/
|
|
69
|
-
warn(message: any, context?: string): void
|
|
70
|
-
warn(message: any, ...optionalParams: [...any, string?]): void
|
|
71
|
-
warn(message: any, ...optionalParams: any[]) {
|
|
72
|
-
optionalParams = this.context
|
|
73
|
-
? optionalParams.concat(this.context)
|
|
74
|
-
: optionalParams
|
|
75
|
-
this.localInstance?.warn(message, ...optionalParams)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Write a 'debug' level log.
|
|
80
|
-
*/
|
|
81
|
-
debug(message: any, context?: string): void
|
|
82
|
-
debug(message: any, ...optionalParams: [...any, string?]): void
|
|
83
|
-
debug(message: any, ...optionalParams: any[]) {
|
|
84
|
-
optionalParams = this.context
|
|
85
|
-
? optionalParams.concat(this.context)
|
|
86
|
-
: optionalParams
|
|
87
|
-
this.localInstance?.debug?.(message, ...optionalParams)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Write a 'verbose' level log.
|
|
92
|
-
*/
|
|
93
|
-
verbose(message: any, context?: string): void
|
|
94
|
-
verbose(message: any, ...optionalParams: [...any, string?]): void
|
|
95
|
-
verbose(message: any, ...optionalParams: any[]) {
|
|
96
|
-
optionalParams = this.context
|
|
97
|
-
? optionalParams.concat(this.context)
|
|
98
|
-
: optionalParams
|
|
99
|
-
this.localInstance?.verbose?.(message, ...optionalParams)
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Write a 'fatal' level log.
|
|
104
|
-
*/
|
|
105
|
-
fatal(message: any, context?: string): void
|
|
106
|
-
fatal(message: any, ...optionalParams: [...any, string?]): void
|
|
107
|
-
fatal(message: any, ...optionalParams: any[]) {
|
|
108
|
-
optionalParams = this.context
|
|
109
|
-
? optionalParams.concat(this.context)
|
|
110
|
-
: optionalParams
|
|
111
|
-
this.localInstance?.fatal?.(message, ...optionalParams)
|
|
112
|
-
}
|
|
113
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { InjectionToken } from '@navios/di'
|
|
2
|
-
|
|
3
|
-
import z from 'zod/v4'
|
|
4
|
-
|
|
5
|
-
import type { LoggerService } from './logger-service.interface.mjs'
|
|
6
|
-
import type { LoggerInstance } from './logger.service.mjs'
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Injection token for the logger output service.
|
|
10
|
-
*
|
|
11
|
-
* This token is used to provide a custom logger implementation.
|
|
12
|
-
* By default, it's bound to ConsoleLogger.
|
|
13
|
-
*/
|
|
14
|
-
export const LoggerOutput = InjectionToken.create<LoggerService>('LoggerOutput')
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Schema for logger options.
|
|
18
|
-
*/
|
|
19
|
-
export const loggerOptionsSchema = z
|
|
20
|
-
.object({
|
|
21
|
-
context: z.string().optional(),
|
|
22
|
-
})
|
|
23
|
-
.optional()
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Options for creating a logger instance.
|
|
27
|
-
*/
|
|
28
|
-
export type LoggerOptions = z.infer<typeof loggerOptionsSchema>
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Injection token for the Logger service.
|
|
32
|
-
*
|
|
33
|
-
* Use this token to inject a contextualized logger instance.
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```typescript
|
|
37
|
-
* const logger = inject(Logger, { context: 'MyService' })
|
|
38
|
-
* logger.log('Hello world') // Logs with context: [MyService]
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
export const Logger = InjectionToken.create<
|
|
42
|
-
LoggerInstance,
|
|
43
|
-
typeof loggerOptionsSchema
|
|
44
|
-
>('Logger', loggerOptionsSchema)
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
type ColorTextFn = (text: string) => string
|
|
2
|
-
|
|
3
|
-
const isColorAllowed = () => !process.env.NO_COLOR
|
|
4
|
-
const colorIfAllowed = (colorFn: ColorTextFn) => (text: string) =>
|
|
5
|
-
isColorAllowed() ? colorFn(text) : text
|
|
6
|
-
|
|
7
|
-
export const clc = {
|
|
8
|
-
bold: colorIfAllowed((text: string) => `\x1B[1m${text}\x1B[0m`),
|
|
9
|
-
green: colorIfAllowed((text: string) => `\x1B[32m${text}\x1B[39m`),
|
|
10
|
-
yellow: colorIfAllowed((text: string) => `\x1B[33m${text}\x1B[39m`),
|
|
11
|
-
red: colorIfAllowed((text: string) => `\x1B[31m${text}\x1B[39m`),
|
|
12
|
-
magentaBright: colorIfAllowed((text: string) => `\x1B[95m${text}\x1B[39m`),
|
|
13
|
-
cyanBright: colorIfAllowed((text: string) => `\x1B[96m${text}\x1B[39m`),
|
|
14
|
-
}
|
|
15
|
-
export const yellow = colorIfAllowed(
|
|
16
|
-
(text: string) => `\x1B[38;5;3m${text}\x1B[39m`,
|
|
17
|
-
)
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { LogLevel } from '../log-levels.mjs'
|
|
2
|
-
|
|
3
|
-
import { LOG_LEVELS } from '../log-levels.mjs'
|
|
4
|
-
import { isLogLevel } from './is-log-level.util.mjs'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @publicApi
|
|
8
|
-
*/
|
|
9
|
-
export function filterLogLevels(parseableString = ''): LogLevel[] {
|
|
10
|
-
const sanitizedString = parseableString.replaceAll(' ', '').toLowerCase()
|
|
11
|
-
|
|
12
|
-
if (sanitizedString[0] === '>') {
|
|
13
|
-
const orEqual = sanitizedString[1] === '='
|
|
14
|
-
|
|
15
|
-
const logLevelIndex = (LOG_LEVELS as string[]).indexOf(
|
|
16
|
-
sanitizedString.substring(orEqual ? 2 : 1),
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
if (logLevelIndex === -1) {
|
|
20
|
-
throw new Error(`parse error (unknown log level): ${sanitizedString}`)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return LOG_LEVELS.slice(orEqual ? logLevelIndex : logLevelIndex + 1)
|
|
24
|
-
} else if (sanitizedString.includes(',')) {
|
|
25
|
-
return sanitizedString.split(',').filter(isLogLevel)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return isLogLevel(sanitizedString) ? [sanitizedString] : LOG_LEVELS
|
|
29
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { LogLevel } from '../log-levels.mjs'
|
|
2
|
-
|
|
3
|
-
const LOG_LEVEL_VALUES: Record<LogLevel, number> = {
|
|
4
|
-
verbose: 0,
|
|
5
|
-
debug: 1,
|
|
6
|
-
log: 2,
|
|
7
|
-
warn: 3,
|
|
8
|
-
error: 4,
|
|
9
|
-
fatal: 5,
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Checks if target level is enabled.
|
|
14
|
-
* @param targetLevel target level
|
|
15
|
-
* @param logLevels array of enabled log levels
|
|
16
|
-
*/
|
|
17
|
-
export function isLogLevelEnabled(
|
|
18
|
-
targetLevel: LogLevel,
|
|
19
|
-
logLevels: LogLevel[] | undefined,
|
|
20
|
-
): boolean {
|
|
21
|
-
if (!logLevels || (Array.isArray(logLevels) && logLevels?.length === 0)) {
|
|
22
|
-
return false
|
|
23
|
-
}
|
|
24
|
-
if (logLevels.includes(targetLevel)) {
|
|
25
|
-
return true
|
|
26
|
-
}
|
|
27
|
-
const highestLogLevelValue = logLevels
|
|
28
|
-
.map((level) => LOG_LEVEL_VALUES[level])
|
|
29
|
-
.sort((a, b) => b - a)?.[0]
|
|
30
|
-
|
|
31
|
-
const targetLevelValue = LOG_LEVEL_VALUES[targetLevel]
|
|
32
|
-
return targetLevelValue >= highestLogLevelValue
|
|
33
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
export const isUndefined = (obj: any): obj is undefined =>
|
|
2
|
-
typeof obj === 'undefined'
|
|
3
|
-
|
|
4
|
-
export const isObject = (fn: any): fn is object =>
|
|
5
|
-
!isNil(fn) && typeof fn === 'object'
|
|
6
|
-
|
|
7
|
-
export const isPlainObject = (fn: any): fn is object => {
|
|
8
|
-
if (!isObject(fn)) {
|
|
9
|
-
return false
|
|
10
|
-
}
|
|
11
|
-
const proto = Object.getPrototypeOf(fn)
|
|
12
|
-
if (proto === null) {
|
|
13
|
-
return true
|
|
14
|
-
}
|
|
15
|
-
const ctor =
|
|
16
|
-
Object.prototype.hasOwnProperty.call(proto, 'constructor') &&
|
|
17
|
-
proto.constructor
|
|
18
|
-
return (
|
|
19
|
-
typeof ctor === 'function' &&
|
|
20
|
-
ctor instanceof ctor &&
|
|
21
|
-
Function.prototype.toString.call(ctor) ===
|
|
22
|
-
Function.prototype.toString.call(Object)
|
|
23
|
-
)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const addLeadingSlash = (path?: string): string =>
|
|
27
|
-
path && typeof path === 'string'
|
|
28
|
-
? path.charAt(0) !== '/' && path.substring(0, 2) !== '{/'
|
|
29
|
-
? '/' + path
|
|
30
|
-
: path
|
|
31
|
-
: ''
|
|
32
|
-
|
|
33
|
-
export const normalizePath = (path?: string): string =>
|
|
34
|
-
path
|
|
35
|
-
? path.startsWith('/')
|
|
36
|
-
? ('/' + path.replace(/\/+$/, '')).replace(/\/+/g, '/')
|
|
37
|
-
: '/' + path.replace(/\/+$/, '')
|
|
38
|
-
: '/'
|
|
39
|
-
|
|
40
|
-
export const stripEndSlash = (path: string) =>
|
|
41
|
-
path[path.length - 1] === '/' ? path.slice(0, path.length - 1) : path
|
|
42
|
-
|
|
43
|
-
export const isFunction = (val: any): val is Function =>
|
|
44
|
-
typeof val === 'function'
|
|
45
|
-
export const isString = (val: any): val is string => typeof val === 'string'
|
|
46
|
-
export const isNumber = (val: any): val is number => typeof val === 'number'
|
|
47
|
-
export const isConstructor = (val: any): boolean => val === 'constructor'
|
|
48
|
-
export const isNil = (val: any): val is null | undefined =>
|
|
49
|
-
isUndefined(val) || val === null
|
|
50
|
-
export const isEmpty = (array: any): boolean => !(array && array.length > 0)
|
|
51
|
-
export const isSymbol = (val: any): val is symbol => typeof val === 'symbol'
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ClassType,
|
|
3
|
-
ClassTypeWithInstance,
|
|
4
|
-
InjectionToken,
|
|
5
|
-
} from '@navios/di'
|
|
6
|
-
|
|
7
|
-
import type { CanActivate } from '../interfaces/index.mjs'
|
|
8
|
-
import type { HandlerMetadata } from './handler.metadata.mjs'
|
|
9
|
-
|
|
10
|
-
import { getAllEndpointMetadata } from './handler.metadata.mjs'
|
|
11
|
-
|
|
12
|
-
export const ControllerMetadataKey = Symbol('ControllerMetadataKey')
|
|
13
|
-
|
|
14
|
-
export interface ControllerMetadata {
|
|
15
|
-
endpoints: Set<HandlerMetadata>
|
|
16
|
-
guards: Set<
|
|
17
|
-
ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>
|
|
18
|
-
>
|
|
19
|
-
customAttributes: Map<string | symbol, any>
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function getControllerMetadata(
|
|
23
|
-
target: ClassType,
|
|
24
|
-
context: ClassDecoratorContext,
|
|
25
|
-
): ControllerMetadata {
|
|
26
|
-
if (context.metadata) {
|
|
27
|
-
const metadata = context.metadata[ControllerMetadataKey] as
|
|
28
|
-
| ControllerMetadata
|
|
29
|
-
| undefined
|
|
30
|
-
if (metadata) {
|
|
31
|
-
return metadata
|
|
32
|
-
} else {
|
|
33
|
-
const endpointsMetadata = getAllEndpointMetadata(context)
|
|
34
|
-
const newMetadata: ControllerMetadata = {
|
|
35
|
-
endpoints: endpointsMetadata,
|
|
36
|
-
guards: new Set<
|
|
37
|
-
| ClassTypeWithInstance<CanActivate>
|
|
38
|
-
| InjectionToken<CanActivate, undefined>
|
|
39
|
-
>(),
|
|
40
|
-
customAttributes: new Map<string | symbol, any>(),
|
|
41
|
-
}
|
|
42
|
-
context.metadata[ControllerMetadataKey] = newMetadata
|
|
43
|
-
// @ts-expect-error We add a custom metadata key to the target
|
|
44
|
-
target[ControllerMetadataKey] = newMetadata
|
|
45
|
-
return newMetadata
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
throw new Error('[Navios] Wrong environment.')
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function extractControllerMetadata(
|
|
52
|
-
target: ClassType,
|
|
53
|
-
): ControllerMetadata {
|
|
54
|
-
// @ts-expect-error We add a custom metadata key to the target
|
|
55
|
-
const metadata = target[ControllerMetadataKey] as
|
|
56
|
-
| ControllerMetadata
|
|
57
|
-
| undefined
|
|
58
|
-
if (!metadata) {
|
|
59
|
-
throw new Error(
|
|
60
|
-
'[Navios] Controller metadata not found. Make sure to use @Controller decorator.',
|
|
61
|
-
)
|
|
62
|
-
}
|
|
63
|
-
return metadata
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export function hasControllerMetadata(target: ClassType): boolean {
|
|
67
|
-
// @ts-expect-error We add a custom metadata key to the target
|
|
68
|
-
const metadata = target[ControllerMetadataKey] as
|
|
69
|
-
| ControllerMetadata
|
|
70
|
-
| undefined
|
|
71
|
-
return !!metadata
|
|
72
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import type { HttpMethod } from '@navios/builder'
|
|
2
|
-
import type { ClassTypeWithInstance, InjectionToken } from '@navios/di'
|
|
3
|
-
|
|
4
|
-
import type {
|
|
5
|
-
AbstractHttpHandlerAdapterInterface,
|
|
6
|
-
CanActivate,
|
|
7
|
-
HttpHeader,
|
|
8
|
-
} from '../interfaces/index.mjs'
|
|
9
|
-
|
|
10
|
-
export const EndpointMetadataKey = Symbol('EndpointMetadataKey')
|
|
11
|
-
|
|
12
|
-
export interface HandlerMetadata<Config = null> {
|
|
13
|
-
classMethod: string
|
|
14
|
-
url: string
|
|
15
|
-
successStatusCode: number
|
|
16
|
-
adapterToken:
|
|
17
|
-
| InjectionToken<AbstractHttpHandlerAdapterInterface, undefined>
|
|
18
|
-
| ClassTypeWithInstance<AbstractHttpHandlerAdapterInterface>
|
|
19
|
-
| null
|
|
20
|
-
headers: Partial<Record<HttpHeader, number | string | string[] | undefined>>
|
|
21
|
-
httpMethod: HttpMethod
|
|
22
|
-
config: Config
|
|
23
|
-
guards: Set<
|
|
24
|
-
ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>
|
|
25
|
-
>
|
|
26
|
-
customAttributes: Map<string | symbol, any>
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function getAllEndpointMetadata(
|
|
30
|
-
context: ClassMethodDecoratorContext | ClassDecoratorContext,
|
|
31
|
-
): Set<HandlerMetadata<any>> {
|
|
32
|
-
if (context.metadata) {
|
|
33
|
-
const metadata = context.metadata[EndpointMetadataKey] as
|
|
34
|
-
| Set<HandlerMetadata>
|
|
35
|
-
| undefined
|
|
36
|
-
if (metadata) {
|
|
37
|
-
return metadata
|
|
38
|
-
} else {
|
|
39
|
-
context.metadata[EndpointMetadataKey] = new Set<HandlerMetadata<any>>()
|
|
40
|
-
return context.metadata[EndpointMetadataKey] as Set<HandlerMetadata<any>>
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
throw new Error('[Navios] Wrong environment.')
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function getEndpointMetadata<Config = any>(
|
|
47
|
-
target: Function,
|
|
48
|
-
context: ClassMethodDecoratorContext,
|
|
49
|
-
): HandlerMetadata<Config> {
|
|
50
|
-
if (context.metadata) {
|
|
51
|
-
const metadata = getAllEndpointMetadata(context)
|
|
52
|
-
if (metadata) {
|
|
53
|
-
const endpointMetadata = Array.from(metadata).find(
|
|
54
|
-
(item) => item.classMethod === target.name,
|
|
55
|
-
)
|
|
56
|
-
if (endpointMetadata) {
|
|
57
|
-
return endpointMetadata
|
|
58
|
-
} else {
|
|
59
|
-
const newMetadata: HandlerMetadata<Config> = {
|
|
60
|
-
classMethod: target.name,
|
|
61
|
-
url: '',
|
|
62
|
-
successStatusCode: 200,
|
|
63
|
-
adapterToken: null,
|
|
64
|
-
headers: {},
|
|
65
|
-
httpMethod: 'GET',
|
|
66
|
-
// @ts-expect-error We are using a generic type here
|
|
67
|
-
config: null,
|
|
68
|
-
guards: new Set<
|
|
69
|
-
| ClassTypeWithInstance<CanActivate>
|
|
70
|
-
| InjectionToken<CanActivate, undefined>
|
|
71
|
-
>(),
|
|
72
|
-
customAttributes: new Map<string | symbol, any>(),
|
|
73
|
-
}
|
|
74
|
-
metadata.add(newMetadata)
|
|
75
|
-
return newMetadata
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
throw new Error('[Navios] Wrong environment.')
|
|
80
|
-
}
|
package/src/metadata/index.mts
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ClassType,
|
|
3
|
-
ClassTypeWithInstance,
|
|
4
|
-
InjectionToken,
|
|
5
|
-
} from '@navios/di'
|
|
6
|
-
|
|
7
|
-
import type { CanActivate } from '../index.mjs'
|
|
8
|
-
|
|
9
|
-
export const ModuleMetadataKey = Symbol('ControllerMetadataKey')
|
|
10
|
-
|
|
11
|
-
export interface ModuleMetadata {
|
|
12
|
-
controllers: Set<ClassType>
|
|
13
|
-
imports: Set<ClassType>
|
|
14
|
-
guards: Set<
|
|
15
|
-
ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>
|
|
16
|
-
>
|
|
17
|
-
overrides: Set<ClassType>
|
|
18
|
-
customAttributes: Map<string | symbol, any>
|
|
19
|
-
/**
|
|
20
|
-
* Extensible entries for adapter-specific data.
|
|
21
|
-
* Adapters can store custom metadata using symbol keys.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```typescript
|
|
25
|
-
* const CommandEntryKey = Symbol('CommandEntryKey')
|
|
26
|
-
* metadata.customEntries.set(CommandEntryKey, new Set([Command1, Command2]))
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
customEntries: Map<symbol, unknown>
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function getModuleMetadata(
|
|
33
|
-
target: ClassType,
|
|
34
|
-
context: ClassDecoratorContext,
|
|
35
|
-
): ModuleMetadata {
|
|
36
|
-
if (context.metadata) {
|
|
37
|
-
const metadata = context.metadata[ModuleMetadataKey] as
|
|
38
|
-
| ModuleMetadata
|
|
39
|
-
| undefined
|
|
40
|
-
if (metadata) {
|
|
41
|
-
return metadata
|
|
42
|
-
} else {
|
|
43
|
-
const newMetadata: ModuleMetadata = {
|
|
44
|
-
controllers: new Set<ClassType>(),
|
|
45
|
-
imports: new Set<ClassType>(),
|
|
46
|
-
guards: new Set<
|
|
47
|
-
| ClassTypeWithInstance<CanActivate>
|
|
48
|
-
| InjectionToken<CanActivate, undefined>
|
|
49
|
-
>(),
|
|
50
|
-
overrides: new Set<ClassType>(),
|
|
51
|
-
customAttributes: new Map<string | symbol, any>(),
|
|
52
|
-
customEntries: new Map<symbol, unknown>(),
|
|
53
|
-
}
|
|
54
|
-
context.metadata[ModuleMetadataKey] = newMetadata
|
|
55
|
-
// @ts-expect-error We add a custom metadata key to the target
|
|
56
|
-
target[ModuleMetadataKey] = newMetadata
|
|
57
|
-
return newMetadata
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
throw new Error('[Navios] Wrong environment.')
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function extractModuleMetadata(target: ClassType): ModuleMetadata {
|
|
64
|
-
// @ts-expect-error We add a custom metadata key to the target
|
|
65
|
-
const metadata = target[ModuleMetadataKey] as ModuleMetadata | undefined
|
|
66
|
-
if (!metadata) {
|
|
67
|
-
throw new Error(
|
|
68
|
-
`[Navios] Module metadata not found for ${target.name}. Make sure to use @Module decorator.`,
|
|
69
|
-
)
|
|
70
|
-
}
|
|
71
|
-
return metadata
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export function hasModuleMetadata(target: ClassType): boolean {
|
|
75
|
-
// @ts-expect-error We add a custom metadata key to the target
|
|
76
|
-
return !!target[ModuleMetadataKey]
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Type-safe helper to get or create a custom entry in module metadata.
|
|
81
|
-
* Adapters use this to store their own metadata in modules.
|
|
82
|
-
*
|
|
83
|
-
* @param metadata - The module metadata object
|
|
84
|
-
* @param key - Symbol key for the custom entry
|
|
85
|
-
* @param defaultValue - Factory function to create default value if entry doesn't exist
|
|
86
|
-
* @returns The existing or newly created entry value
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* ```typescript
|
|
90
|
-
* const CommandEntryKey = Symbol('CommandEntryKey')
|
|
91
|
-
* const commands = getModuleCustomEntry<Set<ClassType>>(
|
|
92
|
-
* metadata,
|
|
93
|
-
* CommandEntryKey,
|
|
94
|
-
* () => new Set(),
|
|
95
|
-
* )
|
|
96
|
-
* commands.add(MyCommand)
|
|
97
|
-
* ```
|
|
98
|
-
*/
|
|
99
|
-
export function getModuleCustomEntry<T>(
|
|
100
|
-
metadata: ModuleMetadata,
|
|
101
|
-
key: symbol,
|
|
102
|
-
defaultValue: () => T,
|
|
103
|
-
): T {
|
|
104
|
-
if (!metadata.customEntries.has(key)) {
|
|
105
|
-
metadata.customEntries.set(key, defaultValue())
|
|
106
|
-
}
|
|
107
|
-
return metadata.customEntries.get(key) as T
|
|
108
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { ClassType } from '@navios/di'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Symbol used to identify Navios-managed classes (Controller, Module, MessageController, etc.).
|
|
5
|
-
* This allows AttributeFactory to work with any Navios-managed class type generically.
|
|
6
|
-
*/
|
|
7
|
-
export const NaviosManagedMetadataKey = Symbol('NaviosManagedMetadataKey')
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Interface for metadata that has custom attributes.
|
|
11
|
-
* Used by Navios-managed classes (Controller, Module, MessageController, etc.).
|
|
12
|
-
*/
|
|
13
|
-
export interface ManagedMetadata {
|
|
14
|
-
customAttributes: Map<string | symbol, any>
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Gets managed metadata from a class if it exists.
|
|
19
|
-
* This is a generic function that works with any Navios-managed class type.
|
|
20
|
-
*
|
|
21
|
-
* @param target - The class to check
|
|
22
|
-
* @returns The metadata with customAttributes, or null if not managed
|
|
23
|
-
*/
|
|
24
|
-
export function getManagedMetadata(target: ClassType): ManagedMetadata | null {
|
|
25
|
-
// @ts-expect-error - Checking for managed metadata key
|
|
26
|
-
if (target[NaviosManagedMetadataKey]) {
|
|
27
|
-
// @ts-expect-error - Accessing managed metadata
|
|
28
|
-
return target[NaviosManagedMetadataKey] as ManagedMetadata
|
|
29
|
-
}
|
|
30
|
-
return null
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Checks if a class is Navios-managed (has managed metadata).
|
|
35
|
-
*
|
|
36
|
-
* @param target - The class to check
|
|
37
|
-
* @returns true if the class is Navios-managed
|
|
38
|
-
*/
|
|
39
|
-
export function hasManagedMetadata(target: ClassType): boolean {
|
|
40
|
-
return getManagedMetadata(target) !== null
|
|
41
|
-
}
|
|
42
|
-
|