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

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.14";
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,15 @@ 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
+ globalThis.__ZEN_MANAGERS__ = {
79
+ initialize: () => {},
80
+ destroy: () => {},
81
+ commands: {},
82
+ controllers: {},
83
+ data: {},
84
+ internal: {}
85
+ };
111
86
  }
112
87
 
113
88
  /**
@@ -464,120 +439,47 @@ class Logger {
464
439
  }
465
440
  }
466
441
 
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;
442
+ var index$5 = /*#__PURE__*/Object.freeze({
443
+ __proto__: null,
444
+ Logger: Logger
445
+ });
446
+
447
+ class ForceMethodBase extends Error {
448
+ constructor(className, methodName) {
449
+ super(`ForeMethod implementation: at '${className}' method: '${methodName}'`);
507
450
  }
508
451
  }
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';
452
+ class ForceMethod extends Error {
453
+ constructor(context, methodName) {
454
+ super(`ForeMethod implementation: at '${context.getName()}' method: '${methodName}'`);
517
455
  }
518
456
  }
519
457
 
520
458
  /**
521
459
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
522
- * @description: Each data command should represent a final REST endpoint.
460
+ * @description: is base class/object for all classes, responsible for: 'getName', implementation.
523
461
  */
524
- class CommandData extends CommandBase {
462
+ let IdCounter = 0;
463
+ /**
464
+ * Base class 4 *
465
+ */
466
+ class ObjectBase {
467
+ virtualId = 0;
525
468
  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');
469
+ throw new ForceMethodBase("ObjectBase", "getName");
539
470
  }
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);
471
+ constructor() {
472
+ this.virtualId = IdCounter;
473
+ APIIncreaseIdCounter();
543
474
  }
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;
475
+ getName() {
476
+ return this.constructor.getName();
556
477
  }
557
478
  }
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
- }
479
+ function APIIncreaseIdCounter() {
480
+ return IdCounter++;
567
481
  }
568
482
 
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
483
  /**
582
484
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
583
485
  * @description: Responsible for commands, Aka ( CommandsSpace ).
@@ -648,11 +550,6 @@ ControllerAlreadyRegistered: ControllerAlreadyRegistered,
648
550
  ForceMethod: ForceMethod
649
551
  });
650
552
 
651
- var index$2 = /*#__PURE__*/Object.freeze({
652
- __proto__: null,
653
- Logger: Logger
654
- });
655
-
656
553
  /**
657
554
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
658
555
  * @description: Responsible for manging/running/hooking commands.
@@ -1015,14 +912,10 @@ class Internal extends Commands {
1015
912
  }
1016
913
  }
1017
914
 
1018
- if (typeof __ZEN_MANAGERS__ === 'undefined' || !__ZEN_MANAGERS__) {
1019
- // @ts-ignore
1020
- globalThis.__ZEN_MANAGERS__ = {};
1021
- }
1022
-
1023
915
  /**
1024
916
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
1025
917
  */
