@zenflux/core 0.0.0-abc.9 → 0.0.0-development.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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.9";
6
+ var version = "0.0.0-abc.17";
7
7
  var description = "ZenFlux core";
8
8
  var author = "Leonid Vinikov <leonidvinikov@gmail.com> (https://github.com/iNewLegend)";
9
9
  var scripts = {
@@ -74,40 +74,16 @@ var pkg = {
74
74
  dependencies: dependencies
75
75
  };
76
76
 
77
- class ForceMethodBase extends Error {
78
- constructor(className, methodName) {
79
- super(`ForeMethod implementation: at '${className}' method: '${methodName}'`);
80
- }
81
- }
82
- class ForceMethod extends Error {
83
- constructor(context, methodName) {
84
- super(`ForeMethod implementation: at '${context.getName()}' method: '${methodName}'`);
85
- }
86
- }
87
-
88
- /**
89
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
90
- * @description: is base class/object for all classes, responsible for: 'getName', implementation.
91
- */
92
- let IdCounter = 0;
93
- /**
94
- * Base class 4 *
95
- */
96
- class ObjectBase {
97
- virtualId = 0;
98
- static getName() {
99
- throw new ForceMethodBase("ObjectBase", "getName");
100
- }
101
- constructor() {
102
- this.virtualId = IdCounter;
103
- APIIncreaseIdCounter();
104
- }
105
- getName() {
106
- return this.constructor.getName();
107
- }
108
- }
109
- function APIIncreaseIdCounter() {
110
- return IdCounter++;
77
+ if (typeof __ZEN_MANAGERS__ === 'undefined' || !__ZEN_MANAGERS__) {
78
+ const managers = {
79
+ initialize: () => {},
80
+ destroy: () => {},
81
+ commands: {},
82
+ controllers: {},
83
+ data: {},
84
+ internal: {}
85
+ };
86
+ globalThis.__ZEN_MANAGERS__ = managers;
111
87
  }
112
88
 
113
89
  /**
@@ -464,120 +440,47 @@ class Logger {
464
440
  }
465
441
  }
466
442
 
467
- /**
468
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
469
- * @description: Base for all commands, they are all will be managed by the `Commands` managers.
470
- * @TODO
471
- * - Add validateArgs method or find something better.
472
- */
473
- class CommandBase extends ObjectBase {
474
- args = {};
475
- options = {};
476
- logger;
477
- constructor(args = {}, options = {}) {
478
- super();
479
- const name = this.constructor.getName();
480
- this.logger = new Logger(name, true, {
481
- sameColor: true
482
- });
483
- this.logger.startWith({
484
- args,
485
- options
486
- });
487
- this.initialize(args, options);
488
- }
489
- initialize(args, options) {
490
- this.args = args;
491
- this.options = options;
492
- }
493
- apply(args = this.args, options = this.options) {
494
- throw new ForceMethod(this, "apply");
495
- }
496
- async run() {
497
- this.onBeforeApply && this.onBeforeApply();
498
- const result = await this.apply(this.args, this.options);
499
- this.onAfterApply && this.onAfterApply();
500
- return result;
501
- }
502
- getArgs() {
503
- return this.args;
504
- }
505
- getOptions() {
506
- return this.options;
443
+ var index$5 = /*#__PURE__*/Object.freeze({
444
+ __proto__: null,
445
+ Logger: Logger
446
+ });
447
+
448
+ class ForceMethodBase extends Error {
449
+ constructor(className, methodName) {
450
+ super(`ForeMethod implementation: at '${className}' method: '${methodName}'`);
507
451
  }
508
452
  }
509
-
510
- /**
511
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
512
- * @description: CommandPublic represents a USER action, every class which inherit from this class will USER action.
513
- * */
514
- class CommandPublic extends CommandBase {
515
- static getName() {
516
- return 'Core/CommandBases/CommandPublic';
453
+ class ForceMethod extends Error {
454
+ constructor(context, methodName) {
455
+ super(`ForeMethod implementation: at '${context.getName()}' method: '${methodName}'`);
517
456
  }
518
457
  }
519
458
 
520
459
  /**
521
460
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
522
- * @description: Each data command should represent a final REST endpoint.
461
+ * @description: is base class/object for all classes, responsible for: 'getName', implementation.
523
462
  */
524
- class CommandData extends CommandBase {
463
+ let IdCounter = 0;
464
+ /**
465
+ * Base class 4 *
466
+ */
467
+ class ObjectBase {
468
+ virtualId = 0;
525
469
  static getName() {
526
- return 'Core/CommandBases/CommandData';
527
- }
528
- /**
529
- * Function getEndpoint() : Override this method is required to determine endpoint and magic query params.
530
- * @example
531
- * ```
532
- * args = { query: { id: 1 } };
533
- * getEndpoint() = '/api/v1/users/{id}';
534
- * result = '/api/v1/users/1';
535
- * ```
536
- */
537
- getEndpoint() {
538
- throw new ForceMethod(this, 'getEndpoint');
470
+ throw new ForceMethodBase("ObjectBase", "getName");
539
471
  }
540
- apply(args = this.args, options = this.options) {
541
- const endpoint = this.applyEndpointFormat(this.getEndpoint(), args);
542
- return __ZEN_MANAGERS__.data.getClient().fetch(endpoint, __ZEN_MANAGERS__.data.currentHttpMethod, args || null);
472
+ constructor() {
473
+ this.virtualId = IdCounter;
474
+ APIIncreaseIdCounter();
543
475
  }
544
- applyEndpointFormat(endpoint, data = {}) {
545
- // Replace query with `magic` placeholders.
546
- if (endpoint.includes('{')) {
547
- endpoint = endpoint.split('/').map(endpointPart => {
548
- const match = endpointPart.match('\\{(.*?)\\}');
549
- if (match?.length && 'undefined' !== typeof data[match[1]]) {
550
- return data[match[1]];
551
- }
552
- return endpointPart;
553
- }).join('/');
554
- }
555
- return endpoint;
476
+ getName() {
477
+ return this.constructor.getName();
556
478
  }
557
479
  }
558
-
559
- /**
560
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
561
- * @description: CommandInternal, is used when part of the logic needed to be in the command but not represent a user action.
562
- */
563
- class CommandInternal extends CommandBase {
564
- static getName() {
565
- return 'Core/CommandBases/CommandInternal';
566
- }
480
+ function APIIncreaseIdCounter() {
481
+ return IdCounter++;
567
482
  }
568
483
 
569
- /**
570
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
571
- */
572
-
573
- var index$5 = /*#__PURE__*/Object.freeze({
574
- __proto__: null,
575
- CommandBase: CommandBase,
576
- CommandData: CommandData,
577
- CommandInternal: CommandInternal,
578
- CommandPublic: CommandPublic
579
- });
580
-
581
484
  /**
582
485
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
583
486
  * @description: Responsible for commands, Aka ( CommandsSpace ).
@@ -648,11 +551,6 @@ ControllerAlreadyRegistered: ControllerAlreadyRegistered,
648
551
  ForceMethod: ForceMethod
649
552
  });
650
553
 
651
- var index$2 = /*#__PURE__*/Object.freeze({
652
- __proto__: null,
653
- Logger: Logger
654
- });
655
-
656
554
  /**
657
555
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
658
556
  * @description: Responsible for manging/running/hooking commands.
@@ -1015,14 +913,10 @@ class Internal extends Commands {
1015
913
  }
1016
914
  }
1017
915
 
1018
- if (typeof __ZEN_MANAGERS__ === 'undefined' || !__ZEN_MANAGERS__) {
1019
- // @ts-ignore
1020
- globalThis.__ZEN_MANAGERS__ = {};
1021
- }
1022
-
1023
916
  /**
1024
917
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
1025
918
  */
919
+ const afterInitializeCallbacks = [];
1026
920
  function initialize(config) {
1027
921
  __ZEN_MANAGERS__.commands = new Commands();
1028
922
  __ZEN_MANAGERS__.controllers = new Controllers();
@@ -1039,15 +933,132 @@ const controllers = __ZEN_MANAGERS__.controllers;
1039
933
  const commands = __ZEN_MANAGERS__.commands;
1040
934
  const data = __ZEN_MANAGERS__.data;
1041
935
  const internal = __ZEN_MANAGERS__.internal;
936
+ __ZEN_MANAGERS__.initialize = initialize;
937
+ __ZEN_MANAGERS__.destroy = destroy;
1042
938
 
1043
- var index$1 = /*#__PURE__*/Object.freeze({
939
+ var index$2 = /*#__PURE__*/Object.freeze({
1044
940
  __proto__: null,
1045
- get commands () { return commands; },
1046
- get controllers () { return controllers; },
1047
- get data () { return data; },
941
+ afterInitializeCallbacks: afterInitializeCallbacks,
942
+ commands: commands,
943
+ controllers: controllers,
944
+ data: data,
1048
945
  destroy: destroy,
1049
946
  initialize: initialize,
1050
- get internal () { return internal; }
947
+ internal: internal
948
+ });
949
+
950
+ /**
951
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
952
+ * @description: Base for all commands, they are all will be managed by the `Commands` managers.
953
+ * @TODO
954
+ * - Add validateArgs method or find something better.
955
+ */
956
+ class CommandBase extends ObjectBase {
957
+ args = {};
958
+ options = {};
959
+ logger;
960
+ constructor(args = {}, options = {}) {
961
+ super();
962
+ const name = this.constructor.getName();
963
+ this.logger = new Logger(name, true, {
964
+ sameColor: true
965
+ });
966
+ this.logger.startWith({
967
+ args,
968
+ options
969
+ });
970
+ this.initialize(args, options);
971
+ }
972
+ initialize(args, options) {
973
+ this.args = args;
974
+ this.options = options;
975
+ }
976
+ apply(args = this.args, options = this.options) {
977
+ throw new ForceMethod(this, "apply");
978
+ }
979
+ async run() {
980
+ this.onBeforeApply && this.onBeforeApply();
981
+ const result = await this.apply(this.args, this.options);
982
+ this.onAfterApply && this.onAfterApply();
983
+ return result;
984
+ }
985
+ getArgs() {
986
+ return this.args;
987
+ }
988
+ getOptions() {
989
+ return this.options;
990
+ }
991
+ }
992
+
993
+ /**
994
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
995
+ * @description: CommandPublic represents a USER action, every class which inherit from this class will USER action.
996
+ * */
997
+ class CommandPublic extends CommandBase {
998
+ static getName() {
999
+ return 'Core/CommandBases/CommandPublic';
1000
+ }
1001
+ }
1002
+
1003
+ /**
1004
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
1005
+ * @description: Each data command should represent a final REST endpoint.
1006
+ */
1007
+ class CommandData extends CommandBase {
1008
+ static getName() {
1009
+ return 'Core/CommandBases/CommandData';
1010
+ }
1011
+ /**
1012
+ * Function getEndpoint() : Override this method is required to determine endpoint and magic query params.
1013
+ * @example
1014
+ * ```
1015
+ * args = { query: { id: 1 } };
1016
+ * getEndpoint() = '/api/v1/users/{id}';
1017
+ * result = '/api/v1/users/1';
1018
+ * ```
1019
+ */
1020
+ getEndpoint() {
1021
+ throw new ForceMethod(this, 'getEndpoint');
1022
+ }
1023
+ apply(args = this.args, options = this.options) {
1024
+ const endpoint = this.applyEndpointFormat(this.getEndpoint(), args);
1025
+ return __ZEN_MANAGERS__.data.getClient().fetch(endpoint, __ZEN_MANAGERS__.data.currentHttpMethod, args || null);
1026
+ }
1027
+ applyEndpointFormat(endpoint, data = {}) {
1028
+ // Replace query with `magic` placeholders.
1029
+ if (endpoint.includes('{')) {
1030
+ endpoint = endpoint.split('/').map(endpointPart => {
1031
+ const match = endpointPart.match('\\{(.*?)\\}');
1032
+ if (match?.length && 'undefined' !== typeof data[match[1]]) {
1033
+ return data[match[1]];
1034
+ }
1035
+ return endpointPart;
1036
+ }).join('/');
1037
+ }
1038
+ return endpoint;
1039
+ }
1040
+ }
1041
+
1042
+ /**
1043
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
1044
+ * @description: CommandInternal, is used when part of the logic needed to be in the command but not represent a user action.
1045
+ */
1046
+ class CommandInternal extends CommandBase {
1047
+ static getName() {
1048
+ return 'Core/CommandBases/CommandInternal';
1049
+ }
1050
+ }
1051
+
1052
+ /**
1053
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
1054
+ */
1055
+
1056
+ var index$1 = /*#__PURE__*/Object.freeze({
1057
+ __proto__: null,
1058
+ CommandBase: CommandBase,
1059
+ CommandData: CommandData,
1060
+ CommandInternal: CommandInternal,
1061
+ CommandPublic: CommandPublic
1051
1062
  });
1052
1063
 
1053
1064
  /**
@@ -1068,12 +1079,12 @@ Internal: Internal
1068
1079
 
1069
1080
  var exported = /*#__PURE__*/Object.freeze({
1070
1081
  __proto__: null,
1071
- commandBases: index$5,
1082
+ commandBases: index$1,
1072
1083
  core: index$4,
1073
1084
  errors: index$3,
1074
1085
  managerBases: index,
1075
- managers: index$1,
1076
- modules: index$2,
1086
+ managers: index$2,
1087
+ modules: index$5,
1077
1088
  utils: index$6
1078
1089
  });
1079
1090
 
@@ -1087,39 +1098,32 @@ errorInitTwice();
1087
1098
  let config = {
1088
1099
  version: pkg.version
1089
1100
  };
1090
- const afterInitializeCallbacks = [];
1091
1101
  const CoreAPI = {
1092
1102
  initialize: configuration => {
1093
1103
  errorInitTwice();
1094
1104
  config = configuration || config;
1095
- commands = new Commands();
1096
- controllers = new Controllers();
1097
- data = new Data(config);
1098
- internal = new Internal();
1105
+ initialize(config);
1099
1106
  isInitialized = true;
1100
- afterInitializeCallbacks.forEach(callback => callback());
1101
1107
  },
1102
1108
  destroy: () => {
1109
+ destroy();
1103
1110
  isInitialized = false;
1104
- commands = {};
1105
- controllers = {};
1106
- data = {};
1107
- internal = {};
1108
1111
  },
1109
1112
  onAfterInitialize: callback => {
1110
1113
  afterInitializeCallbacks.push(callback);
1111
1114
  },
1112
1115
  config,
1113
- ...exported
1116
+ ...exported,
1117
+ managers: typeof __ZEN_MANAGERS__ !== 'undefined' ? __ZEN_MANAGERS__ : {}
1114
1118
  };
1115
1119
  // TODO: Make it available only for development.
1116
1120
  if (!globalThis?.ZenCore) globalThis.ZenCore = CoreAPI;
1117
1121
 
1118
- exports.commandBases = index$5;
1122
+ exports.commandBases = index$1;
1119
1123
  exports.core = index$4;
1120
1124
  exports.default = CoreAPI;
1121
1125
  exports.errors = index$3;
1122
1126
  exports.managerBases = index;
1123
- exports.managers = index$1;
1124
- exports.modules = index$2;
1127
+ exports.managers = index$2;
1128
+ exports.modules = index$5;
1125
1129
  exports.utils = index$6;
@@ -2,14 +2,16 @@ import Commands from "./manager-bases/commands";
2
2
  import Controllers from "./manager-bases/controllers";
3
3
  import Data from "./manager-bases/data";
4
4
  import Internal from "./manager-bases/internal";
5
+ declare global {
6
+ var ZenCore: any;
7
+ }
5
8
  declare global {
6
9
  var __ZEN_MANAGERS__: {
10
+ initialize: (config: any) => void;
11
+ destroy: () => void;
7
12
  commands: Commands;
8
13
  controllers: Controllers;
9
14
  data: Data;
10
15
  internal: Internal;
11
16
  };
12
17
  }
13
- declare global {
14
- var ZenCore: any;
15
- }
@@ -1,14 +1,13 @@
1
- import * as exported from './exports';
1
+ import './globals';
2
2
  import { IAPIConfig } from "./interfaces/config";
3
- declare global {
4
- var ZenCore: any;
5
- }
3
+ import * as exported from './exports';
4
+ import { IManagers } from "./interfaces/managers";
6
5
  export declare let config: IAPIConfig;
7
6
  export declare const CoreAPI: {
7
+ managers: IManagers;
8
8
  commandBases: typeof exported.commandBases;
9
9
  core: typeof exported.core;
10
10
  errors: typeof exported.errors;
11
- managers: typeof exported.managers;
12
11
  managerBases: typeof exported.managerBases;
13
12
  modules: typeof exported.modules;
14
13
  utils: typeof exported.utils;
@@ -0,0 +1,13 @@
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
+ import { IAPIConfig } from "./config";
6
+ export interface IManagers {
7
+ initialize: (config: IAPIConfig) => void;
8
+ destroy: () => void;
9
+ commands: Commands;
10
+ controllers: Controllers;
11
+ data: Data;
12
+ internal: Internal;
13
+ }
@@ -7,6 +7,7 @@ import Data from "../manager-bases/data";
7
7
  import Internal from "../manager-bases/internal";
8
8
  import { IAPIConfig } from "../interfaces/config";
9
9
  import '../globals';
10
+ export declare const afterInitializeCallbacks: (() => void)[];
10
11
  export declare function initialize(config: IAPIConfig): void;
11
12
  export declare function destroy(): void;
12
13
  export declare const controllers: Controllers;
@@ -1,5 +1,5 @@
1
1
  var name = "@zenflux/core";
2
- var version = "0.0.0-abc.9";
2
+ var version = "0.0.0-abc.17";
3
3
  var description = "ZenFlux core";
4
4
  var author = "Leonid Vinikov <leonidvinikov@gmail.com> (https://github.com/iNewLegend)";
5
5
  var scripts = {
@@ -70,40 +70,16 @@ var pkg = {
70
70
  dependencies: dependencies
71
71
  };
72
72
 
73
- class ForceMethodBase extends Error {
74
- constructor(className, methodName) {
75
- super(`ForeMethod implementation: at '${className}' method: '${methodName}'`);
76
- }
77
- }
78
- class ForceMethod extends Error {
79
- constructor(context, methodName) {
80
- super(`ForeMethod implementation: at '${context.getName()}' method: '${methodName}'`);
81
- }
82
- }
83
-
84
- /**
85
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
86
- * @description: is base class/object for all classes, responsible for: 'getName', implementation.
87
- */
88
- let IdCounter = 0;
89
- /**
90
- * Base class 4 *
91
- */
92
- class ObjectBase {
93
- virtualId = 0;
94
- static getName() {
95
- throw new ForceMethodBase("ObjectBase", "getName");
96
- }
97
- constructor() {
98
- this.virtualId = IdCounter;
99
- APIIncreaseIdCounter();
100
- }
101
- getName() {
102
- return this.constructor.getName();
103
- }
104
- }
105
- function APIIncreaseIdCounter() {
106
- return IdCounter++;
73
+ if (typeof __ZEN_MANAGERS__ === 'undefined' || !__ZEN_MANAGERS__) {
74
+ const managers = {
75
+ initialize: () => {},
76
+ destroy: () => {},
77
+ commands: {},
78
+ controllers: {},
79
+ data: {},
80
+ internal: {}
81
+ };
82
+ globalThis.__ZEN_MANAGERS__ = managers;
107
83
  }
108
84
 
109
85
  /**
@@ -460,120 +436,47 @@ class Logger {
460
436
  }
461
437
  }
462
438
 
463
- /**
464
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
465
- * @description: Base for all commands, they are all will be managed by the `Commands` managers.
466
- * @TODO
467
- * - Add validateArgs method or find something better.
468
- */
469
- class CommandBase extends ObjectBase {
470
- args = {};
471
- options = {};
472
- logger;
473
- constructor(args = {}, options = {}) {
474
- super();
475
- const name = this.constructor.getName();
476
- this.logger = new Logger(name, true, {
477
- sameColor: true
478
- });
479
- this.logger.startWith({
480
- args,
481
- options
482
- });
483
- this.initialize(args, options);
484
- }
485
- initialize(args, options) {
486
- this.args = args;
487
- this.options = options;
488
- }
489
- apply(args = this.args, options = this.options) {
490
- throw new ForceMethod(this, "apply");
491
- }
492
- async run() {
493
- this.onBeforeApply && this.onBeforeApply();
494
- const result = await this.apply(this.args, this.options);
495
- this.onAfterApply && this.onAfterApply();
496
- return result;
497
- }
498
- getArgs() {
499
- return this.args;
500
- }
501
- getOptions() {
502
- return this.options;
439
+ var index$5 = /*#__PURE__*/Object.freeze({
440
+ __proto__: null,
441
+ Logger: Logger
442
+ });
443
+
444
+ class ForceMethodBase extends Error {
445
+ constructor(className, methodName) {
446
+ super(`ForeMethod implementation: at '${className}' method: '${methodName}'`);
503
447
  }
504
448
  }
505
-
506
- /**
507
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
508
- * @description: CommandPublic represents a USER action, every class which inherit from this class will USER action.
509
- * */
510
- class CommandPublic extends CommandBase {
511
- static getName() {
512
- return 'Core/CommandBases/CommandPublic';
449
+ class ForceMethod extends Error {
450
+ constructor(context, methodName) {
451
+ super(`ForeMethod implementation: at '${context.getName()}' method: '${methodName}'`);
513
452
  }
514
453
  }
515
454
 
516
455
  /**
517
456
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
518
- * @description: Each data command should represent a final REST endpoint.
457
+ * @description: is base class/object for all classes, responsible for: 'getName', implementation.
519
458
  */
520
- class CommandData extends CommandBase {
459
+ let IdCounter = 0;
460
+ /**
461
+ * Base class 4 *
462
+ */
463
+ class ObjectBase {
464
+ virtualId = 0;
521
465
  static getName() {
522
- return 'Core/CommandBases/CommandData';
523
- }
524
- /**
525
- * Function getEndpoint() : Override this method is required to determine endpoint and magic query params.
526
- * @example
527
- * ```
528
- * args = { query: { id: 1 } };
529
- * getEndpoint() = '/api/v1/users/{id}';
530
- * result = '/api/v1/users/1';
531
- * ```
532
- */
533
- getEndpoint() {
534
- throw new ForceMethod(this, 'getEndpoint');
466
+ throw new ForceMethodBase("ObjectBase", "getName");
535
467
  }
536
- apply(args = this.args, options = this.options) {
537
- const endpoint = this.applyEndpointFormat(this.getEndpoint(), args);
538
- return __ZEN_MANAGERS__.data.getClient().fetch(endpoint, __ZEN_MANAGERS__.data.currentHttpMethod, args || null);
468
+ constructor() {
469
+ this.virtualId = IdCounter;
470
+ APIIncreaseIdCounter();
539
471
  }
540
- applyEndpointFormat(endpoint, data = {}) {
541
- // Replace query with `magic` placeholders.
542
- if (endpoint.includes('{')) {
543
- endpoint = endpoint.split('/').map(endpointPart => {
544
- const match = endpointPart.match('\\{(.*?)\\}');
545
- if (match?.length && 'undefined' !== typeof data[match[1]]) {
546
- return data[match[1]];
547
- }
548
- return endpointPart;
549
- }).join('/');
550
- }
551
- return endpoint;
472
+ getName() {
473
+ return this.constructor.getName();
552
474
  }
553
475
  }
554
-
555
- /**
556
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
557
- * @description: CommandInternal, is used when part of the logic needed to be in the command but not represent a user action.
558
- */
559
- class CommandInternal extends CommandBase {
560
- static getName() {
561
- return 'Core/CommandBases/CommandInternal';
562
- }
476
+ function APIIncreaseIdCounter() {
477
+ return IdCounter++;
563
478
  }
564
479
 
565
- /**
566
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
567
- */
568
-
569
- var index$5 = /*#__PURE__*/Object.freeze({
570
- __proto__: null,
571
- CommandBase: CommandBase,
572
- CommandData: CommandData,
573
- CommandInternal: CommandInternal,
574
- CommandPublic: CommandPublic
575
- });
576
-
577
480
  /**
578
481
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
579
482
  * @description: Responsible for commands, Aka ( CommandsSpace ).
@@ -644,11 +547,6 @@ ControllerAlreadyRegistered: ControllerAlreadyRegistered,
644
547
  ForceMethod: ForceMethod
645
548
  });
646
549
 
647
- var index$2 = /*#__PURE__*/Object.freeze({
648
- __proto__: null,
649
- Logger: Logger
650
- });
651
-
652
550
  /**
653
551
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
654
552
  * @description: Responsible for manging/running/hooking commands.
@@ -1011,14 +909,10 @@ class Internal extends Commands {
1011
909
  }
1012
910
  }
1013
911
 
1014
- if (typeof __ZEN_MANAGERS__ === 'undefined' || !__ZEN_MANAGERS__) {
1015
- // @ts-ignore
1016
- globalThis.__ZEN_MANAGERS__ = {};
1017
- }
1018
-
1019
912
  /**
1020
913
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
1021
914
  */
915
+ const afterInitializeCallbacks = [];
1022
916
  function initialize(config) {
1023
917
  __ZEN_MANAGERS__.commands = new Commands();
1024
918
  __ZEN_MANAGERS__.controllers = new Controllers();
@@ -1035,15 +929,132 @@ const controllers = __ZEN_MANAGERS__.controllers;
1035
929
  const commands = __ZEN_MANAGERS__.commands;
1036
930
  const data = __ZEN_MANAGERS__.data;
1037
931
  const internal = __ZEN_MANAGERS__.internal;
932
+ __ZEN_MANAGERS__.initialize = initialize;
933
+ __ZEN_MANAGERS__.destroy = destroy;
1038
934
 
1039
- var index$1 = /*#__PURE__*/Object.freeze({
935
+ var index$2 = /*#__PURE__*/Object.freeze({
1040
936
  __proto__: null,
1041
- get commands () { return commands; },
1042
- get controllers () { return controllers; },
1043
- get data () { return data; },
937
+ afterInitializeCallbacks: afterInitializeCallbacks,
938
+ commands: commands,
939
+ controllers: controllers,
940
+ data: data,
1044
941
  destroy: destroy,
1045
942
  initialize: initialize,
1046
- get internal () { return internal; }
943
+ internal: internal
944
+ });
945
+
946
+ /**
947
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
948
+ * @description: Base for all commands, they are all will be managed by the `Commands` managers.
949
+ * @TODO
950
+ * - Add validateArgs method or find something better.
951
+ */
952
+ class CommandBase extends ObjectBase {
953
+ args = {};
954
+ options = {};
955
+ logger;
956
+ constructor(args = {}, options = {}) {
957
+ super();
958
+ const name = this.constructor.getName();
959
+ this.logger = new Logger(name, true, {
960
+ sameColor: true
961
+ });
962
+ this.logger.startWith({
963
+ args,
964
+ options
965
+ });
966
+ this.initialize(args, options);
967
+ }
968
+ initialize(args, options) {
969
+ this.args = args;
970
+ this.options = options;
971
+ }
972
+ apply(args = this.args, options = this.options) {
973
+ throw new ForceMethod(this, "apply");
974
+ }
975
+ async run() {
976
+ this.onBeforeApply && this.onBeforeApply();
977
+ const result = await this.apply(this.args, this.options);
978
+ this.onAfterApply && this.onAfterApply();
979
+ return result;
980
+ }
981
+ getArgs() {
982
+ return this.args;
983
+ }
984
+ getOptions() {
985
+ return this.options;
986
+ }
987
+ }
988
+
989
+ /**
990
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
991
+ * @description: CommandPublic represents a USER action, every class which inherit from this class will USER action.
992
+ * */
993
+ class CommandPublic extends CommandBase {
994
+ static getName() {
995
+ return 'Core/CommandBases/CommandPublic';
996
+ }
997
+ }
998
+
999
+ /**
1000
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
1001
+ * @description: Each data command should represent a final REST endpoint.
1002
+ */
1003
+ class CommandData extends CommandBase {
1004
+ static getName() {
1005
+ return 'Core/CommandBases/CommandData';
1006
+ }
1007
+ /**
1008
+ * Function getEndpoint() : Override this method is required to determine endpoint and magic query params.
1009
+ * @example
1010
+ * ```
1011
+ * args = { query: { id: 1 } };
1012
+ * getEndpoint() = '/api/v1/users/{id}';
1013
+ * result = '/api/v1/users/1';
1014
+ * ```
1015
+ */
1016
+ getEndpoint() {
1017
+ throw new ForceMethod(this, 'getEndpoint');
1018
+ }
1019
+ apply(args = this.args, options = this.options) {
1020
+ const endpoint = this.applyEndpointFormat(this.getEndpoint(), args);
1021
+ return __ZEN_MANAGERS__.data.getClient().fetch(endpoint, __ZEN_MANAGERS__.data.currentHttpMethod, args || null);
1022
+ }
1023
+ applyEndpointFormat(endpoint, data = {}) {
1024
+ // Replace query with `magic` placeholders.
1025
+ if (endpoint.includes('{')) {
1026
+ endpoint = endpoint.split('/').map(endpointPart => {
1027
+ const match = endpointPart.match('\\{(.*?)\\}');
1028
+ if (match?.length && 'undefined' !== typeof data[match[1]]) {
1029
+ return data[match[1]];
1030
+ }
1031
+ return endpointPart;
1032
+ }).join('/');
1033
+ }
1034
+ return endpoint;
1035
+ }
1036
+ }
1037
+
1038
+ /**
1039
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
1040
+ * @description: CommandInternal, is used when part of the logic needed to be in the command but not represent a user action.
1041
+ */
1042
+ class CommandInternal extends CommandBase {
1043
+ static getName() {
1044
+ return 'Core/CommandBases/CommandInternal';
1045
+ }
1046
+ }
1047
+
1048
+ /**
1049
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
1050
+ */
1051
+
1052
+ var index$1 = /*#__PURE__*/Object.freeze({
1053
+ __proto__: null,
1054
+ CommandBase: CommandBase,
1055
+ CommandData: CommandData,
1056
+ CommandInternal: CommandInternal,
1057
+ CommandPublic: CommandPublic
1047
1058
  });
1048
1059
 
1049
1060
  /**
@@ -1064,12 +1075,12 @@ Internal: Internal
1064
1075
 
1065
1076
  var exported = /*#__PURE__*/Object.freeze({
1066
1077
  __proto__: null,
1067
- commandBases: index$5,
1078
+ commandBases: index$1,
1068
1079
  core: index$4,
1069
1080
  errors: index$3,
1070
1081
  managerBases: index,
1071
- managers: index$1,
1072
- modules: index$2,
1082
+ managers: index$2,
1083
+ modules: index$5,
1073
1084
  utils: index$6
1074
1085
  });
1075
1086
 
@@ -1083,32 +1094,25 @@ errorInitTwice();
1083
1094
  let config = {
1084
1095
  version: pkg.version
1085
1096
  };
1086
- const afterInitializeCallbacks = [];
1087
1097
  const CoreAPI = {
1088
1098
  initialize: configuration => {
1089
1099
  errorInitTwice();
1090
1100
  config = configuration || config;
1091
- commands = new Commands();
1092
- controllers = new Controllers();
1093
- data = new Data(config);
1094
- internal = new Internal();
1101
+ initialize(config);
1095
1102
  isInitialized = true;
1096
- afterInitializeCallbacks.forEach(callback => callback());
1097
1103
  },
1098
1104
  destroy: () => {
1105
+ destroy();
1099
1106
  isInitialized = false;
1100
- commands = {};
1101
- controllers = {};
1102
- data = {};
1103
- internal = {};
1104
1107
  },
1105
1108
  onAfterInitialize: callback => {
1106
1109
  afterInitializeCallbacks.push(callback);
1107
1110
  },
1108
1111
  config,
1109
- ...exported
1112
+ ...exported,
1113
+ managers: typeof __ZEN_MANAGERS__ !== 'undefined' ? __ZEN_MANAGERS__ : {}
1110
1114
  };
1111
1115
  // TODO: Make it available only for development.
1112
1116
  if (!globalThis?.ZenCore) globalThis.ZenCore = CoreAPI;
1113
1117
 
1114
- export { index$5 as commandBases, index$4 as core, CoreAPI as default, index$3 as errors, index as managerBases, index$1 as managers, index$2 as modules, index$6 as utils };
1118
+ 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 };
@@ -1,12 +1,11 @@
1
- var t="0.0.0-abc.9";class e extends Error{constructor(t,e){super(`ForeMethod implementation: at '${t}' method: '${e}'`)}}class r extends Error{constructor(t,e){super(`ForeMethod implementation: at '${t.getName()}' method: '${e}'`)}}let s=0;class n{virtualId=0;static getName(){throw new e("ObjectBase","getName")}constructor(){this.virtualId=s,s++}getName(){return this.constructor.getName()}}
1
+ var t="0.0.0-abc.17";if("undefined"==typeof __ZEN_MANAGERS__||!__ZEN_MANAGERS__){globalThis.__ZEN_MANAGERS__={initialize:()=>{},destroy:()=>{},commands:{},controllers:{},data:{},internal:{}}}
2
2
  /**
3
3
  * Function getCircularReplacer() : Reduce circular references.
4
4
  *
5
5
  * @copyright https://stackoverflow.com/a/53731154
6
- */
7
- const o=()=>{const t=new WeakSet;return(e,r)=>{if("object"==typeof r&&null!==r){if(t.has(r))return;t.add(r)}return r}},a=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
+ */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};
8
7
  /**
9
8
  * Function hexColorDelta() : Return color difference in ratio decimal point.
10
9
  *
11
10
  * @copyright http://jsfiddle.net/96sME/
12
- */var i=Object.freeze({__proto__:null,getCircularReplacer:o,hexColorDelta:a});class c{static wrappers={};static wrapperDepth=0;static sharedData={};static colorsInUse=[];defaultStyle;color;outputHandler;args={};name;state=!1;static getName(){return"Core/Modules/Logger"}static reset(){c.wrappers={},c.wrapperDepth=0,c.colorsInUse=[],c.sharedData={}}static createCustomWrapper(t,e){c.wrappers[t]||(c.wrappers[t.name]=[]),c.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?(c.sharedData[this.name]||(c.sharedData[this.name]=this.getRandomColor()),this.color=c.sharedData[this.name]):(this.color=this.getRandomColor(),c.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;c.wrapperDepth++;let r={...t};return Object.values(c.wrappers).forEach((([e])=>{t instanceof e.classType&&(r=e.callback(t)||r)})),4>c.wrapperDepth?(e&&r&&Object.entries(r).forEach((([t,e])=>{r[t]=this.useWrapper(e,!0)})),c.wrapperDepth--,r):(c.wrapperDepth--,r)}startEmpty(t=""){this.state&&this.printFunctionNotify("se",c.getCallerName(),t)}startWith(t){if(!this.state)return;t=Object.assign({},t);const e="se",r=c.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 r=c.getCallerName();t=Object.create(t);for(let s in t)"object"==typeof t[s]&&(t[s]=JSON.stringify(this.useWrapper(t[s]),o())),this.out.apply(this,[`%c(ob)-> %c%c${this.name}%c::%c${r}%c() [${e}] ->> ${s}: '${t[s]}'%c`].concat(this.defaultStyle))}debug(t){this.state&&this.printFunctionNotify("db",c.getCallerName(),t)}drop(t,e){if(!this.state)return;const r=c.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",c.getCallerName(),t),r&&this.printNextLineObject("tw",c.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=c.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,r){this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c(${Object.keys(r).join(", ")}) %c↓`].concat(this.defaultStyle));for(let t in r){let e=r[t];"object"==typeof e?e=JSON.stringify(this.useWrapper(e),o()):"function"==typeof r[t]&&(e=c.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 c.colorsInUse.some((e=>a(t,e)>=.8))?this.getRandomColor():t}out(...t){this.outputHandler.apply(this,t)}}class l extends n{args={};options={};logger;constructor(t={},e={}){super();const r=this.constructor.getName();this.logger=new c(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 r(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 h=Object.freeze({__proto__:null,CommandBase:l,CommandData:class extends l{static getName(){return"Core/CommandBases/CommandData"}getEndpoint(){throw new r(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 l{static getName(){return"Core/CommandBases/CommandInternal"}},CommandPublic:class extends l{static getName(){return"Core/CommandBases/CommandPublic"}}});var u=Object.freeze({__proto__:null,Controller:class extends n{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:n});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:r}),f=Object.freeze({__proto__:null,Logger:c});class N extends n{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 c(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){N.hookCommand(this.onBeforeHooks,t,e)}onBeforeUI(t,e){N.hookCommand(this.onBeforeUIHooks,t,e)}onAfter(t,e){N.hookCommand(this.onAfterHooks,t,e)}onAfterUI(t,e){N.hookCommand(this.onAfterUIHooks,t,e)}onAfterOnce(t,e){N.hookCommand(this.onAfterOnceHooks,t,e)}onAfterAffect(t,e){N.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 N.runCallbacks(Object.assign([],this.onAfterHooks[t.getName()]),e,r)),this.onAfterOnceHooks&&await N.runCallbacks(this.onAfterOnceHooks[t.getName()],e,{...r,pop:!0}),this.onAfterUIHooks&&N.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()),N.trace.push(t.getName())}detachCurrent(t){delete this.current[t.getName()],delete this.currentArgs[t.getName()],N.trace.pop(),this.trace.pop()}}class A extends n{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 E extends n{logger;apiBaseUrl;static getName(){return"Core/Clients/Http"}constructor(t="http://localhost"){super(),this.logger=new c(E.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 C extends N{static client;currentHttpMethod;static getName(){return"Core/Managers/Data"}constructor(t){super(),C.client=new E(t.baseURL)}getClient(){return C.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 N{static getName(){return"Core/Managers/Internal"}}"undefined"!=typeof __ZEN_MANAGERS__&&__ZEN_MANAGERS__||(globalThis.__ZEN_MANAGERS__={});const b=__ZEN_MANAGERS__.controllers,w=__ZEN_MANAGERS__.commands,O=__ZEN_MANAGERS__.data,k=__ZEN_MANAGERS__.internal;var M=Object.freeze({__proto__:null,get commands(){return w},get controllers(){return b},get data(){return O},destroy:function(){__ZEN_MANAGERS__.commands={},__ZEN_MANAGERS__.controllers={},__ZEN_MANAGERS__.data={},__ZEN_MANAGERS__.internal={}},initialize:function(t){__ZEN_MANAGERS__.commands=new N,__ZEN_MANAGERS__.controllers=new A,__ZEN_MANAGERS__.data=new C(t),__ZEN_MANAGERS__.internal=new y},get internal(){return k}}),H=Object.freeze({__proto__:null,Commands:N,Controllers:A,Data:C,Internal:y}),j=Object.freeze({__proto__:null,commandBases:h,core:u,errors:_,managerBases:H,managers:M,modules:f,utils:i});let I=!1;function S(){if(I)throw Error("ZenCore is already initialized.")}S();let R={version:t};const $=[],B={initialize:t=>{S(),R=t||R,w=new N,b=new A,O=new C(R),k=new y,I=!0,$.forEach((t=>t()))},destroy:()=>{I=!1,w={},b={},O={},k={}},onAfterInitialize:t=>{$.push(t)},config:R,...j};globalThis?.ZenCore||(globalThis.ZenCore=B);export{h as commandBases,u as core,B as default,_ as errors,H as managerBases,M as managers,f as modules,i as utils};
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,M=__ZEN_MANAGERS__.data,k=__ZEN_MANAGERS__.internal;__ZEN_MANAGERS__.initialize=y,__ZEN_MANAGERS__.destroy=b;var H=Object.freeze({__proto__:null,afterInitializeCallbacks:C,commands:O,controllers:w,data:M,destroy:b,initialize:y,internal:k});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,managers:"undefined"!=typeof __ZEN_MANAGERS__?__ZEN_MANAGERS__:{}};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};
@@ -1,12 +1,11 @@
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.9";class r extends Error{constructor(t,e){super(`ForeMethod implementation: at '${t}' method: '${e}'`)}}class s extends Error{constructor(t,e){super(`ForeMethod implementation: at '${t.getName()}' method: '${e}'`)}}let n=0;class o{virtualId=0;static getName(){throw new r("ObjectBase","getName")}constructor(){this.virtualId=n,n++}getName(){return this.constructor.getName()}}
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.17";if("undefined"==typeof __ZEN_MANAGERS__||!__ZEN_MANAGERS__){globalThis.__ZEN_MANAGERS__={initialize:()=>{},destroy:()=>{},commands:{},controllers:{},data:{},internal:{}}}
2
2
  /**
3
3
  * Function getCircularReplacer() : Reduce circular references.
4
4
  *
5
5
  * @copyright https://stackoverflow.com/a/53731154
6
- */
7
- const a=()=>{const t=new WeakSet;return(e,r)=>{if("object"==typeof r&&null!==r){if(t.has(r))return;t.add(r)}return r}},i=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
+ */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};
8
7
  /**
9
8
  * Function hexColorDelta() : Return color difference in ratio decimal point.
10
9
  *
11
10
  * @copyright http://jsfiddle.net/96sME/
12
- */var c=Object.freeze({__proto__:null,getCircularReplacer:a,hexColorDelta:i});class l{static wrappers={};static wrapperDepth=0;static sharedData={};static colorsInUse=[];defaultStyle;color;outputHandler;args={};name;state=!1;static getName(){return"Core/Modules/Logger"}static reset(){l.wrappers={},l.wrapperDepth=0,l.colorsInUse=[],l.sharedData={}}static createCustomWrapper(t,e){l.wrappers[t]||(l.wrappers[t.name]=[]),l.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?(l.sharedData[this.name]||(l.sharedData[this.name]=this.getRandomColor()),this.color=l.sharedData[this.name]):(this.color=this.getRandomColor(),l.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;l.wrapperDepth++;let r={...t};return Object.values(l.wrappers).forEach((([e])=>{t instanceof e.classType&&(r=e.callback(t)||r)})),4>l.wrapperDepth?(e&&r&&Object.entries(r).forEach((([t,e])=>{r[t]=this.useWrapper(e,!0)})),l.wrapperDepth--,r):(l.wrapperDepth--,r)}startEmpty(t=""){this.state&&this.printFunctionNotify("se",l.getCallerName(),t)}startWith(t){if(!this.state)return;t=Object.assign({},t);const e="se",r=l.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 r=l.getCallerName();t=Object.create(t);for(let s in t)"object"==typeof t[s]&&(t[s]=JSON.stringify(this.useWrapper(t[s]),a())),this.out.apply(this,[`%c(ob)-> %c%c${this.name}%c::%c${r}%c() [${e}] ->> ${s}: '${t[s]}'%c`].concat(this.defaultStyle))}debug(t){this.state&&this.printFunctionNotify("db",l.getCallerName(),t)}drop(t,e){if(!this.state)return;const r=l.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",l.getCallerName(),t),r&&this.printNextLineObject("tw",l.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=l.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,r){this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c(${Object.keys(r).join(", ")}) %c↓`].concat(this.defaultStyle));for(let t in r){let e=r[t];"object"==typeof e?e=JSON.stringify(this.useWrapper(e),a()):"function"==typeof r[t]&&(e=l.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 l.colorsInUse.some((e=>i(t,e)>=.8))?this.getRandomColor():t}out(...t){this.outputHandler.apply(this,t)}}class h extends o{args={};options={};logger;constructor(t={},e={}){super();const r=this.constructor.getName();this.logger=new l(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 s(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 u=Object.freeze({__proto__:null,CommandBase:h,CommandData:class extends h{static getName(){return"Core/CommandBases/CommandData"}getEndpoint(){throw new s(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 h{static getName(){return"Core/CommandBases/CommandInternal"}},CommandPublic:class extends h{static getName(){return"Core/CommandBases/CommandPublic"}}});var p=Object.freeze({__proto__:null,Controller:class extends o{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:o});class g extends Error{constructor(t){super(`Command: '${t.getName()}' is already registered`)}}class m extends Error{constructor(t){super(`Command: '${t}' is not found`)}}class d extends Error{constructor(t){super(`Controller: '${t.getName()}' is already registered`)}}var f,_=Object.freeze({__proto__:null,CommandAlreadyRegistered:g,CommandNotFound:m,ControllerAlreadyRegistered:d,ForceMethod:s}),N=Object.freeze({__proto__:null,Logger:l});class A extends o{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 l(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 g(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 m(t);return new s(e,r)}onBefore(t,e){A.hookCommand(this.onBeforeHooks,t,e)}onBeforeUI(t,e){A.hookCommand(this.onBeforeUIHooks,t,e)}onAfter(t,e){A.hookCommand(this.onAfterHooks,t,e)}onAfterUI(t,e){A.hookCommand(this.onAfterUIHooks,t,e)}onAfterOnce(t,e){A.hookCommand(this.onAfterOnceHooks,t,e)}onAfterAffect(t,e){A.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 A.runCallbacks(Object.assign([],this.onAfterHooks[t.getName()]),e,r)),this.onAfterOnceHooks&&await A.runCallbacks(this.onAfterOnceHooks[t.getName()],e,{...r,pop:!0}),this.onAfterUIHooks&&A.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()),A.trace.push(t.getName())}detachCurrent(t){delete this.current[t.getName()],delete this.currentArgs[t.getName()],A.trace.pop(),this.trace.pop()}}class E extends o{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 d(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__=""}(f||(f={}));class y extends o{logger;apiBaseUrl;static getName(){return"Core/Clients/Http"}constructor(t="http://localhost"){super(),this.logger=new l(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={};[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 C extends A{static client;currentHttpMethod;static getName(){return"Core/Managers/Data"}constructor(t){super(),C.client=new y(t.baseURL)}getClient(){return C.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 A{static getName(){return"Core/Managers/Internal"}}"undefined"!=typeof __ZEN_MANAGERS__&&__ZEN_MANAGERS__||(globalThis.__ZEN_MANAGERS__={});const w=__ZEN_MANAGERS__.controllers,O=__ZEN_MANAGERS__.commands,k=__ZEN_MANAGERS__.data,M=__ZEN_MANAGERS__.internal;var j=Object.freeze({__proto__:null,get commands(){return O},get controllers(){return w},get data(){return k},destroy:function(){__ZEN_MANAGERS__.commands={},__ZEN_MANAGERS__.controllers={},__ZEN_MANAGERS__.data={},__ZEN_MANAGERS__.internal={}},initialize:function(t){__ZEN_MANAGERS__.commands=new A,__ZEN_MANAGERS__.controllers=new E,__ZEN_MANAGERS__.data=new C(t),__ZEN_MANAGERS__.internal=new b},get internal(){return M}}),H=Object.freeze({__proto__:null,Commands:A,Controllers:E,Data:C,Internal:b}),I=Object.freeze({__proto__:null,commandBases:u,core:p,errors:_,managerBases:H,managers:j,modules:N,utils:c});let S=!1;function R(){if(S)throw Error("ZenCore is already initialized.")}R();let T={version:e};const $=[],B={initialize:t=>{R(),T=t||T,O=new A,w=new E,k=new C(T),M=new b,S=!0,$.forEach((t=>t()))},destroy:()=>{S=!1,O={},w={},k={},M={}},onAfterInitialize:t=>{$.push(t)},config:T,...I};globalThis?.ZenCore||(globalThis.ZenCore=B),t.commandBases=u,t.core=p,t.default=B,t.errors=_,t.managerBases=H,t.managers=j,t.modules=N,t.utils=c,Object.defineProperty(t,"__esModule",{value:!0})}));
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 Z={initialize:t=>{B(),G=t||G,b(G),$=!0},destroy:()=>{w(),$=!1},onAfterInitialize:t=>{C.push(t)},config:G,...T,managers:"undefined"!=typeof __ZEN_MANAGERS__?__ZEN_MANAGERS__:{}};globalThis?.ZenCore||(globalThis.ZenCore=Z),t.commandBases=S,t.core=u,t.default=Z,t.errors=_,t.managerBases=R,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.9",
3
+ "version": "0.0.0-development.2",
4
4
  "description": "ZenFlux core",
5
5
  "author": "Leonid Vinikov <leonidvinikov@gmail.com> (https://github.com/iNewLegend)",
6
6
  "scripts": {
package/src/globals.ts CHANGED
@@ -3,20 +3,34 @@ import Controllers from "./manager-bases/controllers";
3
3
  import Data from "./manager-bases/data";
4
4
  import Internal from "./manager-bases/internal";
5
5
 
6
+ import { IManagers } from "./interfaces/managers";
7
+
6
8
  if ( typeof __ZEN_MANAGERS__ === 'undefined' || ! __ZEN_MANAGERS__ ) {
7
- // @ts-ignore
8
- globalThis.__ZEN_MANAGERS__ = {};
9
+ const managers: IManagers = {
10
+ initialize: () => {},
11
+ destroy: () => {},
12
+
13
+ commands: {} as Commands,
14
+ controllers: {} as Controllers,
15
+ data: {} as Data,
16
+ internal: {} as Internal,
17
+ }
18
+
19
+ globalThis.__ZEN_MANAGERS__ = managers;
20
+ }
21
+
22
+ declare global {
23
+ var ZenCore: any;
9
24
  }
10
25
 
11
26
  declare global {
12
27
  var __ZEN_MANAGERS__: {
28
+ initialize: ( config: any ) => void;
29
+ destroy: () => void;
30
+
13
31
  commands: Commands;
14
32
  controllers: Controllers;
15
33
  data: Data;
16
34
  internal: Internal;
17
35
  }
18
36
  }
19
-
20
- declare global {
21
- var ZenCore: any;
22
- }
@@ -1,12 +1,13 @@
1
1
  import pkg from "../package.json";
2
2
 
3
- import '../globals'
4
-
5
- import * as exported from './exports';
3
+ import './globals'
6
4
 
7
5
  import { IAPIConfig } from "./interfaces/config";
8
6
 
9
- import { destroy, initialize } from "./managers";
7
+ import { destroy, initialize, afterInitializeCallbacks } from "./managers";
8
+
9
+ import * as exported from './exports';
10
+ import { IManagers } from "./interfaces/managers";
10
11
 
11
12
  let isInitialized = false;
12
13
 
@@ -22,7 +23,6 @@ export let config: IAPIConfig = {
22
23
  version: pkg.version,
23
24
  }
24
25
 
25
- const afterInitializeCallbacks: ( () => void )[] = [];
26
26
 
27
27
  export const CoreAPI = {
28
28
  initialize: ( configuration?: IAPIConfig ) => {
@@ -34,7 +34,6 @@ export const CoreAPI = {
34
34
 
35
35
  isInitialized = true;
36
36
 
37
- afterInitializeCallbacks.forEach( ( callback ) => callback() );
38
37
  },
39
38
 
40
39
  destroy: () => {
@@ -51,7 +50,7 @@ export const CoreAPI = {
51
50
 
52
51
  ...exported,
53
52
 
54
- managers: typeof __ZEN_MANAGERS__ !== 'undefined' ? __ZEN_MANAGERS__ : undefined,
53
+ managers: typeof __ZEN_MANAGERS__ !== 'undefined' ? __ZEN_MANAGERS__ : {} as IManagers
55
54
  }
56
55
 
57
56
  // TODO: Make it available only for development.
@@ -0,0 +1,16 @@
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
+ }
@@ -5,10 +5,11 @@ 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
-
9
8
  import { IAPIConfig } from "../interfaces/config";
10
9
 
11
- import '../globals'
10
+ import '../globals';
11
+
12
+ export const afterInitializeCallbacks: ( () => void )[] = [];
12
13
 
13
14
  export function initialize( config: IAPIConfig ) {
14
15
  __ZEN_MANAGERS__.commands = new Commands();
@@ -28,3 +29,6 @@ export const controllers = __ZEN_MANAGERS__.controllers;
28
29
  export const commands = __ZEN_MANAGERS__.commands;
29
30
  export const data = __ZEN_MANAGERS__.data;
30
31
  export const internal = __ZEN_MANAGERS__.internal;
32
+
33
+ __ZEN_MANAGERS__.initialize = initialize;
34
+ __ZEN_MANAGERS__.destroy = destroy;