@navios/commander 0.5.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 (72) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +242 -0
  3. package/dist/src/commander.application.d.mts +29 -0
  4. package/dist/src/commander.application.d.mts.map +1 -0
  5. package/dist/src/commander.factory.d.mts +8 -0
  6. package/dist/src/commander.factory.d.mts.map +1 -0
  7. package/dist/src/decorators/cli-module.decorator.d.mts +7 -0
  8. package/dist/src/decorators/cli-module.decorator.d.mts.map +1 -0
  9. package/dist/src/decorators/command.decorator.d.mts +8 -0
  10. package/dist/src/decorators/command.decorator.d.mts.map +1 -0
  11. package/dist/src/decorators/index.d.mts +3 -0
  12. package/dist/src/decorators/index.d.mts.map +1 -0
  13. package/dist/src/index.d.mts +8 -0
  14. package/dist/src/index.d.mts.map +1 -0
  15. package/dist/src/interfaces/cli-module.interface.d.mts +5 -0
  16. package/dist/src/interfaces/cli-module.interface.d.mts.map +1 -0
  17. package/dist/src/interfaces/command-handler.interface.d.mts +4 -0
  18. package/dist/src/interfaces/command-handler.interface.d.mts.map +1 -0
  19. package/dist/src/interfaces/index.d.mts +3 -0
  20. package/dist/src/interfaces/index.d.mts.map +1 -0
  21. package/dist/src/interfaces/module.interface.d.mts +5 -0
  22. package/dist/src/interfaces/module.interface.d.mts.map +1 -0
  23. package/dist/src/metadata/cli-module.metadata.d.mts +11 -0
  24. package/dist/src/metadata/cli-module.metadata.d.mts.map +1 -0
  25. package/dist/src/metadata/command.metadata.d.mts +12 -0
  26. package/dist/src/metadata/command.metadata.d.mts.map +1 -0
  27. package/dist/src/metadata/index.d.mts +3 -0
  28. package/dist/src/metadata/index.d.mts.map +1 -0
  29. package/dist/src/services/cli-parser.service.d.mts +44 -0
  30. package/dist/src/services/cli-parser.service.d.mts.map +1 -0
  31. package/dist/src/services/index.d.mts +3 -0
  32. package/dist/src/services/index.d.mts.map +1 -0
  33. package/dist/src/services/module-loader.service.d.mts +33 -0
  34. package/dist/src/services/module-loader.service.d.mts.map +1 -0
  35. package/dist/tsconfig.lib.tsbuildinfo +1 -0
  36. package/dist/tsconfig.tsbuildinfo +1 -0
  37. package/dist/tsup.config.d.mts +3 -0
  38. package/dist/tsup.config.d.mts.map +1 -0
  39. package/dist/vitest.config.d.mts +3 -0
  40. package/dist/vitest.config.d.mts.map +1 -0
  41. package/lib/_tsup-dts-rollup.d.mts +456 -0
  42. package/lib/_tsup-dts-rollup.d.ts +456 -0
  43. package/lib/index.d.mts +98 -0
  44. package/lib/index.d.ts +98 -0
  45. package/lib/index.js +541 -0
  46. package/lib/index.js.map +1 -0
  47. package/lib/index.mjs +524 -0
  48. package/lib/index.mjs.map +1 -0
  49. package/package.json +40 -0
  50. package/project.json +66 -0
  51. package/src/__tests__/commander.factory.e2e.spec.mts +965 -0
  52. package/src/commander.application.mts +159 -0
  53. package/src/commander.factory.mts +20 -0
  54. package/src/decorators/cli-module.decorator.mts +39 -0
  55. package/src/decorators/command.decorator.mts +29 -0
  56. package/src/decorators/index.mts +2 -0
  57. package/src/index.mts +7 -0
  58. package/src/interfaces/command-handler.interface.mts +3 -0
  59. package/src/interfaces/index.mts +2 -0
  60. package/src/interfaces/module.interface.mts +4 -0
  61. package/src/metadata/cli-module.metadata.mts +54 -0
  62. package/src/metadata/command.metadata.mts +54 -0
  63. package/src/metadata/index.mts +2 -0
  64. package/src/services/__tests__/cli-parser.service.spec.mts +404 -0
  65. package/src/services/cli-parser.service.mts +231 -0
  66. package/src/services/index.mts +2 -0
  67. package/src/services/module-loader.service.mts +120 -0
  68. package/tsconfig.json +18 -0
  69. package/tsconfig.lib.json +8 -0
  70. package/tsconfig.spec.json +13 -0
  71. package/tsup.config.mts +12 -0
  72. package/vitest.config.mts +9 -0
