@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
package/lib/index.js DELETED
@@ -1,604 +0,0 @@
1
- 'use strict';
2
-
3
- var di = require('@navios/di');
4
-
5
- var __create = Object.create;
6
- var __defProp = Object.defineProperty;
7
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
8
- var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
9
- var __typeError = (msg) => {
10
- throw TypeError(msg);
11
- };
12
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
14
- var __decoratorStart = (base) => [, , , __create(null)];
15
- var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
16
- var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
17
- var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
18
- var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
19
- var __runInitializers = (array, flags, self, value) => {
20
- for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) fns[i].call(self) ;
21
- return value;
22
- };
23
- var __decorateElement = (array, flags, name, decorators, target, extra) => {
24
- var it, done, ctx, k = flags & 7, p = false;
25
- var j = 0;
26
- var extraInitializers = array[j] || (array[j] = []);
27
- var desc = k && ((target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(target , name));
28
- __name(target, name);
29
- for (var i = decorators.length - 1; i >= 0; i--) {
30
- ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
31
- it = (0, decorators[i])(target, ctx), done._ = 1;
32
- __expectFn(it) && (target = it);
33
- }
34
- return __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
35
- };
36
-
37
- // src/metadata/command.metadata.mts
38
- var CommandMetadataKey = Symbol("CommandMetadataKey");
39
- function getCommandMetadata(target, context, path, optionsSchema) {
40
- if (context.metadata) {
41
- const metadata = context.metadata[CommandMetadataKey];
42
- if (metadata) {
43
- return metadata;
44
- } else {
45
- const newMetadata = {
46
- path,
47
- optionsSchema,
48
- customAttributes: /* @__PURE__ */ new Map()
49
- };
50
- context.metadata[CommandMetadataKey] = newMetadata;
51
- target[CommandMetadataKey] = newMetadata;
52
- return newMetadata;
53
- }
54
- }
55
- throw new Error("[Navios Commander] Wrong environment.");
56
- }
57
- function extractCommandMetadata(target) {
58
- const metadata = target[CommandMetadataKey];
59
- if (!metadata) {
60
- throw new Error(
61
- "[Navios Commander] Command metadata not found. Make sure to use @Command decorator."
62
- );
63
- }
64
- return metadata;
65
- }
66
- function hasCommandMetadata(target) {
67
- const metadata = target[CommandMetadataKey];
68
- return !!metadata;
69
- }
70
-
71
- // src/metadata/cli-module.metadata.mts
72
- var CliModuleMetadataKey = Symbol("CliModuleMetadataKey");
73
- function getCliModuleMetadata(target, context) {
74
- if (context.metadata) {
75
- const metadata = context.metadata[CliModuleMetadataKey];
76
- if (metadata) {
77
- return metadata;
78
- } else {
79
- const newMetadata = {
80
- commands: /* @__PURE__ */ new Set(),
81
- imports: /* @__PURE__ */ new Set(),
82
- customAttributes: /* @__PURE__ */ new Map()
83
- };
84
- context.metadata[CliModuleMetadataKey] = newMetadata;
85
- target[CliModuleMetadataKey] = newMetadata;
86
- return newMetadata;
87
- }
88
- }
89
- throw new Error("[Navios Commander] Wrong environment.");
90
- }
91
- function extractCliModuleMetadata(target) {
92
- const metadata = target[CliModuleMetadataKey];
93
- if (!metadata) {
94
- throw new Error(
95
- `[Navios Commander] Module metadata not found for ${target.name}. Make sure to use @CliModule decorator.`
96
- );
97
- }
98
- return metadata;
99
- }
100
- function hasCliModuleMetadata(target) {
101
- return !!target[CliModuleMetadataKey];
102
- }
103
-
104
- // src/services/module-loader.service.mts
105
- var _ModuleLoaderService_decorators, _init;
106
- _ModuleLoaderService_decorators = [di.Injectable()];
107
- exports.ModuleLoaderService = class ModuleLoaderService {
108
- container = di.inject(di.Container);
109
- modulesMetadata = /* @__PURE__ */ new Map();
110
- loadedModules = /* @__PURE__ */ new Map();
111
- commandsMetadata = /* @__PURE__ */ new Map();
112
- initialized = false;
113
- async loadModules(appModule) {
114
- if (this.initialized) {
115
- return;
116
- }
117
- await this.traverseModules(appModule);
118
- this.initialized = true;
119
- }
120
- async traverseModules(module, parentMetadata) {
121
- const metadata = extractCliModuleMetadata(module);
122
- if (parentMetadata) {
123
- this.mergeMetadata(metadata, parentMetadata);
124
- }
125
- const moduleName = module.name;
126
- if (this.modulesMetadata.has(moduleName)) {
127
- return;
128
- }
129
- this.modulesMetadata.set(moduleName, metadata);
130
- for (const command of metadata.commands) {
131
- const commandMetadata = extractCommandMetadata(command);
132
- this.commandsMetadata.set(commandMetadata.path, {
133
- class: command,
134
- metadata: commandMetadata
135
- });
136
- }
137
- const imports = metadata.imports ?? /* @__PURE__ */ new Set();
138
- const loadingPromises = Array.from(imports).map(
139
- async (importedModule) => this.traverseModules(importedModule, metadata)
140
- );
141
- await Promise.all(loadingPromises);
142
- const instance = await this.container.get(module);
143
- if (instance.onModuleInit) {
144
- await instance.onModuleInit();
145
- }
146
- this.loadedModules.set(moduleName, instance);
147
- }
148
- mergeMetadata(metadata, parentMetadata) {
149
- if (parentMetadata.customAttributes) {
150
- for (const [key, value] of parentMetadata.customAttributes) {
151
- if (metadata.customAttributes.has(key)) {
152
- continue;
153
- }
154
- metadata.customAttributes.set(key, value);
155
- }
156
- }
157
- }
158
- getAllModules() {
159
- return this.modulesMetadata;
160
- }
161
- getAllCommands() {
162
- const commands = /* @__PURE__ */ new Map();
163
- for (const metadata of this.modulesMetadata.values()) {
164
- for (const command of metadata.commands) {
165
- commands.set(command.name, command);
166
- }
167
- }
168
- return commands;
169
- }
170
- /**
171
- * Get all commands with their metadata, indexed by command path.
172
- * This is populated during loadModules, so path information is available
173
- * before parsing CLI argv.
174
- */
175
- getAllCommandsWithMetadata() {
176
- return this.commandsMetadata;
177
- }
178
- /**
179
- * Get a command by its path, with metadata already extracted.
180
- * Returns undefined if command is not found.
181
- */
182
- getCommandByPath(path) {
183
- return this.commandsMetadata.get(path);
184
- }
185
- dispose() {
186
- this.modulesMetadata.clear();
187
- this.loadedModules.clear();
188
- this.commandsMetadata.clear();
189
- this.initialized = false;
190
- }
191
- };
192
- _init = __decoratorStart();
193
- exports.ModuleLoaderService = __decorateElement(_init, 0, "ModuleLoaderService", _ModuleLoaderService_decorators, exports.ModuleLoaderService);
194
- __runInitializers(_init, 1, exports.ModuleLoaderService);
195
- var _CliParserService_decorators, _init2;
196
- _CliParserService_decorators = [di.Injectable()];
197
- exports.CliParserService = class CliParserService {
198
- /**
199
- * Parses command-line arguments from process.argv
200
- * Commands can be multi-word (e.g., 'db migrate', 'cache clear')
201
- * Expected format: node script.js command [subcommand...] --flag value --boolean-flag positional1 positional2
202
- *
203
- * @param argv - Array of command-line arguments (typically process.argv)
204
- * @param optionsSchema - Optional Zod schema to determine boolean flags and option types
205
- * @returns Parsed command (space-separated if multi-word), options, and positional arguments
206
- */
207
- parse(argv, optionsSchema) {
208
- const args = argv.slice(2);
209
- if (args.length === 0) {
210
- throw new Error("[Navios Commander] No command provided");
211
- }
212
- const booleanFields = optionsSchema ? this.extractBooleanFields(optionsSchema) : /* @__PURE__ */ new Set();
213
- const arrayFields = optionsSchema ? this.extractArrayFields(optionsSchema) : /* @__PURE__ */ new Set();
214
- const commandParts = [];
215
- let i = 0;
216
- while (i < args.length && !args[i].startsWith("-")) {
217
- commandParts.push(args[i]);
218
- i++;
219
- }
220
- if (commandParts.length === 0) {
221
- throw new Error("[Navios Commander] No command provided");
222
- }
223
- const command = commandParts.join(" ");
224
- const options = {};
225
- const positionals = [];
226
- while (i < args.length) {
227
- const arg = args[i];
228
- if (arg.startsWith("--")) {
229
- const key = arg.slice(2);
230
- const equalIndex = key.indexOf("=");
231
- if (equalIndex !== -1) {
232
- const optionName = key.slice(0, equalIndex);
233
- const optionValue = key.slice(equalIndex + 1);
234
- const camelCaseKey = this.camelCase(optionName);
235
- const isArray = arrayFields.has(camelCaseKey) || arrayFields.has(optionName);
236
- if (isArray) {
237
- if (!options[camelCaseKey]) {
238
- options[camelCaseKey] = [];
239
- }
240
- options[camelCaseKey].push(this.parseValue(optionValue));
241
- } else {
242
- options[camelCaseKey] = this.parseValue(optionValue);
243
- }
244
- i++;
245
- } else {
246
- const camelCaseKey = this.camelCase(key);
247
- const isBoolean = booleanFields.has(camelCaseKey) || booleanFields.has(key);
248
- const isArray = arrayFields.has(camelCaseKey) || arrayFields.has(key);
249
- const nextArg = args[i + 1];
250
- if (isBoolean) {
251
- options[camelCaseKey] = true;
252
- i++;
253
- } else if (isArray && nextArg && !nextArg.startsWith("-")) {
254
- if (!options[camelCaseKey]) {
255
- options[camelCaseKey] = [];
256
- }
257
- options[camelCaseKey].push(this.parseValue(nextArg));
258
- i += 2;
259
- } else if (nextArg && !nextArg.startsWith("-")) {
260
- options[camelCaseKey] = this.parseValue(nextArg);
261
- i += 2;
262
- } else {
263
- options[camelCaseKey] = true;
264
- i++;
265
- }
266
- }
267
- } else if (arg.startsWith("-") && arg.length > 1 && arg !== "-") {
268
- const flags = arg.slice(1);
269
- if (flags.length === 1) {
270
- const isBoolean = booleanFields.has(flags);
271
- const isArray = arrayFields.has(flags);
272
- const nextArg = args[i + 1];
273
- if (isBoolean) {
274
- options[flags] = true;
275
- i++;
276
- } else if (isArray && nextArg && !nextArg.startsWith("-")) {
277
- if (!options[flags]) {
278
- options[flags] = [];
279
- }
280
- options[flags].push(this.parseValue(nextArg));
281
- i += 2;
282
- } else if (nextArg && !nextArg.startsWith("-")) {
283
- options[flags] = this.parseValue(nextArg);
284
- i += 2;
285
- } else {
286
- options[flags] = true;
287
- i++;
288
- }
289
- } else {
290
- for (const flag of flags) {
291
- options[flag] = true;
292
- }
293
- i++;
294
- }
295
- } else {
296
- positionals.push(arg);
297
- i++;
298
- }
299
- }
300
- return {
301
- command,
302
- options,
303
- positionals
304
- };
305
- }
306
- /**
307
- * Converts kebab-case to camelCase
308
- */
309
- camelCase(str) {
310
- return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
311
- }
312
- /**
313
- * Attempts to parse string values into appropriate types
314
- */
315
- parseValue(value) {
316
- if (value === "true") return true;
317
- if (value === "false") return false;
318
- if (value === "null") return null;
319
- if (value === "undefined") return void 0;
320
- if (/^-?\d+$/.test(value)) {
321
- return parseInt(value, 10);
322
- }
323
- if (/^-?\d+\.\d+$/.test(value)) {
324
- return parseFloat(value);
325
- }
326
- if (value.startsWith("{") && value.endsWith("}") || value.startsWith("[") && value.endsWith("]")) {
327
- try {
328
- return JSON.parse(value);
329
- } catch {
330
- return value;
331
- }
332
- }
333
- return value;
334
- }
335
- /**
336
- * Extracts boolean field names from a Zod schema
337
- * Handles ZodObject, ZodOptional, and ZodDefault wrappers
338
- */
339
- extractBooleanFields(schema) {
340
- const booleanFields = /* @__PURE__ */ new Set();
341
- try {
342
- const typeName = schema.def.type;
343
- if (typeName === "object") {
344
- const shape = schema.def.shape;
345
- if (shape && typeof shape === "object") {
346
- for (const [key, fieldSchema] of Object.entries(shape)) {
347
- if (this.isSchemaBoolean(fieldSchema)) {
348
- booleanFields.add(key);
349
- }
350
- }
351
- }
352
- }
353
- } catch {
354
- }
355
- return booleanFields;
356
- }
357
- /**
358
- * Extracts array field names from a Zod schema
359
- * Handles ZodObject, ZodOptional, and ZodDefault wrappers
360
- */
361
- extractArrayFields(schema) {
362
- const arrayFields = /* @__PURE__ */ new Set();
363
- try {
364
- const typeName = schema.def.type;
365
- if (typeName === "object") {
366
- const shape = schema.def.shape;
367
- if (shape && typeof shape === "object") {
368
- for (const [key, fieldSchema] of Object.entries(shape)) {
369
- if (this.isSchemaArray(fieldSchema)) {
370
- arrayFields.add(key);
371
- }
372
- }
373
- }
374
- }
375
- } catch {
376
- }
377
- return arrayFields;
378
- }
379
- /**
380
- * Checks if a Zod schema represents a boolean type
381
- * Unwraps ZodOptional and ZodDefault
382
- */
383
- isSchemaBoolean(schema) {
384
- try {
385
- let currentSchema = schema;
386
- const typeName = currentSchema.def.type;
387
- if (typeName === "optional" || typeName === "default") {
388
- currentSchema = currentSchema?._def?.innerType || currentSchema;
389
- }
390
- const innerTypeName = currentSchema.def.type;
391
- return innerTypeName === "boolean";
392
- } catch {
393
- return false;
394
- }
395
- }
396
- /**
397
- * Checks if a Zod schema represents an array type
398
- * Unwraps ZodOptional and ZodDefault
399
- */
400
- isSchemaArray(schema) {
401
- try {
402
- let currentSchema = schema;
403
- const typeName = currentSchema.def.type;
404
- if (typeName === "optional" || typeName === "default") {
405
- currentSchema = currentSchema?._def?.innerType || currentSchema;
406
- }
407
- const innerTypeName = currentSchema.def.type;
408
- return innerTypeName === "array";
409
- } catch {
410
- return false;
411
- }
412
- }
413
- /**
414
- * Formats help text for available commands
415
- */
416
- formatCommandList(commands) {
417
- const lines = ["Available commands:", ""];
418
- for (const { path } of commands) {
419
- lines.push(` ${path}`);
420
- }
421
- return lines.join("\n");
422
- }
423
- };
424
- _init2 = __decoratorStart();
425
- exports.CliParserService = __decorateElement(_init2, 0, "CliParserService", _CliParserService_decorators, exports.CliParserService);
426
- __runInitializers(_init2, 1, exports.CliParserService);
427
-
428
- // src/commander.application.mts
429
- var _CommanderApplication_decorators, _init3;
430
- _CommanderApplication_decorators = [di.Injectable()];
431
- exports.CommanderApplication = class CommanderApplication {
432
- moduleLoader = di.inject(exports.ModuleLoaderService);
433
- cliParser = di.inject(exports.CliParserService);
434
- container = di.inject(di.Container);
435
- appModule = null;
436
- options = {};
437
- isInitialized = false;
438
- async setup(appModule, options = {}) {
439
- this.appModule = appModule;
440
- this.options = options;
441
- }
442
- getContainer() {
443
- return this.container;
444
- }
445
- async init() {
446
- if (!this.appModule) {
447
- throw new Error(
448
- "[Navios Commander] App module is not set. Call setup() first."
449
- );
450
- }
451
- await this.moduleLoader.loadModules(this.appModule);
452
- this.isInitialized = true;
453
- }
454
- async executeCommand(commandPath, options = {}) {
455
- if (!this.isInitialized) {
456
- throw new Error(
457
- "[Navios Commander] Application is not initialized. Call init() first."
458
- );
459
- }
460
- const commandWithMetadata = this.moduleLoader.getCommandByPath(commandPath);
461
- if (!commandWithMetadata) {
462
- throw new Error(`[Navios Commander] Command not found: ${commandPath}`);
463
- }
464
- const { class: commandClass, metadata } = commandWithMetadata;
465
- let validatedOptions = options;
466
- if (metadata.optionsSchema) {
467
- validatedOptions = metadata.optionsSchema.parse(options);
468
- }
469
- const commandInstance = await this.container.get(
470
- commandClass
471
- );
472
- if (!commandInstance.execute) {
473
- throw new Error(
474
- `[Navios Commander] Command ${commandPath} does not implement execute method`
475
- );
476
- }
477
- await commandInstance.execute(validatedOptions);
478
- }
479
- getAllCommands() {
480
- const commandsMap = this.moduleLoader.getAllCommandsWithMetadata();
481
- const commandsWithMetadata = [];
482
- for (const [, { class: cmd, metadata }] of commandsMap) {
483
- commandsWithMetadata.push({
484
- path: metadata.path,
485
- class: cmd
486
- });
487
- }
488
- return commandsWithMetadata;
489
- }
490
- /**
491
- * Runs the CLI application by parsing process.argv and executing the command
492
- * @param argv - Command-line arguments (defaults to process.argv)
493
- */
494
- async run(argv = process.argv) {
495
- if (!this.isInitialized) {
496
- throw new Error(
497
- "[Navios Commander] Application is not initialized. Call init() first."
498
- );
499
- }
500
- try {
501
- const preliminaryParse = this.cliParser.parse(argv);
502
- const commandWithMetadata = this.moduleLoader.getCommandByPath(
503
- preliminaryParse.command
504
- );
505
- const parsed = commandWithMetadata?.metadata.optionsSchema ? this.cliParser.parse(argv, commandWithMetadata.metadata.optionsSchema) : preliminaryParse;
506
- if (parsed.command === "help" || parsed.options.help || parsed.options.h) {
507
- const commands = this.getAllCommands();
508
- console.log(this.cliParser.formatCommandList(commands));
509
- return;
510
- }
511
- await this.executeCommand(parsed.command, parsed.options);
512
- } catch (error) {
513
- if (error instanceof Error) {
514
- console.error(`Error: ${error.message}`);
515
- if (error.message.includes("Command not found")) {
516
- console.log(
517
- "\n" + this.cliParser.formatCommandList(this.getAllCommands())
518
- );
519
- }
520
- }
521
- throw error;
522
- }
523
- }
524
- async dispose() {
525
- if (this.moduleLoader) {
526
- this.moduleLoader.dispose();
527
- }
528
- }
529
- async close() {
530
- await this.dispose();
531
- }
532
- };
533
- _init3 = __decoratorStart();
534
- exports.CommanderApplication = __decorateElement(_init3, 0, "CommanderApplication", _CommanderApplication_decorators, exports.CommanderApplication);
535
- __runInitializers(_init3, 1, exports.CommanderApplication);
536
- var CommanderFactory = class {
537
- static async create(appModule, options = {}) {
538
- const container = new di.Container();
539
- const app = await container.get(exports.CommanderApplication);
540
- await app.setup(appModule, options);
541
- return app;
542
- }
543
- };
544
- function Command({ path, optionsSchema }) {
545
- return function(target, context) {
546
- if (context.kind !== "class") {
547
- throw new Error(
548
- "[Navios Commander] @Command decorator can only be used on classes."
549
- );
550
- }
551
- const token = di.InjectionToken.create(target);
552
- if (context.metadata) {
553
- getCommandMetadata(target, context, path, optionsSchema);
554
- }
555
- return di.Injectable({
556
- token,
557
- scope: di.InjectableScope.Singleton
558
- })(target, context);
559
- };
560
- }
561
- function CliModule({ commands = [], imports = [] } = {
562
- commands: [],
563
- imports: []
564
- }) {
565
- return (target, context) => {
566
- if (context.kind !== "class") {
567
- throw new Error(
568
- "[Navios Commander] @CliModule decorator can only be used on classes."
569
- );
570
- }
571
- const token = di.InjectionToken.create(target);
572
- const moduleMetadata = getCliModuleMetadata(target, context);
573
- for (const command of commands) {
574
- moduleMetadata.commands.add(command);
575
- }
576
- for (const importedModule of imports) {
577
- moduleMetadata.imports.add(importedModule);
578
- }
579
- return di.Injectable({
580
- token,
581
- scope: di.InjectableScope.Singleton
582
- })(target, context);
583
- };
584
- }
585
-
586
- exports.CliModule = CliModule;
587
- exports.CliModuleMetadataKey = CliModuleMetadataKey;
588
- exports.Command = Command;
589
- exports.CommandMetadataKey = CommandMetadataKey;
590
- exports.CommanderFactory = CommanderFactory;
591
- exports.extractCliModuleMetadata = extractCliModuleMetadata;
592
- exports.extractCommandMetadata = extractCommandMetadata;
593
- exports.getCliModuleMetadata = getCliModuleMetadata;
594
- exports.getCommandMetadata = getCommandMetadata;
595
- exports.hasCliModuleMetadata = hasCliModuleMetadata;
596
- exports.hasCommandMetadata = hasCommandMetadata;
597
- Object.keys(di).forEach(function (k) {
598
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
599
- enumerable: true,
600
- get: function () { return di[k]; }
601
- });
602
- });
603
- //# sourceMappingURL=index.js.map
604
- //# sourceMappingURL=index.js.map