@navios/commander 0.5.1 → 0.7.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 (69) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +56 -8
  3. package/dist/src/commander.application.d.mts +124 -6
  4. package/dist/src/commander.application.d.mts.map +1 -1
  5. package/dist/src/commander.factory.d.mts +31 -3
  6. package/dist/src/commander.factory.d.mts.map +1 -1
  7. package/dist/src/decorators/cli-module.decorator.d.mts +36 -1
  8. package/dist/src/decorators/cli-module.decorator.d.mts.map +1 -1
  9. package/dist/src/decorators/command.decorator.d.mts +44 -1
  10. package/dist/src/decorators/command.decorator.d.mts.map +1 -1
  11. package/dist/src/index.d.mts +2 -1
  12. package/dist/src/index.d.mts.map +1 -1
  13. package/dist/src/interfaces/command-handler.interface.d.mts +33 -0
  14. package/dist/src/interfaces/command-handler.interface.d.mts.map +1 -1
  15. package/dist/src/interfaces/commander-execution-context.interface.d.mts +54 -0
  16. package/dist/src/interfaces/commander-execution-context.interface.d.mts.map +1 -0
  17. package/dist/src/interfaces/index.d.mts +1 -1
  18. package/dist/src/interfaces/index.d.mts.map +1 -1
  19. package/dist/src/interfaces/module.interface.d.mts +1 -4
  20. package/dist/src/interfaces/module.interface.d.mts.map +1 -1
  21. package/dist/src/metadata/cli-module.metadata.d.mts +46 -1
  22. package/dist/src/metadata/cli-module.metadata.d.mts.map +1 -1
  23. package/dist/src/metadata/command.metadata.d.mts +48 -1
  24. package/dist/src/metadata/command.metadata.d.mts.map +1 -1
  25. package/dist/src/services/cli-parser.service.d.mts +32 -1
  26. package/dist/src/services/cli-parser.service.d.mts.map +1 -1
  27. package/dist/src/services/module-loader.service.d.mts +44 -5
  28. package/dist/src/services/module-loader.service.d.mts.map +1 -1
  29. package/dist/src/tokens/execution-context.token.d.mts +27 -0
  30. package/dist/src/tokens/execution-context.token.d.mts.map +1 -0
  31. package/dist/src/tokens/index.d.mts +2 -0
  32. package/dist/src/tokens/index.d.mts.map +1 -0
  33. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  34. package/dist/tsconfig.tsbuildinfo +1 -1
  35. package/dist/tsdown.config.d.mts +3 -0
  36. package/dist/tsdown.config.d.mts.map +1 -0
  37. package/lib/index.cjs +7721 -0
  38. package/lib/index.cjs.map +1 -0
  39. package/lib/index.d.cts +670 -0
  40. package/lib/index.d.cts.map +1 -0
  41. package/lib/index.d.mts +670 -98
  42. package/lib/index.d.mts.map +1 -0
  43. package/lib/index.mjs +7511 -565
  44. package/lib/index.mjs.map +1 -1
  45. package/package.json +5 -5
  46. package/project.json +2 -2
  47. package/src/commander.application.mts +161 -17
  48. package/src/commander.factory.mts +32 -4
  49. package/src/decorators/cli-module.decorator.mts +37 -2
  50. package/src/decorators/command.decorator.mts +45 -2
  51. package/src/index.mts +5 -1
  52. package/src/interfaces/command-handler.interface.mts +33 -0
  53. package/src/interfaces/commander-execution-context.interface.mts +64 -0
  54. package/src/interfaces/index.mts +1 -1
  55. package/src/metadata/cli-module.metadata.mts +48 -7
  56. package/src/metadata/command.metadata.mts +48 -1
  57. package/src/services/__tests__/cli-parser.service.spec.mts +15 -11
  58. package/src/services/cli-parser.service.mts +35 -3
  59. package/src/services/module-loader.service.mts +45 -6
  60. package/src/tokens/execution-context.token.mts +34 -0
  61. package/src/tokens/index.mts +1 -0
  62. package/tsdown.config.mts +33 -0
  63. package/lib/_tsup-dts-rollup.d.mts +0 -466
  64. package/lib/_tsup-dts-rollup.d.ts +0 -466
  65. package/lib/index.d.ts +0 -98
  66. package/lib/index.js +0 -604
  67. package/lib/index.js.map +0 -1
  68. package/src/interfaces/module.interface.mts +0 -4
  69. package/tsup.config.mts +0 -12
