Legacy decorators
Navios is written for standard (TC39) decorators, and the rest of these docs assume them. A project that keeps TypeScript's experimentalDecorators option on, for example because another library in the same code base needs it, imports its decorators from the legacy-compat entry points instead.
Each legacy decorator adapts the legacy call signature and then calls the same implementation as the standard decorator of the same name. Behaviour and metadata are identical, so everything else on this site applies unchanged, and both kinds can be used in one application.
Entry points
@navios/server/legacy-compat re-exports everything in @navios/core/legacy-compat, and Injectable and Factory in both are the ones from @navios/di/legacy-compat. Server code imports them from @navios/server/legacy-compat; an application without HTTP imports them from @navios/core/legacy-compat.
Everything that is not a decorator is imported from the package's main entry as usual: handler, reply, inject, NaviosFactory, createContextKey, exceptions and types from @navios/server. @RequestValue() from @navios/server works under both decorator modes.
Controllers and modules
A controller is written the same way as with standard decorators. Only the import path of the decorators changes.
@Endpoint checks the method's parameters and return value against the declaration exactly as the standard decorator does. See Controllers and handlers.
handler() is not a decorator, so it is imported from @navios/server and works unchanged. A controller whose handlers are all handler() fields uses only class decorators from the legacy entry point.
Attributes
Create attributes with the AttributeFactory from the legacy entry point, so that calling one returns a legacy decorator:
Reading is the same as with the standard factory, for example AttributeFactory.has(Public, ctx.route) in a guard. See Attributes.
An attribute created with the standard AttributeFactory from @navios/server cannot be applied as a decorator in a legacy-decorator file. It can still be passed in options: @Controller({ attributes: [Public()] }), or handler(endpoint, { attributes: [Public()] }, fn).
Services and factories outside a server
Code that uses @navios/di without the server imports the two decorators from the DI entry point. inject, Container and the rest come from @navios/di.
Scheduled jobs
Everything else comes from @navios/schedule, and registration is as described in Scheduled jobs. A @Cron method may be synchronous or async.
Other packages
@navios/openapi/legacy-compatexports the documentation attributes (ApiTag,ApiOperation,ApiSummary,ApiDeprecated,ApiSecurity,ApiExclude,ApiStream) as legacy decorators, next toopenApiPlugin.@navios/otel/legacy-compatexportsTracedandTraceable.@Component()from@navios/adapter-xmlworks under both decorator modes from its main entry.@navios/jwthas no decorators.
Writing your own legacy decorator
legacy(decorator) turns a standard decorator of a class, a method or a field into one that takes the arguments of a legacy decorator. A library that ships a standard decorator can offer a legacy form with it:
createClassContext(target) and createMethodContext(target, propertyKey, descriptor) give the context object of a standard decorator alone.