@aponiajs/common
Public decorators, route parameters, schemas, contracts, providers, tokens, errors, and logger APIs.
@aponiajs/common is platform-neutral. It depends on reflect-metadata and
the @standard-schema/spec types.
Class and method decorators
| Export | Signature or purpose |
|---|---|
Module | (metadata: ModuleMetadata) => ClassDecorator |
Controller | (path?: string) => ClassDecorator |
Injectable | () => ClassDecorator |
Inject | (token: Token<unknown>) => ParameterDecorator |
Get | RouteDecoratorFactory |
Post | RouteDecoratorFactory |
Put | RouteDecoratorFactory |
Patch | RouteDecoratorFactory |
Delete | RouteDecoratorFactory |
Head | RouteDecoratorFactory |
Options | RouteDecoratorFactory |
Validation | (validator: RouteValidator) => ClassDecorator |
WebSocketGateway | (options?: string | WebSocketGatewayOptions) => ClassDecorator |
SubscribeMessage | (event: string) => MethodDecorator |
WebSocketServer | () => PropertyDecorator |
Every route decorator shares one factory type with three overloads:
interface RouteDecoratorFactory {
(path: string, schema: RouteSchema): RouteMethodDecorator;
(schema: RouteSchema): RouteMethodDecorator;
(path?: string): RouteMethodDecorator;
}RequestMethod is the union of the seven supported methods.
Metadata readers are also public:
getModuleMetadata()getControllerMetadata()getRouteMetadata()getConstructorDependencies()getRouteParameterMetadata()getValidationMetadata()getWebSocketGatewayMetadata()getWebSocketMessageMetadata()getWebSocketParameterMetadata()getWebSocketServerProperties()
Request parameter decorators
| Export | Injects |
|---|---|
Body(property?) | The validated request body. |
Query(property?) | The parsed query string. |
Param(property?) | Path parameters. |
Headers(property?) | Request headers. |
Cookie(property?) | Cookies, or one cookie's value. |
Ctx() | The whole platform request context. |
Req() | The native Request. |
Res() | The mutable response settings. |
Supporting exports are routeParameterKinds, RouteParameterKind, and
RouteParameterMetadata. The kinds are body, query, params, headers,
cookie, context, request, and set.
See request parameters.
Route schemas
interface RouteSchema {
readonly body?: RouteValidatorInput;
readonly query?: RouteValidatorInput;
readonly params?: RouteValidatorInput;
readonly headers?: RouteValidatorInput;
readonly cookie?: RouteValidatorInput;
readonly response?: RouteResponseSchema;
}
type RouteValidator = StandardSchemaV1 | NativeSchema;
type RouteValidatorInput = RouteValidator | ValidationModelClass;| Export | Purpose |
|---|---|
routeSchemaSlots | The six slot names as a readonly tuple. |
isStandardSchema(validator) | Narrow a validator to its Standard Schema form. |
isRouteResponseSchemaMap(schema) | Narrow a response schema to its status map form. |
resolveRouteValidator(input) | Return the validator behind a raw validator or model class. |
RouteSchemaSlot | Union of the slot names. |
NativeSchema | Structural contract for TypeBox and Elysia t. |
InferValidatorOutput<T> | Output type of either validator kind. |
RouteContext<TSchema> | Platform-neutral request context typed by a schema. |
RouteCookie<TValue> | One request cookie's value contract. |
RouteResponseSchema, RouteResponseSchemaMap | One success validator, or a status-keyed map. |
RouteResponseSettings | Mutable status, headers, and redirect. |
ValidationMetadata, ValidationModelClass, RouteValidatorInput | Validation-model contracts. |
RouteContext exposes body, query, params, headers, cookie,
request, path, and set. An undecorated class in a slot fails with
INVALID_VALIDATION_MODEL. See
route validation.
Module contracts
interface ModuleMetadata {
readonly imports?: readonly ModuleImport[];
readonly controllers?: readonly ClassToken<unknown>[];
readonly providers?: readonly ModuleProvider[];
readonly exports?: readonly Token<unknown>[];
}Public types include DynamicModule, ModuleClass, ModuleImport,
ModuleProvider, ControllerMetadata, RouteMetadata, RouteMethodDecorator,
and RequestMethod.
The low-level module API exports defineModule, ModuleDefinition, and
ModuleOptions. ControllerDefinition is the platform controller contract.
Provider helpers
| Export | Purpose |
|---|---|
provideValue(token, value) | Register a constant value. |
provideFactory(token, inject, factory) | Register a synchronous typed factory. |
provideClass(class, inject) | Register a class with explicit tokens. |
provideAlias(token, existing) | Resolve an existing provider under another token. |
Provider types are Provider, ValueProvider, FactoryProvider,
ClassProvider, AliasProvider, and ProviderScope. The only scope value is
currently "singleton".
Tokens
| Export | Purpose |
|---|---|
createToken<T>(description) | Create a fresh explicit token. |
tokenName(token) | Return a class name or token description for diagnostics. |
Public token types are InjectionToken, ClassToken, Constructor, Token,
TokenValue, and TokenValues.
WebSocket gateways
| Export | Injects or declares |
|---|---|
WebSocketGateway(options?) | The gateway class and its upgrade path, default /ws. |
SubscribeMessage(event) | The handler for one envelope event name. |
MessageBody(property?) | The envelope data value, or one property of it. |
ConnectedSocket() | The native platform socket wrapper. |
WebSocketServer() | A property assigned the native server before afterInit. |
Public types are WebSocketGatewayOptions, WebSocketGatewayMetadata,
WebSocketMessageMetadata, WebSocketParameterKind,
WebSocketParameterMetadata, WsResponse, and the OnGatewayInit,
OnGatewayConnection, and OnGatewayDisconnect lifecycle interfaces.
See WebSocket gateways.
Errors
AponiaError extends Error with:
readonly code: AponiaErrorCode;
readonly details: Readonly<Record<string, unknown>>;See Error codes.
Logging
Exports:
ConsoleLoggerLoggerConsoleLoggerOptionsLoggerServiceLogLevel
Logger extends ConsoleLogger with no additional behavior.
ConsoleLoggerOptions includes logLevels, timestamp, prefix, json,
colors, context, compact, and depth. ConsoleLogger also exposes
setContext(), resetContext(), and isLevelEnabled(level).