@zenflux/commands 0.0.0-stage → 0.0.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 (43) hide show
  1. package/LICENSE +674 -0
  2. package/package.json +25 -3
  3. package/readme.md +42 -0
  4. package/src/api.ts +166 -0
  5. package/src/core/commands-internal.ts +15 -0
  6. package/src/core/commands.ts +684 -0
  7. package/src/core/components.ts +107 -0
  8. package/src/core/hooks/base.ts +451 -0
  9. package/src/core/hooks/data.ts +58 -0
  10. package/src/core/hooks/ui.ts +44 -0
  11. package/src/core/hooks.ts +267 -0
  12. package/src/core/routes.ts +247 -0
  13. package/src/core/shortcuts.ts +358 -0
  14. package/src/core/store.ts +155 -0
  15. package/src/env.d.ts +15 -0
  16. package/src/extras/dev-tools.ts +443 -0
  17. package/src/index.ts +83 -0
  18. package/src/instance.ts +30 -0
  19. package/src/modules/args-object.ts +113 -0
  20. package/src/modules/command-base.ts +51 -0
  21. package/src/modules/command-callback-base.ts +42 -0
  22. package/src/modules/command-infra.ts +230 -0
  23. package/src/modules/command-internal-base.ts +19 -0
  24. package/src/modules/component-base.ts +483 -0
  25. package/src/modules/hook-base.ts +158 -0
  26. package/src/modules/hook-break.ts +8 -0
  27. package/src/modules/hooks/data/after.ts +19 -0
  28. package/src/modules/hooks/data/base.ts +15 -0
  29. package/src/modules/hooks/data/catch.ts +16 -0
  30. package/src/modules/hooks/data/dependency.ts +16 -0
  31. package/src/modules/hooks/data/index.ts +6 -0
  32. package/src/modules/hooks/ui/after.ts +18 -0
  33. package/src/modules/hooks/ui/base.ts +15 -0
  34. package/src/modules/hooks/ui/before.ts +16 -0
  35. package/src/modules/hooks/ui/catch.ts +16 -0
  36. package/src/modules/hooks/ui/index.ts +6 -0
  37. package/src/modules/instance-type.ts +119 -0
  38. package/src/modules/module.ts +224 -0
  39. package/src/types.ts +194 -0
  40. package/src/utils/instances-slice.ts +123 -0
  41. package/src/utils/object.ts +162 -0
  42. package/src/utils/value-store.ts +145 -0
  43. package/README.md +0 -3
