@navios/core 1.1.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 +53 -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 -4424
- 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-3LcTrbxz.d.mts +0 -3804
- package/lib/index-3LcTrbxz.d.mts.map +0 -1
- package/lib/index-B14SekVb.d.cts +0 -3804
- package/lib/index-B14SekVb.d.cts.map +0 -1
- package/lib/navios.factory-CUrO_p6K.cjs +0 -4538
- package/lib/navios.factory-CUrO_p6K.cjs.map +0 -1
- package/lib/navios.factory-DjUOOVVL.mjs +0 -4151
- package/lib/navios.factory-DjUOOVVL.mjs.map +0 -1
- package/lib/tokens-BEuBMGGX.cjs +0 -193
- package/lib/tokens-BEuBMGGX.cjs.map +0 -1
- package/lib/tokens-COyNGV1I.mjs +0 -97
- package/lib/tokens-COyNGV1I.mjs.map +0 -1
- package/lib/use-guards.decorator-DLmRl2CV.mjs +0 -336
- package/lib/use-guards.decorator-DLmRl2CV.mjs.map +0 -1
- package/lib/use-guards.decorator-DhumFTk3.cjs +0 -444
- package/lib/use-guards.decorator-DhumFTk3.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 -14
- package/src/interfaces/navios-module.mts +0 -28
- package/src/interfaces/plugin-context.mts +0 -104
- package/src/interfaces/plugin-stage.mts +0 -62
- package/src/interfaces/plugin.interface.mts +0 -119
- package/src/interfaces/staged-plugin.interface.mts +0 -209
- 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 -79
- package/src/metadata/handler.metadata.mts +0 -80
- package/src/metadata/index.mts +0 -4
- package/src/metadata/module.metadata.mts +0 -116
- package/src/metadata/navios-managed.metadata.mts +0 -42
- package/src/navios.application.mts +0 -678
- 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 -255
- 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/define-plugin.mts +0 -251
- package/src/utils/index.mts +0 -2
- 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,32 +0,0 @@
|
|
|
1
|
-
import type { ModuleMetadata } from '../metadata/index.mjs'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Base interface for all Navios adapters (HTTP, CLI, etc.).
|
|
5
|
-
*
|
|
6
|
-
* Adapters implement this interface to provide runtime-specific functionality.
|
|
7
|
-
* This interface defines the common lifecycle methods shared across all adapter types.
|
|
8
|
-
*/
|
|
9
|
-
export interface AbstractAdapterInterface {
|
|
10
|
-
/**
|
|
11
|
-
* Sets up the adapter with the provided options.
|
|
12
|
-
* Called during application initialization before modules are initialized.
|
|
13
|
-
*/
|
|
14
|
-
setupAdapter(options: unknown): Promise<void>
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Called after all modules are loaded.
|
|
18
|
-
* Adapters use this to register routes, commands, or other module-based functionality.
|
|
19
|
-
*/
|
|
20
|
-
onModulesInit(modules: Map<string, ModuleMetadata>): Promise<void>
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Signals that the adapter is ready to handle requests/commands.
|
|
24
|
-
* Called after onModulesInit completes.
|
|
25
|
-
*/
|
|
26
|
-
ready(): Promise<void>
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Disposes of the adapter and cleans up resources.
|
|
30
|
-
*/
|
|
31
|
-
dispose(): Promise<void>
|
|
32
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ControllerMetadata,
|
|
3
|
-
HandlerMetadata,
|
|
4
|
-
ModuleMetadata,
|
|
5
|
-
} from '../metadata/index.mjs'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Interface providing access to the execution context during request handling.
|
|
9
|
-
*
|
|
10
|
-
* The execution context provides access to metadata and request/reply objects
|
|
11
|
-
* for the current request. It is available in guards and can be injected into
|
|
12
|
-
* services if needed.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* @Injectable()
|
|
17
|
-
* export class AuthGuard implements CanActivate {
|
|
18
|
-
* async canActivate(context: AbstractExecutionContext): Promise<boolean> {
|
|
19
|
-
* const request = context.getRequest()
|
|
20
|
-
* const handler = context.getHandler()
|
|
21
|
-
* // Access request and handler metadata
|
|
22
|
-
* return true
|
|
23
|
-
* }
|
|
24
|
-
* }
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
export interface AbstractExecutionContext {
|
|
28
|
-
/**
|
|
29
|
-
* Gets the metadata for the module containing the current endpoint.
|
|
30
|
-
*/
|
|
31
|
-
getModule(): ModuleMetadata
|
|
32
|
-
/**
|
|
33
|
-
* Gets the metadata for the controller containing the current endpoint.
|
|
34
|
-
*/
|
|
35
|
-
getController(): ControllerMetadata
|
|
36
|
-
/**
|
|
37
|
-
* Gets the metadata for the current endpoint handler.
|
|
38
|
-
*/
|
|
39
|
-
getHandler(): HandlerMetadata
|
|
40
|
-
/**
|
|
41
|
-
* Gets the HTTP request object (adapter-specific).
|
|
42
|
-
*/
|
|
43
|
-
getRequest(): any
|
|
44
|
-
/**
|
|
45
|
-
* Gets the HTTP reply object (adapter-specific).
|
|
46
|
-
*/
|
|
47
|
-
getReply(): any
|
|
48
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import type { ModuleMetadata } from '../metadata/index.mjs'
|
|
2
|
-
import type { AbstractAdapterInterface } from './abstract-adapter.interface.mjs'
|
|
3
|
-
import type { HttpAdapterEnvironment } from './adapter-environment.interface.mjs'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Interface for HTTP adapters extending the base adapter interface.
|
|
7
|
-
*
|
|
8
|
-
* Adapters implement this interface to provide runtime-specific HTTP server
|
|
9
|
-
* functionality (Fastify, Bun, etc.).
|
|
10
|
-
*
|
|
11
|
-
* @typeParam Environment - The adapter environment providing type-safe access to
|
|
12
|
-
* server instance, CORS options, listen options, etc.
|
|
13
|
-
*/
|
|
14
|
-
export interface AbstractHttpAdapterInterface<
|
|
15
|
-
Environment extends HttpAdapterEnvironment = HttpAdapterEnvironment,
|
|
16
|
-
> extends AbstractAdapterInterface {
|
|
17
|
-
/**
|
|
18
|
-
* Sets up the adapter with the provided options.
|
|
19
|
-
* Called during application initialization before modules are initialized.
|
|
20
|
-
*/
|
|
21
|
-
setupAdapter(options: Environment['options']): Promise<void>
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Called after all modules are loaded to register routes.
|
|
25
|
-
*/
|
|
26
|
-
onModulesInit(modules: Map<string, ModuleMetadata>): Promise<void>
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Signals that the server is ready to accept requests.
|
|
30
|
-
*/
|
|
31
|
-
ready(): Promise<void>
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Disposes of the server and cleans up resources.
|
|
35
|
-
*/
|
|
36
|
-
dispose(): Promise<void>
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Returns the underlying HTTP server instance.
|
|
40
|
-
*/
|
|
41
|
-
getServer(): Environment['server']
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Sets a global prefix for all routes.
|
|
45
|
-
*/
|
|
46
|
-
setGlobalPrefix(prefix: string): void
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Gets the current global prefix.
|
|
50
|
-
* Returns empty string if no prefix is set.
|
|
51
|
-
*/
|
|
52
|
-
getGlobalPrefix(): string
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Enables CORS with the specified options.
|
|
56
|
-
*/
|
|
57
|
-
enableCors(options: Environment['corsOptions']): void
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Enables multipart form data handling.
|
|
61
|
-
*/
|
|
62
|
-
enableMultipart(options: Environment['multipartOptions']): void
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Starts the server and listens for incoming requests.
|
|
66
|
-
*/
|
|
67
|
-
listen(options: Environment['listenOptions']): Promise<string>
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Configures the adapter with additional options before init.
|
|
71
|
-
*
|
|
72
|
-
* This method allows setting adapter-specific configuration options
|
|
73
|
-
* before the server is initialized. Options set via configure() are
|
|
74
|
-
* merged with options passed to setupAdapter().
|
|
75
|
-
*
|
|
76
|
-
* Must be called before setupAdapter().
|
|
77
|
-
*/
|
|
78
|
-
configure(options: Partial<Environment['options']>): void
|
|
79
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import type { LogLevel } from '../logger/index.mjs'
|
|
2
|
-
|
|
3
|
-
interface ArrayOfValueOrArray<T> extends Array<ValueOrArray<T>> {}
|
|
4
|
-
|
|
5
|
-
type OriginType = string | boolean | RegExp
|
|
6
|
-
type ValueOrArray<T> = T | ArrayOfValueOrArray<T>
|
|
7
|
-
|
|
8
|
-
export interface AbstractHttpCorsOptions {
|
|
9
|
-
/**
|
|
10
|
-
* Configures the Access-Control-Allow-Origin CORS header.
|
|
11
|
-
*/
|
|
12
|
-
origin?: ValueOrArray<OriginType>
|
|
13
|
-
/**
|
|
14
|
-
* Configures the Access-Control-Allow-Credentials CORS header.
|
|
15
|
-
* Set to true to pass the header, otherwise it is omitted.
|
|
16
|
-
*/
|
|
17
|
-
credentials?: boolean
|
|
18
|
-
/**
|
|
19
|
-
* Configures the Access-Control-Expose-Headers CORS header.
|
|
20
|
-
* Expects a comma-delimited string (ex: 'Content-Range,X-Content-Range')
|
|
21
|
-
* or an array (ex: ['Content-Range', 'X-Content-Range']).
|
|
22
|
-
* If not specified, no custom headers are exposed.
|
|
23
|
-
*/
|
|
24
|
-
exposedHeaders?: string | string[]
|
|
25
|
-
/**
|
|
26
|
-
* Configures the Access-Control-Allow-Headers CORS header.
|
|
27
|
-
* Expects a comma-delimited string (ex: 'Content-Type,Authorization')
|
|
28
|
-
* or an array (ex: ['Content-Type', 'Authorization']). If not
|
|
29
|
-
* specified, defaults to reflecting the headers specified in the
|
|
30
|
-
* request's Access-Control-Request-Headers header.
|
|
31
|
-
*/
|
|
32
|
-
allowedHeaders?: string | string[]
|
|
33
|
-
/**
|
|
34
|
-
* Configures the Access-Control-Allow-Methods CORS header.
|
|
35
|
-
* Expects a comma-delimited string (ex: 'GET,PUT,POST') or an array (ex: ['GET', 'PUT', 'POST']).
|
|
36
|
-
*/
|
|
37
|
-
methods?: string | string[]
|
|
38
|
-
/**
|
|
39
|
-
* Configures the Access-Control-Max-Age CORS header.
|
|
40
|
-
* Set to an integer to pass the header, otherwise it is omitted.
|
|
41
|
-
*/
|
|
42
|
-
maxAge?: number
|
|
43
|
-
/**
|
|
44
|
-
* Configures the Cache-Control header for CORS preflight responses.
|
|
45
|
-
* Set to an integer to pass the header as `Cache-Control: max-age=${cacheControl}`,
|
|
46
|
-
* or set to a string to pass the header as `Cache-Control: ${cacheControl}` (fully define
|
|
47
|
-
* the header value), otherwise the header is omitted.
|
|
48
|
-
*/
|
|
49
|
-
cacheControl?: number | string
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Sets the Fastify log level specifically for the internal OPTIONS route
|
|
53
|
-
* used to handle CORS preflight requests. For example, setting this to `'silent'`
|
|
54
|
-
* will prevent these requests from being logged.
|
|
55
|
-
* Useful for reducing noise in application logs.
|
|
56
|
-
* Default: inherits Fastify's global log level.
|
|
57
|
-
*/
|
|
58
|
-
logLevel?: LogLevel
|
|
59
|
-
}
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import type { ClassType, ScopedContainer } from '@navios/di'
|
|
2
|
-
|
|
3
|
-
import type { HandlerMetadata } from '../metadata/index.mjs'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Static handler result - handler can be called without a scoped container.
|
|
7
|
-
* Used when the controller and all its dependencies are singletons.
|
|
8
|
-
*/
|
|
9
|
-
export type StaticHandler<TRequest = any, TReply = any> = {
|
|
10
|
-
isStatic: true
|
|
11
|
-
handler: (request: TRequest, reply: TReply) => Promise<any>
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Dynamic handler result - handler requires a scoped container for resolution.
|
|
16
|
-
* Used when the controller or its dependencies need per-request resolution.
|
|
17
|
-
*/
|
|
18
|
-
export type DynamicHandler<TRequest = any, TReply = any> = {
|
|
19
|
-
isStatic: false
|
|
20
|
-
handler: (
|
|
21
|
-
scoped: ScopedContainer,
|
|
22
|
-
request: TRequest,
|
|
23
|
-
reply: TReply,
|
|
24
|
-
) => Promise<any>
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Handler result returned by provideHandler.
|
|
29
|
-
* Can be either static (pre-resolved) or dynamic (needs scoped container).
|
|
30
|
-
*/
|
|
31
|
-
export type HandlerResult<TRequest = any, TReply = any> =
|
|
32
|
-
| StaticHandler<TRequest, TReply>
|
|
33
|
-
| DynamicHandler<TRequest, TReply>
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Function type for argument getters that extract data from requests.
|
|
37
|
-
* Each getter populates a target object with data from the request.
|
|
38
|
-
*/
|
|
39
|
-
export type ArgumentGetterFn<TRequest = any> = (
|
|
40
|
-
target: Record<string, any>,
|
|
41
|
-
request: TRequest,
|
|
42
|
-
) => void | Promise<void>
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Function type for formatting arguments from a request.
|
|
46
|
-
* Built from argument getters, optimized for sync/async handling.
|
|
47
|
-
*/
|
|
48
|
-
export type FormatArgumentsFn<TRequest = any> = (
|
|
49
|
-
request: TRequest,
|
|
50
|
-
) => Record<string, any> | Promise<Record<string, any>>
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Interface for HTTP handler adapter services.
|
|
54
|
-
*
|
|
55
|
-
* Adapters handle different types of HTTP requests (REST, streaming, multipart)
|
|
56
|
-
* and are responsible for:
|
|
57
|
-
* - Parsing and validating request data
|
|
58
|
-
* - Creating handler functions
|
|
59
|
-
* - Formatting responses
|
|
60
|
-
* - Providing schema information (for frameworks like Fastify)
|
|
61
|
-
*/
|
|
62
|
-
export interface AbstractHttpHandlerAdapterInterface<TRequest = any> {
|
|
63
|
-
/**
|
|
64
|
-
* Prepares argument getters for parsing request data.
|
|
65
|
-
*
|
|
66
|
-
* Creates functions that extract and validate data from the request,
|
|
67
|
-
* populating a target object with validated arguments.
|
|
68
|
-
*
|
|
69
|
-
* @param handlerMetadata - The handler metadata with schemas and configuration.
|
|
70
|
-
* @returns An array of getter functions that populate request arguments.
|
|
71
|
-
*/
|
|
72
|
-
prepareArguments?: (
|
|
73
|
-
handlerMetadata: HandlerMetadata<any>,
|
|
74
|
-
) => ArgumentGetterFn<TRequest>[]
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Builds a formatArguments function from argument getters.
|
|
78
|
-
*
|
|
79
|
-
* Automatically detects sync vs async getters and optimizes accordingly:
|
|
80
|
-
* - If all getters are sync: returns sync function (no Promise overhead)
|
|
81
|
-
* - If any getter is async: returns async function with Promise.all
|
|
82
|
-
* - If no getters: returns frozen empty object (zero allocation)
|
|
83
|
-
*
|
|
84
|
-
* This method is useful for composition-based adapters that need to
|
|
85
|
-
* build formatArguments without duplicating the optimization logic.
|
|
86
|
-
*
|
|
87
|
-
* @param getters - Array of argument getter functions
|
|
88
|
-
* @returns Function to format arguments from request
|
|
89
|
-
*/
|
|
90
|
-
buildFormatArguments?: (
|
|
91
|
-
getters: ArgumentGetterFn<TRequest>[],
|
|
92
|
-
) => FormatArgumentsFn<TRequest>
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Checks if the handler has any validation schemas defined.
|
|
96
|
-
*
|
|
97
|
-
* @param handlerMetadata - The handler metadata containing configuration.
|
|
98
|
-
* @returns `true` if the handler has any schemas (request, query, response).
|
|
99
|
-
*/
|
|
100
|
-
hasSchema?: (handlerMetadata: HandlerMetadata<any>) => boolean
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Provides schema information for the framework's validation system.
|
|
104
|
-
*
|
|
105
|
-
* For frameworks like Fastify, this returns route schema objects.
|
|
106
|
-
* For frameworks like Bun, this typically returns an empty object.
|
|
107
|
-
*
|
|
108
|
-
* @param handlerMetadata - The handler metadata containing configuration.
|
|
109
|
-
* @returns Schema information for framework registration.
|
|
110
|
-
*/
|
|
111
|
-
provideSchema?: (handlerMetadata: HandlerMetadata<any>) => Record<string, any>
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Creates a request handler function for the endpoint.
|
|
115
|
-
*
|
|
116
|
-
* This is the core method that generates the actual handler function
|
|
117
|
-
* that will be called when a request matches the endpoint.
|
|
118
|
-
*
|
|
119
|
-
* @param controller - The controller class containing the handler method.
|
|
120
|
-
* @param handlerMetadata - The handler metadata with configuration and schemas.
|
|
121
|
-
* @returns A handler result that is either static or dynamic.
|
|
122
|
-
*/
|
|
123
|
-
provideHandler: (
|
|
124
|
-
controller: ClassType,
|
|
125
|
-
handlerMetadata: HandlerMetadata<any>,
|
|
126
|
-
) => Promise<HandlerResult>
|
|
127
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import type { AbstractAdapterInterface } from './abstract-adapter.interface.mjs'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Base interface for adapter environments.
|
|
5
|
-
*
|
|
6
|
-
* All adapter environments extend this interface to provide
|
|
7
|
-
* type-safe access to adapter-specific configuration options.
|
|
8
|
-
*/
|
|
9
|
-
export interface AdapterEnvironment {
|
|
10
|
-
/**
|
|
11
|
-
* Adapter setup/configuration options type
|
|
12
|
-
*/
|
|
13
|
-
options: unknown
|
|
14
|
-
/**
|
|
15
|
-
* Adapter type
|
|
16
|
-
*/
|
|
17
|
-
adapter: AbstractAdapterInterface
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Environment interface for HTTP adapters.
|
|
22
|
-
*
|
|
23
|
-
* Each HTTP adapter (Fastify, Bun, etc.) implements this interface to provide
|
|
24
|
-
* type-safe access to HTTP-specific types throughout the application.
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```typescript
|
|
28
|
-
* // Using with a specific adapter
|
|
29
|
-
* import { FastifyEnvironment } from '@navios/adapter-fastify'
|
|
30
|
-
*
|
|
31
|
-
* const app = await NaviosFactory.create<FastifyEnvironment>(AppModule, {
|
|
32
|
-
* adapter: defineFastifyEnvironment(),
|
|
33
|
-
* })
|
|
34
|
-
*
|
|
35
|
-
* // All methods are now type-safe for Fastify
|
|
36
|
-
* app.configure({ trustProxy: true })
|
|
37
|
-
* app.enableCors({ origin: true }) // FastifyCorsOptions
|
|
38
|
-
* const server = app.getServer() // FastifyInstance
|
|
39
|
-
* await app.listen({ port: 3000 }) // FastifyListenOptions
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
export interface HttpAdapterEnvironment extends AdapterEnvironment {
|
|
43
|
-
/**
|
|
44
|
-
* The underlying HTTP server instance type (e.g., FastifyInstance, Bun.Server)
|
|
45
|
-
*/
|
|
46
|
-
server: unknown
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* CORS configuration options type
|
|
50
|
-
*/
|
|
51
|
-
corsOptions: unknown
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Multipart form data configuration options type
|
|
55
|
-
*/
|
|
56
|
-
multipartOptions: unknown
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Server listen options type (port, host, etc.)
|
|
60
|
-
*/
|
|
61
|
-
listenOptions: unknown
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Default environment with unknown types.
|
|
66
|
-
*
|
|
67
|
-
* Forces users to specify an Environment generic for type-safe adapter access.
|
|
68
|
-
* When no generic is provided to `NaviosApplication` or `NaviosFactory.create()`,
|
|
69
|
-
* this default is used, resulting in `unknown` types for all adapter-specific
|
|
70
|
-
* methods.
|
|
71
|
-
*/
|
|
72
|
-
export interface DefaultAdapterEnvironment extends AdapterEnvironment {
|
|
73
|
-
options: unknown
|
|
74
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { AbstractExecutionContext } from '../interfaces/index.mjs'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Interface that guards must implement to control access to endpoints.
|
|
5
|
-
*
|
|
6
|
-
* Guards are used for authentication, authorization, and request validation.
|
|
7
|
-
* They are executed before the endpoint handler and can prevent the request
|
|
8
|
-
* from proceeding by returning `false` or throwing an exception.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* @Injectable()
|
|
13
|
-
* export class AuthGuard implements CanActivate {
|
|
14
|
-
* async canActivate(context: AbstractExecutionContext): Promise<boolean> {
|
|
15
|
-
* const request = context.getRequest()
|
|
16
|
-
* const token = request.headers.authorization
|
|
17
|
-
*
|
|
18
|
-
* if (!token) {
|
|
19
|
-
* throw new UnauthorizedException('Authentication required')
|
|
20
|
-
* }
|
|
21
|
-
*
|
|
22
|
-
* // Validate token
|
|
23
|
-
* return true
|
|
24
|
-
* }
|
|
25
|
-
* }
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
export interface CanActivate {
|
|
29
|
-
/**
|
|
30
|
-
* Determines if the current request can proceed to the endpoint handler.
|
|
31
|
-
*
|
|
32
|
-
* @param executionContext - The execution context containing request, reply, and metadata
|
|
33
|
-
* @returns `true` if the request can proceed, `false` otherwise. Can also throw an exception.
|
|
34
|
-
*/
|
|
35
|
-
canActivate(
|
|
36
|
-
executionContext: AbstractExecutionContext,
|
|
37
|
-
): Promise<boolean> | boolean
|
|
38
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { OutgoingHttpHeaders } from 'http'
|
|
2
|
-
|
|
3
|
-
export type OmitIndexSignature<T> = {
|
|
4
|
-
[K in keyof T as string extends K
|
|
5
|
-
? never
|
|
6
|
-
: number extends K
|
|
7
|
-
? never
|
|
8
|
-
: K]: T[K]
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* HTTP header strings
|
|
13
|
-
* Use this type only for input values, not for output values.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
export type HttpHeader =
|
|
17
|
-
| keyof OmitIndexSignature<OutgoingHttpHeaders>
|
|
18
|
-
| (string & Record<never, never>)
|
package/src/interfaces/index.mts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export * from './abstract-adapter.interface.mjs'
|
|
2
|
-
export * from './abstract-execution-context.inteface.mjs'
|
|
3
|
-
export * from './adapter-environment.interface.mjs'
|
|
4
|
-
export * from './abstract-http-adapter.interface.mjs'
|
|
5
|
-
export * from './abstract-http-cors-options.interface.mjs'
|
|
6
|
-
export * from './abstract-http-handler-adapter.interface.mjs'
|
|
7
|
-
export * from './abstract-http-listen-options.interface.mjs'
|
|
8
|
-
export * from './can-activate.mjs'
|
|
9
|
-
export * from './http-header.mjs'
|
|
10
|
-
export * from './navios-module.mjs'
|
|
11
|
-
export * from './plugin-stage.mjs'
|
|
12
|
-
export * from './plugin-context.mjs'
|
|
13
|
-
export * from './staged-plugin.interface.mjs'
|
|
14
|
-
export * from './plugin.interface.mjs'
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Interface that all Navios modules must implement.
|
|
3
|
-
*
|
|
4
|
-
* Modules decorated with @Module() should implement this interface to receive
|
|
5
|
-
* lifecycle hooks.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* @Module({
|
|
10
|
-
* controllers: [UserController],
|
|
11
|
-
* })
|
|
12
|
-
* export class AppModule implements NaviosModule {
|
|
13
|
-
* async onModuleInit() {
|
|
14
|
-
* console.log('AppModule initialized')
|
|
15
|
-
* // Perform initialization logic
|
|
16
|
-
* }
|
|
17
|
-
* }
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export interface NaviosModule {
|
|
21
|
-
/**
|
|
22
|
-
* Optional lifecycle hook called after the module is initialized.
|
|
23
|
-
*
|
|
24
|
-
* This is called after all modules are loaded and the HTTP server is set up
|
|
25
|
-
* (if an adapter is configured), but before the server starts listening.
|
|
26
|
-
*/
|
|
27
|
-
onModuleInit?: () => Promise<void> | void
|
|
28
|
-
}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import type { Container } from '@navios/di'
|
|
2
|
-
|
|
3
|
-
import type { ModuleMetadata } from '../metadata/index.mjs'
|
|
4
|
-
import type { ModuleLoaderService } from '../services/module-loader.service.mjs'
|
|
5
|
-
import type { AbstractAdapterInterface } from './abstract-adapter.interface.mjs'
|
|
6
|
-
import type { PluginStage } from './plugin-stage.mjs'
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Container-only context available at early stages.
|
|
10
|
-
* Available at: pre:modules-traverse
|
|
11
|
-
*/
|
|
12
|
-
export interface ContainerOnlyContext {
|
|
13
|
-
/**
|
|
14
|
-
* The dependency injection container.
|
|
15
|
-
*/
|
|
16
|
-
container: Container
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Context with modules loaded.
|
|
21
|
-
* Available at: post:modules-traverse, pre:adapter-resolve
|
|
22
|
-
*/
|
|
23
|
-
export interface ModulesLoadedContext extends ContainerOnlyContext {
|
|
24
|
-
/**
|
|
25
|
-
* All loaded modules with their metadata.
|
|
26
|
-
* Keys are module class names, values are their metadata.
|
|
27
|
-
*/
|
|
28
|
-
modules: Map<string, ModuleMetadata>
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Module loader service for extending the module tree.
|
|
32
|
-
* Use `moduleLoader.extendModules()` to add controllers dynamically.
|
|
33
|
-
*/
|
|
34
|
-
moduleLoader: ModuleLoaderService
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Full context with adapter available.
|
|
39
|
-
* Available at: post:adapter-resolve and all later stages
|
|
40
|
-
*
|
|
41
|
-
* @typeParam TAdapter - The adapter type, defaults to AbstractAdapterInterface
|
|
42
|
-
*/
|
|
43
|
-
export interface FullPluginContext<
|
|
44
|
-
TAdapter extends AbstractAdapterInterface = AbstractAdapterInterface,
|
|
45
|
-
> extends ModulesLoadedContext {
|
|
46
|
-
/**
|
|
47
|
-
* The current adapter instance.
|
|
48
|
-
* Use type guards or cast to adapter-specific types for HTTP methods.
|
|
49
|
-
*/
|
|
50
|
-
adapter: TAdapter
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Maps each plugin stage to its available context type.
|
|
55
|
-
*
|
|
56
|
-
* @typeParam TAdapter - The adapter type for stages that have adapter access
|
|
57
|
-
*/
|
|
58
|
-
export interface PluginStageContextMap<
|
|
59
|
-
TAdapter extends AbstractAdapterInterface = AbstractAdapterInterface,
|
|
60
|
-
> {
|
|
61
|
-
'pre:modules-traverse': ContainerOnlyContext
|
|
62
|
-
'post:modules-traverse': ModulesLoadedContext
|
|
63
|
-
'pre:adapter-resolve': ModulesLoadedContext
|
|
64
|
-
'post:adapter-resolve': FullPluginContext<TAdapter>
|
|
65
|
-
'pre:adapter-setup': FullPluginContext<TAdapter>
|
|
66
|
-
'post:adapter-setup': FullPluginContext<TAdapter>
|
|
67
|
-
'pre:modules-init': FullPluginContext<TAdapter>
|
|
68
|
-
'post:modules-init': FullPluginContext<TAdapter>
|
|
69
|
-
'pre:ready': FullPluginContext<TAdapter>
|
|
70
|
-
'post:ready': FullPluginContext<TAdapter>
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Helper type to get the context type for a specific stage.
|
|
75
|
-
*
|
|
76
|
-
* @typeParam S - The plugin stage
|
|
77
|
-
* @typeParam TAdapter - The adapter type for stages that have adapter access
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
* ```typescript
|
|
81
|
-
* type MyContext = ContextForStage<'pre:adapter-resolve'>
|
|
82
|
-
* // MyContext is ModulesLoadedContext (no adapter)
|
|
83
|
-
*
|
|
84
|
-
* type FullContext = ContextForStage<'post:modules-init', BunApplicationService>
|
|
85
|
-
* // FullContext has typed adapter
|
|
86
|
-
* ```
|
|
87
|
-
*/
|
|
88
|
-
export type ContextForStage<
|
|
89
|
-
S extends PluginStage,
|
|
90
|
-
TAdapter extends AbstractAdapterInterface = AbstractAdapterInterface,
|
|
91
|
-
> = PluginStageContextMap<TAdapter>[S]
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Context provided to plugins during registration.
|
|
95
|
-
*
|
|
96
|
-
* @deprecated Use stage-specific context types (ContainerOnlyContext,
|
|
97
|
-
* ModulesLoadedContext, FullPluginContext) for better type safety.
|
|
98
|
-
* This is an alias for FullPluginContext for backward compatibility.
|
|
99
|
-
*
|
|
100
|
-
* @typeParam TAdapter - The adapter type, defaults to AbstractAdapterInterface
|
|
101
|
-
*/
|
|
102
|
-
export type PluginContext<
|
|
103
|
-
TAdapter extends AbstractAdapterInterface = AbstractAdapterInterface,
|
|
104
|
-
> = FullPluginContext<TAdapter>
|