@zenflux/commands 0.0.1 → 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.
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "author": "Leonid Vinikov <leonidvinikov@gmail.com> (https://github.com/iNewLegend)",
5
5
  "description": "$e: Elementor's web-cli as a package. Components that register commands, routes, hooks, shortcuts and a store each (a reducer's state), run by name ($e.run( 'component/command', args )). @zenflux/react-commander's manager.",
6
6
  "license": "GPL-3.0-or-later",
7
- "version": "0.0.1",
7
+ "version": "0.0.2",
8
8
  "type": "module",
9
9
  "sideEffects": false,
10
10
  "files": [
@@ -21,5 +21,8 @@
21
21
  },
22
22
  "publishConfig": {
23
23
  "access": "public"
24
+ },
25
+ "dependencies": {
26
+ "@zenflux/core": "0.2.0"
24
27
  }
25
28
  }
package/readme.md CHANGED
@@ -36,5 +36,7 @@ $e.run( "counter/add", { by: 2 } );
36
36
  - `$e.routes`, `$e.shortcuts`, and `$e.devTools` (with `isDebug`) as Elementor's.
37
37
  - `withInstances( config )` adds a slice to a component's store for the state of its instances, each by its unique name (`patchInstance()`, `removeInstance()`, `getInstance()`, `getInstances()`); `instancesStore()` is a store of that slice alone. @zenflux/react-commander keeps its components' state there.
38
38
  - A component's store is a reducer's state and nothing more: `defaultStore()` gives `{ reducer, actions, selectors }` (`valueStore( { ... } )` makes one of plain values), `select( component.store )` binds the selectors, `dispatch( component.store )` the action creators, `subscribe( listener, component.store )` hears each change. An action that changes nothing tells no one. No dependency: @zenflux/react-commander's `useSelect()` draws a component again as a store it read changes.
