@zenflux/core 0.0.1-dev.2 → 0.1.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 (121) hide show
  1. package/package.json +30 -48
  2. package/src/bases/controller-base.ts +96 -0
  3. package/src/bases/index.ts +2 -0
  4. package/src/bases/object-base.ts +83 -0
  5. package/src/clients/http.ts +48 -37
  6. package/src/command-bases/command-base.ts +35 -37
  7. package/src/command-bases/command-internal.ts +5 -7
  8. package/src/command-bases/command-public.ts +5 -6
  9. package/src/command-bases/command-restful.ts +55 -0
  10. package/src/command-bases/index.ts +5 -5
  11. package/src/errors/command-already-registered.ts +6 -5
  12. package/src/errors/command-not-found.ts +6 -4
  13. package/src/errors/controller-already-registered.ts +6 -5
  14. package/src/errors/controller-already-set.ts +8 -5
  15. package/src/errors/force-method-implementation.ts +23 -0
  16. package/src/errors/index-public.ts +1 -0
  17. package/src/errors/index.ts +5 -5
  18. package/src/exports-index.ts +13 -0
  19. package/src/exports.ts +67 -9
  20. package/src/index.ts +12 -3
  21. package/src/interfaces/commands.ts +3 -3
  22. package/src/interfaces/config.ts +10 -3
  23. package/src/interfaces/index.ts +5 -6
  24. package/src/interfaces/logger.ts +18 -0
  25. package/src/interfaces/{data.ts → restful.ts} +10 -10
  26. package/src/{manager-bases → managers}/commands.ts +52 -61
  27. package/src/managers/controllers.ts +40 -0
  28. package/src/managers/export.ts +30 -0
  29. package/src/managers/index.ts +5 -28
  30. package/src/managers/internal.ts +11 -0
  31. package/src/{manager-bases/data.ts → managers/restful.ts} +25 -24
  32. package/LICENSE +0 -21
  33. package/README.md +0 -2
  34. package/dist/es/clients/http.d.ts +0 -31
  35. package/dist/es/clients/http.d.ts.map +0 -1
  36. package/dist/es/command-bases/command-base.d.ts +0 -27
  37. package/dist/es/command-bases/command-base.d.ts.map +0 -1
  38. package/dist/es/command-bases/command-data.d.ts +0 -18
  39. package/dist/es/command-bases/command-data.d.ts.map +0 -1
  40. package/dist/es/command-bases/command-internal.d.ts +0 -10
  41. package/dist/es/command-bases/command-internal.d.ts.map +0 -1
  42. package/dist/es/command-bases/command-public.d.ts +0 -10
  43. package/dist/es/command-bases/command-public.d.ts.map +0 -1
  44. package/dist/es/command-bases/index.d.ts +0 -8
  45. package/dist/es/command-bases/index.d.ts.map +0 -1
  46. package/dist/es/core/controller.d.ts +0 -36
  47. package/dist/es/core/controller.d.ts.map +0 -1
  48. package/dist/es/core/index.d.ts +0 -3
  49. package/dist/es/core/index.d.ts.map +0 -1
  50. package/dist/es/core/object-base.d.ts +0 -15
  51. package/dist/es/core/object-base.d.ts.map +0 -1
  52. package/dist/es/errors/command-already-registered.d.ts +0 -9
  53. package/dist/es/errors/command-already-registered.d.ts.map +0 -1
  54. package/dist/es/errors/command-not-found.d.ts +0 -8
  55. package/dist/es/errors/command-not-found.d.ts.map +0 -1
  56. package/dist/es/errors/controller-already-registered.d.ts +0 -9
  57. package/dist/es/errors/controller-already-registered.d.ts.map +0 -1
  58. package/dist/es/errors/controller-already-set.d.ts +0 -8
  59. package/dist/es/errors/controller-already-set.d.ts.map +0 -1
  60. package/dist/es/errors/force-method.d.ts +0 -12
  61. package/dist/es/errors/force-method.d.ts.map +0 -1
  62. package/dist/es/errors/index.d.ts +0 -6
  63. package/dist/es/errors/index.d.ts.map +0 -1
  64. package/dist/es/exports.d.ts +0 -12
  65. package/dist/es/exports.d.ts.map +0 -1
  66. package/dist/es/index.d.ts +0 -6
  67. package/dist/es/index.d.ts.map +0 -1
  68. package/dist/es/initializer.d.ts +0 -22
  69. package/dist/es/initializer.d.ts.map +0 -1
  70. package/dist/es/interfaces/commands.d.ts +0 -14
  71. package/dist/es/interfaces/commands.d.ts.map +0 -1
  72. package/dist/es/interfaces/config.d.ts +0 -15
  73. package/dist/es/interfaces/config.d.ts.map +0 -1
  74. package/dist/es/interfaces/data.d.ts +0 -19
  75. package/dist/es/interfaces/data.d.ts.map +0 -1
  76. package/dist/es/interfaces/index.d.ts +0 -9
  77. package/dist/es/interfaces/index.d.ts.map +0 -1
  78. package/dist/es/interfaces/managers.d.ts +0 -14
  79. package/dist/es/interfaces/managers.d.ts.map +0 -1
  80. package/dist/es/interfaces/object-base.d.ts +0 -11
  81. package/dist/es/interfaces/object-base.d.ts.map +0 -1
  82. package/dist/es/manager-bases/commands.d.ts +0 -76
  83. package/dist/es/manager-bases/commands.d.ts.map +0 -1
  84. package/dist/es/manager-bases/controllers.d.ts +0 -19
  85. package/dist/es/manager-bases/controllers.d.ts.map +0 -1
  86. package/dist/es/manager-bases/data.d.ts +0 -26
  87. package/dist/es/manager-bases/data.d.ts.map +0 -1
  88. package/dist/es/manager-bases/index.d.ts +0 -8
  89. package/dist/es/manager-bases/index.d.ts.map +0 -1
  90. package/dist/es/manager-bases/internal.d.ts +0 -10
  91. package/dist/es/manager-bases/internal.d.ts.map +0 -1
  92. package/dist/es/managers/index.d.ts +0 -16
  93. package/dist/es/managers/index.d.ts.map +0 -1
  94. package/dist/es/modules/index.d.ts +0 -2
  95. package/dist/es/modules/index.d.ts.map +0 -1
  96. package/dist/es/modules/logger.d.ts +0 -118
  97. package/dist/es/modules/logger.d.ts.map +0 -1
  98. package/dist/es/utils/index.d.ts +0 -3
  99. package/dist/es/utils/index.d.ts.map +0 -1
  100. package/dist/es/utils/object.d.ts +0 -7
  101. package/dist/es/utils/object.d.ts.map +0 -1
  102. package/dist/es/utils/rgb.d.ts +0 -7
  103. package/dist/es/utils/rgb.d.ts.map +0 -1
  104. package/dist/es/zenflux-core.js +0 -2235
  105. package/src/command-bases/command-data.ts +0 -54
  106. package/src/core/controller.ts +0 -61
  107. package/src/core/index.ts +0 -2
  108. package/src/core/object-base.ts +0 -46
  109. package/src/errors/force-method.ts +0 -22
  110. package/src/initializer.ts +0 -56
  111. package/src/interfaces/managers.ts +0 -16
  112. package/src/interfaces/object-base.ts +0 -12
  113. package/src/manager-bases/controllers.ts +0 -37
  114. package/src/manager-bases/index.ts +0 -7
  115. package/src/manager-bases/internal.ts +0 -13
  116. package/src/modules/index.ts +0 -1
  117. package/src/modules/logger.ts +0 -459
  118. package/src/utils/index.ts +0 -2
  119. package/src/utils/object.ts +0 -18
  120. package/src/utils/rgb.ts +0 -33
  121. package/types/index.d.ts +0 -6
