@navios/commander 0.5.0 → 0.5.2

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 (33) hide show
  1. package/README.md +37 -0
  2. package/dist/src/commander.application.d.mts.map +1 -1
  3. package/dist/src/index.d.mts +1 -0
  4. package/dist/src/index.d.mts.map +1 -1
  5. package/dist/src/interfaces/commander-execution-context.interface.d.mts +11 -0
  6. package/dist/src/interfaces/commander-execution-context.interface.d.mts.map +1 -0
  7. package/dist/src/interfaces/index.d.mts +1 -0
  8. package/dist/src/interfaces/index.d.mts.map +1 -1
  9. package/dist/src/services/cli-parser.service.d.mts +10 -0
  10. package/dist/src/services/cli-parser.service.d.mts.map +1 -1
  11. package/dist/src/tokens/execution-context.token.d.mts +5 -0
  12. package/dist/src/tokens/execution-context.token.d.mts.map +1 -0
  13. package/dist/src/tokens/index.d.mts +2 -0
  14. package/dist/src/tokens/index.d.mts.map +1 -0
  15. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  16. package/dist/tsconfig.tsbuildinfo +1 -1
  17. package/lib/_tsup-dts-rollup.d.mts +33 -0
  18. package/lib/_tsup-dts-rollup.d.ts +33 -0
  19. package/lib/index.d.mts +3 -0
  20. package/lib/index.d.ts +3 -0
  21. package/lib/index.js +108 -7
  22. package/lib/index.js.map +1 -1
  23. package/lib/index.mjs +107 -9
  24. package/lib/index.mjs.map +1 -1
  25. package/package.json +1 -1
  26. package/src/commander.application.mts +32 -8
  27. package/src/index.mts +1 -0
  28. package/src/interfaces/commander-execution-context.interface.mts +21 -0
  29. package/src/interfaces/index.mts +1 -0
  30. package/src/services/__tests__/cli-parser.service.spec.mts +251 -0
  31. package/src/services/cli-parser.service.mts +81 -2
  32. package/src/tokens/execution-context.token.mts +10 -0
  33. package/src/tokens/index.mts +1 -0
package/README.md CHANGED
@@ -129,6 +129,43 @@ export class UserModule {}
129
129
  export class AppModule {}
130
130
  ```
131
131
 
132
+ ### Accessing ExecutionContext
133
+
134
+ 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.
135
+
136
+ ```typescript
137
+ import { Command, CommandHandler, ExecutionContext } from '@navios/commander'
138
+ import { Injectable, inject } from '@navios/di'
139
+
140
+ @Injectable()
141
+ class CommandLogger {
142
+ private executionContext = inject(ExecutionContext)
143
+
144
+ logCommandInfo() {
145
+ const ctx = this.executionContext
146
+ console.log('Command Path:', ctx.getCommandPath())
147
+ console.log('Command Options:', ctx.getOptions())
148
+ console.log('Module:', ctx.getModule())
149
+ }
150
+ }
151
+
152
+ @Command({ path: 'example' })
153
+ export class ExampleCommand implements CommandHandler {
154
+ private logger = inject(CommandLogger)
155
+
156
+ async execute(options: any) {
157
+ this.logger.logCommandInfo()
158
+ // Your command logic here
159
+ }
160
+ }
161
+ ```
162
+
163
+ The `ExecutionContext` provides the following methods:
164
+ - `getModule()` - Returns the CLI module metadata
165
+ - `getCommand()` - Returns the command metadata
166
+ - `getCommandPath()` - Returns the command path (e.g., 'user:create')
167
+ - `getOptions()` - Returns the validated command options
168
+
132
169
  ### Listing All Commands
133
170
 
134
171
  ```typescript
@@ -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,EAAE,qBAAqB,EAAkB,MAAM,YAAY,CAAA;AAEvE,OAAO,EAAE,SAAS,EAAsB,MAAM,YAAY,CAAA;AAE1D,OAAO,KAAK,EAAkB,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAMpE,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;IA0D3D,cAAc;cAIJ,MAAM;eACL,qBAAqB,CAAC,GAAG,CAAC;;IAarC;;;OAGG;IACG,GAAG,CAAC,IAAI,GAAE,MAAM,EAAiB;IAgDjC,OAAO;IAMP,KAAK;CAGZ"}
@@ -5,4 +5,5 @@ 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":"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;AACpC,cAAc,oBAAoB,CAAA"}
@@ -0,0 +1,11 @@
1
+ import type { CommandMetadata } from '../metadata/command.metadata.mjs';
2
+ export declare class CommanderExecutionContext {
3
+ private readonly command;
4
+ private readonly commandPath;
5
+ private readonly options;
6
+ constructor(command: CommandMetadata, commandPath: string, options: any);
7
+ getCommand(): CommandMetadata;
8
+ getCommandPath(): string;
9
+ getOptions(): any;
10
+ }
11
+ //# 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,qBAAa,yBAAyB;IAElC,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAFP,OAAO,EAAE,eAAe,EACxB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,GAAG;IAG/B,UAAU,IAAI,eAAe;IAI7B,cAAc,IAAI,MAAM;IAIxB,UAAU,IAAI,GAAG;CAGlB"}
@@ -1,3 +1,4 @@
1
1
  export * from './module.interface.mjs';
2
2
  export * from './command-handler.interface.mjs';
3
+ export * from './commander-execution-context.interface.mjs';
3
4
  //# 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,wBAAwB,CAAA;AACtC,cAAc,iCAAiC,CAAA;AAC/C,cAAc,6CAA6C,CAAA"}
@@ -28,11 +28,21 @@ export declare class CliParserService {
28
28
  * Handles ZodObject, ZodOptional, and ZodDefault wrappers
29
29
  */
30
30
  private extractBooleanFields;
31
+ /**
32
+ * Extracts array field names from a Zod schema
33
+ * Handles ZodObject, ZodOptional, and ZodDefault wrappers
34
+ */
35
+ private extractArrayFields;
31
36
  /**
32
37
  * Checks if a Zod schema represents a boolean type
33
38
  * Unwraps ZodOptional and ZodDefault
34
39
  */
35
40
  private isSchemaBoolean;
41
+ /**
42
+ * Checks if a Zod schema represents an array type
43
+ * Unwraps ZodOptional and ZodDefault
44
+ */
45
+ private isSchemaArray;
36
46
  /**
37
47
  * Formats help text for available commands
38
48
  */
@@ -1 +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;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GAAG,MAAM;CAOzE"}
@@ -0,0 +1,5 @@
1
+ import { InjectionToken } from '@navios/di';
2
+ import type { CommanderExecutionContext } from '../interfaces/index.mjs';
3
+ export declare const ExecutionContextInjectionToken = "CommanderExecutionContextInjectionToken";
4
+ export declare const ExecutionContext: InjectionToken<CommanderExecutionContext, undefined, false>;
5
+ //# sourceMappingURL=execution-context.token.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution-context.token.d.mts","sourceRoot":"","sources":["../../../src/tokens/execution-context.token.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAE3C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAA;AAExE,eAAO,MAAM,8BAA8B,4CACA,CAAA;AAE3C,eAAO,MAAM,gBAAgB,6DAE5B,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './execution-context.token.mjs';
2
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/tokens/index.mts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAA"}