@zenflux/core 0.0.1-dev.1 → 0.0.1-dev.3

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 (179) hide show
  1. package/dist/es/src/bases/controller-base.d.ts +55 -0
  2. package/dist/es/src/bases/controller-base.d.ts.map +1 -0
  3. package/dist/es/src/bases/index.d.ts +3 -0
  4. package/dist/es/src/bases/index.d.ts.map +1 -0
  5. package/dist/es/src/bases/object-base.d.ts +32 -0
  6. package/dist/es/src/bases/object-base.d.ts.map +1 -0
  7. package/dist/es/src/clients/http.d.ts +40 -0
  8. package/dist/es/src/clients/http.d.ts.map +1 -0
  9. package/dist/es/src/command-bases/command-base.d.ts +29 -0
  10. package/dist/es/src/command-bases/command-base.d.ts.map +1 -0
  11. package/dist/es/src/command-bases/command-internal.d.ts +9 -0
  12. package/dist/es/src/command-bases/command-internal.d.ts.map +1 -0
  13. package/dist/es/src/command-bases/command-public.d.ts +9 -0
  14. package/dist/es/src/command-bases/command-public.d.ts.map +1 -0
  15. package/dist/es/src/command-bases/command-restful.d.ts +22 -0
  16. package/dist/es/src/command-bases/command-restful.d.ts.map +1 -0
  17. package/dist/es/src/command-bases/index.d.ts +8 -0
  18. package/dist/es/src/command-bases/index.d.ts.map +1 -0
  19. package/dist/es/src/errors/command-already-registered.d.ts +11 -0
  20. package/dist/es/src/errors/command-already-registered.d.ts.map +1 -0
  21. package/dist/es/src/errors/command-not-found.d.ts +10 -0
  22. package/dist/es/src/errors/command-not-found.d.ts.map +1 -0
  23. package/dist/es/src/errors/controller-already-registered.d.ts +11 -0
  24. package/dist/es/src/errors/controller-already-registered.d.ts.map +1 -0
  25. package/dist/es/src/errors/controller-already-set.d.ts +11 -0
  26. package/dist/es/src/errors/controller-already-set.d.ts.map +1 -0
  27. package/dist/es/src/errors/force-method-implementation.d.ts +14 -0
  28. package/dist/es/src/errors/force-method-implementation.d.ts.map +1 -0
  29. package/dist/es/src/errors/index-public.d.ts +2 -0
  30. package/dist/es/src/errors/index-public.d.ts.map +1 -0
  31. package/dist/es/src/errors/index.d.ts +6 -0
  32. package/dist/es/src/errors/index.d.ts.map +1 -0
  33. package/dist/es/src/exports.d.ts +37 -0
  34. package/dist/es/src/exports.d.ts.map +1 -0
  35. package/dist/es/src/index.d.ts +6 -0
  36. package/dist/es/src/index.d.ts.map +1 -0
  37. package/dist/es/src/initializer.d.ts +36 -0
  38. package/dist/es/src/initializer.d.ts.map +1 -0
  39. package/dist/es/{interfaces → src/interfaces}/commands.d.ts +3 -3
  40. package/dist/es/src/interfaces/commands.d.ts.map +1 -0
  41. package/dist/es/src/interfaces/config.d.ts +21 -0
  42. package/dist/es/src/interfaces/config.d.ts.map +1 -0
  43. package/dist/es/src/interfaces/index.d.ts +8 -0
  44. package/dist/es/src/interfaces/index.d.ts.map +1 -0
  45. package/dist/es/src/interfaces/logger.d.ts +20 -0
  46. package/dist/es/src/interfaces/logger.d.ts.map +1 -0
  47. package/dist/es/{interfaces/data.d.ts → src/interfaces/restful.d.ts} +2 -2
  48. package/dist/es/src/interfaces/restful.d.ts.map +1 -0
  49. package/dist/es/src/managers/commands.d.ts +68 -0
  50. package/dist/es/src/managers/commands.d.ts.map +1 -0
  51. package/dist/es/src/managers/controllers.d.ts +17 -0
  52. package/dist/es/src/managers/controllers.d.ts.map +1 -0
  53. package/dist/es/src/managers/export.d.ts +16 -0
  54. package/dist/es/src/managers/export.d.ts.map +1 -0
  55. package/dist/es/src/managers/index.d.ts +8 -0
  56. package/dist/es/src/managers/index.d.ts.map +1 -0
  57. package/dist/es/src/managers/internal.d.ts +9 -0
  58. package/dist/es/src/managers/internal.d.ts.map +1 -0
  59. package/dist/es/{manager-bases/data.d.ts → src/managers/restful.d.ts} +9 -10
  60. package/dist/es/src/managers/restful.d.ts.map +1 -0
  61. package/dist/es/tsdoc-metadata.json +11 -0
  62. package/dist/es/zenflux-core.d.ts +470 -0
  63. package/dist/es/zenflux-core.js +709 -1025
  64. package/package.json +29 -47
  65. package/src/bases/controller-base.ts +96 -0
  66. package/src/bases/index.ts +2 -0
  67. package/src/bases/object-base.ts +83 -0
  68. package/src/clients/http.ts +51 -39
  69. package/src/command-bases/command-base.ts +34 -38
  70. package/src/command-bases/command-internal.ts +5 -7
  71. package/src/command-bases/command-public.ts +5 -6
  72. package/src/command-bases/command-restful.ts +55 -0
  73. package/src/command-bases/index.ts +5 -5
  74. package/src/errors/command-already-registered.ts +6 -5
  75. package/src/errors/command-not-found.ts +6 -4
  76. package/src/errors/controller-already-registered.ts +6 -5
  77. package/src/errors/controller-already-set.ts +8 -5
  78. package/src/errors/force-method-implementation.ts +23 -0
  79. package/src/errors/index-public.ts +1 -0
  80. package/src/errors/index.ts +5 -5
  81. package/src/exports.ts +47 -9
  82. package/src/index.ts +3 -4
  83. package/src/initializer.ts +13 -13
  84. package/src/interfaces/commands.ts +3 -3
  85. package/src/interfaces/config.ts +14 -2
  86. package/src/interfaces/index.ts +5 -6
  87. package/src/interfaces/logger.ts +18 -0
  88. package/src/interfaces/{data.ts → restful.ts} +10 -10
  89. package/src/{manager-bases → managers}/commands.ts +52 -60
  90. package/src/managers/controllers.ts +39 -0
  91. package/src/managers/export.ts +30 -0
  92. package/src/managers/index.ts +5 -28
  93. package/src/managers/internal.ts +11 -0
  94. package/src/{manager-bases/data.ts → managers/restful.ts} +18 -19
  95. package/LICENSE +0 -21
  96. package/README.md +0 -2
  97. package/dist/es/clients/http.d.ts +0 -32
  98. package/dist/es/clients/http.d.ts.map +0 -1
  99. package/dist/es/command-bases/command-base.d.ts +0 -27
  100. package/dist/es/command-bases/command-base.d.ts.map +0 -1
  101. package/dist/es/command-bases/command-data.d.ts +0 -18
  102. package/dist/es/command-bases/command-data.d.ts.map +0 -1
  103. package/dist/es/command-bases/command-internal.d.ts +0 -10
  104. package/dist/es/command-bases/command-internal.d.ts.map +0 -1
  105. package/dist/es/command-bases/command-public.d.ts +0 -10
  106. package/dist/es/command-bases/command-public.d.ts.map +0 -1
  107. package/dist/es/command-bases/index.d.ts +0 -8
  108. package/dist/es/command-bases/index.d.ts.map +0 -1
  109. package/dist/es/core/controller.d.ts +0 -36
  110. package/dist/es/core/controller.d.ts.map +0 -1
  111. package/dist/es/core/index.d.ts +0 -3
  112. package/dist/es/core/index.d.ts.map +0 -1
  113. package/dist/es/core/object-base.d.ts +0 -15
  114. package/dist/es/core/object-base.d.ts.map +0 -1
  115. package/dist/es/errors/command-already-registered.d.ts +0 -9
  116. package/dist/es/errors/command-already-registered.d.ts.map +0 -1
  117. package/dist/es/errors/command-not-found.d.ts +0 -8
  118. package/dist/es/errors/command-not-found.d.ts.map +0 -1
  119. package/dist/es/errors/controller-already-registered.d.ts +0 -9
  120. package/dist/es/errors/controller-already-registered.d.ts.map +0 -1
  121. package/dist/es/errors/controller-already-set.d.ts +0 -8
  122. package/dist/es/errors/controller-already-set.d.ts.map +0 -1
  123. package/dist/es/errors/force-method.d.ts +0 -12
  124. package/dist/es/errors/force-method.d.ts.map +0 -1
  125. package/dist/es/errors/index.d.ts +0 -6
  126. package/dist/es/errors/index.d.ts.map +0 -1
  127. package/dist/es/exports.d.ts +0 -12
  128. package/dist/es/exports.d.ts.map +0 -1
  129. package/dist/es/index.d.ts +0 -6
  130. package/dist/es/index.d.ts.map +0 -1
  131. package/dist/es/initializer.d.ts +0 -22
  132. package/dist/es/initializer.d.ts.map +0 -1
  133. package/dist/es/interfaces/commands.d.ts.map +0 -1
  134. package/dist/es/interfaces/config.d.ts +0 -11
  135. package/dist/es/interfaces/config.d.ts.map +0 -1
  136. package/dist/es/interfaces/data.d.ts.map +0 -1
  137. package/dist/es/interfaces/index.d.ts +0 -9
  138. package/dist/es/interfaces/index.d.ts.map +0 -1
  139. package/dist/es/interfaces/managers.d.ts +0 -14
  140. package/dist/es/interfaces/managers.d.ts.map +0 -1
  141. package/dist/es/interfaces/object-base.d.ts +0 -11
  142. package/dist/es/interfaces/object-base.d.ts.map +0 -1
  143. package/dist/es/manager-bases/commands.d.ts +0 -76
  144. package/dist/es/manager-bases/commands.d.ts.map +0 -1
  145. package/dist/es/manager-bases/controllers.d.ts +0 -19
  146. package/dist/es/manager-bases/controllers.d.ts.map +0 -1
  147. package/dist/es/manager-bases/data.d.ts.map +0 -1
  148. package/dist/es/manager-bases/index.d.ts +0 -8
  149. package/dist/es/manager-bases/index.d.ts.map +0 -1
  150. package/dist/es/manager-bases/internal.d.ts +0 -10
  151. package/dist/es/manager-bases/internal.d.ts.map +0 -1
  152. package/dist/es/managers/index.d.ts +0 -16
  153. package/dist/es/managers/index.d.ts.map +0 -1
  154. package/dist/es/modules/index.d.ts +0 -2
  155. package/dist/es/modules/index.d.ts.map +0 -1
  156. package/dist/es/modules/logger.d.ts +0 -118
  157. package/dist/es/modules/logger.d.ts.map +0 -1
  158. package/dist/es/utils/index.d.ts +0 -3
  159. package/dist/es/utils/index.d.ts.map +0 -1
  160. package/dist/es/utils/object.d.ts +0 -7
  161. package/dist/es/utils/object.d.ts.map +0 -1
  162. package/dist/es/utils/rgb.d.ts +0 -7
  163. package/dist/es/utils/rgb.d.ts.map +0 -1
  164. package/src/command-bases/command-data.ts +0 -54
  165. package/src/core/controller.ts +0 -61
  166. package/src/core/index.ts +0 -2
  167. package/src/core/object-base.ts +0 -46
  168. package/src/errors/force-method.ts +0 -22
  169. package/src/interfaces/managers.ts +0 -16
  170. package/src/interfaces/object-base.ts +0 -12
  171. package/src/manager-bases/controllers.ts +0 -37
  172. package/src/manager-bases/index.ts +0 -7
  173. package/src/manager-bases/internal.ts +0 -13
  174. package/src/modules/index.ts +0 -1
  175. package/src/modules/logger.ts +0 -459
  176. package/src/utils/index.ts +0 -2
  177. package/src/utils/object.ts +0 -18
  178. package/src/utils/rgb.ts +0 -33
  179. 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 { 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 { 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 { 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 { 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";
package/src/exports.ts CHANGED
@@ -1,11 +1,49 @@
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
+
5
+ /**
6
+ * api-extractor 7.97.1: ERROR: The "export * as ___" syntax is not supported yet; as a workaround, use "import * as ___" with a separate "export { ___ }" declaration
7
+ *
8
+ * export * as bases from "./bases";
9
+ * export * as commandBases from "./command-bases";
10
+ * export * as errors from "./errors";
11
+ * export * as interfaces from "./interfaces";
12
+ * export * as managers from "./managers/export";
13
+ */
14
+
15
+ import * as bases from "@z-core/bases";
16
+ import * as commandBases from "@z-core/command-bases";
17
+ import * as errors from "@z-core/errors/index-public";
18
+ import * as interfaces from "@z-core/interfaces";
19
+ import * as managers from "@z-core/managers/export";
20
+
21
+ import { ILogger, TCaller } from "@z-core/interfaces";
22
+
23
+ export const classes = {
24
+ /* eslint-disable @typescript-eslint/no-unused-vars */
25
+ /* eslint-disable @typescript-eslint/explicit-member-accessibility */
26
+
27
+ Logger: class NullLogger implements ILogger {
28
+ constructor(owner: typeof bases.ObjectBase, params: any = {} ) {}
29
+ log( caller: TCaller, message: string, ... params: any[] ) {}
30
+ warn( caller: TCaller, message: string, ... params: any[] ) {}
31
+ error( caller: TCaller, message: string, ... params: any[] ) {}
32
+ info( caller: TCaller, message: string, ... params: any[] ) {}
33
+ debug( caller: TCaller, message: string, ... params: any[] ) {}
34
+ startsEmpty( caller: TCaller ) {}
35
+ startsWith( caller: TCaller, params: object ) {}
36
+ dump( caller: TCaller, data: any ) {}
37
+ drop( caller: TCaller, according: { [ key: string ]: string }, data: any ) {}
38
+ }
39
+
40
+ /* eslint-enable */
41
+ };
42
+
43
+ export {
44
+ bases,
45
+ commandBases,
46
+ errors,
47
+ interfaces,
48
+ managers
49
+ };
package/src/index.ts CHANGED
@@ -1,8 +1,7 @@
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";
5
-
6
- export * from './exports';
4
+ export { CoreAPI as default } from "@z-core/initializer";
7
5
 
6
+ export * from "@z-core/exports";
8
7
 
@@ -1,20 +1,15 @@
1
1
  // @ts-ignore
2
2
  import * as pkg from "../package.json" assert { type: "json" };
3
3
 
4
- import { IAPIConfig } from "./interfaces/config";
4
+ import { IAPIConfig } from "@z-core/interfaces";
5
5
 
6
- import { destroy, initialize, afterInitializeCallbacks } from "./managers";
6
+ import { destroy, initialize, afterInitializeCallbacks } from "@z-core/managers/export";
7
7
 
8
- import * as exported from './exports';
9
-
10
- declare global {
11
- var ZenCore: any;
12
- var __ZEN_CORE__IS_INITIALIZED__: boolean;
13
- }
8
+ import * as exported from "@z-core/exports";
14
9
 
15
10
  function errorInitTwice() {
16
- if ( 'undefined' !== typeof __ZEN_CORE__IS_INITIALIZED__ && __ZEN_CORE__IS_INITIALIZED__) {
17
- throw new Error( 'ZenCore is already initialized.' );
11
+ if ( "undefined" !== typeof __ZEN_CORE__IS_INITIALIZED__ && __ZEN_CORE__IS_INITIALIZED__) {
12
+ throw new Error( "ZenCore is already initialized." );
18
13
  }
19
14
  }
20
15
 
@@ -25,10 +20,10 @@ export let config: IAPIConfig = {
25
20
  };
26
21
 
27
22
  export const CoreAPI = {
28
- initialize: ( configuration?: IAPIConfig ) => {
23
+ initialize: ( configuration?: Partial<IAPIConfig> ) => {
29
24
  errorInitTwice();
30
25
 
31
- config = configuration || config;
26
+ config = (configuration || config) as IAPIConfig;
32
27
 
33
28
  initialize( config );
34
29
 
@@ -51,6 +46,11 @@ export const CoreAPI = {
51
46
  ...exported,
52
47
  };
53
48
 
54
- // TODO: Make it available only for development.
55
49
  if ( ! globalThis?.ZenCore ) globalThis.ZenCore = CoreAPI;
56
50
 
51
+ declare global {
52
+ var ZenCore: typeof CoreAPI;
53
+ var __ZEN_CORE__IS_INITIALIZED__: boolean;
54
+ }
55
+
56
+ // console.log( `ZenCore initialized, version: ${pkg.version}` );
@@ -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,11 +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;
18
+
19
+ /**
20
+ * @description Request Init for fetch API.
21
+ */
22
+ requestInit?: RequestInit;
11
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,50 @@
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 ZenCore from "@zenflux/core";
8
6
 
9
- import ObjectBase from "../core/object-base";
10
- import Controller from "../core/controller";
7
+ import { ObjectBase } from "@z-core/bases/object-base";
8
+ import { ControllerBase } from "@z-core/bases/controller-base";
9
+
10
+ import { CommandBase } from "@z-core/command-bases";
11
+
12
+ import { CommandAlreadyRegistered, CommandNotFound } from "@z-core/errors";
11
13
 
12
14
  import {
13
- CommandCallbackType,
14
- ICommandArgsInterface,
15
+ TCommandCallbackType,
16
+
15
17
  IOnHookAffectInterface,
16
18
  IOnHookInterface,
19
+
20
+ ICommandArgsInterface,
17
21
  ICommandOptionsInterface,
18
- } from "../interfaces/";
22
+
23
+ ILogger,
24
+ } from "@z-core/interfaces";
19
25
 
20
26
  export class Commands extends ObjectBase {
21
27
  public static readonly trace:string[] = [];
22
28
 
23
- current: { [ key: string ]: CommandBase } = {};
24
- currentArgs: { [ key: string ]: ICommandArgsInterface } = {};
29
+ private current: { [ key: string ]: CommandBase } = {};
30
+ private currentArgs: { [ key: string ]: ICommandArgsInterface } = {};
25
31
 
26
- trace:string[] = [];
32
+ private trace:string[] = [];
27
33
 
28
- commands: { [ key: string ]: typeof CommandBase } = {};
34
+ private commands: { [ key: string ]: typeof CommandBase } = {};
29
35
 
30
- onBeforeHooks: IOnHookInterface = {};
31
- onBeforeUIHooks: IOnHookInterface = {};
36
+ private onBeforeHooks: IOnHookInterface = {};
37
+ private onBeforeUIHooks: IOnHookInterface = {};
32
38
 
33
- onAfterHooks: IOnHookInterface = {};
34
- onAfterOnceHooks: IOnHookInterface = {};
35
- onAfterUIHooks: IOnHookInterface = {};
36
- onAfterAffectHooks: IOnHookAffectInterface = {};
39
+ private onAfterHooks: IOnHookInterface = {};
40
+ private onAfterOnceHooks: IOnHookInterface = {};
41
+ private onAfterUIHooks: IOnHookInterface = {};
42
+ private onAfterAffectHooks: IOnHookAffectInterface = {};
37
43
 
38
- private readonly logger: Logger;
44
+ private readonly logger: ILogger;
39
45
 
40
- static getName() {
41
- return 'Core/Managers/Commands';
46
+ public static getName() {
47
+ return "ZenFlux/Core/Managers/Commands";
42
48
  }
43
49
 
44
50
  private static async runCallbacks( callbacks: Array<Function>, args: ICommandArgsInterface = {}, options: ICommandOptionsInterface = {} ) {
@@ -55,7 +61,7 @@ export class Commands extends ObjectBase {
55
61
  }
56
62
  }
57
63
 
58
- private static hookCommand( stack: any, hookCommand: string, context: CommandCallbackType | string ) {
64
+ private static hookCommand( stack: any, hookCommand: string, context: TCommandCallbackType | string ) {
59
65
  if ( ! stack[ hookCommand ] ) {
60
66
  stack[ hookCommand ] = [];
61
67
  }
@@ -63,12 +69,13 @@ export class Commands extends ObjectBase {
63
69
  stack[ hookCommand ].push( context );
64
70
  }
65
71
 
66
- constructor() {
72
+ public constructor() {
67
73
  super();
68
74
 
69
- this.logger = new Logger( this.getName(), true );
75
+ const type = ( this.constructor as typeof Commands );
70
76
 
71
- this.logger.startEmpty();
77
+ this.logger = new ZenCore.classes.Logger( type );
78
+ this.logger.startsEmpty( this.constructor );
72
79
  }
73
80
 
74
81
  public async run( command: string | CommandBase, args: ICommandArgsInterface = {}, options: any = {} ) {
@@ -85,7 +92,7 @@ export class Commands extends ObjectBase {
85
92
  return result;
86
93
  }
87
94
 
88
- public register( commands: { [ key: string ]: typeof CommandBase }, controller: Controller ) {// eslint-disable-line @typescript-eslint/no-unused-vars
95
+ public register( commands: { [ key: string ]: typeof CommandBase }, controller: ControllerBase ) {// eslint-disable-line @typescript-eslint/no-unused-vars
89
96
  const result: { [ key: string ]: typeof CommandBase } = {};
90
97
 
91
98
  Object.values( commands ).forEach( ( command ) => {
@@ -129,42 +136,42 @@ export class Commands extends ObjectBase {
129
136
  }
130
137
 
131
138
  /**
132
- * Function onBefore() : Used to set hooks that effects only data and not UI.
139
+ * Used to set hooks that effects only data and not UI.
133
140
  */
134
- public onBefore( hookCommand: string, callback: CommandCallbackType ) {
141
+ public onBefore( hookCommand: string, callback: TCommandCallbackType ) {
135
142
  Commands.hookCommand( this.onBeforeHooks, hookCommand, callback );
136
143
  }
137
144
 
138
145
  /**
139
- * Function onBeforeUI() : Used to set hooks that effects only UI.
146
+ * Used to set hooks that effects only UI.
140
147
  */
141
- public onBeforeUI( hookCommand: string, callback: CommandCallbackType ) {
148
+ public onBeforeUI( hookCommand: string, callback: TCommandCallbackType ) {
142
149
  Commands.hookCommand( this.onBeforeUIHooks, hookCommand, callback );
143
150
  }
144
151
 
145
152
  /**
146
- * Function onAfter() : Used to set hooks that effects only data and not UI.
153
+ * Used to set hooks that effects only data and not UI.
147
154
  */
148
- public onAfter( hookCommand: string, callback: CommandCallbackType ) {
155
+ public onAfter( hookCommand: string, callback: TCommandCallbackType ) {
149
156
  Commands.hookCommand( this.onAfterHooks, hookCommand, callback );
150
157
  }
151
158
 
152
159
  /**
153
- * Function onAfterUI() : Used to set hooks that effects only UI.
160
+ * Used to set hooks that effects only UI.
154
161
  */
155
- public onAfterUI( command: string, callback: CommandCallbackType ) {
162
+ public onAfterUI( command: string, callback: TCommandCallbackType ) {
156
163
  Commands.hookCommand( this.onAfterUIHooks, command, callback );
157
164
  }
158
165
 
159
166
  /**
160
- * Function onAfterOnce() : Used to set hooks that effects only data and not UI.
167
+ * Used to set hooks that effects only data and not UI.
161
168
  */
162
- public onAfterOnce( command: string, callback: CommandCallbackType ) {
169
+ public onAfterOnce( command: string, callback: TCommandCallbackType ) {
163
170
  Commands.hookCommand( this.onAfterOnceHooks, command, callback );
164
171
  }
165
172
 
166
173
  /**
167
- * Function onAfterAffect() : Used to register a trigger that runs command after `hookCommand` run's.
174
+ * Used to register a trigger that runs command after `hookCommand` run's.
168
175
  */
169
176
  public onAfterAffect( hookCommand: string, affectCommand: string ) {
170
177
  Commands.hookCommand( this.onAfterAffectHooks, hookCommand, affectCommand );
@@ -185,24 +192,11 @@ export class Commands extends ObjectBase {
185
192
  protected async runInstance( command: CommandBase, args: ICommandArgsInterface = {}, options = {} ) {
186
193
  let result: any = null;
187
194
 
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
- }
195
+ this.logger.startsWith( this.runInstance, {
196
+ command: command.getName(),
197
+ options,
198
+ args,
199
+ } );
206
200
 
207
201
  this.onBeforeRun( command, args, options );
208
202
 
@@ -251,7 +245,7 @@ export class Commands extends ObjectBase {
251
245
  Object.assign( [], this.onAfterUIHooks[ command.getName() ] ),
252
246
  args,
253
247
  options
254
- )
248
+ );
255
249
  }
256
250
 
257
251
  return result;
@@ -273,5 +267,3 @@ export class Commands extends ObjectBase {
273
267
  this.trace.pop();
274
268
  }
275
269
  }
276
-
277
- export default Commands;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @author Leonid Vinikov <leonidvinikov@gmail.com>
3
+ * @description Responsible for manging controllers, each controller is global singleton instance.
4
+ */
5
+ import { ObjectBase } from "@z-core/bases/object-base";
6
+ import { ControllerBase } from "@z-core/bases/controller-base";
7
+
8
+ import { ControllerAlreadyRegistered } from "@z-core/errors/controller-already-registered";
9
+
10
+ export class Controllers extends ObjectBase {
11
+ private controllers: { [ key: string ]: ControllerBase } = {};
12
+
13
+ public constructor() {
14
+ super();
15
+ }
16
+
17
+ public static getName() {
18
+ return "ZenFlux/Core/Managers/Controllers";
19
+ }
20
+
21
+ public get( name: string ) {
22
+ return this.controllers[ name ];
23
+ }
24
+
25
+ public getAll() {
26
+ return this.controllers;
27
+ }
28
+
29
+ public register( controller: ControllerBase ) {
30
+ if ( this.controllers[ controller.getName() ] ) {
31
+ throw new ControllerAlreadyRegistered( controller );
32
+ }
33
+
34
+ // Register.
35
+ this.controllers[ controller.getName() ] = controller;
36
+
37
+ return controller;
38
+ }
39
+ }
@@ -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 { 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";