@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/CHANGELOG.md ADDED
@@ -0,0 +1,32 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.7.0] - 2025-12-18
9
+
10
+ ### Added
11
+
12
+ - **Comprehensive JSDoc Documentation**: Added detailed JSDoc comments to all public APIs including:
13
+ - `CommanderFactory` class and `create` method
14
+ - `CommanderApplication` class and all methods (`init`, `run`, `executeCommand`, `getAllCommands`, `getContainer`, `close`)
15
+ - `Command` decorator function and `CommandOptions` interface
16
+ - `CliModule` decorator function and `CliModuleOptions` interface
17
+ - `CommandHandler` interface with generic type parameter
18
+ - `CommanderExecutionContext` class and all methods (`getCommand`, `getCommandPath`, `getOptions`)
19
+ - `CommandExecutionContext` injection token
20
+ - `CommandMetadata` and `CliModuleMetadata` interfaces
21
+ - Metadata utility functions (`getCommandMetadata`, `extractCommandMetadata`, `hasCommandMetadata`, `getCliModuleMetadata`, `extractCliModuleMetadata`, `hasCliModuleMetadata`)
22
+ - `CliParserService` class and `ParsedCliArgs` interface
23
+ - `CliModuleLoaderService` class and `CommandWithMetadata` interface
24
+
25
+ ### Documentation
26
+
27
+ - Complete JSDoc comments for better IDE support and developer experience
28
+ - Enhanced type information and parameter descriptions
29
+ - Added usage examples in JSDoc comments for all public APIs
30
+ - Improved discoverability of API features through comprehensive documentation
31
+ - Updated README to accurately reflect the ExecutionContext API
32
+
package/README.md CHANGED
@@ -23,6 +23,7 @@ Commands are defined using the `@Command` decorator. Each command must implement
23
23
 
24
24
  ```typescript
25
25
  import { Command, CommandHandler } from '@navios/commander'
26
+
26
27
  import { z } from 'zod'
27
28
 
28
29
  const greetOptionsSchema = z.object({
@@ -49,6 +50,7 @@ Modules organize commands and can import other modules:
49
50
 
50
51
  ```typescript
51
52
  import { CliModule } from '@navios/commander'
53
+
52
54
  import { GreetCommand } from './greet.command'
53
55
 
