@navios/commander 1.0.0 → 1.2.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 (76) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +22 -0
  3. package/dist/src/commander.factory.d.mts +59 -0
  4. package/dist/src/commander.factory.d.mts.map +1 -1
  5. package/dist/src/commands/help.command.d.mts.map +1 -1
  6. package/dist/src/decorators/command.decorator.d.mts +9 -2
  7. package/dist/src/decorators/command.decorator.d.mts.map +1 -1
  8. package/dist/src/legacy-compat/decorators/cli-module.decorator.d.mts +26 -0
  9. package/dist/src/legacy-compat/decorators/cli-module.decorator.d.mts.map +1 -0
  10. package/dist/src/legacy-compat/decorators/command.decorator.d.mts +34 -0
  11. package/dist/src/legacy-compat/decorators/command.decorator.d.mts.map +1 -0
  12. package/dist/src/legacy-compat/decorators/index.d.mts +3 -0
  13. package/dist/src/legacy-compat/decorators/index.d.mts.map +1 -0
  14. package/dist/src/legacy-compat/index.d.mts +28 -0
  15. package/dist/src/legacy-compat/index.d.mts.map +1 -0
  16. package/dist/src/overrides/help.command.d.mts +18 -0
  17. package/dist/src/overrides/help.command.d.mts.map +1 -0
  18. package/dist/src/tokens/help-command.token.d.mts +4 -0
  19. package/dist/src/tokens/help-command.token.d.mts.map +1 -0
  20. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  21. package/dist/tsconfig.tsbuildinfo +1 -1
  22. package/lib/cli-module.decorator-CkP22084.cjs +71 -0
  23. package/lib/cli-module.decorator-CkP22084.cjs.map +1 -0
  24. package/lib/cli-module.decorator-DGuGfpex.d.mts +411 -0
  25. package/lib/cli-module.decorator-DGuGfpex.d.mts.map +1 -0
  26. package/lib/cli-module.decorator-DVl8009Q.d.cts +213 -0
  27. package/lib/cli-module.decorator-DVl8009Q.d.cts.map +1 -0
  28. package/lib/cli-module.decorator-UGbtkRYc.mjs +66 -0
  29. package/lib/cli-module.decorator-UGbtkRYc.mjs.map +1 -0
  30. package/lib/command.decorator-DVLSAqYZ.mjs +135 -0
  31. package/lib/command.decorator-DVLSAqYZ.mjs.map +1 -0
  32. package/lib/command.decorator-UrNJmQN0.cjs +176 -0
  33. package/lib/command.decorator-UrNJmQN0.cjs.map +1 -0
  34. package/lib/help-command.token-C0Kgj60o.mjs +427 -0
  35. package/lib/help-command.token-C0Kgj60o.mjs.map +1 -0
  36. package/lib/help-command.token-CMWYI6em.cjs +438 -0
  37. package/lib/help-command.token-CMWYI6em.cjs.map +1 -0
  38. package/lib/help.command-DQyv6ali.cjs +317 -0
  39. package/lib/help.command-DQyv6ali.cjs.map +1 -0
  40. package/lib/help.command-dtZbhq0w.mjs +318 -0
  41. package/lib/help.command-dtZbhq0w.mjs.map +1 -0
  42. package/lib/index.cjs +45 -627
  43. package/lib/index.cjs.map +1 -1
  44. package/lib/index.d.cts +139 -281
  45. package/lib/index.d.cts.map +1 -1
  46. package/lib/index.d.mts +62 -402
  47. package/lib/index.d.mts.map +1 -1
  48. package/lib/index.mjs +30 -612
  49. package/lib/index.mjs.map +1 -1
  50. package/lib/legacy-compat/index.cjs +108 -0
  51. package/lib/legacy-compat/index.cjs.map +1 -0
  52. package/lib/legacy-compat/index.d.cts +63 -0
  53. package/lib/legacy-compat/index.d.cts.map +1 -0
  54. package/lib/legacy-compat/index.d.mts +63 -0
  55. package/lib/legacy-compat/index.d.mts.map +1 -0
  56. package/lib/legacy-compat/index.mjs +101 -0
  57. package/lib/legacy-compat/index.mjs.map +1 -0
  58. package/package.json +20 -3
  59. package/src/commander.factory.mts +107 -8
  60. package/src/commands/help.command.mts +4 -3
  61. package/src/decorators/command.decorator.mts +17 -8
  62. package/src/legacy-compat/decorators/cli-module.decorator.mts +46 -0
  63. package/src/legacy-compat/decorators/command.decorator.mts +46 -0
  64. package/src/legacy-compat/decorators/index.mts +2 -0
  65. package/src/legacy-compat/index.mts +31 -0
  66. package/src/overrides/help.command.mts +40 -0
  67. package/src/tokens/help-command.token.mts +5 -0
  68. package/tsconfig.json +0 -3
  69. package/tsconfig.spec.json +1 -1
  70. package/tsdown.config.mts +1 -1
  71. package/dist/src/commander.application.d.mts +0 -147
  72. package/dist/src/commander.application.d.mts.map +0 -1
  73. package/dist/src/metadata/cli-module.metadata.d.mts +0 -60
  74. package/dist/src/metadata/cli-module.metadata.d.mts.map +0 -1
  75. package/dist/src/services/module-loader.service.d.mts +0 -74
  76. package/dist/src/services/module-loader.service.d.mts.map +0 -1