package/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2025 Oleksandr Hanzha
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,242 @@
1
+ # @navios/commander
2
+
3
+ A CLI command framework built on `@navios/di` that provides a decorator-based approach to building command-line applications, similar to how `@navios/core` works for HTTP applications.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @navios/commander @navios/di zod
9
+ ```
10
+
11
+ ## Features
12
+
13
+ - **Decorator-based**: Use `@Command` and `@CliModule` decorators to define commands and modules
14
+ - **Dependency Injection**: Full integration with `@navios/di`
15
+ - **Schema Validation**: Built-in support for Zod schemas to validate command options
16
+ - **Modular Architecture**: Organize commands into modules with imports support
17
+
18
+ ## Usage
19
+
20
+ ### Creating a Command
21
+
22
+ Commands are defined using the `@Command` decorator. Each command must implement the `CommandHandler` interface with an `execute` method.
23
+
24
+ ```typescript
25
+ import { Command, CommandHandler } from '@navios/commander'
26
+ import { z } from 'zod'
27
+
28
+ const greetOptionsSchema = z.object({
29
+ name: z.string(),
30
+ greeting: z.string().optional().default('Hello'),
31
+ })
32
+
33
+ type GreetOptions = z.infer<typeof greetOptionsSchema>
34
+
35
+ @Command({
36
+ path: 'greet',
37
+ optionsSchema: greetOptionsSchema,
38
+ })
39
+ export class GreetCommand implements CommandHandler<GreetOptions> {
40
+ async execute(options: GreetOptions) {
41
+ console.log(`${options.greeting}, ${options.name}!`)
42
+ }
43
+ }
44
+ ```
45
+
46
+ ### Creating a CLI Module
47
+
48
+ Modules organize commands and can import other modules:
49
+
50
+ ```typescript
51
+ import { CliModule } from '@navios/commander'
52
+ import { GreetCommand } from './greet.command'
53
+
54
+ @CliModule({
55
+ commands: [GreetCommand],
56
+ })
57
+ export class AppModule {}
58
+ ```
59
+
60
+ ### Bootstrapping the Application
61
+
62
+ Use `CommanderFactory` to create and run your CLI application:
63
+
64
+ ```typescript
65
+ import { CommanderFactory } from '@navios/commander'
66
+ import { AppModule } from './app.module'
67
+
68
+ async function bootstrap() {
69
+ const app = await CommanderFactory.create(AppModule)
70
+ await app.init()
71
+
72
+ // Run with command-line arguments
73
+ await app.run(process.argv)
74
+
75
+ await app.close()
76
+ }
77
+
78
+ bootstrap()
79
+ ```
80
+
81
+ Then run your CLI:
82
+
83
+ ```bash
84
+ node dist/cli.js greet --name World --greeting Hi
85
+ ```
86
+
87
+ ### Advanced Example with Dependency Injection
88
+
89
+ ```typescript
90
+ import { Command, CommandHandler, CliModule } from '@navios/commander'
91
+ import { Injectable, inject } from '@navios/di'
92
+ import { z } from 'zod'
93
+
94
+ // Service
95
+ @Injectable()
96
+ class UserService {
97
+ async getUser(id: string) {
98
+ return { id, name: 'John Doe' }
99
+ }
100
+ }
101
+
102
+ // Command with injected service
103
+ const userOptionsSchema = z.object({
104
+ userId: z.string(),
105
+ })
106
+
107
+ @Command({
108
+ path: 'user:show',
109
+ optionsSchema: userOptionsSchema,
110
+ })
111
+ export class ShowUserCommand implements CommandHandler<z.infer<typeof userOptionsSchema>> {
112
+ private userService = inject(UserService)
113
+
114
+ async execute(options: { userId: string }) {
115
+ const user = await this.userService.getUser(options.userId)
116
+ console.log(`User: ${user.name} (ID: ${user.id})`)
117
+ }
118
+ }
119
+
120
+ // Module
121
+ @CliModule({
122
+ commands: [ShowUserCommand],
123
+ })
124
+ export class UserModule {}
125
+
126
+ @CliModule({
127
+ imports: [UserModule],
128
+ })
129
+ export class AppModule {}
130
+ ```
131
+
132
+ ### Listing All Commands
133
+
134
+ ```typescript
135
+ const app = await CommanderFactory.create(AppModule)
136
+ await app.init()
137
+
138
+ const commands = app.getAllCommands()
139
+ console.log('Available commands:')
140
+ commands.forEach(({ path }) => {
141
+ console.log(` - ${path}`)
142
+ })
143
+ ```
144
+
145
+ ## Advanced Usage
146
+
147
+ ### Programmatic Command Execution
148
+
149
+ For advanced use cases where you need to execute commands programmatically (e.g., in tests or programmatic workflows), you can use `executeCommand`:
150
+
151
+ ```typescript
152
+ import { CommanderFactory } from '@navios/commander'
153
+ import { AppModule } from './app.module'
154
+
155
+ async function bootstrap() {
156
+ const app = await CommanderFactory.create(AppModule)
157
+ await app.init()
158
+
159
+ // Execute a command programmatically
160
+ await app.executeCommand('greet', {
161
+ name: 'World',
162
+ greeting: 'Hi',
163
+ })
164
+
165
+ await app.close()
166
+ }
167
+
168
+ bootstrap()
169
+ ```
170
+
171
+ This is useful for:
172
+ - Unit and integration testing
173
+ - Building CLI tools that wrap other CLI tools
174
+ - Programmatic automation workflows
175
+
176
+ ## API Reference
177
+
178
+ ### Decorators
179
+
180
+ #### `@Command(options)`
181
+
182
+ Defines a CLI command.
183
+
184
+ **Options:**
185
+ - `path: string` - The command path (e.g., 'user:create', 'db:migrate')
186
+ - `optionsSchema?: ZodSchema` - Optional Zod schema for validating command options
187
+
188
+ #### `@CliModule(options)`
189
+
190
+ Defines a CLI module.
191
+
192
+ **Options:**
193
+ - `commands?: ClassType[]` - Array of command classes
194
+ - `imports?: ClassType[]` - Array of other modules to import
195
+
196
+ ### Interfaces
197
+
198
+ #### `CommandHandler<TOptions>`
199
+
200
+ Interface that command classes must implement.
201
+
202
+ ```typescript
203
+ interface CommandHandler<TOptions = any> {
204
+ execute(options: TOptions): void | Promise<void>
205
+ }
206
+ ```
207
+
208
+ #### `CliModule`
209
+
210
+ Optional lifecycle hooks for modules.
211
+
212
+ ```typescript
213
+ interface CliModule {
214
+ onModuleInit?(): void | Promise<void>
215
+ onModuleDestroy?(): void | Promise<void>
216
+ }
217
+ ```
218
+
219
+ ### Classes
220
+
221
+ #### `CommanderFactory`
222
+
223
+ Factory class for creating CLI applications.
224
+
225
+ **Methods:**
226
+ - `static async create(appModule, options?)` - Creates a new CommanderApplication
227
+
228
+ #### `CommanderApplication`
229
+
230
+ Main application class.
231
+
232
+ **Methods:**
233
+ - `async init()` - Initializes the application
234
+ - `async run(argv)` - Parses command-line arguments and executes the appropriate command (default usage)
235
+ - `async executeCommand(path, options?)` - Executes a command programmatically with options (advanced usage)
236
+ - `getAllCommands()` - Returns all registered commands
237
+ - `getContainer()` - Returns the DI container
238
+ - `async close()` - Closes the application
239
+
240
+ ## License
241
+
242
+ MIT
@@ -0,0 +1,29 @@
1
+ import type { ClassTypeWithInstance } from '@navios/di';
2
+ import { Container } from '@navios/di';
3
+ import type { Module } from './interfaces/index.mjs';
4
+ export interface CommanderApplicationOptions {
5
+ }
6
+ export declare class CommanderApplication {
7
+ private moduleLoader;
8
+ private cliParser;
9
+ protected container: Container;
10
+ private appModule;
11
+ private options;
12
+ isInitialized: boolean;
13
+ setup(appModule: ClassTypeWithInstance<Module>, options?: CommanderApplicationOptions): Promise<void>;
14
+ getContainer(): Container;
15
+ init(): Promise<void>;
16
+ executeCommand(commandPath: string, options?: any): Promise<void>;
17
+ getAllCommands(): {
18
+ path: string;
19
+ class: ClassTypeWithInstance<any>;
20
+ }[];
21
+ /**
22
+ * Runs the CLI application by parsing process.argv and executing the command
23
+ * @param argv - Command-line arguments (defaults to process.argv)
24
+ */
25
+ run(argv?: string[]): Promise<void>;
26
+ dispose(): Promise<void>;
27
+ close(): Promise<void>;
28
+ }
29
+ //# sourceMappingURL=commander.application.d.mts.map
@@ -0,0 +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"}
@@ -0,0 +1,8 @@
1
+ import type { ClassTypeWithInstance } from '@navios/di';
2
+ import type { CommanderApplicationOptions } from './commander.application.mjs';
3
+ import type { Module } from './interfaces/index.mjs';
4
+ import { CommanderApplication } from './commander.application.mjs';
5
+ export declare class CommanderFactory {
6
+ static create(appModule: ClassTypeWithInstance<Module>, options?: CommanderApplicationOptions): Promise<CommanderApplication>;
7
+ }
8
+ //# sourceMappingURL=commander.factory.d.mts.map
@@ -0,0 +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"}
@@ -0,0 +1,7 @@
1
+ import type { ClassType } from '@navios/di';
2
+ export interface CliModuleOptions {
3
+ commands?: ClassType[] | Set<ClassType>;
4
+ imports?: ClassType[] | Set<ClassType>;
5
+ }
6
+ export declare function CliModule({ commands, imports }?: CliModuleOptions): (target: ClassType, context: ClassDecoratorContext) => ClassType;
7
+ //# sourceMappingURL=cli-module.decorator.d.mts.map
@@ -0,0 +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"}
@@ -0,0 +1,8 @@
1
+ import type { ClassType } from '@navios/di';
2
+ import type { ZodObject } from 'zod';
3
+ export interface CommandOptions {
4
+ path: string;
5
+ optionsSchema?: ZodObject;
6
+ }
7
+ export declare function Command({ path, optionsSchema }: CommandOptions): (target: ClassType, context: ClassDecoratorContext) => ClassType;
8
+ //# sourceMappingURL=command.decorator.d.mts.map
@@ -0,0 +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"}
@@ -0,0 +1,3 @@
1
+ export * from './command.decorator.mjs';
2
+ export * from './cli-module.decorator.mjs';
3
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/decorators/index.mts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAA;AACvC,cAAc,4BAA4B,CAAA"}
@@ -0,0 +1,8 @@
1
+ export * from '@navios/di';
2
+ export * from './commander.application.mjs';
3
+ export * from './commander.factory.mjs';
4
+ export * from './decorators/index.mjs';
5
+ export * from './interfaces/index.mjs';
6
+ export * from './metadata/index.mjs';
7
+ export * from './services/index.mjs';
8
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +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"}
@@ -0,0 +1,5 @@
1
+ export interface CliModule {
2
+ onModuleInit?(): void | Promise<void>;
3
+ onModuleDestroy?(): void | Promise<void>;
4
+ }
5
+ //# sourceMappingURL=cli-module.interface.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli-module.interface.d.mts","sourceRoot":"","sources":["../../../src/interfaces/cli-module.interface.mts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACxB,YAAY,CAAC,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACrC,eAAe,CAAC,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACzC"}
@@ -0,0 +1,4 @@
1
+ export interface CommandHandler<TOptions = any> {
2
+ execute(options: TOptions): void | Promise<void>;
3
+ }
4
+ //# sourceMappingURL=command-handler.interface.d.mts.map
@@ -0,0 +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"}
@@ -0,0 +1,3 @@
1
+ export * from './module.interface.mjs';
2
+ export * from './command-handler.interface.mjs';
3
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/interfaces/index.mts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA;AACtC,cAAc,iCAAiC,CAAA"}
@@ -0,0 +1,5 @@
1
+ export interface Module {
2
+ onModuleInit?(): void | Promise<void>;
3
+ onModuleDestroy?(): void | Promise<void>;
4
+ }
5
+ //# sourceMappingURL=module.interface.d.mts.map
@@ -0,0 +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"}
@@ -0,0 +1,11 @@
1
+ import type { ClassType } from '@navios/di';
2
+ export declare const CliModuleMetadataKey: unique symbol;
3
+ export interface CliModuleMetadata {
4
+ commands: Set<ClassType>;
5
+ imports: Set<ClassType>;
6
+ customAttributes: Map<string | symbol, any>;
7
+ }
8
+ export declare function getCliModuleMetadata(target: ClassType, context: ClassDecoratorContext): CliModuleMetadata;
9
+ export declare function extractCliModuleMetadata(target: ClassType): CliModuleMetadata;
10
+ export declare function hasCliModuleMetadata(target: ClassType): boolean;
11
+ //# sourceMappingURL=cli-module.metadata.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli-module.metadata.d.mts","sourceRoot":"","sources":["../../../src/metadata/cli-module.metadata.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAE3C,eAAO,MAAM,oBAAoB,eAAiC,CAAA;AAElE,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,GAAG,CAAC,SAAS,CAAC,CAAA;IACxB,OAAO,EAAE,GAAG,CAAC,SAAS,CAAC,CAAA;IACvB,gBAAgB,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAA;CAC5C;AAED,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,SAAS,EACjB,OAAO,EAAE,qBAAqB,GAC7B,iBAAiB,CAoBnB;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,SAAS,GAChB,iBAAiB,CAWnB;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAG/D"}
@@ -0,0 +1,12 @@
1
+ import type { ClassType } from '@navios/di';
2
+ import type { ZodObject } from 'zod';
3
+ export declare const CommandMetadataKey: unique symbol;
4
+ export interface CommandMetadata {
5
+ path: string;
6
+ optionsSchema?: ZodObject;
7
+ customAttributes: Map<string | symbol, any>;
8
+ }
9
+ export declare function getCommandMetadata(target: ClassType, context: ClassDecoratorContext, path: string, optionsSchema?: ZodObject): CommandMetadata;
10
+ export declare function extractCommandMetadata(target: ClassType): CommandMetadata;
11
+ export declare function hasCommandMetadata(target: ClassType): boolean;
12
+ //# sourceMappingURL=command.metadata.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command.metadata.d.mts","sourceRoot":"","sources":["../../../src/metadata/command.metadata.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAEpC,eAAO,MAAM,kBAAkB,eAA+B,CAAA;AAE9D,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,aAAa,CAAC,EAAE,SAAS,CAAA;IACzB,gBAAgB,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAA;CAC5C;AAED,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,SAAS,EACjB,OAAO,EAAE,qBAAqB,EAC9B,IAAI,EAAE,MAAM,EACZ,aAAa,CAAC,EAAE,SAAS,GACxB,eAAe,CAoBjB;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,SAAS,GAAG,eAAe,CASzE;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAI7D"}
@@ -0,0 +1,3 @@
1
+ export * from './command.metadata.mjs';
2
+ export * from './cli-module.metadata.mjs';
3
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/metadata/index.mts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA;AACtC,cAAc,2BAA2B,CAAA"}
@@ -0,0 +1,44 @@
1
+ import type { ZodObject } from 'zod';
2
+ export interface ParsedCliArgs {
3
+ command: string;
4
+ options: Record<string, any>;
5
+ positionals: string[];
6
+ }
7
+ export declare class CliParserService {
8
+ /**
9
+ * Parses command-line arguments from process.argv
10
+ * Commands can be multi-word (e.g., 'db migrate', 'cache clear')
11
+ * Expected format: node script.js command [subcommand...] --flag value --boolean-flag positional1 positional2
12
+ *
13
+ * @param argv - Array of command-line arguments (typically process.argv)
14
+ * @param optionsSchema - Optional Zod schema to determine boolean flags and option types
15
+ * @returns Parsed command (space-separated if multi-word), options, and positional arguments
16
+ */
17
+ parse(argv: string[], optionsSchema?: ZodObject): ParsedCliArgs;
18
+ /**
19
+ * Converts kebab-case to camelCase
20
+ */
21
+ private camelCase;
22
+ /**
23
+ * Attempts to parse string values into appropriate types
24
+ */
25
+ private parseValue;
26
+ /**
27
+ * Extracts boolean field names from a Zod schema
28
+ * Handles ZodObject, ZodOptional, and ZodDefault wrappers
29
+ */
30
+ private extractBooleanFields;
31
+ /**
32
+ * Checks if a Zod schema represents a boolean type
33
+ * Unwraps ZodOptional and ZodDefault
34
+ */
35
+ private isSchemaBoolean;
36
+ /**
37
+ * Formats help text for available commands
38
+ */
39
+ formatCommandList(commands: Array<{
40
+ path: string;
41
+ class: any;
42
+ }>): string;
43
+ }
44
+ //# sourceMappingURL=cli-parser.service.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli-parser.service.d.mts","sourceRoot":"","sources":["../../../src/services/cli-parser.service.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAW,MAAM,KAAK,CAAA;AAI7C,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC5B,WAAW,EAAE,MAAM,EAAE,CAAA;CACtB;AAED,qBACa,gBAAgB;IAC3B;;;;;;;;OAQG;IACH,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,aAAa,CAAC,EAAE,SAAS,GAAG,aAAa;IAwG/D;;OAEG;IACH,OAAO,CAAC,SAAS;IAIjB;;OAEG;IACH,OAAO,CAAC,UAAU;IAkClB;;;OAGG;IACH,OAAO,CAAC,oBAAoB;IA0B5B;;;OAGG;IACH,OAAO,CAAC,eAAe;IAiBvB;;OAEG;IACH,iBAAiB,CAAC,QAAQ,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,GAAG,CAAA;KAAE,CAAC,GAAG,MAAM;CAOzE"}
@@ -0,0 +1,3 @@
1
+ export * from './module-loader.service.mjs';
2
+ export * from './cli-parser.service.mjs';
3
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/services/index.mts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAA;AAC3C,cAAc,0BAA0B,CAAA"}
@@ -0,0 +1,33 @@
1
+ import type { ClassTypeWithInstance } from '@navios/di';
2
+ import { Container } from '@navios/di';
3
+ import type { CommandHandler, Module } from '../interfaces/index.mjs';
4
+ import type { CliModuleMetadata, CommandMetadata } from '../metadata/index.mjs';
5
+ export interface CommandWithMetadata {
6
+ class: ClassTypeWithInstance<CommandHandler>;
7
+ metadata: CommandMetadata;
8
+ }
9
+ export declare class ModuleLoaderService {
10
+ protected container: Container;
11
+ private modulesMetadata;
12
+ private loadedModules;
13
+ private commandsMetadata;
14
+ private initialized;
15
+ loadModules(appModule: ClassTypeWithInstance<Module>): Promise<void>;
16
+ private traverseModules;
17
+ private mergeMetadata;
18
+ getAllModules(): Map<string, CliModuleMetadata>;
19
+ getAllCommands(): Map<string, ClassTypeWithInstance<any>>;
20
+ /**
21
+ * Get all commands with their metadata, indexed by command path.
22
+ * This is populated during loadModules, so path information is available
23
+ * before parsing CLI argv.
24
+ */
25
+ getAllCommandsWithMetadata(): Map<string, CommandWithMetadata>;
26
+ /**
27
+ * Get a command by its path, with metadata already extracted.
28
+ * Returns undefined if command is not found.
29
+ */
30
+ getCommandByPath(path: string): CommandWithMetadata | undefined;
31
+ dispose(): void;
32
+ }
33
+ //# sourceMappingURL=module-loader.service.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-loader.service.d.mts","sourceRoot":"","sources":["../../../src/services/module-loader.service.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAEvD,OAAO,EAAE,SAAS,EAAsB,MAAM,YAAY,CAAA;AAE1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AACrE,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAO/E,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,qBAAqB,CAAC,cAAc,CAAC,CAAA;IAC5C,QAAQ,EAAE,eAAe,CAAA;CAC1B;AAED,qBACa,mBAAmB;IAC9B,SAAS,CAAC,SAAS,YAAoB;IACvC,OAAO,CAAC,eAAe,CAA4C;IACnE,OAAO,CAAC,aAAa,CAA8B;IACnD,OAAO,CAAC,gBAAgB,CAA8C;IACtE,OAAO,CAAC,WAAW,CAAQ;IAErB,WAAW,CAAC,SAAS,EAAE,qBAAqB,CAAC,MAAM,CAAC;YAQ5C,eAAe;IAmC7B,OAAO,CAAC,aAAa;IAcrB,aAAa,IAAI,GAAG,CAAC,MAAM,EAAE,iBAAiB,CAAC;IAI/C,cAAc,IAAI,GAAG,CAAC,MAAM,EAAE,qBAAqB,CAAC,GAAG,CAAC,CAAC;IAUzD;;;;OAIG;IACH,0BAA0B,IAAI,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC;IAI9D;;;OAGG;IACH,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,mBAAmB,GAAG,SAAS;IAI/D,OAAO;CAMR"}