import { Container } from '@adonisjs/fold'; import Macroable from '@poppinss/macroable'; import type { HookHandler } from '@poppinss/hooks/types'; import type { Importer, SemverNode, AppEnvironments, ApplicationStates, ExperimentalFlagsList } from './types.ts'; import { FeatureFlags } from './feature_flags.ts'; /** * Application class manages the state of an AdonisJS application. It includes: * * - Setting up the base features like importing config and setting up logger. * - Parsing the "adonisrc.js" file * - Setting up the IoC container * - Registering and booting providers * - Invoking lifecycle methods on the providers and hooks * * The Application class extends Macroable to allow runtime extension of functionality. * It manages the entire lifecycle from creation to termination, providing hooks at * each stage for customization. * * @template ContainerBindings - Type definition for IoC container bindings * @extends {Macroable} * @class Application */ export declare class Application> extends Macroable { #private; /** * Stores metadata information about the application including * app name, version, and AdonisJS version. * * @type {Map} */ info: Map<'appName' | 'version' | 'adonisVersion' | string, any>; /** * Returns the application name from the info map. * Defaults to 'adonisjs_app' if not set. * * @readonly * @type {string} */ get appName(): any; /** * Returns the application version from the info map. * Returns null if no version is set. * * @readonly * @type {SemverNode | null} */ get version(): SemverNode | null; /** * The parsed version for the "@adonisjs/core" package. * Returns null if no version is available. * * @readonly * @type {SemverNode | null} */ get adonisVersion(): SemverNode | null; /** * The URL for the root of the application directory. * * @readonly * @type {URL} */ get appRoot(): URL; /** * A boolean to know if the application has been booted. * Returns true when the application state is beyond 'initiated'. * * @readonly * @type {boolean} */ get isBooted(): boolean; /** * A boolean to know if the application is ready and fully started. * Returns true only when the application state is 'ready'. * * @readonly * @type {boolean} */ get isReady(): boolean; /** * A boolean to know if the application has been terminated. * Returns true only when the application state is 'terminated'. * * @readonly * @type {boolean} */ get isTerminated(): boolean; /** * A boolean to know if the application is in the middle of * the termination process but not yet fully terminated. * * @readonly * @type {boolean} */ get isTerminating(): boolean; /** * Reference to the config instance. The value is available * after the "init" method has been called. * * @readonly * @type {any} */ get config(): import("@adonisjs/config").Config; /** * Reference to the parsed adonisrc.js file. The value is available * after the "init" method has been called. * * @readonly * @type {any} */ get rcFile(): import("./types.ts").RcFile; /** * Normalized current NODE_ENV value. Converts common variations * to standard values (development, production, test). * * @readonly * @type {string} */ get nodeEnvironment(): string; /** * Returns true when the NODE_ENV is set to 'production'. * Useful for conditional logic based on production environment. * * @readonly * @type {boolean} */ get inProduction(): boolean; /** * Returns true when the NODE_ENV is set to 'development'. * Useful for enabling development-specific features. * * @readonly * @type {boolean} */ get inDev(): boolean; /** * Returns true when the NODE_ENV is set to 'test'. * Useful for enabling test-specific behavior. * * @readonly * @type {boolean} */ get inTest(): boolean; /** * Returns true if the process is managed and running under PM2. * Detected by checking for the pm_id environment variable. * * @readonly * @type {boolean} */ get managedByPm2(): boolean; /** * Reference to scaffolding generators for creating application files. * Provides utilities for generating controllers, models, migrations, etc. * * @readonly * @type {any} */ get generators(): { singularControllerNames: string[]; entityPathSegment(segmentName: string): string; createEntity(entityName: string): { path: string; name: string; }; importPath(...paths: string[]): string; tableName(entityName: string): string; modelName(entityName: string): string; modelFileName(entityName: string): string; controllerName(entityName: string, singular?: boolean): string; controllerFileName(entityName: string, singular?: boolean): string; eventName(entityName: string): string; eventFileName(entityName: string): string; listenerName(entityName: string): string; listenerFileName(entityName: string): string; middlewareName(entityName: string): string; middlewareFileName(entityName: string): string; providerName(entityName: string): string; providerFileName(entityName: string): string; policyName(entityName: string): string; policyFileName(entityName: string): string; factoryName(entityName: string): string; factoryFileName(entityName: string): string; serviceName(entityName: string): string; serviceFileName(entityName: string): string; seederName(entityName: string): string; seederFileName(entityName: string): string; commandTerminalName(entityName: string): string; commandName(entityName: string): string; commandFileName(entityName: string): string; validatorName(entityName: string): string; validatorActionName(entityName: string, action: string): string; validatorFileName(entityName: string): string; exceptionName(entityName: string): string; exceptionFileName(entityName: string): string; mailerName(entityName: string, type?: "notification" | "provision"): string; mailerFileName(entityName: string, type?: "notification" | "provision"): string; mailName(entityName: string, type?: string): string; mailFileName(entityName: string, type?: string): string; testGroupName(entity: { path: string; name: string; }): string; testFileName(entityName: string): string; viewFileName(entityName: string): string; transformerName(entityName: string): string; transformerFileName(entityName: string): string; inertiaPageName(entityName: string): string; inertiaPageFileName(entityName: string, extension: string): string; }; /** * Reference to the stubs module for scaffolding resources or ejecting stubs. * Provides functionality to create and manage code generation templates. * * @type {Object} * @property {Function} create - Factory function to create a StubsManager instance */ stubs: { create: () => Promise; }; /** * Feature flags manager for checking the status of experimental features. * Reads configuration from adonisrc.js experimental section. * * @type {FeatureFlags} */ experimentalFlags: FeatureFlags; /** * Flag indicating if VineJS provider is configured and available. * When true, the @vinejs/vine package can be safely imported. * * @type {boolean} * @default false */ usingVineJS: boolean; /** * Flag indicating if Edge template engine provider is configured. * When true, the edge.js package can be safely imported. * * @type {boolean} * @default false */ usingEdgeJS: boolean; /** * Detects which AI coding agent the application is running under. * Checks for environment variables set by different AI coding assistants: * - CLAUDECODE='1' for Claude Code * - GEMINI_CLI='1' for Gemini * - GITHUB_COPILOT_CLI_MODE='1' for GitHub Copilot * - WINDSURF_SESSION='1' or TERM_PROGRAM='windsurf' for Windsurf * - CODEX_CLI='1' or CODEX_SANDBOX='1' for Codex * - OPENCODE='1' for OpenCode * - CURSOR_AGENT='1' for Cursor * * @readonly * @type {'claude' | 'gemini' | 'copilot' | 'windsurf' | 'codex' | 'opencode' | 'cursor' | null} * @returns The name of the detected AI agent, or null if none detected */ get detectedAIAgent(): ("claude" | "cursor" | "opencode" | "gemini" | "copilot" | "windsurf" | "codex") | null; /** * Returns true if the application is running within any AI coding agent. * This is a convenience getter that checks if detectedAIAgent is not null. * * @readonly * @type {boolean} * @returns True when running under an AI coding agent, false otherwise */ get runningInAIAgent(): boolean; /** * Reference to the AdonisJS IoC container. The container manages * dependency injection and service binding throughout the application. * Available after the "init" method has been called. * * @type {Container} */ container: Container; /** * Creates an instance of Application. * * @param {URL} appRoot - The root URL of the application * @param {Object} options - Configuration options * @param {AppEnvironments} options.environment - The application environment * @param {Importer} [options.importer] - Optional module importer function */ constructor(appRoot: URL, options: { environment: AppEnvironments; importer?: Importer; }); /** * The current environment in which the application is running * * @returns {AppEnvironments} The current application environment */ getEnvironment(): AppEnvironments; /** * Switch the environment in which the app is running. The * environment can only be changed before the app is booted. * * @param {AppEnvironments} environment - The new environment to set * @returns {this} Returns the application instance for method chaining * @throws {RuntimeException} When called after the app has been booted */ setEnvironment(environment: AppEnvironments): this; /** * The current state of the application * * @returns {ApplicationStates} The current application state */ getState(): ApplicationStates; /** * Specify the contents of the "adonisrc.js" file as * an object. Calling this method will disable loading * the "adonisrc.js" file from the disk. * * @param {Record} value - The RC file contents as an object * @returns {this} Returns the application instance for method chaining */ rcContents(value: Record): this; /** * Define the config values to use when booting the * config provider. Calling this method disables * reading files from the config directory. * * @param {Record} values - The config values to use * @returns {this} Returns the application instance for method chaining */ useConfig(values: Record): this; /** * Notify the parent process when the Node.js process is spawned with an IPC channel. * The arguments accepted are same as "process.send" * * @param {any} message - The message to send to the parent process * @param {any} [sendHandle] - Optional handle to send with the message * @param {Object} [options] - Options for sending the message * @param {boolean} [options.swallowErrors] - Whether to swallow errors * @param {boolean} [options.keepOpen] - Whether to keep the connection open * @param {function} [callback] - Callback function to handle send result */ notify(message: any, sendHandle?: any, options?: { swallowErrors?: boolean | undefined; keepOpen?: boolean | undefined; }, callback?: (error: Error | null) => void): void; /** * Listen for a process signal. This method is same as calling * "process.on(signal)" * * @param {NodeJS.Signals} signal - The signal to listen for * @param {NodeJS.SignalsListener} callback - The callback to execute when signal is received * @returns {this} Returns the application instance for method chaining */ listen(signal: NodeJS.Signals, callback: NodeJS.SignalsListener): this; /** * Listen for a process signal once. This method is same as calling * "process.once(signal)" * * @param {NodeJS.Signals} signal - The signal to listen for * @param {NodeJS.SignalsListener} callback - The callback to execute when signal is received * @returns {this} Returns the application instance for method chaining */ listenOnce(signal: NodeJS.Signals, callback: NodeJS.SignalsListener): this; /** * Listen for a process signal conditionally. * * @param {boolean} conditional - Whether to register the listener * @param {NodeJS.Signals} signal - The signal to listen for * @param {NodeJS.SignalsListener} callback - The callback to execute when signal is received * @returns {this} Returns the application instance for method chaining */ listenIf(conditional: boolean, signal: NodeJS.Signals, callback: NodeJS.SignalsListener): this; /** * Listen for a process signal once conditionally. * * @param {boolean} conditional - Whether to register the listener * @param {NodeJS.Signals} signal - The signal to listen for * @param {NodeJS.SignalsListener} callback - The callback to execute when signal is received * @returns {this} Returns the application instance for method chaining */ listenOnceIf(conditional: boolean, signal: NodeJS.Signals, callback: NodeJS.SignalsListener): this; /** * Register hooks that are called before the app starts * the initiating process * * @param {HookHandler} handler - The hook handler function to register * @returns {this} Returns the application instance for method chaining */ initiating(handler: HookHandler<[Application], [Application]>): this; /** * Initiate the application. Calling this method performs following * operations: * * - Parses the "adonisrc.js" file * - Validate and set environment variables * - Loads the application config from the configured config dir. * - Configures the logger * - Instantiates the IoC container * * @returns {Promise} Promise that resolves when initiation is complete */ init(): Promise; /** * Register hooks that are called before the app boot * process starts * * @param {HookHandler} handler - The hook handler function to register * @returns {this} Returns the application instance for method chaining */ booting(handler: HookHandler<[Application], [Application]>): this; /** * Boot the application. Calling this method performs the following * operations: * * - Resolve providers and call the "register" method on them. * - Call the "boot" method on providers * - Run the "booted" hooks * * @returns {Promise} Promise that resolves when boot is complete */ boot(): Promise; /** * Register a hook to get notified when the application has * been booted. * * The hook will be called immediately if the app has already * been booted. * * @param {HookHandler} handler - The hook handler function to register * @returns {Promise} Promise that resolves after the handler is executed */ booted(handler: HookHandler<[Application], [Application]>): Promise; /** * Register hooks that are called when the app is starting * * @param {HookHandler} handler - The hook handler function to register * @returns {this} Returns the application instance for method chaining */ starting(handler: HookHandler<[Application], [Application]>): this; /** * Start the application. Calling this method performs the following * operations: * * - Run the "start" lifecycle hooks on all the providers * - Start the application by invoking the supplied callback * - Run the "ready" lifecycle hooks on all the providers * - Run the "ready" application hooks * * @param {function} callback - The callback function to invoke when starting the app * @returns {Promise} Promise that resolves when start is complete */ start(callback: (app: this) => void | Promise): Promise; /** * Register hooks that are called when the app is ready. * * The hook will be called immediately if the app is already ready. * * @param {HookHandler} handler - The hook handler function to register * @returns {Promise} Promise that resolves after the handler is executed */ ready(handler: HookHandler<[Application], [Application]>): Promise; /** * Register hooks that are called before the app is terminated. * * @param {HookHandler} handler - The hook handler function to register * @returns {this} Returns the application instance for method chaining */ terminating(handler: HookHandler<[Application], [Application]>): this; /** * Terminate application gracefully. Calling this method performs * the following operations: * * - Run "shutdown" hooks on all the providers * - Run "terminating" app lifecycle hooks * * @returns {Promise} Promise that resolves when termination is complete */ terminate(): Promise; /** * Returns relative path to a file from the app root * * @param {string} absolutePath - The absolute path to convert * @returns {string} The relative path from app root */ relativePath(absolutePath: string): string; /** * Returns URL to a path from the application root. * * @param {...string} paths - Path segments to join * @returns {URL} The constructed URL */ makeURL(...paths: string[]): URL; /** * Returns file system path from the application root. * * @param {...string} paths - Path segments to join * @returns {string} The constructed file system path */ makePath(...paths: string[]): string; /** * Makes path to the config directory * * @param {...string} paths - Path segments to append to config directory * @returns {string} The constructed config directory path */ configPath(...paths: string[]): string; /** * Makes path to the public directory * * @param {...string} paths - Path segments to append to public directory * @returns {string} The constructed public directory path */ publicPath(...paths: string[]): string; /** * Makes path to the providers directory * * @param {...string} paths - Path segments to append to providers directory * @returns {string} The constructed providers directory path */ providersPath(...paths: string[]): string; /** * Makes path to the factories directory * * @param {...string} paths - Path segments to append to factories directory * @returns {string} The constructed factories directory path */ factoriesPath(...paths: string[]): string; /** * Makes path to the migrations directory * * @param {...string} paths - Path segments to append to migrations directory * @returns {string} The constructed migrations directory path */ migrationsPath(...paths: string[]): string; /** * Makes path to the seeders directory * * @param {...string} paths - Path segments to append to seeders directory * @returns {string} The constructed seeders directory path */ seedersPath(...paths: string[]): string; /** * Makes path to the language files directory * * @param {...string} paths - Path segments to append to language files directory * @returns {string} The constructed language files directory path */ languageFilesPath(...paths: string[]): string; /** * Makes path to the views directory * * @param {...string} paths - Path segments to append to views directory * @returns {string} The constructed views directory path */ viewsPath(...paths: string[]): string; /** * Makes path to the start directory * * @param {...string} paths - Path segments to append to start directory * @returns {string} The constructed start directory path */ startPath(...paths: string[]): string; /** * Makes path to the tmp directory * * @param {...string} paths - Path segments to append to tmp directory * @returns {string} The constructed tmp directory path */ tmpPath(...paths: string[]): string; /** * Makes path to the contracts directory * * @param {...string} paths - Path segments to append to contracts directory * @returns {string} The constructed contracts directory path * @deprecated Use "types" directory instead */ contractsPath(...paths: string[]): string; /** * Makes path to the http controllers directory * * @param {...string} paths - Path segments to append to http controllers directory * @returns {string} The constructed http controllers directory path */ httpControllersPath(...paths: string[]): string; /** * Makes path to the models directory * * @param {...string} paths - Path segments to append to models directory * @returns {string} The constructed models directory path */ modelsPath(...paths: string[]): string; /** * Makes path to the services directory * * @param {...string} paths - Path segments to append to services directory * @returns {string} The constructed services directory path */ servicesPath(...paths: string[]): string; /** * Makes path to the exceptions directory * * @param {...string} paths - Path segments to append to exceptions directory * @returns {string} The constructed exceptions directory path */ exceptionsPath(...paths: string[]): string; /** * Makes path to the mailers directory * * @param {...string} paths - Path segments to append to mailers directory * @returns {string} The constructed mailers directory path */ mailersPath(...paths: string[]): string; /** * Makes path to the mails directory * * @param {...string} paths - Path segments to append to mails directory * @returns {string} The constructed mails directory path */ mailsPath(...paths: string[]): string; /** * Makes path to the middleware directory * * @param {...string} paths - Path segments to append to middleware directory * @returns {string} The constructed middleware directory path */ middlewarePath(...paths: string[]): string; /** * Makes path to the policies directory * * @param {...string} paths - Path segments to append to policies directory * @returns {string} The constructed policies directory path */ policiesPath(...paths: string[]): string; /** * Makes path to the validators directory * * @param {...string} paths - Path segments to append to validators directory * @returns {string} The constructed validators directory path */ validatorsPath(...paths: string[]): string; /** * Makes path to the commands directory * * @param {...string} paths - Path segments to append to commands directory * @returns {string} The constructed commands directory path */ commandsPath(...paths: string[]): string; /** * Makes path to the events directory * * @param {...string} paths - Path segments to append to events directory * @returns {string} The constructed events directory path */ eventsPath(...paths: string[]): string; /** * Makes path to the listeners directory * * @param {...string} paths - Path segments to append to listeners directory * @returns {string} The constructed listeners directory path */ listenersPath(...paths: string[]): string; /** * Makes path to the transformers directory * * @param {...string} paths - Path segments to append to transformers directory * @returns {string} The constructed transformers directory path */ transformersPath(...paths: string[]): string; /** * Makes path to the client directory for writing generated * output * * @param {...string} paths - Path segments to append to events directory * @returns {string} The constructed directory path */ generatedClientPath(...paths: string[]): string; /** * Makes path to the server directory for writing generated * output * * @param {...string} paths - Path segments to append to events directory * @returns {string} The constructed directory path */ generatedServerPath(...paths: string[]): string; /** * Import a module by identifier. This method uses the importer function * defined at the time of creating the application instance and throws * an error if no importer was defined. * * @param {string} moduleIdentifier - The module identifier to import * @returns {any} The imported module * @throws {RuntimeException} When no importer function is defined */ import(moduleIdentifier: string): any; /** * Import a module by identifier and return its default export. This method uses the importer function * defined at the time of creating the application instance and throws * an error if no importer was defined. * * @template T - The type of the default export * @param {string} moduleIdentifier - The module identifier to import * @returns The default export of the imported module * @throws {RuntimeException} When no importer function is defined */ importDefault(moduleIdentifier: string): Promise; /** * JSON representation of the application * * @returns The application state as a JSON object */ toJSON(): { isReady: boolean; isTerminating: boolean; environment: AppEnvironments; nodeEnvironment: string; appName: any; version: string | null; adonisVersion: string | null; }; }