@navios/core 1.0.0 → 1.1.0

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.
Files changed (49) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/lib/{index-C0Sg16Eb.d.cts → index-3LcTrbxz.d.mts} +491 -52
  3. package/lib/index-3LcTrbxz.d.mts.map +1 -0
  4. package/lib/{index-DySQ6Dpd.d.mts → index-B14SekVb.d.cts} +491 -52
  5. package/lib/index-B14SekVb.d.cts.map +1 -0
  6. package/lib/index.cjs +18 -3
  7. package/lib/index.d.cts +2 -2
  8. package/lib/index.d.mts +2 -2
  9. package/lib/index.mjs +4 -4
  10. package/lib/legacy-compat/index.cjs +3 -3
  11. package/lib/legacy-compat/index.d.cts +1 -1
  12. package/lib/legacy-compat/index.d.mts +1 -1
  13. package/lib/legacy-compat/index.mjs +2 -2
  14. package/lib/{navios.factory-CO5MB_OK.cjs → navios.factory-CUrO_p6K.cjs} +461 -48
  15. package/lib/navios.factory-CUrO_p6K.cjs.map +1 -0
  16. package/lib/{navios.factory-D6Y94P9B.mjs → navios.factory-DjUOOVVL.mjs} +372 -49
  17. package/lib/navios.factory-DjUOOVVL.mjs.map +1 -0
  18. package/lib/testing/index.cjs +2 -2
  19. package/lib/testing/index.d.cts +1 -1
  20. package/lib/testing/index.d.mts +1 -1
  21. package/lib/testing/index.mjs +2 -2
  22. package/lib/{tokens-CWw9kyeD.cjs → tokens-BEuBMGGX.cjs} +18 -21
  23. package/lib/tokens-BEuBMGGX.cjs.map +1 -0
  24. package/lib/{tokens-4J9sredA.mjs → tokens-COyNGV1I.mjs} +17 -20
  25. package/lib/tokens-COyNGV1I.mjs.map +1 -0
  26. package/lib/{use-guards.decorator-BecoQSmE.mjs → use-guards.decorator-DLmRl2CV.mjs} +14 -17
  27. package/lib/use-guards.decorator-DLmRl2CV.mjs.map +1 -0
  28. package/lib/{use-guards.decorator-C4ml9XaT.cjs → use-guards.decorator-DhumFTk3.cjs} +15 -18
  29. package/lib/use-guards.decorator-DhumFTk3.cjs.map +1 -0
  30. package/package.json +2 -2
  31. package/src/interfaces/index.mts +3 -0
  32. package/src/interfaces/plugin-context.mts +104 -0
  33. package/src/interfaces/plugin-stage.mts +62 -0
  34. package/src/interfaces/plugin.interface.mts +42 -62
  35. package/src/interfaces/staged-plugin.interface.mts +209 -0
  36. package/src/metadata/controller.metadata.mts +29 -22
  37. package/src/metadata/module.metadata.mts +33 -25
  38. package/src/navios.application.mts +247 -53
  39. package/src/services/module-loader.service.mts +11 -8
  40. package/src/utils/define-plugin.mts +251 -0
  41. package/src/utils/index.mts +1 -0
  42. package/lib/index-C0Sg16Eb.d.cts.map +0 -1
  43. package/lib/index-DySQ6Dpd.d.mts.map +0 -1
  44. package/lib/navios.factory-CO5MB_OK.cjs.map +0 -1
  45. package/lib/navios.factory-D6Y94P9B.mjs.map +0 -1
  46. package/lib/tokens-4J9sredA.mjs.map +0 -1
  47. package/lib/tokens-CWw9kyeD.cjs.map +0 -1
  48. package/lib/use-guards.decorator-BecoQSmE.mjs.map +0 -1
  49. package/lib/use-guards.decorator-C4ml9XaT.cjs.map +0 -1
@@ -25,7 +25,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
25
25
  }) : target, mod));
26
26
 
27
27
  //#endregion
28
- const require_tokens = require('./tokens-CWw9kyeD.cjs');
28
+ const require_tokens = require('./tokens-BEuBMGGX.cjs');
29
29
  let _navios_di = require("@navios/di");
30
30
  let zod_v4 = require("zod/v4");
31
31
  zod_v4 = __toESM(zod_v4);
