import { default as http, IncomingMessage } from 'node:http'; import { Route } from '../route'; import { SigilPlugin } from './misc'; import { SigilMiddlewareCallback } from './misc/sigil-middleware'; import { ServerDefinition, SigilOptions } from './types'; import { ILogOptions } from '../utils/make-log'; /** * Core class for the Sigil framework that initializes an HTTP/S server, * manages middleware, plugins, routes, and response templating. * * @template T type of Sigil runtime options. */ export default abstract class SigilCore> { /** * Bound logger function configured with Sigil debug options. */ readonly logger: (options: ILogOptions) => void; /** * Underlying HTTP or HTTPS server instance, undefined in serverless mode. */ protected $server: ServerDefinition; /** * Reference to the handler function for incoming HTTP messages. */ protected $incomingMessageHandlerRef?: (req: IncomingMessage, res: http.ServerResponse) => any; /** * Registered middleware callbacks, keyed by identifier. */ protected readonly $middlewares: Map; /** * Registered plugins for extending framework behavior. */ protected $plugins: Map; /** * Template function for generating HTTP responses. */ protected readonly $responseTemplate: SigilOptions["responseTemplate"]; /** * Set of registered routes with their mount paths. */ protected readonly $routes: Set<[string, Route]>; /** * Sigil runtime configuration options. */ protected readonly $options: Partial; /** * Root router instance for mounting application routes. */ protected readonly $root: Route, Record>; /** * Flag indicating whether the framework has completed initialization. */ protected $initialized: boolean; /** * Internal flag to prevent multiple plugin initializations. */ protected $pluginsInitialized: boolean; /** * Constructs the Sigil core framework instance. * Initializes logger, HTTP/S server (unless serverless), response template, * and triggers initial plugin updates in serverless mode. * * @param options configuration options for Sigil (server, debug, etc.). */ protected constructor(options?: T); /** * Callback to initialize and update all registered plugins. * Called once when the server is ready and on subsequent route updates. * * @returns promise resolving after plugin hooks are executed. */ protected $updateCallback(): Promise; }