@navios/commander 0.8.0 → 0.9.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.
package/lib/index.cjs CHANGED
@@ -46,7 +46,7 @@ zod_v4 = __toESM(zod_v4);
46
46
  let util = require("util");
47
47
  let node_async_hooks = require("node:async_hooks");
48
48
 
49
- //#region ../core/lib/use-guards.decorator-CUww54Nt.mjs
49
+ //#region ../core/lib/use-guards.decorator-CzVXuLkz.mjs
50
50
  const EndpointMetadataKey = Symbol("EndpointMetadataKey");
51
51
  function getAllEndpointMetadata(context) {
52
52
  if (context.metadata) {
@@ -156,7 +156,7 @@ function hasModuleMetadata(target) {
156
156
  * }
157
157
  * }
158
158
  * ```
159
- */ function Controller({ guards, registry } = {}) {
159
+ */ function Controller({ guards, registry, priority, scope } = {}) {
160
160
  return function(target, context) {
161
161
  if (context.kind !== "class") throw new Error("[Navios] @Controller decorator can only be used on classes.");
162
162
  const token = _navios_di.InjectionToken.create(target);
@@ -166,7 +166,9 @@ function hasModuleMetadata(target) {
166
166
  }
167
167
  return (0, _navios_di.Injectable)({
168
168
  token,
169
- registry
169
+ registry,
170
+ priority,
171
+ scope
170
172
  })(target, context);
171
173
  };
172
174
  }
@@ -251,13 +253,13 @@ function Endpoint(endpoint) {
251
253
  }
252
254
  /**
253
255
  * Decorator that marks a class as a Navios module.
254
- *
256
+ *
255
257
  * Modules are the basic building blocks of a Navios application.
256
258
  * They organize controllers, services, and other modules into logical units.
257
- *
259
+ *
258
260
  * @param options - Module configuration options
259
261
  * @returns A class decorator
260
- *
262
+ *
261
263
  * @example
262
264
  * ```typescript
263
265
  * @Module({
@@ -267,7 +269,7 @@ function Endpoint(endpoint) {
267
269
  * })
268
270
  * export class AppModule {}
269
271
  * ```
270
- */ function Module({ controllers = [], imports = [], guards = [] } = {
272
+ */ function Module({ controllers = [], imports = [], guards = [], priority, registry } = {
271
273
  controllers: [],
272
274
  imports: [],
273
275
  guards: []
@@ -281,7 +283,9 @@ function Endpoint(endpoint) {
281
283
  for (const guard of Array.from(guards).reverse()) moduleMetadata.guards.add(guard);
282
284
  return (0, _navios_di.Injectable)({
283
285
  token,
284
- scope: _navios_di.InjectableScope.Singleton
286
+ scope: _navios_di.InjectableScope.Singleton,
287
+ priority,
288
+ registry
285
289
  })(target, context);
286
290
  };
287
291
  }
@@ -385,7 +389,7 @@ function Stream(endpoint) {
385
389
  };
386
390
 
387
391
  //#endregion
388
- //#region ../core/lib/src-gBAChVRL.mjs
392
+ //#region ../core/lib/src-Bo23RIo-.mjs
389
393
  function envInt(key, defaultValue) {
390
394
  const envKey = node_process.env[key] || process.env[key];
391
395
  return envKey ? parseInt(envKey, 10) : defaultValue;
@@ -3059,7 +3063,7 @@ _dec$9 = (0, _navios_di.Injectable)();
3059
3063
  async traverseModules(module$1, parentMetadata) {
3060
3064
  const metadata = extractModuleMetadata(module$1);
3061
3065
  if (parentMetadata) this.mergeMetadata(metadata, parentMetadata);
3062
- const moduleName = module$1.name;
3066
+ const moduleName = (0, _navios_di.getInjectableToken)(module$1).id;
3063
3067
  if (this.modulesMetadata.has(moduleName)) return;
3064
3068
  try {
3065
3069
  this.modulesMetadata.set(moduleName, metadata);
@@ -3456,7 +3460,7 @@ _dec$8 = (0, _navios_di.Injectable)();
3456
3460
  }
3457
3461
  httpTokens = /* @__PURE__ */ new Map();
3458
3462
  setupHttpEnvironment(tokens) {
3459
- this.httpTokens = tokens;
3463
+ for (const [token, value] of tokens) this.httpTokens.set(token, value);
3460
3464
  }
3461
3465
  getHttpToken(token) {
3462
3466
  return this.httpTokens.get(token);
@@ -6093,9 +6097,9 @@ _dec$15 = (0, _navios_di.Injectable)();
6093
6097
  * })
6094
6098
  * ```
6095
6099
  */ static async create(appModule, options = { adapter: [] }) {
6096
- const container = options.container ?? new _navios_di.Container();
6100
+ const container = options.container ?? new _navios_di.Container(options.registry);
6097
6101
  if (options.enableRequestId === true) setRequestIdEnabled(true);
6098
- container.getServiceLocator().getManager().storeCreatedHolder(NaviosOptionsToken.toString(), options, _navios_di.InjectableType.Class, _navios_di.InjectableScope.Singleton);
6102
+ container.addInstance(NaviosOptionsToken, options);
6099
6103
  await this.registerLoggerConfiguration(container, options);
6100
6104
  const adapters = Array.isArray(options.adapter) ? options.adapter : [options.adapter];
6101
6105
  for (const adapter of adapters) await this.registerEnvironment(container, adapter);
@@ -6110,11 +6114,14 @@ _dec$15 = (0, _navios_di.Injectable)();
6110
6114
  }
6111
6115
  static async registerLoggerConfiguration(container, options) {
6112
6116
  const { logger } = options;
6113
- if (Array.isArray(logger) || isNil(logger)) {
6114
- (await container.get(LoggerOutput))?.setup({ logLevels: logger });
6117
+ if (Array.isArray(logger) || isNil(logger) || options.enableRequestId) {
6118
+ (await container.get(LoggerOutput))?.setup({
6119
+ logLevels: Array.isArray(logger) ? logger : void 0,
6120
+ requestId: options.enableRequestId ?? false
6121
+ });
6115
6122
  return;
6116
6123
  }
6117
- if (logger !== true && !isNil(logger)) container.getServiceLocator().getManager().storeCreatedHolder(LoggerOutput.toString(), logger, _navios_di.InjectableType.Class, _navios_di.InjectableScope.Singleton);
6124
+ if (logger !== true && !isNil(logger)) container.addInstance(LoggerOutput, logger);
6118
6125
  }
6119
6126
  };
6120
6127
 
@@ -6689,7 +6696,7 @@ var CliModuleLoaderService = class {
6689
6696
  async traverseModules(module$1, parentMetadata) {
6690
6697
  const metadata = extractCliModuleMetadata(module$1);
6691
6698
  if (parentMetadata) this.mergeMetadata(metadata, parentMetadata);
6692
- const moduleName = module$1.name;
6699
+ const moduleName = (0, lib_exports.getInjectableToken)(module$1).id;
6693
6700
  if (this.modulesMetadata.has(moduleName)) return;
6694
6701
  this.modulesMetadata.set(moduleName, metadata);
6695
6702
  for (const command of metadata.commands) {
@@ -7778,14 +7785,16 @@ var CommanderApplication = class {
7778
7785
  * }
7779
7786
  * }
7780
7787
  * ```
7781
- */ function Command({ path, optionsSchema }) {
7788
+ */ function Command({ path, optionsSchema, priority, registry }) {
7782
7789
  return function(target, context) {
7783
7790
  if (context.kind !== "class") throw new Error("[Navios Commander] @Command decorator can only be used on classes.");
7784
7791
  const token = lib_exports.InjectionToken.create(target);
7785
7792
  if (context.metadata) getCommandMetadata(target, context, path, optionsSchema);
7786
7793
  return (0, lib_exports.Injectable)({
7787
7794
  token,
7788
- scope: lib_exports.InjectableScope.Singleton
7795
+ scope: lib_exports.InjectableScope.Singleton,
7796
+ priority,
7797
+ registry
7789
7798
  })(target, context);
7790
7799
  };
7791
7800
  }
@@ -7813,7 +7822,7 @@ var CommanderApplication = class {
7813
7822
  * })
7814
7823
  * export class AppModule {}
7815
7824
  * ```
7816
- */ function CliModule({ commands = [], imports = [] } = {
7825
+ */ function CliModule({ commands = [], imports = [], priority, registry } = {
7817
7826
  commands: [],
7818
7827
  imports: []
7819
7828
  }) {
@@ -7825,7 +7834,9 @@ var CommanderApplication = class {
7825
7834
  for (const importedModule of imports) moduleMetadata.imports.add(importedModule);
7826
7835
  return (0, lib_exports.Injectable)({
7827
7836
  token,
7828
- scope: lib_exports.InjectableScope.Singleton
7837
+ scope: lib_exports.InjectableScope.Singleton,
7838
+ priority,
7839
+ registry
7829
7840
  })(target, context);
7830
7841
  };
7831
7842
  }