@@ -1157,6 +1157,57 @@ var LoggerInstance = class {
1157
1157
  }
1158
1158
  };
1159
1159
 
1160
+ //#endregion
1161
+ //#region src/interfaces/plugin-stage.mts
1162
+ /**
1163
+ * Base stage names (without pre:/post: prefix)
1164
+ */
1165
+ const PluginStageBase = {
1166
+ MODULES_TRAVERSE: "modules-traverse",
1167
+ ADAPTER_RESOLVE: "adapter-resolve",
1168
+ ADAPTER_SETUP: "adapter-setup",
1169
+ MODULES_INIT: "modules-init",
1170
+ READY: "ready"
1171
+ };
1172
+ /**
1173
+ * Helper to create pre stage name from base
1174
+ */
1175
+ const preStage = (base) => `pre:${base}`;
1176
+ /**
1177
+ * Helper to create post stage name from base
1178
+ */
1179
+ const postStage = (base) => `post:${base}`;
1180
+ /**
1181
+ * All stages as constants for direct access
1182
+ */
1183
+ const PluginStages = {
1184
+ PRE_MODULES_TRAVERSE: "pre:modules-traverse",
1185
+ POST_MODULES_TRAVERSE: "post:modules-traverse",
1186
+ PRE_ADAPTER_RESOLVE: "pre:adapter-resolve",
1187
+ POST_ADAPTER_RESOLVE: "post:adapter-resolve",
1188
+ PRE_ADAPTER_SETUP: "pre:adapter-setup",
1189
+ POST_ADAPTER_SETUP: "post:adapter-setup",
1190
+ PRE_MODULES_INIT: "pre:modules-init",
1191
+ POST_MODULES_INIT: "post:modules-init",
1192
+ PRE_READY: "pre:ready",
1193
+ POST_READY: "post:ready"
1194
+ };
1195
+ /**
1196
+ * All stages in execution order
1197
+ */
1198
+ const PLUGIN_STAGES_ORDER = [
1199
+ PluginStages.PRE_MODULES_TRAVERSE,
1200
+ PluginStages.POST_MODULES_TRAVERSE,
1201
+ PluginStages.PRE_ADAPTER_RESOLVE,
1202
+ PluginStages.POST_ADAPTER_RESOLVE,
1203
+ PluginStages.PRE_ADAPTER_SETUP,
1204
+ PluginStages.POST_ADAPTER_SETUP,
1205
+ PluginStages.PRE_MODULES_INIT,
1206
+ PluginStages.POST_MODULES_INIT,
1207
+ PluginStages.PRE_READY,
1208
+ PluginStages.POST_READY
1209
+ ];
1210
+
1160
1211
  //#endregion
1161
1212
  //#region src/responders/enums/framework-error.enum.mts
1162
1213
  /**
@@ -2794,9 +2845,15 @@ var ModuleLoaderService = class {
2794
2845
  * ```
2795
2846
  */ async extendModules(extensions) {
2796
2847
  if (!this.initialized) throw new Error("ModuleLoaderService must be initialized before extending. Call loadModules() first.");
2797
- for (const extension of extensions) if (extension.module) await this.traverseModules(extension.module);
2798
- else if (extension.controllers && extension.moduleName) await this.registerControllers(extension.controllers, extension.moduleName);
2799
- else if (extension.controllers) throw new Error("moduleName is required when providing controllers without a module");
2848
+ for (const extension of extensions) {
2849
+ if (extension.module) {
2850
+ await this.traverseModules(extension.module);
2851
+ continue;
2852
+ }
2853
+ if (!extension.controllers) continue;
2854
+ if (!extension.moduleName) throw new Error("moduleName is required when providing controllers without a module");
2855
+ await this.registerControllers(extension.controllers, extension.moduleName);
2856
+ }
2800
2857
  }
2801
2858
  /**
2802
2859
  * Registers controllers under a synthetic module.
@@ -2808,6 +2865,7 @@ var ModuleLoaderService = class {
2808
2865
  this.logger.debug(`Extended module ${moduleName} with ${controllers.length} controllers`);
2809
2866
  } else {
2810
2867
  const metadata = {
2868
+ name: moduleName,
2811
2869
  controllers: new Set(controllers),
2812
2870
  imports: /* @__PURE__ */ new Set(),
2813
2871
  guards: /* @__PURE__ */ new Set(),
