import type { ModuleMetadata } from '@navios/core'; import type { Server } from 'bun'; import { Container } from '@navios/core'; import type { BunApplicationOptions, BunApplicationServiceInterface } from '../interfaces/application.interface.mjs'; import type { BunCorsOptions } from '../utils/cors.util.mjs'; /** * Bun HTTP adapter service implementation for Navios. * * This service provides the core HTTP server functionality for Navios applications * running on the Bun runtime. It handles server initialization, route registration, * request handling, and server lifecycle management. * * @example * ```ts * const app = await NaviosFactory.create(AppModule, { * adapter: defineBunEnvironment(), * }) * * app.configure({ development: true }) * await app.init() * await app.listen({ port: 3000, hostname: '0.0.0.0' }) * ``` * * @implements {BunApplicationServiceInterface} */ export declare class BunApplicationService implements BunApplicationServiceInterface { private logger; protected container: Container; private errorProducer; private server; private controllerAdapter; private globalPrefix; private routes; private serverOptions; private corsOptions; private configureOptions; /** * app.configure({ * development: process.env.NODE_ENV === 'development', * maxRequestBodySize: 1024 * 1024, // 1MB * }) * await app.init() * ``` */ setupAdapter(options: unknown): Promise; /** * Initializes the Bun server instance and registers it in the dependency injection container. * * This method is called automatically during the application initialization process. * It makes the server instance available for injection via `BunServerToken`. * * @throws {Error} If the server has not been created yet. */ initServer(): Promise; /** * Marks the server as ready. * * For Bun, the server is ready immediately upon creation, so this is a no-op. */ ready(): Promise; /** * Sets a global prefix for all routes. * * This prefix will be prepended to all registered route paths. Useful for * API versioning or organizing routes under a common path. * * @param prefix - The prefix to prepend to all routes (e.g., '/api/v1'). * Should start with a forward slash. * * @example * ```ts * app.setGlobalPrefix('/api/v1') * // All routes will be prefixed with /api/v1 * ``` */ setGlobalPrefix(prefix: string): void; /** * Gets the current global prefix for all routes. * * @returns The global prefix string, or empty string if no prefix is set. * * @example * ```ts * app.setGlobalPrefix('/api/v1') * console.log(app.getGlobalPrefix()) // '/api/v1' * ``` */ getGlobalPrefix(): string; /** * Gets the underlying Bun server instance. * * This allows direct access to the Bun server for advanced use cases, * such as WebSocket upgrades or custom middleware. * * @returns The Bun server instance. * @throws {Error} If the server has not been initialized yet. * * @example * ```ts * const server = app.getServer() * // Access Bun-specific server methods * ``` */ getServer(): Server; onModulesInit(modules: Map): Promise; /** * Fallback request handler for unmatched routes and CORS preflight. * * Handles: * - CORS preflight (OPTIONS) requests * - 404 responses for unmatched routes with CORS headers * * @param request - The incoming request * @returns A Response with appropriate status and CORS headers * @private */ private handleRequest; /** * Enables CORS (Cross-Origin Resource Sharing) support. * * Configures CORS headers for all routes. The options are applied when * handling requests. * * @param options - CORS configuration options. * * @example * ```ts * app.enableCors({ * origin: true, // Allow all origins * methods: ['GET', 'POST', 'PUT', 'DELETE'], * credentials: true, * }) * ``` */ enableCors(options: BunCorsOptions): void; /** * Enables multipart form data support. * * @param _options - Multipart options (not currently supported in Bun adapter). * @deprecated Multipart support is handled automatically by Bun's native FormData support. */ enableMultipart(): void; /** * Starts the Bun HTTP server and begins listening for incoming requests. * * This method creates and starts the Bun server with the configured routes * and options. The server will handle all registered routes and return 404 * for unmatched requests. * * @param options - Server listen options including port and hostname. * @returns A promise that resolves to a string in the format `hostname:port` * indicating where the server is listening. * * @example * ```ts * const address = await app.listen({ * port: 3000, * hostname: '0.0.0.0', * }) * console.log(`Server listening on ${address}`) * ``` */ listen(options: any): Promise; /** * Configures the adapter with additional options before initialization. * * Options set via configure() are merged with options passed to * setupAdapter(), with configure() options taking precedence. * Must be called before init(). * * @param options - Partial Bun server configuration options * * @example * ```ts * app.configure({ development: true }) * await app.init() * ``` */ configure(options: Partial): void; /** * Gracefully shuts down the Bun server. * * This method stops the server and cleans up resources. Should be called * during application shutdown to ensure proper cleanup. * * @example * ```ts * process.on('SIGTERM', async () => { * await app.dispose() * process.exit(0) * }) * ``` */ dispose(): Promise; } //# sourceMappingURL=application.service.d.mts.map