@zenflux/core 0.0.0-abc.19 → 0.0.0-abc.20

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.
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var name = "@zenflux/core";
6
- var version = "0.0.0-abc.14";
6
+ var version = "0.0.0-abc.20";
7
7
  var description = "ZenFlux core";
8
8
  var author = "Leonid Vinikov <leonidvinikov@gmail.com> (https://github.com/iNewLegend)";
9
9
  var scripts = {
@@ -74,18 +74,6 @@ var pkg = {
74
74
  dependencies: dependencies
75
75
  };
76
76
 
77
- const managers = {
78
- initialize: () => {},
79
- destroy: () => {},
80
- commands: {},
81
- controllers: {},
82
- data: {},
83
- internal: {}
84
- };
85
- if (typeof __ZEN_MANAGERS__ === 'undefined' || !__ZEN_MANAGERS__) {
86
- globalThis.__ZEN_MANAGERS__ = managers;
87
- }
88
-
89
77
  /**
90
78
  * Function getCircularReplacer() : Reduce circular references.
91
79
  *
@@ -445,6 +433,27 @@ __proto__: null,
445
433
  Logger: Logger
446
434
  });
447
435
 
436
+ class CommandAlreadyRegistered extends Error {
437
+ constructor(command) {
438
+ super(`Command: '${command.getName()}' is already registered`);
439
+ }
440
+ }
441
+
442
+ /**
443
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
444
+ */
445
+ class CommandNotFound extends Error {
446
+ constructor(command) {
447
+ super(`Command: '${command}' is not found`);
448
+ }
449
+ }
450
+
451
+ class ControllerAlreadyRegistered extends Error {
452
+ constructor(controller) {
453
+ super(`Controller: '${controller.getName()}' is already registered`);
454
+ }
455
+ }
456
+
448
457
  class ForceMethodBase extends Error {
449
458
  constructor(className, methodName) {
450
459
  super(`ForeMethod implementation: at '${className}' method: '${methodName}'`);
@@ -456,6 +465,14 @@ class ForceMethod extends Error {
456
465
  }
457
466
  }
458
467
 
468
+ var index$4 = /*#__PURE__*/Object.freeze({
469
+ __proto__: null,
470
+ CommandAlreadyRegistered: CommandAlreadyRegistered,
471
+ CommandNotFound: CommandNotFound,
472
+ ControllerAlreadyRegistered: ControllerAlreadyRegistered,
473
+ ForceMethod: ForceMethod
474
+ });
475
+
459
476
  /**
460
477
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
461
478
  * @description: is base class/object for all classes, responsible for: 'getName', implementation.
@@ -481,76 +498,6 @@ function APIIncreaseIdCounter() {
481
498
  return IdCounter++;
482
499
  }
483
500
 
484
- /**
485
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
486
- * @description: Responsible for commands, Aka ( CommandsSpace ).
487
- */
488
- class Controller extends ObjectBase {
489
- commands;
490
- data;
491
- internal;
492
- static getName() {
493
- return 'Core/Core/Controller';
494
- }
495
- constructor() {
496
- super();
497
- this.initialize();
498
- }
499
- initialize() {
500
- this.register();
501
- this.setupHooks && this.setupHooks();
502
- }
503
- register() {
504
- this.commands = __ZEN_MANAGERS__.commands.register(this.getCommands(), this);
505
- this.data = __ZEN_MANAGERS__.data.register(this.getData(), this);
506
- this.internal = __ZEN_MANAGERS__.internal.register(this.getInternal(), this);
507
- }
508
- getCommands() {
509
- return {};
510
- }
511
- getData() {
512
- return {};
513
- }
514
- getInternal() {
515
- return {};
516
- }
517
- }
518
-
519
- var index$4 = /*#__PURE__*/Object.freeze({
520
- __proto__: null,
521
- Controller: Controller,
522
- ObjectBase: ObjectBase
523
- });
524
-
525
- class CommandAlreadyRegistered extends Error {
526
- constructor(command) {
527
- super(`Command: '${command.getName()}' is already registered`);
528
- }
529
- }
530
-
531
- /**
532
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
533
- */
534
- class CommandNotFound extends Error {
535
- constructor(command) {
536
- super(`Command: '${command}' is not found`);
537
- }
538
- }
539
-
540
- class ControllerAlreadyRegistered extends Error {
541
- constructor(controller) {
542
- super(`Controller: '${controller.getName()}' is already registered`);
543
- }
544
- }
545
-
546
- var index$3 = /*#__PURE__*/Object.freeze({
547
- __proto__: null,
548
- CommandAlreadyRegistered: CommandAlreadyRegistered,
549
- CommandNotFound: CommandNotFound,
550
- ControllerAlreadyRegistered: ControllerAlreadyRegistered,
551
- ForceMethod: ForceMethod
552
- });
553
-
554
501
  /**
555
502
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
556
503
  * @description: Responsible for manging/running/hooking commands.
@@ -918,33 +865,40 @@ class Internal extends Commands {
918
865
  */
919
866
  const afterInitializeCallbacks = [];
920
867
  function initialize(config) {
921
- __ZEN_MANAGERS__.commands = new Commands();
922
- __ZEN_MANAGERS__.controllers = new Controllers();
923
- __ZEN_MANAGERS__.data = new Data(config);
924
- __ZEN_MANAGERS__.internal = new Internal();
868
+ commands = new Commands();
869
+ controllers = new Controllers();
870
+ data = new Data(config);
871
+ internal = new Internal();
925
872
  }
926
873
  function destroy() {
927
- __ZEN_MANAGERS__.commands = {};
928
- __ZEN_MANAGERS__.controllers = {};
929
- __ZEN_MANAGERS__.data = {};
930
- __ZEN_MANAGERS__.internal = {};
874
+ commands = {};
875
+ controllers = {};
876
+ data = {};
877
+ internal = {};
931
878
  }
932
- const controllers = __ZEN_MANAGERS__.controllers;
933
- const commands = __ZEN_MANAGERS__.commands;
934
- const data = __ZEN_MANAGERS__.data;
935
- const internal = __ZEN_MANAGERS__.internal;
879
+ var commands = {};
880
+ var controllers = {};
881
+ var data = {};
882
+ var internal = {};
883
+ /*
936
884
  __ZEN_MANAGERS__.initialize = initialize;
937
885
  __ZEN_MANAGERS__.destroy = destroy;
938
886
 
939
- var index$2 = /*#__PURE__*/Object.freeze({
887
+ export var commands = __ZEN_MANAGERS__.commands;
888
+ export var controllers = __ZEN_MANAGERS__.controllers;
889
+ export var data = __ZEN_MANAGERS__.data;
890
+ export var internal = __ZEN_MANAGERS__.internal;
891
+ */
892
+
893
+ var index$3 = /*#__PURE__*/Object.freeze({
940
894
  __proto__: null,
941
895
  afterInitializeCallbacks: afterInitializeCallbacks,
942
- commands: commands,
943
- controllers: controllers,
944
- data: data,
896
+ get commands () { return commands; },
897
+ get controllers () { return controllers; },
898
+ get data () { return data; },
945
899
  destroy: destroy,
946
900
  initialize: initialize,
947
- internal: internal
901
+ get internal () { return internal; }
948
902
  });
949
903
 
950
904
  /**
@@ -1022,7 +976,7 @@ class CommandData extends CommandBase {
1022
976
  }
1023
977
  apply(args = this.args, options = this.options) {
1024
978
  const endpoint = this.applyEndpointFormat(this.getEndpoint(), args);
1025
- return __ZEN_MANAGERS__.data.getClient().fetch(endpoint, __ZEN_MANAGERS__.data.currentHttpMethod, args || null);
979
+ return data.getClient().fetch(endpoint, data.currentHttpMethod, args || null);
1026
980
  }
1027
981
  applyEndpointFormat(endpoint, data = {}) {
1028
982
  // Replace query with `magic` placeholders.
@@ -1053,7 +1007,7 @@ class CommandInternal extends CommandBase {
1053
1007
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
1054
1008
  */
1055
1009
 
1056
- var index$1 = /*#__PURE__*/Object.freeze({
1010
+ var index$2 = /*#__PURE__*/Object.freeze({
1057
1011
  __proto__: null,
1058
1012
  CommandBase: CommandBase,
1059
1013
  CommandData: CommandData,
@@ -1061,6 +1015,47 @@ CommandInternal: CommandInternal,
1061
1015
  CommandPublic: CommandPublic
1062
1016
  });
1063
1017
 
1018
+ /**
1019
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
1020
+ * @description: Responsible for commands, Aka ( CommandsSpace ).
1021
+ */
1022
+ class Controller extends ObjectBase {
1023
+ commands;
1024
+ data;
1025
+ internal;
1026
+ static getName() {
1027
+ return 'Core/Core/Controller';
1028
+ }
1029
+ constructor() {
1030
+ super();
1031
+ this.initialize();
1032
+ }
1033
+ initialize() {
1034
+ this.register();
1035
+ this.setupHooks && this.setupHooks();
1036
+ }
1037
+ register() {
1038
+ this.commands = commands.register(this.getCommands(), this);
1039
+ this.data = data.register(this.getData(), this);
1040
+ this.internal = internal.register(this.getInternal(), this);
1041
+ }
1042
+ getCommands() {
1043
+ return {};
1044
+ }
1045
+ getData() {
1046
+ return {};
1047
+ }
1048
+ getInternal() {
1049
+ return {};
1050
+ }
1051
+ }
1052
+
1053
+ var index$1 = /*#__PURE__*/Object.freeze({
1054
+ __proto__: null,
1055
+ Controller: Controller,
1056
+ ObjectBase: ObjectBase
1057
+ });
1058
+
1064
1059
  /**
1065
1060
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
1066
1061
  */
@@ -1079,11 +1074,11 @@ Internal: Internal
1079
1074
 
1080
1075
  var exported = /*#__PURE__*/Object.freeze({
1081
1076
  __proto__: null,
1082
- commandBases: index$1,
1083
- core: index$4,
1084
- errors: index$3,
1077
+ commandBases: index$2,
1078
+ core: index$1,
1079
+ errors: index$4,
1085
1080
  managerBases: index,
1086
- managers: index$2,
1081
+ managers: index$3,
1087
1082
  modules: index$5,
1088
1083
  utils: index$6
1089
1084
  });
@@ -1118,11 +1113,11 @@ const CoreAPI = {
1118
1113
  // TODO: Make it available only for development.
1119
1114
  if (!globalThis?.ZenCore) globalThis.ZenCore = CoreAPI;
1120
1115
 
1121
- exports.commandBases = index$1;
1122
- exports.core = index$4;
1116
+ exports.commandBases = index$2;
1117
+ exports.core = index$1;
1123
1118
  exports.default = CoreAPI;
1124
- exports.errors = index$3;
1119
+ exports.errors = index$4;
1125
1120
  exports.managerBases = index;
1126
- exports.managers = index$2;
1121
+ exports.managers = index$3;
1127
1122
  exports.modules = index$5;
1128
1123
  exports.utils = index$6;
@@ -1,9 +1,3 @@
1
- import { IManagers } from "./interfaces/managers";
2
- declare const managers: IManagers;
3
1
  declare global {
4
2
  var ZenCore: any;
5
3
  }
6
- declare global {
7
- var __ZEN_MANAGERS__: typeof managers;
8
- }
9
- export {};
@@ -1,6 +1,9 @@
1
1
  import './globals';
2
2
  import { IAPIConfig } from "./interfaces/config";
3
3
  import * as exported from './exports';
4
+ declare global {
5
+ var ZenCore: any;
6
+ }
4
7
  export declare let config: IAPIConfig;
5
8
  export declare const CoreAPI: {
6
9
  commandBases: typeof exported.commandBases;
@@ -4,7 +4,8 @@
4
4
  */
5
5
  import { Logger } from "../modules/";
6
6
  import { CommandBase } from "../command-bases";
7
- import { Controller, ObjectBase } from "../core";
7
+ import ObjectBase from "../core/object-base";
8
+ import Controller from "../core/controller";
8
9
  import { ICommandArgsInterface, CommandCallbackType, IOnHookAffectInterface, IOnHookInterface } from "../interfaces/commands";
9
10
  export declare class Commands extends ObjectBase {
10
11
  static readonly trace: string[];
@@ -2,7 +2,8 @@
2
2
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
3
3
  * @description: Responsible for manging controllers, each controller is global singleton instance.
4
4
  */
5
- import { Controller, ObjectBase } from "../core";
5
+ import ObjectBase from "../core/object-base";
6
+ import Controller from "../core/controller";
6
7
  export declare class Controllers extends ObjectBase {
7
8
  controllers: {
8
9
  [key: string]: Controller;
@@ -10,7 +10,7 @@ import '../globals';
10
10
  export declare const afterInitializeCallbacks: (() => void)[];
11
11
  export declare function initialize(config: IAPIConfig): void;
12
12
  export declare function destroy(): void;
13
- export declare const controllers: Controllers;
14
- export declare const commands: Commands;
15
- export declare const data: Data;
16
- export declare const internal: Internal;
13
+ export declare var commands: Commands;
14
+ export declare var controllers: Controllers;
15
+ export declare var data: Data;
16
+ export declare var internal: Internal;
@@ -1,5 +1,5 @@
1
1
  var name = "@zenflux/core";
2
- var version = "0.0.0-abc.14";
2
+ var version = "0.0.0-abc.20";
3
3
  var description = "ZenFlux core";
4
4
  var author = "Leonid Vinikov <leonidvinikov@gmail.com> (https://github.com/iNewLegend)";
5
5
  var scripts = {
@@ -70,18 +70,6 @@ var pkg = {
70
70
  dependencies: dependencies
71
71
  };
72
72
 
73
- const managers = {
74
- initialize: () => {},
75
- destroy: () => {},
76
- commands: {},
77
- controllers: {},
78
- data: {},
79
- internal: {}
80
- };
81
- if (typeof __ZEN_MANAGERS__ === 'undefined' || !__ZEN_MANAGERS__) {
82
- globalThis.__ZEN_MANAGERS__ = managers;
83
- }
84
-
85
73
  /**
86
74
  * Function getCircularReplacer() : Reduce circular references.
87
75
  *
@@ -441,6 +429,27 @@ __proto__: null,
441
429
  Logger: Logger
442
430
  });
443
431
 
432
+ class CommandAlreadyRegistered extends Error {
433
+ constructor(command) {
434
+ super(`Command: '${command.getName()}' is already registered`);
435
+ }
436
+ }
437
+
438
+ /**
439
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
440
+ */
441
+ class CommandNotFound extends Error {
442
+ constructor(command) {
443
+ super(`Command: '${command}' is not found`);
444
+ }
445
+ }
446
+
447
+ class ControllerAlreadyRegistered extends Error {
448
+ constructor(controller) {
449
+ super(`Controller: '${controller.getName()}' is already registered`);
450
+ }
451
+ }
452
+
444
453
  class ForceMethodBase extends Error {
445
454
  constructor(className, methodName) {
446
455
  super(`ForeMethod implementation: at '${className}' method: '${methodName}'`);
@@ -452,6 +461,14 @@ class ForceMethod extends Error {
452
461
  }
453
462
  }
454
463
 
464
+ var index$4 = /*#__PURE__*/Object.freeze({
465
+ __proto__: null,
466
+ CommandAlreadyRegistered: CommandAlreadyRegistered,
467
+ CommandNotFound: CommandNotFound,
468
+ ControllerAlreadyRegistered: ControllerAlreadyRegistered,
469
+ ForceMethod: ForceMethod
470
+ });
471
+
455
472
  /**
456
473
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
457
474
  * @description: is base class/object for all classes, responsible for: 'getName', implementation.
@@ -477,76 +494,6 @@ function APIIncreaseIdCounter() {
477
494
  return IdCounter++;
478
495
  }
479
496
 
480
- /**
481
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
482
- * @description: Responsible for commands, Aka ( CommandsSpace ).
483
- */
484
- class Controller extends ObjectBase {
485
- commands;
486
- data;
487
- internal;
488
- static getName() {
489
- return 'Core/Core/Controller';
490
- }
491
- constructor() {
492
- super();
493
- this.initialize();
494
- }
495
- initialize() {
496
- this.register();
497
- this.setupHooks && this.setupHooks();
498
- }
499
- register() {
500
- this.commands = __ZEN_MANAGERS__.commands.register(this.getCommands(), this);
501
- this.data = __ZEN_MANAGERS__.data.register(this.getData(), this);
502
- this.internal = __ZEN_MANAGERS__.internal.register(this.getInternal(), this);
503
- }
504
- getCommands() {
505
- return {};
506
- }
507
- getData() {
508
- return {};
509
- }
510
- getInternal() {
511
- return {};
512
- }
513
- }
514
-
515
- var index$4 = /*#__PURE__*/Object.freeze({
516
- __proto__: null,
517
- Controller: Controller,
518
- ObjectBase: ObjectBase
519
- });
520
-
521
- class CommandAlreadyRegistered extends Error {
522
- constructor(command) {
523
- super(`Command: '${command.getName()}' is already registered`);
524
- }
525
- }
526
-
527
- /**
528
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
529
- */
530
- class CommandNotFound extends Error {
531
- constructor(command) {
532
- super(`Command: '${command}' is not found`);
533
- }
534
- }
535
-
536
- class ControllerAlreadyRegistered extends Error {
537
- constructor(controller) {
538
- super(`Controller: '${controller.getName()}' is already registered`);
539
- }
540
- }
541
-
542
- var index$3 = /*#__PURE__*/Object.freeze({
543
- __proto__: null,
544
- CommandAlreadyRegistered: CommandAlreadyRegistered,
545
- CommandNotFound: CommandNotFound,
546
- ControllerAlreadyRegistered: ControllerAlreadyRegistered,
547
- ForceMethod: ForceMethod
548
- });
549
-
550
497
  /**
551
498
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
552
499
  * @description: Responsible for manging/running/hooking commands.
@@ -914,33 +861,40 @@ class Internal extends Commands {
914
861
  */
915
862
  const afterInitializeCallbacks = [];
916
863
  function initialize(config) {
917
- __ZEN_MANAGERS__.commands = new Commands();
918
- __ZEN_MANAGERS__.controllers = new Controllers();
919
- __ZEN_MANAGERS__.data = new Data(config);
920
- __ZEN_MANAGERS__.internal = new Internal();
864
+ commands = new Commands();
865
+ controllers = new Controllers();
866
+ data = new Data(config);
867
+ internal = new Internal();
921
868
  }
922
869
  function destroy() {
923
- __ZEN_MANAGERS__.commands = {};
924
- __ZEN_MANAGERS__.controllers = {};
925
- __ZEN_MANAGERS__.data = {};
926
- __ZEN_MANAGERS__.internal = {};
870
+ commands = {};
871
+ controllers = {};
872
+ data = {};
873
+ internal = {};
927
874
  }
928
- const controllers = __ZEN_MANAGERS__.controllers;
929
- const commands = __ZEN_MANAGERS__.commands;
930
- const data = __ZEN_MANAGERS__.data;
931
- const internal = __ZEN_MANAGERS__.internal;
875
+ var commands = {};
876
+ var controllers = {};
877
+ var data = {};
878
+ var internal = {};
879
+ /*
932
880
  __ZEN_MANAGERS__.initialize = initialize;
933
881
  __ZEN_MANAGERS__.destroy = destroy;
934
882
 
935
- var index$2 = /*#__PURE__*/Object.freeze({
883
+ export var commands = __ZEN_MANAGERS__.commands;
884
+ export var controllers = __ZEN_MANAGERS__.controllers;
885
+ export var data = __ZEN_MANAGERS__.data;
886
+ export var internal = __ZEN_MANAGERS__.internal;
887
+ */
888
+
889
+ var index$3 = /*#__PURE__*/Object.freeze({
936
890
  __proto__: null,
937
891
  afterInitializeCallbacks: afterInitializeCallbacks,
938
- commands: commands,
939
- controllers: controllers,
940
- data: data,
892
+ get commands () { return commands; },
893
+ get controllers () { return controllers; },
894
+ get data () { return data; },
941
895
  destroy: destroy,
942
896
  initialize: initialize,
943
- internal: internal
897
+ get internal () { return internal; }
944
898
  });
945
899
 
946
900
  /**
@@ -1018,7 +972,7 @@ class CommandData extends CommandBase {
1018
972
  }
1019
973
  apply(args = this.args, options = this.options) {
1020
974
  const endpoint = this.applyEndpointFormat(this.getEndpoint(), args);
1021
- return __ZEN_MANAGERS__.data.getClient().fetch(endpoint, __ZEN_MANAGERS__.data.currentHttpMethod, args || null);
975
+ return data.getClient().fetch(endpoint, data.currentHttpMethod, args || null);
1022
976
  }
1023
977
  applyEndpointFormat(endpoint, data = {}) {
1024
978
  // Replace query with `magic` placeholders.
@@ -1049,7 +1003,7 @@ class CommandInternal extends CommandBase {
1049
1003
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
1050
1004
  */
1051
1005
 
1052
- var index$1 = /*#__PURE__*/Object.freeze({
1006
+ var index$2 = /*#__PURE__*/Object.freeze({
1053
1007
  __proto__: null,
1054
1008
  CommandBase: CommandBase,
1055
1009
  CommandData: CommandData,
@@ -1057,6 +1011,47 @@ CommandInternal: CommandInternal,
1057
1011
  CommandPublic: CommandPublic
1058
1012
  });
1059
1013
 
1014
+ /**
1015
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
1016
+ * @description: Responsible for commands, Aka ( CommandsSpace ).
1017
+ */
1018
+ class Controller extends ObjectBase {
1019
+ commands;
1020
+ data;
1021
+ internal;
1022
+ static getName() {
1023
+ return 'Core/Core/Controller';
1024
+ }
1025
+ constructor() {
1026
+ super();
1027
+ this.initialize();
1028
+ }
1029
+ initialize() {
1030
+ this.register();
1031
+ this.setupHooks && this.setupHooks();
1032
+ }
1033
+ register() {
1034
+ this.commands = commands.register(this.getCommands(), this);
1035
+ this.data = data.register(this.getData(), this);
1036
+ this.internal = internal.register(this.getInternal(), this);
1037
+ }
1038
+ getCommands() {
1039
+ return {};
1040
+ }
1041
+ getData() {
1042
+ return {};
1043
+ }
1044
+ getInternal() {
1045
+ return {};
1046
+ }
1047
+ }
1048
+
1049
+ var index$1 = /*#__PURE__*/Object.freeze({
1050
+ __proto__: null,
1051
+ Controller: Controller,
1052
+ ObjectBase: ObjectBase
1053
+ });
1054
+
1060
1055
  /**
1061
1056
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
1062
1057
  */
@@ -1075,11 +1070,11 @@ Internal: Internal
1075
1070
 
1076
1071
  var exported = /*#__PURE__*/Object.freeze({
1077
1072
  __proto__: null,
1078
- commandBases: index$1,
1079
- core: index$4,
1080
- errors: index$3,
1073
+ commandBases: index$2,
1074
+ core: index$1,
1075
+ errors: index$4,
1081
1076
  managerBases: index,
1082
- managers: index$2,
1077
+ managers: index$3,
1083
1078
  modules: index$5,
1084
1079
  utils: index$6
1085
1080
  });
@@ -1114,4 +1109,4 @@ const CoreAPI = {
1114
1109
  // TODO: Make it available only for development.
1115
1110
  if (!globalThis?.ZenCore) globalThis.ZenCore = CoreAPI;
1116
1111
 
1117
- export { index$1 as commandBases, index$4 as core, CoreAPI as default, index$3 as errors, index as managerBases, index$2 as managers, index$5 as modules, index$6 as utils };
1112
+ export { index$2 as commandBases, index$1 as core, CoreAPI as default, index$4 as errors, index as managerBases, index$3 as managers, index$5 as modules, index$6 as utils };
@@ -1,11 +1,12 @@
1
- var t="0.0.0-abc.14";"undefined"!=typeof __ZEN_MANAGERS__&&__ZEN_MANAGERS__||(globalThis.__ZEN_MANAGERS__={initialize:()=>{},destroy:()=>{},commands:{},controllers:{},data:{},internal:{}})
1
+ var t="0.0.0-abc.20";
2
2
  /**
3
3
  * Function getCircularReplacer() : Reduce circular references.
4
4
  *
5
5
  * @copyright https://stackoverflow.com/a/53731154
6
- */;const e=()=>{const t=new WeakSet;return(e,r)=>{if("object"==typeof r&&null!==r){if(t.has(r))return;t.add(r)}return r}},r=function(t,e){t=t.replace("#",""),e=e.replace("#","");const r=parseInt(t.substring(0,2),16),s=parseInt(t.substring(2,4),16),n=parseInt(t.substring(4,6),16),o=parseInt(e.substring(0,2),16),a=parseInt(e.substring(2,4),16),i=parseInt(e.substring(4,6),16);let c=255-Math.abs(r-o),l=255-Math.abs(s-a),h=255-Math.abs(n-i);return c/=255,l/=255,h/=255,(c+l+h)/3};
6
+ */
7
+ const e=()=>{const t=new WeakSet;return(e,r)=>{if("object"==typeof r&&null!==r){if(t.has(r))return;t.add(r)}return r}},r=function(t,e){t=t.replace("#",""),e=e.replace("#","");const r=parseInt(t.substring(0,2),16),s=parseInt(t.substring(2,4),16),n=parseInt(t.substring(4,6),16),o=parseInt(e.substring(0,2),16),a=parseInt(e.substring(2,4),16),i=parseInt(e.substring(4,6),16);let c=255-Math.abs(r-o),l=255-Math.abs(s-a),h=255-Math.abs(n-i);return c/=255,l/=255,h/=255,(c+l+h)/3};
7
8
  /**
8
9
  * Function hexColorDelta() : Return color difference in ratio decimal point.
9
10
  *
10
11
  * @copyright http://jsfiddle.net/96sME/
11
- */var s=Object.freeze({__proto__:null,getCircularReplacer:e,hexColorDelta:r});class n{static wrappers={};static wrapperDepth=0;static sharedData={};static colorsInUse=[];defaultStyle;color;outputHandler;args={};name;state=!1;static getName(){return"Core/Modules/Logger"}static reset(){n.wrappers={},n.wrapperDepth=0,n.colorsInUse=[],n.sharedData={}}static createCustomWrapper(t,e){n.wrappers[t]||(n.wrappers[t.name]=[]),n.wrappers[t.name].push({classType:t,callback:e})}static getCallerName(){const t=Error(),e=t.stack?t.stack.split("\n")[3].trim():"_UNKNOWN_CALLER_NAME_";return e.startsWith("at new")?"constructor":e.split(".")[1].split(" ")[0]}static getFunctionView(t){let e="anonymous function()";return"string"!=typeof t&&0!==t.name.length&&(e=t.name.split(" ")[1]+"()"),e}constructor(t,e=!1,r={}){"off"!==globalThis.process?.env.flow_modules_logger&&(this.state=e,this.args=r,this.name="",this.name="string"==typeof t?t:t.constructor.name,e&&this.initialize())}initialize(){this.args.sameColor?(n.sharedData[this.name]||(n.sharedData[this.name]=this.getRandomColor()),this.color=n.sharedData[this.name]):(this.color=this.getRandomColor(),n.colorsInUse.push(this.color)),this.outputHandler=console.log,this.defaultStyle=["color: grey;font-size:7px","display: block","color: "+this.color,"color: grey","font-weight: bold","color: #607D8B","font-size: 16px;color: red;font-weight:800"]}setOutputHandler(t){this.outputHandler=t}useWrapper(t,e=!0){if(!t||"object"!=typeof t||Array.isArray(t))return t;n.wrapperDepth++;let r={...t};return Object.values(n.wrappers).forEach((([e])=>{t instanceof e.classType&&(r=e.callback(t)||r)})),4>n.wrapperDepth?(e&&r&&Object.entries(r).forEach((([t,e])=>{r[t]=this.useWrapper(e,!0)})),n.wrapperDepth--,r):(n.wrapperDepth--,r)}startEmpty(t=""){this.state&&this.printFunctionNotify("se",n.getCallerName(),t)}startWith(t){if(!this.state)return;t=Object.assign({},t);const e="se",r=n.getCallerName();if("string"==typeof t)this.printInLineString(e,r,t);else if(1===Object.keys(t).length){const s=Object.keys(t)[0];let n=Object.values(t)[0];"object"==typeof n?this.printNextLineObject(e,r,s,n||{}):"function"==typeof n?this.printInLineFunction(e,r,s,n):this.printInLineElement(e,r,s,n)}else this.printMultiLineObject(e,r,t)}object(t={},r=""){if(!this.state)return;const s=n.getCallerName();t=Object.create(t);for(let n in t)"object"==typeof t[n]&&(t[n]=JSON.stringify(this.useWrapper(t[n]),e())),this.out.apply(this,[`%c(ob)-> %c%c${this.name}%c::%c${s}%c() [${r}] ->> ${n}: '${t[n]}'%c`].concat(this.defaultStyle))}debug(t){this.state&&this.printFunctionNotify("db",n.getCallerName(),t)}drop(t,e){if(!this.state)return;const r=n.getCallerName();for(let e in t)this.out.apply(this,[`%c(dr)-> %c%c${this.name}%c::%c${r}%c() ->> corresponding ${e}: '${t[e]}' RESULT: %c↓`].concat(this.defaultStyle));this.out(e)}throw(t,e="null",r={}){throw this.printFunctionNotify("tw",n.getCallerName(),t),r&&this.printNextLineObject("tw",n.getCallerName(),e,r),Error().stack}clone(){return Object.assign(Object.create(Object.getPrototypeOf(this)),this)}printFunctionNotify(t,e,r){this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c() ${r}%c`].concat(this.defaultStyle))}printInLineElement(t,e,r,s){this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c() ->> ${r}: '${s}'%c`].concat(this.defaultStyle))}printInLineFunction(t,e,r,s){s=n.getFunctionView(s),this.printInLineElement(t,e,r,s)}printInLineString(t,e,r){this.printInLineElement(t,e,"(string)",r)}printNextLineObject(t,e,r,s){s=this.useWrapper(s),this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c() ->> ${r} %c↓`].concat(this.defaultStyle)),this.out(s)}printMultiLineObject(t,r,s){this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${r}%c(${Object.keys(s).join(", ")}) %c↓`].concat(this.defaultStyle));for(let t in s){let r=s[t];"object"==typeof r?r=JSON.stringify(this.useWrapper(r),e()):"function"==typeof s[t]&&(r=n.getFunctionView(r)),this.out.call(this,"%c"+t+": `"+this.useWrapper(r)+"`","color: #a3a3a3")}}getRandomColor(){let t="#";for(let e=0;6>e;e++)t+="0123456789ABCDEF"[Math.floor(16*Math.random())];return n.colorsInUse.some((e=>r(t,e)>=.8))?this.getRandomColor():t}out(...t){this.outputHandler.apply(this,t)}}var o=Object.freeze({__proto__:null,Logger:n});class a extends Error{constructor(t,e){super(`ForeMethod implementation: at '${t}' method: '${e}'`)}}class i extends Error{constructor(t,e){super(`ForeMethod implementation: at '${t.getName()}' method: '${e}'`)}}let c=0;class l{virtualId=0;static getName(){throw new a("ObjectBase","getName")}constructor(){this.virtualId=c,c++}getName(){return this.constructor.getName()}}var h=Object.freeze({__proto__:null,Controller:class extends l{commands;data;internal;static getName(){return"Core/Core/Controller"}constructor(){super(),this.initialize()}initialize(){this.register(),this.setupHooks&&this.setupHooks()}register(){this.commands=__ZEN_MANAGERS__.commands.register(this.getCommands(),this),this.data=__ZEN_MANAGERS__.data.register(this.getData(),this),this.internal=__ZEN_MANAGERS__.internal.register(this.getInternal(),this)}getCommands(){return{}}getData(){return{}}getInternal(){return{}}},ObjectBase:l});class u extends Error{constructor(t){super(`Command: '${t.getName()}' is already registered`)}}class p extends Error{constructor(t){super(`Command: '${t}' is not found`)}}class g extends Error{constructor(t){super(`Controller: '${t.getName()}' is already registered`)}}var m,d=Object.freeze({__proto__:null,CommandAlreadyRegistered:u,CommandNotFound:p,ControllerAlreadyRegistered:g,ForceMethod:i});class _ extends l{static trace=[];current={};currentArgs={};trace=[];commands={};onBeforeHooks={};onBeforeUIHooks={};onAfterHooks={};onAfterOnceHooks={};onAfterUIHooks={};onAfterAffectHooks={};logger;static getName(){return"Core/Managers/Commands"}static async runCallbacks(t,e={},r={}){const s=t?.length||0;for(let n=0;s>n;++n){const s=!0===r.pop?t.pop():t[n];if(!s)throw Error("Callback is not defined.");await s(e,r)}}static hookCommand(t,e,r){t[e]||(t[e]=[]),t[e].push(r)}constructor(){super(),this.logger=new n(this.getName(),!0),this.logger.startEmpty()}async run(t,e={},r={}){"string"==typeof t&&(t=this.getCommandInstance(t,e,r)),this.attachCurrent(t,e);const s=await this.runInstance(t,e,r);return this.detachCurrent(t),s}register(t,e){const r={};return Object.values(t).forEach((t=>{const e=t.getName();if(this.commands[e])throw new u(t);this.commands[e]=t,r[e]=t})),r}getAll(){return this.commands}getByName(t){return this.commands[t]}getLogger(){return this.logger}getCommandInstance(t,e={},r={}){const s=this.commands[t];if(!s)throw new p(t);return new s(e,r)}onBefore(t,e){_.hookCommand(this.onBeforeHooks,t,e)}onBeforeUI(t,e){_.hookCommand(this.onBeforeUIHooks,t,e)}onAfter(t,e){_.hookCommand(this.onAfterHooks,t,e)}onAfterUI(t,e){_.hookCommand(this.onAfterUIHooks,t,e)}onAfterOnce(t,e){_.hookCommand(this.onAfterOnceHooks,t,e)}onAfterAffect(t,e){_.hookCommand(this.onAfterAffectHooks,t,e)}onBeforeRun(t,e={},r={}){if(this.onBeforeHooks[t.getName()]){this.onBeforeHooks[t.getName()].forEach((t=>t(e,r)))}if(this.onBeforeUIHooks[t.getName()]){this.onBeforeUIHooks[t.getName()].forEach((t=>t(e,r)))}}async runInstance(t,e={},r={}){let s=null;return Object.keys(e).length?(this.logger.startWith({command:t.getName(),options:r,CommandArgs:"->"}),this.logger.debug("CommandArgs:"),this.logger.object(e)):this.logger.startWith({command:t.getName(),options:r,args:e}),this.onBeforeRun(t,e,r),s=await t.run(),await this.onAfterRun(t,e,r,s),s}async onAfterRun(t,e,r,s){return r=Object.assign({},r),this.onAfterAffectHooks[t.getName()]&&(this.onAfterAffectHooks[t.getName()].forEach((t=>{e.result=s,s=this.run(""+t,e,r)})),s=await s),this.onAfterHooks&&(e.result=s,await _.runCallbacks(Object.assign([],this.onAfterHooks[t.getName()]),e,r)),this.onAfterOnceHooks&&await _.runCallbacks(this.onAfterOnceHooks[t.getName()],e,{...r,pop:!0}),this.onAfterUIHooks&&_.runCallbacks(Object.assign([],this.onAfterUIHooks[t.getName()]),e,r),s}attachCurrent(t,e={}){this.current[t.getName()]=t,this.currentArgs[t.getName()]=e,this.trace.push(t.getName()),_.trace.push(t.getName())}detachCurrent(t){delete this.current[t.getName()],delete this.currentArgs[t.getName()],_.trace.pop(),this.trace.pop()}}class f extends l{controllers={};static getName(){return"Core/Managers/Controllers"}get(t){return this.controllers[t]}getAll(){return this.controllers}register(t){if(this.controllers[t.getName()])throw new g(t);return this.controllers[t.getName()]=t,t}}!function(t){t.DELETE="DELETE",t.GET="GET",t.OPTIONS="OPTIONS",t.PATCH="PATCH",t.POST="POST",t.PUT="PUT",t.__EMPTY__=""}(m||(m={}));class N extends l{logger;apiBaseUrl;static getName(){return"Core/Clients/Http"}constructor(t="http://localhost"){super(),this.logger=new n(N.getName(),!0),this.logger.startWith({apiBaseUrl:t}),this.apiBaseUrl=t+"/"}async fetch(t,e,r=null){this.logger.startWith({path:t,method:e,body:r});const s={credentials:"include"},n={};[m.POST,m.PUT,m.PATCH].includes(e)?(Object.assign(n,{"Content-Type":"application/json"}),Object.assign(s,{method:e,headers:n,body:JSON.stringify(r)})):Object.assign(s,{headers:n});const o=await globalThis.fetch(this.apiBaseUrl+t,s);let a;try{a=await o.json()}catch(t){return console.error(t),!1}if(a?.error&&a?.global&&a?.message)throw Error(a.message);return this.logger.drop({path:t},a),a}}class A extends _{static client;currentHttpMethod;static getName(){return"Core/Managers/Data"}constructor(t){super(),A.client=new N(t.baseURL)}getClient(){return A.client}get(t,e={},r={}){return this.currentHttpMethod=m.GET,super.run(t,e,r)}update(t,e={},r={}){return this.currentHttpMethod=m.PATCH,super.run(t,e,r)}delete(t,e={},r={}){return this.currentHttpMethod=m.DELETE,super.run(t,e,r)}create(t,e={},r={}){return this.currentHttpMethod=m.POST,super.run(t,e,r)}async runInstance(t,e={},r={}){if(!this.currentHttpMethod)throw Error('Cannot run directly use one of the http methods: "get", "update", "delete, "create');const s={type:this.currentHttpMethod,args:{query:{},data:{}}};return m.GET===this.currentHttpMethod?s.args.query=e:s.args.data=e,e.result=await super.runInstance(t,s,r),this.currentHttpMethod=m.__EMPTY__,e.result}}class E extends _{static getName(){return"Core/Managers/Internal"}}const C=[];function y(t){__ZEN_MANAGERS__.commands=new _,__ZEN_MANAGERS__.controllers=new f,__ZEN_MANAGERS__.data=new A(t),__ZEN_MANAGERS__.internal=new E}function b(){__ZEN_MANAGERS__.commands={},__ZEN_MANAGERS__.controllers={},__ZEN_MANAGERS__.data={},__ZEN_MANAGERS__.internal={}}const w=__ZEN_MANAGERS__.controllers,O=__ZEN_MANAGERS__.commands,k=__ZEN_MANAGERS__.data,M=__ZEN_MANAGERS__.internal;__ZEN_MANAGERS__.initialize=y,__ZEN_MANAGERS__.destroy=b;var H=Object.freeze({__proto__:null,afterInitializeCallbacks:C,commands:O,controllers:w,data:k,destroy:b,initialize:y,internal:M});class I extends l{args={};options={};logger;constructor(t={},e={}){super();const r=this.constructor.getName();this.logger=new n(r,!0,{sameColor:!0}),this.logger.startWith({args:t,options:e}),this.initialize(t,e)}initialize(t,e){this.args=t,this.options=e}apply(t=this.args,e=this.options){throw new i(this,"apply")}async run(){this.onBeforeApply&&this.onBeforeApply();const t=await this.apply(this.args,this.options);return this.onAfterApply&&this.onAfterApply(),t}getArgs(){return this.args}getOptions(){return this.options}}var j=Object.freeze({__proto__:null,CommandBase:I,CommandData:class extends I{static getName(){return"Core/CommandBases/CommandData"}getEndpoint(){throw new i(this,"getEndpoint")}apply(t=this.args,e=this.options){const r=this.applyEndpointFormat(this.getEndpoint(),t);return __ZEN_MANAGERS__.data.getClient().fetch(r,__ZEN_MANAGERS__.data.currentHttpMethod,t||null)}applyEndpointFormat(t,e={}){return t.includes("{")&&(t=t.split("/").map((t=>{const r=t.match("\\{(.*?)\\}");return r?.length&&void 0!==e[r[1]]?e[r[1]]:t})).join("/")),t}},CommandInternal:class extends I{static getName(){return"Core/CommandBases/CommandInternal"}},CommandPublic:class extends I{static getName(){return"Core/CommandBases/CommandPublic"}}}),S=Object.freeze({__proto__:null,Commands:_,Controllers:f,Data:A,Internal:E}),R=Object.freeze({__proto__:null,commandBases:j,core:h,errors:d,managerBases:S,managers:H,modules:o,utils:s});let $=!1;function B(){if($)throw Error("ZenCore is already initialized.")}B();let T={version:t};const G={initialize:t=>{B(),T=t||T,y(T),$=!0},destroy:()=>{b(),$=!1},onAfterInitialize:t=>{C.push(t)},config:T,...R};globalThis?.ZenCore||(globalThis.ZenCore=G);export{j as commandBases,h as core,G as default,d as errors,S as managerBases,H as managers,o as modules,s as utils};
12
+ */var s=Object.freeze({__proto__:null,getCircularReplacer:e,hexColorDelta:r});class n{static wrappers={};static wrapperDepth=0;static sharedData={};static colorsInUse=[];defaultStyle;color;outputHandler;args={};name;state=!1;static getName(){return"Core/Modules/Logger"}static reset(){n.wrappers={},n.wrapperDepth=0,n.colorsInUse=[],n.sharedData={}}static createCustomWrapper(t,e){n.wrappers[t]||(n.wrappers[t.name]=[]),n.wrappers[t.name].push({classType:t,callback:e})}static getCallerName(){const t=Error(),e=t.stack?t.stack.split("\n")[3].trim():"_UNKNOWN_CALLER_NAME_";return e.startsWith("at new")?"constructor":e.split(".")[1].split(" ")[0]}static getFunctionView(t){let e="anonymous function()";return"string"!=typeof t&&0!==t.name.length&&(e=t.name.split(" ")[1]+"()"),e}constructor(t,e=!1,r={}){"off"!==globalThis.process?.env.flow_modules_logger&&(this.state=e,this.args=r,this.name="",this.name="string"==typeof t?t:t.constructor.name,e&&this.initialize())}initialize(){this.args.sameColor?(n.sharedData[this.name]||(n.sharedData[this.name]=this.getRandomColor()),this.color=n.sharedData[this.name]):(this.color=this.getRandomColor(),n.colorsInUse.push(this.color)),this.outputHandler=console.log,this.defaultStyle=["color: grey;font-size:7px","display: block","color: "+this.color,"color: grey","font-weight: bold","color: #607D8B","font-size: 16px;color: red;font-weight:800"]}setOutputHandler(t){this.outputHandler=t}useWrapper(t,e=!0){if(!t||"object"!=typeof t||Array.isArray(t))return t;n.wrapperDepth++;let r={...t};return Object.values(n.wrappers).forEach((([e])=>{t instanceof e.classType&&(r=e.callback(t)||r)})),4>n.wrapperDepth?(e&&r&&Object.entries(r).forEach((([t,e])=>{r[t]=this.useWrapper(e,!0)})),n.wrapperDepth--,r):(n.wrapperDepth--,r)}startEmpty(t=""){this.state&&this.printFunctionNotify("se",n.getCallerName(),t)}startWith(t){if(!this.state)return;t=Object.assign({},t);const e="se",r=n.getCallerName();if("string"==typeof t)this.printInLineString(e,r,t);else if(1===Object.keys(t).length){const s=Object.keys(t)[0];let n=Object.values(t)[0];"object"==typeof n?this.printNextLineObject(e,r,s,n||{}):"function"==typeof n?this.printInLineFunction(e,r,s,n):this.printInLineElement(e,r,s,n)}else this.printMultiLineObject(e,r,t)}object(t={},r=""){if(!this.state)return;const s=n.getCallerName();t=Object.create(t);for(let n in t)"object"==typeof t[n]&&(t[n]=JSON.stringify(this.useWrapper(t[n]),e())),this.out.apply(this,[`%c(ob)-> %c%c${this.name}%c::%c${s}%c() [${r}] ->> ${n}: '${t[n]}'%c`].concat(this.defaultStyle))}debug(t){this.state&&this.printFunctionNotify("db",n.getCallerName(),t)}drop(t,e){if(!this.state)return;const r=n.getCallerName();for(let e in t)this.out.apply(this,[`%c(dr)-> %c%c${this.name}%c::%c${r}%c() ->> corresponding ${e}: '${t[e]}' RESULT: %c↓`].concat(this.defaultStyle));this.out(e)}throw(t,e="null",r={}){throw this.printFunctionNotify("tw",n.getCallerName(),t),r&&this.printNextLineObject("tw",n.getCallerName(),e,r),Error().stack}clone(){return Object.assign(Object.create(Object.getPrototypeOf(this)),this)}printFunctionNotify(t,e,r){this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c() ${r}%c`].concat(this.defaultStyle))}printInLineElement(t,e,r,s){this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c() ->> ${r}: '${s}'%c`].concat(this.defaultStyle))}printInLineFunction(t,e,r,s){s=n.getFunctionView(s),this.printInLineElement(t,e,r,s)}printInLineString(t,e,r){this.printInLineElement(t,e,"(string)",r)}printNextLineObject(t,e,r,s){s=this.useWrapper(s),this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c() ->> ${r} %c↓`].concat(this.defaultStyle)),this.out(s)}printMultiLineObject(t,r,s){this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${r}%c(${Object.keys(s).join(", ")}) %c↓`].concat(this.defaultStyle));for(let t in s){let r=s[t];"object"==typeof r?r=JSON.stringify(this.useWrapper(r),e()):"function"==typeof s[t]&&(r=n.getFunctionView(r)),this.out.call(this,"%c"+t+": `"+this.useWrapper(r)+"`","color: #a3a3a3")}}getRandomColor(){let t="#";for(let e=0;6>e;e++)t+="0123456789ABCDEF"[Math.floor(16*Math.random())];return n.colorsInUse.some((e=>r(t,e)>=.8))?this.getRandomColor():t}out(...t){this.outputHandler.apply(this,t)}}var o=Object.freeze({__proto__:null,Logger:n});class a extends Error{constructor(t){super(`Command: '${t.getName()}' is already registered`)}}class i extends Error{constructor(t){super(`Command: '${t}' is not found`)}}class c extends Error{constructor(t){super(`Controller: '${t.getName()}' is already registered`)}}class l extends Error{constructor(t,e){super(`ForeMethod implementation: at '${t}' method: '${e}'`)}}class h extends Error{constructor(t,e){super(`ForeMethod implementation: at '${t.getName()}' method: '${e}'`)}}var u=Object.freeze({__proto__:null,CommandAlreadyRegistered:a,CommandNotFound:i,ControllerAlreadyRegistered:c,ForceMethod:h});let p=0;class g{virtualId=0;static getName(){throw new l("ObjectBase","getName")}constructor(){this.virtualId=p,p++}getName(){return this.constructor.getName()}}class m extends g{static trace=[];current={};currentArgs={};trace=[];commands={};onBeforeHooks={};onBeforeUIHooks={};onAfterHooks={};onAfterOnceHooks={};onAfterUIHooks={};onAfterAffectHooks={};logger;static getName(){return"Core/Managers/Commands"}static async runCallbacks(t,e={},r={}){const s=t?.length||0;for(let n=0;s>n;++n){const s=!0===r.pop?t.pop():t[n];if(!s)throw Error("Callback is not defined.");await s(e,r)}}static hookCommand(t,e,r){t[e]||(t[e]=[]),t[e].push(r)}constructor(){super(),this.logger=new n(this.getName(),!0),this.logger.startEmpty()}async run(t,e={},r={}){"string"==typeof t&&(t=this.getCommandInstance(t,e,r)),this.attachCurrent(t,e);const s=await this.runInstance(t,e,r);return this.detachCurrent(t),s}register(t,e){const r={};return Object.values(t).forEach((t=>{const e=t.getName();if(this.commands[e])throw new a(t);this.commands[e]=t,r[e]=t})),r}getAll(){return this.commands}getByName(t){return this.commands[t]}getLogger(){return this.logger}getCommandInstance(t,e={},r={}){const s=this.commands[t];if(!s)throw new i(t);return new s(e,r)}onBefore(t,e){m.hookCommand(this.onBeforeHooks,t,e)}onBeforeUI(t,e){m.hookCommand(this.onBeforeUIHooks,t,e)}onAfter(t,e){m.hookCommand(this.onAfterHooks,t,e)}onAfterUI(t,e){m.hookCommand(this.onAfterUIHooks,t,e)}onAfterOnce(t,e){m.hookCommand(this.onAfterOnceHooks,t,e)}onAfterAffect(t,e){m.hookCommand(this.onAfterAffectHooks,t,e)}onBeforeRun(t,e={},r={}){if(this.onBeforeHooks[t.getName()]){this.onBeforeHooks[t.getName()].forEach((t=>t(e,r)))}if(this.onBeforeUIHooks[t.getName()]){this.onBeforeUIHooks[t.getName()].forEach((t=>t(e,r)))}}async runInstance(t,e={},r={}){let s=null;return Object.keys(e).length?(this.logger.startWith({command:t.getName(),options:r,CommandArgs:"->"}),this.logger.debug("CommandArgs:"),this.logger.object(e)):this.logger.startWith({command:t.getName(),options:r,args:e}),this.onBeforeRun(t,e,r),s=await t.run(),await this.onAfterRun(t,e,r,s),s}async onAfterRun(t,e,r,s){return r=Object.assign({},r),this.onAfterAffectHooks[t.getName()]&&(this.onAfterAffectHooks[t.getName()].forEach((t=>{e.result=s,s=this.run(""+t,e,r)})),s=await s),this.onAfterHooks&&(e.result=s,await m.runCallbacks(Object.assign([],this.onAfterHooks[t.getName()]),e,r)),this.onAfterOnceHooks&&await m.runCallbacks(this.onAfterOnceHooks[t.getName()],e,{...r,pop:!0}),this.onAfterUIHooks&&m.runCallbacks(Object.assign([],this.onAfterUIHooks[t.getName()]),e,r),s}attachCurrent(t,e={}){this.current[t.getName()]=t,this.currentArgs[t.getName()]=e,this.trace.push(t.getName()),m.trace.push(t.getName())}detachCurrent(t){delete this.current[t.getName()],delete this.currentArgs[t.getName()],m.trace.pop(),this.trace.pop()}}class d extends g{controllers={};static getName(){return"Core/Managers/Controllers"}get(t){return this.controllers[t]}getAll(){return this.controllers}register(t){if(this.controllers[t.getName()])throw new c(t);return this.controllers[t.getName()]=t,t}}var f;!function(t){t.DELETE="DELETE",t.GET="GET",t.OPTIONS="OPTIONS",t.PATCH="PATCH",t.POST="POST",t.PUT="PUT",t.__EMPTY__=""}(f||(f={}));class C extends g{logger;apiBaseUrl;static getName(){return"Core/Clients/Http"}constructor(t="http://localhost"){super(),this.logger=new n(C.getName(),!0),this.logger.startWith({apiBaseUrl:t}),this.apiBaseUrl=t+"/"}async fetch(t,e,r=null){this.logger.startWith({path:t,method:e,body:r});const s={credentials:"include"},n={};[f.POST,f.PUT,f.PATCH].includes(e)?(Object.assign(n,{"Content-Type":"application/json"}),Object.assign(s,{method:e,headers:n,body:JSON.stringify(r)})):Object.assign(s,{headers:n});const o=await globalThis.fetch(this.apiBaseUrl+t,s);let a;try{a=await o.json()}catch(t){return console.error(t),!1}if(a?.error&&a?.global&&a?.message)throw Error(a.message);return this.logger.drop({path:t},a),a}}class y extends m{static client;currentHttpMethod;static getName(){return"Core/Managers/Data"}constructor(t){super(),y.client=new C(t.baseURL)}getClient(){return y.client}get(t,e={},r={}){return this.currentHttpMethod=f.GET,super.run(t,e,r)}update(t,e={},r={}){return this.currentHttpMethod=f.PATCH,super.run(t,e,r)}delete(t,e={},r={}){return this.currentHttpMethod=f.DELETE,super.run(t,e,r)}create(t,e={},r={}){return this.currentHttpMethod=f.POST,super.run(t,e,r)}async runInstance(t,e={},r={}){if(!this.currentHttpMethod)throw Error('Cannot run directly use one of the http methods: "get", "update", "delete, "create');const s={type:this.currentHttpMethod,args:{query:{},data:{}}};return f.GET===this.currentHttpMethod?s.args.query=e:s.args.data=e,e.result=await super.runInstance(t,s,r),this.currentHttpMethod=f.__EMPTY__,e.result}}class b extends m{static getName(){return"Core/Managers/Internal"}}const N=[];function w(t){A=new m,k=new d,E=new y(t),H=new b}function O(){A={},k={},E={},H={}}var A={},k={},E={},H={},I=Object.freeze({__proto__:null,afterInitializeCallbacks:N,get commands(){return A},get controllers(){return k},get data(){return E},destroy:O,initialize:w,get internal(){return H}});class _ extends g{args={};options={};logger;constructor(t={},e={}){super();const r=this.constructor.getName();this.logger=new n(r,!0,{sameColor:!0}),this.logger.startWith({args:t,options:e}),this.initialize(t,e)}initialize(t,e){this.args=t,this.options=e}apply(t=this.args,e=this.options){throw new h(this,"apply")}async run(){this.onBeforeApply&&this.onBeforeApply();const t=await this.apply(this.args,this.options);return this.onAfterApply&&this.onAfterApply(),t}getArgs(){return this.args}getOptions(){return this.options}}var j=Object.freeze({__proto__:null,CommandBase:_,CommandData:class extends _{static getName(){return"Core/CommandBases/CommandData"}getEndpoint(){throw new h(this,"getEndpoint")}apply(t=this.args,e=this.options){const r=this.applyEndpointFormat(this.getEndpoint(),t);return E.getClient().fetch(r,E.currentHttpMethod,t||null)}applyEndpointFormat(t,e={}){return t.includes("{")&&(t=t.split("/").map((t=>{const r=t.match("\\{(.*?)\\}");return r?.length&&void 0!==e[r[1]]?e[r[1]]:t})).join("/")),t}},CommandInternal:class extends _{static getName(){return"Core/CommandBases/CommandInternal"}},CommandPublic:class extends _{static getName(){return"Core/CommandBases/CommandPublic"}}});var $=Object.freeze({__proto__:null,Controller:class extends g{commands;data;internal;static getName(){return"Core/Core/Controller"}constructor(){super(),this.initialize()}initialize(){this.register(),this.setupHooks&&this.setupHooks()}register(){this.commands=A.register(this.getCommands(),this),this.data=E.register(this.getData(),this),this.internal=H.register(this.getInternal(),this)}getCommands(){return{}}getData(){return{}}getInternal(){return{}}},ObjectBase:g}),B=Object.freeze({__proto__:null,Commands:m,Controllers:d,Data:y,Internal:b}),T=Object.freeze({__proto__:null,commandBases:j,core:$,errors:u,managerBases:B,managers:I,modules:o,utils:s});let M=!1;function U(){if(M)throw Error("ZenCore is already initialized.")}U();let D={version:t};const L={initialize:t=>{U(),D=t||D,w(D),M=!0},destroy:()=>{O(),M=!1},onAfterInitialize:t=>{N.push(t)},config:D,...T};globalThis?.ZenCore||(globalThis.ZenCore=L);export{j as commandBases,$ as core,L as default,u as errors,B as managerBases,I as managers,o as modules,s as utils};
@@ -1,11 +1,12 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["@zenflux/core"]={})}(this,(function(t){"use strict";var e="0.0.0-abc.14";"undefined"!=typeof __ZEN_MANAGERS__&&__ZEN_MANAGERS__||(globalThis.__ZEN_MANAGERS__={initialize:()=>{},destroy:()=>{},commands:{},controllers:{},data:{},internal:{}})
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["@zenflux/core"]={})}(this,(function(t){"use strict";var e="0.0.0-abc.20";
2
2
  /**
3
3
  * Function getCircularReplacer() : Reduce circular references.
4
4
  *
5
5
  * @copyright https://stackoverflow.com/a/53731154
6
- */;const r=()=>{const t=new WeakSet;return(e,r)=>{if("object"==typeof r&&null!==r){if(t.has(r))return;t.add(r)}return r}},s=function(t,e){t=t.replace("#",""),e=e.replace("#","");const r=parseInt(t.substring(0,2),16),s=parseInt(t.substring(2,4),16),n=parseInt(t.substring(4,6),16),o=parseInt(e.substring(0,2),16),a=parseInt(e.substring(2,4),16),i=parseInt(e.substring(4,6),16);let c=255-Math.abs(r-o),l=255-Math.abs(s-a),h=255-Math.abs(n-i);return c/=255,l/=255,h/=255,(c+l+h)/3};
6
+ */
7
+ const r=()=>{const t=new WeakSet;return(e,r)=>{if("object"==typeof r&&null!==r){if(t.has(r))return;t.add(r)}return r}},s=function(t,e){t=t.replace("#",""),e=e.replace("#","");const r=parseInt(t.substring(0,2),16),s=parseInt(t.substring(2,4),16),n=parseInt(t.substring(4,6),16),o=parseInt(e.substring(0,2),16),a=parseInt(e.substring(2,4),16),i=parseInt(e.substring(4,6),16);let c=255-Math.abs(r-o),l=255-Math.abs(s-a),h=255-Math.abs(n-i);return c/=255,l/=255,h/=255,(c+l+h)/3};
7
8
  /**
8
9
  * Function hexColorDelta() : Return color difference in ratio decimal point.
9
10
  *
10
11
  * @copyright http://jsfiddle.net/96sME/
11
- */var n=Object.freeze({__proto__:null,getCircularReplacer:r,hexColorDelta:s});class o{static wrappers={};static wrapperDepth=0;static sharedData={};static colorsInUse=[];defaultStyle;color;outputHandler;args={};name;state=!1;static getName(){return"Core/Modules/Logger"}static reset(){o.wrappers={},o.wrapperDepth=0,o.colorsInUse=[],o.sharedData={}}static createCustomWrapper(t,e){o.wrappers[t]||(o.wrappers[t.name]=[]),o.wrappers[t.name].push({classType:t,callback:e})}static getCallerName(){const t=Error(),e=t.stack?t.stack.split("\n")[3].trim():"_UNKNOWN_CALLER_NAME_";return e.startsWith("at new")?"constructor":e.split(".")[1].split(" ")[0]}static getFunctionView(t){let e="anonymous function()";return"string"!=typeof t&&0!==t.name.length&&(e=t.name.split(" ")[1]+"()"),e}constructor(t,e=!1,r={}){"off"!==globalThis.process?.env.flow_modules_logger&&(this.state=e,this.args=r,this.name="",this.name="string"==typeof t?t:t.constructor.name,e&&this.initialize())}initialize(){this.args.sameColor?(o.sharedData[this.name]||(o.sharedData[this.name]=this.getRandomColor()),this.color=o.sharedData[this.name]):(this.color=this.getRandomColor(),o.colorsInUse.push(this.color)),this.outputHandler=console.log,this.defaultStyle=["color: grey;font-size:7px","display: block","color: "+this.color,"color: grey","font-weight: bold","color: #607D8B","font-size: 16px;color: red;font-weight:800"]}setOutputHandler(t){this.outputHandler=t}useWrapper(t,e=!0){if(!t||"object"!=typeof t||Array.isArray(t))return t;o.wrapperDepth++;let r={...t};return Object.values(o.wrappers).forEach((([e])=>{t instanceof e.classType&&(r=e.callback(t)||r)})),4>o.wrapperDepth?(e&&r&&Object.entries(r).forEach((([t,e])=>{r[t]=this.useWrapper(e,!0)})),o.wrapperDepth--,r):(o.wrapperDepth--,r)}startEmpty(t=""){this.state&&this.printFunctionNotify("se",o.getCallerName(),t)}startWith(t){if(!this.state)return;t=Object.assign({},t);const e="se",r=o.getCallerName();if("string"==typeof t)this.printInLineString(e,r,t);else if(1===Object.keys(t).length){const s=Object.keys(t)[0];let n=Object.values(t)[0];"object"==typeof n?this.printNextLineObject(e,r,s,n||{}):"function"==typeof n?this.printInLineFunction(e,r,s,n):this.printInLineElement(e,r,s,n)}else this.printMultiLineObject(e,r,t)}object(t={},e=""){if(!this.state)return;const s=o.getCallerName();t=Object.create(t);for(let n in t)"object"==typeof t[n]&&(t[n]=JSON.stringify(this.useWrapper(t[n]),r())),this.out.apply(this,[`%c(ob)-> %c%c${this.name}%c::%c${s}%c() [${e}] ->> ${n}: '${t[n]}'%c`].concat(this.defaultStyle))}debug(t){this.state&&this.printFunctionNotify("db",o.getCallerName(),t)}drop(t,e){if(!this.state)return;const r=o.getCallerName();for(let e in t)this.out.apply(this,[`%c(dr)-> %c%c${this.name}%c::%c${r}%c() ->> corresponding ${e}: '${t[e]}' RESULT: %c↓`].concat(this.defaultStyle));this.out(e)}throw(t,e="null",r={}){throw this.printFunctionNotify("tw",o.getCallerName(),t),r&&this.printNextLineObject("tw",o.getCallerName(),e,r),Error().stack}clone(){return Object.assign(Object.create(Object.getPrototypeOf(this)),this)}printFunctionNotify(t,e,r){this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c() ${r}%c`].concat(this.defaultStyle))}printInLineElement(t,e,r,s){this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c() ->> ${r}: '${s}'%c`].concat(this.defaultStyle))}printInLineFunction(t,e,r,s){s=o.getFunctionView(s),this.printInLineElement(t,e,r,s)}printInLineString(t,e,r){this.printInLineElement(t,e,"(string)",r)}printNextLineObject(t,e,r,s){s=this.useWrapper(s),this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c() ->> ${r} %c↓`].concat(this.defaultStyle)),this.out(s)}printMultiLineObject(t,e,s){this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c(${Object.keys(s).join(", ")}) %c↓`].concat(this.defaultStyle));for(let t in s){let e=s[t];"object"==typeof e?e=JSON.stringify(this.useWrapper(e),r()):"function"==typeof s[t]&&(e=o.getFunctionView(e)),this.out.call(this,"%c"+t+": `"+this.useWrapper(e)+"`","color: #a3a3a3")}}getRandomColor(){let t="#";for(let e=0;6>e;e++)t+="0123456789ABCDEF"[Math.floor(16*Math.random())];return o.colorsInUse.some((e=>s(t,e)>=.8))?this.getRandomColor():t}out(...t){this.outputHandler.apply(this,t)}}var a=Object.freeze({__proto__:null,Logger:o});class i extends Error{constructor(t,e){super(`ForeMethod implementation: at '${t}' method: '${e}'`)}}class c extends Error{constructor(t,e){super(`ForeMethod implementation: at '${t.getName()}' method: '${e}'`)}}let l=0;class h{virtualId=0;static getName(){throw new i("ObjectBase","getName")}constructor(){this.virtualId=l,l++}getName(){return this.constructor.getName()}}var u=Object.freeze({__proto__:null,Controller:class extends h{commands;data;internal;static getName(){return"Core/Core/Controller"}constructor(){super(),this.initialize()}initialize(){this.register(),this.setupHooks&&this.setupHooks()}register(){this.commands=__ZEN_MANAGERS__.commands.register(this.getCommands(),this),this.data=__ZEN_MANAGERS__.data.register(this.getData(),this),this.internal=__ZEN_MANAGERS__.internal.register(this.getInternal(),this)}getCommands(){return{}}getData(){return{}}getInternal(){return{}}},ObjectBase:h});class p extends Error{constructor(t){super(`Command: '${t.getName()}' is already registered`)}}class g extends Error{constructor(t){super(`Command: '${t}' is not found`)}}class m extends Error{constructor(t){super(`Controller: '${t.getName()}' is already registered`)}}var d,_=Object.freeze({__proto__:null,CommandAlreadyRegistered:p,CommandNotFound:g,ControllerAlreadyRegistered:m,ForceMethod:c});class f extends h{static trace=[];current={};currentArgs={};trace=[];commands={};onBeforeHooks={};onBeforeUIHooks={};onAfterHooks={};onAfterOnceHooks={};onAfterUIHooks={};onAfterAffectHooks={};logger;static getName(){return"Core/Managers/Commands"}static async runCallbacks(t,e={},r={}){const s=t?.length||0;for(let n=0;s>n;++n){const s=!0===r.pop?t.pop():t[n];if(!s)throw Error("Callback is not defined.");await s(e,r)}}static hookCommand(t,e,r){t[e]||(t[e]=[]),t[e].push(r)}constructor(){super(),this.logger=new o(this.getName(),!0),this.logger.startEmpty()}async run(t,e={},r={}){"string"==typeof t&&(t=this.getCommandInstance(t,e,r)),this.attachCurrent(t,e);const s=await this.runInstance(t,e,r);return this.detachCurrent(t),s}register(t,e){const r={};return Object.values(t).forEach((t=>{const e=t.getName();if(this.commands[e])throw new p(t);this.commands[e]=t,r[e]=t})),r}getAll(){return this.commands}getByName(t){return this.commands[t]}getLogger(){return this.logger}getCommandInstance(t,e={},r={}){const s=this.commands[t];if(!s)throw new g(t);return new s(e,r)}onBefore(t,e){f.hookCommand(this.onBeforeHooks,t,e)}onBeforeUI(t,e){f.hookCommand(this.onBeforeUIHooks,t,e)}onAfter(t,e){f.hookCommand(this.onAfterHooks,t,e)}onAfterUI(t,e){f.hookCommand(this.onAfterUIHooks,t,e)}onAfterOnce(t,e){f.hookCommand(this.onAfterOnceHooks,t,e)}onAfterAffect(t,e){f.hookCommand(this.onAfterAffectHooks,t,e)}onBeforeRun(t,e={},r={}){if(this.onBeforeHooks[t.getName()]){this.onBeforeHooks[t.getName()].forEach((t=>t(e,r)))}if(this.onBeforeUIHooks[t.getName()]){this.onBeforeUIHooks[t.getName()].forEach((t=>t(e,r)))}}async runInstance(t,e={},r={}){let s=null;return Object.keys(e).length?(this.logger.startWith({command:t.getName(),options:r,CommandArgs:"->"}),this.logger.debug("CommandArgs:"),this.logger.object(e)):this.logger.startWith({command:t.getName(),options:r,args:e}),this.onBeforeRun(t,e,r),s=await t.run(),await this.onAfterRun(t,e,r,s),s}async onAfterRun(t,e,r,s){return r=Object.assign({},r),this.onAfterAffectHooks[t.getName()]&&(this.onAfterAffectHooks[t.getName()].forEach((t=>{e.result=s,s=this.run(""+t,e,r)})),s=await s),this.onAfterHooks&&(e.result=s,await f.runCallbacks(Object.assign([],this.onAfterHooks[t.getName()]),e,r)),this.onAfterOnceHooks&&await f.runCallbacks(this.onAfterOnceHooks[t.getName()],e,{...r,pop:!0}),this.onAfterUIHooks&&f.runCallbacks(Object.assign([],this.onAfterUIHooks[t.getName()]),e,r),s}attachCurrent(t,e={}){this.current[t.getName()]=t,this.currentArgs[t.getName()]=e,this.trace.push(t.getName()),f.trace.push(t.getName())}detachCurrent(t){delete this.current[t.getName()],delete this.currentArgs[t.getName()],f.trace.pop(),this.trace.pop()}}class N extends h{controllers={};static getName(){return"Core/Managers/Controllers"}get(t){return this.controllers[t]}getAll(){return this.controllers}register(t){if(this.controllers[t.getName()])throw new m(t);return this.controllers[t.getName()]=t,t}}!function(t){t.DELETE="DELETE",t.GET="GET",t.OPTIONS="OPTIONS",t.PATCH="PATCH",t.POST="POST",t.PUT="PUT",t.__EMPTY__=""}(d||(d={}));class A extends h{logger;apiBaseUrl;static getName(){return"Core/Clients/Http"}constructor(t="http://localhost"){super(),this.logger=new o(A.getName(),!0),this.logger.startWith({apiBaseUrl:t}),this.apiBaseUrl=t+"/"}async fetch(t,e,r=null){this.logger.startWith({path:t,method:e,body:r});const s={credentials:"include"},n={};[d.POST,d.PUT,d.PATCH].includes(e)?(Object.assign(n,{"Content-Type":"application/json"}),Object.assign(s,{method:e,headers:n,body:JSON.stringify(r)})):Object.assign(s,{headers:n});const o=await globalThis.fetch(this.apiBaseUrl+t,s);let a;try{a=await o.json()}catch(t){return console.error(t),!1}if(a?.error&&a?.global&&a?.message)throw Error(a.message);return this.logger.drop({path:t},a),a}}class E extends f{static client;currentHttpMethod;static getName(){return"Core/Managers/Data"}constructor(t){super(),E.client=new A(t.baseURL)}getClient(){return E.client}get(t,e={},r={}){return this.currentHttpMethod=d.GET,super.run(t,e,r)}update(t,e={},r={}){return this.currentHttpMethod=d.PATCH,super.run(t,e,r)}delete(t,e={},r={}){return this.currentHttpMethod=d.DELETE,super.run(t,e,r)}create(t,e={},r={}){return this.currentHttpMethod=d.POST,super.run(t,e,r)}async runInstance(t,e={},r={}){if(!this.currentHttpMethod)throw Error('Cannot run directly use one of the http methods: "get", "update", "delete, "create');const s={type:this.currentHttpMethod,args:{query:{},data:{}}};return d.GET===this.currentHttpMethod?s.args.query=e:s.args.data=e,e.result=await super.runInstance(t,s,r),this.currentHttpMethod=d.__EMPTY__,e.result}}class y extends f{static getName(){return"Core/Managers/Internal"}}const C=[];function b(t){__ZEN_MANAGERS__.commands=new f,__ZEN_MANAGERS__.controllers=new N,__ZEN_MANAGERS__.data=new E(t),__ZEN_MANAGERS__.internal=new y}function w(){__ZEN_MANAGERS__.commands={},__ZEN_MANAGERS__.controllers={},__ZEN_MANAGERS__.data={},__ZEN_MANAGERS__.internal={}}const O=__ZEN_MANAGERS__.controllers,M=__ZEN_MANAGERS__.commands,k=__ZEN_MANAGERS__.data,j=__ZEN_MANAGERS__.internal;__ZEN_MANAGERS__.initialize=b,__ZEN_MANAGERS__.destroy=w;var H=Object.freeze({__proto__:null,afterInitializeCallbacks:C,commands:M,controllers:O,data:k,destroy:w,initialize:b,internal:j});class I extends h{args={};options={};logger;constructor(t={},e={}){super();const r=this.constructor.getName();this.logger=new o(r,!0,{sameColor:!0}),this.logger.startWith({args:t,options:e}),this.initialize(t,e)}initialize(t,e){this.args=t,this.options=e}apply(t=this.args,e=this.options){throw new c(this,"apply")}async run(){this.onBeforeApply&&this.onBeforeApply();const t=await this.apply(this.args,this.options);return this.onAfterApply&&this.onAfterApply(),t}getArgs(){return this.args}getOptions(){return this.options}}var S=Object.freeze({__proto__:null,CommandBase:I,CommandData:class extends I{static getName(){return"Core/CommandBases/CommandData"}getEndpoint(){throw new c(this,"getEndpoint")}apply(t=this.args,e=this.options){const r=this.applyEndpointFormat(this.getEndpoint(),t);return __ZEN_MANAGERS__.data.getClient().fetch(r,__ZEN_MANAGERS__.data.currentHttpMethod,t||null)}applyEndpointFormat(t,e={}){return t.includes("{")&&(t=t.split("/").map((t=>{const r=t.match("\\{(.*?)\\}");return r?.length&&void 0!==e[r[1]]?e[r[1]]:t})).join("/")),t}},CommandInternal:class extends I{static getName(){return"Core/CommandBases/CommandInternal"}},CommandPublic:class extends I{static getName(){return"Core/CommandBases/CommandPublic"}}}),R=Object.freeze({__proto__:null,Commands:f,Controllers:N,Data:E,Internal:y}),T=Object.freeze({__proto__:null,commandBases:S,core:u,errors:_,managerBases:R,managers:H,modules:a,utils:n});let $=!1;function B(){if($)throw Error("ZenCore is already initialized.")}B();let G={version:e};const x={initialize:t=>{B(),G=t||G,b(G),$=!0},destroy:()=>{w(),$=!1},onAfterInitialize:t=>{C.push(t)},config:G,...T};globalThis?.ZenCore||(globalThis.ZenCore=x),t.commandBases=S,t.core=u,t.default=x,t.errors=_,t.managerBases=R,t.managers=H,t.modules=a,t.utils=n,Object.defineProperty(t,"__esModule",{value:!0})}));
12
+ */var n=Object.freeze({__proto__:null,getCircularReplacer:r,hexColorDelta:s});class o{static wrappers={};static wrapperDepth=0;static sharedData={};static colorsInUse=[];defaultStyle;color;outputHandler;args={};name;state=!1;static getName(){return"Core/Modules/Logger"}static reset(){o.wrappers={},o.wrapperDepth=0,o.colorsInUse=[],o.sharedData={}}static createCustomWrapper(t,e){o.wrappers[t]||(o.wrappers[t.name]=[]),o.wrappers[t.name].push({classType:t,callback:e})}static getCallerName(){const t=Error(),e=t.stack?t.stack.split("\n")[3].trim():"_UNKNOWN_CALLER_NAME_";return e.startsWith("at new")?"constructor":e.split(".")[1].split(" ")[0]}static getFunctionView(t){let e="anonymous function()";return"string"!=typeof t&&0!==t.name.length&&(e=t.name.split(" ")[1]+"()"),e}constructor(t,e=!1,r={}){"off"!==globalThis.process?.env.flow_modules_logger&&(this.state=e,this.args=r,this.name="",this.name="string"==typeof t?t:t.constructor.name,e&&this.initialize())}initialize(){this.args.sameColor?(o.sharedData[this.name]||(o.sharedData[this.name]=this.getRandomColor()),this.color=o.sharedData[this.name]):(this.color=this.getRandomColor(),o.colorsInUse.push(this.color)),this.outputHandler=console.log,this.defaultStyle=["color: grey;font-size:7px","display: block","color: "+this.color,"color: grey","font-weight: bold","color: #607D8B","font-size: 16px;color: red;font-weight:800"]}setOutputHandler(t){this.outputHandler=t}useWrapper(t,e=!0){if(!t||"object"!=typeof t||Array.isArray(t))return t;o.wrapperDepth++;let r={...t};return Object.values(o.wrappers).forEach((([e])=>{t instanceof e.classType&&(r=e.callback(t)||r)})),4>o.wrapperDepth?(e&&r&&Object.entries(r).forEach((([t,e])=>{r[t]=this.useWrapper(e,!0)})),o.wrapperDepth--,r):(o.wrapperDepth--,r)}startEmpty(t=""){this.state&&this.printFunctionNotify("se",o.getCallerName(),t)}startWith(t){if(!this.state)return;t=Object.assign({},t);const e="se",r=o.getCallerName();if("string"==typeof t)this.printInLineString(e,r,t);else if(1===Object.keys(t).length){const s=Object.keys(t)[0];let n=Object.values(t)[0];"object"==typeof n?this.printNextLineObject(e,r,s,n||{}):"function"==typeof n?this.printInLineFunction(e,r,s,n):this.printInLineElement(e,r,s,n)}else this.printMultiLineObject(e,r,t)}object(t={},e=""){if(!this.state)return;const s=o.getCallerName();t=Object.create(t);for(let n in t)"object"==typeof t[n]&&(t[n]=JSON.stringify(this.useWrapper(t[n]),r())),this.out.apply(this,[`%c(ob)-> %c%c${this.name}%c::%c${s}%c() [${e}] ->> ${n}: '${t[n]}'%c`].concat(this.defaultStyle))}debug(t){this.state&&this.printFunctionNotify("db",o.getCallerName(),t)}drop(t,e){if(!this.state)return;const r=o.getCallerName();for(let e in t)this.out.apply(this,[`%c(dr)-> %c%c${this.name}%c::%c${r}%c() ->> corresponding ${e}: '${t[e]}' RESULT: %c↓`].concat(this.defaultStyle));this.out(e)}throw(t,e="null",r={}){throw this.printFunctionNotify("tw",o.getCallerName(),t),r&&this.printNextLineObject("tw",o.getCallerName(),e,r),Error().stack}clone(){return Object.assign(Object.create(Object.getPrototypeOf(this)),this)}printFunctionNotify(t,e,r){this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c() ${r}%c`].concat(this.defaultStyle))}printInLineElement(t,e,r,s){this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c() ->> ${r}: '${s}'%c`].concat(this.defaultStyle))}printInLineFunction(t,e,r,s){s=o.getFunctionView(s),this.printInLineElement(t,e,r,s)}printInLineString(t,e,r){this.printInLineElement(t,e,"(string)",r)}printNextLineObject(t,e,r,s){s=this.useWrapper(s),this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c() ->> ${r} %c↓`].concat(this.defaultStyle)),this.out(s)}printMultiLineObject(t,e,s){this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c(${Object.keys(s).join(", ")}) %c↓`].concat(this.defaultStyle));for(let t in s){let e=s[t];"object"==typeof e?e=JSON.stringify(this.useWrapper(e),r()):"function"==typeof s[t]&&(e=o.getFunctionView(e)),this.out.call(this,"%c"+t+": `"+this.useWrapper(e)+"`","color: #a3a3a3")}}getRandomColor(){let t="#";for(let e=0;6>e;e++)t+="0123456789ABCDEF"[Math.floor(16*Math.random())];return o.colorsInUse.some((e=>s(t,e)>=.8))?this.getRandomColor():t}out(...t){this.outputHandler.apply(this,t)}}var a=Object.freeze({__proto__:null,Logger:o});class i extends Error{constructor(t){super(`Command: '${t.getName()}' is already registered`)}}class c extends Error{constructor(t){super(`Command: '${t}' is not found`)}}class l extends Error{constructor(t){super(`Controller: '${t.getName()}' is already registered`)}}class h extends Error{constructor(t,e){super(`ForeMethod implementation: at '${t}' method: '${e}'`)}}class u extends Error{constructor(t,e){super(`ForeMethod implementation: at '${t.getName()}' method: '${e}'`)}}var p=Object.freeze({__proto__:null,CommandAlreadyRegistered:i,CommandNotFound:c,ControllerAlreadyRegistered:l,ForceMethod:u});let g=0;class m{virtualId=0;static getName(){throw new h("ObjectBase","getName")}constructor(){this.virtualId=g,g++}getName(){return this.constructor.getName()}}class d extends m{static trace=[];current={};currentArgs={};trace=[];commands={};onBeforeHooks={};onBeforeUIHooks={};onAfterHooks={};onAfterOnceHooks={};onAfterUIHooks={};onAfterAffectHooks={};logger;static getName(){return"Core/Managers/Commands"}static async runCallbacks(t,e={},r={}){const s=t?.length||0;for(let n=0;s>n;++n){const s=!0===r.pop?t.pop():t[n];if(!s)throw Error("Callback is not defined.");await s(e,r)}}static hookCommand(t,e,r){t[e]||(t[e]=[]),t[e].push(r)}constructor(){super(),this.logger=new o(this.getName(),!0),this.logger.startEmpty()}async run(t,e={},r={}){"string"==typeof t&&(t=this.getCommandInstance(t,e,r)),this.attachCurrent(t,e);const s=await this.runInstance(t,e,r);return this.detachCurrent(t),s}register(t,e){const r={};return Object.values(t).forEach((t=>{const e=t.getName();if(this.commands[e])throw new i(t);this.commands[e]=t,r[e]=t})),r}getAll(){return this.commands}getByName(t){return this.commands[t]}getLogger(){return this.logger}getCommandInstance(t,e={},r={}){const s=this.commands[t];if(!s)throw new c(t);return new s(e,r)}onBefore(t,e){d.hookCommand(this.onBeforeHooks,t,e)}onBeforeUI(t,e){d.hookCommand(this.onBeforeUIHooks,t,e)}onAfter(t,e){d.hookCommand(this.onAfterHooks,t,e)}onAfterUI(t,e){d.hookCommand(this.onAfterUIHooks,t,e)}onAfterOnce(t,e){d.hookCommand(this.onAfterOnceHooks,t,e)}onAfterAffect(t,e){d.hookCommand(this.onAfterAffectHooks,t,e)}onBeforeRun(t,e={},r={}){if(this.onBeforeHooks[t.getName()]){this.onBeforeHooks[t.getName()].forEach((t=>t(e,r)))}if(this.onBeforeUIHooks[t.getName()]){this.onBeforeUIHooks[t.getName()].forEach((t=>t(e,r)))}}async runInstance(t,e={},r={}){let s=null;return Object.keys(e).length?(this.logger.startWith({command:t.getName(),options:r,CommandArgs:"->"}),this.logger.debug("CommandArgs:"),this.logger.object(e)):this.logger.startWith({command:t.getName(),options:r,args:e}),this.onBeforeRun(t,e,r),s=await t.run(),await this.onAfterRun(t,e,r,s),s}async onAfterRun(t,e,r,s){return r=Object.assign({},r),this.onAfterAffectHooks[t.getName()]&&(this.onAfterAffectHooks[t.getName()].forEach((t=>{e.result=s,s=this.run(""+t,e,r)})),s=await s),this.onAfterHooks&&(e.result=s,await d.runCallbacks(Object.assign([],this.onAfterHooks[t.getName()]),e,r)),this.onAfterOnceHooks&&await d.runCallbacks(this.onAfterOnceHooks[t.getName()],e,{...r,pop:!0}),this.onAfterUIHooks&&d.runCallbacks(Object.assign([],this.onAfterUIHooks[t.getName()]),e,r),s}attachCurrent(t,e={}){this.current[t.getName()]=t,this.currentArgs[t.getName()]=e,this.trace.push(t.getName()),d.trace.push(t.getName())}detachCurrent(t){delete this.current[t.getName()],delete this.currentArgs[t.getName()],d.trace.pop(),this.trace.pop()}}class f extends m{controllers={};static getName(){return"Core/Managers/Controllers"}get(t){return this.controllers[t]}getAll(){return this.controllers}register(t){if(this.controllers[t.getName()])throw new l(t);return this.controllers[t.getName()]=t,t}}var C;!function(t){t.DELETE="DELETE",t.GET="GET",t.OPTIONS="OPTIONS",t.PATCH="PATCH",t.POST="POST",t.PUT="PUT",t.__EMPTY__=""}(C||(C={}));class y extends m{logger;apiBaseUrl;static getName(){return"Core/Clients/Http"}constructor(t="http://localhost"){super(),this.logger=new o(y.getName(),!0),this.logger.startWith({apiBaseUrl:t}),this.apiBaseUrl=t+"/"}async fetch(t,e,r=null){this.logger.startWith({path:t,method:e,body:r});const s={credentials:"include"},n={};[C.POST,C.PUT,C.PATCH].includes(e)?(Object.assign(n,{"Content-Type":"application/json"}),Object.assign(s,{method:e,headers:n,body:JSON.stringify(r)})):Object.assign(s,{headers:n});const o=await globalThis.fetch(this.apiBaseUrl+t,s);let a;try{a=await o.json()}catch(t){return console.error(t),!1}if(a?.error&&a?.global&&a?.message)throw Error(a.message);return this.logger.drop({path:t},a),a}}class b extends d{static client;currentHttpMethod;static getName(){return"Core/Managers/Data"}constructor(t){super(),b.client=new y(t.baseURL)}getClient(){return b.client}get(t,e={},r={}){return this.currentHttpMethod=C.GET,super.run(t,e,r)}update(t,e={},r={}){return this.currentHttpMethod=C.PATCH,super.run(t,e,r)}delete(t,e={},r={}){return this.currentHttpMethod=C.DELETE,super.run(t,e,r)}create(t,e={},r={}){return this.currentHttpMethod=C.POST,super.run(t,e,r)}async runInstance(t,e={},r={}){if(!this.currentHttpMethod)throw Error('Cannot run directly use one of the http methods: "get", "update", "delete, "create');const s={type:this.currentHttpMethod,args:{query:{},data:{}}};return C.GET===this.currentHttpMethod?s.args.query=e:s.args.data=e,e.result=await super.runInstance(t,s,r),this.currentHttpMethod=C.__EMPTY__,e.result}}class N extends d{static getName(){return"Core/Managers/Internal"}}const w=[];function O(t){k=new d,_=new f,j=new b(t),E=new N}function A(){k={},_={},j={},E={}}var k={},_={},j={},E={},H=Object.freeze({__proto__:null,afterInitializeCallbacks:w,get commands(){return k},get controllers(){return _},get data(){return j},destroy:A,initialize:O,get internal(){return E}});class I extends m{args={};options={};logger;constructor(t={},e={}){super();const r=this.constructor.getName();this.logger=new o(r,!0,{sameColor:!0}),this.logger.startWith({args:t,options:e}),this.initialize(t,e)}initialize(t,e){this.args=t,this.options=e}apply(t=this.args,e=this.options){throw new u(this,"apply")}async run(){this.onBeforeApply&&this.onBeforeApply();const t=await this.apply(this.args,this.options);return this.onAfterApply&&this.onAfterApply(),t}getArgs(){return this.args}getOptions(){return this.options}}var $=Object.freeze({__proto__:null,CommandBase:I,CommandData:class extends I{static getName(){return"Core/CommandBases/CommandData"}getEndpoint(){throw new u(this,"getEndpoint")}apply(t=this.args,e=this.options){const r=this.applyEndpointFormat(this.getEndpoint(),t);return j.getClient().fetch(r,j.currentHttpMethod,t||null)}applyEndpointFormat(t,e={}){return t.includes("{")&&(t=t.split("/").map((t=>{const r=t.match("\\{(.*?)\\}");return r?.length&&void 0!==e[r[1]]?e[r[1]]:t})).join("/")),t}},CommandInternal:class extends I{static getName(){return"Core/CommandBases/CommandInternal"}},CommandPublic:class extends I{static getName(){return"Core/CommandBases/CommandPublic"}}});var T=Object.freeze({__proto__:null,Controller:class extends m{commands;data;internal;static getName(){return"Core/Core/Controller"}constructor(){super(),this.initialize()}initialize(){this.register(),this.setupHooks&&this.setupHooks()}register(){this.commands=k.register(this.getCommands(),this),this.data=j.register(this.getData(),this),this.internal=E.register(this.getInternal(),this)}getCommands(){return{}}getData(){return{}}getInternal(){return{}}},ObjectBase:m}),B=Object.freeze({__proto__:null,Commands:d,Controllers:f,Data:b,Internal:N}),M=Object.freeze({__proto__:null,commandBases:$,core:T,errors:p,managerBases:B,managers:H,modules:a,utils:n});let x=!1;function U(){if(x)throw Error("ZenCore is already initialized.")}U();let D={version:e};const L={initialize:t=>{U(),D=t||D,O(D),x=!0},destroy:()=>{A(),x=!1},onAfterInitialize:t=>{w.push(t)},config:D,...M};globalThis?.ZenCore||(globalThis.ZenCore=L),t.commandBases=$,t.core=T,t.default=L,t.errors=p,t.managerBases=B,t.managers=H,t.modules=a,t.utils=n,Object.defineProperty(t,"__esModule",{value:!0})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenflux/core",
3
- "version": "0.0.0-abc.19",
3
+ "version": "0.0.0-abc.20",
4
4
  "description": "ZenFlux core",
5
5
  "author": "Leonid Vinikov <leonidvinikov@gmail.com> (https://github.com/iNewLegend)",
6
6
  "scripts": {
@@ -5,6 +5,8 @@
5
5
  import { ForceMethod } from '../errors/force-method';
6
6
  import { CommandBase } from './command-base';
7
7
 
8
+ import * as managers from '../managers';
9
+
8
10
  export abstract class CommandData extends CommandBase {
9
11
  static getName() {
10
12
  return 'Core/CommandBases/CommandData';
@@ -26,8 +28,8 @@ export abstract class CommandData extends CommandBase {
26
28
  apply( args = this.args, options = this.options ) {// eslint-disable-line @typescript-eslint/no-unused-vars
27
29
  const endpoint = this.applyEndpointFormat( this.getEndpoint(), args );
28
30
 
29
- return __ZEN_MANAGERS__.data.getClient().fetch(
30
- endpoint, __ZEN_MANAGERS__.data.currentHttpMethod, args || null
31
+ return managers.data.getClient().fetch(
32
+ endpoint, managers.data.currentHttpMethod, args || null
31
33
  );
32
34
  }
33
35
 
@@ -6,6 +6,8 @@ import ObjectBase from "./object-base";
6
6
 
7
7
  import { CommandData, CommandInternal, CommandPublic } from "../command-bases";
8
8
 
9
+ import * as managers from "../managers";
10
+
9
11
  export abstract class Controller extends ObjectBase {
10
12
  commands: { [ key: string ]: typeof CommandPublic };
11
13
  data: { [ key: string ]: typeof CommandData };
@@ -28,13 +30,13 @@ export abstract class Controller extends ObjectBase {
28
30
  }
29
31
 
30
32
  register() {
31
- this.commands = __ZEN_MANAGERS__.commands.register( this.getCommands(), this ) as
33
+ this.commands = managers.commands.register( this.getCommands(), this ) as
32
34
  { [ key: string ]: typeof CommandPublic };
33
35
 
34
- this.data = __ZEN_MANAGERS__.data.register( this.getData(), this ) as
36
+ this.data = managers.data.register( this.getData(), this ) as
35
37
  { [ key: string ]: typeof CommandData };
36
38
 
37
- this.internal = __ZEN_MANAGERS__.internal.register( this.getInternal(), this ) as
39
+ this.internal = managers.internal.register( this.getInternal(), this ) as
38
40
  { [ key: string ]: typeof CommandInternal };
39
41
  }
40
42
 
@@ -7,7 +7,10 @@ import { IAPIConfig } from "./interfaces/config";
7
7
  import { destroy, initialize, afterInitializeCallbacks } from "./managers";
8
8
 
9
9
  import * as exported from './exports';
10
- import { IManagers } from "./interfaces/managers";
10
+
11
+ declare global {
12
+ var ZenCore: any;
13
+ }
11
14
 
12
15
  let isInitialized = false;
13
16
 
@@ -4,9 +4,11 @@
4
4
  */
5
5
  import { Logger } from "../modules/";
6
6
  import { CommandBase } from "../command-bases";
7
- import { Controller, ObjectBase } from "../core";
8
7
  import { CommandAlreadyRegistered, CommandNotFound } from "../errors/";
9
8
 
9
+ import ObjectBase from "../core/object-base";
10
+ import Controller from "../core/controller";
11
+
10
12
  import {
11
13
  ICommandArgsInterface,
12
14
  CommandCallbackType,
@@ -2,7 +2,8 @@
2
2
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
3
3
  * @description: Responsible for manging controllers, each controller is global singleton instance.
4
4
  */
5
- import { Controller, ObjectBase } from "../core";
5
+ import ObjectBase from "../core/object-base";
6
+ import Controller from "../core/controller";
6
7
 
7
8
  import { ControllerAlreadyRegistered } from "../errors/controller-already-registered";
8
9
 
@@ -5,6 +5,7 @@ import Commands from "../manager-bases/commands";
5
5
  import Controllers from "../manager-bases/controllers";
6
6
  import Data from "../manager-bases/data";
7
7
  import Internal from "../manager-bases/internal";
8
+
8
9
  import { IAPIConfig } from "../interfaces/config";
9
10
 
10
11
  import '../globals';
@@ -12,23 +13,30 @@ import '../globals';
12
13
  export const afterInitializeCallbacks: ( () => void )[] = [];
13
14
 
14
15
  export function initialize( config: IAPIConfig ) {
15
- __ZEN_MANAGERS__.commands = new Commands();
16
- __ZEN_MANAGERS__.controllers = new Controllers();
17
- __ZEN_MANAGERS__.data = new Data( config );
18
- __ZEN_MANAGERS__.internal = new Internal();
16
+ commands = new Commands();
17
+ controllers = new Controllers();
18
+ data = new Data( config );
19
+ internal = new Internal();
19
20
  }
20
21
 
21
22
  export function destroy() {
22
- __ZEN_MANAGERS__.commands = {} as Commands;
23
- __ZEN_MANAGERS__.controllers = {} as Controllers;
24
- __ZEN_MANAGERS__.data = {} as Data;
25
- __ZEN_MANAGERS__.internal = {} as Internal;
23
+ commands = {} as Commands;
24
+ controllers = {} as Controllers;
25
+ data = {} as Data;
26
+ internal = {} as Internal;
26
27
  }
27
28
 
28
- export const controllers = __ZEN_MANAGERS__.controllers;
29
- export const commands = __ZEN_MANAGERS__.commands;
30
- export const data = __ZEN_MANAGERS__.data;
31
- export const internal = __ZEN_MANAGERS__.internal;
29
+ export var commands = {} as Commands;
30
+ export var controllers = {} as Controllers;
31
+ export var data = {} as Data;
32
+ export var internal = {} as Internal;
32
33
 
34
+ /*
33
35
  __ZEN_MANAGERS__.initialize = initialize;
34
36
  __ZEN_MANAGERS__.destroy = destroy;
37
+
38
+ export var commands = __ZEN_MANAGERS__.commands;
39
+ export var controllers = __ZEN_MANAGERS__.controllers;
40
+ export var data = __ZEN_MANAGERS__.data;
41
+ export var internal = __ZEN_MANAGERS__.internal;
42
+ */
package/src/globals.ts DELETED
@@ -1,28 +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 { IManagers } from "./interfaces/managers";
7
-
8
- const managers: IManagers = {
9
- initialize: () => {},
10
- destroy: () => {},
11
-
12
- commands: {} as Commands,
13
- controllers: {} as Controllers,
14
- data: {} as Data,
15
- internal: {} as Internal,
16
- }
17
-
18
- if ( typeof __ZEN_MANAGERS__ === 'undefined' || ! __ZEN_MANAGERS__ ) {
19
- globalThis.__ZEN_MANAGERS__ = managers;
20
- }
21
-
22
- declare global {
23
- var ZenCore: any;
24
- }
25
-
26
- declare global {
27
- var __ZEN_MANAGERS__: typeof managers;
28
- }