@@ -2907,6 +2965,167 @@ var ModuleLoaderService = class {
2907
2965
  if (!adapterSupports(adapter, method)) throw new Error(`Current adapter does not implement '${method}()'`);
2908
2966
  }
2909
2967
 
2968
+ //#endregion
2969
+ //#region src/utils/define-plugin.mts
2970
+ /**
2971
+ * Creates a curried plugin factory for a specific stage.
2972
+ * Returns a function that takes config and returns a function that takes options.
2973
+ */ function createPluginFactory(stage) {
2974
+ return (config) => (options) => ({
2975
+ plugin: {
2976
+ name: config.name,
2977
+ stage,
2978
+ register: config.register
2979
+ },
2980
+ options
2981
+ });
2982
+ }
2983
+ /**
2984
+ * Define a plugin that runs before modules are traversed.
2985
+ *
2986
+ * Context: container only
2987
+ *
2988
+ * Use this stage for early DI setup before any modules are loaded.
2989
+ *
2990
+ * @example
2991
+ * ```typescript
2992
+ * export const defineEarlySetupPlugin = definePreModulesTraversePlugin({
2993
+ * name: 'early-setup',
2994
+ * register: (context, options: { key: string }) => {
2995
+ * context.container.addInstance(SomeToken, options.key)
2996
+ * },
2997
+ * })
2998
+ *
2999
+ * // Usage
3000
+ * app.usePlugin(defineEarlySetupPlugin({ key: 'value' }))
3001
+ * ```
3002
+ */ const definePreModulesTraversePlugin = createPluginFactory(PluginStages.PRE_MODULES_TRAVERSE);
3003
+ /**
3004
+ * Define a plugin that runs after modules are traversed.
3005
+ *
3006
+ * Context: container + modules + moduleLoader
3007
+ *
3008
+ * Use this stage to inspect loaded modules or extend the module tree.
3009
+ *
3010
+ * @example
3011
+ * ```typescript
3012
+ * export const defineModuleInspectorPlugin = definePostModulesTraversePlugin({
3013
+ * name: 'module-inspector',
3014
+ * register: (context, options) => {
3015
+ * console.log('Loaded modules:', context.modules.size)
3016
+ * },
3017
+ * })
3018
+ * ```
3019
+ */ const definePostModulesTraversePlugin = createPluginFactory(PluginStages.POST_MODULES_TRAVERSE);
3020
+ /**
3021
+ * Define a plugin that runs before adapter is resolved from container.
3022
+ *
3023
+ * Context: container + modules + moduleLoader (NO adapter yet!)
3024
+ *
3025
+ * Use this stage to modify registry/bindings before adapter instantiation.
3026
+ * This is ideal for instrumentation, service wrapping, or changing DI bindings.
3027
+ *
3028
+ * @example
3029
+ * ```typescript
3030
+ * export const defineOtelPlugin = definePreAdapterResolvePlugin({
3031
+ * name: 'otel',
3032
+ * register: (context, options: OtelOptions) => {
3033
+ * const registry = context.container.getRegistry()
3034
+ * // Modify registry before adapter is created
3035
+ * },
3036
+ * })
3037
+ *
3038
+ * // Usage
3039
+ * app.usePlugin(defineOtelPlugin({ serviceName: 'my-app' }))
3040
+ * ```
3041
+ */ const definePreAdapterResolvePlugin = createPluginFactory(PluginStages.PRE_ADAPTER_RESOLVE);
3042
+ /**
3043
+ * Define a plugin that runs after adapter is resolved.
3044
+ *
3045
+ * Context: full (container + modules + moduleLoader + adapter)
3046
+ *
3047
+ * @example
3048
+ * ```typescript
3049
+ * export const defineAdapterConfigPlugin = definePostAdapterResolvePlugin<
3050
+ * { prefix: string },
3051
+ * BunApplicationServiceInterface
3052
+ * >()({
3053
+ * name: 'adapter-config',
3054
+ * register: (context, options) => {
3055
+ * context.adapter.setGlobalPrefix(options.prefix)
3056
+ * },
3057
+ * })
3058
+ * ```
3059
+ */ function definePostAdapterResolvePlugin() {
3060
+ return createPluginFactory(PluginStages.POST_ADAPTER_RESOLVE);
3061
+ }
3062
+ /**
3063
+ * Define a plugin that runs before adapter setup.
3064
+ *
3065
+ * Context: full
3066
+ */ function definePreAdapterSetupPlugin() {
3067
+ return createPluginFactory(PluginStages.PRE_ADAPTER_SETUP);
3068
+ }
3069
+ /**
3070
+ * Define a plugin that runs after adapter setup.
3071
+ *
3072
+ * Context: full
3073
+ */ function definePostAdapterSetupPlugin() {
3074
+ return createPluginFactory(PluginStages.POST_ADAPTER_SETUP);
3075
+ }
3076
+ /**
3077
+ * Define a plugin that runs before modules init (route registration).
3078
+ *
3079
+ * Context: full
3080
+ */ function definePreModulesInitPlugin() {
3081
+ return createPluginFactory(PluginStages.PRE_MODULES_INIT);
3082
+ }
3083
+ /**
3084
+ * Define a plugin that runs after modules init (route registration).
3085
+ *
3086
+ * Context: full
3087
+ *
3088
+ * This is the default stage for legacy NaviosPlugin implementations.
3089
+ *
3090
+ * @example
3091
+ * ```typescript
3092
+ * export const defineOpenApiPlugin = definePostModulesInitPlugin<
3093
+ * BunApplicationServiceInterface
3094
+ * >()({
3095
+ * name: 'openapi',
3096
+ * register: async (context, options: OpenApiOptions) => {
3097
+ * // Routes are registered, can generate OpenAPI docs
3098
+ * },
3099
+ * })
3100
+ * ```
3101
+ */ function definePostModulesInitPlugin() {
3102
+ return createPluginFactory(PluginStages.POST_MODULES_INIT);
3103
+ }
3104
+ /**
3105
+ * Define a plugin that runs before adapter signals ready.
3106
+ *
3107
+ * Context: full
3108
+ */ function definePreReadyPlugin() {
3109
+ return createPluginFactory(PluginStages.PRE_READY);
3110
+ }
3111
+ /**
3112
+ * Define a plugin that runs after adapter signals ready.
3113
+ *
3114
+ * Context: full - this is the final stage, app is fully initialized
3115
+ *
3116
+ * @example
3117
+ * ```typescript
3118
+ * export const defineStartupLogPlugin = definePostReadyPlugin()({
3119
+ * name: 'startup-log',
3120
+ * register: (context) => {
3121
+ * console.log('Application fully initialized!')
3122
+ * },
3123
+ * })
3124
+ * ```
3125
+ */ function definePostReadyPlugin() {
3126
+ return createPluginFactory(PluginStages.POST_READY);
3127
+ }
3128
+
2910
3129
  //#endregion
