@navios/commander 1.0.0-alpha.4 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/dist/src/commander.factory.d.mts +59 -0
  3. package/dist/src/commander.factory.d.mts.map +1 -1
  4. package/dist/src/commands/help.command.d.mts.map +1 -1
  5. package/dist/src/decorators/command.decorator.d.mts +9 -2
  6. package/dist/src/decorators/command.decorator.d.mts.map +1 -1
  7. package/dist/src/overrides/help.command.d.mts +18 -0
  8. package/dist/src/overrides/help.command.d.mts.map +1 -0
  9. package/dist/src/tokens/help-command.token.d.mts +4 -0
  10. package/dist/src/tokens/help-command.token.d.mts.map +1 -0
  11. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  12. package/dist/tsconfig.tsbuildinfo +1 -1
  13. package/lib/help-command.token-BPEgaaxY.mjs +558 -0
  14. package/lib/help-command.token-BPEgaaxY.mjs.map +1 -0
  15. package/lib/help-command.token-DcvTjwbA.cjs +611 -0
  16. package/lib/help-command.token-DcvTjwbA.cjs.map +1 -0
  17. package/lib/help.command-D9lsIDIe.cjs +316 -0
  18. package/lib/help.command-D9lsIDIe.cjs.map +1 -0
  19. package/lib/help.command-DtokRzad.mjs +317 -0
  20. package/lib/help.command-DtokRzad.mjs.map +1 -0
  21. package/lib/index.cjs +43 -566
  22. package/lib/index.cjs.map +1 -1
  23. package/lib/index.d.cts +184 -119
  24. package/lib/index.d.cts.map +1 -1
  25. package/lib/index.d.mts +184 -119
  26. package/lib/index.d.mts.map +1 -1
  27. package/lib/index.mjs +28 -551
  28. package/lib/index.mjs.map +1 -1
  29. package/package.json +11 -4
  30. package/src/commander.factory.mts +107 -8
  31. package/src/commands/help.command.mts +4 -3
  32. package/src/decorators/command.decorator.mts +17 -8
  33. package/src/overrides/help.command.mts +40 -0
  34. package/src/tokens/help-command.token.mts +5 -0
  35. package/tsconfig.json +0 -3
  36. package/tsconfig.spec.json +1 -1
  37. package/dist/src/commander.application.d.mts +0 -147
  38. package/dist/src/commander.application.d.mts.map +0 -1
  39. package/dist/src/metadata/cli-module.metadata.d.mts +0 -60
  40. package/dist/src/metadata/cli-module.metadata.d.mts.map +0 -1
  41. package/dist/src/services/module-loader.service.d.mts +0 -74
  42. package/dist/src/services/module-loader.service.d.mts.map +0 -1
