@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
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,103 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [2.0.0-alpha.0] - Unreleased
|
|
9
|
+
|
|
10
|
+
`@navios/core` is now the part of Navios that does not depend on HTTP. The HTTP framework it was in 1.x is `@navios/server`, which is built on this package and re-exports it. The changes to the HTTP framework itself are listed in the changelog of `@navios/server`.
|
|
11
|
+
|
|
12
|
+
### Breaking
|
|
13
|
+
|
|
14
|
+
- **The HTTP framework moved to `@navios/server`.** Controllers, `@Endpoint`, `handler()`, `RequestContext`, `HttpException` and the other errors, `reply()`, `NaviosFactory`, `NaviosApplication`, the adapter contract, SSE and request values are exported from `@navios/server`. An HTTP application replaces the import specifier `@navios/core` with `@navios/server`, including `@navios/core/testing`, `@navios/core/legacy-compat` and the `declare module` of `Register`.
|
|
15
|
+
- **`@navios/core/conformance` moved** to `@navios/server/conformance`.
|
|
16
|
+
- **`@navios/builder` is no longer a peer dependency.**
|
|
17
|
+
- **`Guard` and `Interceptor` are generic.** `Guard<Ctx>` and `Interceptor<Ctx, Result>` default to `ExecutionContext`, the context every transport provides. `@navios/server` exports the HTTP-typed versions under the same names.
|
|
18
|
+
- **`currentContext()` returns an `ExecutionContext`.** The one from `@navios/server` returns the `RequestContext`.
|
|
19
|
+
- **`@Module` knows `imports`, `providers`, `guards`, `interceptors` and `attributes`.** `prefix`, `controllers` and `requestValues` are added by `@navios/server`. `ModuleMetadata` keeps options of transports in `entries`.
|
|
20
|
+
- **`buildModuleGraph(roots)` takes no prefix** and returns nodes with `entries`, `importers`, `isRoot` and `disputed` in place of `prefix`, `controllers` and `requestValues`. It is exported from `@navios/core/transport`.
|
|
21
|
+
- **The plugin API has no HTTP members.** `adapter`, `encoder` and `mapError` are on the HTTP transport, `api.transport(httpTransport)`, and `onBootstrap` hooks receive no arguments.
|
|
22
|
+
- **`@navios/di` 2.0** has its own breaking changes: registries and priorities are removed, a singleton cannot depend on a request-scoped service, `container.beginRequest()` is `container.createScope()`. What applications use of it is re-exported by name.
|
|
23
|
+
- **Guards run before the interceptors of the module, the class and the handler.** Interceptors of the application stay outside the guards. `handlerChain` returns the two groups as `outer` and `inner`. Only `true` from a guard lets the handler run.
|
|
24
|
+
- **`provideConfig` returns an `InjectionToken<ConfigService<…>>`**, which can be replaced like any other token. `load` runs once per container, and at once when it is synchronous. `ConfigService` logs nothing and can be created with `new`. `ConfigServiceToken`, `ConfigServiceOptions`, `ConfigServiceOptionsSchema`, `PathImpl` and `PathImpl2` are removed. `get()` is never typed `undefined`, and `getOrThrow()` and `getOrDefault()` neither `undefined` nor `null`.
|
|
25
|
+
- **`envInt`** throws for a variable that is not an integer. It used to take `12abc` for 12 and to return `NaN` for `abc`.
|
|
26
|
+
- **The provider of a token is chosen by who provides it**: the application's container and options, plugins, modules, the default. A module wins over what it imports, and a module of the application over one that a plugin adds; two modules that provide different things for a token without one importing the other are an error where one of them would be used, and so is a provider that comes after its token was resolved. `providers` takes what `provide()` returns and refuses anything else.
|
|
27
|
+
- **Modules cannot import each other in a cycle**, and a class can be made a module once.
|
|
28
|
+
- **An application that fails to initialise or to start is closed**, its container included.
|
|
29
|
+
- **`enableShutdownHooks()` ends the process**: when everything the signal closes is closed, the process gets the signal again, or exits with its code when it is process 1. `{ exit: false }` turns that off. A signal during a `close()` waits for it.
|
|
30
|
+
- **The console logger** prints `log` and above when `NODE_ENV` is `production` and uses colours when stdout is a terminal. `setup()` changes the options it is given. With `json`, an error is an `error` object on the line of its message, with its own fields and the errors it holds. `filterLogLevels` throws for a level that does not exist; `isLogLevelEnabled` and `loggerOptionsSchema` are no longer exported.
|
|
31
|
+
- **`Logger` is transient**: every injection has its own instance.
|
|
32
|
+
- **`getModuleMetadata` and `hasModuleMetadata`** are exported from `@navios/core/transport`; `ModuleMetadataKey` is not exported.
|
|
33
|
+
|
|
34
|
+
### Added
|
|
35
|
+
|
|
36
|
+
- **`createApplication(AppModule, options)`** and `Application`: an application that hosts zero or more transports sharing one module graph, container, plugin set and lifecycle. `init()`, `start()`, `close()`, `transport(factory)`.
|
|
37
|
+
- **Transports.** `defineTransport` in `@navios/core/transport`, with the module graph, `describeHandlerClass`, `handlerChain`, `resolveChain`, `runChain` and `BasicExecutionContext` for transport authors.
|
|
38
|
+
- **`shutdownTimeout`** bounds every step of `close()`, each hook on its own. A step that takes longer is logged and left behind.
|
|
39
|
+
- **A plugin can provide the logger**, as can a module it adds. What is logged before all plugins are set up is written then.
|
|
40
|
+
- **`ExecutionContext`**, `HandlerInfo` and `ExecutionContextToken`: what a guard, an interceptor or a request-scoped service can rely on with any transport.
|
|
41
|
+
- **Open `@Module` options.** A transport package adds its own option by declaration merging. An option that no transport of the running application reads is ignored, so one module can serve several transports.
|
|
42
|
+
- **`@navios/core/testing`** with `fakeTransport`.
|
|
43
|
+
- **A warning when two copies of the package are loaded.**
|
|
44
|
+
|
|
45
|
+
### Fixed
|
|
46
|
+
|
|
47
|
+
- **`close()` called again while a shutdown is in flight** returns that shutdown instead of resolving at once. From something the shutdown waits for it resolves at once; from something `init()` or `start()` waits for it rejects, instead of waiting for itself, and closes afterwards. `start()` called from something `init()` waits for does the same.
|
|
48
|
+
- **Hooks run in dependency order**: `onApplicationBootstrap` for dependencies first, `onApplicationShutdown` for dependents first, once per object, and only for objects the container built that declare them.
|
|
49
|
+
- **What a destroy hook throws** goes to the application's logger.
|
|
50
|
+
- **A subclass inherits what decorators attached to its base class**, guards and endpoints included, with the decorators of `@navios/core/legacy-compat` as well, and from a module that `registerModule` made one.
|
|
51
|
+
- **A configuration that fails validation** is reported with the paths of what is wrong and without its values.
|
|
52
|
+
- **The console logger** prints an error that is passed without a context, and neither throws for what it is given nor prints nothing when it is created with `new`.
|
|
53
|
+
- **A `close()` that rejects after a signal** from `enableShutdownHooks()` is reported through the logger instead of becoming an unhandled rejection.
|
|
54
|
+
- **`providers` of a module are applied before anything is resolved**, so `@Module({ providers: [provide(LoggerOutput, …)] })` takes effect. Providers of modules that a plugin adds are applied after the plugins are set up.
|
|
55
|
+
- **`buildModuleGraph` visits a module once** however many paths reach it; diamond imports used to cost exponential time. Inherited guards and interceptors now always come before the module's own, and what a shared module inherits no longer depends on the path that reached it first. Import paths that give it different values of an attribute are an error where a handler would inherit the attribute.
|
|
56
|
+
- **An `undefined` entry in `imports`**, the usual sign of an import cycle between files, throws an error that names the importing module.
|
|
57
|
+
- **A plugin registered twice with different options**, and two plugins of one name, throw instead of dropping the second registration.
|
|
58
|
+
- **The second-copy warning** also covers copies loaded only through `@navios/core/transport`, `/testing` or `/legacy-compat`.
|
|
59
|
+
- **An `onFinish` callback that throws** is reported to the application's logger; it used to be dropped silently.
|
|
60
|
+
|
|
61
|
+
## [1.1.0] - 2026-01-15
|
|
62
|
+
|
|
63
|
+
### Added
|
|
64
|
+
|
|
65
|
+
- **Staged Plugin System**: New comprehensive plugin lifecycle with 10 stages for fine-grained control over application initialization
|
|
66
|
+
- `pre:modules-traverse` - Before module tree traversal (container only)
|
|
67
|
+
- `post:modules-traverse` - After module tree traversal (modules available)
|
|
68
|
+
- `pre:adapter-resolve` - Before adapter is resolved from container (ideal for DI modifications)
|
|
69
|
+
- `post:adapter-resolve` - After adapter is resolved
|
|
70
|
+
- `pre:adapter-setup` - Before adapter setup
|
|
71
|
+
- `post:adapter-setup` - After adapter setup
|
|
72
|
+
- `pre:modules-init` - Before route registration
|
|
73
|
+
- `post:modules-init` - After route registration (legacy plugin default)
|
|
74
|
+
- `pre:ready` - Before adapter signals ready
|
|
75
|
+
- `post:ready` - After adapter signals ready (app fully initialized)
|
|
76
|
+
- **Stage-Specific Context Types**: Each stage provides appropriate context
|
|
77
|
+
- `ContainerOnlyContext` - Container access only (early stages)
|
|
78
|
+
- `ModulesLoadedContext` - Container + modules + moduleLoader (pre-adapter stages)
|
|
79
|
+
- `FullPluginContext<TAdapter>` - Full context with typed adapter (post-adapter stages)
|
|
80
|
+
- **Plugin Factory Functions**: Convenient factory functions for creating staged plugins
|
|
81
|
+
- `definePreModulesTraversePlugin()` - Create pre:modules-traverse plugins
|
|
82
|
+
- `definePostModulesTraversePlugin()` - Create post:modules-traverse plugins
|
|
83
|
+
- `definePreAdapterResolvePlugin()` - Create pre:adapter-resolve plugins (ideal for instrumentation)
|
|
84
|
+
- `definePostAdapterResolvePlugin<TAdapter>()()` - Create post:adapter-resolve plugins
|
|
85
|
+
- `definePreAdapterSetupPlugin<TAdapter>()()` - Create pre:adapter-setup plugins
|
|
86
|
+
- `definePostAdapterSetupPlugin<TAdapter>()()` - Create post:adapter-setup plugins
|
|
87
|
+
- `definePreModulesInitPlugin<TAdapter>()()` - Create pre:modules-init plugins
|
|
88
|
+
- `definePostModulesInitPlugin<TAdapter>()()` - Create post:modules-init plugins
|
|
89
|
+
- `definePreReadyPlugin<TAdapter>()()` - Create pre:ready plugins
|
|
90
|
+
- `definePostReadyPlugin<TAdapter>()()` - Create post:ready plugins
|
|
91
|
+
- **Plugin Stage Constants**: `PluginStages` object with all stage names as constants
|
|
92
|
+
- **Stage Order Array**: `PLUGIN_STAGES_ORDER` array defining execution order
|
|
93
|
+
|
|
94
|
+
### Changed
|
|
95
|
+
|
|
96
|
+
- **Legacy Plugin Deprecation**: `NaviosPlugin` interface now deprecated in favor of staged plugins
|
|
97
|
+
- Legacy plugins automatically map to `post:modules-init` stage
|
|
98
|
+
- `PluginDefinition` type deprecated in favor of `StagedPluginDefinition`
|
|
99
|
+
- **Plugin Context Types**: `PluginContext` type deprecated, use stage-specific context types instead
|
|
100
|
+
|
|
101
|
+
### Dependencies
|
|
102
|
+
|
|
103
|
+
- Updated internal plugin execution to support staged lifecycle
|
|
104
|
+
|
|
8
105
|
## [1.0.0] - 2026-01-09
|
|
9
106
|
|
|
10
107
|
### Added
|
|
@@ -362,14 +459,3 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
362
459
|
- `@navios/di` - Dependency injection container
|
|
363
460
|
- `@navios/builder` (peer dependency) - Type-safe API definitions
|
|
364
461
|
- `zod` (peer dependency) - Schema validation
|
|
365
|
-
|
|
366
|
-
---
|
|
367
|
-
|
|
368
|
-
## [Unreleased]
|
|
369
|
-
|
|
370
|
-
### Planned
|
|
371
|
-
|
|
372
|
-
- Additional adapter implementations
|
|
373
|
-
- Enhanced middleware support
|
|
374
|
-
- WebSocket support
|
|
375
|
-
- Performance optimizations
|
package/README.md
CHANGED
|
@@ -1,261 +1,108 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @navios/core
|
|
2
2
|
|
|
3
|
-
Navios is a
|
|
3
|
+
What a Navios application is made of, whatever reaches it: dependency injection, modules, plugins, lifecycle hooks, configuration and logging, and the contracts a transport builds on. It has no HTTP in it.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
- An HTTP server is [`@navios/server`](https://www.npmjs.com/package/@navios/server), which is built on this package and re-exports it. Install that one for a web application.
|
|
6
|
+
- This package alone runs a worker: a process that consumes a queue, runs scheduled jobs, or both.
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
**[Documentation](https://navios.tech/docs/server/guides/other-transports)**
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
- **Bun** (via `@navios/adapter-bun`) - A fast JavaScript runtime optimized for server-side applications
|
|
11
|
-
|
|
12
|
-
## Prerequisites
|
|
13
|
-
|
|
14
|
-
To work as an HTTP server, you must install one of the supported adapters:
|
|
10
|
+
## Install
|
|
15
11
|
|
|
16
12
|
```bash
|
|
17
|
-
|
|
18
|
-
npm install @navios/adapter-fastify
|
|
19
|
-
|
|
20
|
-
# OR for Bun adapter
|
|
21
|
-
npm install @navios/adapter-bun
|
|
13
|
+
npm install @navios/core@next
|
|
22
14
|
```
|
|
23
15
|
|
|
24
|
-
The
|
|
25
|
-
|
|
26
|
-
## Features
|
|
27
|
-
|
|
28
|
-
- **Type Safety**: Navios provides a type-safe API for defining endpoints, request and response schemas. This ensures that your API is always type-safe and reduces the risk of runtime errors.
|
|
29
|
-
- **Validation**: Zod provides powerful validation capabilities, allowing you to define complex validation rules for your data. This ensures that the data you work with is always valid and meets your requirements.
|
|
30
|
-
- **Build with Navios Builder**: Navios Builder is a powerful HTTP client that simplifies API requests. By combining it with Navios, you can use the same API definition for both the client and server, ensuring consistency and reducing duplication.
|
|
31
|
-
- **Declarative API**: The API is designed to be declarative, allowing you to define your API endpoints and their schemas in a clear and concise manner. This makes it easy to understand and maintain your API client.
|
|
32
|
-
- **Customizable**: The package allows you to customize the behavior of the API client, such as using a custom client.
|
|
33
|
-
- **Error Handling**: The package provides built-in error handling capabilities with RFC 7807 Problem Details format for standardized error responses. Includes customizable error responders and comprehensive exception handling.
|
|
16
|
+
The 2.0 alpha is published under the `next` tag. All `@navios` packages of a project must have the same alpha version, because an alpha may break between releases.
|
|
34
17
|
|
|
35
|
-
|
|
18
|
+
Navios uses standard (TC39) decorators, so leave `experimentalDecorators` off. A project that has to keep it on imports from `@navios/core/legacy-compat`.
|
|
36
19
|
|
|
37
|
-
|
|
20
|
+
## Example
|
|
38
21
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
#### Fastify Adapter (`@navios/adapter-fastify`)
|
|
42
|
-
|
|
43
|
-
- Built on top of [Fastify](https://www.fastify.io/), a fast and low-overhead web framework
|
|
44
|
-
- Excellent performance and a rich ecosystem of plugins
|
|
45
|
-
- Full Node.js compatibility
|
|
46
|
-
- Supports all Fastify features including hooks, plugins, and decorators
|
|
22
|
+
A worker that runs scheduled jobs, with [`@navios/schedule`](https://www.npmjs.com/package/@navios/schedule):
|
|
47
23
|
|
|
48
24
|
```ts
|
|
49
|
-
import {
|
|
50
|
-
|
|
51
|
-
const app = await NaviosFactory.create(AppModule, {
|
|
52
|
-
adapter: defineFastifyEnvironment(),
|
|
53
|
-
})
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
#### Bun Adapter (`@navios/adapter-bun`)
|
|
57
|
-
|
|
58
|
-
- Built for [Bun](https://bun.sh/), a fast JavaScript runtime optimized for performance
|
|
59
|
-
- Native HTTP server implementation with excellent performance
|
|
60
|
-
- Optimized for Bun's runtime features
|
|
61
|
-
- Lightweight and efficient
|
|
62
|
-
|
|
63
|
-
```ts
|
|
64
|
-
import { defineBunEnvironment } from '@navios/adapter-bun'
|
|
65
|
-
|
|
66
|
-
const app = await NaviosFactory.create(AppModule, {
|
|
67
|
-
adapter: defineBunEnvironment(),
|
|
68
|
-
})
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
### Choosing an Adapter
|
|
72
|
-
|
|
73
|
-
The choice of adapter depends on your deployment environment and performance requirements:
|
|
74
|
-
|
|
75
|
-
- Use **Fastify adapter** if you need Node.js compatibility, access to the Fastify ecosystem, or are deploying to traditional Node.js environments
|
|
76
|
-
- Use **Bun adapter** if you're running on Bun runtime and want to take advantage of its performance optimizations
|
|
77
|
-
|
|
78
|
-
## Main Concepts
|
|
79
|
-
|
|
80
|
-
- **Module**: A module is a collection of controllers, and other modules. It is used to group related functionality together and provide a clear structure for your API. It also can define some shared guards, attributes, and service overrides.
|
|
81
|
-
- **Controller**: A controller is a class that defines a set of endpoints for a specific resource. It is used to handle incoming requests and return responses. Controllers can also define guards and attributes that apply to all endpoints in the controller.
|
|
82
|
-
- **Endpoint**: An endpoint is a specific route in your API that handles a specific request. It used original endpoint definition from Navios Builder, and a set of request and response schemas. Endpoints can also define guards and attributes that apply to the endpoint.
|
|
83
|
-
- **Service**: A service is a class that defines the business logic for a specific resource. It is used to separate the business logic from the controller and provide a clear structure for your API.
|
|
84
|
-
- **Guard**: A guard is a class that is used to validate incoming requests and ensure that they meet certain criteria. Guards can be used to validate request parameters, headers, and body. They can also be used to check authentication and authorization.
|
|
85
|
-
- **Attribute**: An attribute is a decorator that is used to add metadata to a class or method. Attributes can be used in guards, controllers, modules, and endpoints to provide additional information about the class or method.
|
|
86
|
-
|
|
87
|
-
## Legacy-Compatible Decorators
|
|
88
|
-
|
|
89
|
-
Navios provides legacy-compatible decorators for projects that use TypeScript's experimental decorator API. These decorators are available from `@navios/core/legacy-compat` and provide the same functionality as the standard decorators, but with compatibility for projects that cannot use Stage 3 decorators.
|
|
90
|
-
|
|
91
|
-
```ts
|
|
92
|
-
import { Controller, Endpoint, Module } from '@navios/core/legacy-compat'
|
|
93
|
-
|
|
94
|
-
@Module({
|
|
95
|
-
controllers: [UserController],
|
|
96
|
-
})
|
|
97
|
-
export class AppModule {}
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
For more information, see the [Legacy-Compatible Decorators documentation](./docs/legacy-compat.md).
|
|
101
|
-
|
|
102
|
-
## Getting Started
|
|
103
|
-
|
|
104
|
-
### Define your API
|
|
105
|
-
|
|
106
|
-
Define your API in a shared location accessible to both the client and server. This allows you to use the same API definition for both the client and server, ensuring consistency and reducing duplication.
|
|
107
|
-
|
|
108
|
-
```ts
|
|
109
|
-
import { builder } from '@navios/builder'
|
|
110
|
-
|
|
111
|
-
import { z } from 'zod/v4'
|
|
112
|
-
|
|
113
|
-
const api = builder({
|
|
114
|
-
useDiscriminatorResponse: true,
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
const login = api.declareEndpoint({
|
|
118
|
-
method: 'post',
|
|
119
|
-
url: '/login',
|
|
120
|
-
requestSchema: z.object({
|
|
121
|
-
email: z.string().email(),
|
|
122
|
-
password: z.string().min(6),
|
|
123
|
-
}),
|
|
124
|
-
responseSchema: z.discriminatedUnion('success', [
|
|
125
|
-
z.object({
|
|
126
|
-
success: z.literal(true),
|
|
127
|
-
user: z.object({
|
|
128
|
-
id: z.string(),
|
|
129
|
-
name: z.string(),
|
|
130
|
-
email: z.string().email(),
|
|
131
|
-
}),
|
|
132
|
-
}),
|
|
133
|
-
z.object({
|
|
134
|
-
success: z.literal(false),
|
|
135
|
-
error: z.string(),
|
|
136
|
-
}),
|
|
137
|
-
]),
|
|
138
|
-
})
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
### Create your server
|
|
142
|
-
|
|
143
|
-
```bash
|
|
144
|
-
# Install core dependencies
|
|
145
|
-
yarn install --save @navios/core @navios/builder zod
|
|
146
|
-
|
|
147
|
-
# Install one of the supported adapters
|
|
148
|
-
yarn install --save @navios/adapter-fastify
|
|
149
|
-
# OR
|
|
150
|
-
yarn install --save @navios/adapter-bun
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
Create AuthService:
|
|
154
|
-
|
|
155
|
-
```ts
|
|
156
|
-
import { Injectable } from '@navios/core'
|
|
25
|
+
import { createApplication, inject, Injectable, Logger, Module } from '@navios/core'
|
|
26
|
+
import { Cron, Schedulable, Schedule, scheduleTransport } from '@navios/schedule'
|
|
157
27
|
|
|
158
28
|
@Injectable()
|
|
159
|
-
|
|
160
|
-
async
|
|
161
|
-
|
|
162
|
-
// For example, check the email and password against a database
|
|
29
|
+
class SessionsService {
|
|
30
|
+
async deleteExpired() {
|
|
31
|
+
return 0
|
|
163
32
|
}
|
|
164
33
|
}
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
Create your first Controller:
|
|
168
|
-
|
|
169
|
-
```ts
|
|
170
|
-
import type { EndpointParams } from '@navios/core'
|
|
171
34
|
|
|
172
|
-
|
|
35
|
+
@Schedulable()
|
|
36
|
+
class MaintenanceJobs {
|
|
37
|
+
private readonly sessions = inject(SessionsService)
|
|
38
|
+
private readonly logger = inject(Logger, { context: 'MaintenanceJobs' })
|
|
173
39
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
loginService = inject(LoginService)
|
|
40
|
+
@Cron(Schedule.EveryHour)
|
|
41
|
+
async purgeSessions() {
|
|
42
|
+
this.logger.log(`Removed ${await this.sessions.deleteExpired()} expired sessions`)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
180
45
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
// Handle the login request
|
|
184
|
-
const { email, password } = request
|
|
46
|
+
@Module({ jobs: [MaintenanceJobs] })
|
|
47
|
+
class WorkerModule {}
|
|
185
48
|
|
|
186
|
-
|
|
187
|
-
|
|
49
|
+
const app = createApplication(WorkerModule, {
|
|
50
|
+
transports: [scheduleTransport()],
|
|
51
|
+
})
|
|
52
|
+
app.enableShutdownHooks()
|
|
188
53
|
|
|
189
|
-
|
|
190
|
-
return { success: true, user }
|
|
191
|
-
} else {
|
|
192
|
-
return { success: false, error: 'Invalid credentials' }
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
54
|
+
await app.start()
|
|
196
55
|
```
|
|
197
56
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
```ts
|
|
201
|
-
import { Module } from '@navios/core'
|
|
57
|
+
## Transports
|
|
202
58
|
|
|
203
|
-
|
|
59
|
+
An application hosts zero or more transports: the ways work reaches it. They share its modules, its container, its plugins and its lifecycle.
|
|
204
60
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
// overrides: [OverrideService],
|
|
61
|
+
```ts
|
|
62
|
+
const app = createApplication(AppModule, {
|
|
63
|
+
transports: [messageTransport()], // from @navios/microservice
|
|
209
64
|
})
|
|
210
|
-
export class AppModule {}
|
|
211
65
|
```
|
|
212
66
|
|
|
213
|
-
|
|
67
|
+
| Transport | Package | `@Module` option |
|
|
68
|
+
| --------- | ---------------------------------------------------------------------------- | -------------------- |
|
|
69
|
+
| HTTP | [`@navios/server`](https://www.npmjs.com/package/@navios/server) | `controllers` |
|
|
70
|
+
| Messages | [`@navios/microservice`](https://www.npmjs.com/package/@navios/microservice) | `messageControllers` |
|
|
71
|
+
| Cron jobs | [`@navios/schedule`](https://www.npmjs.com/package/@navios/schedule) | `jobs` |
|
|
214
72
|
|
|
215
|
-
|
|
216
|
-
// Import your chosen adapter
|
|
217
|
-
import { defineFastifyEnvironment } from '@navios/adapter-fastify'
|
|
218
|
-
import { NaviosFactory } from '@navios/core'
|
|
73
|
+
A module lists what it has for each transport, and an application ignores the options of transports it does not have, so one module can serve several.
|
|
219
74
|
|
|
220
|
-
|
|
75
|
+
## What it contains
|
|
221
76
|
|
|
222
|
-
|
|
77
|
+
| Need | How |
|
|
78
|
+
| ----------------------------------------- | ---------------------------------------------------------------------------- |
|
|
79
|
+
| Services and their scopes | `@Injectable()`, `inject()`, `provide()` and the rest of `@navios/di` |
|
|
80
|
+
| Grouping, shared guards and attributes | `@Module()` |
|
|
81
|
+
| The application and its lifecycle | `createApplication`, `init()`, `start()`, `close()` |
|
|
82
|
+
| Hooks | `onModuleInit`, `onApplicationBootstrap`, `onApplicationShutdown` |
|
|
83
|
+
| Reusable setup | `definePlugin` |
|
|
84
|
+
| Guards and interceptors for any transport | `Guard`, `Interceptor`, `ExecutionContext`, `@UseGuards`, `@UseInterceptors` |
|
|
85
|
+
| Per-execution data | `createContextKey`, `currentContext()` |
|
|
86
|
+
| Metadata on modules and handlers | `AttributeFactory` |
|
|
87
|
+
| Typed configuration, logging | `provideConfig`, `Logger` |
|
|
223
88
|
|
|
224
|
-
|
|
225
|
-
const app = await NaviosFactory.create(AppModule, {
|
|
226
|
-
// Provide the adapter environment
|
|
227
|
-
adapter: defineFastifyEnvironment(),
|
|
228
|
-
// OR adapter: defineBunEnvironment(),
|
|
229
|
-
})
|
|
230
|
-
app.setGlobalPrefix('/api')
|
|
231
|
-
app.enableCors({
|
|
232
|
-
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'],
|
|
233
|
-
})
|
|
234
|
-
await app.init()
|
|
235
|
-
await app.listen({ port: 3000, host: '0.0.0.0' })
|
|
236
|
-
}
|
|
237
|
-
await boot()
|
|
238
|
-
```
|
|
89
|
+
## Entry points
|
|
239
90
|
|
|
240
|
-
|
|
91
|
+
| Import | Contents |
|
|
92
|
+
| ---------------------------- | ----------------------------------------------------------------------------------------------- |
|
|
93
|
+
| `@navios/core` | The above, with what applications use of `@navios/di`. |
|
|
94
|
+
| `@navios/core/transport` | For transport authors: the contract, the module graph, handler chains, `BasicExecutionContext`. |
|
|
95
|
+
| `@navios/core/testing` | `fakeTransport`, a transport for tests of plugins and of the application lifecycle. |
|
|
96
|
+
| `@navios/core/legacy-compat` | Decorators for `experimentalDecorators` projects. |
|
|
241
97
|
|
|
242
|
-
##
|
|
98
|
+
## One copy
|
|
243
99
|
|
|
244
|
-
|
|
245
|
-
- **[Complete Documentation](./docs/README.md)** - Comprehensive framework documentation
|
|
246
|
-
- **[Adapter Guide](./docs/adapters.md)** - Detailed adapter information and comparison
|
|
247
|
-
- **[Legacy-Compatible Decorators](./docs/legacy-compat.md)** - Using Navios with TypeScript experimental decorators
|
|
248
|
-
- **[API Examples](https://github.com/Arilas/navios/tree/main/examples)** - Working code examples
|
|
249
|
-
- **[CHANGELOG](./CHANGELOG.md)** - Version history and release notes
|
|
100
|
+
Every package of an application has to resolve the same `@navios/core`. `@navios/server` depends on it; adapters, plugins and other transports list it as a peer dependency. If two copies are loaded, a warning names both locations. Two copies that a bundler put into one file are not noticed.
|
|
250
101
|
|
|
251
|
-
##
|
|
102
|
+
## Upgrading from 1.x
|
|
252
103
|
|
|
253
|
-
|
|
254
|
-
- **[@navios/adapter-bun](https://www.npmjs.com/package/@navios/adapter-bun)** - Bun HTTP adapter
|
|
255
|
-
- **[@navios/builder](https://www.npmjs.com/package/@navios/builder)** - Type-safe API definitions
|
|
256
|
-
- **[@navios/di](https://www.npmjs.com/package/@navios/di)** - Dependency injection container
|
|
257
|
-
- **[@navios/jwt](https://www.npmjs.com/package/@navios/jwt)** - JWT authentication utilities
|
|
104
|
+
In 1.x this package was the HTTP framework. That is now `@navios/server`: replace the import specifier `@navios/core` with `@navios/server`, and see [Migrating to 2.0](https://navios.tech/docs/server/reference/migrating-to-2). [CHANGELOG.md](./CHANGELOG.md) has the full list.
|
|
258
105
|
|
|
259
106
|
## License
|
|
260
107
|
|
|
261
|
-
MIT
|
|
108
|
+
MIT. The console logger is ported from [NestJS](https://github.com/nestjs/nest) (MIT). Big thanks to the NestJS team for their work.
|