@@ -0,0 +1,684 @@
1
+ import CommandBase from "@zenflux/commands/src/modules/command-base";
2
+ import HookBreak from "@zenflux/commands/src/modules/hook-break";
3
+ import Module from "@zenflux/commands/src/modules/module";
4
+
5
+ import { $e } from "@zenflux/commands/src/instance";
6
+ import { isCommandClass } from "@zenflux/commands/src/modules/command-infra";
7
+
8
+ import type { ModuleEvents } from "@zenflux/commands/src/modules/module";
9
+ import type { CommandClass, RegisteredCallback, RunnableCommand } from "@zenflux/commands/src/modules/command-infra";
10
+ import type ComponentBase from "@zenflux/commands/src/modules/component-base";
11
+ import type { CommandArgs } from "@zenflux/commands/src/types";
12
+
13
+ /**
14
+ * What a commands system keeps by name: a command class, or a function (a route's).
15
+ */
16
+ export type CommandEntry = CommandClass | RegisteredCallback;
17
+
18
+ /**
19
+ * What a run by name gives: the command's result as the system passes it on (for an async command, a promise of it
20
+ * that resolves once its 'after' hooks are done), or false when it did not run. Typed by name: `$e.run()`.
21
+ */
22
+ export type CommandsRunResult = void | Promise<void> | false;
23
+
24
+ export interface CommandsEvents extends ModuleEvents {
25
+ /**
26
+ * A command is about to run.
27
+ */
28
+ "run:before": ( component: ComponentBase, command: string, args: CommandArgs ) => void;
29
+
30
+ /**
31
+ * A command ran: its result, or the error it failed with.
32
+ */
33
+ "run:after": <TResult>( component: ComponentBase, command: string, args: CommandArgs, result: TResult ) => void;
34
+
35
+ /**
36
+ * A command failed: what it threw or rejected with, or an error it handled itself and reported (`catchApply()`).
37
+ */
38
+ "run:catch": <TError>( component: ComponentBase, command: string, args: CommandArgs, error: TError ) => void;
39
+ }
40
+
41
+ /**
42
+ * @param value
43
+ *
44
+ * @return whether the value is a promise (an async command's result)
45
+ */
46
+ const isPromise = <TValue>( value: TValue ): value is TValue & Promise<Awaited<TValue>> => value instanceof Promise;
47
+
48
+ /**
49
+ * @param namespace A component's.
50
+ * @param name A command's or route's full name.
51
+ *
52
+ * @return whether the name is one of the component's: '<namespace>/<name>', not one of a component inside it
53
+ * ('editor/elements/select' is the 'editor/elements' component's, not the editor's). As OwnNames (types.ts).
54
+ */
55
+ const isOwnName = ( namespace: string, name: string ): boolean => {
56
+ const own = name.startsWith( namespace + "/" ) ? name.slice( namespace.length + 1 ) : "";
57
+
58
+ return "" !== own && ! own.includes( "/" );
59
+ };
60
+
61
+ /**
62
+ * The commands systems' base: commands by name ('component/command'), each run with its component's dependency, hooks
63
+ * and trace. `$e.commands`, `$e.commandsInternal` and `$e.routes` are commands systems; each runs by name in its own
64
+ * way (`run()`, `to()`), through `runCommand()`.
65
+ */
66
+ export class CommandsBase<TEntry extends CommandEntry = CommandEntry> extends Module<CommandsEvents> {
67
+ public static getName(): string {
68
+ return "ZenFlux/Commands/Core/CommandsBase";
69
+ }
70
+
71
+ /**
72
+ * The commands running now, of every kind, first to last.
73
+ */
74
+ public static trace: string[] = [];
75
+
76
+ public current: { [ container: string ]: string };
77
+ public currentArgs: { [ container: string ]: CommandArgs };
78
+ public currentTrace: string[];
79
+ public commands: { [ command: string ]: TEntry };
80
+ public components: { [ command: string ]: string };
81
+
82
+ public constructor( args?: object ) {
83
+ super( args );
84
+
85
+ this.current = {};
86
+ this.currentArgs = {};
87
+ this.currentTrace = [];
88
+ this.commands = {};
89
+ this.components = {};
90
+ }
91
+
92
+ /**
93
+ * @param id
94
+ *
95
+ * @return command class (a route's function)
96
+ */
97
+ public getCommandClass( id: string ): TEntry | undefined {
98
+ return this.commands[ id ];
99
+ }
100
+
101
+ /**
102
+ * Receive all loaded commands.
103
+ *
104
+ * @return commands
105
+ */
106
+ public getAll(): string[] {
107
+ return Object.keys( this.commands ).sort();
108
+ }
109
+
110
+ /**
111
+ * Register new command.
112
+ *
113
+ * @param component Its component, or its namespace.
114
+ * @param command Its full name, in the component's namespace: 'panel/close'.
115
+ * @param callback The command class (a route's function).
116
+ *
117
+ * @return commands
118
+ */
119
+ public register( component: ComponentBase | string, command: string, callback: TEntry ): this {
120
+ const owner = this.componentOf( component ),
121
+ namespace = owner.getNamespace();
122
+
123
+ if ( ! isOwnName( namespace, command ) ) {
124
+ this.error( `\`${ command }\` is not a name of the '${ namespace }' component's: '${ namespace }/<name>'.` );
125
+ }
126
+
127
+ if ( this.commands[ command ] ) {
128
+ this.error( `\`${ command }\` is already registered.` );
129
+ }
130
+
131
+ this.commands[ command ] = callback;
132
+ this.components[ command ] = namespace;
133
+
134
+ const shortcut = owner.getShortcuts()[ command ];
135
+
136
+ if ( shortcut ) {
137
+ const handler = Object.assign( shortcut, {
138
+ command,
139
+ callback: ( event: KeyboardEvent ) => this.runShortcut( command, event ),
140
+ } );
141
+
142
+ $e.shortcuts.register( handler.keys, handler );
143
+ }
144
+
145
+ return this;
146
+ }
147
+
148
+ /**
149
+ * @param component Its component, or its namespace.
150
+ * @param command Its full name.
151
+ *
152
+ * @return commands
153
+ */
154
+ public unregister( component: ComponentBase | string, command: string ): this {
155
+ const owner = this.componentOf( component );
156
+
157
+ if ( ! this.commands[ command ] || this.components[ command ] !== owner.getNamespace() ) {
158
+ this.error( `\`${ command }\` not exist.` );
159
+ }
160
+
161
+ delete this.commands[ command ];
162
+ delete this.components[ command ];
163
+
164
+ const shortcut = owner.getShortcuts()[ command ];
165
+
166
+ if ( shortcut ) {
167
+ $e.shortcuts.unregister( shortcut.keys, shortcut );
168
+ }
169
+
170
+ return this;
171
+ }
172
+
173
+ /**
174
+ * Receive Component of the command.
175
+ *
176
+ * @param command
177
+ *
178
+ * @return component
179
+ */
180
+ public getComponent( command: string ): ComponentBase | undefined {
181
+ return $e.components.getByNamespace( this.components[ command ] );
182
+ }
183
+
184
+ /**
185
+ * Checks if current running command is the same parameter command.
186
+ *
187
+ * @param command
188
+ *
189
+ * @return is this command the same as the one passed in the arguments
190
+ */
191
+ public is( command: string ): boolean {
192
+ const component = this.getComponent( command );
193
+
194
+ if ( ! component ) {
195
+ return false;
196
+ }
197
+
198
+ return command === this.current[ component.getServiceName() ];
199
+ }
200
+
201
+ /**
202
+ * Checks if parameter command is the first command in trace that currently running.
203
+ *
204
+ * @param command
205
+ *
206
+ * @return is parameter command the first command in trace that currently running
207
+ */
208
+ public isCurrentFirstTrace( command: string ): boolean {
209
+ return command === this.getCurrentFirstTrace();
210
+ }
211
+
212
+ /**
213
+ * Receive currently running components and its commands.
214
+ *
215
+ * @param container
216
+ *
217
+ * @return the container's command (false when none runs); without one, every container's
218
+ */
219
+ public getCurrent(): { [ container: string ]: string };
220
+ public getCurrent( container: string ): string | false;
221
+ public getCurrent( container = "" ): { [ container: string ]: string } | string | false {
222
+ if ( container ) {
223
+ if ( ! this.current[ container ] ) {
224
+ return false;
225
+ }
226
+
227
+ return this.current[ container ];
228
+ }
229
+
230
+ return this.current;
231
+ }
232
+
233
+ /**
234
+ * Receive currently running command args.
235
+ *
236
+ * @param container
237
+ *
238
+ * @return the container's command's args (false when none runs); without one, every container's
239
+ */
240
+ public getCurrentArgs(): { [ container: string ]: CommandArgs };
241
+ public getCurrentArgs( container: string ): CommandArgs | false;
242
+ public getCurrentArgs( container = "" ): { [ container: string ]: CommandArgs } | CommandArgs | false {
243
+ if ( container ) {
244
+ if ( ! this.currentArgs[ container ] ) {
245
+ return false;
246
+ }
247
+
248
+ return this.currentArgs[ container ];
249
+ }
250
+
251
+ return this.currentArgs;
252
+ }
253
+
254
+ /**
255
+ * Receive first command that currently running.
256
+ *
257
+ * @return first running command
258
+ */
259
+ public getCurrentFirst(): string | undefined {
260
+ return Object.values( this.current )[ 0 ];
261
+ }
262
+
263
+ /**
264
+ * Receive last command that currently running.
265
+ *
266
+ * @return last running command
267
+ */
268
+ public getCurrentLast(): string | undefined {
269
+ const current = Object.values( this.current );
270
+
271
+ return current[ current.length - 1 ];
272
+ }
273
+
274
+ /**
275
+ * Receive first command in trace that currently running
276
+ *
277
+ * @return first command in trace
278
+ */
279
+ public getCurrentFirstTrace(): string | undefined {
280
+ return this.currentTrace[ 0 ];
281
+ }
282
+
283
+ /**
284
+ * Responsible to add current command to trace and trigger 'run:before' event.
285
+ * Run before command.
286
+ *
287
+ * @param command
288
+ * @param args
289
+ * @param addTrace
290
+ */
291
+ public beforeRun( command: string, args: CommandArgs = {}, addTrace = true ): void {
292
+ const component = this.requireComponent( command ),
293
+ container = component.getServiceName();
294
+
295
+ if ( addTrace ) {
296
+ this.addCurrentTrace( container, command, args );
297
+ }
298
+
299
+ if ( args.onBefore ) {
300
+ args.onBefore.apply( component, [ args ] );
301
+ }
302
+
303
+ if ( this.hasListeners( "run:before" ) ) {
304
+ this.trigger( "run:before", component, command, args );
305
+ }
306
+ }
307
+
308
+ /**
309
+ * Responsible to validate if the run is even possible.
310
+ * Runs immediately after entering `run()`.
311
+ *
312
+ * @param command
313
+ * @param args
314
+ *
315
+ * @return dependency result
316
+ */
317
+ public validateRun( command: string, args: CommandArgs = {} ): boolean {
318
+ if ( ! this.commands[ command ] ) {
319
+ this.error( `\`${ command }\` not found.` );
320
+ }
321
+
322
+ return this.requireComponent( command ).dependency( command, args );
323
+ }
324
+
325
+ /**
326
+ * Runs a command, by its name.
327
+ *
328
+ * @param command
329
+ * @param args
330
+ *
331
+ * @return results
332
+ */
333
+ protected runCommand( command: string, args: CommandArgs = {} ): CommandsRunResult {
334
+ if ( ! this.validateRun( command, args ) ) {
335
+ return false;
336
+ }
337
+
338
+ this.beforeRun( command, args );
339
+
340
+ // Get command class or callback.
341
+ const context: CommandEntry = this.commands[ command ],
342
+ currentComponent = this.requireComponent( command );
343
+
344
+ // Is simple callback? (e.g. a route)
345
+ if ( ! isCommandClass( context ) ) {
346
+ const results = context.apply( currentComponent, [ args ] );
347
+
348
+ this.afterRun( command, args, results );
349
+
350
+ return results;
351
+ }
352
+
353
+ let instance: RunnableCommand;
354
+
355
+ try {
356
+ // The class registered under the name takes the args its name runs with (`$e.run()` checks them against
357
+ // its registry): TS can't follow a class through its name.
358
+ instance = new context( args as never );
359
+ } catch( e ) {
360
+ // Its args did not validate.
361
+ this.removeCurrentTrace( currentComponent );
362
+
363
+ throw e;
364
+ }
365
+
366
+ if ( ! this.validateInstanceScope( instance, currentComponent, command ) ) {
367
+ this.removeCurrentTrace( currentComponent );
368
+
369
+ return false;
370
+ }
371
+
372
+ return this.runInstance( instance );
373
+ }
374
+
375
+ /**
376
+ * @param instance
377
+ *
378
+ * @return results
379
+ */
380
+ public runInstance( instance: RunnableCommand ): CommandsRunResult {
381
+ let results: void;
382
+
383
+ // For UI Hooks.
384
+ instance.onBeforeRun( instance.args );
385
+
386
+ try {
387
+ // For data hooks.
388
+ instance.onBeforeApply( instance.args );
389
+
390
+ results = instance.run();
391
+ } catch( e ) {
392
+ this.catchApply( e, instance );
393
+
394
+ // A dependency hook stopped the command.
395
+ if ( e instanceof HookBreak ) {
396
+ this.removeCurrentTrace( instance.component );
397
+
398
+ return false;
399
+ }
400
+
401
+ // The error is the caller's, as when an async command rejects (Elementor's went on to the 'after' hooks
402
+ // with a null result).
403
+ this.afterRun( instance.command, instance.args, e );
404
+
405
+ throw e;
406
+ }
407
+
408
+ return this.applyRunAfter( instance, results );
409
+ }
410
+
411
+ /**
412
+ * Responsible for applying everything that need to be run after each command runs.
413
+ * Called on run() after runInstance(), to manipulate results & apply 'after' hooks.
414
+ *
415
+ * @param instance
416
+ * @param result
417
+ *
418
+ * @return result; for a promise, one of its value once the 'after' hooks are done
419
+ */
420
+ public applyRunAfter<TResult>( instance: RunnableCommand, result: TResult ): TResult | Promise<Awaited<TResult>> {
421
+ if ( isPromise( result ) ) {
422
+ return this.applyRunAfterAsync( instance, result );
423
+ }
424
+
425
+ this.applyRunAfterSync( instance, result );
426
+
427
+ return result;
428
+ }
429
+
430
+ /**
431
+ * Responsible to handle simple(synchronous) 'run after' behavior.
432
+ *
433
+ * @param instance
434
+ * @param result
435
+ */
436
+ public applyRunAfterSync<TResult>( instance: RunnableCommand, result: TResult ): void {
437
+ // Run Data hooks.
438
+ instance.onAfterApply( instance.args, result );
439
+
440
+ // For UI hooks.
441
+ instance.onAfterRun( instance.args, result );
442
+
443
+ this.afterRun( instance.command, instance.args, result );
444
+ }
445
+
446
+ /**
447
+ * Await for promise result.
448
+ *
449
+ * @param instance
450
+ * @param result
451
+ *
452
+ * @return result, once the 'after' hooks are done
453
+ */
454
+ public applyRunAfterAsync<TResult>( instance: RunnableCommand, result: Promise<TResult> ): Promise<TResult> {
455
+ // One step after the result: its 'after' hooks, and only then the value (or the error, after the catch
456
+ // hooks). Each `await` or wrapping promise more would cost every run a turn of the microtask queue.
457
+ return result.then(
458
+ ( value ) => {
459
+ const hooks = this.applyRunAfterAsyncResult( instance, value );
460
+
461
+ return hooks ? hooks.then( () => value ) : value;
462
+ },
463
+ ( e ) => {
464
+ this.catchApply( e, instance );
465
+ this.afterRun( instance.command, instance.args, e );
466
+
467
+ throw e;
468
+ },
469
+ );
470
+ }
471
+
472
+ /**
473
+ * Runs the 'after' hooks of a command whose promise resolved, and waits for those that answer with a promise,
474
+ * before the command is released.
475
+ *
476
+ * @param instance
477
+ * @param result
478
+ *
479
+ * @return what to wait for, when a hook answered with a promise
480
+ */
481
+ public applyRunAfterAsyncResult<TResult>( instance: RunnableCommand, result: TResult ): Promise<void> | void {
482
+ // Run Data hooks.
483
+ const results = instance.onAfterApply( instance.args, result ),
484
+ promises = Array.isArray( results ) ? results.flat().filter( ( filtered ) => filtered instanceof Promise ) : [];
485
+
486
+ if ( promises.length ) {
487
+ // Wait for hooks before return the value.
488
+ return Promise.all( promises ).then( () => this.releaseRunAfter( instance, result ) );
489
+ }
490
+
491
+ this.releaseRunAfter( instance, result );
492
+ }
493
+
494
+ /**
495
+ * The UI 'after' hooks of a command, and its release.
496
+ *
497
+ * @param instance
498
+ * @param result
499
+ */
500
+ public releaseRunAfter<TResult>( instance: RunnableCommand, result: TResult ): void {
501
+ // For UI hooks.
502
+ instance.onAfterRun( instance.args, result );
503
+
504
+ this.afterRun( instance.command, instance.args, result );
505
+ }
506
+
507
+ /**
508
+ * Responsible to clear command from trace, and run 'run:after' event.
509
+ * Method fired after the command runs.
510
+ *
511
+ * @param command
512
+ * @param args
513
+ * @param results Its result, or the error it failed with.
514
+ * @param removeTrace
515
+ */
516
+ public afterRun<TResult>( command: string, args: CommandArgs, results?: TResult, removeTrace = true ): void {
517
+ const component = this.requireComponent( command );
518
+
519
+ if ( args.onAfter ) {
520
+ args.onAfter.call( component, args, results );
521
+ }
522
+
523
+ if ( this.hasListeners( "run:after" ) ) {
524
+ this.trigger( "run:after", component, command, args, results );
525
+ }
526
+
527
+ if ( removeTrace ) {
528
+ this.removeCurrentTrace( component );
529
+ }
530
+ }
531
+
532
+ /**
533
+ * A command failed: its catch hooks run, and 'run:catch' tells who listens. A command that handles its own
534
+ * failure (it tells the user, and its run goes on) reports it here too, so it failed for its caller as well.
535
+ *
536
+ * @param e What the command threw, or rejected with, or the error it handled.
537
+ * @param instance
538
+ */
539
+ public catchApply<TError>( e: TError, instance: RunnableCommand ): void {
540
+ instance.onCatchApply( e );
541
+
542
+ // A 'Hook-Break' is how a dependency hook stops a command, not an error.
543
+ if ( ! ( e instanceof HookBreak ) ) {
544
+ this.logger.error( this.catchApply, `'${ instance.command }' failed:`, e );
545
+ }
546
+
547
+ this.trigger( "run:catch", instance.component, instance.command, instance.args, e );
548
+ }
549
+
550
+ /**
551
+ * Run shortcut.
552
+ *
553
+ * It's separated in order to allow override.
554
+ *
555
+ * @param command
556
+ * @param event The command's args.
557
+ *
558
+ * @return result
559
+ */
560
+ public runShortcut( command: string, event: KeyboardEvent ): CommandsRunResult {
561
+ return this.runCommand( command, event );
562
+ }
563
+
564
+ public validateInstanceScope( instance: RunnableCommand, currentComponent: ComponentBase, command: string ): boolean {
565
+ if ( ! ( instance instanceof CommandBase ) ) {
566
+ this.error( `invalid instance, command: '${ command }' ` );
567
+ }
568
+
569
+ // In case of different scope.
570
+ if ( currentComponent !== instance.component ) {
571
+ if ( $e.devTools ) {
572
+ $e.devTools.log.warn( `Command: '${ command }' registerArgs.component: '${ instance.component.getNamespace() }' while current component is: '${ currentComponent.getNamespace() }'` );
573
+ }
574
+
575
+ return false;
576
+ }
577
+
578
+ return true;
579
+ }
580
+
581
+ public addCurrentTrace( container: string, command: string, args: CommandArgs ): void {
582
+ this.currentTrace.push( command );
583
+
584
+ CommandsBase.trace.push( command );
585
+
586
+ this.attachCurrent( container, command, args );
587
+ }
588
+
589
+ public removeCurrentTrace( currentComponent: ComponentBase ): void {
590
+ const container = currentComponent.getServiceName();
591
+
592
+ this.currentTrace.pop();
593
+
594
+ CommandsBase.trace.pop();
595
+
596
+ this.detachCurrent( container );
597
+ }
598
+
599
+ public attachCurrent( container: string, command: string, args: CommandArgs ): void {
600
+ this.current[ container ] = command;
601
+ this.currentArgs[ container ] = args;
602
+ }
603
+
604
+ public detachCurrent( container: string ): void {
605
+ delete this.current[ container ];
606
+ delete this.currentArgs[ container ];
607
+ }
608
+
609
+ /**
610
+ * @return the API call that runs these commands, for the dev tools' log
611
+ */
612
+ public getCall(): string {
613
+ return "$e.run";
614
+ }
615
+
616
+ /**
617
+ * Throws error.
618
+ *
619
+ * @throws {Error}
620
+ *
621
+ * @param message
622
+ */
623
+ public error( message: string ): never {
624
+ throw Error( `Commands: ${ message }` );
625
+ }
626
+
627
+ /**
628
+ * @param command
629
+ *
630
+ * @throws {Error} when the command has no component (it is not registered)
631
+ *
632
+ * @return the command's component
633
+ */
634
+ protected requireComponent( command: string ): ComponentBase {
635
+ const component = this.getComponent( command );
636
+
637
+ if ( ! component ) {
638
+ return this.error( `\`${ command }\` has no component.` );
639
+ }
640
+
641
+ return component;
642
+ }
643
+
644
+ /**
645
+ * @param component A component, or its namespace.
646
+ *
647
+ * @return the component
648
+ */
649
+ private componentOf( component: ComponentBase | string ): ComponentBase {
650
+ if ( "string" !== typeof component ) {
651
+ return component;
652
+ }
653
+
654
+ const registered = $e.components.getByNamespace( component );
655
+
656
+ if ( ! registered ) {
657
+ return this.error( `'${ component }' component is not exist.` );
658
+ }
659
+
660
+ return registered;
661
+ }
662
+ }
663
+
664
+ /**
665
+ * `$e.commands`: commands by name ('component/command'), each run with its component's dependency, hooks and trace.
666
+ * `$e.commandsInternal` and `$e.routes` are commands too.
667
+ */
668
+ export default class Commands<TEntry extends CommandEntry = CommandClass> extends CommandsBase<TEntry> {
669
+ public static getName(): string {
670
+ return "ZenFlux/Commands/Core/Commands";
671
+ }
672
+
673
+ /**
674
+ * Runs a command, by a name known at runtime (`$e.run()` takes the app's names, typed).
675
+ *
676
+ * @param command
677
+ * @param args
678
+ *
679
+ * @return results
680
+ */
681
+ public run( command: string, args?: CommandArgs ): CommandsRunResult {
682
+ return this.runCommand( command, args );
683
+ }
684
+ }