@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.
- package/CHANGELOG.md +35 -0
- package/README.md +22 -0
- package/dist/src/commander.factory.d.mts +59 -0
- package/dist/src/commander.factory.d.mts.map +1 -1
- package/dist/src/commands/help.command.d.mts.map +1 -1
- package/dist/src/decorators/command.decorator.d.mts +9 -2
- package/dist/src/decorators/command.decorator.d.mts.map +1 -1
- package/dist/src/legacy-compat/decorators/cli-module.decorator.d.mts +26 -0
- package/dist/src/legacy-compat/decorators/cli-module.decorator.d.mts.map +1 -0
- package/dist/src/legacy-compat/decorators/command.decorator.d.mts +34 -0
- package/dist/src/legacy-compat/decorators/command.decorator.d.mts.map +1 -0
- package/dist/src/legacy-compat/decorators/index.d.mts +3 -0
- package/dist/src/legacy-compat/decorators/index.d.mts.map +1 -0
- package/dist/src/legacy-compat/index.d.mts +28 -0
- package/dist/src/legacy-compat/index.d.mts.map +1 -0
- package/dist/src/overrides/help.command.d.mts +18 -0
- package/dist/src/overrides/help.command.d.mts.map +1 -0
- package/dist/src/tokens/help-command.token.d.mts +4 -0
- package/dist/src/tokens/help-command.token.d.mts.map +1 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/lib/cli-module.decorator-CkP22084.cjs +71 -0
- package/lib/cli-module.decorator-CkP22084.cjs.map +1 -0
- package/lib/cli-module.decorator-DGuGfpex.d.mts +411 -0
- package/lib/cli-module.decorator-DGuGfpex.d.mts.map +1 -0
- package/lib/cli-module.decorator-DVl8009Q.d.cts +213 -0
- package/lib/cli-module.decorator-DVl8009Q.d.cts.map +1 -0
- package/lib/cli-module.decorator-UGbtkRYc.mjs +66 -0
- package/lib/cli-module.decorator-UGbtkRYc.mjs.map +1 -0
- package/lib/command.decorator-DVLSAqYZ.mjs +135 -0
- package/lib/command.decorator-DVLSAqYZ.mjs.map +1 -0
- package/lib/command.decorator-UrNJmQN0.cjs +176 -0
- package/lib/command.decorator-UrNJmQN0.cjs.map +1 -0
- package/lib/help-command.token-C0Kgj60o.mjs +427 -0
- package/lib/help-command.token-C0Kgj60o.mjs.map +1 -0
- package/lib/help-command.token-CMWYI6em.cjs +438 -0
- package/lib/help-command.token-CMWYI6em.cjs.map +1 -0
- package/lib/help.command-DQyv6ali.cjs +317 -0
- package/lib/help.command-DQyv6ali.cjs.map +1 -0
- package/lib/help.command-dtZbhq0w.mjs +318 -0
- package/lib/help.command-dtZbhq0w.mjs.map +1 -0
- package/lib/index.cjs +45 -627
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +139 -281
- package/lib/index.d.cts.map +1 -1
- package/lib/index.d.mts +62 -402
- package/lib/index.d.mts.map +1 -1
- package/lib/index.mjs +30 -612
- package/lib/index.mjs.map +1 -1
- package/lib/legacy-compat/index.cjs +108 -0
- package/lib/legacy-compat/index.cjs.map +1 -0
- package/lib/legacy-compat/index.d.cts +63 -0
- package/lib/legacy-compat/index.d.cts.map +1 -0
- package/lib/legacy-compat/index.d.mts +63 -0
- package/lib/legacy-compat/index.d.mts.map +1 -0
- package/lib/legacy-compat/index.mjs +101 -0
- package/lib/legacy-compat/index.mjs.map +1 -0
- package/package.json +20 -3
- package/src/commander.factory.mts +107 -8
- package/src/commands/help.command.mts +4 -3
- package/src/decorators/command.decorator.mts +17 -8
- package/src/legacy-compat/decorators/cli-module.decorator.mts +46 -0
- package/src/legacy-compat/decorators/command.decorator.mts +46 -0
- package/src/legacy-compat/decorators/index.mts +2 -0
- package/src/legacy-compat/index.mts +31 -0
- package/src/overrides/help.command.mts +40 -0
- package/src/tokens/help-command.token.mts +5 -0
- package/tsconfig.json +0 -3
- package/tsconfig.spec.json +1 -1
- package/tsdown.config.mts +1 -1
- package/dist/src/commander.application.d.mts +0 -147
- package/dist/src/commander.application.d.mts.map +0 -1
- package/dist/src/metadata/cli-module.metadata.d.mts +0 -60
- package/dist/src/metadata/cli-module.metadata.d.mts.map +0 -1
- package/dist/src/services/module-loader.service.d.mts +0 -74
- package/dist/src/services/module-loader.service.d.mts.map +0 -1
package/lib/index.cjs
CHANGED
|
@@ -1,556 +1,9 @@
|
|
|
1
|
+
const require_command_decorator = require('./command.decorator-UrNJmQN0.cjs');
|
|
2
|
+
const require_help_command_token = require('./help-command.token-CMWYI6em.cjs');
|
|
3
|
+
const require_cli_module_decorator = require('./cli-module.decorator-CkP22084.cjs');
|
|
1
4
|
let _navios_core = require("@navios/core");
|
|
2
5
|
let zod = require("zod");
|
|
3
6
|
|
|
4
|
-
//#region src/metadata/command.metadata.mts
|
|
5
|
-
/**
|
|
6
|
-
* @internal
|
|
7
|
-
* Symbol key used to store command metadata on classes.
|
|
8
|
-
*/ const CommandMetadataKey = Symbol("CommandMetadataKey");
|
|
9
|
-
/**
|
|
10
|
-
* Gets or creates command metadata for a class.
|
|
11
|
-
*
|
|
12
|
-
* @internal
|
|
13
|
-
* @param target - The command class
|
|
14
|
-
* @param context - The decorator context
|
|
15
|
-
* @param path - The command path
|
|
16
|
-
* @param description - Optional description for help text
|
|
17
|
-
* @param optionsSchema - Optional Zod schema
|
|
18
|
-
* @returns The command metadata
|
|
19
|
-
*/ function getCommandMetadata(target, context, path, description, optionsSchema) {
|
|
20
|
-
if (context.metadata) {
|
|
21
|
-
const metadata = context.metadata[CommandMetadataKey];
|
|
22
|
-
if (metadata) return metadata;
|
|
23
|
-
else {
|
|
24
|
-
const newMetadata = {
|
|
25
|
-
path,
|
|
26
|
-
description,
|
|
27
|
-
optionsSchema,
|
|
28
|
-
customAttributes: /* @__PURE__ */ new Map()
|
|
29
|
-
};
|
|
30
|
-
context.metadata[CommandMetadataKey] = newMetadata;
|
|
31
|
-
target[CommandMetadataKey] = newMetadata;
|
|
32
|
-
return newMetadata;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
throw new Error("[Navios Commander] Wrong environment.");
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Extracts command metadata from a class.
|
|
39
|
-
*
|
|
40
|
-
* @param target - The command class
|
|
41
|
-
* @returns The command metadata
|
|
42
|
-
* @throws {Error} If the class is not decorated with @Command
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* ```typescript
|
|
46
|
-
* const metadata = extractCommandMetadata(GreetCommand)
|
|
47
|
-
* console.log(metadata.path) // 'greet'
|
|
48
|
-
* ```
|
|
49
|
-
*/ function extractCommandMetadata(target) {
|
|
50
|
-
const metadata = target[CommandMetadataKey];
|
|
51
|
-
if (!metadata) throw new Error("[Navios Commander] Command metadata not found. Make sure to use @Command decorator.");
|
|
52
|
-
return metadata;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Checks if a class has command metadata.
|
|
56
|
-
*
|
|
57
|
-
* @param target - The class to check
|
|
58
|
-
* @returns `true` if the class is decorated with @Command, `false` otherwise
|
|
59
|
-
*/ function hasCommandMetadata(target) {
|
|
60
|
-
return !!target[CommandMetadataKey];
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
//#endregion
|
|
64
|
-
//#region src/metadata/command-entry.metadata.mts
|
|
65
|
-
/**
|
|
66
|
-
* Symbol key for storing commands in ModuleMetadata.customEntries.
|
|
67
|
-
* Used by @CliModule to store command classes.
|
|
68
|
-
*
|
|
69
|
-
* @public
|
|
70
|
-
*/ const CommandEntryKey = Symbol("CommandEntryKey");
|
|
71
|
-
/**
|
|
72
|
-
* Extracts commands from a module's metadata.
|
|
73
|
-
* Returns empty set if no commands are defined.
|
|
74
|
-
*
|
|
75
|
-
* @param moduleClass - The module class decorated with @CliModule or @Module
|
|
76
|
-
* @returns Set of command classes registered in the module
|
|
77
|
-
*
|
|
78
|
-
* @example
|
|
79
|
-
* ```typescript
|
|
80
|
-
* const commands = extractModuleCommands(AppModule)
|
|
81
|
-
* for (const command of commands) {
|
|
82
|
-
* console.log(command.name)
|
|
83
|
-
* }
|
|
84
|
-
* ```
|
|
85
|
-
*/ function extractModuleCommands(moduleClass) {
|
|
86
|
-
return (0, _navios_core.extractModuleMetadata)(moduleClass).customEntries.get(CommandEntryKey) ?? /* @__PURE__ */ new Set();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
//#endregion
|
|
90
|
-
//#region src/decorators/command.decorator.mts
|
|
91
|
-
/**
|
|
92
|
-
* Decorator that marks a class as a CLI command.
|
|
93
|
-
*
|
|
94
|
-
* The decorated class must implement the `CommandHandler` interface with an `execute` method.
|
|
95
|
-
* The command will be automatically registered when its module is loaded.
|
|
96
|
-
*
|
|
97
|
-
* @param options - Configuration options for the command
|
|
98
|
-
* @returns A class decorator function
|
|
99
|
-
*
|
|
100
|
-
* @example
|
|
101
|
-
* ```typescript
|
|
102
|
-
* import { Command, CommandHandler } from '@navios/commander'
|
|
103
|
-
* import { z } from 'zod'
|
|
104
|
-
*
|
|
105
|
-
* const optionsSchema = z.object({
|
|
106
|
-
* name: z.string(),
|
|
107
|
-
* greeting: z.string().optional().default('Hello')
|
|
108
|
-
* })
|
|
109
|
-
*
|
|
110
|
-
* @Command({
|
|
111
|
-
* path: 'greet',
|
|
112
|
-
* optionsSchema: optionsSchema
|
|
113
|
-
* })
|
|
114
|
-
* export class GreetCommand implements CommandHandler<z.infer<typeof optionsSchema>> {
|
|
115
|
-
* async execute(options) {
|
|
116
|
-
* console.log(`${options.greeting}, ${options.name}!`)
|
|
117
|
-
* }
|
|
118
|
-
* }
|
|
119
|
-
* ```
|
|
120
|
-
*/ function Command({ path, description, optionsSchema, priority, registry }) {
|
|
121
|
-
return function(target, context) {
|
|
122
|
-
if (context.kind !== "class") throw new Error("[Navios Commander] @Command decorator can only be used on classes.");
|
|
123
|
-
const token = _navios_core.InjectionToken.create(target);
|
|
124
|
-
if (context.metadata) getCommandMetadata(target, context, path, description, optionsSchema);
|
|
125
|
-
return (0, _navios_core.Injectable)({
|
|
126
|
-
token,
|
|
127
|
-
scope: _navios_core.InjectableScope.Singleton,
|
|
128
|
-
priority,
|
|
129
|
-
registry
|
|
130
|
-
})(target, context);
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
//#endregion
|
|
135
|
-
//#region src/services/command-registry.service.mts
|
|
136
|
-
function applyDecs2203RFactory$3() {
|
|
137
|
-
function createAddInitializerMethod(initializers, decoratorFinishedRef) {
|
|
138
|
-
return function addInitializer(initializer) {
|
|
139
|
-
assertNotFinished(decoratorFinishedRef, "addInitializer");
|
|
140
|
-
assertCallable(initializer, "An initializer");
|
|
141
|
-
initializers.push(initializer);
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
|
|
145
|
-
var kindStr;
|
|
146
|
-
switch (kind) {
|
|
147
|
-
case 1:
|
|
148
|
-
kindStr = "accessor";
|
|
149
|
-
break;
|
|
150
|
-
case 2:
|
|
151
|
-
kindStr = "method";
|
|
152
|
-
break;
|
|
153
|
-
case 3:
|
|
154
|
-
kindStr = "getter";
|
|
155
|
-
break;
|
|
156
|
-
case 4:
|
|
157
|
-
kindStr = "setter";
|
|
158
|
-
break;
|
|
159
|
-
default: kindStr = "field";
|
|
160
|
-
}
|
|
161
|
-
var ctx = {
|
|
162
|
-
kind: kindStr,
|
|
163
|
-
name: isPrivate ? "#" + name : name,
|
|
164
|
-
static: isStatic,
|
|
165
|
-
private: isPrivate,
|
|
166
|
-
metadata
|
|
167
|
-
};
|
|
168
|
-
var decoratorFinishedRef = { v: false };
|
|
169
|
-
ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
|
|
170
|
-
var get, set;
|
|
171
|
-
if (kind === 0) if (isPrivate) {
|
|
172
|
-
get = desc.get;
|
|
173
|
-
set = desc.set;
|
|
174
|
-
} else {
|
|
175
|
-
get = function() {
|
|
176
|
-
return this[name];
|
|
177
|
-
};
|
|
178
|
-
set = function(v) {
|
|
179
|
-
this[name] = v;
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
else if (kind === 2) get = function() {
|
|
183
|
-
return desc.value;
|
|
184
|
-
};
|
|
185
|
-
else {
|
|
186
|
-
if (kind === 1 || kind === 3) get = function() {
|
|
187
|
-
return desc.get.call(this);
|
|
188
|
-
};
|
|
189
|
-
if (kind === 1 || kind === 4) set = function(v) {
|
|
190
|
-
desc.set.call(this, v);
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
ctx.access = get && set ? {
|
|
194
|
-
get,
|
|
195
|
-
set
|
|
196
|
-
} : get ? { get } : { set };
|
|
197
|
-
try {
|
|
198
|
-
return dec(value, ctx);
|
|
199
|
-
} finally {
|
|
200
|
-
decoratorFinishedRef.v = true;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
function assertNotFinished(decoratorFinishedRef, fnName) {
|
|
204
|
-
if (decoratorFinishedRef.v) throw new Error("attempted to call " + fnName + " after decoration was finished");
|
|
205
|
-
}
|
|
206
|
-
function assertCallable(fn, hint) {
|
|
207
|
-
if (typeof fn !== "function") throw new TypeError(hint + " must be a function");
|
|
208
|
-
}
|
|
209
|
-
function assertValidReturnValue(kind, value) {
|
|
210
|
-
var type = typeof value;
|
|
211
|
-
if (kind === 1) {
|
|
212
|
-
if (type !== "object" || value === null) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
|
|
213
|
-
if (value.get !== void 0) assertCallable(value.get, "accessor.get");
|
|
214
|
-
if (value.set !== void 0) assertCallable(value.set, "accessor.set");
|
|
215
|
-
if (value.init !== void 0) assertCallable(value.init, "accessor.init");
|
|
216
|
-
} else if (type !== "function") {
|
|
217
|
-
var hint;
|
|
218
|
-
if (kind === 0) hint = "field";
|
|
219
|
-
else if (kind === 10) hint = "class";
|
|
220
|
-
else hint = "method";
|
|
221
|
-
throw new TypeError(hint + " decorators must return a function or void 0");
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
|
|
225
|
-
var decs = decInfo[0];
|
|
226
|
-
var desc, init, value;
|
|
227
|
-
if (isPrivate) if (kind === 0 || kind === 1) desc = {
|
|
228
|
-
get: decInfo[3],
|
|
229
|
-
set: decInfo[4]
|
|
230
|
-
};
|
|
231
|
-
else if (kind === 3) desc = { get: decInfo[3] };
|
|
232
|
-
else if (kind === 4) desc = { set: decInfo[3] };
|
|
233
|
-
else desc = { value: decInfo[3] };
|
|
234
|
-
else if (kind !== 0) desc = Object.getOwnPropertyDescriptor(base, name);
|
|
235
|
-
if (kind === 1) value = {
|
|
236
|
-
get: desc.get,
|
|
237
|
-
set: desc.set
|
|
238
|
-
};
|
|
239
|
-
else if (kind === 2) value = desc.value;
|
|
240
|
-
else if (kind === 3) value = desc.get;
|
|
241
|
-
else if (kind === 4) value = desc.set;
|
|
242
|
-
var newValue, get, set;
|
|
243
|
-
if (typeof decs === "function") {
|
|
244
|
-
newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
|
|
245
|
-
if (newValue !== void 0) {
|
|
246
|
-
assertValidReturnValue(kind, newValue);
|
|
247
|
-
if (kind === 0) init = newValue;
|
|
248
|
-
else if (kind === 1) {
|
|
249
|
-
init = newValue.init;
|
|
250
|
-
get = newValue.get || value.get;
|
|
251
|
-
set = newValue.set || value.set;
|
|
252
|
-
value = {
|
|
253
|
-
get,
|
|
254
|
-
set
|
|
255
|
-
};
|
|
256
|
-
} else value = newValue;
|
|
257
|
-
}
|
|
258
|
-
} else for (var i = decs.length - 1; i >= 0; i--) {
|
|
259
|
-
var dec = decs[i];
|
|
260
|
-
newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
|
|
261
|
-
if (newValue !== void 0) {
|
|
262
|
-
assertValidReturnValue(kind, newValue);
|
|
263
|
-
var newInit;
|
|
264
|
-
if (kind === 0) newInit = newValue;
|
|
265
|
-
else if (kind === 1) {
|
|
266
|
-
newInit = newValue.init;
|
|
267
|
-
get = newValue.get || value.get;
|
|
268
|
-
set = newValue.set || value.set;
|
|
269
|
-
value = {
|
|
270
|
-
get,
|
|
271
|
-
set
|
|
272
|
-
};
|
|
273
|
-
} else value = newValue;
|
|
274
|
-
if (newInit !== void 0) if (init === void 0) init = newInit;
|
|
275
|
-
else if (typeof init === "function") init = [init, newInit];
|
|
276
|
-
else init.push(newInit);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
if (kind === 0 || kind === 1) {
|
|
280
|
-
if (init === void 0) init = function(instance, init$1) {
|
|
281
|
-
return init$1;
|
|
282
|
-
};
|
|
283
|
-
else if (typeof init !== "function") {
|
|
284
|
-
var ownInitializers = init;
|
|
285
|
-
init = function(instance, init$1) {
|
|
286
|
-
var value$1 = init$1;
|
|
287
|
-
for (var i$1 = 0; i$1 < ownInitializers.length; i$1++) value$1 = ownInitializers[i$1].call(instance, value$1);
|
|
288
|
-
return value$1;
|
|
289
|
-
};
|
|
290
|
-
} else {
|
|
291
|
-
var originalInitializer = init;
|
|
292
|
-
init = function(instance, init$1) {
|
|
293
|
-
return originalInitializer.call(instance, init$1);
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
ret.push(init);
|
|
297
|
-
}
|
|
298
|
-
if (kind !== 0) {
|
|
299
|
-
if (kind === 1) {
|
|
300
|
-
desc.get = value.get;
|
|
301
|
-
desc.set = value.set;
|
|
302
|
-
} else if (kind === 2) desc.value = value;
|
|
303
|
-
else if (kind === 3) desc.get = value;
|
|
304
|
-
else if (kind === 4) desc.set = value;
|
|
305
|
-
if (isPrivate) if (kind === 1) {
|
|
306
|
-
ret.push(function(instance, args) {
|
|
307
|
-
return value.get.call(instance, args);
|
|
308
|
-
});
|
|
309
|
-
ret.push(function(instance, args) {
|
|
310
|
-
return value.set.call(instance, args);
|
|
311
|
-
});
|
|
312
|
-
} else if (kind === 2) ret.push(value);
|
|
313
|
-
else ret.push(function(instance, args) {
|
|
314
|
-
return value.call(instance, args);
|
|
315
|
-
});
|
|
316
|
-
else Object.defineProperty(base, name, desc);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
function applyMemberDecs(Class, decInfos, metadata) {
|
|
320
|
-
var ret = [];
|
|
321
|
-
var protoInitializers;
|
|
322
|
-
var staticInitializers;
|
|
323
|
-
var existingProtoNonFields = /* @__PURE__ */ new Map();
|
|
324
|
-
var existingStaticNonFields = /* @__PURE__ */ new Map();
|
|
325
|
-
for (var i = 0; i < decInfos.length; i++) {
|
|
326
|
-
var decInfo = decInfos[i];
|
|
327
|
-
if (!Array.isArray(decInfo)) continue;
|
|
328
|
-
var kind = decInfo[1];
|
|
329
|
-
var name = decInfo[2];
|
|
330
|
-
var isPrivate = decInfo.length > 3;
|
|
331
|
-
var isStatic = kind >= 5;
|
|
332
|
-
var base;
|
|
333
|
-
var initializers;
|
|
334
|
-
if (isStatic) {
|
|
335
|
-
base = Class;
|
|
336
|
-
kind = kind - 5;
|
|
337
|
-
staticInitializers = staticInitializers || [];
|
|
338
|
-
initializers = staticInitializers;
|
|
339
|
-
} else {
|
|
340
|
-
base = Class.prototype;
|
|
341
|
-
protoInitializers = protoInitializers || [];
|
|
342
|
-
initializers = protoInitializers;
|
|
343
|
-
}
|
|
344
|
-
if (kind !== 0 && !isPrivate) {
|
|
345
|
-
var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
|
|
346
|
-
var existingKind = existingNonFields.get(name) || 0;
|
|
347
|
-
if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
|
|
348
|
-
else if (!existingKind && kind > 2) existingNonFields.set(name, kind);
|
|
349
|
-
else existingNonFields.set(name, true);
|
|
350
|
-
}
|
|
351
|
-
applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
|
|
352
|
-
}
|
|
353
|
-
pushInitializers(ret, protoInitializers);
|
|
354
|
-
pushInitializers(ret, staticInitializers);
|
|
355
|
-
return ret;
|
|
356
|
-
}
|
|
357
|
-
function pushInitializers(ret, initializers) {
|
|
358
|
-
if (initializers) ret.push(function(instance) {
|
|
359
|
-
for (var i = 0; i < initializers.length; i++) initializers[i].call(instance);
|
|
360
|
-
return instance;
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
function applyClassDecs(targetClass, classDecs, metadata) {
|
|
364
|
-
if (classDecs.length > 0) {
|
|
365
|
-
var initializers = [];
|
|
366
|
-
var newClass = targetClass;
|
|
367
|
-
var name = targetClass.name;
|
|
368
|
-
for (var i = classDecs.length - 1; i >= 0; i--) {
|
|
369
|
-
var decoratorFinishedRef = { v: false };
|
|
370
|
-
try {
|
|
371
|
-
var nextNewClass = classDecs[i](newClass, {
|
|
372
|
-
kind: "class",
|
|
373
|
-
name,
|
|
374
|
-
addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
|
|
375
|
-
metadata
|
|
376
|
-
});
|
|
377
|
-
} finally {
|
|
378
|
-
decoratorFinishedRef.v = true;
|
|
379
|
-
}
|
|
380
|
-
if (nextNewClass !== void 0) {
|
|
381
|
-
assertValidReturnValue(10, nextNewClass);
|
|
382
|
-
newClass = nextNewClass;
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
return [defineMetadata(newClass, metadata), function() {
|
|
386
|
-
for (var i$1 = 0; i$1 < initializers.length; i$1++) initializers[i$1].call(newClass);
|
|
387
|
-
}];
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
function defineMetadata(Class, metadata) {
|
|
391
|
-
return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
|
|
392
|
-
configurable: true,
|
|
393
|
-
enumerable: true,
|
|
394
|
-
value: metadata
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
|
-
return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
|
|
398
|
-
if (parentClass !== void 0) var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
|
|
399
|
-
var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
|
|
400
|
-
var e = applyMemberDecs(targetClass, memberDecs, metadata);
|
|
401
|
-
if (!classDecs.length) defineMetadata(targetClass, metadata);
|
|
402
|
-
return {
|
|
403
|
-
e,
|
|
404
|
-
get c() {
|
|
405
|
-
return applyClassDecs(targetClass, classDecs, metadata);
|
|
406
|
-
}
|
|
407
|
-
};
|
|
408
|
-
};
|
|
409
|
-
}
|
|
410
|
-
function _apply_decs_2203_r$3(targetClass, memberDecs, classDecs, parentClass) {
|
|
411
|
-
return (_apply_decs_2203_r$3 = applyDecs2203RFactory$3())(targetClass, memberDecs, classDecs, parentClass);
|
|
412
|
-
}
|
|
413
|
-
var _dec$3, _initClass$3;
|
|
414
|
-
let _CommandRegistryService;
|
|
415
|
-
_dec$3 = (0, _navios_core.Injectable)();
|
|
416
|
-
var CommandRegistryService = class {
|
|
417
|
-
static {
|
|
418
|
-
({c: [_CommandRegistryService, _initClass$3]} = _apply_decs_2203_r$3(this, [], [_dec$3]));
|
|
419
|
-
}
|
|
420
|
-
commands = /* @__PURE__ */ new Map();
|
|
421
|
-
/**
|
|
422
|
-
* Register a command with its metadata.
|
|
423
|
-
*
|
|
424
|
-
* @param path - The command path (e.g., 'greet', 'user:create')
|
|
425
|
-
* @param command - The registered command data
|
|
426
|
-
* @throws Error if a command with the same path is already registered
|
|
427
|
-
*/ register(path, command) {
|
|
428
|
-
if (this.commands.has(path)) throw new Error(`[Navios Commander] Duplicate command path: ${path}`);
|
|
429
|
-
this.commands.set(path, command);
|
|
430
|
-
}
|
|
431
|
-
/**
|
|
432
|
-
* Get a command by its path.
|
|
433
|
-
*
|
|
434
|
-
* @param path - The command path
|
|
435
|
-
* @returns The registered command or undefined if not found
|
|
436
|
-
*/ getByPath(path) {
|
|
437
|
-
return this.commands.get(path);
|
|
438
|
-
}
|
|
439
|
-
/**
|
|
440
|
-
* Get all registered commands.
|
|
441
|
-
*
|
|
442
|
-
* @returns Map of path to registered command
|
|
443
|
-
*/ getAll() {
|
|
444
|
-
return new Map(this.commands);
|
|
445
|
-
}
|
|
446
|
-
/**
|
|
447
|
-
* Get all registered commands as an array of path and class pairs.
|
|
448
|
-
* Useful for listing available commands.
|
|
449
|
-
*
|
|
450
|
-
* @returns Array of objects containing path and class
|
|
451
|
-
*/ getAllAsArray() {
|
|
452
|
-
const result = [];
|
|
453
|
-
for (const [path, { class: cls }] of this.commands) result.push({
|
|
454
|
-
path,
|
|
455
|
-
class: cls
|
|
456
|
-
});
|
|
457
|
-
return result;
|
|
458
|
-
}
|
|
459
|
-
/**
|
|
460
|
-
* Formats help text listing all available commands with descriptions.
|
|
461
|
-
*
|
|
462
|
-
* @returns Formatted string listing all commands
|
|
463
|
-
*/ formatCommandList() {
|
|
464
|
-
const lines = ["Available commands:", ""];
|
|
465
|
-
for (const [path, { metadata }] of this.commands) {
|
|
466
|
-
const description = metadata.description;
|
|
467
|
-
if (description) lines.push(` ${path.padEnd(20)} ${description}`);
|
|
468
|
-
else lines.push(` ${path}`);
|
|
469
|
-
}
|
|
470
|
-
return lines.join("\n");
|
|
471
|
-
}
|
|
472
|
-
/**
|
|
473
|
-
* Formats help text for a specific command.
|
|
474
|
-
*
|
|
475
|
-
* @param commandPath - The command path to show help for
|
|
476
|
-
* @returns Formatted string with command help
|
|
477
|
-
*/ formatCommandHelp(commandPath) {
|
|
478
|
-
const command = this.commands.get(commandPath);
|
|
479
|
-
if (!command) return `Unknown command: ${commandPath}\n\n${this.formatCommandList()}`;
|
|
480
|
-
const { metadata } = command;
|
|
481
|
-
const lines = [];
|
|
482
|
-
lines.push(`Usage: ${metadata.path} [options]`);
|
|
483
|
-
lines.push("");
|
|
484
|
-
if (metadata.description) {
|
|
485
|
-
lines.push(metadata.description);
|
|
486
|
-
lines.push("");
|
|
487
|
-
}
|
|
488
|
-
if (metadata.optionsSchema) {
|
|
489
|
-
lines.push("Options:");
|
|
490
|
-
try {
|
|
491
|
-
const shape = metadata.optionsSchema.def.shape;
|
|
492
|
-
if (shape && typeof shape === "object") for (const [key, fieldSchema] of Object.entries(shape)) {
|
|
493
|
-
const optionFlag = `--${key.replace(/([A-Z])/g, "-$1").toLowerCase()}`;
|
|
494
|
-
const fieldType = this.getSchemaTypeName(fieldSchema);
|
|
495
|
-
lines.push(` ${optionFlag.padEnd(20)} ${fieldType}`);
|
|
496
|
-
}
|
|
497
|
-
} catch {}
|
|
498
|
-
}
|
|
499
|
-
return lines.join("\n");
|
|
500
|
-
}
|
|
501
|
-
/**
|
|
502
|
-
* Gets a human-readable type name from a Zod schema.
|
|
503
|
-
*/ getSchemaTypeName(schema) {
|
|
504
|
-
try {
|
|
505
|
-
let currentSchema = schema;
|
|
506
|
-
let typeName = currentSchema?.def?.type;
|
|
507
|
-
let isOptional = false;
|
|
508
|
-
let defaultValue;
|
|
509
|
-
while (typeName === "optional" || typeName === "default") {
|
|
510
|
-
if (typeName === "optional") isOptional = true;
|
|
511
|
-
if (typeName === "default") {
|
|
512
|
-
isOptional = true;
|
|
513
|
-
defaultValue = currentSchema?.def?.defaultValue?.();
|
|
514
|
-
}
|
|
515
|
-
currentSchema = currentSchema?.def?.innerType;
|
|
516
|
-
typeName = currentSchema?.def?.type;
|
|
517
|
-
}
|
|
518
|
-
let result = `<${typeName || "unknown"}>`;
|
|
519
|
-
if (defaultValue !== void 0) result += ` (default: ${JSON.stringify(defaultValue)})`;
|
|
520
|
-
else if (isOptional) result += " (optional)";
|
|
521
|
-
const description = this.getSchemaMeta(schema)?.description;
|
|
522
|
-
if (description) result += ` - ${description}`;
|
|
523
|
-
return result;
|
|
524
|
-
} catch {
|
|
525
|
-
return "<unknown>";
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
/**
|
|
529
|
-
* Gets metadata from a Zod schema, traversing innerType if needed.
|
|
530
|
-
* Zod v4 stores meta at the outermost layer when .meta() is called last,
|
|
531
|
-
* or in innerType when .meta() is called before .optional()/.default().
|
|
532
|
-
*/ getSchemaMeta(schema) {
|
|
533
|
-
try {
|
|
534
|
-
const directMeta = schema.meta?.();
|
|
535
|
-
if (directMeta) return directMeta;
|
|
536
|
-
const innerType = schema.def?.innerType;
|
|
537
|
-
if (innerType) return this.getSchemaMeta(innerType);
|
|
538
|
-
return;
|
|
539
|
-
} catch {
|
|
540
|
-
return;
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
/**
|
|
544
|
-
* Clear all registered commands.
|
|
545
|
-
*/ clear() {
|
|
546
|
-
this.commands.clear();
|
|
547
|
-
}
|
|
548
|
-
static {
|
|
549
|
-
_initClass$3();
|
|
550
|
-
}
|
|
551
|
-
};
|
|
552
|
-
|
|
553
|
-
//#endregion
|
|
554
7
|
//#region src/commands/help.command.mts
|
|
555
8
|
function applyDecs2203RFactory$2() {
|
|
556
9
|
function createAddInitializerMethod(initializers, decoratorFinishedRef) {
|
|
@@ -832,7 +285,8 @@ function _apply_decs_2203_r$2(targetClass, memberDecs, classDecs, parentClass) {
|
|
|
832
285
|
var _dec$2, _initClass$2;
|
|
833
286
|
const helpOptionsSchema = zod.z.object({ command: zod.z.string().optional() });
|
|
834
287
|
let _HelpCommand;
|
|
835
|
-
_dec$2 = Command({
|
|
288
|
+
_dec$2 = require_command_decorator.Command({
|
|
289
|
+
token: require_help_command_token.HelpCommandToken,
|
|
836
290
|
path: "help",
|
|
837
291
|
description: "Show available commands or help for a specific command",
|
|
838
292
|
optionsSchema: helpOptionsSchema
|
|
@@ -842,7 +296,7 @@ var HelpCommand = class {
|
|
|
842
296
|
({c: [_HelpCommand, _initClass$2]} = _apply_decs_2203_r$2(this, [], [_dec$2]));
|
|
843
297
|
}
|
|
844
298
|
logger = (0, _navios_core.inject)(_navios_core.Logger, { context: "Commander" });
|
|
845
|
-
commandRegistry = (0, _navios_core.inject)(_CommandRegistryService);
|
|
299
|
+
commandRegistry = (0, _navios_core.inject)(require_help_command_token._CommandRegistryService);
|
|
846
300
|
async execute(options) {
|
|
847
301
|
if (options.command) this.logger.log(this.commandRegistry.formatCommandHelp(options.command));
|
|
848
302
|
else this.logger.log(this.commandRegistry.formatCommandList());
|
|
@@ -1692,7 +1146,7 @@ var CommanderAdapterService = class {
|
|
|
1692
1146
|
({c: [_CommanderAdapterService, _initClass]} = _apply_decs_2203_r(this, [], [_dec]));
|
|
1693
1147
|
}
|
|
1694
1148
|
container = (0, _navios_core.inject)(_navios_core.Container);
|
|
1695
|
-
commandRegistry = (0, _navios_core.inject)(_CommandRegistryService);
|
|
1149
|
+
commandRegistry = (0, _navios_core.inject)(require_help_command_token._CommandRegistryService);
|
|
1696
1150
|
cliParser = (0, _navios_core.inject)(_CliParserService);
|
|
1697
1151
|
logger = (0, _navios_core.inject)(_navios_core.Logger, { context: "Commander" });
|
|
1698
1152
|
options = {};
|
|
@@ -1709,14 +1163,14 @@ var CommanderAdapterService = class {
|
|
|
1709
1163
|
*/ async onModulesInit(modules) {
|
|
1710
1164
|
this.registerBuiltInCommands();
|
|
1711
1165
|
for (const [moduleName, metadata] of modules) {
|
|
1712
|
-
const commands = metadata.customEntries.get(CommandEntryKey);
|
|
1166
|
+
const commands = metadata.customEntries.get(require_command_decorator.CommandEntryKey);
|
|
1713
1167
|
if (!commands) continue;
|
|
1714
1168
|
for (const commandClass of commands) {
|
|
1715
|
-
if (!hasCommandMetadata(commandClass)) {
|
|
1169
|
+
if (!require_command_decorator.hasCommandMetadata(commandClass)) {
|
|
1716
1170
|
this.logger.warn(`Class ${commandClass.name} in module ${moduleName} is listed in commands but has no @Command decorator. Skipping.`);
|
|
1717
1171
|
continue;
|
|
1718
1172
|
}
|
|
1719
|
-
const commandMetadata = extractCommandMetadata(commandClass);
|
|
1173
|
+
const commandMetadata = require_command_decorator.extractCommandMetadata(commandClass);
|
|
1720
1174
|
this.commandRegistry.register(commandMetadata.path, {
|
|
1721
1175
|
class: commandClass,
|
|
1722
1176
|
metadata: commandMetadata,
|
|
@@ -1728,7 +1182,7 @@ var CommanderAdapterService = class {
|
|
|
1728
1182
|
/**
|
|
1729
1183
|
* Registers built-in commands like help.
|
|
1730
1184
|
*/ registerBuiltInCommands() {
|
|
1731
|
-
const helpMetadata = extractCommandMetadata(_HelpCommand);
|
|
1185
|
+
const helpMetadata = require_command_decorator.extractCommandMetadata(_HelpCommand);
|
|
1732
1186
|
this.commandRegistry.register(helpMetadata.path, {
|
|
1733
1187
|
class: _HelpCommand,
|
|
1734
1188
|
metadata: helpMetadata,
|
|
@@ -1881,6 +1335,31 @@ var CommanderAdapterService = class {
|
|
|
1881
1335
|
* await adapter.run(process.argv)
|
|
1882
1336
|
* ```
|
|
1883
1337
|
*/ static async create(appModule, options = {}) {
|
|
1338
|
+
if (options.enableTUI) {
|
|
1339
|
+
let tuiModule;
|
|
1340
|
+
try {
|
|
1341
|
+
tuiModule = await import("@navios/commander-tui");
|
|
1342
|
+
} catch {
|
|
1343
|
+
throw new Error("TUI mode requires @navios/commander-tui package. Install it with: npm install @navios/commander-tui");
|
|
1344
|
+
}
|
|
1345
|
+
const { overrideConsoleLogger, ScreenManager } = tuiModule;
|
|
1346
|
+
overrideConsoleLogger(options.tuiOptions?.hideDefaultScreen ?? false);
|
|
1347
|
+
if (options.tuiOptions?.hideDefaultScreen) await Promise.resolve().then(() => require("./help.command-DQyv6ali.cjs"));
|
|
1348
|
+
const app = await _navios_core.NaviosFactory.create(appModule, {
|
|
1349
|
+
adapter: defineCliEnvironment(),
|
|
1350
|
+
logger: options.logLevels
|
|
1351
|
+
});
|
|
1352
|
+
await (await app.get(ScreenManager)).bind({
|
|
1353
|
+
exitOnCtrlC: options.tuiOptions?.exitOnCtrlC,
|
|
1354
|
+
sidebarWidth: options.tuiOptions?.sidebarWidth,
|
|
1355
|
+
sidebarPosition: options.tuiOptions?.sidebarPosition,
|
|
1356
|
+
sidebarTitle: options.tuiOptions?.sidebarTitle,
|
|
1357
|
+
autoClose: options.tuiOptions?.autoClose,
|
|
1358
|
+
theme: options.tuiOptions?.theme,
|
|
1359
|
+
useMouse: options.tuiOptions?.useMouse
|
|
1360
|
+
});
|
|
1361
|
+
return app;
|
|
1362
|
+
}
|
|
1884
1363
|
return await _navios_core.NaviosFactory.create(appModule, {
|
|
1885
1364
|
adapter: defineCliEnvironment(),
|
|
1886
1365
|
logger: _navios_core.ConsoleLogger.create({
|
|
@@ -1897,82 +1376,21 @@ var CommanderAdapterService = class {
|
|
|
1897
1376
|
};
|
|
1898
1377
|
|
|
1899
1378
|
//#endregion
|
|
1900
|
-
|
|
1901
|
-
/**
|
|
1902
|
-
* Decorator that marks a class as a CLI module.
|
|
1903
|
-
*
|
|
1904
|
-
* This decorator extends the standard @Module decorator, adding support for
|
|
1905
|
-
* CLI commands while maintaining full compatibility with HTTP controllers.
|
|
1906
|
-
* Modules organize commands and can import other modules to compose larger
|
|
1907
|
-
* CLI applications.
|
|
1908
|
-
*
|
|
1909
|
-
* The module can optionally implement `NaviosModule` interface for lifecycle hooks.
|
|
1910
|
-
*
|
|
1911
|
-
* @param options - Configuration options for the module
|
|
1912
|
-
* @returns A class decorator function
|
|
1913
|
-
*
|
|
1914
|
-
* @example
|
|
1915
|
-
* ```typescript
|
|
1916
|
-
* import { CliModule } from '@navios/commander'
|
|
1917
|
-
* import { GreetCommand } from './greet.command'
|
|
1918
|
-
* import { UserModule } from './user.module'
|
|
1919
|
-
*
|
|
1920
|
-
* @CliModule({
|
|
1921
|
-
* commands: [GreetCommand],
|
|
1922
|
-
* imports: [UserModule]
|
|
1923
|
-
* })
|
|
1924
|
-
* export class AppModule {}
|
|
1925
|
-
* ```
|
|
1926
|
-
*
|
|
1927
|
-
* @example
|
|
1928
|
-
* ```typescript
|
|
1929
|
-
* // Mixed HTTP and CLI module
|
|
1930
|
-
* @CliModule({
|
|
1931
|
-
* controllers: [HealthController],
|
|
1932
|
-
* commands: [MigrateCommand],
|
|
1933
|
-
* imports: [DatabaseModule],
|
|
1934
|
-
* })
|
|
1935
|
-
* export class AppModule {}
|
|
1936
|
-
* ```
|
|
1937
|
-
*/ function CliModule({ commands = [], controllers = [], imports = [], guards = [], overrides = [], priority, registry } = {
|
|
1938
|
-
commands: [],
|
|
1939
|
-
controllers: [],
|
|
1940
|
-
imports: [],
|
|
1941
|
-
guards: [],
|
|
1942
|
-
overrides: []
|
|
1943
|
-
}) {
|
|
1944
|
-
return (target, context) => {
|
|
1945
|
-
if (context.kind !== "class") throw new Error("[Navios Commander] @CliModule decorator can only be used on classes.");
|
|
1946
|
-
const result = (0, _navios_core.Module)({
|
|
1947
|
-
controllers,
|
|
1948
|
-
imports,
|
|
1949
|
-
guards,
|
|
1950
|
-
overrides,
|
|
1951
|
-
priority,
|
|
1952
|
-
registry
|
|
1953
|
-
})(target, context);
|
|
1954
|
-
const commandSet = (0, _navios_core.getModuleCustomEntry)((0, _navios_core.getModuleMetadata)(target, context), CommandEntryKey, () => /* @__PURE__ */ new Set());
|
|
1955
|
-
for (const command of commands) commandSet.add(command);
|
|
1956
|
-
return result;
|
|
1957
|
-
};
|
|
1958
|
-
}
|
|
1959
|
-
|
|
1960
|
-
//#endregion
|
|
1961
|
-
exports.CliModule = CliModule;
|
|
1379
|
+
exports.CliModule = require_cli_module_decorator.CliModule;
|
|
1962
1380
|
Object.defineProperty(exports, 'CliParserService', {
|
|
1963
1381
|
enumerable: true,
|
|
1964
1382
|
get: function () {
|
|
1965
1383
|
return _CliParserService;
|
|
1966
1384
|
}
|
|
1967
1385
|
});
|
|
1968
|
-
exports.Command = Command;
|
|
1969
|
-
exports.CommandEntryKey = CommandEntryKey;
|
|
1386
|
+
exports.Command = require_command_decorator.Command;
|
|
1387
|
+
exports.CommandEntryKey = require_command_decorator.CommandEntryKey;
|
|
1970
1388
|
exports.CommandExecutionContext = CommandExecutionContext;
|
|
1971
|
-
exports.CommandMetadataKey = CommandMetadataKey;
|
|
1389
|
+
exports.CommandMetadataKey = require_command_decorator.CommandMetadataKey;
|
|
1972
1390
|
Object.defineProperty(exports, 'CommandRegistryService', {
|
|
1973
1391
|
enumerable: true,
|
|
1974
1392
|
get: function () {
|
|
1975
|
-
return _CommandRegistryService;
|
|
1393
|
+
return require_help_command_token._CommandRegistryService;
|
|
1976
1394
|
}
|
|
1977
1395
|
});
|
|
1978
1396
|
Object.defineProperty(exports, 'CommanderAdapterService', {
|
|
@@ -1990,10 +1408,10 @@ Object.defineProperty(exports, 'HelpCommand', {
|
|
|
1990
1408
|
}
|
|
1991
1409
|
});
|
|
1992
1410
|
exports.defineCliEnvironment = defineCliEnvironment;
|
|
1993
|
-
exports.extractCommandMetadata = extractCommandMetadata;
|
|
1994
|
-
exports.extractModuleCommands = extractModuleCommands;
|
|
1995
|
-
exports.getCommandMetadata = getCommandMetadata;
|
|
1996
|
-
exports.hasCommandMetadata = hasCommandMetadata;
|
|
1411
|
+
exports.extractCommandMetadata = require_command_decorator.extractCommandMetadata;
|
|
1412
|
+
exports.extractModuleCommands = require_command_decorator.extractModuleCommands;
|
|
1413
|
+
exports.getCommandMetadata = require_command_decorator.getCommandMetadata;
|
|
1414
|
+
exports.hasCommandMetadata = require_command_decorator.hasCommandMetadata;
|
|
1997
1415
|
Object.keys(_navios_core).forEach(function (k) {
|
|
1998
1416
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
1999
1417
|
enumerable: true,
|