@@ -1,12 +1,13 @@
1
1
  /**
2
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
2
+ * @author Leonid Vinikov <leonidvinikov@gmail.com>
3
3
  */
4
- import CommandBase from "../command-bases/command-base";
4
+ import type { CommandBase } from "@z-core/command-bases/command-base";
5
5
 
6
+ /**
7
+ * @internal
8
+ */
6
9
  export class CommandAlreadyRegistered extends Error {
7
- constructor( command: typeof CommandBase ) {
10
+ public constructor( command: typeof CommandBase ) {
8
11
  super( `Command: '${ command.getName() }' is already registered` );
9
12
  }
10
13
  }
11
-
12
- export default CommandAlreadyRegistered;
@@ -1,10 +1,12 @@
1
1
  /**
2
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
2
+ * @author Leonid Vinikov <leonidvinikov@gmail.com>
3
+ */
4
+
5
+ /**
6
+ * @internal
3
7
  */
4
8
  export class CommandNotFound extends Error {
5
- constructor( command: string ) {
9
+ public constructor( command: string ) {
6
10
  super( `Command: '${ command }' is not found` );
7
11
  }
8
12
  }
9
-
10
- export default CommandNotFound;
@@ -1,12 +1,13 @@
1
1
  /**
2
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
2
+ * @author Leonid Vinikov <leonidvinikov@gmail.com>
3
3
  */
4
- import Controller from "../core/controller";
4
+ import type { ControllerBase } from "@z-core/bases";
5
5
 
6
+ /**
7
+ * @internal
8
+ */
6
9
  export class ControllerAlreadyRegistered extends Error {
7
- constructor( controller: Controller ) {
10
+ public constructor( controller: ControllerBase ) {
8
11
  super( `Controller: '${ controller.getName() }' is already registered` );
9
12
  }
10
13
  }
11
-
12
- export default ControllerAlreadyRegistered;
@@ -1,10 +1,13 @@
1
1
  /**
2
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
2
+ * @author Leonid Vinikov <leonidvinikov@gmail.com>
3
+ */
4
+ import type { ControllerBase } from "@z-core/bases";
5
+
6
+ /**
7
+ * @internal
3
8
  */
4
9
  export class ControllerAlreadySet extends Error {
5
- constructor() {
6
- super( 'Controller already set.' );
10
+ public constructor( controller: ControllerBase ) {
11
+ super( `Controller: '${ controller.getName() }' is already set` );
7
12
  }
8
13
  }
9
-
10
- export default ControllerAlreadySet;
@@ -0,0 +1,23 @@
1
+ import type { ObjectBase } from "@z-core/bases";
2
+
3
+ /**
4
+ * @internal
5
+ */
6
+ export class ForceMethodBase extends Error {
7
+ public constructor( className: string, methodName: string ) {
8
+ super(
9
+ `ForceMethod implementation: at: '${ className }' method: '${ methodName }'`
10
+ );
11
+ }
12
+ }
13
+
14
+ /**
15
+ * @public
16
+ */
17
+ export class ForceMethodImplementation extends Error {
18
+ public constructor( context: ObjectBase | typeof ObjectBase | string, methodName: string ) {
19
+ super(
20
+ `ForceMethod implementation: at: '${ "string" === typeof context ? context : context.getName() }' method: '${ methodName }'`
21
+ );
22
+ }
23
+ }
@@ -0,0 +1 @@
1
+ export { ForceMethodImplementation } from "@z-core/errors/force-method-implementation";
@@ -1,5 +1,5 @@
1
- export { CommandAlreadyRegistered } from "./command-already-registered";
2
- export { CommandNotFound } from "./command-not-found";
3
- export { ControllerAlreadyRegistered } from "./controller-already-registered";
4
- export { ControllerAlreadySet } from './controller-already-set';
5
- export { ForceMethod } from "./force-method";
1
+ export { CommandAlreadyRegistered } from "@z-core/errors/command-already-registered";
2
+ export { CommandNotFound } from "@z-core/errors/command-not-found";
3
+ export { ControllerAlreadyRegistered } from "@z-core/errors/controller-already-registered";
4
+ export { ControllerAlreadySet } from "@z-core/errors/controller-already-set";
5
+ export { ForceMethodImplementation } from "@z-core/errors/force-method-implementation";
@@ -0,0 +1,13 @@
1
+ import * as bases from "@z-core/bases";
2
+ import * as commandBases from "@z-core/command-bases";
3
+ import * as errors from "@z-core/errors/index-public";
4
+ import * as interfaces from "@z-core/interfaces";
5
+ import * as managers from "@z-core/managers/export";
6
+
7
+ export {
8
+ bases,
9
+ commandBases,
10
+ errors,
11
+ interfaces,
12
+ managers,
13
+ };
package/src/exports.ts CHANGED
@@ -1,11 +1,69 @@
1
1
  /**
2
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
2
+ * @author Leonid Vinikov <leonidvinikov@gmail.com>
3
3
  */
4
- export * as commandBases from "./command-bases";
5
- export * as core from "./core";
6
- export * as errors from "./errors";
7
- export * as interfaces from "./interfaces";
8
- export * as managers from "./managers";
9
- export * as managerBases from "./manager-bases";
10
- export * as modules from "./modules";
11
- export * as utils from "./utils";
4
+ // @ts-ignore - TODO handle error in jest
5
+ import * as pkg from "../package.json" assert { type: "json" };
6
+
7
+ import { bases, commandBases, errors, interfaces, managers, } from "@z-core/exports-index";
8
+
9
+ declare global {
10
+ var __ZEN_CORE__IS_INITIALIZED__: boolean;
11
+ }
12
+
13
+ export const classes = {
14
+ /* eslint-disable @typescript-eslint/no-unused-vars */
15
+ /* eslint-disable @typescript-eslint/explicit-member-accessibility */
16
+
17
+ Logger: class NullLogger implements interfaces.ILogger {
18
+ constructor( owner: typeof bases.ObjectBase, params: any = {} ) {
19
+ }
20
+
21
+ log( caller: interfaces.TCaller, message: string, ... params: any[] ) {}
22
+ warn( caller: interfaces.TCaller, message: string, ... params: any[] ) {}
23
+ error( caller: interfaces.TCaller, message: string, ... params: any[] ) {}
24
+ info( caller: interfaces.TCaller, message: string, ... params: any[] ) {}
25
+ debug( caller: interfaces.TCaller, message: string, ... params: any[] ) {}
26
+ startsEmpty( caller: interfaces.TCaller ) {}
27
+ startsWith( caller: interfaces.TCaller, params: object ) {}
28
+ dump( caller: interfaces.TCaller, data: any ) {}
29
+ drop( caller: interfaces.TCaller, according: { [ key: string ]: string }, data: any ) {}
30
+ }
31
+
32
+ /* eslint-enable */
33
+ };
34
+
35
+ let exportedConfig: interfaces.IAPIConfig = {
36
+ version: pkg.version,
37
+ };
38
+
39
+ export function initialize( config?: Partial<interfaces.IAPIConfig> ) {
40
+ if ( "undefined" !== typeof __ZEN_CORE__IS_INITIALIZED__ && __ZEN_CORE__IS_INITIALIZED__ ) {
41
+ throw new Error( "ZenCore is already initialized." );
42
+ }
43
+
44
+ exportedConfig = ( config || exportedConfig ) as interfaces.IAPIConfig;
45
+
46
+ managers.initialize( exportedConfig );
47
+
48
+ globalThis.__ZEN_CORE__IS_INITIALIZED__ = true;
49
+ }
50
+
51
+ export function destroy() {
52
+ managers.destroy();
53
+
54
+ globalThis.__ZEN_CORE__IS_INITIALIZED__ = false;
55
+ }
56
+
57
+ export function onAfterInitialize( callback: () => void ) {
58
+ managers.afterInitializeCallbacks.push( callback );
59
+ }
60
+
61
+ export const config = exportedConfig;
62
+
63
+ export {
64
+ bases,
65
+ commandBases,
66
+ errors,
67
+ interfaces,
68
+ managers
69
+ };
package/src/index.ts CHANGED
@@ -1,8 +1,17 @@
1
1
  /**
2
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
2
+ * @author Leonid Vinikov <leonidvinikov@gmail.com>
3
3
  */
4
- export { CoreAPI as default } from "./initializer";
4
+ import * as ZenCore from "@z-core/exports";
5
5
 
6
- export * from './exports';
6
+ // TODO: Only in development mode
7
+ if ( ! globalThis?.zCore ) {
8
+ globalThis.zCore = ZenCore;
9
+ }
7
10
 
11
+ declare global {
12
+ var zCore: typeof ZenCore;
13
+ }
8
14
 
15
+ export * from "@z-core/exports-index";
16
+
17
+ export default ZenCore;
@@ -1,4 +1,4 @@
1
- export type CommandCallbackType = ( args?: any, options?: any ) => any;
1
+ export type TCommandCallbackType = ( args?: any, options?: any ) => any;
2
2
 
3
3
  export interface ICommandArgsInterface {
4
4
  [ key: string ]: any;
@@ -9,9 +9,9 @@ export interface ICommandOptionsInterface {
9
9
  }
10
10
 
11
11
  export interface IOnHookAffectInterface {
12
- [ key: string ]: Array<String>;
12
+ [ key: string ]: Array<string>;
13
13
  }
14
14
 
15
15
  export interface IOnHookInterface {
16
- [ key: string ]: Array<CommandCallbackType>;
16
+ [ key: string ]: Array<TCommandCallbackType>;
17
17
  }
@@ -1,16 +1,23 @@
1
+ /**
2
+ * @author Leonid Vinikov <leonidvinikov@gmail.com>
3
+ */
4
+
5
+ /**
6
+ *
7
+ */
1
8
  export interface IAPIConfig {
2
9
  /**
3
- * @description: API version, from `package.json`
10
+ * @description API version, from `package.json`
4
11
  */
5
12
  version: string;
6
13
 
7
14
  /**
8
- * @description: API base url for http requests.
15
+ * @description API base url for http requests.
9
16
  */
10
17
  baseURL?: string;
11
18
 
12
19
  /**
13
- * @description: Request Init for fetch API.
20
+ * @description Request Init for fetch API.
14
21
  */
15
22
  requestInit?: RequestInit;
16
23
  }
@@ -1,8 +1,7 @@
1
1
  /**
2
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
2
+ * @author Leonid Vinikov <leonidvinikov@gmail.com>
3
3
  */
4
- export * from './commands';
5
- export * from './config';
6
- export * from './data';
7
- export * from './managers';
8
- export * from './object-base';
4
+ export * from "@z-core/interfaces/commands";
5
+ export * from "@z-core/interfaces/config";
6
+ export * from "@z-core/interfaces/logger";
7
+ export * from "@z-core/interfaces/restful";
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @author Leonid Vinikov <leonidvinikov@gmail.com>
3
+ */
4
+ export type TCaller = string | Function;
5
+
6
+ export interface ILogger {
7
+ log( caller: TCaller, message: string, ...params: any[] ): void;
8
+ warn( caller: TCaller, message: string, ...params: any[] ): void;
9
+ error( caller: TCaller, message: string, ...params: any[] ): void;
10
+ info( caller: TCaller, message: string, ...params: any[] ): void;
11
+ debug( caller: TCaller, message: string, ...params: any[] ): void;
12
+
13
+ startsEmpty( caller: TCaller ): void;
14
+ startsWith( caller: TCaller, params: object ): void;
15
+
16
+ dump( caller: TCaller, params: { [ key: string ]: object|string } ): void;
17
+ drop( caller: TCaller, according: { [ key: string ]: string }, data: any ): void;
18
+ }
@@ -7,17 +7,17 @@ export type TResponseHandlerCallbackType = ( text: string) => boolean;
7
7
  export type TPossibleHandlersType = TErrorHandlerCallbackType | TResponseFilterCallbackType | TResponseHandlerCallbackType;
8
8
 
9
9
  export enum E_RESPONSE_HANDLER_TYPE {
10
- ERROR_HANDLER = 'error_handler',
11
- RESPONSE_FILTER = 'response_filter',
12
- RESPONSE_HANDLER = 'response_handler',
10
+ ERROR_HANDLER = "error_handler",
11
+ RESPONSE_FILTER = "response_filter",
12
+ RESPONSE_HANDLER = "response_handler",
13
13
  };
14
14
 
15
15
  export enum E_HTTP_METHOD_TYPE {
16
- DELETE = 'DELETE', // Delete.
17
- GET = 'GET', // Read.
18
- OPTIONS = 'OPTIONS',// Options about the request
19
- PATCH = 'PATCH', // Update/Modify.
20
- POST = 'POST', // Create.
21
- PUT = 'PUT', // Update/Replace.
22
- '__EMPTY__' = ''
16
+ DELETE = "DELETE", // Delete.
17
+ GET = "GET", // Read.
18
+ OPTIONS = "OPTIONS",// Options about the request
19
+ PATCH = "PATCH", // Update/Modify.
20
+ POST = "POST", // Create.
21
+ PUT = "PUT", // Update/Replace.
22
+ "__EMPTY__" = ""
23
23
  };
@@ -1,44 +1,49 @@
1
1
  /**
2
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
3
- * @description: Responsible for manging/running/hooking commands.
2
+ * @author Leonid Vinikov <leonidvinikov@gmail.com>
3
+ * @description Responsible for manging/running/hooking commands.
4
4
  */
5
- import { Logger } from "../modules/";
6
- import { CommandBase } from "../command-bases";
7
- import { CommandAlreadyRegistered, CommandNotFound } from "../errors/";
5
+ import { ObjectBase } from "@z-core/bases/object-base";
8
6
 
9
- import ObjectBase from "../core/object-base";
10
- import Controller from "../core/controller";
7
+ import { CommandNotFound } from "@z-core/errors/command-not-found";
8
+ import { CommandAlreadyRegistered } from "@z-core/errors/command-already-registered";
9
+
10
+ import type {
11
+ TCommandCallbackType,
11
12
 
12
- import {
13
- CommandCallbackType,
14
- ICommandArgsInterface,
15
13
  IOnHookAffectInterface,
16
14
  IOnHookInterface,
15
+
16
+ ICommandArgsInterface,
17
17
  ICommandOptionsInterface,
18
- } from "../interfaces/";
18
+
19
+ ILogger,
20
+ } from "@z-core/interfaces";
21
+
22
+ import type { ControllerBase } from "@z-core/bases/controller-base";
23
+ import type { CommandBase } from "@z-core/command-bases/command-base";
19
24
 
20
25
  export class Commands extends ObjectBase {
21
26
  public static readonly trace:string[] = [];
22
27
 
23
- current: { [ key: string ]: CommandBase } = {};
24
- currentArgs: { [ key: string ]: ICommandArgsInterface } = {};
28
+ private current: { [ key: string ]: CommandBase } = {};
29
+ private currentArgs: { [ key: string ]: ICommandArgsInterface } = {};
25
30
 
26
- trace:string[] = [];
31
+ private trace:string[] = [];
27
32
 
28
- commands: { [ key: string ]: typeof CommandBase } = {};
33
+ private commands: { [ key: string ]: typeof CommandBase } = {};
29
34
 
30
- onBeforeHooks: IOnHookInterface = {};
31
- onBeforeUIHooks: IOnHookInterface = {};
35
+ private onBeforeHooks: IOnHookInterface = {};
36
+ private onBeforeUIHooks: IOnHookInterface = {};
32
37
 
33
- onAfterHooks: IOnHookInterface = {};
34
- onAfterOnceHooks: IOnHookInterface = {};
35
- onAfterUIHooks: IOnHookInterface = {};
36
- onAfterAffectHooks: IOnHookAffectInterface = {};
38
+ private onAfterHooks: IOnHookInterface = {};
39
+ private onAfterOnceHooks: IOnHookInterface = {};
40
+ private onAfterUIHooks: IOnHookInterface = {};
41
+ private onAfterAffectHooks: IOnHookAffectInterface = {};
37
42
 
38
- private readonly logger: Logger;
43
+ private readonly logger: ILogger;
39
44
 
40
- static getName() {
41
- return 'Core/Managers/Commands';
45
+ public static getName() {
46
+ return "ZenFlux/Core/Managers/Commands";
42
47
  }
43
48
 
44
49
  private static async runCallbacks( callbacks: Array<Function>, args: ICommandArgsInterface = {}, options: ICommandOptionsInterface = {} ) {
@@ -55,7 +60,7 @@ export class Commands extends ObjectBase {
55
60
  }
56
61
  }
57
62
 
58
- private static hookCommand( stack: any, hookCommand: string, context: CommandCallbackType | string ) {
63
+ private static hookCommand( stack: any, hookCommand: string, context: TCommandCallbackType | string ) {
59
64
  if ( ! stack[ hookCommand ] ) {
60
65
  stack[ hookCommand ] = [];
61
66
  }
@@ -63,12 +68,13 @@ export class Commands extends ObjectBase {
63
68
  stack[ hookCommand ].push( context );
64
69
  }
65
70
 
66
- constructor() {
71
+ public constructor() {
67
72
  super();
68
73
 
69
- this.logger = new Logger( this.getName(), true );
74
+ const type = ( this.constructor as typeof Commands );
70
75
 
71
- this.logger.startEmpty();
76
+ this.logger = new zCore.classes.Logger( type );
77
+ this.logger.startsEmpty( this.constructor );
72
78
  }
73
79
 
74
80
  public async run( command: string | CommandBase, args: ICommandArgsInterface = {}, options: any = {} ) {
@@ -85,7 +91,7 @@ export class Commands extends ObjectBase {
85
91
  return result;
86
92
  }
87
93
 
88
- public register( commands: { [ key: string ]: typeof CommandBase }, controller: Controller ) {// eslint-disable-line @typescript-eslint/no-unused-vars
94
+ public register( commands: { [ key: string ]: typeof CommandBase }, controller: ControllerBase ) {// eslint-disable-line @typescript-eslint/no-unused-vars
89
95
  const result: { [ key: string ]: typeof CommandBase } = {};
90
96
 
91
97
  Object.values( commands ).forEach( ( command ) => {
@@ -129,42 +135,42 @@ export class Commands extends ObjectBase {
129
135
  }
130
136
 
131
137
  /**
132
- * Function onBefore() : Used to set hooks that effects only data and not UI.
138
+ * Used to set hooks that effects only data and not UI.
133
139
  */
134
- public onBefore( hookCommand: string, callback: CommandCallbackType ) {
140
+ public onBefore( hookCommand: string, callback: TCommandCallbackType ) {
135
141
  Commands.hookCommand( this.onBeforeHooks, hookCommand, callback );
136
142
  }
137
143
 
138
144
  /**
139
- * Function onBeforeUI() : Used to set hooks that effects only UI.
145
+ * Used to set hooks that effects only UI.
140
146
  */
141
- public onBeforeUI( hookCommand: string, callback: CommandCallbackType ) {
147
+ public onBeforeUI( hookCommand: string, callback: TCommandCallbackType ) {
142
148
  Commands.hookCommand( this.onBeforeUIHooks, hookCommand, callback );
143
149
  }
144
150
 
145
151
  /**
146
- * Function onAfter() : Used to set hooks that effects only data and not UI.
152
+ * Used to set hooks that effects only data and not UI.
147
153
  */
148
- public onAfter( hookCommand: string, callback: CommandCallbackType ) {
154
+ public onAfter( hookCommand: string, callback: TCommandCallbackType ) {
149
155
  Commands.hookCommand( this.onAfterHooks, hookCommand, callback );
150
156
  }
151
157
 
152
158
  /**
153
- * Function onAfterUI() : Used to set hooks that effects only UI.
159
+ * Used to set hooks that effects only UI.
154
160
  */
155
- public onAfterUI( command: string, callback: CommandCallbackType ) {
161
+ public onAfterUI( command: string, callback: TCommandCallbackType ) {
156
162
  Commands.hookCommand( this.onAfterUIHooks, command, callback );
157
163
  }
158
164
 
159
165
  /**
160
- * Function onAfterOnce() : Used to set hooks that effects only data and not UI.
166
+ * Used to set hooks that effects only data and not UI.
161
167
  */
162
- public onAfterOnce( command: string, callback: CommandCallbackType ) {
168
+ public onAfterOnce( command: string, callback: TCommandCallbackType ) {
163
169
  Commands.hookCommand( this.onAfterOnceHooks, command, callback );
164
170
  }
165
171
 
166
172
  /**
167
- * Function onAfterAffect() : Used to register a trigger that runs command after `hookCommand` run's.
173
+ * Used to register a trigger that runs command after `hookCommand` run's.
168
174
  */
169
175
  public onAfterAffect( hookCommand: string, affectCommand: string ) {
170
176
  Commands.hookCommand( this.onAfterAffectHooks, hookCommand, affectCommand );
@@ -185,24 +191,11 @@ export class Commands extends ObjectBase {
185
191
  protected async runInstance( command: CommandBase, args: ICommandArgsInterface = {}, options = {} ) {
186
192
  let result: any = null;
187
193
 
188
- // TODO: Maybe a logger method to handle such cases.
189
- if ( Object.keys( args ).length ) {
190
- this.logger.startWith( {
191
- command: command.getName(),
192
- options,
193
- CommandArgs: "->",
194
- } );
195
-
196
- this.logger.debug( "CommandArgs:" );
197
- this.logger.object( args );
198
- } else {
199
- this.logger.startWith( {
200
- command: command.getName(),
201
- options,
202
- args,
203
- } );
204
-
205
- }
194
+ this.logger.startsWith( this.runInstance, {
195
+ command: command.getName(),
196
+ options,
197
+ args,
198
+ } );
206
199
 
207
200
  this.onBeforeRun( command, args, options );
208
201
 
@@ -251,7 +244,7 @@ export class Commands extends ObjectBase {
251
244
  Object.assign( [], this.onAfterUIHooks[ command.getName() ] ),
252
245
  args,
253
246
  options
254
- )
247
+ );
255
248
  }
256
249
 
257
250
  return result;
@@ -273,5 +266,3 @@ export class Commands extends ObjectBase {
273
266
  this.trace.pop();
274
267
  }
275
268
  }
276
-
277
- export default Commands;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @author Leonid Vinikov <leonidvinikov@gmail.com>
3
+ * @description Responsible for manging controllers, each controller is global singleton instance.
4
+ */
5
+ import { ControllerAlreadyRegistered } from "@z-core/errors/controller-already-registered";
6
+
7
+ import { ObjectBase } from "@z-core/bases/object-base";
8
+
9
+ import type { ControllerBase } from "@z-core/bases/controller-base";
10
+
11
+ export class Controllers extends ObjectBase {
12
+ private controllers: { [ key: string ]: ControllerBase } = {};
13
+
14
+ public constructor() {
15
+ super();
16
+ }
17
+
18
+ public static getName() {
19
+ return "ZenFlux/Core/Managers/Controllers";
20
+ }
21
+
22
+ public get( name: string ) {
23
+ return this.controllers[ name ];
24
+ }
25
+
26
+ public getAll() {
27
+ return this.controllers;
28
+ }
29
+
30
+ public register( controller: ControllerBase ) {
31
+ if ( this.controllers[ controller.getName() ] ) {
32
+ throw new ControllerAlreadyRegistered( controller );
33
+ }
34
+
35
+ // Register.
36
+ this.controllers[ controller.getName() ] = controller;
37
+
38
+ return controller;
39
+ }
40
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @author Leonid Vinikov <leonidvinikov@gmail.com>
3
+ */
4
+ import { Commands } from "@z-core/managers/commands";
5
+ import { Controllers } from "@z-core/managers/controllers";
6
+ import { Restful } from "@z-core/managers/restful";
7
+ import { Internal } from "@z-core/managers/internal";
8
+
9
+ import type { IAPIConfig } from "@z-core/interfaces";
10
+
11
+ export const afterInitializeCallbacks: ( () => void )[] = [];
12
+
13
+ export function initialize( config: IAPIConfig ) {
14
+ commands = new Commands();
15
+ controllers = new Controllers();
16
+ restful = new Restful( config );
17
+ internal = new Internal();
18
+ }
19
+
20
+ export function destroy() {
21
+ commands = {} as Commands;
22
+ controllers = {} as Controllers;
23
+ restful = {} as Restful;
24
+ internal = {} as Internal;
25
+ }
26
+
27
+ export let commands = {} as Commands;
28
+ export let controllers = {} as Controllers;
29
+ export let restful = {} as Restful;
30
+ export let internal = {} as Internal;
@@ -1,30 +1,7 @@
1
1
  /**
2
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
2
+ * @author Leonid Vinikov <leonidvinikov@gmail.com>
3
3
  */
4
- import Commands from "../manager-bases/commands";
5
- import Controllers from "../manager-bases/controllers";
6
- import Data from "../manager-bases/data";
7
- import Internal from "../manager-bases/internal";
8
-
9
- import { IAPIConfig } from "../interfaces/";
10
-
11
- export const afterInitializeCallbacks: ( () => void )[] = [];
12
-
13
- export function initialize( config: IAPIConfig ) {
14
- commands = new Commands();
15
- controllers = new Controllers();
16
- data = new Data( config );
17
- internal = new Internal();
18
- }
19
-
20
- export function destroy() {
21
- commands = {} as Commands;
22
- controllers = {} as Controllers;
23
- data = {} as Data;
24
- internal = {} as Internal;
25
- }
26
-
27
- export var commands = {} as Commands;
28
- export var controllers = {} as Controllers;
29
- export var data = {} as Data;
30
- export var internal = {} as Internal;
4
+ export { Commands } from "@z-core/managers/commands";
5
+ export { Controllers } from "@z-core/managers/controllers";
6
+ export { Restful } from "@z-core/managers/restful";
7
+ export { Internal } from "@z-core/managers/internal";