@@ -1,147 +0,0 @@
1
- import type { ClassTypeWithInstance, NaviosModule } from '@navios/core';
2
- import { Container } from '@navios/core';
3
- /**
4
- * Configuration options for CommanderApplication.
5
- *
6
- * @public
7
- */
8
- export interface CommanderApplicationOptions {
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
- */
23
- export declare class CommanderApplication {
24
- private moduleLoader;
25
- private cliParser;
26
- protected container: Container;
27
- private appModule;
28
- private options;
29
- /**
30
- * Indicates whether the application has been initialized.
31
- * Set to `true` after `init()` is called successfully.
32
- */
33
- isInitialized: boolean;
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
- */
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
- */
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
- */
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
- */
102
- getAllCommands(): {
103
- path: string;
104
- class: ClassTypeWithInstance<any>;
105
- }[];
106
- /**
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
- * ```
127
- */
128
- run(argv?: string[]): Promise<void>;
129
- /**
130
- * @internal
131
- * Disposes of resources used by the application.
132
- */
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
- */
145
- close(): Promise<void>;
146
- }
147
- //# sourceMappingURL=commander.application.d.mts.map
@@ -1 +0,0 @@
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,60 +0,0 @@
1
- import type { ClassType } from '@navios/core';
2
- /**
3
- * @internal
4
- * Symbol key used to store CLI module metadata on classes.
5
- */
6
- export declare const CliModuleMetadataKey: unique symbol;
7
- /**
8
- * Metadata associated with a CLI module.
9
- *
10
- * @public
11
- */
12
- export interface CliModuleMetadata {
13
- /**
14
- * Set of command classes registered in this module.
15
- */
16
- commands: Set<ClassType>;
17
- /**
18
- * Set of other modules imported by this module.
19
- */
20
- imports: Set<ClassType>;
21
- /**
22
- * Set of service override classes imported for side effects.
23
- */
24
- overrides: Set<ClassType>;
25
- /**
26
- * Map of custom attributes that can be attached to the module.
27
- */
28
- customAttributes: Map<string | symbol, any>;
29
- }
30
- /**
31
- * Gets or creates CLI module metadata for a class.
32
- *
33
- * @internal
34
- * @param target - The module class
35
- * @param context - The decorator context
36
- * @returns The module metadata
37
- */
38
- export declare function getCliModuleMetadata(target: ClassType, context: ClassDecoratorContext): CliModuleMetadata;
39
- /**
40
- * Extracts CLI module metadata from a class.
41
- *
42
- * @param target - The module class
43
- * @returns The module metadata
44
- * @throws {Error} If the class is not decorated with @CliModule
45
- *
46
- * @example
47
- * ```typescript
48
- * const metadata = extractCliModuleMetadata(AppModule)
49
- * console.log(metadata.commands.size) // Number of commands
50
- * ```
51
- */
52
- export declare function extractCliModuleMetadata(target: ClassType): CliModuleMetadata;
53
- /**
54
- * Checks if a class has CLI module metadata.
55
- *
56
- * @param target - The class to check
57
- * @returns `true` if the class is decorated with @CliModule, `false` otherwise
58
- */
59
- export declare function hasCliModuleMetadata(target: ClassType): boolean;
60
- //# sourceMappingURL=cli-module.metadata.d.mts.map
@@ -1 +0,0 @@
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,cAAc,CAAA;AAE7C;;;GAGG;AACH,eAAO,MAAM,oBAAoB,eAAiC,CAAA;AAElE;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,QAAQ,EAAE,GAAG,CAAC,SAAS,CAAC,CAAA;IACxB;;OAEG;IACH,OAAO,EAAE,GAAG,CAAC,SAAS,CAAC,CAAA;IACvB;;OAEG;IACH,SAAS,EAAE,GAAG,CAAC,SAAS,CAAC,CAAA;IACzB;;OAEG;IACH,gBAAgB,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAA;CAC5C;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,SAAS,EACjB,OAAO,EAAE,qBAAqB,GAC7B,iBAAiB,CAqBnB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,SAAS,GAAG,iBAAiB,CAS7E;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAG/D"}
@@ -1,74 +0,0 @@
1
- import type { ClassTypeWithInstance, NaviosModule } from '@navios/core';
2
- import { Container } from '@navios/core';
3
- import type { CommandHandler } from '../interfaces/index.mjs';
4
- import type { CliModuleMetadata, CommandMetadata } from '../metadata/index.mjs';
5
- /**
6
- * Command class with its associated metadata.
7
- *
8
- * @public
9
- */
10
- export interface CommandWithMetadata {
11
- /**
12
- * The command class constructor.
13
- */
14
- class: ClassTypeWithInstance<CommandHandler>;
15
- /**
16
- * The command metadata including path and options schema.
17
- */
18
- metadata: CommandMetadata;
19
- }
20
- /**
21
- * Service for loading and managing CLI modules and commands.
22
- *
23
- * Handles module traversal, command registration, and metadata collection.
24
- * This service is used internally by CommanderApplication.
25
- *
26
- * @public
27
- */
28
- export declare class CliModuleLoaderService {
29
- private logger;
30
- protected container: Container;
31
- private modulesMetadata;
32
- private loadedModules;
33
- private commandsMetadata;
34
- private initialized;
35
- /**
36
- * Loads all modules starting from the root app module.
37
- *
38
- * Traverses the module tree, loads imported modules, and collects command metadata.
39
- *
40
- * @param appModule - The root CLI module
41
- */
42
- loadModules(appModule: ClassTypeWithInstance<NaviosModule>): Promise<void>;
43
- private traverseModules;
44
- private validateOverrides;
45
- private mergeMetadata;
46
- /**
47
- * Gets all loaded module metadata.
48
- *
49
- * @returns Map of module names to their metadata
50
- */
51
- getAllModules(): Map<string, CliModuleMetadata>;
52
- /**
53
- * Gets all command classes indexed by command class name.
54
- *
55
- * @returns Map of command class names to command classes
56
- */
57
- getAllCommands(): Map<string, ClassTypeWithInstance<any>>;
58
- /**
59
- * Get all commands with their metadata, indexed by command path.
60
- * This is populated during loadModules, so path information is available
61
- * before parsing CLI argv.
62
- */
63
- getAllCommandsWithMetadata(): Map<string, CommandWithMetadata>;
64
- /**
65
- * Get a command by its path, with metadata already extracted.
66
- * Returns undefined if command is not found.
67
- */
68
- getCommandByPath(path: string): CommandWithMetadata | undefined;
69
- /**
70
- * Disposes of all loaded modules and commands, clearing internal state.
71
- */
72
- dispose(): void;
73
- }
74
- //# sourceMappingURL=module-loader.service.d.mts.map
@@ -1 +0,0 @@
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,YAAY,EAAE,MAAM,cAAc,CAAA;AAEvE,OAAO,EACL,SAAS,EAKV,MAAM,cAAc,CAAA;AAErB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAO/E;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,KAAK,EAAE,qBAAqB,CAAC,cAAc,CAAC,CAAA;IAC5C;;OAEG;IACH,QAAQ,EAAE,eAAe,CAAA;CAC1B;AAED;;;;;;;GAOG;AACH,qBACa,sBAAsB;IACjC,OAAO,CAAC,MAAM,CAEZ;IACF,SAAS,CAAC,SAAS,YAAoB;IACvC,OAAO,CAAC,eAAe,CAA4C;IACnE,OAAO,CAAC,aAAa,CAA8B;IACnD,OAAO,CAAC,gBAAgB,CAA8C;IACtE,OAAO,CAAC,WAAW,CAAQ;IAE3B;;;;;;OAMG;IACG,WAAW,CAAC,SAAS,EAAE,qBAAqB,CAAC,YAAY,CAAC;YAQlD,eAAe;IAqC7B,OAAO,CAAC,iBAAiB;IA6DzB,OAAO,CAAC,aAAa;IAcrB;;;;OAIG;IACH,aAAa,IAAI,GAAG,CAAC,MAAM,EAAE,iBAAiB,CAAC;IAI/C;;;;OAIG;IACH,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;;OAEG;IACH,OAAO;CAMR"}