2911
3130
  //#region src/navios.environment.mts
2912
3131
  function applyDecs2203RFactory$1() {
@@ -3505,7 +3724,14 @@ var NaviosApplication = class {
3505
3724
  container = (0, _navios_di.inject)(_navios_di.Container);
3506
3725
  appModule = null;
3507
3726
  options = { adapter: [] };
3508
- plugins = [];
3727
+ /**
3728
+ * Plugin storage organized by stage for efficient execution.
3729
+ * Each stage has a Set of plugin definitions.
3730
+ */ plugins = new Map(PLUGIN_STAGES_ORDER.map((stage) => [stage, /* @__PURE__ */ new Set()]));
3731
+ /**
3732
+ * Queue of adapter configuration methods to apply after adapter resolution.
3733
+ * Allows calling methods like enableCors() before init().
3734
+ */ pendingAdapterCalls = [];
3509
3735
  /**
3510
3736
  * Indicates whether the application has been initialized.
3511
3737
  * Set to `true` after `init()` completes successfully.
@@ -3514,13 +3740,15 @@ var NaviosApplication = class {
3514
3740
  * Sets up the application with the provided module and options.
3515
3741
  * This is called automatically by NaviosFactory.create().
3516
3742
  *
3743
+ * Note: Adapter resolution has been moved to init() to allow
3744
+ * plugins to modify the container/registry before adapter instantiation.
3745
+ *
3517
3746
  * @param appModule - The root application module
3518
3747
  * @param options - Application configuration options
3519
3748
  * @internal
3520
3749
  */ async setup(appModule, options = { adapter: [] }) {
3521
3750
  this.appModule = appModule;
3522
3751
  this.options = options;
3523
- if (this.environment.hasAdapterSetup()) this.adapter = await this.container.get(require_tokens.AdapterToken);
3524
3752
  }
3525
3753
  /**
3526
3754
  * Gets the dependency injection container used by this application.
@@ -3539,35 +3767,58 @@ var NaviosApplication = class {
3539
3767
  return this.adapter;
3540
3768
  }
3541
3769
  /**
3542
- * Registers a plugin to be initialized after modules are loaded.
3770
+ * Registers one or more plugins for initialization during the application lifecycle.
3543
3771
  *
3544
- * Plugins are initialized in the order they are registered,
3545
- * after all modules are loaded but before the server starts listening.
3772
+ * Plugins can target specific stages or use the legacy interface (defaults to post:modules-init).
3773
+ * Plugins are executed in stage order, and within a stage in registration order.
3546
3774
  *
3547
- * @param definition - Plugin definition with options
3775
+ * @param definitions - Single plugin definition or array of definitions
3548
3776
  * @returns this for method chaining
3549
3777
  *
3550
3778
  * @example
3551
3779
  * ```typescript
3552
- * import { defineOpenApiPlugin } from '@navios/openapi-fastify'
3780
+ * // Single plugin (legacy or staged)
3781
+ * app.usePlugin(defineOpenApiPlugin({ info: { title: 'My API', version: '1.0.0' } }))
3782
+ *
3783
+ * // Multiple plugins in one call
3784
+ * app.usePlugin([
3785
+ * defineOtelPlugin({ serviceName: 'my-service' }),
3786
+ * defineOpenApiPlugin({ info: { title: 'My API', version: '1.0.0' } }),
3787
+ * ])
3553
3788
  *
3554
- * app.usePlugin(defineOpenApiPlugin({
3555
- * info: { title: 'My API', version: '1.0.0' },
3556
- * }))
3789
+ * // Staged plugin with explicit stage
3790
+ * app.usePlugin(definePreAdapterResolvePlugin({
3791
+ * name: 'early-setup',
3792
+ * register: (ctx) => { ... },
3793
+ * })({}))
3557
3794
  * ```
3558
- */ usePlugin(definition) {
3559
- this.plugins.push(definition);
3795
+ */ usePlugin(definitions) {
3796
+ const definitionsArray = Array.isArray(definitions) ? definitions : [definitions];
3797
+ for (const definition of definitionsArray) {
3798
+ const stage = this.resolvePluginStage(definition);
3799
+ const stageSet = this.plugins.get(stage);
3800
+ if (!stageSet) throw new Error(`Unknown plugin stage: ${stage}`);
3801
+ stageSet.add(definition);
3802
+ this.logger.debug(`Registered plugin "${definition.plugin.name}" for stage: ${stage}`);
3803
+ }
3560
3804
  return this;
3561
3805
  }
3562
3806
  /**
3807
+ * Resolves the stage for a plugin definition.
3808
+ * Staged plugins use their explicit stage, legacy plugins default to post:modules-init.
3809
+ */ resolvePluginStage(definition) {
3810
+ if ("stage" in definition.plugin) return definition.plugin.stage;
3811
+ return PluginStages.POST_MODULES_INIT;
3812
+ }
3813
+ /**
3563
3814
  * Initializes the application.
3564
3815
  *
3565
- * This method:
3566
- * - Loads all modules and their dependencies
3567
- * - Sets up the adapter if one is configured
3568
- * - Calls onModuleInit hooks on all modules
3569
- * - Initializes registered plugins
3570
- * - Marks the application as initialized
3816
+ * This method executes the following lifecycle stages:
3817
+ * 1. pre:modules-traverse Load modules post:modules-traverse
3818
+ * 2. pre:adapter-resolve Resolve adapter post:adapter-resolve
3819
+ * 3. pre:adapter-setup Setup adapter post:adapter-setup
3820
+ * 4. pre:modules-init Initialize modules → post:modules-init
3821
+ * 5. pre:ready Ready signal → post:ready
3571
3822
  *
3572
3823
  * Must be called before `listen()`.
3573
3824
  *
@@ -3583,31 +3834,83 @@ var NaviosApplication = class {
3583
3834
  * ```
3584
3835
  */ async init() {
3585
3836
  if (!this.appModule) throw new Error("App module is not set. Call setAppModule() first.");
3586
- await this.moduleLoader.loadModules(this.appModule);
3587
- if (this.environment.hasAdapterSetup() && this.adapter) await this.adapter.setupAdapter(this.options);
3588
- await this.initPlugins();
3589
- await this.initModules();
3590
- if (this.adapter) await this.adapter.ready();
3837
+ await this.wrapStage(PluginStageBase.MODULES_TRAVERSE, () => this.moduleLoader.loadModules(this.appModule));
3838
+ if (this.environment.hasAdapterSetup()) {
3839
+ await this.wrapStage(PluginStageBase.ADAPTER_RESOLVE, async () => {
3840
+ this.adapter = await this.container.get(require_tokens.AdapterToken);
3841
+ this.applyPendingAdapterCalls();
3842
+ });
3843
+ if (this.adapter) await this.wrapStage(PluginStageBase.ADAPTER_SETUP, () => this.adapter.setupAdapter(this.options));
3844
+ }
3845
+ await this.wrapStage(PluginStageBase.MODULES_INIT, () => this.initModules());
3846
+ if (this.adapter) await this.wrapStage(PluginStageBase.READY, () => this.adapter.ready());
3591
3847
  this.isInitialized = true;
3592
3848
  this.logger.debug("Navios application initialized");
3593
3849
  }
3594
- async initModules() {
3595
- const modules = this.moduleLoader.getAllModules();
3596
- if (this.adapter) await this.adapter.onModulesInit(modules);
3850
+ /**
3851
+ * Wraps an operation with pre/post plugin stage execution.
3852
+ *
3853
+ * @param baseName - The base stage name (e.g., 'modules-traverse')
3854
+ * @param operation - The operation to execute between pre/post stages
3855
+ */ async wrapStage(baseName, operation) {
3856
+ await this.executePluginStage(preStage(baseName));
3857
+ const result = await operation();
3858
+ await this.executePluginStage(postStage(baseName));
3859
+ return result;
3597
3860
  }
3598
- async initPlugins() {
3599
- if (this.plugins.length === 0) return;
3600
- if (!this.adapter) throw new Error("Cannot initialize plugins without an adapter");
3601
- const context = {
3861
+ /**
3862
+ * Executes all plugins registered for a specific stage.
3863
+ *
3864
+ * @param stage - The lifecycle stage to execute plugins for
3865
+ */ async executePluginStage(stage) {
3866
+ const stagePlugins = this.plugins.get(stage);
3867
+ if (!stagePlugins || stagePlugins.size === 0) return;
3868
+ const context = this.buildContextForStage(stage);
3869
+ this.logger.debug(`Executing ${stagePlugins.size} plugin(s) for stage: ${stage}`);
3870
+ for (const { plugin, options } of stagePlugins) {
3871
+ this.logger.debug(`Executing plugin: ${plugin.name} (stage: ${stage})`);
3872
+ try {
3873
+ await plugin.register(context, options);
3874
+ } catch (error) {
3875
+ this.logger.error(`Plugin "${plugin.name}" failed at stage "${stage}"`, error);
3876
+ throw error;
3877
+ }
3878
+ }
3879
+ }
3880
+ /**
3881
+ * Builds the appropriate context object for a given stage.
3882
+ *
3883
+ * @param stage - The lifecycle stage
3884
+ * @returns Context object with stage-appropriate properties
3885
+ */ buildContextForStage(stage) {
3886
+ const baseContext = { container: this.container };
3887
+ if (stage === PluginStages.PRE_MODULES_TRAVERSE) return baseContext;
3888
+ const modulesContext = {
3889
+ ...baseContext,
3602
3890
  modules: this.moduleLoader.getAllModules(),
3603
- adapter: this.adapter,
3604
- container: this.container,
3605
3891
  moduleLoader: this.moduleLoader
3606
3892
  };
3607
- for (const { plugin, options } of this.plugins) {
3608
- this.logger.debug(`Initializing plugin: ${plugin.name}`);
3609
- await plugin.register(context, options);
3893
+ if (stage === PluginStages.POST_MODULES_TRAVERSE || stage === PluginStages.PRE_ADAPTER_RESOLVE) return modulesContext;
3894
+ if (!this.adapter) throw new Error(`Cannot execute stage "${stage}" without adapter`);
3895
+ return {
3896
+ ...modulesContext,
3897
+ adapter: this.adapter
3898
+ };
3899
+ }
3900
+ async initModules() {
3901
+ const modules = this.moduleLoader.getAllModules();
3902
+ if (this.adapter) await this.adapter.onModulesInit(modules);
3903
+ }
3904
+ /**
3905
+ * Applies any pending adapter configuration calls that were queued
3906
+ * before the adapter was resolved.
3907
+ */ applyPendingAdapterCalls() {
3908
+ if (!this.adapter || this.pendingAdapterCalls.length === 0) return;
3909
+ for (const { method, args } of this.pendingAdapterCalls) {
3910
+ assertAdapterSupports(this.adapter, method);
3911
+ this.adapter[method](...args);
3610
3912
  }
3913
+ this.pendingAdapterCalls = [];
3611
3914
  }
3612
3915
  async get(token, args) {
3613
3916
  return this.container.get(token, args);
@@ -3632,8 +3935,13 @@ var NaviosApplication = class {
3632
3935
  * ```
3633
3936
  */ configure(options) {
3634
3937
  if (this.isInitialized) throw new Error("configure() must be called before init()");
3635
- assertAdapterSupports(this.adapter, "configure");
3636
- this.adapter.configure(options);
3938
+ if (this.adapter) {
3939
+ assertAdapterSupports(this.adapter, "configure");
3940
+ this.adapter.configure(options);
3941
+ } else this.pendingAdapterCalls.push({
3942
+ method: "configure",
3943
+ args: [options]
3944
+ });
3637
3945
  return this;
3638
3946
  }
3639
3947
  /**
@@ -3651,8 +3959,13 @@ var NaviosApplication = class {
3651
3959
  * })
3652
3960
  * ```
3653
3961
  */ enableCors(options) {
3654
- assertAdapterSupports(this.adapter, "enableCors");
3655
- this.adapter.enableCors(options);
3962
+ if (this.adapter) {
3963
+ assertAdapterSupports(this.adapter, "enableCors");
3964
+ this.adapter.enableCors(options);
3965
+ } else this.pendingAdapterCalls.push({
3966
+ method: "enableCors",
3967
+ args: [options]
3968
+ });
3656
3969
  }
3657
3970
  /**
3658
3971
  * Enables multipart/form-data support for file uploads.
@@ -3669,8 +3982,13 @@ var NaviosApplication = class {
3669
3982
  * })
3670
3983
  * ```
3671
3984
  */ enableMultipart(options) {
3672
- assertAdapterSupports(this.adapter, "enableMultipart");
3673
- this.adapter.enableMultipart(options);
3985
+ if (this.adapter) {
3986
+ assertAdapterSupports(this.adapter, "enableMultipart");
3987
+ this.adapter.enableMultipart(options);
3988
+ } else this.pendingAdapterCalls.push({
3989
+ method: "enableMultipart",
3990
+ args: [options]
3991
+ });
3674
3992
  }
3675
3993
  /**
3676
3994
  * Sets a global prefix for all routes.
@@ -3684,8 +4002,13 @@ var NaviosApplication = class {
3684
4002
  * // All routes will be prefixed with /api/v1
3685
4003
  * ```
3686
4004
  */ setGlobalPrefix(prefix) {
3687
- assertAdapterSupports(this.adapter, "setGlobalPrefix");
3688
- this.adapter.setGlobalPrefix(prefix);
4005
+ if (this.adapter) {
4006
+ assertAdapterSupports(this.adapter, "setGlobalPrefix");
4007
+ this.adapter.setGlobalPrefix(prefix);
4008
+ } else this.pendingAdapterCalls.push({
4009
+ method: "setGlobalPrefix",
4010
+ args: [prefix]
4011
+ });
3689
4012
  }
3690
4013
  /**
3691
4014
  * Gets the underlying HTTP server instance.
@@ -3912,6 +4235,24 @@ Object.defineProperty(exports, 'NotFoundResponderToken', {
3912
4235
  return NotFoundResponderToken;
3913
4236
  }
3914
4237
  });
4238
+ Object.defineProperty(exports, 'PLUGIN_STAGES_ORDER', {
4239
+ enumerable: true,
4240
+ get: function () {
4241
+ return PLUGIN_STAGES_ORDER;
4242
+ }
4243
+ });
4244
+ Object.defineProperty(exports, 'PluginStageBase', {
4245
+ enumerable: true,
4246
+ get: function () {
4247
+ return PluginStageBase;
4248
+ }
4249
+ });
4250
+ Object.defineProperty(exports, 'PluginStages', {
4251
+ enumerable: true,
4252
+ get: function () {
4253
+ return PluginStages;
4254
+ }
4255
+ });
3915
4256
  Object.defineProperty(exports, 'ValidationErrorResponderToken', {
3916
4257
  enumerable: true,
3917
4258
  get: function () {
@@ -3996,6 +4337,66 @@ Object.defineProperty(exports, 'clc', {
3996
4337
  return clc;
3997
4338
  }
3998
4339
  });
4340
+ Object.defineProperty(exports, 'definePostAdapterResolvePlugin', {
4341
+ enumerable: true,
4342
+ get: function () {
4343
+ return definePostAdapterResolvePlugin;
4344
+ }
4345
+ });
4346
+ Object.defineProperty(exports, 'definePostAdapterSetupPlugin', {
4347
+ enumerable: true,
4348
+ get: function () {
4349
+ return definePostAdapterSetupPlugin;
4350
+ }
4351
+ });
4352
+ Object.defineProperty(exports, 'definePostModulesInitPlugin', {
4353
+ enumerable: true,
4354
+ get: function () {
4355
+ return definePostModulesInitPlugin;
4356
+ }
4357
+ });
4358
+ Object.defineProperty(exports, 'definePostModulesTraversePlugin', {
4359
+ enumerable: true,
4360
+ get: function () {
4361
+ return definePostModulesTraversePlugin;
4362
+ }
4363
+ });
4364
+ Object.defineProperty(exports, 'definePostReadyPlugin', {
4365
+ enumerable: true,
4366
+ get: function () {
4367
+ return definePostReadyPlugin;
4368
+ }
4369
+ });
4370
+ Object.defineProperty(exports, 'definePreAdapterResolvePlugin', {
4371
+ enumerable: true,
4372
+ get: function () {
4373
+ return definePreAdapterResolvePlugin;
4374
+ }
4375
+ });
4376
+ Object.defineProperty(exports, 'definePreAdapterSetupPlugin', {
4377
+ enumerable: true,
4378
+ get: function () {
4379
+ return definePreAdapterSetupPlugin;
4380
+ }
4381
+ });
4382
+ Object.defineProperty(exports, 'definePreModulesInitPlugin', {
4383
+ enumerable: true,
4384
+ get: function () {
4385
+ return definePreModulesInitPlugin;
4386
+ }
4387
+ });
4388
+ Object.defineProperty(exports, 'definePreModulesTraversePlugin', {
4389
+ enumerable: true,
4390
+ get: function () {
4391
+ return definePreModulesTraversePlugin;
4392
+ }
4393
+ });
4394
+ Object.defineProperty(exports, 'definePreReadyPlugin', {
4395
+ enumerable: true,
4396
+ get: function () {
4397
+ return definePreReadyPlugin;
4398
+ }
4399
+ });
3999
4400
  Object.defineProperty(exports, 'filterLogLevels', {
4000
4401
  enumerable: true,
4001
4402
  get: function () {
@@ -4098,6 +4499,18 @@ Object.defineProperty(exports, 'normalizePath', {
4098
4499
  return normalizePath;
4099
4500
  }
4100
4501
  });
4502
+ Object.defineProperty(exports, 'postStage', {
4503
+ enumerable: true,
4504
+ get: function () {
4505
+ return postStage;
4506
+ }
4507
+ });
4508
+ Object.defineProperty(exports, 'preStage', {
4509
+ enumerable: true,
4510
+ get: function () {
4511
+ return preStage;
4512
+ }
4513
+ });
4101
4514
  Object.defineProperty(exports, 'runWithRequestId', {
4102
4515
  enumerable: true,
4103
4516
  get: function () {
@@ -4122,4 +4535,4 @@ Object.defineProperty(exports, 'yellow', {
4122
4535
  return yellow;
4123
4536
  }
4124
4537
  });
4125
- //# sourceMappingURL=navios.factory-CO5MB_OK.cjs.map
4538
+ //# sourceMappingURL=navios.factory-CUrO_p6K.cjs.map