54
56
  @CliModule({
@@ -63,6 +65,7 @@ Use `CommanderFactory` to create and run your CLI application:
63
65
 
64
66
  ```typescript
65
67
  import { CommanderFactory } from '@navios/commander'
68
+
66
69
  import { AppModule } from './app.module'
67
70
 
68
71
  async function bootstrap() {
@@ -87,8 +90,9 @@ node dist/cli.js greet --name World --greeting Hi
87
90
  ### Advanced Example with Dependency Injection
88
91
 
89
92
  ```typescript
90
- import { Command, CommandHandler, CliModule } from '@navios/commander'
91
- import { Injectable, inject } from '@navios/di'
93
+ import { CliModule, Command, CommandHandler } from '@navios/commander'
94
+ import { inject, Injectable } from '@navios/di'
95
+
92
96
  import { z } from 'zod'
93
97
 
94
98
  // Service
@@ -108,7 +112,9 @@ const userOptionsSchema = z.object({
108
112
  path: 'user:show',
109
113
  optionsSchema: userOptionsSchema,
110
114
  })
111
- export class ShowUserCommand implements CommandHandler<z.infer<typeof userOptionsSchema>> {
115
+ export class ShowUserCommand implements CommandHandler<
116
+ z.infer<typeof userOptionsSchema>
117
+ > {
112
118
  private userService = inject(UserService)
113
119
 
114
120
  async execute(options: { userId: string }) {
@@ -129,6 +135,43 @@ export class UserModule {}
129
135
  export class AppModule {}
130
136
  ```
131
137
 
138
+ ### Accessing ExecutionContext
139
+
140
+ The `ExecutionContext` provides access to the current command execution information, including the module metadata, command metadata, command path, and options. This is useful for middleware, guards, or any service that needs context about the current command execution.
141
+
142
+ ```typescript
143
+ import { Command, CommandHandler, CommandExecutionContext } from '@navios/commander'
144
+ import { inject, Injectable } from '@navios/di'
145
+
146
+ @Injectable()
147
+ class CommandLogger {
148
+ private executionContext = inject(CommandExecutionContext)
149
+
150
+ logCommandInfo() {
151
+ const ctx = this.executionContext
152
+ console.log('Command Path:', ctx.getCommandPath())
153
+ console.log('Command Options:', ctx.getOptions())
154
+ console.log('Command Metadata:', ctx.getCommand())
155
+ }
156
+ }
157
+
158
+ @Command({ path: 'example' })
159
+ export class ExampleCommand implements CommandHandler {
160
+ private logger = inject(CommandLogger)
161
+
162
+ async execute(options: any) {
163
+ this.logger.logCommandInfo()
164
+ // Your command logic here
165
+ }
166
+ }
167
+ ```
168
+
169
+ The `ExecutionContext` provides the following methods:
170
+
171
+ - `getCommand()` - Returns the command metadata
172
+ - `getCommandPath()` - Returns the command path (e.g., 'user:create')
173
+ - `getOptions()` - Returns the validated command options
174
+
132
175
  ### Listing All Commands
133
176
 
134
177
  ```typescript
@@ -150,6 +193,7 @@ For advanced use cases where you need to execute commands programmatically (e.g.
150
193
 
151
194
  ```typescript
152
195
  import { CommanderFactory } from '@navios/commander'
196
+
153
197
  import { AppModule } from './app.module'
154
198
 
155
199
  async function bootstrap() {
@@ -169,6 +213,7 @@ bootstrap()
169
213
  ```
170
214
 
171
215
  This is useful for:
216
+
172
217
  - Unit and integration testing
173
218
  - Building CLI tools that wrap other CLI tools
174
219
  - Programmatic automation workflows
@@ -182,6 +227,7 @@ This is useful for:
182
227
  Defines a CLI command.
183
228
 
184
229
  **Options:**
230
+
185
231
  - `path: string` - The command path (e.g., 'user:create', 'db:migrate')
186
232
  - `optionsSchema?: ZodSchema` - Optional Zod schema for validating command options
187
233
 
@@ -190,6 +236,7 @@ Defines a CLI command.
190
236
  Defines a CLI module.
191
237
 
192
238
  **Options:**
239
+
193
240
  - `commands?: ClassType[]` - Array of command classes
194
241
  - `imports?: ClassType[]` - Array of other modules to import
195
242
 
@@ -205,14 +252,13 @@ interface CommandHandler<TOptions = any> {
205
252
  }
206
253
  ```
207
254
 
208
- #### `CliModule`
255
+ #### `Module` (alias for `NaviosModule`)
209
256
 
210
- Optional lifecycle hooks for modules.
257
+ Optional lifecycle hooks for modules. This is an alias for `NaviosModule` from `@navios/core`.
211
258
 
212
259
  ```typescript
213
- interface CliModule {
214
- onModuleInit?(): void | Promise<void>
215
- onModuleDestroy?(): void | Promise<void>
260
+ interface NaviosModule {
261
+ onModuleInit?: () => Promise<void> | void
216
262
  }
217
263
  ```
218
264
 
@@ -223,6 +269,7 @@ interface CliModule {
223
269
  Factory class for creating CLI applications.
224
270
 
225
271
  **Methods:**
272
+
226
273
  - `static async create(appModule, options?)` - Creates a new CommanderApplication
227
274
 
228
275
  #### `CommanderApplication`
@@ -230,6 +277,7 @@ Factory class for creating CLI applications.
230
277
  Main application class.
231
278
 
232
279
  **Methods:**
280
+
233
281
  - `async init()` - Initializes the application
234
282
  - `async run(argv)` - Parses command-line arguments and executes the appropriate command (default usage)
235
283
  - `async executeCommand(path, options?)` - Executes a command programmatically with options (advanced usage)
@@ -1,29 +1,147 @@
1
- import type { ClassTypeWithInstance } from '@navios/di';
2
- import { Container } from '@navios/di';
3
- import type { Module } from './interfaces/index.mjs';
1
+ import type { ClassTypeWithInstance, NaviosModule } from '@navios/core';
2
+ import { Container } from '@navios/core';
3
+ /**
4
+ * Configuration options for CommanderApplication.
5
+ *
6
+ * @public
7
+ */
4
8
  export interface CommanderApplicationOptions {
5
9
  }
10
+ /**
11
+ * Main application class for managing CLI command execution.
12
+ *
13
+ * This class handles module loading, command registration, and command execution.
14
+ * It provides both programmatic and CLI-based command execution capabilities.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const app = await CommanderFactory.create(AppModule)
19
+ * await app.init()
20
+ * await app.run(process.argv)
21
+ * ```
22
+ */
6
23
  export declare class CommanderApplication {
7
24
  private moduleLoader;
8
25
  private cliParser;
9
26
  protected container: Container;
10
27
  private appModule;
11
28
  private options;
29
+ /**
30
+ * Indicates whether the application has been initialized.
31
+ * Set to `true` after `init()` is called successfully.
32
+ */
12
33
  isInitialized: boolean;
13
- setup(appModule: ClassTypeWithInstance<Module>, options?: CommanderApplicationOptions): Promise<void>;
34
+ /**
35
+ * @internal
36
+ * Sets up the application with the provided module and options.
37
+ * This is called automatically by CommanderFactory.create().
38
+ */
39
+ setup(appModule: ClassTypeWithInstance<NaviosModule>, options?: CommanderApplicationOptions): Promise<void>;
40
+ /**
41
+ * Gets the dependency injection container used by this application.
42
+ *
43
+ * @returns The Container instance
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * const container = app.getContainer()
48
+ * const service = await container.get(MyService)
49
+ * ```
50
+ */
14
51
  getContainer(): Container;
52
+ /**
53
+ * Initializes the application by loading all modules and registering commands.
54
+ *
55
+ * This method must be called before executing commands or running the CLI.
56
+ * It traverses the module tree, loads all imported modules, and collects command metadata.
57
+ *
58
+ * @throws {Error} If the app module is not set (setup() was not called)
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * const app = await CommanderFactory.create(AppModule)
63
+ * await app.init() // Must be called before run() or executeCommand()
64
+ * ```
65
+ */
15
66
  init(): Promise<void>;
67
+ /**
68
+ * Executes a command programmatically with the provided options.
69
+ *
70
+ * This method is useful for testing, automation, or programmatic workflows.
71
+ * The options will be validated against the command's Zod schema if one is provided.
72
+ *
73
+ * @param commandPath - The command path (e.g., 'greet', 'user:create')
74
+ * @param options - The command options object (will be validated if schema exists)
75
+ * @throws {Error} If the application is not initialized
76
+ * @throws {Error} If the command is not found
77
+ * @throws {Error} If the command does not implement the execute method
78
+ * @throws {ZodError} If options validation fails
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * await app.executeCommand('greet', {
83
+ * name: 'World',
84
+ * greeting: 'Hi'
85
+ * })
86
+ * ```
87
+ */
16
88
  executeCommand(commandPath: string, options?: any): Promise<void>;
89
+ /**
90
+ * Gets all registered commands with their paths and class references.
91
+ *
92
+ * @returns An array of objects containing the command path and class
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * const commands = app.getAllCommands()
97
+ * commands.forEach(({ path }) => {
98
+ * console.log(`Available: ${path}`)
99
+ * })
100
+ * ```
101
+ */
17
102
  getAllCommands(): {
18
103
  path: string;
19
104
  class: ClassTypeWithInstance<any>;
20
105
  }[];
21
106
  /**
22
- * Runs the CLI application by parsing process.argv and executing the command
23
- * @param argv - Command-line arguments (defaults to process.argv)
107
+ * Runs the CLI application by parsing command-line arguments and executing the appropriate command.
108
+ *
109
+ * This is the main entry point for CLI usage. It parses `argv`, validates options,
110
+ * and executes the matching command. Supports help command (`help`, `--help`, `-h`)
111
+ * which displays all available commands.
112
+ *
113
+ * @param argv - Command-line arguments array (defaults to `process.argv`)
114
+ * @throws {Error} If the application is not initialized
115
+ * @throws {Error} If no command is provided
116
+ * @throws {Error} If the command is not found
117
+ * @throws {ZodError} If options validation fails
118
+ *
119
+ * @example
120
+ * ```typescript
121
+ * // Parse and execute from process.argv
122
+ * await app.run()
123
+ *
124
+ * // Or provide custom arguments
125
+ * await app.run(['node', 'cli.js', 'greet', '--name', 'World'])
126
+ * ```
24
127
  */
25
128
  run(argv?: string[]): Promise<void>;
129
+ /**
130
+ * @internal
131
+ * Disposes of resources used by the application.
132
+ */
26
133
  dispose(): Promise<void>;
134
+ /**
135
+ * Closes the application and cleans up resources.
136
+ *
137
+ * This should be called when the application is no longer needed to free up resources.
138
+ *
139
+ * @example
140
+ * ```typescript
141
+ * await app.run(process.argv)
142
+ * await app.close()
143
+ * ```
144
+ */
27
145
  close(): Promise<void>;
28
146
  }
29
147
  //# sourceMappingURL=commander.application.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"commander.application.d.mts","sourceRoot":"","sources":["../../src/commander.application.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAkB,MAAM,YAAY,CAAA;AAEvE,OAAO,EAAE,SAAS,EAAsB,MAAM,YAAY,CAAA;AAE1D,OAAO,KAAK,EAAkB,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAIpE,MAAM,WAAW,2BAA2B;CAAG;AAE/C,qBACa,oBAAoB;IAC/B,OAAO,CAAC,YAAY,CAA8B;IAClD,OAAO,CAAC,SAAS,CAA2B;IAC5C,SAAS,CAAC,SAAS,YAAoB;IAEvC,OAAO,CAAC,SAAS,CAA6C;IAC9D,OAAO,CAAC,OAAO,CAAkC;IAEjD,aAAa,UAAQ;IAEf,KAAK,CACT,SAAS,EAAE,qBAAqB,CAAC,MAAM,CAAC,EACxC,OAAO,GAAE,2BAAgC;IAM3C,YAAY;IAIN,IAAI;IAUJ,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,GAAE,GAAQ;IAoC3D,cAAc;cAIJ,MAAM;eACL,qBAAqB,CAAC,GAAG,CAAC;;IAarC;;;OAGG;IACG,GAAG,CAAC,IAAI,GAAE,MAAM,EAAiB;IAgDjC,OAAO;IAMP,KAAK;CAGZ"}
1
+ {"version":3,"file":"commander.application.d.mts","sourceRoot":"","sources":["../../src/commander.application.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EAErB,YAAY,EACb,MAAM,cAAc,CAAA;AAErB,OAAO,EAAE,SAAS,EAAsB,MAAM,cAAc,CAAA;AAQ5D;;;;GAIG;AACH,MAAM,WAAW,2BAA2B;CAAG;AAE/C;;;;;;;;;;;;GAYG;AACH,qBACa,oBAAoB;IAC/B,OAAO,CAAC,YAAY,CAAiC;IACrD,OAAO,CAAC,SAAS,CAA2B;IAC5C,SAAS,CAAC,SAAS,YAAoB;IAEvC,OAAO,CAAC,SAAS,CAAmD;IACpE,OAAO,CAAC,OAAO,CAAkC;IAEjD;;;OAGG;IACH,aAAa,UAAQ;IAErB;;;;OAIG;IACG,KAAK,CACT,SAAS,EAAE,qBAAqB,CAAC,YAAY,CAAC,EAC9C,OAAO,GAAE,2BAAgC;IAM3C;;;;;;;;;;OAUG;IACH,YAAY;IAIZ;;;;;;;;;;;;;OAaG;IACG,IAAI;IAUV;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,GAAE,GAAQ;IAuD3D;;;;;;;;;;;;OAYG;IACH,cAAc;cAIJ,MAAM;eACL,qBAAqB,CAAC,GAAG,CAAC;;IAarC;;;;;;;;;;;;;;;;;;;;;OAqBG;IACG,GAAG,CAAC,IAAI,GAAE,MAAM,EAAiB;IAgDvC;;;OAGG;IACG,OAAO;IAMb;;;;;;;;;;OAUG;IACG,KAAK;CAGZ"}
@@ -1,8 +1,36 @@
1
- import type { ClassTypeWithInstance } from '@navios/di';
1
+ import type { ClassTypeWithInstance, NaviosModule } from '@navios/core';
2
2
  import type { CommanderApplicationOptions } from './commander.application.mjs';
3
- import type { Module } from './interfaces/index.mjs';
4
3
  import { CommanderApplication } from './commander.application.mjs';
4
+ /**
5
+ * Factory class for creating and configuring CLI applications.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { CommanderFactory } from '@navios/commander'
10
+ * import { AppModule } from './app.module'
11
+ *
12
+ * async function bootstrap() {
13
+ * const app = await CommanderFactory.create(AppModule)
14
+ * await app.init()
15
+ * await app.run(process.argv)
16
+ * await app.close()
17
+ * }
18
+ * ```
19
+ */
5
20
  export declare class CommanderFactory {
6
- static create(appModule: ClassTypeWithInstance<Module>, options?: CommanderApplicationOptions): Promise<CommanderApplication>;
21
+ /**
22
+ * Creates a new CommanderApplication instance and configures it with the provided module.
23
+ *
24
+ * @param appModule - The root CLI module class that contains commands and/or imports other modules
25
+ * @param options - Optional configuration options for the application
26
+ * @returns A promise that resolves to a configured CommanderApplication instance
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * const app = await CommanderFactory.create(AppModule)
31
+ * await app.init()
32
+ * ```
33
+ */
34
+ static create(appModule: ClassTypeWithInstance<NaviosModule>, options?: CommanderApplicationOptions): Promise<CommanderApplication>;
7
35
  }
8
36
  //# sourceMappingURL=commander.factory.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"commander.factory.d.mts","sourceRoot":"","sources":["../../src/commander.factory.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAIvD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,6BAA6B,CAAA;AAC9E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAEpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AAElE,qBAAa,gBAAgB;WACd,MAAM,CACjB,SAAS,EAAE,qBAAqB,CAAC,MAAM,CAAC,EACxC,OAAO,GAAE,2BAAgC;CAO5C"}
1
+ {"version":3,"file":"commander.factory.d.mts","sourceRoot":"","sources":["../../src/commander.factory.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAIvE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,6BAA6B,CAAA;AAE9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AAElE;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,gBAAgB;IAC3B;;;;;;;;;;;;OAYG;WACU,MAAM,CACjB,SAAS,EAAE,qBAAqB,CAAC,YAAY,CAAC,EAC9C,OAAO,GAAE,2BAAgC;CAO5C"}
@@ -1,7 +1,42 @@
1
- import type { ClassType } from '@navios/di';
1
+ import type { ClassType } from '@navios/core';
2
+ /**
3
+ * Options for the `@CliModule` decorator.
4
+ *
5
+ * @public
6
+ */
2
7
  export interface CliModuleOptions {
8
+ /**
9
+ * Array or Set of command classes to register in this module.
10
+ * Commands must be decorated with `@Command`.
11
+ */
3
12
  commands?: ClassType[] | Set<ClassType>;
13
+ /**
14
+ * Array or Set of other CLI modules to import.
15
+ * Imported modules' commands will be available in this module.
16
+ */
4
17
  imports?: ClassType[] | Set<ClassType>;
5
18
  }
19
+ /**
20
+ * Decorator that marks a class as a CLI module.
21
+ *
22
+ * Modules organize commands and can import other modules to compose larger CLI applications.
23
+ * The module can optionally implement `NaviosModule` interface for lifecycle hooks.
24
+ *
25
+ * @param options - Configuration options for the module
26
+ * @returns A class decorator function
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * import { CliModule } from '@navios/commander'
31
+ * import { GreetCommand } from './greet.command'
32
+ * import { UserModule } from './user.module'
33
+ *
34
+ * @CliModule({
35
+ * commands: [GreetCommand],
36
+ * imports: [UserModule]
37
+ * })
38
+ * export class AppModule {}
39
+ * ```
40
+ */
6
41
  export declare function CliModule({ commands, imports }?: CliModuleOptions): (target: ClassType, context: ClassDecoratorContext) => ClassType;
7
42
  //# sourceMappingURL=cli-module.decorator.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cli-module.decorator.d.mts","sourceRoot":"","sources":["../../../src/decorators/cli-module.decorator.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAM3C,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,EAAE,SAAS,EAAE,GAAG,GAAG,CAAC,SAAS,CAAC,CAAA;IACvC,OAAO,CAAC,EAAE,SAAS,EAAE,GAAG,GAAG,CAAC,SAAS,CAAC,CAAA;CACvC;AAED,wBAAgB,SAAS,CACvB,EAAE,QAAa,EAAE,OAAY,EAAE,GAAE,gBAGhC,IAEO,QAAQ,SAAS,EAAE,SAAS,qBAAqB,eAqB1D"}
1
+ {"version":3,"file":"cli-module.decorator.d.mts","sourceRoot":"","sources":["../../../src/decorators/cli-module.decorator.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAM7C;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,QAAQ,CAAC,EAAE,SAAS,EAAE,GAAG,GAAG,CAAC,SAAS,CAAC,CAAA;IACvC;;;OAGG;IACH,OAAO,CAAC,EAAE,SAAS,EAAE,GAAG,GAAG,CAAC,SAAS,CAAC,CAAA;CACvC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,SAAS,CACvB,EAAE,QAAa,EAAE,OAAY,EAAE,GAAE,gBAGhC,IAEO,QAAQ,SAAS,EAAE,SAAS,qBAAqB,eAqB1D"}
@@ -1,8 +1,51 @@
1
- import type { ClassType } from '@navios/di';
1
+ import type { ClassType } from '@navios/core';
2
2
  import type { ZodObject } from 'zod';
3
+ /**
4
+ * Options for the `@Command` decorator.
5
+ *
6
+ * @public
7
+ */
3
8
  export interface CommandOptions {
9
+ /**
10
+ * The command path that users will invoke from the CLI.
11
+ * Can be a single word (e.g., 'greet') or multi-word with colons (e.g., 'user:create', 'db:migrate').
12
+ */
4
13
  path: string;
14
+ /**
15
+ * Optional Zod schema for validating command options.
16
+ * If provided, options will be validated and parsed according to this schema.
17
+ */
5
18
  optionsSchema?: ZodObject;
6
19
  }
20
+ /**
21
+ * Decorator that marks a class as a CLI command.
22
+ *
23
+ * The decorated class must implement the `CommandHandler` interface with an `execute` method.
24
+ * The command will be automatically registered when its module is loaded.
25
+ *
26
+ * @param options - Configuration options for the command
27
+ * @returns A class decorator function
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * import { Command, CommandHandler } from '@navios/commander'
32
+ * import { z } from 'zod'
33
+ *
34
+ * const optionsSchema = z.object({
35
+ * name: z.string(),
36
+ * greeting: z.string().optional().default('Hello')
37
+ * })
38
+ *
39
+ * @Command({
40
+ * path: 'greet',
41
+ * optionsSchema: optionsSchema
42
+ * })
43
+ * export class GreetCommand implements CommandHandler<z.infer<typeof optionsSchema>> {
44
+ * async execute(options) {
45
+ * console.log(`${options.greeting}, ${options.name}!`)
46
+ * }
47
+ * }
48
+ * ```
49
+ */
7
50
  export declare function Command({ path, optionsSchema }: CommandOptions): (target: ClassType, context: ClassDecoratorContext) => ClassType;
8
51
  //# sourceMappingURL=command.decorator.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"command.decorator.d.mts","sourceRoot":"","sources":["../../../src/decorators/command.decorator.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAMpC,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,aAAa,CAAC,EAAE,SAAS,CAAA;CAC1B;AAED,wBAAgB,OAAO,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,EAAE,cAAc,IAC5C,QAAQ,SAAS,EAAE,SAAS,qBAAqB,eAenE"}
1
+ {"version":3,"file":"command.decorator.d.mts","sourceRoot":"","sources":["../../../src/decorators/command.decorator.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAMpC;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;;OAGG;IACH,aAAa,CAAC,EAAE,SAAS,CAAA;CAC1B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,OAAO,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,EAAE,cAAc,IAC5C,QAAQ,SAAS,EAAE,SAAS,qBAAqB,eAenE"}
@@ -1,8 +1,9 @@
1
- export * from '@navios/di';
1
+ export * from '@navios/core';
2
2
  export * from './commander.application.mjs';
3
3
  export * from './commander.factory.mjs';
4
4
  export * from './decorators/index.mjs';
5
5
  export * from './interfaces/index.mjs';
6
6
  export * from './metadata/index.mjs';
7
7
  export * from './services/index.mjs';
8
+ export * from './tokens/index.mjs';
8
9
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/index.mts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,6BAA6B,CAAA;AAC3C,cAAc,yBAAyB,CAAA;AACvC,cAAc,wBAAwB,CAAA;AACtC,cAAc,wBAAwB,CAAA;AACtC,cAAc,sBAAsB,CAAA;AACpC,cAAc,sBAAsB,CAAA"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/index.mts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAA;AAG5B,cAAc,6BAA6B,CAAA;AAC3C,cAAc,yBAAyB,CAAA;AACvC,cAAc,wBAAwB,CAAA;AACtC,cAAc,wBAAwB,CAAA;AACtC,cAAc,sBAAsB,CAAA;AACpC,cAAc,sBAAsB,CAAA;AACpC,cAAc,oBAAoB,CAAA"}
@@ -1,4 +1,37 @@
1
+ /**
2
+ * Interface that all command classes must implement.
3
+ *
4
+ * Commands decorated with `@Command` must implement this interface.
5
+ * The `execute` method is called when the command is invoked.
6
+ *
7
+ * @template TOptions - The type of options that the command accepts
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { Command, CommandHandler } from '@navios/commander'
12
+ * import { z } from 'zod'
13
+ *
14
+ * const optionsSchema = z.object({
15
+ * name: z.string()
16
+ * })
17
+ *
18
+ * type Options = z.infer<typeof optionsSchema>
19
+ *
20
+ * @Command({ path: 'greet', optionsSchema })
21
+ * export class GreetCommand implements CommandHandler<Options> {
22
+ * async execute(options: Options) {
23
+ * console.log(`Hello, ${options.name}!`)
24
+ * }
25
+ * }
26
+ * ```
27
+ */
1
28
  export interface CommandHandler<TOptions = any> {
29
+ /**
30
+ * Executes the command with the provided options.
31
+ *
32
+ * @param options - The validated command options (validated against the command's schema if provided)
33
+ * @returns A promise or void
34
+ */
2
35
  execute(options: TOptions): void | Promise<void>;
3
36
  }
4
37
  //# sourceMappingURL=command-handler.interface.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"command-handler.interface.d.mts","sourceRoot":"","sources":["../../../src/interfaces/command-handler.interface.mts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc,CAAC,QAAQ,GAAG,GAAG;IAC5C,OAAO,CAAC,OAAO,EAAE,QAAQ,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACjD"}
1
+ {"version":3,"file":"command-handler.interface.d.mts","sourceRoot":"","sources":["../../../src/interfaces/command-handler.interface.mts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,WAAW,cAAc,CAAC,QAAQ,GAAG,GAAG;IAC5C;;;;;OAKG;IACH,OAAO,CAAC,OAAO,EAAE,QAAQ,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACjD"}
@@ -0,0 +1,54 @@
1
+ import type { CommandMetadata } from '../metadata/command.metadata.mjs';
2
+ /**
3
+ * Execution context for a command execution.
4
+ *
5
+ * Provides access to command metadata, path, and validated options during command execution.
6
+ * This context is automatically injected and available via the `CommandExecutionContext` token.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { inject, Injectable } from '@navios/di'
11
+ * import { CommandExecutionContext } from '@navios/commander'
12
+ *
13
+ * @Injectable()
14
+ * class CommandLogger {
15
+ * private ctx = inject(CommandExecutionContext)
16
+ *
17
+ * log() {
18
+ * console.log('Command:', this.ctx.getCommandPath())
19
+ * console.log('Options:', this.ctx.getOptions())
20
+ * }
21
+ * }
22
+ * ```
23
+ */
24
+ export declare class CommanderExecutionContext {
25
+ private readonly command;
26
+ private readonly commandPath;
27
+ private readonly options;
28
+ /**
29
+ * @internal
30
+ * Creates a new execution context.
31
+ */
32
+ constructor(command: CommandMetadata, commandPath: string, options: any);
33
+ /**
34
+ * Gets the command metadata.
35
+ *
36
+ * @returns The command metadata including path and options schema
37
+ */
38
+ getCommand(): CommandMetadata;
39
+ /**
40
+ * Gets the command path that was invoked.
41
+ *
42
+ * @returns The command path (e.g., 'greet', 'user:create')
43
+ */
44
+ getCommandPath(): string;
45
+ /**
46
+ * Gets the validated command options.
47
+ *
48
+ * Options are validated against the command's Zod schema if one was provided.
49
+ *
50
+ * @returns The validated options object
51
+ */
52
+ getOptions(): any;
53
+ }
54
+ //# sourceMappingURL=commander-execution-context.interface.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commander-execution-context.interface.d.mts","sourceRoot":"","sources":["../../../src/interfaces/commander-execution-context.interface.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAA;AAEvE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,yBAAyB;IAMlC,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,OAAO;IAP1B;;;OAGG;gBAEgB,OAAO,EAAE,eAAe,EACxB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,GAAG;IAG/B;;;;OAIG;IACH,UAAU,IAAI,eAAe;IAI7B;;;;OAIG;IACH,cAAc,IAAI,MAAM;IAIxB;;;;;;OAMG;IACH,UAAU,IAAI,GAAG;CAGlB"}
@@ -1,3 +1,3 @@
1
- export * from './module.interface.mjs';
2
1
  export * from './command-handler.interface.mjs';
2
+ export * from './commander-execution-context.interface.mjs';
3
3
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/interfaces/index.mts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA;AACtC,cAAc,iCAAiC,CAAA"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/interfaces/index.mts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAA;AAC/C,cAAc,6CAA6C,CAAA"}
@@ -1,5 +1,2 @@
1
- export interface Module {
2
- onModuleInit?(): void | Promise<void>;
3
- onModuleDestroy?(): void | Promise<void>;
4
- }
1
+ export type { NaviosModule as Module } from '@navios/core';
5
2
  //# sourceMappingURL=module.interface.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"module.interface.d.mts","sourceRoot":"","sources":["../../../src/interfaces/module.interface.mts"],"names":[],"mappings":"AAAA,MAAM,WAAW,MAAM;IACrB,YAAY,CAAC,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACrC,eAAe,CAAC,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACzC"}
1
+ {"version":3,"file":"module.interface.d.mts","sourceRoot":"","sources":["../../../src/interfaces/module.interface.mts"],"names":[],"mappings":"AACA,YAAY,EAAE,YAAY,IAAI,MAAM,EAAE,MAAM,cAAc,CAAA"}