39
+ - Every class of `$e` extends @zenflux/core's `InitializeBase` and names itself, `static getName()` with its full name (`ZenFlux/Commands/Modules/CommandBase`); an app's component or command may name itself the same way, or keeps its base's name. `instanceof` between two copies of a class (two bundles) matches by that name.
40
+ - What `$e` writes to the console (a command or a hook's callback that failed, a warning) goes through `this.logger`, @zenflux/core's logger of the class by its name, made as it first writes: core's level (`LOGGER_LOG_LEVEL`) and output subscribers hold for it.
39
41
 
40
42
  GPL-3.0-or-later, the license of Elementor, whose web-cli it ports (LICENSE).
package/src/api.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  /// <reference path="./env.d.ts" />
2
2
 
3
+ import { InitializeBase } from "@zenflux/core/src/bases/initialize-base";
4
+
3
5
  /* Alphabetical order */
4
6
  import CommandBase from "./modules/command-base";
5
7
  import CommandInternalBase from "./modules/command-internal-base";
@@ -58,7 +60,11 @@ const DEFAULT_CONFIG: Required<APIConfig> = {
58
60
  storePrefix: "zenflux",
59
61
  };
60
62
 
61
- export default class API {
63
+ export default class API extends InitializeBase {
64
+ public static getName(): string {
65
+ return "ZenFlux/Commands/API";
66
+ }
67
+
62
68
  public config: Required<APIConfig>;
63
69
  public components: Components;
64
70
  public commands: Commands;
@@ -86,6 +92,8 @@ export default class API {
86
92
  * @param config
87
93
  */
88
94
  public constructor( config: APIConfig = {} ) {
95
+ super();
96
+
89
97
  setAPI( this );
90
98
 
91
99
  this.config = { ...DEFAULT_CONFIG, ...config };
@@ -1,6 +1,10 @@
1
1
  import Commands from "./commands";
2
2
 
3
3
  export default class CommandsInternal extends Commands {
4
+ public static getName(): string {
5
+ return "ZenFlux/Commands/Core/CommandsInternal";
6
+ }
7
+
4
8
  public getCall(): string {
5
9
  return "$e.internal";
6
10
  }
@@ -1,5 +1,4 @@
1
1
  import CommandBase from "@zenflux/commands/src/modules/command-base";
2
- import Console from "@zenflux/commands/src/utils/console";
3
2
  import HookBreak from "@zenflux/commands/src/modules/hook-break";
4
3
  import Module from "@zenflux/commands/src/modules/module";
5
4
 
@@ -65,6 +64,10 @@ const isOwnName = ( namespace: string, name: string ): boolean => {
65
64
  * way (`run()`, `to()`), through `runCommand()`.
66
65
  */
67
66
  export class CommandsBase<TEntry extends CommandEntry = CommandEntry> extends Module<CommandsEvents> {
67
+ public static getName(): string {
68
+ return "ZenFlux/Commands/Core/CommandsBase";
69
+ }
70
+
68
71
  /**
69
72
  * The commands running now, of every kind, first to last.
70
73
  */
@@ -536,7 +539,10 @@ export class CommandsBase<TEntry extends CommandEntry = CommandEntry> extends Mo
536
539
  public catchApply<TError>( e: TError, instance: RunnableCommand ): void {
537
540
  instance.onCatchApply( e );
538
541
 
539
- Console.error( e );
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
+ }
540
546
 
541
547
  this.trigger( "run:catch", instance.component, instance.command, instance.args, e );
542
548
  }
@@ -660,6 +666,10 @@ export class CommandsBase<TEntry extends CommandEntry = CommandEntry> extends Mo
660
666
  * `$e.commandsInternal` and `$e.routes` are commands too.
661
667
  */
662
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
+
663
673
  /**
664
674
  * Runs a command, by a name known at runtime (`$e.run()` takes the app's names, typed).
665
675
  *
@@ -13,6 +13,10 @@ const isOfSameClass = <TComponent extends ComponentBase>( registered: ComponentB
13
13
  registered.constructor === component.constructor;
14
14
 
15
15
  export default class Components extends Module {
16
+ public static getName(): string {
17
+ return "ZenFlux/Commands/Core/Components";
18
+ }
19
+
16
20
  public components: { [ namespace: string ]: ComponentBase | undefined };
17
21
  public activeComponents: { [ namespace: string ]: true };
18
22
 
@@ -1,4 +1,5 @@
1
- import Console from "@zenflux/commands/src/utils/console";
1
+ import { InitializeBase } from "@zenflux/core/src/bases/initialize-base";
2
+
2
3
  import HookBreak from "@zenflux/commands/src/modules/hook-break";
3
4
  import { $e } from "@zenflux/commands/src/instance";
4
5
 
@@ -47,7 +48,11 @@ export interface HookCallbacksByEvent {
47
48
  /**
48
49
  * The hooks of one type (data or UI): callbacks by event, then command, then container type ('all' for any).
49
50
  */
50
- export default class HooksBase {
51
+ export default class HooksBase extends InitializeBase {
52
+ public static getName(): string {
53
+ return "ZenFlux/Commands/Core/Hooks/HooksBase";
54
+ }
55
+
51
56
  /**
52
57
  * Current command.
53
58
  */
@@ -71,6 +76,8 @@ export default class HooksBase {
71
76
  public callbacksFlatList: HookCallbacksById;
72
77
 
73
78
  public constructor() {
79
+ super();
80
+
74
81
  this.current = "";
75
82
 
76
83
  this.usedIds = [];
@@ -391,7 +398,7 @@ export default class HooksBase {
391
398
  throw e;
392
399
  }
393
400
 
394
- Console.error( e );
401
+ this.logger.error( this.run, `'${ event }' callback '${ callback.id }' failed:`, e );
395
402
  }
396
403
  }
397
404
 
@@ -12,6 +12,10 @@ import type { CommandArgs, HookReturn } from "@zenflux/commands/src/types";
12
12
  * for their promises), 'catch' when it failed.
13
13
  */
14
14
  export default class Data extends HooksBase {
15
+ public static getName(): string {
16
+ return "ZenFlux/Commands/Core/Hooks/Data";
17
+ }
18
+
15
19
  public constructor() {
16
20
  super();
17
21
 
@@ -8,6 +8,10 @@ import type { CommandArgs, HookReturn } from "@zenflux/commands/src/types";
8
8
  * UI hooks: 'before' the command runs, 'after' it ran, 'catch' when it failed.
9
9
  */
10
10
  export default class Ui extends HooksBase {
11
+ public static getName(): string {
12
+ return "ZenFlux/Commands/Core/Hooks/UI";
13
+ }
14
+
11
15
  public constructor() {
12
16
  super();
13
17
 
package/src/core/hooks.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { InitializeBase } from "@zenflux/core/src/bases/initialize-base";
2
+
1
3
  import HooksData from "./hooks/data";
2
4
  import HooksUI from "./hooks/ui";
3
5
 
@@ -6,10 +8,18 @@ import type { HookCallback, HookCallbacksByEvent, HookCallbacksById } from "./ho
6
8
  import type { HookType, RunnableHook } from "@zenflux/commands/src/modules/hook-base";
7
9
  import type { CommandArgs, HookReturn } from "@zenflux/commands/src/types";
8
10
 
9
- export default class Hooks {
11
+ export default class Hooks extends InitializeBase {
12
+ public static getName(): string {
13
+ return "ZenFlux/Commands/Core/Hooks";
14
+ }
15
+
10
16
  public data = new HooksData();
11
17
  public ui = new HooksUI();
12
18
 
19
+ public constructor() {
20
+ super();
21
+ }
22
+
13
23
  /**
14
24
  * Activate all hooks.
15
25
  */
@@ -25,6 +25,10 @@ export interface RouteState {
25
25
  * A route opens its component first (`component.open()`).
26
26
  */
27
27
  export default class Routes extends Commands<RegisteredCallback> {
28
+ public static getName(): string {
29
+ return "ZenFlux/Commands/Core/Routes";
30
+ }
31
+
28
32
  public savedStates: { [ container: string ]: Partial<RouteState> };
29
33
  public historyPerComponent: { [ namespaceRoot: string ]: RouteState[] };
30
34
 
@@ -1,4 +1,5 @@
1
- import Console from "@zenflux/commands/src/utils/console";
1
+ import { InitializeBase } from "@zenflux/core/src/bases/initialize-base";
2
+
2
3
  import { $e } from "@zenflux/commands/src/instance";
3
4
 
4
5
  const isMac = "undefined" !== typeof navigator && navigator.userAgent.includes( "Macintosh" );
@@ -92,7 +93,11 @@ export interface ShortcutConfig extends Omit<ShortcutHandler, "callback"> {
92
93
  * `$e.shortcuts`: keys ('ctrl+shift+z', 'esc', 'ctrl+comma', 'ctrl+s,ctrl+enter'; ctrl is cmd on a Mac) to handlers, the ones in the
93
94
  * active component's scope first.
94
95
  */
95
- export default class Shortcuts {
96
+ export default class Shortcuts extends InitializeBase {
97
+ public static getName(): string {
98
+ return "ZenFlux/Commands/Core/Shortcuts";
99
+ }
100
+
96
101
  /**
97
102
  * By `event.code`, the key's place on the keyboard.
98
103
  */
@@ -104,6 +109,8 @@ export default class Shortcuts {
104
109
  * @param target Window to listen to, and to the frames in it as they take the focus (their keys do not reach it).
105
110
  */
106
111
  public constructor( target: Window ) {
112
+ super();
113
+
107
114
  this.specialKeys = {
108
115
  Enter: "enter",
109
116
  NumpadEnter: "enter",
@@ -230,7 +237,7 @@ export default class Shortcuts {
230
237
  }
231
238
 
232
239
  if ( 1 < filteredHandlers.length && $e.config.isDebug ) {
233
- Console.warn( "Multiple handlers for shortcut.", filteredHandlers, event );
240
+ this.logger.warn( this.handle, "Multiple handlers for shortcut.", filteredHandlers, event );
234
241
  }
235
242
 
236
243
  event.preventDefault();
@@ -1,3 +1,5 @@
1
+ import { InitializeBase } from "@zenflux/core/src/bases/initialize-base";
2
+
1
3
  import { CommandsBase } from "@zenflux/commands/src/core/commands";
2
4
  import { $e } from "@zenflux/commands/src/instance";
3
5
  import { isCommandClass } from "@zenflux/commands/src/modules/command-infra";
@@ -65,7 +67,11 @@ export interface HookLog {
65
67
  * names, and its result with `getInfo().secretResult`. The app's REST requests too, under the command that made them
66
68
  * (`request()`).
67
69
  */
68
- class Log {
70
+ class Log extends InitializeBase {
71
+ public static getName(): string {
72
+ return "ZenFlux/Commands/Extras/Log";
73
+ }
74
+
69
75
  /**
70
76
  * Off: nothing is logged (`$e.devTools.log.enabled = false`).
71
77
  */
@@ -267,12 +273,16 @@ class Log {
267
273
  };
268
274
  }
269
275
 
270
- public warn( ...args: Parameters<typeof console.warn> ): void {
271
- console.warn( "$e:", ...args );
276
+ public constructor() {
277
+ super();
278
+ }
279
+
280
+ public warn<TParams extends unknown[]>( message: string, ...params: TParams ): void {
281
+ this.logger.warn( this.warn, message, ...params );
272
282
  }
273
283
 
274
284
  public error<TError>( error: TError ): void {
275
- console.error( "$e:", error );
285
+ this.logger.error( this.error, "failed:", error );
276
286
  }
277
287
  }
278
288
 
@@ -314,10 +324,16 @@ export interface HookRow {
314
324
  * `$e.devTools`, with `isDebug`, as Elementor's dev tools: the log of what runs (`log`), and what is registered, as
315
325
  * console tables that the functions also return.
316
326
  */
317
- export default class DevTools {
327
+ export default class DevTools extends InitializeBase {
328
+ public static getName(): string {
329
+ return "ZenFlux/Commands/Extras/DevTools";
330
+ }
331
+
318
332
  public log: Log;
319
333
 
320
334
  public constructor() {
335
+ super();
336
+
321
337
  this.log = new Log();
322
338
 
323
339
  this.log.listen( this.getSystems() );
@@ -37,8 +37,8 @@ const ownArgument = <TObject extends object>( args: TObject, property: string ):
37
37
  };
38
38
 
39
39
  export default class ArgsObject<TArgs extends object = object> extends InstanceType {
40
- public static getInstanceType(): string {
41
- return "ArgsObject";
40
+ public static getName(): string {
41
+ return "ZenFlux/Commands/Modules/ArgsObject";
42
42
  }
43
43
 
44
44
  public args: TArgs;
@@ -15,8 +15,8 @@ export default abstract class CommandBase<
15
15
  TResult = void,
16
16
  TComponent extends ComponentBase = ComponentBase,
17
17
  > extends CommandInfra<TArgs, TResult, TComponent> {
18
- public static getInstanceType(): string {
19
- return "CommandBase";
18
+ public static getName(): string {
19
+ return "ZenFlux/Commands/Modules/CommandBase";
20
20
  }
21
21
 
22
22
  public onBeforeRun( args: TArgs ): void {
@@ -9,8 +9,8 @@ const isCallbackClass = ( value: Function ): value is typeof CommandCallbackBase
9
9
  * To support pure callbacks in the API (core/commands.ts), to ensure they have registered with the proper context.
10
10
  */
11
11
  export default class CommandCallbackBase extends CommandBase<CommandArgs> {
12
- public static getInstanceType(): string {
13
- return "CommandCallbackBase";
12
+ public static getName(): string {
13
+ return "ZenFlux/Commands/Modules/CommandCallbackBase";
14
14
  }
15
15
 
16
16
  /**
@@ -47,7 +47,7 @@ export interface RunnableCommand {
47
47
  export interface CommandClass {
48
48
  new ( args: never ): RunnableCommand;
49
49
  registerConfig: Readonly<RegisterConfig> | null;
50
- getInstanceType(): string;
50
+ getName(): string;
51
51
  getInfo(): CommandInfo;
52
52
  getRegisterConfig(): Readonly<RegisterConfig>;
53
53
  getCommand(): string;
@@ -61,7 +61,7 @@ export interface CommandClass {
61
61
  * @return whether it is a command class (it names its type)
62
62
  */
63
63
  export const isCommandClass = ( value: Function ): value is CommandClass =>
64
- "getInstanceType" in value && "function" === typeof value.getInstanceType;
64
+ "getName" in value && "function" === typeof value.getName && "getInfo" in value;
65
65
 
66
66
  /**
67
67
  * A command: `apply( args )` does it. `TArgs` are its args (checked by `$e.run()`), `TResult` what `apply()` returns,
@@ -77,8 +77,8 @@ export default abstract class CommandInfra<
77
77
  */
78
78
  public static registerConfig: Readonly<RegisterConfig> | null = null;
79
79
 
80
- public static getInstanceType(): string {
81
- return "CommandInfra";
80
+ public static getName(): string {
81
+ return "ZenFlux/Commands/Modules/CommandInfra";
82
82
  }
83
83
 
84
84
  /**
@@ -162,7 +162,7 @@ export default abstract class CommandInfra<
162
162
  *
163
163
  * @param args
164
164
  */
165
- public initialize( _args: TArgs ): void {}
165
+ public initialize( _args?: TArgs ): void {}
166
166
 
167
167
  /**
168
168
  * Validate command arguments.
@@ -13,7 +13,7 @@ export default abstract class CommandInternalBase<
13
13
  TResult = void,
14
14
  TComponent extends ComponentBase = ComponentBase,
15
15
  > extends CommandBase<TArgs, TResult, TComponent> {
16
- public static getInstanceType(): string {
17
- return "CommandInternalBase";
16
+ public static getName(): string {
17
+ return "ZenFlux/Commands/Modules/CommandInternalBase";
18
18
  }
19
19
  }
@@ -119,6 +119,10 @@ interface ComponentBase<TStore extends StoreConfig = StoreConfig> {
119
119
  */
120
120
 
121
121
  abstract class ComponentBase<TStore extends StoreConfig = StoreConfig> extends Module<ComponentEvents> {
122
+ public static getName(): string {
123
+ return "ZenFlux/Commands/Modules/ComponentBase";
124
+ }
125
+
122
126
  /**
123
127
  * Whether it is open: set as its first route runs (`open()`), and by `close()`.
124
128
  */
@@ -1,3 +1,5 @@
1
+ import { InitializeBase } from "@zenflux/core/src/bases/initialize-base";
2
+
1
3
  import { $e } from "@zenflux/commands/src/instance";
2
4
 
3
5
  import type { CommandArgs, HookArgs, HookReturn } from "@zenflux/commands/src/types";
@@ -28,7 +30,11 @@ export interface RunnableHook {
28
30
  * (`getCommand()` returns it), which types the args its `apply()` gets (HookArgs); `TValue` is what it gets after them:
29
31
  * the command's result for an 'after' hook, the error it failed with for a 'catch' hook, nothing before.
30
32
  */
31
- export default abstract class HookBase<TCommand extends string = string, TValue = void> {
33
+ export default abstract class HookBase<TCommand extends string = string, TValue = void> extends InitializeBase {
34
+ public static getName(): string {
35
+ return "ZenFlux/Commands/Modules/HookBase";
36
+ }
37
+
32
38
  /**
33
39
  * Callback type, eg ( hook, event ).
34
40
  */
@@ -45,6 +51,9 @@ export default abstract class HookBase<TCommand extends string = string, TValue
45
51
  public id: string;
46
52
 
47
53
  public constructor() {
54
+ // It runs its own initialize(), with its arguments.
55
+ super( false );
56
+
48
57
  this.initialize();
49
58
 
50
59
  this.type = this.getType();
@@ -9,6 +9,10 @@ import type { HookResult } from "@zenflux/commands/src/types";
9
9
  * returns).
10
10
  */
11
11
  export abstract class After<TCommand extends string = string> extends Base<TCommand, HookResult<TCommand>> {
12
+ public static getName(): string {
13
+ return "ZenFlux/Commands/Modules/Hooks/Data/After";
14
+ }
15
+
12
16
  public register(): void {
13
17
  $e.hooks.registerDataAfter( this );
14
18
  }
@@ -3,6 +3,10 @@ import HookBase from "@zenflux/commands/src/modules/hook-base";
3
3
  import type { HookType } from "@zenflux/commands/src/modules/hook-base";
4
4
 
5
5
  export abstract class Base<TCommand extends string = string, TValue = void> extends HookBase<TCommand, TValue> {
6
+ public static getName(): string {
7
+ return "ZenFlux/Commands/Modules/Hooks/Data/Base";
8
+ }
9
+
6
10
  public getType(): HookType {
7
11
  return "data";
8
12
  }
@@ -6,6 +6,10 @@ import { $e } from "@zenflux/commands/src/instance";
6
6
  * When the command failed, with what it threw or rejected with (a data command's: a BaseError).
7
7
  */
8
8
  export abstract class Catch<TCommand extends string = string, TError = Error> extends Base<TCommand, TError> {
9
+ public static getName(): string {
10
+ return "ZenFlux/Commands/Modules/Hooks/Data/Catch";
11
+ }
12
+
9
13
  public register(): void {
10
14
  $e.hooks.registerDataCatch( this );
11
15
  }
@@ -6,6 +6,10 @@ import { $e } from "@zenflux/commands/src/instance";
6
6
  * Before the command applies: false stops it (without an error).
7
7
  */
8
8
  export abstract class Dependency<TCommand extends string = string> extends Base<TCommand> {
9
+ public static getName(): string {
10
+ return "ZenFlux/Commands/Modules/Hooks/Data/Dependency";
11
+ }
12
+
9
13
  public register(): void {
10
14
  $e.hooks.registerDataDependency( this );
11
15
  }
@@ -8,6 +8,10 @@ import type { HookResult } from "@zenflux/commands/src/types";
8
8
  * After the command ran, with its result (an async command's, once it resolved).
9
9
  */
10
10
  export abstract class After<TCommand extends string = string> extends Base<TCommand, HookResult<TCommand>> {
11
+ public static getName(): string {
12
+ return "ZenFlux/Commands/Modules/Hooks/UI/After";
13
+ }
14
+
11
15
  public register(): void {
12
16
  $e.hooks.registerUIAfter( this );
13
17
  }
@@ -3,6 +3,10 @@ import HookBase from "@zenflux/commands/src/modules/hook-base";
3
3
  import type { HookType } from "@zenflux/commands/src/modules/hook-base";
4
4
 
5
5
  export abstract class Base<TCommand extends string = string, TValue = void> extends HookBase<TCommand, TValue> {
6
+ public static getName(): string {
7
+ return "ZenFlux/Commands/Modules/Hooks/UI/Base";
8
+ }
9
+
6
10
  public getType(): HookType {
7
11
  return "ui";
8
12
  }
@@ -6,6 +6,10 @@ import { $e } from "@zenflux/commands/src/instance";
6
6
  * Before the command runs.
7
7
  */
8
8
  export abstract class Before<TCommand extends string = string> extends Base<TCommand> {
9
+ public static getName(): string {
10
+ return "ZenFlux/Commands/Modules/Hooks/UI/Before";
11
+ }
12
+
9
13
  public register(): void {
10
14
  $e.hooks.registerUIBefore( this );
11
15
  }
@@ -6,6 +6,10 @@ import { $e } from "@zenflux/commands/src/instance";
6
6
  * When the command failed, with what it threw or rejected with.
7
7
  */
8
8
  export abstract class Catch<TCommand extends string = string, TError = Error> extends Base<TCommand, TError> {
9
+ public static getName(): string {
10
+ return "ZenFlux/Commands/Modules/Hooks/UI/Catch";
11
+ }
12
+
9
13
  public register(): void {
10
14
  $e.hooks.registerUICatch( this );
11
15
  }
@@ -1,8 +1,10 @@
1
+ import { InitializeBase } from "@zenflux/core/src/bases/initialize-base";
2
+
1
3
  /**
2
4
  * A class that names its type, whichever bundle it comes from.
3
5
  */
4
6
  interface NamedType {
5
- getInstanceType(): string;
7
+ getName(): string;
6
8
  }
7
9
 
8
10
  /**
@@ -15,7 +17,7 @@ interface TypedObject {
15
17
  }
16
18
 
17
19
  const namesType = ( value: Function | undefined ): value is Function & NamedType =>
18
- !! value && "getInstanceType" in value && "function" === typeof value.getInstanceType;
20
+ !! value && "getName" in value && "function" === typeof value.getName;
19
21
 
20
22
  /**
21
23
  * @param target
@@ -29,14 +31,14 @@ const isTypedObject = ( target: object ): target is TypedObject =>
29
31
  /**
30
32
  * `instanceof` that also holds between copies of a class: every bundle that includes this package has its own
31
33
  * classes, so a command class from one bundle is not an instance of another bundle's CommandBase by prototype.
32
- * Classes name their type with `getInstanceType()`, and an object matches a class by that name too.
34
+ * Classes name their type with `getName()` (`ObjectBase`'s), and an object matches a class by that name too.
33
35
  */
34
36
  /**
35
37
  * The types an instance of a class records as it is made (its `instanceTypes`), by class.
36
38
  */
37
39
  const instanceTypesOf = new WeakMap<Function, string[]>();
38
40
 
39
- export default class InstanceType {
41
+ export default class InstanceType extends InitializeBase {
40
42
  public static [ Symbol.hasInstance ]( target: object ): boolean {
41
43
  // What `super[ Symbol.hasInstance ]` is for a class that extends nothing: the prototype chain.
42
44
  let result = Function.prototype[ Symbol.hasInstance ].call( this, target );
@@ -52,19 +54,19 @@ export default class InstanceType {
52
54
  }
53
55
 
54
56
  if ( ! result ) {
55
- if ( this.getInstanceType() === target.constructor.getInstanceType() ) {
57
+ if ( this.getName() === target.constructor.getName() ) {
56
58
  result = true;
57
59
  }
58
60
  }
59
61
 
60
- if ( result && ! target.instanceTypes.includes( this.getInstanceType() ) ) {
61
- target.instanceTypes.push( this.getInstanceType() );
62
+ if ( result && ! target.instanceTypes.includes( this.getName() ) ) {
63
+ target.instanceTypes.push( this.getName() );
62
64
  }
63
65
  }
64
66
 
65
67
  if ( ! result && target ) {
66
68
  // Check if the given 'target' is an instance of known types.
67
- result = Array.isArray( target.instanceTypes ) && target.instanceTypes.includes( this.getInstanceType() );
69
+ result = Array.isArray( target.instanceTypes ) && target.instanceTypes.includes( this.getName() );
68
70
  }
69
71
 
70
72
  return result;
@@ -76,11 +78,14 @@ export default class InstanceType {
76
78
  *
77
79
  * @return its type's name
78
80
  */
79
- public static getInstanceType(): string {
80
- return "BaseInstanceType";
81
+ public static getName(): string {
82
+ return "ZenFlux/Commands/Modules/InstanceType";
81
83
  }
82
84
 
83
85
  public constructor() {
86
+ // It runs its own initialize(), with its arguments.
87
+ super( false );
88
+
84
89
  // The types depend on the class alone: found once for it, a copy for each instance after (a command is made
85
90
  // for every run, and the walk below costs most of its making).
86
91
  const known = instanceTypesOf.get( new.target );
@@ -1,3 +1,5 @@
1
+ import { InitializeBase } from "@zenflux/core/src/bases/initialize-base";
2
+
1
3
  import { deepMerge, isJsonObject, isJsonObjectDeep } from "@zenflux/commands/src/utils/object";
2
4
 
3
5
  import type { JsonObject, JsonValue } from "@zenflux/commands/src/utils/object";
@@ -30,12 +32,18 @@ export interface ModuleEvents {
30
32
  * (`getDefaultSettings()`, merged with the first argument when it is a plain object of JSON values) and the 'init'
31
33
  * event (`onInit()`, then its listeners).
32
34
  */
33
- export default class Module<TEvents extends ModuleEvents & ModuleEventMap<TEvents> = ModuleEvents> {
35
+ export default class Module<TEvents extends ModuleEvents & ModuleEventMap<TEvents> = ModuleEvents> extends InitializeBase {
36
+ public static getName(): string {
37
+ return "ZenFlux/Commands/Modules/Module";
38
+ }
39
+
34
40
  #events: { [ TEvent in keyof TEvents ]?: TEvents[ TEvent ][] } = {};
35
41
 
36
42
  #settings: JsonObject = {};
37
43
 
38
44
  public constructor( args?: object ) {
45
+ super();
46
+
39
47
  this.__construct( args );
40
48
 
41
49
  this.#settings = deepMerge( this.getDefaultSettings(), args && isJsonObjectDeep( args ) ? args : {} );
@@ -1,19 +0,0 @@
1
- import HookBreak from "@zenflux/commands/src/modules/hook-break";
2
-
3
- export default class Console {
4
- /**
5
- * @param message What failed: an error, or whatever a command threw or rejected with.
6
- */
7
- public static error<TMessage>( message: TMessage ): void {
8
- // A 'Hook-Break' is how a dependency hook stops a command, not an error.
9
- if ( ! ( message instanceof HookBreak ) ) {
10
-
11
- console.error( message );
12
- }
13
- }
14
-
15
- public static warn( ...args: Parameters<typeof console.warn> ): void {
16
-
17
- console.warn( ...args );
18
- }
19
- }