@navios/commander 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.mjs CHANGED
@@ -38,13 +38,7 @@ var __copyProps = (to, from, except, desc) => {
38
38
  }
39
39
  return to;
40
40
  };
41
- var __reExport = (target, mod, secondTarget, symbols) => {
42
- if (symbols) {
43
- __defProp(target, Symbol.toStringTag, { value: "Module" });
44
- secondTarget && __defProp(secondTarget, Symbol.toStringTag, { value: "Module" });
45
- }
46
- __copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default");
47
- };
41
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
48
42
 
49
43
  //#endregion
50
44
  //#region ../core/lib/use-guards.decorator-kZ3lNK8v.mjs
@@ -469,7 +463,7 @@ const XmlStreamAdapterToken = InjectionToken.create("XmlStreamAdapterToken");
469
463
  };
470
464
 
471
465
  //#endregion
472
- //#region ../core/lib/src-DzPY5s6d.mjs
466
+ //#region ../core/lib/src-DpPBxmjz.mjs
473
467
  function envInt(key, defaultValue) {
474
468
  const envKey = env[key] || process.env[key];
475
469
  return envKey ? parseInt(envKey, 10) : defaultValue;
@@ -5467,6 +5461,7 @@ _dec$14 = Injectable();
5467
5461
  container = inject(Container);
5468
5462
  appModule = null;
5469
5463
  options = { adapter: [] };
5464
+ plugins = [];
5470
5465
  /**
5471
5466
  * Indicates whether the application has been initialized.
5472
5467
  * Set to `true` after `init()` completes successfully.
@@ -5491,18 +5486,40 @@ _dec$14 = Injectable();
5491
5486
  return this.container;
5492
5487
  }
5493
5488
  /**
5489
+ * Registers a plugin to be initialized after modules are loaded.
5490
+ *
5491
+ * Plugins are initialized in the order they are registered,
5492
+ * after all modules are loaded but before the server starts listening.
5493
+ *
5494
+ * @param definition - Plugin definition with options
5495
+ * @returns this for method chaining
5496
+ *
5497
+ * @example
5498
+ * ```typescript
5499
+ * import { defineOpenApiPlugin } from '@navios/openapi-fastify'
5500
+ *
5501
+ * app.usePlugin(defineOpenApiPlugin({
5502
+ * info: { title: 'My API', version: '1.0.0' },
5503
+ * }))
5504
+ * ```
5505
+ */ usePlugin(definition) {
5506
+ this.plugins.push(definition);
5507
+ return this;
5508
+ }
5509
+ /**
5494
5510
  * Initializes the application.
5495
- *
5511
+ *
5496
5512
  * This method:
5497
5513
  * - Loads all modules and their dependencies
5498
5514
  * - Sets up the HTTP server if an adapter is configured
5499
5515
  * - Calls onModuleInit hooks on all modules
5516
+ * - Initializes registered plugins
5500
5517
  * - Marks the application as initialized
5501
- *
5518
+ *
5502
5519
  * Must be called before `listen()`.
5503
- *
5520
+ *
5504
5521
  * @throws Error if app module is not set
5505
- *
5522
+ *
5506
5523
  * @example
5507
5524
  * ```typescript
5508
5525
  * const app = await NaviosFactory.create(AppModule, {
@@ -5516,6 +5533,7 @@ _dec$14 = Injectable();
5516
5533
  await this.moduleLoader.loadModules(this.appModule);
5517
5534
  if (this.environment.hasHttpSetup()) await this.httpApplication?.setupHttpServer(this.options);
5518
5535
  await this.initModules();
5536
+ await this.initPlugins();
5519
5537
  if (this.environment.hasHttpSetup()) await this.httpApplication?.ready();
5520
5538
  this.isInitialized = true;
5521
5539
  this.logger.debug("Navios application initialized");
@@ -5524,6 +5542,19 @@ _dec$14 = Injectable();
5524
5542
  const modules = this.moduleLoader.getAllModules();
5525
5543
  await this.httpApplication?.onModulesInit(modules);
5526
5544
  }
5545
+ async initPlugins() {
5546
+ if (this.plugins.length === 0) return;
5547
+ const context = {
5548
+ modules: this.moduleLoader.getAllModules(),
5549
+ server: this.httpApplication?.getServer() ?? null,
5550
+ container: this.container,
5551
+ globalPrefix: this.httpApplication?.getGlobalPrefix() ?? ""
5552
+ };
5553
+ for (const { plugin, options } of this.plugins) {
5554
+ this.logger.debug(`Initializing plugin: ${plugin.name}`);
5555
+ await plugin.register(context, options);
5556
+ }
5557
+ }
5527
5558
  /**
5528
5559
  * Enables CORS (Cross-Origin Resource Sharing) for the application.
5529
5560
  *
@@ -5801,8 +5832,8 @@ var lib_exports = /* @__PURE__ */ __export({
5801
5832
  stripEndSlash: () => stripEndSlash,
5802
5833
  yellow: () => yellow
5803
5834
  });
5804
- import * as import___navios_di from "@navios/di";
5805
- __reExport(lib_exports, import___navios_di);
5835
+ import * as import__navios_di from "@navios/di";
5836
+ __reExport(lib_exports, import__navios_di);
5806
5837
 
5807
5838
  //#endregion
5808
5839
  //#region src/interfaces/commander-execution-context.interface.mts