918
+ const afterInitializeCallbacks = [];
1026
919
  function initialize(config) {
1027
920
  __ZEN_MANAGERS__.commands = new Commands();
1028
921
  __ZEN_MANAGERS__.controllers = new Controllers();
@@ -1039,15 +932,132 @@ const controllers = __ZEN_MANAGERS__.controllers;
1039
932
  const commands = __ZEN_MANAGERS__.commands;
1040
933
  const data = __ZEN_MANAGERS__.data;
1041
934
  const internal = __ZEN_MANAGERS__.internal;
935
+ __ZEN_MANAGERS__.initialize = initialize;
936
+ __ZEN_MANAGERS__.destroy = destroy;
1042
937
 
1043
- var index$1 = /*#__PURE__*/Object.freeze({
938
+ var index$2 = /*#__PURE__*/Object.freeze({
1044
939
  __proto__: null,
1045
- get commands () { return commands; },
1046
- get controllers () { return controllers; },
1047
- get data () { return data; },
940
+ afterInitializeCallbacks: afterInitializeCallbacks,
941
+ commands: commands,
942
+ controllers: controllers,
943
+ data: data,
1048
944
  destroy: destroy,
1049
945
  initialize: initialize,
1050
- get internal () { return internal; }
946
+ internal: internal
947
+ });
948
+
949
+ /**
950
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
951
+ * @description: Base for all commands, they are all will be managed by the `Commands` managers.
952
+ * @TODO
953
+ * - Add validateArgs method or find something better.
954
+ */
955
+ class CommandBase extends ObjectBase {
956
+ args = {};
957
+ options = {};
958
+ logger;
959
+ constructor(args = {}, options = {}) {
960
+ super();
961
+ const name = this.constructor.getName();
962
+ this.logger = new Logger(name, true, {
963
+ sameColor: true
964
+ });
965
+ this.logger.startWith({
966
+ args,
967
+ options
968
+ });
969
+ this.initialize(args, options);
970
+ }
971
+ initialize(args, options) {
972
+ this.args = args;
973
+ this.options = options;
974
+ }
975
+ apply(args = this.args, options = this.options) {
976
+ throw new ForceMethod(this, "apply");
977
+ }
978
+ async run() {
979
+ this.onBeforeApply && this.onBeforeApply();
980
+ const result = await this.apply(this.args, this.options);
981
+ this.onAfterApply && this.onAfterApply();
982
+ return result;
983
+ }
984
+ getArgs() {
985
+ return this.args;
986
+ }
987
+ getOptions() {
988
+ return this.options;
989
+ }
990
+ }
991
+
992
+ /**
993
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
994
+ * @description: CommandPublic represents a USER action, every class which inherit from this class will USER action.
995
+ * */
996
+ class CommandPublic extends CommandBase {
997
+ static getName() {
998
+ return 'Core/CommandBases/CommandPublic';
999
+ }
1000
+ }
1001
+
1002
+ /**
1003
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
1004
+ * @description: Each data command should represent a final REST endpoint.
1005
+ */
1006
+ class CommandData extends CommandBase {
1007
+ static getName() {
1008
+ return 'Core/CommandBases/CommandData';
1009
+ }
1010
+ /**
1011
+ * Function getEndpoint() : Override this method is required to determine endpoint and magic query params.
1012
+ * @example
1013
+ * ```
1014
+ * args = { query: { id: 1 } };
1015
+ * getEndpoint() = '/api/v1/users/{id}';
1016
+ * result = '/api/v1/users/1';
1017
+ * ```
1018
+ */
1019
+ getEndpoint() {
1020
+ throw new ForceMethod(this, 'getEndpoint');
1021
+ }
1022
+ apply(args = this.args, options = this.options) {
1023
+ const endpoint = this.applyEndpointFormat(this.getEndpoint(), args);
1024
+ return __ZEN_MANAGERS__.data.getClient().fetch(endpoint, __ZEN_MANAGERS__.data.currentHttpMethod, args || null);
1025
+ }
1026
+ applyEndpointFormat(endpoint, data = {}) {
1027
+ // Replace query with `magic` placeholders.
1028
+ if (endpoint.includes('{')) {
1029
+ endpoint = endpoint.split('/').map(endpointPart => {
1030
+ const match = endpointPart.match('\\{(.*?)\\}');
1031
+ if (match?.length && 'undefined' !== typeof data[match[1]]) {
1032
+ return data[match[1]];
1033
+ }
1034
+ return endpointPart;
1035
+ }).join('/');
1036
+ }
1037
+ return endpoint;
1038
+ }
1039
+ }
1040
+
1041
+ /**
1042
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
1043
+ * @description: CommandInternal, is used when part of the logic needed to be in the command but not represent a user action.
1044
+ */
1045
+ class CommandInternal extends CommandBase {
1046
+ static getName() {
1047
+ return 'Core/CommandBases/CommandInternal';
1048
+ }
1049
+ }
1050
+
1051
+ /**
1052
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
1053
+ */
1054
+
1055
+ var index$1 = /*#__PURE__*/Object.freeze({
1056
+ __proto__: null,
1057
+ CommandBase: CommandBase,
1058
+ CommandData: CommandData,
1059
+ CommandInternal: CommandInternal,
1060
+ CommandPublic: CommandPublic
1051
1061
  });
1052
1062
 
1053
1063
  /**
@@ -1068,12 +1078,12 @@ Internal: Internal
1068
1078
 
1069
1079
  var exported = /*#__PURE__*/Object.freeze({
1070
1080
  __proto__: null,
1071
- commandBases: index$5,
1081
+ commandBases: index$1,
1072
1082
  core: index$4,
1073
1083
  errors: index$3,
1074
1084
  managerBases: index,
1075
- managers: index$1,
1076
- modules: index$2,
1085
+ managers: index$2,
1086
+ modules: index$5,
1077
1087
  utils: index$6
1078
1088
  });
1079
1089
 
@@ -1087,39 +1097,32 @@ errorInitTwice();
1087
1097
  let config = {
1088
1098
  version: pkg.version
1089
1099
  };
1090
- const afterInitializeCallbacks = [];
1091
1100
  const CoreAPI = {
1092
1101
  initialize: configuration => {
1093
1102
  errorInitTwice();
1094
1103
  config = configuration || config;
1095
- commands = new Commands();
1096
- controllers = new Controllers();
1097
- data = new Data(config);
1098
- internal = new Internal();
1104
+ initialize(config);
1099
1105
  isInitialized = true;
1100
- afterInitializeCallbacks.forEach(callback => callback());
1101
1106
  },
1102
1107
  destroy: () => {
1108
+ destroy();
1103
1109
  isInitialized = false;
1104
- commands = {};
1105
- controllers = {};
1106
- data = {};
1107
- internal = {};
1108
1110
  },
1109
1111
  onAfterInitialize: callback => {
1110
1112
  afterInitializeCallbacks.push(callback);
1111
1113
  },
1112
1114
  config,
1113
- ...exported
1115
+ ...exported,
1116
+ managers: typeof __ZEN_MANAGERS__ !== 'undefined' ? __ZEN_MANAGERS__ : undefined
1114
1117
  };
1115
1118
  // TODO: Make it available only for development.
1116
1119
  if (!globalThis?.ZenCore) globalThis.ZenCore = CoreAPI;
1117
1120
 
1118
- exports.commandBases = index$5;
1121
+ exports.commandBases = index$1;
1119
1122
  exports.core = index$4;
1120
1123
  exports.default = CoreAPI;
1121
1124
  exports.errors = index$3;
1122
1125
  exports.managerBases = index;
1123
- exports.managers = index$1;
1124
- exports.modules = index$2;
1126
+ exports.managers = index$2;
1127
+ exports.modules = index$5;
1125
1128
  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,19 @@
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';
6
4
  export declare let config: IAPIConfig;
7
5
  export declare const CoreAPI: {
6
+ managers: {
7
+ initialize: (config: any) => void;
8
+ destroy: () => void;
9
+ commands: exported.managerBases.Commands;
10
+ controllers: exported.managerBases.Controllers;
11
+ data: exported.managerBases.Data;
12
+ internal: exported.managerBases.Internal;
13
+ } | undefined;
8
14
  commandBases: typeof exported.commandBases;
9
15
  core: typeof exported.core;
10
16
  errors: typeof exported.errors;
11
- managers: typeof exported.managers;
12
17
  managerBases: typeof exported.managerBases;
13
18
  modules: typeof exported.modules;
14
19
  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.14";
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,15 @@ 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
+ globalThis.__ZEN_MANAGERS__ = {
75
+ initialize: () => {},
76
+ destroy: () => {},
77
+ commands: {},
78
+ controllers: {},
79
+ data: {},
80
+ internal: {}
81
+ };
107
82
  }
108
83
 
109
84
  /**
@@ -460,120 +435,47 @@ class Logger {
460
435
  }
461
436
  }
462
437
 
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;
438
+ var index$5 = /*#__PURE__*/Object.freeze({
439
+ __proto__: null,
440
+ Logger: Logger
441
+ });
442
+
443
+ class ForceMethodBase extends Error {
444
+ constructor(className, methodName) {
445
+ super(`ForeMethod implementation: at '${className}' method: '${methodName}'`);
503
446
  }
504
447
  }
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';
448
+ class ForceMethod extends Error {
449
+ constructor(context, methodName) {
450
+ super(`ForeMethod implementation: at '${context.getName()}' method: '${methodName}'`);
513
451
  }
514
452
  }
515
453
 
516
454
  /**
517
455
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
518
- * @description: Each data command should represent a final REST endpoint.
456
+ * @description: is base class/object for all classes, responsible for: 'getName', implementation.
519
457
  */
520
- class CommandData extends CommandBase {
458
+ let IdCounter = 0;
459
+ /**
460
+ * Base class 4 *
461
+ */
462
+ class ObjectBase {
463
+ virtualId = 0;
521
464
  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');
465
+ throw new ForceMethodBase("ObjectBase", "getName");
535
466
  }
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);
467
+ constructor() {
468
+ this.virtualId = IdCounter;
469
+ APIIncreaseIdCounter();
539
470
  }
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;
471
+ getName() {
472
+ return this.constructor.getName();
552
473
  }
553
474
  }
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
- }
475
+ function APIIncreaseIdCounter() {
476
+ return IdCounter++;
563
477
  }
564
478
 
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
479
  /**
578
480
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
579
481
  * @description: Responsible for commands, Aka ( CommandsSpace ).
@@ -644,11 +546,6 @@ ControllerAlreadyRegistered: ControllerAlreadyRegistered,
644
546
  ForceMethod: ForceMethod
645
547
  });
646
548
 
647
- var index$2 = /*#__PURE__*/Object.freeze({
648
- __proto__: null,
649
- Logger: Logger
650
- });
651
-
652
549
  /**
653
550
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
654
551
  * @description: Responsible for manging/running/hooking commands.
@@ -1011,14 +908,10 @@ class Internal extends Commands {
1011
908
  }
1012
909
  }
1013
910
 
1014
- if (typeof __ZEN_MANAGERS__ === 'undefined' || !__ZEN_MANAGERS__) {
1015
- // @ts-ignore
1016
- globalThis.__ZEN_MANAGERS__ = {};
1017
- }
1018
-
1019
911
  /**
1020
912
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
1021
913
  */
914
+ const afterInitializeCallbacks = [];
1022
915
  function initialize(config) {
1023
916
  __ZEN_MANAGERS__.commands = new Commands();
1024
917
  __ZEN_MANAGERS__.controllers = new Controllers();
@@ -1035,15 +928,132 @@ const controllers = __ZEN_MANAGERS__.controllers;
1035
928
  const commands = __ZEN_MANAGERS__.commands;
1036
929
  const data = __ZEN_MANAGERS__.data;
1037
930
  const internal = __ZEN_MANAGERS__.internal;
931
+ __ZEN_MANAGERS__.initialize = initialize;
932
+ __ZEN_MANAGERS__.destroy = destroy;
1038
933
 
1039
- var index$1 = /*#__PURE__*/Object.freeze({
934
+ var index$2 = /*#__PURE__*/Object.freeze({
1040
935
  __proto__: null,
1041
- get commands () { return commands; },
1042
- get controllers () { return controllers; },
1043
- get data () { return data; },
936
+ afterInitializeCallbacks: afterInitializeCallbacks,
937
+ commands: commands,
938
+ controllers: controllers,
939
+ data: data,
1044
940
  destroy: destroy,
1045
941
  initialize: initialize,
1046
- get internal () { return internal; }
942
+ internal: internal
943
+ });
944
+
945
+ /**
946
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
947
+ * @description: Base for all commands, they are all will be managed by the `Commands` managers.
948
+ * @TODO
949
+ * - Add validateArgs method or find something better.
950
+ */
951
+ class CommandBase extends ObjectBase {
952
+ args = {};
953
+ options = {};
954
+ logger;
955
+ constructor(args = {}, options = {}) {
956
+ super();
957
+ const name = this.constructor.getName();
958
+ this.logger = new Logger(name, true, {
959
+ sameColor: true
960
+ });
961
+ this.logger.startWith({
962
+ args,
963
+ options
964
+ });
965
+ this.initialize(args, options);
966
+ }
967
+ initialize(args, options) {
968
+ this.args = args;
969
+ this.options = options;
970
+ }
971
+ apply(args = this.args, options = this.options) {
972
+ throw new ForceMethod(this, "apply");
973
+ }
974
+ async run() {
975
+ this.onBeforeApply && this.onBeforeApply();
976
+ const result = await this.apply(this.args, this.options);
977
+ this.onAfterApply && this.onAfterApply();
978
+ return result;
979
+ }
980
+ getArgs() {
981
+ return this.args;
982
+ }
983
+ getOptions() {
984
+ return this.options;
985
+ }
986
+ }
987
+
988
+ /**
989
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
990
+ * @description: CommandPublic represents a USER action, every class which inherit from this class will USER action.
991
+ * */
992
+ class CommandPublic extends CommandBase {
993
+ static getName() {
994
+ return 'Core/CommandBases/CommandPublic';
995
+ }
996
+ }
997
+
998
+ /**
999
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
1000
+ * @description: Each data command should represent a final REST endpoint.
1001
+ */
1002
+ class CommandData extends CommandBase {
1003
+ static getName() {
1004
+ return 'Core/CommandBases/CommandData';
1005
+ }
1006
+ /**
1007
+ * Function getEndpoint() : Override this method is required to determine endpoint and magic query params.
1008
+ * @example
1009
+ * ```
1010
+ * args = { query: { id: 1 } };
1011
+ * getEndpoint() = '/api/v1/users/{id}';
1012
+ * result = '/api/v1/users/1';
1013
+ * ```
1014
+ */
1015
+ getEndpoint() {
1016
+ throw new ForceMethod(this, 'getEndpoint');
1017
+ }
1018
+ apply(args = this.args, options = this.options) {
1019
+ const endpoint = this.applyEndpointFormat(this.getEndpoint(), args);
1020
+ return __ZEN_MANAGERS__.data.getClient().fetch(endpoint, __ZEN_MANAGERS__.data.currentHttpMethod, args || null);
1021
+ }
1022
+ applyEndpointFormat(endpoint, data = {}) {
1023
+ // Replace query with `magic` placeholders.
1024
+ if (endpoint.includes('{')) {
1025
+ endpoint = endpoint.split('/').map(endpointPart => {
1026
+ const match = endpointPart.match('\\{(.*?)\\}');
1027
+ if (match?.length && 'undefined' !== typeof data[match[1]]) {
1028
+ return data[match[1]];
1029
+ }
1030
+ return endpointPart;
1031
+ }).join('/');
1032
+ }
1033
+ return endpoint;
1034
+ }
1035
+ }
1036
+
1037
+ /**
1038
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
1039
+ * @description: CommandInternal, is used when part of the logic needed to be in the command but not represent a user action.
1040
+ */
1041
+ class CommandInternal extends CommandBase {
1042
+ static getName() {
1043
+ return 'Core/CommandBases/CommandInternal';
1044
+ }
1045
+ }
1046
+
1047
+ /**
1048
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
1049
+ */
1050
+
1051
+ var index$1 = /*#__PURE__*/Object.freeze({
1052
+ __proto__: null,
1053
+ CommandBase: CommandBase,
1054
+ CommandData: CommandData,
1055
+ CommandInternal: CommandInternal,
1056
+ CommandPublic: CommandPublic
1047
1057
  });
1048
1058
 
1049
1059
  /**
@@ -1064,12 +1074,12 @@ Internal: Internal
1064
1074
 
1065
1075
  var exported = /*#__PURE__*/Object.freeze({
1066
1076
  __proto__: null,
1067
- commandBases: index$5,
1077
+ commandBases: index$1,
1068
1078
  core: index$4,
1069
1079
  errors: index$3,
1070
1080
  managerBases: index,
1071
- managers: index$1,
1072
- modules: index$2,
1081
+ managers: index$2,
1082
+ modules: index$5,
1073
1083
  utils: index$6
1074
1084
  });
1075
1085
 
@@ -1083,32 +1093,25 @@ errorInitTwice();
1083
1093
  let config = {
1084
1094
  version: pkg.version
1085
1095
  };
1086
- const afterInitializeCallbacks = [];
1087
1096
  const CoreAPI = {
1088
1097
  initialize: configuration => {
1089
1098
  errorInitTwice();
1090
1099
  config = configuration || config;
1091
- commands = new Commands();
1092
- controllers = new Controllers();
1093
- data = new Data(config);
1094
- internal = new Internal();
1100
+ initialize(config);
1095
1101
  isInitialized = true;
1096
- afterInitializeCallbacks.forEach(callback => callback());
1097
1102
  },
1098
1103
  destroy: () => {
1104
+ destroy();
1099
1105
  isInitialized = false;
1100
- commands = {};
1101
- controllers = {};
1102
- data = {};
1103
- internal = {};
1104
1106
  },
1105
1107
  onAfterInitialize: callback => {
1106
1108
  afterInitializeCallbacks.push(callback);
1107
1109
  },
1108
1110
  config,
1109
- ...exported
1111
+ ...exported,
1112
+ managers: typeof __ZEN_MANAGERS__ !== 'undefined' ? __ZEN_MANAGERS__ : undefined
1110
1113
  };
1111
1114
  // TODO: Make it available only for development.
1112
1115
  if (!globalThis?.ZenCore) globalThis.ZenCore = CoreAPI;
1113
1116
 
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 };
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 };
@@ -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.14";"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__:void 0};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.14";"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__:void 0};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.1",
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,32 @@ 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
+ globalThis.__ZEN_MANAGERS__ = {
10
+ initialize: () => {},
11
+ destroy: () => {},
12
+
13
+ commands: {} as Commands,
14
+ controllers: {} as Controllers,
15
+ data: {} as Data,
16
+ internal: {} as Internal,
17
+ } as IManagers;
18
+ }
19
+
20
+ declare global {
21
+ var ZenCore: any;
9
22
  }
10
23
 
11
24
  declare global {
12
25
  var __ZEN_MANAGERS__: {
26
+ initialize: ( config: any ) => void;
27
+ destroy: () => void;
28
+
13
29
  commands: Commands;
14
30
  controllers: Controllers;
15
31
  data: Data;
16
32
  internal: Internal;
17
33
  }
18
34
  }
19
-
20
- declare global {
21
- var ZenCore: any;
22
- }
@@ -1,12 +1,12 @@
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
10
 
11
11
  let isInitialized = false;
12
12
 
@@ -22,7 +22,6 @@ export let config: IAPIConfig = {
22
22
  version: pkg.version,
23
23
  }
24
24
 
25
- const afterInitializeCallbacks: ( () => void )[] = [];
26
25
 
27
26
  export const CoreAPI = {
28
27
  initialize: ( configuration?: IAPIConfig ) => {
@@ -34,7 +33,6 @@ export const CoreAPI = {
34
33
 
35
34
  isInitialized = true;
36
35
 
37
- afterInitializeCallbacks.forEach( ( callback ) => callback() );
38
36
  },
39
37
 
40
38
  destroy: () => {
@@ -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;