@@ -0,0 +1,71 @@
1
+ const require_command_decorator = require('./command.decorator-UrNJmQN0.cjs');
2
+ let _navios_core = require("@navios/core");
3
+
4
+ //#region src/decorators/cli-module.decorator.mts
5
+ /**
6
+ * Decorator that marks a class as a CLI module.
7
+ *
8
+ * This decorator extends the standard @Module decorator, adding support for
9
+ * CLI commands while maintaining full compatibility with HTTP controllers.
10
+ * Modules organize commands and can import other modules to compose larger
11
+ * CLI applications.
12
+ *
13
+ * The module can optionally implement `NaviosModule` interface for lifecycle hooks.
14
+ *
15
+ * @param options - Configuration options for the module
16
+ * @returns A class decorator function
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * import { CliModule } from '@navios/commander'
21
+ * import { GreetCommand } from './greet.command'
22
+ * import { UserModule } from './user.module'
23
+ *
24
+ * @CliModule({
25
+ * commands: [GreetCommand],
26
+ * imports: [UserModule]
27
+ * })
28
+ * export class AppModule {}
29
+ * ```
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * // Mixed HTTP and CLI module
34
+ * @CliModule({
35
+ * controllers: [HealthController],
36
+ * commands: [MigrateCommand],
37
+ * imports: [DatabaseModule],
38
+ * })
39
+ * export class AppModule {}
40
+ * ```
41
+ */ function CliModule({ commands = [], controllers = [], imports = [], guards = [], overrides = [], priority, registry } = {
42
+ commands: [],
43
+ controllers: [],
44
+ imports: [],
45
+ guards: [],
46
+ overrides: []
47
+ }) {
48
+ return (target, context) => {
49
+ if (context.kind !== "class") throw new Error("[Navios Commander] @CliModule decorator can only be used on classes.");
50
+ const result = (0, _navios_core.Module)({
51
+ controllers,
52
+ imports,
53
+ guards,
54
+ overrides,
55
+ priority,
56
+ registry
57
+ })(target, context);
58
+ const commandSet = (0, _navios_core.getModuleCustomEntry)((0, _navios_core.getModuleMetadata)(target, context), require_command_decorator.CommandEntryKey, () => /* @__PURE__ */ new Set());
59
+ for (const command of commands) commandSet.add(command);
60
+ return result;
61
+ };
62
+ }
63
+
64
+ //#endregion
65
+ Object.defineProperty(exports, 'CliModule', {
66
+ enumerable: true,
67
+ get: function () {
68
+ return CliModule;
69
+ }
70
+ });
71
+ //# sourceMappingURL=cli-module.decorator-CkP22084.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli-module.decorator-CkP22084.cjs","names":["Module","getModuleMetadata","getModuleCustomEntry","CommandEntryKey","CliModule","commands","controllers","imports","guards","overrides","priority","registry","target","context","kind","Error","result","metadata","commandSet","Set","command","add"],"sources":["../src/decorators/cli-module.decorator.mts"],"sourcesContent":["import type { ClassType, Registry } from '@navios/core'\n\nimport { Module, getModuleMetadata, getModuleCustomEntry } from '@navios/core'\n\nimport {\n CommandEntryKey,\n type CommandEntryValue,\n} from '../metadata/command-entry.metadata.mjs'\n\n/**\n * Options for the `@CliModule` decorator.\n *\n * @public\n */\nexport interface CliModuleOptions {\n /**\n * Array or Set of command classes to register in this module.\n * Commands must be decorated with `@Command`.\n */\n commands?: ClassType[] | Set<ClassType>\n /**\n * Array or Set of controller classes for HTTP endpoints.\n * Allows mixing HTTP and CLI functionality in the same module.\n */\n controllers?: ClassType[] | Set<ClassType>\n /**\n * Array or Set of other modules to import.\n * Imported modules' commands and controllers will be available.\n */\n imports?: ClassType[] | Set<ClassType>\n /**\n * Guards to apply to all controllers in this module.\n * Guards are executed in reverse order (last guard first).\n */\n guards?: ClassType[] | Set<ClassType>\n /**\n * Service override classes to import for side effects.\n * These classes are imported to ensure their @Injectable decorators execute,\n * allowing them to register with the DI system. Overrides should use the same\n * InjectionToken as the original service with a higher priority.\n */\n overrides?: ClassType[] | Set<ClassType>\n /**\n * Priority level for the module.\n * Higher priority modules will be loaded first.\n */\n priority?: number\n /**\n * Registry to use for the module.\n * Registry is used to store the module and its commands.\n */\n registry?: Registry\n}\n\n/**\n * Decorator that marks a class as a CLI module.\n *\n * This decorator extends the standard @Module decorator, adding support for\n * CLI commands while maintaining full compatibility with HTTP controllers.\n * Modules organize commands and can import other modules to compose larger\n * CLI applications.\n *\n * The module can optionally implement `NaviosModule` interface for lifecycle hooks.\n *\n * @param options - Configuration options for the module\n * @returns A class decorator function\n *\n * @example\n * ```typescript\n * import { CliModule } from '@navios/commander'\n * import { GreetCommand } from './greet.command'\n * import { UserModule } from './user.module'\n *\n * @CliModule({\n * commands: [GreetCommand],\n * imports: [UserModule]\n * })\n * export class AppModule {}\n * ```\n *\n * @example\n * ```typescript\n * // Mixed HTTP and CLI module\n * @CliModule({\n * controllers: [HealthController],\n * commands: [MigrateCommand],\n * imports: [DatabaseModule],\n * })\n * export class AppModule {}\n * ```\n */\nexport function CliModule(\n {\n commands = [],\n controllers = [],\n imports = [],\n guards = [],\n overrides = [],\n priority,\n registry,\n }: CliModuleOptions = {\n commands: [],\n controllers: [],\n imports: [],\n guards: [],\n overrides: [],\n },\n) {\n return (target: ClassType, context: ClassDecoratorContext) => {\n if (context.kind !== 'class') {\n throw new Error(\n '[Navios Commander] @CliModule decorator can only be used on classes.',\n )\n }\n\n // Apply standard @Module decorator first\n const result = Module({\n controllers,\n imports,\n guards,\n overrides,\n priority,\n registry,\n })(target, context)\n\n // Get the module metadata that @Module just created\n const metadata = getModuleMetadata(target, context)\n\n // Store commands in customEntries\n const commandSet = getModuleCustomEntry<CommandEntryValue>(\n metadata,\n CommandEntryKey,\n () => new Set(),\n )\n for (const command of commands) {\n commandSet.add(command)\n }\n\n return result\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2FA,SAAgBI,UACd,EACEC,WAAW,EAAE,EACbC,cAAc,EAAE,EAChBC,UAAU,EAAE,EACZC,SAAS,EAAE,EACXC,YAAY,EAAE,EACdC,UACAC,aACoB;CACpBN,UAAU,EAAE;CACZC,aAAa,EAAE;CACfC,SAAS,EAAE;CACXC,QAAQ,EAAE;CACVC,WAAW,EAAE;CACd,EAAA;AAED,SAAQG,QAAmBC,YAAAA;AACzB,MAAIA,QAAQC,SAAS,QACnB,OAAM,IAAIC,MACR,uEAAA;EAKJ,MAAMC,kCAAgB;GACpBV;GACAC;GACAC;GACAC;GACAC;GACAC;GACF,CAAA,CAAGC,QAAQC,QAAAA;EAMX,MAAMK,wFAH6BN,QAAQC,QAAAA,EAKzCV,iEACM,IAAIgB,KAAAA,CAAAA;AAEZ,OAAK,MAAMC,WAAWf,SACpBa,YAAWG,IAAID,QAAAA;AAGjB,SAAOJ"}
@@ -0,0 +1,411 @@
1
+ import { AbstractAdapterInterface, AdapterEnvironment, ClassType, ClassTypeWithInstance, InjectionToken, Registry } from "@navios/core";
2
+ import { ZodObject } from "zod";
3
+
4
+ //#region src/interfaces/command-handler.interface.d.mts
5
+
6
+ /**
7
+ * Interface that all command classes must implement.
8
+ *
9
+ * Commands decorated with `@Command` must implement this interface.
10
+ * The `execute` method is called when the command is invoked.
11
+ *
12
+ * @template TOptions - The type of options that the command accepts
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * import { Command, CommandHandler } from '@navios/commander'
17
+ * import { z } from 'zod'
18
+ *
19
+ * const optionsSchema = z.object({
20
+ * name: z.string()
21
+ * })
22
+ *
23
+ * type Options = z.infer<typeof optionsSchema>
24
+ *
25
+ * @Command({ path: 'greet', optionsSchema })
26
+ * export class GreetCommand implements CommandHandler<Options> {
27
+ * async execute(options: Options) {
28
+ * console.log(`Hello, ${options.name}!`)
29
+ * }
30
+ * }
31
+ * ```
32
+ */
33
+ interface CommandHandler<TOptions = any> {
34
+ /**
35
+ * Executes the command with the provided options.
36
+ *
37
+ * @param options - The validated command options (validated against the command's schema if provided)
38
+ * @returns A promise or void
39
+ */
40
+ execute(options: TOptions): void | Promise<void>;
41
+ }
42
+ //#endregion
43
+ //#region src/interfaces/abstract-cli-adapter.interface.d.mts
44
+ /**
45
+ * Interface for CLI adapters.
46
+ * Extends the base adapter interface with CLI-specific methods.
47
+ *
48
+ * @public
49
+ */
50
+ interface AbstractCliAdapterInterface extends AbstractAdapterInterface {
51
+ /**
52
+ * Run the CLI application with the given arguments.
53
+ * Parses arguments and executes the matching command.
54
+ *
55
+ * @param argv - Command-line arguments array (defaults to `process.argv`)
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * const adapter = app.getAdapter() as AbstractCliAdapterInterface
60
+ * await adapter.run(process.argv)
61
+ * ```
62
+ */
63
+ run(argv?: string[]): Promise<void>;
64
+ /**
65
+ * Execute a command programmatically with the provided options.
66
+ *
67
+ * @param path - The command path (e.g., 'greet', 'user:create')
68
+ * @param options - The command options object
69
+ *
70
+ * @example
71
+ * ```typescript
72
+ * await adapter.executeCommand('user:create', {
73
+ * name: 'John',
74
+ * email: 'john@example.com',
75
+ * })
76
+ * ```
77
+ */
78
+ executeCommand(path: string, options: Record<string, unknown>): Promise<void>;
79
+ /**
80
+ * Get all registered command paths and their class references.
81
+ *
82
+ * @returns Array of objects containing path and class
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * const commands = adapter.getAllCommands()
87
+ * commands.forEach(({ path }) => console.log(path))
88
+ * ```
89
+ */
90
+ getAllCommands(): Array<{
91
+ path: string;
92
+ class: unknown;
93
+ }>;
94
+ }
95
+ //#endregion
96
+ //#region src/interfaces/environment.interface.d.mts
97
+ /**
98
+ * Options for configuring the CLI adapter.
99
+ *
100
+ * @public
101
+ */
102
+ interface CliAdapterOptions {}
103
+ /**
104
+ * Environment type definition for CLI adapters.
105
+ * Used with NaviosFactory.create<CliEnvironment>() for type-safe CLI applications.
106
+ *
107
+ * @public
108
+ *
109
+ * @example
110
+ * ```typescript
111
+ * import { NaviosFactory } from '@navios/core'
112
+ * import { defineCliEnvironment, type CliEnvironment } from '@navios/commander'
113
+ *
114
+ * const app = await NaviosFactory.create<CliEnvironment>(AppModule, {
115
+ * adapter: defineCliEnvironment(),
116
+ * })
117
+ * ```
118
+ */
119
+ interface CliEnvironment extends AdapterEnvironment {
120
+ options: CliAdapterOptions;
121
+ adapter: AbstractCliAdapterInterface;
122
+ }
123
+ //#endregion
124
+ //#region src/metadata/command.metadata.d.mts
125
+ /**
126
+ * @internal
127
+ * Symbol key used to store command metadata on classes.
128
+ */
129
+ declare const CommandMetadataKey: unique symbol;
130
+ /**
131
+ * Metadata associated with a command.
132
+ *
133
+ * @public
134
+ */
135
+ interface CommandMetadata {
136
+ /**
137
+ * The command path (e.g., 'greet', 'user:create').
138
+ */
139
+ path: string;
140
+ /**
141
+ * Optional description of the command for help text.
142
+ */
143
+ description?: string;
144
+ /**
145
+ * Optional Zod schema for validating command options.
146
+ */
147
+ optionsSchema?: ZodObject;
148
+ /**
149
+ * Map of custom attributes that can be attached to the command.
150
+ */
151
+ customAttributes: Map<string | symbol, any>;
152
+ }
153
+ /**
154
+ * Gets or creates command metadata for a class.
155
+ *
156
+ * @internal
157
+ * @param target - The command class
158
+ * @param context - The decorator context
159
+ * @param path - The command path
160
+ * @param description - Optional description for help text
161
+ * @param optionsSchema - Optional Zod schema
162
+ * @returns The command metadata
163
+ */
164
+ declare function getCommandMetadata(target: ClassType, context: ClassDecoratorContext, path: string, description?: string, optionsSchema?: ZodObject): CommandMetadata;
165
+ /**
166
+ * Extracts command metadata from a class.
167
+ *
168
+ * @param target - The command class
169
+ * @returns The command metadata
170
+ * @throws {Error} If the class is not decorated with @Command
171
+ *
172
+ * @example
173
+ * ```typescript
174
+ * const metadata = extractCommandMetadata(GreetCommand)
175
+ * console.log(metadata.path) // 'greet'
176
+ * ```
177
+ */
178
+ declare function extractCommandMetadata(target: ClassType): CommandMetadata;
179
+ /**
180
+ * Checks if a class has command metadata.
181
+ *
182
+ * @param target - The class to check
183
+ * @returns `true` if the class is decorated with @Command, `false` otherwise
184
+ */
185
+ declare function hasCommandMetadata(target: ClassType): boolean;
186
+ //#endregion
187
+ //#region src/interfaces/commander-execution-context.interface.d.mts
188
+ /**
189
+ * Execution context for a command execution.
190
+ *
191
+ * Provides access to command metadata, path, and validated options during command execution.
192
+ * This context is automatically injected and available via the `CommandExecutionContext` token.
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * import { inject, Injectable } from '@navios/core'
197
+ * import { CommandExecutionContext } from '@navios/commander'
198
+ *
199
+ * @Injectable()
200
+ * class CommandLogger {
201
+ * private ctx = inject(CommandExecutionContext)
202
+ *
203
+ * log() {
204
+ * console.log('Command:', this.ctx.getCommandPath())
205
+ * console.log('Options:', this.ctx.getOptions())
206
+ * }
207
+ * }
208
+ * ```
209
+ */
210
+ declare class CommanderExecutionContext {
211
+ private readonly command;
212
+ private readonly commandPath;
213
+ private readonly options;
214
+ /**
215
+ * @internal
216
+ * Creates a new execution context.
217
+ */
218
+ constructor(command: CommandMetadata, commandPath: string, options: any);
219
+ /**
220
+ * Gets the command metadata.
221
+ *
222
+ * @returns The command metadata including path and options schema
223
+ */
224
+ getCommand(): CommandMetadata;
225
+ /**
226
+ * Gets the command path that was invoked.
227
+ *
228
+ * @returns The command path (e.g., 'greet', 'user:create')
229
+ */
230
+ getCommandPath(): string;
231
+ /**
232
+ * Gets the validated command options.
233
+ *
234
+ * Options are validated against the command's Zod schema if one was provided.
235
+ *
236
+ * @returns The validated options object
237
+ */
238
+ getOptions(): any;
239
+ }
240
+ //#endregion
241
+ //#region src/decorators/command.decorator.d.mts
242
+ /**
243
+ * Options for the `@Command` decorator.
244
+ *
245
+ * @public
246
+ */
247
+ interface CommandOptions {
248
+ /**
249
+ * The token to use for the command.
250
+ * If provided, the command will be registered with this token.
251
+ */
252
+ token?: InjectionToken<ClassTypeWithInstance<CommandHandler<any>>>;
253
+ /**
254
+ * The command path that users will invoke from the CLI.
255
+ * Can be a single word (e.g., 'greet') or multi-word with colons (e.g., 'user:create', 'db:migrate').
256
+ */
257
+ path: string;
258
+ /**
259
+ * Optional description of the command for help text.
260
+ * Displayed when users run `help` or `--help`.
261
+ */
262
+ description?: string;
263
+ /**
264
+ * Optional Zod schema for validating command options.
265
+ * If provided, options will be validated and parsed according to this schema.
266
+ */
267
+ optionsSchema?: ZodObject;
268
+ /**
269
+ * Priority level for the command.
270
+ * Higher priority commands will be loaded first.
271
+ */
272
+ priority?: number;
273
+ /**
274
+ * Registry to use for the command.
275
+ * Registry is used to store the command and its options schema.
276
+ */
277
+ registry?: Registry;
278
+ }
279
+ /**
280
+ * Decorator that marks a class as a CLI command.
281
+ *
282
+ * The decorated class must implement the `CommandHandler` interface with an `execute` method.
283
+ * The command will be automatically registered when its module is loaded.
284
+ *
285
+ * @param options - Configuration options for the command
286
+ * @returns A class decorator function
287
+ *
288
+ * @example
289
+ * ```typescript
290
+ * import { Command, CommandHandler } from '@navios/commander'
291
+ * import { z } from 'zod'
292
+ *
293
+ * const optionsSchema = z.object({
294
+ * name: z.string(),
295
+ * greeting: z.string().optional().default('Hello')
296
+ * })
297
+ *
298
+ * @Command({
299
+ * path: 'greet',
300
+ * optionsSchema: optionsSchema
301
+ * })
302
+ * export class GreetCommand implements CommandHandler<z.infer<typeof optionsSchema>> {
303
+ * async execute(options) {
304
+ * console.log(`${options.greeting}, ${options.name}!`)
305
+ * }
306
+ * }
307
+ * ```
308
+ */
309
+ declare function Command({
310
+ path,
311
+ description,
312
+ token,
313
+ optionsSchema,
314
+ priority,
315
+ registry
316
+ }: CommandOptions): (target: ClassType, context: ClassDecoratorContext) => any;
317
+ //#endregion
318
+ //#region src/decorators/cli-module.decorator.d.mts
319
+ /**
320
+ * Options for the `@CliModule` decorator.
321
+ *
322
+ * @public
323
+ */
324
+ interface CliModuleOptions {
325
+ /**
326
+ * Array or Set of command classes to register in this module.
327
+ * Commands must be decorated with `@Command`.
328
+ */
329
+ commands?: ClassType[] | Set<ClassType>;
330
+ /**
331
+ * Array or Set of controller classes for HTTP endpoints.
332
+ * Allows mixing HTTP and CLI functionality in the same module.
333
+ */
334
+ controllers?: ClassType[] | Set<ClassType>;
335
+ /**
336
+ * Array or Set of other modules to import.
337
+ * Imported modules' commands and controllers will be available.
338
+ */
339
+ imports?: ClassType[] | Set<ClassType>;
340
+ /**
341
+ * Guards to apply to all controllers in this module.
342
+ * Guards are executed in reverse order (last guard first).
343
+ */
344
+ guards?: ClassType[] | Set<ClassType>;
345
+ /**
346
+ * Service override classes to import for side effects.
347
+ * These classes are imported to ensure their @Injectable decorators execute,
348
+ * allowing them to register with the DI system. Overrides should use the same
349
+ * InjectionToken as the original service with a higher priority.
350
+ */
351
+ overrides?: ClassType[] | Set<ClassType>;
352
+ /**
353
+ * Priority level for the module.
354
+ * Higher priority modules will be loaded first.
355
+ */
356
+ priority?: number;
357
+ /**
358
+ * Registry to use for the module.
359
+ * Registry is used to store the module and its commands.
360
+ */
361
+ registry?: Registry;
362
+ }
363
+ /**
364
+ * Decorator that marks a class as a CLI module.
365
+ *
366
+ * This decorator extends the standard @Module decorator, adding support for
367
+ * CLI commands while maintaining full compatibility with HTTP controllers.
368
+ * Modules organize commands and can import other modules to compose larger
369
+ * CLI applications.
370
+ *
371
+ * The module can optionally implement `NaviosModule` interface for lifecycle hooks.
372
+ *
373
+ * @param options - Configuration options for the module
374
+ * @returns A class decorator function
375
+ *
376
+ * @example
377
+ * ```typescript
378
+ * import { CliModule } from '@navios/commander'
379
+ * import { GreetCommand } from './greet.command'
380
+ * import { UserModule } from './user.module'
381
+ *
382
+ * @CliModule({
383
+ * commands: [GreetCommand],
384
+ * imports: [UserModule]
385
+ * })
386
+ * export class AppModule {}
387
+ * ```
388
+ *
389
+ * @example
390
+ * ```typescript
391
+ * // Mixed HTTP and CLI module
392
+ * @CliModule({
393
+ * controllers: [HealthController],
394
+ * commands: [MigrateCommand],
395
+ * imports: [DatabaseModule],
396
+ * })
397
+ * export class AppModule {}
398
+ * ```
399
+ */
400
+ declare function CliModule({
401
+ commands,
402
+ controllers,
403
+ imports,
404
+ guards,
405
+ overrides,
406
+ priority,
407
+ registry
408
+ }?: CliModuleOptions): (target: ClassType, context: ClassDecoratorContext) => ClassType;
409
+ //#endregion
410
+ export { CommanderExecutionContext as a, extractCommandMetadata as c, CliAdapterOptions as d, CliEnvironment as f, CommandOptions as i, getCommandMetadata as l, CommandHandler as m, CliModuleOptions as n, CommandMetadata as o, AbstractCliAdapterInterface as p, Command as r, CommandMetadataKey as s, CliModule as t, hasCommandMetadata as u };
411
+ //# sourceMappingURL=cli-module.decorator-DGuGfpex.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli-module.decorator-DGuGfpex.d.mts","names":["CommandHandler","TOptions","Promise","AbstractAdapterInterface","AbstractCliAdapterInterface","Promise","Record","Array","AdapterEnvironment","AbstractCliAdapterInterface","CliAdapterOptions","CliEnvironment","ClassType","ZodObject","CommandMetadataKey","CommandMetadata","Map","getCommandMetadata","ClassDecoratorContext","extractCommandMetadata","hasCommandMetadata","CommandMetadata","CommanderExecutionContext","InjectionToken","ClassType","ClassTypeWithInstance","Registry","ZodObject","CommandHandler","CommandOptions","Command","path","description","token","optionsSchema","priority","registry","ClassDecoratorContext","ClassType","Registry","CliModuleOptions","Set","CliModule","commands","controllers","imports","guards","overrides","priority","registry","ClassDecoratorContext"],"sources":["../src/interfaces/command-handler.interface.d.mts","../src/interfaces/abstract-cli-adapter.interface.d.mts","../src/interfaces/environment.interface.d.mts","../src/metadata/command.metadata.d.mts","../src/interfaces/commander-execution-context.interface.d.mts","../src/decorators/command.decorator.d.mts","../src/decorators/cli-module.decorator.d.mts"],"sourcesContent":["/**\n * Interface that all command classes must implement.\n *\n * Commands decorated with `@Command` must implement this interface.\n * The `execute` method is called when the command is invoked.\n *\n * @template TOptions - The type of options that the command accepts\n *\n * @example\n * ```typescript\n * import { Command, CommandHandler } from '@navios/commander'\n * import { z } from 'zod'\n *\n * const optionsSchema = z.object({\n * name: z.string()\n * })\n *\n * type Options = z.infer<typeof optionsSchema>\n *\n * @Command({ path: 'greet', optionsSchema })\n * export class GreetCommand implements CommandHandler<Options> {\n * async execute(options: Options) {\n * console.log(`Hello, ${options.name}!`)\n * }\n * }\n * ```\n */\nexport interface CommandHandler<TOptions = any> {\n /**\n * Executes the command with the provided options.\n *\n * @param options - The validated command options (validated against the command's schema if provided)\n * @returns A promise or void\n */\n execute(options: TOptions): void | Promise<void>;\n}\n//# sourceMappingURL=command-handler.interface.d.mts.map","import type { AbstractAdapterInterface } from '@navios/core';\n/**\n * Interface for CLI adapters.\n * Extends the base adapter interface with CLI-specific methods.\n *\n * @public\n */\nexport interface AbstractCliAdapterInterface extends AbstractAdapterInterface {\n /**\n * Run the CLI application with the given arguments.\n * Parses arguments and executes the matching command.\n *\n * @param argv - Command-line arguments array (defaults to `process.argv`)\n *\n * @example\n * ```typescript\n * const adapter = app.getAdapter() as AbstractCliAdapterInterface\n * await adapter.run(process.argv)\n * ```\n */\n run(argv?: string[]): Promise<void>;\n /**\n * Execute a command programmatically with the provided options.\n *\n * @param path - The command path (e.g., 'greet', 'user:create')\n * @param options - The command options object\n *\n * @example\n * ```typescript\n * await adapter.executeCommand('user:create', {\n * name: 'John',\n * email: 'john@example.com',\n * })\n * ```\n */\n executeCommand(path: string, options: Record<string, unknown>): Promise<void>;\n /**\n * Get all registered command paths and their class references.\n *\n * @returns Array of objects containing path and class\n *\n * @example\n * ```typescript\n * const commands = adapter.getAllCommands()\n * commands.forEach(({ path }) => console.log(path))\n * ```\n */\n getAllCommands(): Array<{\n path: string;\n class: unknown;\n }>;\n}\n//# sourceMappingURL=abstract-cli-adapter.interface.d.mts.map","import type { AdapterEnvironment } from '@navios/core';\nimport type { AbstractCliAdapterInterface } from './abstract-cli-adapter.interface.mjs';\n/**\n * Options for configuring the CLI adapter.\n *\n * @public\n */\nexport interface CliAdapterOptions {\n}\n/**\n * Environment type definition for CLI adapters.\n * Used with NaviosFactory.create<CliEnvironment>() for type-safe CLI applications.\n *\n * @public\n *\n * @example\n * ```typescript\n * import { NaviosFactory } from '@navios/core'\n * import { defineCliEnvironment, type CliEnvironment } from '@navios/commander'\n *\n * const app = await NaviosFactory.create<CliEnvironment>(AppModule, {\n * adapter: defineCliEnvironment(),\n * })\n * ```\n */\nexport interface CliEnvironment extends AdapterEnvironment {\n options: CliAdapterOptions;\n adapter: AbstractCliAdapterInterface;\n}\n//# sourceMappingURL=environment.interface.d.mts.map","import type { ClassType } from '@navios/core';\nimport type { ZodObject } from 'zod';\n/**\n * @internal\n * Symbol key used to store command metadata on classes.\n */\nexport declare const CommandMetadataKey: unique symbol;\n/**\n * Metadata associated with a command.\n *\n * @public\n */\nexport interface CommandMetadata {\n /**\n * The command path (e.g., 'greet', 'user:create').\n */\n path: string;\n /**\n * Optional description of the command for help text.\n */\n description?: string;\n /**\n * Optional Zod schema for validating command options.\n */\n optionsSchema?: ZodObject;\n /**\n * Map of custom attributes that can be attached to the command.\n */\n customAttributes: Map<string | symbol, any>;\n}\n/**\n * Gets or creates command metadata for a class.\n *\n * @internal\n * @param target - The command class\n * @param context - The decorator context\n * @param path - The command path\n * @param description - Optional description for help text\n * @param optionsSchema - Optional Zod schema\n * @returns The command metadata\n */\nexport declare function getCommandMetadata(target: ClassType, context: ClassDecoratorContext, path: string, description?: string, optionsSchema?: ZodObject): CommandMetadata;\n/**\n * Extracts command metadata from a class.\n *\n * @param target - The command class\n * @returns The command metadata\n * @throws {Error} If the class is not decorated with @Command\n *\n * @example\n * ```typescript\n * const metadata = extractCommandMetadata(GreetCommand)\n * console.log(metadata.path) // 'greet'\n * ```\n */\nexport declare function extractCommandMetadata(target: ClassType): CommandMetadata;\n/**\n * Checks if a class has command metadata.\n *\n * @param target - The class to check\n * @returns `true` if the class is decorated with @Command, `false` otherwise\n */\nexport declare function hasCommandMetadata(target: ClassType): boolean;\n//# sourceMappingURL=command.metadata.d.mts.map","import type { CommandMetadata } from '../metadata/command.metadata.mjs';\n/**\n * Execution context for a command execution.\n *\n * Provides access to command metadata, path, and validated options during command execution.\n * This context is automatically injected and available via the `CommandExecutionContext` token.\n *\n * @example\n * ```typescript\n * import { inject, Injectable } from '@navios/core'\n * import { CommandExecutionContext } from '@navios/commander'\n *\n * @Injectable()\n * class CommandLogger {\n * private ctx = inject(CommandExecutionContext)\n *\n * log() {\n * console.log('Command:', this.ctx.getCommandPath())\n * console.log('Options:', this.ctx.getOptions())\n * }\n * }\n * ```\n */\nexport declare class CommanderExecutionContext {\n private readonly command;\n private readonly commandPath;\n private readonly options;\n /**\n * @internal\n * Creates a new execution context.\n */\n constructor(command: CommandMetadata, commandPath: string, options: any);\n /**\n * Gets the command metadata.\n *\n * @returns The command metadata including path and options schema\n */\n getCommand(): CommandMetadata;\n /**\n * Gets the command path that was invoked.\n *\n * @returns The command path (e.g., 'greet', 'user:create')\n */\n getCommandPath(): string;\n /**\n * Gets the validated command options.\n *\n * Options are validated against the command's Zod schema if one was provided.\n *\n * @returns The validated options object\n */\n getOptions(): any;\n}\n//# sourceMappingURL=commander-execution-context.interface.d.mts.map","import { InjectionToken } from '@navios/core';\nimport type { ClassType, ClassTypeWithInstance, Registry } from '@navios/core';\nimport type { ZodObject } from 'zod';\nimport type { CommandHandler } from '../interfaces/index.mjs';\n/**\n * Options for the `@Command` decorator.\n *\n * @public\n */\nexport interface CommandOptions {\n /**\n * The token to use for the command.\n * If provided, the command will be registered with this token.\n */\n token?: InjectionToken<ClassTypeWithInstance<CommandHandler<any>>>;\n /**\n * The command path that users will invoke from the CLI.\n * Can be a single word (e.g., 'greet') or multi-word with colons (e.g., 'user:create', 'db:migrate').\n */\n path: string;\n /**\n * Optional description of the command for help text.\n * Displayed when users run `help` or `--help`.\n */\n description?: string;\n /**\n * Optional Zod schema for validating command options.\n * If provided, options will be validated and parsed according to this schema.\n */\n optionsSchema?: ZodObject;\n /**\n * Priority level for the command.\n * Higher priority commands will be loaded first.\n */\n priority?: number;\n /**\n * Registry to use for the command.\n * Registry is used to store the command and its options schema.\n */\n registry?: Registry;\n}\n/**\n * Decorator that marks a class as a CLI command.\n *\n * The decorated class must implement the `CommandHandler` interface with an `execute` method.\n * The command will be automatically registered when its module is loaded.\n *\n * @param options - Configuration options for the command\n * @returns A class decorator function\n *\n * @example\n * ```typescript\n * import { Command, CommandHandler } from '@navios/commander'\n * import { z } from 'zod'\n *\n * const optionsSchema = z.object({\n * name: z.string(),\n * greeting: z.string().optional().default('Hello')\n * })\n *\n * @Command({\n * path: 'greet',\n * optionsSchema: optionsSchema\n * })\n * export class GreetCommand implements CommandHandler<z.infer<typeof optionsSchema>> {\n * async execute(options) {\n * console.log(`${options.greeting}, ${options.name}!`)\n * }\n * }\n * ```\n */\nexport declare function Command({ path, description, token, optionsSchema, priority, registry, }: CommandOptions): (target: ClassType, context: ClassDecoratorContext) => any;\n//# sourceMappingURL=command.decorator.d.mts.map","import type { ClassType, Registry } from '@navios/core';\n/**\n * Options for the `@CliModule` decorator.\n *\n * @public\n */\nexport interface CliModuleOptions {\n /**\n * Array or Set of command classes to register in this module.\n * Commands must be decorated with `@Command`.\n */\n commands?: ClassType[] | Set<ClassType>;\n /**\n * Array or Set of controller classes for HTTP endpoints.\n * Allows mixing HTTP and CLI functionality in the same module.\n */\n controllers?: ClassType[] | Set<ClassType>;\n /**\n * Array or Set of other modules to import.\n * Imported modules' commands and controllers will be available.\n */\n imports?: ClassType[] | Set<ClassType>;\n /**\n * Guards to apply to all controllers in this module.\n * Guards are executed in reverse order (last guard first).\n */\n guards?: ClassType[] | Set<ClassType>;\n /**\n * Service override classes to import for side effects.\n * These classes are imported to ensure their @Injectable decorators execute,\n * allowing them to register with the DI system. Overrides should use the same\n * InjectionToken as the original service with a higher priority.\n */\n overrides?: ClassType[] | Set<ClassType>;\n /**\n * Priority level for the module.\n * Higher priority modules will be loaded first.\n */\n priority?: number;\n /**\n * Registry to use for the module.\n * Registry is used to store the module and its commands.\n */\n registry?: Registry;\n}\n/**\n * Decorator that marks a class as a CLI module.\n *\n * This decorator extends the standard @Module decorator, adding support for\n * CLI commands while maintaining full compatibility with HTTP controllers.\n * Modules organize commands and can import other modules to compose larger\n * CLI applications.\n *\n * The module can optionally implement `NaviosModule` interface for lifecycle hooks.\n *\n * @param options - Configuration options for the module\n * @returns A class decorator function\n *\n * @example\n * ```typescript\n * import { CliModule } from '@navios/commander'\n * import { GreetCommand } from './greet.command'\n * import { UserModule } from './user.module'\n *\n * @CliModule({\n * commands: [GreetCommand],\n * imports: [UserModule]\n * })\n * export class AppModule {}\n * ```\n *\n * @example\n * ```typescript\n * // Mixed HTTP and CLI module\n * @CliModule({\n * controllers: [HealthController],\n * commands: [MigrateCommand],\n * imports: [DatabaseModule],\n * })\n * export class AppModule {}\n * ```\n */\nexport declare function CliModule({ commands, controllers, imports, guards, overrides, priority, registry, }?: CliModuleOptions): (target: ClassType, context: ClassDecoratorContext) => ClassType;\n//# sourceMappingURL=cli-module.decorator.d.mts.map"],"mappings":";;;;;;;;;AA2BA;;;;ACpBA;;;;;;;;;;ACAA;AAkBA;;;;;;;;ACnBqBc,UHqBJd,cGrBqC,CAAA,WAAA,GAAA,CAAA,CAAA;EAMrCe;AA6BjB;;;;;EAA6K,OAAA,CAAA,OAAA,EHPxJd,QGOwJ,CAAA,EAAA,IAAA,GHPtIC,OGOsI,CAAA,IAAA,CAAA;AAc7K;;;;;;AH5BA;;;UCpBiBE,2BAAAA,SAAoCD;EAApCC;;;;;;;;;;ACAjB;AAkBA;EACaM,GAAAA,CAAAA,IAAAA,CAAAA,EAAAA,MAAAA,EAAAA,CAAAA,EDNaL,OCMbK,CAAAA,IAAAA,CAAAA;EACAD;;;;;;ACrBb;AAMA;AA6BA;;;;;;EAcwBU,cAAAA,CAAAA,IAAAA,EAAAA,MAAsB,EAAA,OAAA,EFpBJb,MEoBaM,CAAAA,MAAYG,EAAAA,OAAAA,CAAAA,CAAAA,EFpBCV,OEoBc,CAAA,IAAA,CAAA;EAO1De;;;;ACvCxB;;;;ACdA;;;EAKYG,cAAAA,EAAAA,EJiCUhB,KIjCVgB,CAAAA;IAeQI,IAAAA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