UNPKG

@rnaga/wp-node

Version:

👉 **[View Full Documentation at rnaga.github.io/wp-node →](https://rnaga.github.io/wp-node/)**

76 lines • 3.33 kB
import "reflect-metadata"; import type * as types from "./types"; import { Context } from "./core/context"; import { Hooks } from "./core/hooks/hooks"; /** * The Application class serves as a central helper for managing the lifecycle of the application. * It provides methods to initialize and retrieve application contexts, register hooks, and manage configurations. * * Key Responsibilities: * - **Context Initialization**: The `getContext` method initializes and retrieves the application context for a given environment. * It ensures that hooks and configurations are properly set up and passed to the context. * - **Hook Registration**: The `registerHooks` method allows registering custom hooks for specific environments. * Hooks are used to extend or modify the application's behavior dynamically. * - **Configuration Management**: The class holds global and environment-specific configurations, which are passed to the context during initialization. * * Usage: * - Use `Application.getContext(env)` to retrieve the application context for a specific environment. * - Use `Application.registerHooks(clazzes, env)` to register hooks for an environment. * - Access `Application.configs` or `Application.config` to manage configurations. * * This class is designed to be used as a static utility and cannot be instantiated directly. */ export default class Application { /** * A flag to indicate if the application is currently installing. */ static installing: boolean; /** * Stores the global configurations accessible across different parts of the application. */ static configs: types.Configs; /** * A singular configuration object if only one environment configuration is needed. */ static config: types.Config; /** * A map storing instances of Hooks by environment keys. */ private static hooksInstanceMap; /** * Private constructor to prevent instantiation. */ private constructor(); /** * Returns the map of hooks instances. */ static get hooks(): Map<string, Hooks<types.hooks.Filters, types.hooks.Actions>>; /** * Registers hooks for a given environment. * * @param clazzes - Array of hook class constructors to be registered. * @param env - Optional environment name, defaults to "default". */ static registerHooks(clazzes: types.Constructor[], env?: string): void; /** * Retrieves the application context for a given environment, * initializing hooks and configurations. * * This method initializes the hooks based on the environment * and hooks registered via the `registerHooks` method. * * It ensures the application configuration is valid * and throws errors if not properly set. * * @param env - The environment identifier for which to get the context, defaults to "default". * @returns Promise<Context> - A promise that resolves to the instance * of Context configured with appropriate hooks and settings. * @throws Error - If the configuration is invalid or undefined. */ static getContext(env?: string): Promise<Context>; /** * Closes all database connections gracefully. */ static terminate(): void; } //# sourceMappingURL=application.d.ts.map