import { type Logger, type RootLogger } from "@workleap/logging"; import { EventBus } from "../messaging/EventBus.js"; import type { DeferredRegistrationScopeCompletionFunction, DeferredRegistrationScopeOptions, Plugin } from "../plugins/Plugin.js"; import { ModuleManager } from "../registration/ModuleManager.js"; export type RuntimeMode = "development" | "production"; export type ModuleManagerFactory = (runtime: Runtime) => ModuleManager; export type PluginFactory = (runtime: TRuntime) => Plugin; export interface RuntimeOptions { mode?: RuntimeMode; moduleManager?: ModuleManagerFactory; loggers?: RootLogger[]; plugins?: PluginFactory[]; } export interface RuntimeMethodOptions { logger?: Logger; } export interface RegisterRouteOptions extends RuntimeMethodOptions { hoist?: true; parentPath?: string; parentId?: string; } export interface RegisterNavigationItemOptions extends RuntimeMethodOptions { menuId?: string; sectionId?: string; } export interface GetNavigationItemsOptions { menuId?: string; } export interface GetPluginOptions { throwOnNotFound?: boolean; } export interface StartDeferredRegistrationScopeOptions extends RuntimeMethodOptions { transactional?: boolean; } export interface CompleteDeferredRegistrationScopeOptions extends RuntimeMethodOptions { } export interface ValidateRegistrationsOptions extends RuntimeMethodOptions { } /** * The non plugin counterpart of {@link Plugin.onDeferredRegistrationScopeStarted}. Same options, same * return value, same guarantees — use it to clear and replay a registry that modules fill from their * deferred registration functions when that registry isn't owned by a plugin. * * Prefer the plugin hook when the registry lives in a plugin: it needs no subscription and no disposal. */ export type DeferredRegistrationScopeStartedListener = (options: DeferredRegistrationScopeOptions) => DeferredRegistrationScopeCompletionFunction | void; export declare const RootMenuId = "root"; export interface IRuntime = any> { get moduleManager(): ModuleManager; registerRoute: (route: TRoute, options?: RegisterRouteOptions) => void; registerPublicRoute: (route: Omit, options?: RegisterRouteOptions) => void; get routes(): TRoute[]; registerNavigationItem: (navigationItem: TNavigationItem, options?: RegisterNavigationItemOptions) => void; getNavigationItems: (options?: GetNavigationItemsOptions) => TNavigationItem[]; getNavigationItemsByMenu: () => Map; startDeferredRegistrationScope: (options?: StartDeferredRegistrationScopeOptions) => void; completeDeferredRegistrationScope: (options?: CompleteDeferredRegistrationScopeOptions) => void; registerDeferredRegistrationScopeStartedListener: (callback: DeferredRegistrationScopeStartedListener) => () => void; removeDeferredRegistrationScopeStartedListener: (callback: DeferredRegistrationScopeStartedListener) => void; _notifyDeferredRegistrationScopeStarted: (options: DeferredRegistrationScopeOptions) => DeferredRegistrationScopeCompletionFunction[]; get mode(): RuntimeMode; get plugins(): Plugin[]; getPlugin: (pluginName: string, options?: GetPluginOptions) => Plugin | undefined; get logger(): Logger; get eventBus(): EventBus; startScope: (logger: Logger) => TRuntime; _getLogger: (options?: RuntimeMethodOptions) => Logger; _validateRegistrations: (options?: ValidateRegistrationsOptions) => void; } export declare abstract class Runtime = any> implements IRuntime { #private; protected readonly _mode: RuntimeMode; protected readonly _moduleManager: ModuleManager; protected readonly _logger: Logger; protected readonly _eventBus: EventBus; protected readonly _plugins: Plugin[]; constructor(options?: RuntimeOptions); get moduleManager(): ModuleManager; abstract registerRoute(route: TRoute, options?: RegisterRouteOptions): void; abstract registerPublicRoute(route: Omit, options?: RegisterRouteOptions): void; abstract get routes(): TRoute[]; abstract registerNavigationItem(navigationItem: TNavigationItem, options?: RegisterNavigationItemOptions): void; abstract getNavigationItems(options?: GetNavigationItemsOptions): TNavigationItem[]; abstract getNavigationItemsByMenu(): Map; abstract startDeferredRegistrationScope(options?: StartDeferredRegistrationScopeOptions): void; abstract completeDeferredRegistrationScope(options?: CompleteDeferredRegistrationScopeOptions): void; /** * Registers a listener executed when a deferred registration run starts, before any module's deferred * registration function. Implement it to clear and replay a registry that modules fill from their * deferred registration functions, otherwise its entries outlive the condition that registered them. * * The listener may return a function to be executed once the run has settled, while the runtime's scope * is still open. It's the place to commit a buffered registry, and it must not read the runtime's * navigation items: on an update run, the items of that run are not committed yet. * * Both the listener and the function it returns must be synchronous, nothing awaits them. An error * thrown by either is logged and swallowed, it never fails the run. * * When the registry lives in a plugin, implement {@link Plugin.onDeferredRegistrationScopeStarted} * instead — it's the same contract with nothing to subscribe or dispose. * * @returns A function removing the listener. */ registerDeferredRegistrationScopeStartedListener(callback: DeferredRegistrationScopeStartedListener): () => void; /** * Removes a listener registered with {@link Runtime.registerDeferredRegistrationScopeStartedListener}. */ removeDeferredRegistrationScopeStartedListener(callback: DeferredRegistrationScopeStartedListener): void; /** * Framework internal. Driven by "ModuleManager.#withDeferredRegistrationScope", alongside the plugin * hooks, so that both surfaces share one set of ordering and error guarantees. * * @returns The completion functions returned by the notified listeners, in registration order. */ _notifyDeferredRegistrationScopeStarted(options: DeferredRegistrationScopeOptions): DeferredRegistrationScopeCompletionFunction[]; get mode(): RuntimeMode; get plugins(): Plugin>[]; getPlugin(pluginName: string, options?: GetPluginOptions): Plugin> | undefined; get logger(): Logger; get eventBus(): EventBus; abstract startScope(logger: Logger): TRuntime; _getLogger(options?: RuntimeMethodOptions): Logger; abstract _validateRegistrations(options?: ValidateRegistrationsOptions): void; } export declare abstract class RuntimeScope = Runtime> implements IRuntime { protected readonly _runtime: TRuntime; protected readonly _logger: Logger; constructor(runtime: TRuntime, logger: Logger); get moduleManager(): ModuleManager; registerRoute(route: TRoute, options?: RegisterRouteOptions): void; registerPublicRoute(route: Omit, options?: RegisterRouteOptions): void; get routes(): TRoute[]; registerNavigationItem(navigationItem: TNavigationItem, options?: RegisterNavigationItemOptions): void; getNavigationItems(options?: GetNavigationItemsOptions): TNavigationItem[]; getNavigationItemsByMenu(): Map; startDeferredRegistrationScope(): void; completeDeferredRegistrationScope(): void; registerDeferredRegistrationScopeStartedListener(callback: DeferredRegistrationScopeStartedListener): () => void; removeDeferredRegistrationScopeStartedListener(callback: DeferredRegistrationScopeStartedListener): void; _notifyDeferredRegistrationScopeStarted(): DeferredRegistrationScopeCompletionFunction[]; get mode(): RuntimeMode; get plugins(): Plugin>[]; getPlugin(pluginName: string, options?: GetPluginOptions): Plugin> | undefined; get logger(): Logger; get eventBus(): EventBus; startScope(): TRuntime; _getLogger(options?: RuntimeMethodOptions): Logger; _validateRegistrations(): void; }