@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
@@ -1,466 +0,0 @@
1
- import { AnyInjectableType } from '@navios/di';
2
- import { asyncInject } from '@navios/di';
3
- import { BaseInjectionTokenSchemaType } from '@navios/di';
4
- import { BaseInstanceHolderManager } from '@navios/di';
5
- import { BoundInjectionToken } from '@navios/di';
6
- import { ChannelEmitter } from '@navios/di';
7
- import { ClassType } from '@navios/di';
8
- import { ClassTypeWithArgument } from '@navios/di';
9
- import { ClassTypeWithInstance } from '@navios/di';
10
- import { ClassTypeWithInstanceAndArgument } from '@navios/di';
11
- import { ClassTypeWithInstanceAndOptionalArgument } from '@navios/di';
12
- import { ClassTypeWithOptionalArgument } from '@navios/di';
13
- import { Container } from '@navios/di';
14
- import { createRequestContextHolder } from '@navios/di';
15
- import { defaultInjectors } from '@navios/di';
16
- import { DefaultRequestContextHolder } from '@navios/di';
17
- import { DIError } from '@navios/di';
18
- import { DIErrorCode } from '@navios/di';
19
- import { ErrorsEnum } from '@navios/di';
20
- import { EventEmitter } from '@navios/di';
21
- import { EventEmitterInterface } from '@navios/di';
22
- import { EventsArgs } from '@navios/di';
23
- import { EventsConfig } from '@navios/di';
24
- import { EventsNames } from '@navios/di';
25
- import { Factorable } from '@navios/di';
26
- import { FactorableWithArgs } from '@navios/di';
27
- import { Factory } from '@navios/di';
28
- import { FactoryContext } from '@navios/di';
29
- import { FactoryInjectionToken } from '@navios/di';
30
- import { FactoryNotFound } from '@navios/di';
31
- import { FactoryOptions } from '@navios/di';
32
- import { FactoryRecord } from '@navios/di';
33
- import { FactoryTokenNotResolved } from '@navios/di';
34
- import { getInjectableToken } from '@navios/di';
35
- import { getInjectors } from '@navios/di';
36
- import { globalRegistry } from '@navios/di';
37
- import { inject } from '@navios/di';
38
- import { Injectable } from '@navios/di';
39
- import { InjectableOptions } from '@navios/di';
40
- import { InjectableScope } from '@navios/di';
41
- import { InjectableTokenMeta } from '@navios/di';
42
- import { InjectableType } from '@navios/di';
43
- import { InjectionToken } from '@navios/di';
44
- import { InjectionTokenSchemaType } from '@navios/di';
45
- import { InjectionTokenType } from '@navios/di';
46
- import { Injectors } from '@navios/di';
47
- import { InjectState } from '@navios/di';
48
- import { InstanceDestroying } from '@navios/di';
49
- import { InstanceNotFound } from '@navios/di';
50
- import { IsUnion } from '@navios/di';
51
- import { Join } from '@navios/di';
52
- import { OnServiceDestroy } from '@navios/di';
53
- import { OnServiceInit } from '@navios/di';
54
- import { OptionalInjectionTokenSchemaType } from '@navios/di';
55
- import { Options } from 'tsup';
56
- import { PopUnion } from '@navios/di';
57
- import { provideFactoryContext } from '@navios/di';
58
- import { Registry } from '@navios/di';
59
- import { RequestContextHolder } from '@navios/di';
60
- import { ServiceInstantiator } from '@navios/di';
61
- import { ServiceLocator } from '@navios/di';
62
- import { ServiceLocatorEventBus } from '@navios/di';
63
- import { ServiceLocatorInstanceDestroyListener } from '@navios/di';
64
- import { ServiceLocatorInstanceEffect } from '@navios/di';
65
- import { ServiceLocatorInstanceHolder } from '@navios/di';
66
- import { ServiceLocatorInstanceHolderCreated } from '@navios/di';
67
- import { ServiceLocatorInstanceHolderCreating } from '@navios/di';
68
- import { ServiceLocatorInstanceHolderDestroying } from '@navios/di';
69
- import { ServiceLocatorInstanceHolderError } from '@navios/di';
70
- import { ServiceLocatorInstanceHolderStatus } from '@navios/di';
71
- import { ServiceLocatorManager } from '@navios/di';
72
- import { UnionToArray } from '@navios/di';
73
- import { UnionToIntersection } from '@navios/di';
74
- import { UnionToOvlds } from '@navios/di';
75
- import { UnknownError } from '@navios/di';
76
- import { UserWorkspaceConfig } from 'vitest/config';
77
- import { wrapSyncInit } from '@navios/di';
78
- import type { ZodObject } from 'zod';
79
-
80
- export { AnyInjectableType }
81
-
82
- export { asyncInject }
83
-
84
- export { BaseInjectionTokenSchemaType }
85
-
86
- export { BaseInstanceHolderManager }
87
-
88
- export { BoundInjectionToken }
89
-
90
- export { ChannelEmitter }
91
-
92
- export { ClassType }
93
-
94
- export { ClassTypeWithArgument }
95
-
96
- export { ClassTypeWithInstance }
97
-
98
- export { ClassTypeWithInstanceAndArgument }
99
-
100
- export { ClassTypeWithInstanceAndOptionalArgument }
101
-
102
- export { ClassTypeWithOptionalArgument }
103
-
104
- declare function CliModule({ commands, imports }?: CliModuleOptions): (target: ClassType, context: ClassDecoratorContext) => ClassType;
105
- export { CliModule }
106
- export { CliModule as CliModule_alias_1 }
107
- export { CliModule as CliModule_alias_2 }
108
-
109
- declare interface CliModuleMetadata {
110
- commands: Set<ClassType>;
111
- imports: Set<ClassType>;
112
- customAttributes: Map<string | symbol, any>;
113
- }
114
- export { CliModuleMetadata }
115
- export { CliModuleMetadata as CliModuleMetadata_alias_1 }
116
- export { CliModuleMetadata as CliModuleMetadata_alias_2 }
117
-
118
- declare const CliModuleMetadataKey: unique symbol;
119
- export { CliModuleMetadataKey }
120
- export { CliModuleMetadataKey as CliModuleMetadataKey_alias_1 }
121
- export { CliModuleMetadataKey as CliModuleMetadataKey_alias_2 }
122
-
123
- declare interface CliModuleOptions {
124
- commands?: ClassType[] | Set<ClassType>;
125
- imports?: ClassType[] | Set<ClassType>;
126
- }
127
- export { CliModuleOptions }
128
- export { CliModuleOptions as CliModuleOptions_alias_1 }
129
- export { CliModuleOptions as CliModuleOptions_alias_2 }
130
-
131
- declare class CliParserService {
132
- /**
133
- * Parses command-line arguments from process.argv
134
- * Commands can be multi-word (e.g., 'db migrate', 'cache clear')
135
- * Expected format: node script.js command [subcommand...] --flag value --boolean-flag positional1 positional2
136
- *
137
- * @param argv - Array of command-line arguments (typically process.argv)
138
- * @param optionsSchema - Optional Zod schema to determine boolean flags and option types
139
- * @returns Parsed command (space-separated if multi-word), options, and positional arguments
140
- */
141
- parse(argv: string[], optionsSchema?: ZodObject): ParsedCliArgs;
142
- /**
143
- * Converts kebab-case to camelCase
144
- */
145
- private camelCase;
146
- /**
147
- * Attempts to parse string values into appropriate types
148
- */
149
- private parseValue;
150
- /**
151
- * Extracts boolean field names from a Zod schema
152
- * Handles ZodObject, ZodOptional, and ZodDefault wrappers
153
- */
154
- private extractBooleanFields;
155
- /**
156
- * Extracts array field names from a Zod schema
157
- * Handles ZodObject, ZodOptional, and ZodDefault wrappers
158
- */
159
- private extractArrayFields;
160
- /**
161
- * Checks if a Zod schema represents a boolean type
162
- * Unwraps ZodOptional and ZodDefault
163
- */
164
- private isSchemaBoolean;
165
- /**
166
- * Checks if a Zod schema represents an array type
167
- * Unwraps ZodOptional and ZodDefault
168
- */
169
- private isSchemaArray;
170
- /**
171
- * Formats help text for available commands
172
- */
173
- formatCommandList(commands: Array<{
174
- path: string;
175
- class: any;
176
- }>): string;
177
- }
178
- export { CliParserService }
179
- export { CliParserService as CliParserService_alias_1 }
180
- export { CliParserService as CliParserService_alias_2 }
181
-
182
- declare function Command({ path, optionsSchema }: CommandOptions): (target: ClassType, context: ClassDecoratorContext) => ClassType;
183
- export { Command }
184
- export { Command as Command_alias_1 }
185
- export { Command as Command_alias_2 }
186
-
187
- declare class CommanderApplication {
188
- private moduleLoader;
189
- private cliParser;
190
- protected container: Container;
191
- private appModule;
192
- private options;
193
- isInitialized: boolean;
194
- setup(appModule: ClassTypeWithInstance<Module>, options?: CommanderApplicationOptions): Promise<void>;
195
- getContainer(): Container;
196
- init(): Promise<void>;
197
- executeCommand(commandPath: string, options?: any): Promise<void>;
198
- getAllCommands(): {
199
- path: string;
200
- class: ClassTypeWithInstance<any>;
201
- }[];
202
- /**
203
- * Runs the CLI application by parsing process.argv and executing the command
204
- * @param argv - Command-line arguments (defaults to process.argv)
205
- */
206
- run(argv?: string[]): Promise<void>;
207
- dispose(): Promise<void>;
208
- close(): Promise<void>;
209
- }
210
- export { CommanderApplication }
211
- export { CommanderApplication as CommanderApplication_alias_1 }
212
-
213
- declare interface CommanderApplicationOptions {
214
- }
215
- export { CommanderApplicationOptions }
216
- export { CommanderApplicationOptions as CommanderApplicationOptions_alias_1 }
217
-
218
- declare class CommanderFactory {
219
- static create(appModule: ClassTypeWithInstance<Module>, options?: CommanderApplicationOptions): Promise<CommanderApplication>;
220
- }
221
- export { CommanderFactory }
222
- export { CommanderFactory as CommanderFactory_alias_1 }
223
-
224
- declare interface CommandHandler<TOptions = any> {
225
- execute(options: TOptions): void | Promise<void>;
226
- }
227
- export { CommandHandler }
228
- export { CommandHandler as CommandHandler_alias_1 }
229
- export { CommandHandler as CommandHandler_alias_2 }
230
-
231
- declare interface CommandMetadata {
232
- path: string;
233
- optionsSchema?: ZodObject;
234
- customAttributes: Map<string | symbol, any>;
235
- }
236
- export { CommandMetadata }
237
- export { CommandMetadata as CommandMetadata_alias_1 }
238
- export { CommandMetadata as CommandMetadata_alias_2 }
239
-
240
- declare const CommandMetadataKey: unique symbol;
241
- export { CommandMetadataKey }
242
- export { CommandMetadataKey as CommandMetadataKey_alias_1 }
243
- export { CommandMetadataKey as CommandMetadataKey_alias_2 }
244
-
245
- declare interface CommandOptions {
246
- path: string;
247
- optionsSchema?: ZodObject;
248
- }
249
- export { CommandOptions }
250
- export { CommandOptions as CommandOptions_alias_1 }
251
- export { CommandOptions as CommandOptions_alias_2 }
252
-
253
- declare interface CommandWithMetadata {
254
- class: ClassTypeWithInstance<CommandHandler>;
255
- metadata: CommandMetadata;
256
- }
257
- export { CommandWithMetadata }
258
- export { CommandWithMetadata as CommandWithMetadata_alias_1 }
259
- export { CommandWithMetadata as CommandWithMetadata_alias_2 }
260
-
261
- export { Container }
262
-
263
- export { createRequestContextHolder }
264
-
265
- export declare const default_alias: Options | Options[] | ((overrideOptions: Options) => Options | Options[] | Promise<Options | Options[]>);
266
-
267
- export declare const default_alias_1: UserWorkspaceConfig;
268
-
269
- export { defaultInjectors }
270
-
271
- export { DefaultRequestContextHolder }
272
-
273
- export { DIError }
274
-
275
- export { DIErrorCode }
276
-
277
- export { ErrorsEnum }
278
-
279
- export { EventEmitter }
280
-
281
- export { EventEmitterInterface }
282
-
283
- export { EventsArgs }
284
-
285
- export { EventsConfig }
286
-
287
- export { EventsNames }
288
-
289
- declare function extractCliModuleMetadata(target: ClassType): CliModuleMetadata;
290
- export { extractCliModuleMetadata }
291
- export { extractCliModuleMetadata as extractCliModuleMetadata_alias_1 }
292
- export { extractCliModuleMetadata as extractCliModuleMetadata_alias_2 }
293
-
294
- declare function extractCommandMetadata(target: ClassType): CommandMetadata;
295
- export { extractCommandMetadata }
296
- export { extractCommandMetadata as extractCommandMetadata_alias_1 }
297
- export { extractCommandMetadata as extractCommandMetadata_alias_2 }
298
-
299
- export { Factorable }
300
-
301
- export { FactorableWithArgs }
302
-
303
- export { Factory }
304
-
305
- export { FactoryContext }
306
-
307
- export { FactoryInjectionToken }
308
-
309
- export { FactoryNotFound }
310
-
311
- export { FactoryOptions }
312
-
313
- export { FactoryRecord }
314
-
315
- export { FactoryTokenNotResolved }
316
-
317
- declare function getCliModuleMetadata(target: ClassType, context: ClassDecoratorContext): CliModuleMetadata;
318
- export { getCliModuleMetadata }
319
- export { getCliModuleMetadata as getCliModuleMetadata_alias_1 }
320
- export { getCliModuleMetadata as getCliModuleMetadata_alias_2 }
321
-
322
- declare function getCommandMetadata(target: ClassType, context: ClassDecoratorContext, path: string, optionsSchema?: ZodObject): CommandMetadata;
323
- export { getCommandMetadata }
324
- export { getCommandMetadata as getCommandMetadata_alias_1 }
325
- export { getCommandMetadata as getCommandMetadata_alias_2 }
326
-
327
- export { getInjectableToken }
328
-
329
- export { getInjectors }
330
-
331
- export { globalRegistry }
332
-
333
- declare function hasCliModuleMetadata(target: ClassType): boolean;
334
- export { hasCliModuleMetadata }
335
- export { hasCliModuleMetadata as hasCliModuleMetadata_alias_1 }
336
- export { hasCliModuleMetadata as hasCliModuleMetadata_alias_2 }
337
-
338
- declare function hasCommandMetadata(target: ClassType): boolean;
339
- export { hasCommandMetadata }
340
- export { hasCommandMetadata as hasCommandMetadata_alias_1 }
341
- export { hasCommandMetadata as hasCommandMetadata_alias_2 }
342
-
343
- export { inject }
344
-
345
- export { Injectable }
346
-
347
- export { InjectableOptions }
348
-
349
- export { InjectableScope }
350
-
351
- export { InjectableTokenMeta }
352
-
353
- export { InjectableType }
354
-
355
- export { InjectionToken }
356
-
357
- export { InjectionTokenSchemaType }
358
-
359
- export { InjectionTokenType }
360
-
361
- export { Injectors }
362
-
363
- export { InjectState }
364
-
365
- export { InstanceDestroying }
366
-
367
- export { InstanceNotFound }
368
-
369
- export { IsUnion }
370
-
371
- export { Join }
372
-
373
- declare interface Module {
374
- onModuleInit?(): void | Promise<void>;
375
- onModuleDestroy?(): void | Promise<void>;
376
- }
377
- export { Module }
378
- export { Module as Module_alias_1 }
379
- export { Module as Module_alias_2 }
380
-
381
- declare class ModuleLoaderService {
382
- protected container: Container;
383
- private modulesMetadata;
384
- private loadedModules;
385
- private commandsMetadata;
386
- private initialized;
387
- loadModules(appModule: ClassTypeWithInstance<Module>): Promise<void>;
388
- private traverseModules;
389
- private mergeMetadata;
390
- getAllModules(): Map<string, CliModuleMetadata>;
391
- getAllCommands(): Map<string, ClassTypeWithInstance<any>>;
392
- /**
393
- * Get all commands with their metadata, indexed by command path.
394
- * This is populated during loadModules, so path information is available
395
- * before parsing CLI argv.
396
- */
397
- getAllCommandsWithMetadata(): Map<string, CommandWithMetadata>;
398
- /**
399
- * Get a command by its path, with metadata already extracted.
400
- * Returns undefined if command is not found.
401
- */
402
- getCommandByPath(path: string): CommandWithMetadata | undefined;
403
- dispose(): void;
404
- }
405
- export { ModuleLoaderService }
406
- export { ModuleLoaderService as ModuleLoaderService_alias_1 }
407
- export { ModuleLoaderService as ModuleLoaderService_alias_2 }
408
-
409
- export { OnServiceDestroy }
410
-
411
- export { OnServiceInit }
412
-
413
- export { OptionalInjectionTokenSchemaType }
414
-
415
- declare interface ParsedCliArgs {
416
- command: string;
417
- options: Record<string, any>;
418
- positionals: string[];
419
- }
420
- export { ParsedCliArgs }
421
- export { ParsedCliArgs as ParsedCliArgs_alias_1 }
422
- export { ParsedCliArgs as ParsedCliArgs_alias_2 }
423
-
424
- export { PopUnion }
425
-
426
- export { provideFactoryContext }
427
-
428
- export { Registry }
429
-
430
- export { RequestContextHolder }
431
-
432
- export { ServiceInstantiator }
433
-
434
- export { ServiceLocator }
435
-
436
- export { ServiceLocatorEventBus }
437
-
438
- export { ServiceLocatorInstanceDestroyListener }
439
-
440
- export { ServiceLocatorInstanceEffect }
441
-
442
- export { ServiceLocatorInstanceHolder }
443
-
444
- export { ServiceLocatorInstanceHolderCreated }
445
-
446
- export { ServiceLocatorInstanceHolderCreating }
447
-
448
- export { ServiceLocatorInstanceHolderDestroying }
449
-
450
- export { ServiceLocatorInstanceHolderError }
451
-
452
- export { ServiceLocatorInstanceHolderStatus }
453
-
454
- export { ServiceLocatorManager }
455
-
456
- export { UnionToArray }
457
-
458
- export { UnionToIntersection }
459
-
460
- export { UnionToOvlds }
461
-
462
- export { UnknownError }
463
-
464
- export { wrapSyncInit }
465
-
466
- export { }