@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,54 +0,0 @@
1
- /**
2
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
3
- * @description: Each data command should represent a final REST endpoint.
4
- */
5
- import { ForceMethod } from '../errors/force-method';
6
- import { CommandBase } from './command-base';
7
-
8
- import * as managers from '../managers';
9
-
10
- export abstract class CommandData extends CommandBase {
11
- static getName() {
12
- return 'Core/CommandBases/CommandData';
13
- }
14
-
15
- /**
16
- * Function getEndpoint() : Override this method is required to determine endpoint and magic query params.
17
- * @example
18
- * ```
19
- * args = { query: { id: 1 } };
20
- * getEndpoint() = '/api/v1/users/{id}';
21
- * result = '/api/v1/users/1';
22
- * ```
23
- */
24
- getEndpoint(): string {
25
- throw new ForceMethod( this, 'getEndpoint' );
26
- }
27
-
28
- apply( args = this.args, options = this.options ) {// eslint-disable-line @typescript-eslint/no-unused-vars
29
- const endpoint = this.applyEndpointFormat( this.getEndpoint(), args );
30
-
31
- return managers.data.getClient().fetch(
32
- endpoint, managers.data.currentHttpMethod, args || null
33
- );
34
- }
35
-
36
- private applyEndpointFormat( endpoint: string, data: any = {} ): string {
37
- // Replace query with `magic` placeholders.
38
- if ( endpoint.includes( '{' ) ) {
39
- endpoint = endpoint.split( '/' ).map( ( endpointPart ) => {
40
- const match = endpointPart.match( '\\{(.*?)\\}' );
41
-
42
- if ( match?.length && 'undefined' !== typeof data[ match[ 1 ] ] ) {
43
- return data[ match[ 1 ] ];
44
- }
45
-
46
- return endpointPart;
47
- } ).join( '/' );
48
- }
49
-
50
- return endpoint;
51
- }
52
- }
53
-
54
- export default CommandData;
@@ -1,61 +0,0 @@
1
- /**
2
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
3
- * @description: Responsible for commands, Aka ( CommandsSpace ).
4
- */
5
- import ObjectBase from "./object-base";
6
-
7
- import { CommandData, CommandInternal, CommandPublic } from "../command-bases";
8
-
9
- import * as managers from "../managers/";
10
-
11
- export abstract class Controller extends ObjectBase {
12
- commands: { [ key: string ]: typeof CommandPublic };
13
- data: { [ key: string ]: typeof CommandData };
14
- internal: { [ key: string ]: typeof CommandInternal };
15
-
16
- static getName() {
17
- return 'Core/Core/Controller';
18
- }
19
-
20
- public constructor() {
21
- super();
22
-
23
- this.initialize();
24
- }
25
-
26
- initialize() {
27
- this.register();
28
-
29
- this.setupHooks && this.setupHooks();
30
- }
31
-
32
- register() {
33
- this.commands = managers.commands.register( this.getCommands(), this ) as
34
- { [ key: string ]: typeof CommandPublic };
35
-
36
- this.data = managers.data.register( this.getData(), this ) as
37
- { [ key: string ]: typeof CommandData };
38
-
39
- this.internal = managers.internal.register( this.getInternal(), this ) as
40
- { [ key: string ]: typeof CommandInternal };
41
- }
42
-
43
- getCommands(): { [ key: string ]: typeof CommandPublic } {
44
- return {};
45
- }
46
-
47
- getData(): { [ key: string ]: typeof CommandData } {
48
- return {};
49
- }
50
-
51
- getInternal(): { [ key: string ]: typeof CommandInternal } {
52
- return {};
53
- }
54
-
55
- /**
56
- * Function setupHooks() : Override this method to setup hooks.
57
- */
58
- setupHooks?():void
59
- }
60
-
61
- export default Controller;
package/src/core/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export { Controller } from './controller';
2
- export { ObjectBase } from './object-base';
@@ -1,46 +0,0 @@
1
- /**
2
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
3
- * @description: is base class/object for all classes, responsible for: 'getName', implementation.
4
- */
5
- import { ForceMethodBase } from "../errors/force-method";
6
-
7
- import { IObjectBaseInterface } from "../interfaces/";
8
-
9
- let IdCounter = 0;
10
-
11
- /**
12
- * Base class 4 *
13
- */
14
- export abstract class ObjectBase implements IObjectBaseInterface {
15
- public virtualId: number = 0;
16
-
17
- static getName(): string {
18
- throw new ForceMethodBase( "ObjectBase", "getName" );
19
- }
20
-
21
- constructor() {
22
- this.virtualId = IdCounter;
23
-
24
- APIIncreaseIdCounter();
25
- }
26
-
27
- getName(): string {
28
- return ( this.constructor as typeof ObjectBase ).getName();
29
- }
30
- }
31
-
32
- export function APIResetIdCounter() {
33
- IdCounter = 0;
34
-
35
- return 0;
36
- }
37
-
38
- export function APIIncreaseIdCounter(): number {
39
- return IdCounter++;
40
- }
41
-
42
- export function APIGetIdCounter(): number {
43
- return IdCounter;
44
- }
45
-
46
- export default ObjectBase;
@@ -1,22 +0,0 @@
1
- /**
2
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
3
- */
4
- import ObjectBase from "../core/object-base";
5
-
6
- export class ForceMethodBase extends Error {
7
- constructor( className: string, methodName: string ) {
8
- super(
9
- `ForeMethod implementation: at '${ className }' method: '${ methodName }'`
10
- );
11
- }
12
- }
13
-
14
- export class ForceMethod extends Error {
15
- constructor( context: ObjectBase | typeof ObjectBase, methodName: string ) {
16
- super(
17
- `ForeMethod implementation: at '${ context.getName() }' method: '${ methodName }'`
18
- );
19
- }
20
- }
21
-
22
- export default ForceMethod;
@@ -1,56 +0,0 @@
1
- // @ts-ignore
2
- import * as pkg from "../package.json" assert { type: "json" };
3
-
4
- import { IAPIConfig } from "./interfaces/config";
5
-
6
- import { destroy, initialize, afterInitializeCallbacks } from "./managers";
7
-
8
- import * as exported from './exports';
9
-
10
- declare global {
11
- var ZenCore: any;
12
- var __ZEN_CORE__IS_INITIALIZED__: boolean;
13
- }
14
-
15
- function errorInitTwice() {
16
- if ( 'undefined' !== typeof __ZEN_CORE__IS_INITIALIZED__ && __ZEN_CORE__IS_INITIALIZED__) {
17
- throw new Error( 'ZenCore is already initialized.' );
18
- }
19
- }
20
-
21
- errorInitTwice();
22
-
23
- export let config: IAPIConfig = {
24
- version: pkg.version,
25
- };
26
-
27
- export const CoreAPI = {
28
- initialize: ( configuration?: IAPIConfig ) => {
29
- errorInitTwice();
30
-
31
- config = configuration || config;
32
-
33
- initialize( config );
34
-
35
- globalThis.__ZEN_CORE__IS_INITIALIZED__ = true;
36
-
37
- },
38
-
39
- destroy: () => {
40
- destroy();
41
-
42
- globalThis.__ZEN_CORE__IS_INITIALIZED__ = false;
43
- },
44
-
45
- onAfterInitialize: ( callback: () => void ) => {
46
- afterInitializeCallbacks.push( callback );
47
- },
48
-
49
- config,
50
-
51
- ...exported,
52
- };
53
-
54
- // TODO: Make it available only for development.
55
- if ( ! globalThis?.ZenCore ) globalThis.ZenCore = CoreAPI;
56
-
@@ -1,16 +0,0 @@
1
- import Commands from "../manager-bases/commands";
2
- import Controllers from "../manager-bases/controllers";
3
- import Data from "../manager-bases/data";
4
- import Internal from "../manager-bases/internal";
5
-
6
- import { IAPIConfig } from "./config";
7
-
8
- export interface IManagers {
9
- initialize: ( config: IAPIConfig ) => void;
10
- destroy: () => void;
11
-
12
- commands: Commands;
13
- controllers: Controllers;
14
- data: Data;
15
- internal: Internal;
16
- }
@@ -1,12 +0,0 @@
1
- export interface IObjectBaseInterface {
2
-
3
- /**
4
- * Virtual id is used for identification of object or for debugging proposes.
5
- */
6
- virtualId: number;
7
-
8
- /**
9
- *
10
- */
11
- getName(): string;
12
- }
@@ -1,37 +0,0 @@
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 "../core/object-base";
6
- import Controller from "../core/controller";
7
-
8
- import { ControllerAlreadyRegistered } from "../errors/controller-already-registered";
9
-
10
- export class Controllers extends ObjectBase {
11
- controllers: { [ key: string ]: Controller } = {};
12
-
13
- static getName() {
14
- return 'Core/Managers/Controllers';
15
- }
16
-
17
- get( name: string ) {
18
- return this.controllers[ name ];
19
- }
20
-
21
- getAll() {
22
- return this.controllers;
23
- }
24
-
25
- register( controller: Controller ) {
26
- if ( this.controllers[ controller.getName() ] ) {
27
- throw new ControllerAlreadyRegistered( controller );
28
- }
29
-
30
- // Register.
31
- this.controllers[ controller.getName() ] = controller;
32
-
33
- return controller;
34
- }
35
- }
36
-
37
- export default Controllers;
@@ -1,7 +0,0 @@
1
- /**
2
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
3
- */
4
- export { Commands } from './commands';
5
- export { Controllers } from './controllers';
6
- export { Data } from './data';
7
- export { Internal } from './internal';
@@ -1,13 +0,0 @@
1
- /**
2
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
3
- * @description: Responsible for manging internal commands, To serve commands that are not triggered by user.
4
- */
5
- import { Commands } from "./commands";
6
-
7
- export class Internal extends Commands {
8
- static getName() {
9
- return 'Core/Managers/Internal';
10
- }
11
- }
12
-
13
- export default Internal;
@@ -1 +0,0 @@
1
- export { Logger } from "./logger";