package/lib/index.d.mts CHANGED
@@ -1,98 +1,670 @@
1
- export { Factory } from './_tsup-dts-rollup.mjs';
2
- export { FactoryOptions } from './_tsup-dts-rollup.mjs';
3
- export { Injectable } from './_tsup-dts-rollup.mjs';
4
- export { InjectableOptions } from './_tsup-dts-rollup.mjs';
5
- export { InjectableScope } from './_tsup-dts-rollup.mjs';
6
- export { InjectableType } from './_tsup-dts-rollup.mjs';
7
- export { FactoryNotFound } from './_tsup-dts-rollup.mjs';
8
- export { FactoryTokenNotResolved } from './_tsup-dts-rollup.mjs';
9
- export { InstanceDestroying } from './_tsup-dts-rollup.mjs';
10
- export { InstanceNotFound } from './_tsup-dts-rollup.mjs';
11
- export { UnknownError } from './_tsup-dts-rollup.mjs';
12
- export { ErrorsEnum } from './_tsup-dts-rollup.mjs';
13
- export { DIErrorCode } from './_tsup-dts-rollup.mjs';
14
- export { DIError } from './_tsup-dts-rollup.mjs';
15
- export { Factorable } from './_tsup-dts-rollup.mjs';
16
- export { FactorableWithArgs } from './_tsup-dts-rollup.mjs';
17
- export { OnServiceInit } from './_tsup-dts-rollup.mjs';
18
- export { OnServiceDestroy } from './_tsup-dts-rollup.mjs';
19
- export { getInjectors } from './_tsup-dts-rollup.mjs';
20
- export { Injectors } from './_tsup-dts-rollup.mjs';
21
- export { getInjectableToken } from './_tsup-dts-rollup.mjs';
22
- export { Join } from './_tsup-dts-rollup.mjs';
23
- export { UnionToIntersection } from './_tsup-dts-rollup.mjs';
24
- export { UnionToOvlds } from './_tsup-dts-rollup.mjs';
25
- export { PopUnion } from './_tsup-dts-rollup.mjs';
26
- export { IsUnion } from './_tsup-dts-rollup.mjs';
27
- export { UnionToArray } from './_tsup-dts-rollup.mjs';
28
- export { InjectState } from './_tsup-dts-rollup.mjs';
29
- export { BaseInstanceHolderManager } from './_tsup-dts-rollup.mjs';
30
- export { EventsConfig } from './_tsup-dts-rollup.mjs';
31
- export { EventsNames } from './_tsup-dts-rollup.mjs';
32
- export { EventsArgs } from './_tsup-dts-rollup.mjs';
33
- export { ChannelEmitter } from './_tsup-dts-rollup.mjs';
34
- export { EventEmitterInterface } from './_tsup-dts-rollup.mjs';
35
- export { EventEmitter } from './_tsup-dts-rollup.mjs';
36
- export { FactoryContext } from './_tsup-dts-rollup.mjs';
37
- export { ClassType } from './_tsup-dts-rollup.mjs';
38
- export { ClassTypeWithArgument } from './_tsup-dts-rollup.mjs';
39
- export { ClassTypeWithOptionalArgument } from './_tsup-dts-rollup.mjs';
40
- export { ClassTypeWithInstance } from './_tsup-dts-rollup.mjs';
41
- export { ClassTypeWithInstanceAndArgument } from './_tsup-dts-rollup.mjs';
42
- export { ClassTypeWithInstanceAndOptionalArgument } from './_tsup-dts-rollup.mjs';
43
- export { BaseInjectionTokenSchemaType } from './_tsup-dts-rollup.mjs';
44
- export { OptionalInjectionTokenSchemaType } from './_tsup-dts-rollup.mjs';
45
- export { InjectionTokenSchemaType } from './_tsup-dts-rollup.mjs';
46
- export { InjectionToken } from './_tsup-dts-rollup.mjs';
47
- export { BoundInjectionToken } from './_tsup-dts-rollup.mjs';
48
- export { FactoryInjectionToken } from './_tsup-dts-rollup.mjs';
49
- export { AnyInjectableType } from './_tsup-dts-rollup.mjs';
50
- export { InjectionTokenType } from './_tsup-dts-rollup.mjs';
51
- export { defaultInjectors } from './_tsup-dts-rollup.mjs';
52
- export { asyncInject } from './_tsup-dts-rollup.mjs';
53
- export { inject } from './_tsup-dts-rollup.mjs';
54
- export { wrapSyncInit } from './_tsup-dts-rollup.mjs';
55
- export { provideFactoryContext } from './_tsup-dts-rollup.mjs';
56
- export { FactoryRecord } from './_tsup-dts-rollup.mjs';
57
- export { Registry } from './_tsup-dts-rollup.mjs';
58
- export { globalRegistry } from './_tsup-dts-rollup.mjs';
59
- export { ServiceInstantiator } from './_tsup-dts-rollup.mjs';
60
- export { ServiceLocator } from './_tsup-dts-rollup.mjs';
61
- export { ServiceLocatorEventBus } from './_tsup-dts-rollup.mjs';
62
- export { ServiceLocatorInstanceHolderStatus } from './_tsup-dts-rollup.mjs';
63
- export { ServiceLocatorInstanceEffect } from './_tsup-dts-rollup.mjs';
64
- export { ServiceLocatorInstanceDestroyListener } from './_tsup-dts-rollup.mjs';
65
- export { ServiceLocatorInstanceHolderCreating } from './_tsup-dts-rollup.mjs';
66
- export { ServiceLocatorInstanceHolderCreated } from './_tsup-dts-rollup.mjs';
67
- export { ServiceLocatorInstanceHolderDestroying } from './_tsup-dts-rollup.mjs';
68
- export { ServiceLocatorInstanceHolderError } from './_tsup-dts-rollup.mjs';
69
- export { ServiceLocatorInstanceHolder } from './_tsup-dts-rollup.mjs';
70
- export { ServiceLocatorManager } from './_tsup-dts-rollup.mjs';
71
- export { createRequestContextHolder } from './_tsup-dts-rollup.mjs';
72
- export { RequestContextHolder } from './_tsup-dts-rollup.mjs';
73
- export { DefaultRequestContextHolder } from './_tsup-dts-rollup.mjs';
74
- export { InjectableTokenMeta } from './_tsup-dts-rollup.mjs';
75
- export { Container } from './_tsup-dts-rollup.mjs';
76
- export { CommanderApplicationOptions_alias_1 as CommanderApplicationOptions } from './_tsup-dts-rollup.mjs';
77
- export { CommanderApplication_alias_1 as CommanderApplication } from './_tsup-dts-rollup.mjs';
78
- export { CommanderFactory_alias_1 as CommanderFactory } from './_tsup-dts-rollup.mjs';
79
- export { Command } from './_tsup-dts-rollup.mjs';
80
- export { CommandOptions } from './_tsup-dts-rollup.mjs';
81
- export { CliModule } from './_tsup-dts-rollup.mjs';
82
- export { CliModuleOptions } from './_tsup-dts-rollup.mjs';
83
- export { Module } from './_tsup-dts-rollup.mjs';
84
- export { CommandHandler } from './_tsup-dts-rollup.mjs';
85
- export { getCommandMetadata } from './_tsup-dts-rollup.mjs';
86
- export { extractCommandMetadata } from './_tsup-dts-rollup.mjs';
87
- export { hasCommandMetadata } from './_tsup-dts-rollup.mjs';
88
- export { CommandMetadataKey } from './_tsup-dts-rollup.mjs';
89
- export { CommandMetadata } from './_tsup-dts-rollup.mjs';
90
- export { getCliModuleMetadata } from './_tsup-dts-rollup.mjs';
91
- export { extractCliModuleMetadata } from './_tsup-dts-rollup.mjs';
92
- export { hasCliModuleMetadata } from './_tsup-dts-rollup.mjs';
93
- export { CliModuleMetadataKey } from './_tsup-dts-rollup.mjs';
94
- export { CliModuleMetadata } from './_tsup-dts-rollup.mjs';
95
- export { CommandWithMetadata } from './_tsup-dts-rollup.mjs';
96
- export { ModuleLoaderService } from './_tsup-dts-rollup.mjs';
97
- export { ParsedCliArgs } from './_tsup-dts-rollup.mjs';
98
- export { CliParserService } from './_tsup-dts-rollup.mjs';
1
+ import { ClassType, ClassTypeWithInstance, Container, InjectionToken, NaviosModule } from "@navios/core";
2
+ import { ZodObject } from "zod";
3
+ export * from "@navios/core";
4
+
5
+ //#region src/commander.application.d.mts
6
+
7
+ /**
8
+ * Configuration options for CommanderApplication.
9
+ *
10
+ * @public
11
+ */
12
+ interface CommanderApplicationOptions {}
13
+ /**
14
+ * Main application class for managing CLI command execution.
15
+ *
16
+ * This class handles module loading, command registration, and command execution.
17
+ * It provides both programmatic and CLI-based command execution capabilities.
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * const app = await CommanderFactory.create(AppModule)
22
+ * await app.init()
23
+ * await app.run(process.argv)
24
+ * ```
25
+ */
26
+ declare class CommanderApplication {
27
+ private moduleLoader;
28
+ private cliParser;
29
+ protected container: Container;
30
+ private appModule;
31
+ private options;
32
+ /**
33
+ * Indicates whether the application has been initialized.
34
+ * Set to `true` after `init()` is called successfully.
35
+ */
36
+ isInitialized: boolean;
37
+ /**
38
+ * @internal
39
+ * Sets up the application with the provided module and options.
40
+ * This is called automatically by CommanderFactory.create().
41
+ */
42
+ setup(appModule: ClassTypeWithInstance<NaviosModule>, options?: CommanderApplicationOptions): Promise<void>;
43
+ /**
44
+ * Gets the dependency injection container used by this application.
45
+ *
46
+ * @returns The Container instance
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * const container = app.getContainer()
51
+ * const service = await container.get(MyService)
52
+ * ```
53
+ */
54
+ getContainer(): Container;
55
+ /**
56
+ * Initializes the application by loading all modules and registering commands.
57
+ *
58
+ * This method must be called before executing commands or running the CLI.
59
+ * It traverses the module tree, loads all imported modules, and collects command metadata.
60
+ *
61
+ * @throws {Error} If the app module is not set (setup() was not called)
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * const app = await CommanderFactory.create(AppModule)
66
+ * await app.init() // Must be called before run() or executeCommand()
67
+ * ```
68
+ */
69
+ init(): Promise<void>;
70
+ /**
71
+ * Executes a command programmatically with the provided options.
72
+ *
73
+ * This method is useful for testing, automation, or programmatic workflows.
74
+ * The options will be validated against the command's Zod schema if one is provided.
75
+ *
76
+ * @param commandPath - The command path (e.g., 'greet', 'user:create')
77
+ * @param options - The command options object (will be validated if schema exists)
78
+ * @throws {Error} If the application is not initialized
79
+ * @throws {Error} If the command is not found
80
+ * @throws {Error} If the command does not implement the execute method
81
+ * @throws {ZodError} If options validation fails
82
+ *
83
+ * @example
84
+ * ```typescript
85
+ * await app.executeCommand('greet', {
86
+ * name: 'World',
87
+ * greeting: 'Hi'
88
+ * })
89
+ * ```
90
+ */
91
+ executeCommand(commandPath: string, options?: any): Promise<void>;
92
+ /**
93
+ * Gets all registered commands with their paths and class references.
94
+ *
95
+ * @returns An array of objects containing the command path and class
96
+ *
97
+ * @example
98
+ * ```typescript
99
+ * const commands = app.getAllCommands()
100
+ * commands.forEach(({ path }) => {
101
+ * console.log(`Available: ${path}`)
102
+ * })
103
+ * ```
104
+ */
105
+ getAllCommands(): {
106
+ path: string;
107
+ class: ClassTypeWithInstance<any>;
108
+ }[];
109
+ /**
110
+ * Runs the CLI application by parsing command-line arguments and executing the appropriate command.
111
+ *
112
+ * This is the main entry point for CLI usage. It parses `argv`, validates options,
113
+ * and executes the matching command. Supports help command (`help`, `--help`, `-h`)
114
+ * which displays all available commands.
115
+ *
116
+ * @param argv - Command-line arguments array (defaults to `process.argv`)
117
+ * @throws {Error} If the application is not initialized
118
+ * @throws {Error} If no command is provided
119
+ * @throws {Error} If the command is not found
120
+ * @throws {ZodError} If options validation fails
121
+ *
122
+ * @example
123
+ * ```typescript
124
+ * // Parse and execute from process.argv
125
+ * await app.run()
126
+ *
127
+ * // Or provide custom arguments
128
+ * await app.run(['node', 'cli.js', 'greet', '--name', 'World'])
129
+ * ```
130
+ */
131
+ run(argv?: string[]): Promise<void>;
132
+ /**
133
+ * @internal
134
+ * Disposes of resources used by the application.
135
+ */
136
+ dispose(): Promise<void>;
137
+ /**
138
+ * Closes the application and cleans up resources.
139
+ *
140
+ * This should be called when the application is no longer needed to free up resources.
141
+ *
142
+ * @example
143
+ * ```typescript
144
+ * await app.run(process.argv)
145
+ * await app.close()
146
+ * ```
147
+ */
148
+ close(): Promise<void>;
149
+ }
150
+ //#endregion
151
+ //#region src/commander.factory.d.mts
152
+ /**
153
+ * Factory class for creating and configuring CLI applications.
154
+ *
155
+ * @example
156
+ * ```typescript
157
+ * import { CommanderFactory } from '@navios/commander'
158
+ * import { AppModule } from './app.module'
159
+ *
160
+ * async function bootstrap() {
161
+ * const app = await CommanderFactory.create(AppModule)
162
+ * await app.init()
163
+ * await app.run(process.argv)
164
+ * await app.close()
165
+ * }
166
+ * ```
167
+ */
168
+ declare class CommanderFactory {
169
+ /**
170
+ * Creates a new CommanderApplication instance and configures it with the provided module.
171
+ *
172
+ * @param appModule - The root CLI module class that contains commands and/or imports other modules
173
+ * @param options - Optional configuration options for the application
174
+ * @returns A promise that resolves to a configured CommanderApplication instance
175
+ *
176
+ * @example
177
+ * ```typescript
178
+ * const app = await CommanderFactory.create(AppModule)
179
+ * await app.init()
180
+ * ```
181
+ */
182
+ static create(appModule: ClassTypeWithInstance<NaviosModule>, options?: CommanderApplicationOptions): Promise<CommanderApplication>;
183
+ }
184
+ //#endregion
185
+ //#region src/decorators/command.decorator.d.mts
186
+ /**
187
+ * Options for the `@Command` decorator.
188
+ *
189
+ * @public
190
+ */
191
+ interface CommandOptions {
192
+ /**
193
+ * The command path that users will invoke from the CLI.
194
+ * Can be a single word (e.g., 'greet') or multi-word with colons (e.g., 'user:create', 'db:migrate').
195
+ */
196
+ path: string;
197
+ /**
198
+ * Optional Zod schema for validating command options.
199
+ * If provided, options will be validated and parsed according to this schema.
200
+ */
201
+ optionsSchema?: ZodObject;
202
+ }
203
+ /**
204
+ * Decorator that marks a class as a CLI command.
205
+ *
206
+ * The decorated class must implement the `CommandHandler` interface with an `execute` method.
207
+ * The command will be automatically registered when its module is loaded.
208
+ *
209
+ * @param options - Configuration options for the command
210
+ * @returns A class decorator function
211
+ *
212
+ * @example
213
+ * ```typescript
214
+ * import { Command, CommandHandler } from '@navios/commander'
215
+ * import { z } from 'zod'
216
+ *
217
+ * const optionsSchema = z.object({
218
+ * name: z.string(),
219
+ * greeting: z.string().optional().default('Hello')
220
+ * })
221
+ *
222
+ * @Command({
223
+ * path: 'greet',
224
+ * optionsSchema: optionsSchema
225
+ * })
226
+ * export class GreetCommand implements CommandHandler<z.infer<typeof optionsSchema>> {
227
+ * async execute(options) {
228
+ * console.log(`${options.greeting}, ${options.name}!`)
229
+ * }
230
+ * }
231
+ * ```
232
+ */
233
+ declare function Command({
234
+ path,
235
+ optionsSchema
236
+ }: CommandOptions): (target: ClassType, context: ClassDecoratorContext) => ClassType;
237
+ //#endregion
238
+ //#region src/decorators/cli-module.decorator.d.mts
239
+ /**
240
+ * Options for the `@CliModule` decorator.
241
+ *
242
+ * @public
243
+ */
244
+ interface CliModuleOptions {
245
+ /**
246
+ * Array or Set of command classes to register in this module.
247
+ * Commands must be decorated with `@Command`.
248
+ */
249
+ commands?: ClassType[] | Set<ClassType>;
250
+ /**
251
+ * Array or Set of other CLI modules to import.
252
+ * Imported modules' commands will be available in this module.
253
+ */
254
+ imports?: ClassType[] | Set<ClassType>;
255
+ }
256
+ /**
257
+ * Decorator that marks a class as a CLI module.
258
+ *
259
+ * Modules organize commands and can import other modules to compose larger CLI applications.
260
+ * The module can optionally implement `NaviosModule` interface for lifecycle hooks.
261
+ *
262
+ * @param options - Configuration options for the module
263
+ * @returns A class decorator function
264
+ *
265
+ * @example
266
+ * ```typescript
267
+ * import { CliModule } from '@navios/commander'
268
+ * import { GreetCommand } from './greet.command'
269
+ * import { UserModule } from './user.module'
270
+ *
271
+ * @CliModule({
272
+ * commands: [GreetCommand],
273
+ * imports: [UserModule]
274
+ * })
275
+ * export class AppModule {}
276
+ * ```
277
+ */
278
+ declare function CliModule({
279
+ commands,
280
+ imports
281
+ }?: CliModuleOptions): (target: ClassType, context: ClassDecoratorContext) => ClassType;
282
+ //#endregion
283
+ //#region src/interfaces/command-handler.interface.d.mts
284
+ /**
285
+ * Interface that all command classes must implement.
286
+ *
287
+ * Commands decorated with `@Command` must implement this interface.
288
+ * The `execute` method is called when the command is invoked.
289
+ *
290
+ * @template TOptions - The type of options that the command accepts
291
+ *
292
+ * @example
293
+ * ```typescript
294
+ * import { Command, CommandHandler } from '@navios/commander'
295
+ * import { z } from 'zod'
296
+ *
297
+ * const optionsSchema = z.object({
298
+ * name: z.string()
299
+ * })
300
+ *
301
+ * type Options = z.infer<typeof optionsSchema>
302
+ *
303
+ * @Command({ path: 'greet', optionsSchema })
304
+ * export class GreetCommand implements CommandHandler<Options> {
305
+ * async execute(options: Options) {
306
+ * console.log(`Hello, ${options.name}!`)
307
+ * }
308
+ * }
309
+ * ```
310
+ */
311
+ interface CommandHandler<TOptions = any> {
312
+ /**
313
+ * Executes the command with the provided options.
314
+ *
315
+ * @param options - The validated command options (validated against the command's schema if provided)
316
+ * @returns A promise or void
317
+ */
318
+ execute(options: TOptions): void | Promise<void>;
319
+ }
320
+ //#endregion
321
+ //#region src/metadata/command.metadata.d.mts
322
+ /**
323
+ * @internal
324
+ * Symbol key used to store command metadata on classes.
325
+ */
326
+ declare const CommandMetadataKey: unique symbol;
327
+ /**
328
+ * Metadata associated with a command.
329
+ *
330
+ * @public
331
+ */
332
+ interface CommandMetadata {
333
+ /**
334
+ * The command path (e.g., 'greet', 'user:create').
335
+ */
336
+ path: string;
337
+ /**
338
+ * Optional Zod schema for validating command options.
339
+ */
340
+ optionsSchema?: ZodObject;
341
+ /**
342
+ * Map of custom attributes that can be attached to the command.
343
+ */
344
+ customAttributes: Map<string | symbol, any>;
345
+ }
346
+ /**
347
+ * Gets or creates command metadata for a class.
348
+ *
349
+ * @internal
350
+ * @param target - The command class
351
+ * @param context - The decorator context
352
+ * @param path - The command path
353
+ * @param optionsSchema - Optional Zod schema
354
+ * @returns The command metadata
355
+ */
356
+ declare function getCommandMetadata(target: ClassType, context: ClassDecoratorContext, path: string, optionsSchema?: ZodObject): CommandMetadata;
357
+ /**
358
+ * Extracts command metadata from a class.
359
+ *
360
+ * @param target - The command class
361
+ * @returns The command metadata
362
+ * @throws {Error} If the class is not decorated with @Command
363
+ *
364
+ * @example
365
+ * ```typescript
366
+ * const metadata = extractCommandMetadata(GreetCommand)
367
+ * console.log(metadata.path) // 'greet'
368
+ * ```
369
+ */
370
+ declare function extractCommandMetadata(target: ClassType): CommandMetadata;
371
+ /**
372
+ * Checks if a class has command metadata.
373
+ *
374
+ * @param target - The class to check
375
+ * @returns `true` if the class is decorated with @Command, `false` otherwise
376
+ */
377
+ declare function hasCommandMetadata(target: ClassType): boolean;
378
+ //#endregion
379
+ //#region src/interfaces/commander-execution-context.interface.d.mts
380
+ /**
381
+ * Execution context for a command execution.
382
+ *
383
+ * Provides access to command metadata, path, and validated options during command execution.
384
+ * This context is automatically injected and available via the `CommandExecutionContext` token.
385
+ *
386
+ * @example
387
+ * ```typescript
388
+ * import { inject, Injectable } from '@navios/di'
389
+ * import { CommandExecutionContext } from '@navios/commander'
390
+ *
391
+ * @Injectable()
392
+ * class CommandLogger {
393
+ * private ctx = inject(CommandExecutionContext)
394
+ *
395
+ * log() {
396
+ * console.log('Command:', this.ctx.getCommandPath())
397
+ * console.log('Options:', this.ctx.getOptions())
398
+ * }
399
+ * }
400
+ * ```
401
+ */
402
+ declare class CommanderExecutionContext {
403
+ private readonly command;
404
+ private readonly commandPath;
405
+ private readonly options;
406
+ /**
407
+ * @internal
408
+ * Creates a new execution context.
409
+ */
410
+ constructor(command: CommandMetadata, commandPath: string, options: any);
411
+ /**
412
+ * Gets the command metadata.
413
+ *
414
+ * @returns The command metadata including path and options schema
415
+ */
416
+ getCommand(): CommandMetadata;
417
+ /**
418
+ * Gets the command path that was invoked.
419
+ *
420
+ * @returns The command path (e.g., 'greet', 'user:create')
421
+ */
422
+ getCommandPath(): string;
423
+ /**
424
+ * Gets the validated command options.
425
+ *
426
+ * Options are validated against the command's Zod schema if one was provided.
427
+ *
428
+ * @returns The validated options object
429
+ */
430
+ getOptions(): any;
431
+ }
432
+ //#endregion
433
+ //#region src/metadata/cli-module.metadata.d.mts
434
+ /**
435
+ * @internal
436
+ * Symbol key used to store CLI module metadata on classes.
437
+ */
438
+ declare const CliModuleMetadataKey: unique symbol;
439
+ /**
440
+ * Metadata associated with a CLI module.
441
+ *
442
+ * @public
443
+ */
444
+ interface CliModuleMetadata {
445
+ /**
446
+ * Set of command classes registered in this module.
447
+ */
448
+ commands: Set<ClassType>;
449
+ /**
450
+ * Set of other modules imported by this module.
451
+ */
452
+ imports: Set<ClassType>;
453
+ /**
454
+ * Map of custom attributes that can be attached to the module.
455
+ */
456
+ customAttributes: Map<string | symbol, any>;
457
+ }
458
+ /**
459
+ * Gets or creates CLI module metadata for a class.
460
+ *
461
+ * @internal
462
+ * @param target - The module class
463
+ * @param context - The decorator context
464
+ * @returns The module metadata
465
+ */
466
+ declare function getCliModuleMetadata(target: ClassType, context: ClassDecoratorContext): CliModuleMetadata;
467
+ /**
468
+ * Extracts CLI module metadata from a class.
469
+ *
470
+ * @param target - The module class
471
+ * @returns The module metadata
472
+ * @throws {Error} If the class is not decorated with @CliModule
473
+ *
474
+ * @example
475
+ * ```typescript
476
+ * const metadata = extractCliModuleMetadata(AppModule)
477
+ * console.log(metadata.commands.size) // Number of commands
478
+ * ```
479
+ */
480
+ declare function extractCliModuleMetadata(target: ClassType): CliModuleMetadata;
481
+ /**
482
+ * Checks if a class has CLI module metadata.
483
+ *
484
+ * @param target - The class to check
485
+ * @returns `true` if the class is decorated with @CliModule, `false` otherwise
486
+ */
487
+ declare function hasCliModuleMetadata(target: ClassType): boolean;
488
+ //#endregion
489
+ //#region src/services/module-loader.service.d.mts
490
+ /**
491
+ * Command class with its associated metadata.
492
+ *
493
+ * @public
494
+ */
495
+ interface CommandWithMetadata {
496
+ /**
497
+ * The command class constructor.
498
+ */
499
+ class: ClassTypeWithInstance<CommandHandler>;
500
+ /**
501
+ * The command metadata including path and options schema.
502
+ */
503
+ metadata: CommandMetadata;
504
+ }
505
+ /**
506
+ * Service for loading and managing CLI modules and commands.
507
+ *
508
+ * Handles module traversal, command registration, and metadata collection.
509
+ * This service is used internally by CommanderApplication.
510
+ *
511
+ * @public
512
+ */
513
+ declare class CliModuleLoaderService {
514
+ protected container: Container;
515
+ private modulesMetadata;
516
+ private loadedModules;
517
+ private commandsMetadata;
518
+ private initialized;
519
+ /**
520
+ * Loads all modules starting from the root app module.
521
+ *
522
+ * Traverses the module tree, loads imported modules, and collects command metadata.
523
+ *
524
+ * @param appModule - The root CLI module
525
+ */
526
+ loadModules(appModule: ClassTypeWithInstance<NaviosModule>): Promise<void>;
527
+ private traverseModules;
528
+ private mergeMetadata;
529
+ /**
530
+ * Gets all loaded module metadata.
531
+ *
532
+ * @returns Map of module names to their metadata
533
+ */
534
+ getAllModules(): Map<string, CliModuleMetadata>;
535
+ /**
536
+ * Gets all command classes indexed by command class name.
537
+ *
538
+ * @returns Map of command class names to command classes
539
+ */
540
+ getAllCommands(): Map<string, ClassTypeWithInstance<any>>;
541
+ /**
542
+ * Get all commands with their metadata, indexed by command path.
543
+ * This is populated during loadModules, so path information is available
544
+ * before parsing CLI argv.
545
+ */
546
+ getAllCommandsWithMetadata(): Map<string, CommandWithMetadata>;
547
+ /**
548
+ * Get a command by its path, with metadata already extracted.
549
+ * Returns undefined if command is not found.
550
+ */
551
+ getCommandByPath(path: string): CommandWithMetadata | undefined;
552
+ /**
553
+ * Disposes of all loaded modules and commands, clearing internal state.
554
+ */
555
+ dispose(): void;
556
+ }
557
+ //#endregion
558
+ //#region src/services/cli-parser.service.d.mts
559
+ /**
560
+ * Result of parsing command-line arguments.
561
+ *
562
+ * @public
563
+ */
564
+ interface ParsedCliArgs {
565
+ /**
566
+ * The command path (e.g., 'greet', 'user:create').
567
+ * Multi-word commands are joined with spaces.
568
+ */
569
+ command: string;
570
+ /**
571
+ * Parsed options as key-value pairs.
572
+ * Keys are converted from kebab-case to camelCase.
573
+ */
574
+ options: Record<string, any>;
575
+ /**
576
+ * Positional arguments that don't match any option flags.
577
+ */
578
+ positionals: string[];
579
+ }
580
+ /**
581
+ * Service for parsing command-line arguments.
582
+ *
583
+ * Handles parsing of various CLI argument formats including:
584
+ * - Long options: `--key value` or `--key=value`
585
+ * - Short options: `-k value` or `-abc` (multiple flags)
586
+ * - Boolean flags
587
+ * - Array options
588
+ * - Positional arguments
589
+ *
590
+ * @public
591
+ */
592
+ declare class CliParserService {
593
+ /**
594
+ * Parses command-line arguments from process.argv
595
+ * Commands can be multi-word (e.g., 'db migrate', 'cache clear')
596
+ * Expected format: node script.js command [subcommand...] --flag value --boolean-flag positional1 positional2
597
+ *
598
+ * @param argv - Array of command-line arguments (typically process.argv)
599
+ * @param optionsSchema - Optional Zod schema to determine boolean flags and option types
600
+ * @returns Parsed command (space-separated if multi-word), options, and positional arguments
601
+ */
602
+ parse(argv: string[], optionsSchema?: ZodObject): ParsedCliArgs;
603
+ /**
604
+ * Converts kebab-case to camelCase
605
+ */
606
+ private camelCase;
607
+ /**
608
+ * Attempts to parse string values into appropriate types
609
+ */
610
+ private parseValue;
611
+ /**
612
+ * Extracts boolean field names from a Zod schema
613
+ * Handles ZodObject, ZodOptional, and ZodDefault wrappers
614
+ */
615
+ private extractBooleanFields;
616
+ /**
617
+ * Extracts array field names from a Zod schema
618
+ * Handles ZodObject, ZodOptional, and ZodDefault wrappers
619
+ */
620
+ private extractArrayFields;
621
+ /**
622
+ * Checks if a Zod schema represents a boolean type
623
+ * Unwraps ZodOptional and ZodDefault
624
+ */
625
+ private isSchemaBoolean;
626
+ /**
627
+ * Checks if a Zod schema represents an array type
628
+ * Unwraps ZodOptional and ZodDefault
629
+ */
630
+ private isSchemaArray;
631
+ /**
632
+ * Formats help text listing all available commands.
633
+ *
634
+ * @param commands - Array of command objects with path and class
635
+ * @returns Formatted string listing all commands
636
+ */
637
+ formatCommandList(commands: Array<{
638
+ path: string;
639
+ class: any;
640
+ }>): string;
641
+ }
642
+ //#endregion
643
+ //#region src/tokens/execution-context.token.d.mts
644
+ /**
645
+ * Injection token for accessing the current command execution context.
646
+ *
647
+ * Use this token with `inject()` to access the `CommanderExecutionContext` in services
648
+ * that need information about the currently executing command.
649
+ *
650
+ * @example
651
+ * ```typescript
652
+ * import { inject, Injectable } from '@navios/di'
653
+ * import { CommandExecutionContext } from '@navios/commander'
654
+ *
655
+ * @Injectable()
656
+ * class MyService {
657
+ * private ctx = inject(CommandExecutionContext)
658
+ *
659
+ * doSomething() {
660
+ * const commandPath = this.ctx.getCommandPath()
661
+ * const options = this.ctx.getOptions()
662
+ * // Use context information...
663
+ * }
664
+ * }
665
+ * ```
666
+ */
667
+ declare const CommandExecutionContext: InjectionToken<CommanderExecutionContext, undefined, false>;
668
+ //#endregion
669
+ export { CliModule, CliModuleLoaderService, CliModuleMetadata, CliModuleMetadataKey, CliModuleOptions, CliParserService, Command, CommandExecutionContext, CommandHandler, CommandMetadata, CommandMetadataKey, CommandOptions, CommandWithMetadata, CommanderApplication, CommanderApplicationOptions, CommanderExecutionContext, CommanderFactory, ParsedCliArgs, extractCliModuleMetadata, extractCommandMetadata, getCliModuleMetadata, getCommandMetadata, hasCliModuleMetadata, hasCommandMetadata };
670
+ //# sourceMappingURL=index.d.mts.map