@zenflux/core 0.0.0-abc.1 → 0.0.0-abc.10

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.
@@ -2,6 +2,78 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var name = "@zenflux/core";
6
+ var version = "0.0.0-abc.10";
7
+ var description = "ZenFlux core";
8
+ var author = "Leonid Vinikov <leonidvinikov@gmail.com> (https://github.com/iNewLegend)";
9
+ var scripts = {
10
+ test: "export flow_modules_logger=off && jest",
11
+ build: "rollup --config rollup.config.ts --configPlugin typescript",
12
+ watch: "rollup --config rollup.config.ts --configPlugin typescript --watch"
13
+ };
14
+ var repository = {
15
+ type: "git",
16
+ url: "git+https://github.com/zenflux/core.git"
17
+ };
18
+ var keywords = [
19
+ "zenflux",
20
+ "zen",
21
+ "flux",
22
+ "commands",
23
+ "manager",
24
+ "commands manager"
25
+ ];
26
+ var files = [
27
+ "dist",
28
+ "src",
29
+ "types"
30
+ ];
31
+ var license = "MIT";
32
+ var main = "dist/cjs/zenflux-core.js";
33
+ var unpkg = "dist/umd/zenflux-core.js";
34
+ var module$1 = "dist/es/zenflux-core.js";
35
+ var types = "types/index.d.ts";
36
+ var devDependencies = {
37
+ "@babel/core": "^7.20.7",
38
+ "@babel/plugin-transform-runtime": "^7.19.6",
39
+ "@babel/preset-env": "^7.20.2",
40
+ "@babel/preset-typescript": "^7.18.6",
41
+ "@babel/runtime": "^7.20.7",
42
+ "@rollup/plugin-babel": "^6.0.3",
43
+ "@rollup/plugin-json": "^6.0.0",
44
+ "@rollup/plugin-node-resolve": "^15.0.1",
45
+ "@rollup/plugin-replace": "^5.0.2",
46
+ "@rollup/plugin-terser": "^0.2.1",
47
+ "@rollup/plugin-typescript": "^10.0.1",
48
+ "@types/jest": "^29.2.5",
49
+ "@typescript-eslint/eslint-plugin": "^5.48.0",
50
+ "@typescript-eslint/parser": "^5.48.0",
51
+ "babel-jest": "^29.3.1",
52
+ rollup: "^3.9.1",
53
+ "ts-jest": "^29.0.3",
54
+ tslib: "^2.4.1"
55
+ };
56
+ var dependencies = {
57
+ "@babel/runtime": "^7.19.0"
58
+ };
59
+ var pkg = {
60
+ name: name,
61
+ version: version,
62
+ description: description,
63
+ author: author,
64
+ scripts: scripts,
65
+ repository: repository,
66
+ keywords: keywords,
67
+ files: files,
68
+ license: license,
69
+ main: main,
70
+ unpkg: unpkg,
71
+ module: module$1,
72
+ types: types,
73
+ devDependencies: devDependencies,
74
+ dependencies: dependencies
75
+ };
76
+
5
77
  class ForceMethodBase extends Error {
6
78
  constructor(className, methodName) {
7
79
  super(`ForeMethod implementation: at '${className}' method: '${methodName}'`);
@@ -445,19 +517,6 @@ class CommandPublic extends CommandBase {
445
517
  }
446
518
  }
447
519
 
448
- let commands = {};
449
- let controllers = {};
450
- let data = {};
451
- let internal = {};
452
-
453
- var index$5 = /*#__PURE__*/Object.freeze({
454
- __proto__: null,
455
- commands: commands,
456
- controllers: controllers,
457
- data: data,
458
- internal: internal
459
- });
460
-
461
520
  /**
462
521
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
463
522
  * @description: Each data command should represent a final REST endpoint.
@@ -480,7 +539,7 @@ class CommandData extends CommandBase {
480
539
  }
481
540
  apply(args = this.args, options = this.options) {
482
541
  const endpoint = this.applyEndpointFormat(this.getEndpoint(), args);
483
- return data.getClient().fetch(endpoint, data.currentHttpMethod, args || null);
542
+ return __ZEN_MANAGERS__.data.getClient().fetch(endpoint, __ZEN_MANAGERS__.data.currentHttpMethod, args || null);
484
543
  }
485
544
  applyEndpointFormat(endpoint, data = {}) {
486
545
  // Replace query with `magic` placeholders.
@@ -511,7 +570,7 @@ class CommandInternal extends CommandBase {
511
570
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
512
571
  */
513
572
 
514
- var index$4 = /*#__PURE__*/Object.freeze({
573
+ var index$5 = /*#__PURE__*/Object.freeze({
515
574
  __proto__: null,
516
575
  CommandBase: CommandBase,
517
576
  CommandData: CommandData,
@@ -539,9 +598,9 @@ class Controller extends ObjectBase {
539
598
  this.setupHooks && this.setupHooks();
540
599
  }
541
600
  register() {
542
- this.commands = commands.register(this.getCommands(), this);
543
- this.data = data.register(this.getData(), this);
544
- this.internal = internal.register(this.getInternal(), this);
601
+ this.commands = __ZEN_MANAGERS__.commands.register(this.getCommands(), this);
602
+ this.data = __ZEN_MANAGERS__.data.register(this.getData(), this);
603
+ this.internal = __ZEN_MANAGERS__.internal.register(this.getInternal(), this);
545
604
  }
546
605
  getCommands() {
547
606
  return {};
@@ -554,7 +613,7 @@ class Controller extends ObjectBase {
554
613
  }
555
614
  }
556
615
 
557
- var index$3 = /*#__PURE__*/Object.freeze({
616
+ var index$4 = /*#__PURE__*/Object.freeze({
558
617
  __proto__: null,
559
618
  Controller: Controller,
560
619
  ObjectBase: ObjectBase
@@ -581,7 +640,7 @@ class ControllerAlreadyRegistered extends Error {
581
640
  }
582
641
  }
583
642
 
584
- var index$2 = /*#__PURE__*/Object.freeze({
643
+ var index$3 = /*#__PURE__*/Object.freeze({
585
644
  __proto__: null,
586
645
  CommandAlreadyRegistered: CommandAlreadyRegistered,
587
646
  CommandNotFound: CommandNotFound,
@@ -589,7 +648,7 @@ ControllerAlreadyRegistered: ControllerAlreadyRegistered,
589
648
  ForceMethod: ForceMethod
590
649
  });
591
650
 
592
- var index$1 = /*#__PURE__*/Object.freeze({
651
+ var index$2 = /*#__PURE__*/Object.freeze({
593
652
  __proto__: null,
594
653
  Logger: Logger
595
654
  });
@@ -956,6 +1015,40 @@ class Internal extends Commands {
956
1015
  }
957
1016
  }
958
1017
 
1018
+ /**
1019
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
1020
+ */
1021
+ if (typeof __ZEN_MANAGERS__ === 'undefined' || !__ZEN_MANAGERS__) {
1022
+ // @ts-ignore
1023
+ globalThis.__ZEN_MANAGERS__ = {};
1024
+ }
1025
+ function initialize(config) {
1026
+ __ZEN_MANAGERS__.commands = new Commands();
1027
+ __ZEN_MANAGERS__.controllers = new Controllers();
1028
+ __ZEN_MANAGERS__.data = new Data(config);
1029
+ __ZEN_MANAGERS__.internal = new Internal();
1030
+ }
1031
+ function destroy() {
1032
+ __ZEN_MANAGERS__.commands = {};
1033
+ __ZEN_MANAGERS__.controllers = {};
1034
+ __ZEN_MANAGERS__.data = {};
1035
+ __ZEN_MANAGERS__.internal = {};
1036
+ }
1037
+ const controllers = __ZEN_MANAGERS__.controllers;
1038
+ const commands = __ZEN_MANAGERS__.commands;
1039
+ const data = __ZEN_MANAGERS__.data;
1040
+ const internal = __ZEN_MANAGERS__.internal;
1041
+
1042
+ var index$1 = /*#__PURE__*/Object.freeze({
1043
+ __proto__: null,
1044
+ get commands () { return commands; },
1045
+ get controllers () { return controllers; },
1046
+ get data () { return data; },
1047
+ destroy: destroy,
1048
+ initialize: initialize,
1049
+ get internal () { return internal; }
1050
+ });
1051
+
959
1052
  /**
960
1053
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
961
1054
  */
@@ -974,87 +1067,15 @@ Internal: Internal
974
1067
 
975
1068
  var exported = /*#__PURE__*/Object.freeze({
976
1069
  __proto__: null,
977
- commandBases: index$4,
978
- core: index$3,
979
- errors: index$2,
1070
+ commandBases: index$5,
1071
+ core: index$4,
1072
+ errors: index$3,
980
1073
  managerBases: index,
981
- managers: index$5,
982
- modules: index$1,
1074
+ managers: index$1,
1075
+ modules: index$2,
983
1076
  utils: index$6
984
1077
  });
985
1078
 
986
- var name = "@zenflux/core";
987
- var version = "0.0.0-abc.1";
988
- var description = "ZenFlux core";
989
- var author = "Leonid Vinikov <leonidvinikov@gmail.com> (https://github.com/iNewLegend)";
990
- var scripts = {
991
- test: "export flow_modules_logger=off && jest",
992
- build: "rollup --config rollup.config.ts --configPlugin typescript"
993
- };
994
- var repository = {
995
- type: "git",
996
- url: "git+https://github.com/zenflux/core.git"
997
- };
998
- var keywords = [
999
- "zenflux",
1000
- "zen",
1001
- "flux",
1002
- "commands",
1003
- "manager",
1004
- "commands manager"
1005
- ];
1006
- var files = [
1007
- "dist",
1008
- "src",
1009
- "types"
1010
- ];
1011
- var license = "MIT";
1012
- var main = "dist/cjs/zenflux-core.js";
1013
- var unpkg = "dist/umd/zenflux-core.js";
1014
- var module$1 = "dist/es/zenflux-core.js";
1015
- var types = "types/index.d.ts";
1016
- var devDependencies = {
1017
- "@babel/core": "^7.20.7",
1018
- "@babel/plugin-transform-runtime": "^7.19.6",
1019
- "@babel/preset-env": "^7.20.2",
1020
- "@babel/preset-typescript": "^7.18.6",
1021
- "@babel/runtime": "^7.20.7",
1022
- "@rollup/plugin-babel": "^6.0.3",
1023
- "@rollup/plugin-json": "^6.0.0",
1024
- "@rollup/plugin-node-resolve": "^15.0.1",
1025
- "@rollup/plugin-replace": "^5.0.2",
1026
- "@rollup/plugin-terser": "^0.2.1",
1027
- "@rollup/plugin-typescript": "^10.0.1",
1028
- "@types/jest": "^29.2.5",
1029
- "@typescript-eslint/eslint-plugin": "^5.48.0",
1030
- "@typescript-eslint/parser": "^5.48.0",
1031
- "babel-jest": "^29.3.1",
1032
- rollup: "^3.9.1",
1033
- "ts-jest": "^29.0.3",
1034
- tslib: "^2.4.1"
1035
- };
1036
- var dependencies = {
1037
- "@babel/runtime": "^7.19.0"
1038
- };
1039
- var pkg = {
1040
- name: name,
1041
- version: version,
1042
- description: description,
1043
- author: author,
1044
- scripts: scripts,
1045
- repository: repository,
1046
- keywords: keywords,
1047
- files: files,
1048
- license: license,
1049
- main: main,
1050
- unpkg: unpkg,
1051
- module: module$1,
1052
- types: types,
1053
- devDependencies: devDependencies,
1054
- dependencies: dependencies
1055
- };
1056
-
1057
- const managers = index$5;
1058
1079
  let isInitialized = false;
1059
1080
  function errorInitTwice() {
1060
1081
  if (isInitialized) {
@@ -1070,19 +1091,19 @@ const CoreAPI = {
1070
1091
  initialize: configuration => {
1071
1092
  errorInitTwice();
1072
1093
  config = configuration || config;
1073
- managers.commands = new Commands();
1074
- managers.controllers = new Controllers();
1075
- managers.data = new Data(config);
1076
- managers.internal = new Internal();
1094
+ commands = new Commands();
1095
+ controllers = new Controllers();
1096
+ data = new Data(config);
1097
+ internal = new Internal();
1077
1098
  isInitialized = true;
1078
1099
  afterInitializeCallbacks.forEach(callback => callback());
1079
1100
  },
1080
1101
  destroy: () => {
1081
1102
  isInitialized = false;
1082
- managers.commands = {};
1083
- managers.controllers = {};
1084
- managers.data = {};
1085
- managers.internal = {};
1103
+ commands = {};
1104
+ controllers = {};
1105
+ data = {};
1106
+ internal = {};
1086
1107
  },
1087
1108
  onAfterInitialize: callback => {
1088
1109
  afterInitializeCallbacks.push(callback);
@@ -1093,11 +1114,11 @@ const CoreAPI = {
1093
1114
  // TODO: Make it available only for development.
1094
1115
  if (!globalThis?.ZenCore) globalThis.ZenCore = CoreAPI;
1095
1116
 
1096
- exports.commandBases = index$4;
1097
- exports.core = index$3;
1117
+ exports.commandBases = index$5;
1118
+ exports.core = index$4;
1098
1119
  exports.default = CoreAPI;
1099
- exports.errors = index$2;
1120
+ exports.errors = index$3;
1100
1121
  exports.managerBases = index;
1101
- exports.managers = index$5;
1102
- exports.modules = index$1;
1122
+ exports.managers = index$1;
1123
+ exports.modules = index$2;
1103
1124
  exports.utils = index$6;
@@ -0,0 +1,15 @@
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
+ declare global {
6
+ var ZenCore: any;
7
+ }
8
+ declare global {
9
+ var __ZEN_MANAGERS__: {
10
+ commands: Commands;
11
+ controllers: Controllers;
12
+ data: Data;
13
+ internal: Internal;
14
+ };
15
+ }
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
3
3
  */
4
- export * from './exports';
5
4
  export { CoreAPI as default } from "./initializer";
5
+ export * from './exports';
@@ -1,8 +1,22 @@
1
1
  /**
2
2
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
3
3
  */
4
- import * as managersBases from "../manager-bases";
5
- export declare let commands: managersBases.Commands;
6
- export declare let controllers: managersBases.Controllers;
7
- export declare let data: managersBases.Data;
8
- export declare let internal: managersBases.Internal;
4
+ import Commands from "../manager-bases/commands";
5
+ import Controllers from "../manager-bases/controllers";
6
+ import Data from "../manager-bases/data";
7
+ import Internal from "../manager-bases/internal";
8
+ import { IAPIConfig } from "../interfaces/config";
9
+ declare global {
10
+ var __ZEN_MANAGERS__: {
11
+ commands: Commands;
12
+ controllers: Controllers;
13
+ data: Data;
14
+ internal: Internal;
15
+ };
16
+ }
17
+ export declare function initialize(config: IAPIConfig): void;
18
+ export declare function destroy(): void;
19
+ export declare const controllers: Controllers;
20
+ export declare const commands: Commands;
21
+ export declare const data: Data;
22
+ export declare const internal: Internal;
@@ -1,3 +1,75 @@
1
+ var name = "@zenflux/core";
2
+ var version = "0.0.0-abc.10";
3
+ var description = "ZenFlux core";
4
+ var author = "Leonid Vinikov <leonidvinikov@gmail.com> (https://github.com/iNewLegend)";
5
+ var scripts = {
6
+ test: "export flow_modules_logger=off && jest",
7
+ build: "rollup --config rollup.config.ts --configPlugin typescript",
8
+ watch: "rollup --config rollup.config.ts --configPlugin typescript --watch"
9
+ };
10
+ var repository = {
11
+ type: "git",
12
+ url: "git+https://github.com/zenflux/core.git"
13
+ };
14
+ var keywords = [
15
+ "zenflux",
16
+ "zen",
17
+ "flux",
18
+ "commands",
19
+ "manager",
20
+ "commands manager"
21
+ ];
22
+ var files = [
23
+ "dist",
24
+ "src",
25
+ "types"
26
+ ];
27
+ var license = "MIT";
28
+ var main = "dist/cjs/zenflux-core.js";
29
+ var unpkg = "dist/umd/zenflux-core.js";
30
+ var module = "dist/es/zenflux-core.js";
31
+ var types = "types/index.d.ts";
32
+ var devDependencies = {
33
+ "@babel/core": "^7.20.7",
34
+ "@babel/plugin-transform-runtime": "^7.19.6",
35
+ "@babel/preset-env": "^7.20.2",
36
+ "@babel/preset-typescript": "^7.18.6",
37
+ "@babel/runtime": "^7.20.7",
38
+ "@rollup/plugin-babel": "^6.0.3",
39
+ "@rollup/plugin-json": "^6.0.0",
40
+ "@rollup/plugin-node-resolve": "^15.0.1",
41
+ "@rollup/plugin-replace": "^5.0.2",
42
+ "@rollup/plugin-terser": "^0.2.1",
43
+ "@rollup/plugin-typescript": "^10.0.1",
44
+ "@types/jest": "^29.2.5",
45
+ "@typescript-eslint/eslint-plugin": "^5.48.0",
46
+ "@typescript-eslint/parser": "^5.48.0",
47
+ "babel-jest": "^29.3.1",
48
+ rollup: "^3.9.1",
49
+ "ts-jest": "^29.0.3",
50
+ tslib: "^2.4.1"
51
+ };
52
+ var dependencies = {
53
+ "@babel/runtime": "^7.19.0"
54
+ };
55
+ var pkg = {
56
+ name: name,
57
+ version: version,
58
+ description: description,
59
+ author: author,
60
+ scripts: scripts,
61
+ repository: repository,
62
+ keywords: keywords,
63
+ files: files,
64
+ license: license,
65
+ main: main,
66
+ unpkg: unpkg,
67
+ module: module,
68
+ types: types,
69
+ devDependencies: devDependencies,
70
+ dependencies: dependencies
71
+ };
72
+
1
73
  class ForceMethodBase extends Error {
2
74
  constructor(className, methodName) {
3
75
  super(`ForeMethod implementation: at '${className}' method: '${methodName}'`);
@@ -441,19 +513,6 @@ class CommandPublic extends CommandBase {
441
513
  }
442
514
  }
443
515
 
444
- let commands = {};
445
- let controllers = {};
446
- let data = {};
447
- let internal = {};
448
-
449
- var index$5 = /*#__PURE__*/Object.freeze({
450
- __proto__: null,
451
- commands: commands,
452
- controllers: controllers,
453
- data: data,
454
- internal: internal
455
- });
456
-
457
516
  /**
458
517
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
459
518
  * @description: Each data command should represent a final REST endpoint.
@@ -476,7 +535,7 @@ class CommandData extends CommandBase {
476
535
  }
477
536
  apply(args = this.args, options = this.options) {
478
537
  const endpoint = this.applyEndpointFormat(this.getEndpoint(), args);
479
- return data.getClient().fetch(endpoint, data.currentHttpMethod, args || null);
538
+ return __ZEN_MANAGERS__.data.getClient().fetch(endpoint, __ZEN_MANAGERS__.data.currentHttpMethod, args || null);
480
539
  }
481
540
  applyEndpointFormat(endpoint, data = {}) {
482
541
  // Replace query with `magic` placeholders.
@@ -507,7 +566,7 @@ class CommandInternal extends CommandBase {
507
566
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
508
567
  */
509
568
 
510
- var index$4 = /*#__PURE__*/Object.freeze({
569
+ var index$5 = /*#__PURE__*/Object.freeze({
511
570
  __proto__: null,
512
571
  CommandBase: CommandBase,
513
572
  CommandData: CommandData,
@@ -535,9 +594,9 @@ class Controller extends ObjectBase {
535
594
  this.setupHooks && this.setupHooks();
536
595
  }
537
596
  register() {
538
- this.commands = commands.register(this.getCommands(), this);
539
- this.data = data.register(this.getData(), this);
540
- this.internal = internal.register(this.getInternal(), this);
597
+ this.commands = __ZEN_MANAGERS__.commands.register(this.getCommands(), this);
598
+ this.data = __ZEN_MANAGERS__.data.register(this.getData(), this);
599
+ this.internal = __ZEN_MANAGERS__.internal.register(this.getInternal(), this);
541
600
  }
542
601
  getCommands() {
543
602
  return {};
@@ -550,7 +609,7 @@ class Controller extends ObjectBase {
550
609
  }
551
610
  }
552
611
 
553
- var index$3 = /*#__PURE__*/Object.freeze({
612
+ var index$4 = /*#__PURE__*/Object.freeze({
554
613
  __proto__: null,
555
614
  Controller: Controller,
556
615
  ObjectBase: ObjectBase
@@ -577,7 +636,7 @@ class ControllerAlreadyRegistered extends Error {
577
636
  }
578
637
  }
579
638
 
580
- var index$2 = /*#__PURE__*/Object.freeze({
639
+ var index$3 = /*#__PURE__*/Object.freeze({
581
640
  __proto__: null,
582
641
  CommandAlreadyRegistered: CommandAlreadyRegistered,
583
642
  CommandNotFound: CommandNotFound,
@@ -585,7 +644,7 @@ ControllerAlreadyRegistered: ControllerAlreadyRegistered,
585
644
  ForceMethod: ForceMethod
586
645
  });
587
646
 
588
- var index$1 = /*#__PURE__*/Object.freeze({
647
+ var index$2 = /*#__PURE__*/Object.freeze({
589
648
  __proto__: null,
590
649
  Logger: Logger
591
650
  });
@@ -952,6 +1011,40 @@ class Internal extends Commands {
952
1011
  }
953
1012
  }
954
1013
 
1014
+ /**
1015
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
1016
+ */
1017
+ if (typeof __ZEN_MANAGERS__ === 'undefined' || !__ZEN_MANAGERS__) {
1018
+ // @ts-ignore
1019
+ globalThis.__ZEN_MANAGERS__ = {};
1020
+ }
1021
+ function initialize(config) {
1022
+ __ZEN_MANAGERS__.commands = new Commands();
1023
+ __ZEN_MANAGERS__.controllers = new Controllers();
1024
+ __ZEN_MANAGERS__.data = new Data(config);
1025
+ __ZEN_MANAGERS__.internal = new Internal();
1026
+ }
1027
+ function destroy() {
1028
+ __ZEN_MANAGERS__.commands = {};
1029
+ __ZEN_MANAGERS__.controllers = {};
1030
+ __ZEN_MANAGERS__.data = {};
1031
+ __ZEN_MANAGERS__.internal = {};
1032
+ }
1033
+ const controllers = __ZEN_MANAGERS__.controllers;
1034
+ const commands = __ZEN_MANAGERS__.commands;
1035
+ const data = __ZEN_MANAGERS__.data;
1036
+ const internal = __ZEN_MANAGERS__.internal;
1037
+
1038
+ var index$1 = /*#__PURE__*/Object.freeze({
1039
+ __proto__: null,
1040
+ get commands () { return commands; },
1041
+ get controllers () { return controllers; },
1042
+ get data () { return data; },
1043
+ destroy: destroy,
1044
+ initialize: initialize,
1045
+ get internal () { return internal; }
1046
+ });
1047
+
955
1048
  /**
956
1049
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
957
1050
  */
@@ -970,87 +1063,15 @@ Internal: Internal
970
1063
 
971
1064
  var exported = /*#__PURE__*/Object.freeze({
972
1065
  __proto__: null,
973
- commandBases: index$4,
974
- core: index$3,
975
- errors: index$2,
1066
+ commandBases: index$5,
1067
+ core: index$4,
1068
+ errors: index$3,
976
1069
  managerBases: index,
977
- managers: index$5,
978
- modules: index$1,
1070
+ managers: index$1,
1071
+ modules: index$2,
979
1072
  utils: index$6
980
1073
  });
981
1074
 
982
- var name = "@zenflux/core";
983
- var version = "0.0.0-abc.1";
984
- var description = "ZenFlux core";
985
- var author = "Leonid Vinikov <leonidvinikov@gmail.com> (https://github.com/iNewLegend)";
986
- var scripts = {
987
- test: "export flow_modules_logger=off && jest",
988
- build: "rollup --config rollup.config.ts --configPlugin typescript"
989
- };
990
- var repository = {
991
- type: "git",
992
- url: "git+https://github.com/zenflux/core.git"
993
- };
994
- var keywords = [
995
- "zenflux",
996
- "zen",
997
- "flux",
998
- "commands",
999
- "manager",
1000
- "commands manager"
1001
- ];
1002
- var files = [
1003
- "dist",
1004
- "src",
1005
- "types"
1006
- ];
1007
- var license = "MIT";
1008
- var main = "dist/cjs/zenflux-core.js";
1009
- var unpkg = "dist/umd/zenflux-core.js";
1010
- var module = "dist/es/zenflux-core.js";
1011
- var types = "types/index.d.ts";
1012
- var devDependencies = {
1013
- "@babel/core": "^7.20.7",
1014
- "@babel/plugin-transform-runtime": "^7.19.6",
1015
- "@babel/preset-env": "^7.20.2",
1016
- "@babel/preset-typescript": "^7.18.6",
1017
- "@babel/runtime": "^7.20.7",
1018
- "@rollup/plugin-babel": "^6.0.3",
1019
- "@rollup/plugin-json": "^6.0.0",
1020
- "@rollup/plugin-node-resolve": "^15.0.1",
1021
- "@rollup/plugin-replace": "^5.0.2",
1022
- "@rollup/plugin-terser": "^0.2.1",
1023
- "@rollup/plugin-typescript": "^10.0.1",
1024
- "@types/jest": "^29.2.5",
1025
- "@typescript-eslint/eslint-plugin": "^5.48.0",
1026
- "@typescript-eslint/parser": "^5.48.0",
1027
- "babel-jest": "^29.3.1",
1028
- rollup: "^3.9.1",
1029
- "ts-jest": "^29.0.3",
1030
- tslib: "^2.4.1"
1031
- };
1032
- var dependencies = {
1033
- "@babel/runtime": "^7.19.0"
1034
- };
1035
- var pkg = {
1036
- name: name,
1037
- version: version,
1038
- description: description,
1039
- author: author,
1040
- scripts: scripts,
1041
- repository: repository,
1042
- keywords: keywords,
1043
- files: files,
1044
- license: license,
1045
- main: main,
1046
- unpkg: unpkg,
1047
- module: module,
1048
- types: types,
1049
- devDependencies: devDependencies,
1050
- dependencies: dependencies
1051
- };
1052
-
1053
- const managers = index$5;
1054
1075
  let isInitialized = false;
1055
1076
  function errorInitTwice() {
1056
1077
  if (isInitialized) {
@@ -1066,19 +1087,19 @@ const CoreAPI = {
1066
1087
  initialize: configuration => {
1067
1088
  errorInitTwice();
1068
1089
  config = configuration || config;
1069
- managers.commands = new Commands();
1070
- managers.controllers = new Controllers();
1071
- managers.data = new Data(config);
1072
- managers.internal = new Internal();
1090
+ commands = new Commands();
1091
+ controllers = new Controllers();
1092
+ data = new Data(config);
1093
+ internal = new Internal();
1073
1094
  isInitialized = true;
1074
1095
  afterInitializeCallbacks.forEach(callback => callback());
1075
1096
  },
1076
1097
  destroy: () => {
1077
1098
  isInitialized = false;
1078
- managers.commands = {};
1079
- managers.controllers = {};
1080
- managers.data = {};
1081
- managers.internal = {};
1099
+ commands = {};
1100
+ controllers = {};
1101
+ data = {};
1102
+ internal = {};
1082
1103
  },
1083
1104
  onAfterInitialize: callback => {
1084
1105
  afterInitializeCallbacks.push(callback);
@@ -1089,4 +1110,4 @@ const CoreAPI = {
1089
1110
  // TODO: Make it available only for development.
1090
1111
  if (!globalThis?.ZenCore) globalThis.ZenCore = CoreAPI;
1091
1112
 
1092
- export { index$4 as commandBases, index$3 as core, CoreAPI as default, index$2 as errors, index as managerBases, index$5 as managers, index$1 as modules, index$6 as utils };
1113
+ 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 };
@@ -1,12 +1,12 @@
1
- class t extends Error{constructor(t,e){super(`ForeMethod implementation: at '${t}' method: '${e}'`)}}class e extends Error{constructor(t,e){super(`ForeMethod implementation: at '${t.getName()}' method: '${e}'`)}}let r=0;class s{virtualId=0;static getName(){throw new t("ObjectBase","getName")}constructor(){this.virtualId=r,r++}getName(){return this.constructor.getName()}}
1
+ var t="0.0.0-abc.10";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()}}
2
2
  /**
3
3
  * Function getCircularReplacer() : Reduce circular references.
4
4
  *
5
5
  * @copyright https://stackoverflow.com/a/53731154
6
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}},n=function(t,e){t=t.replace("#",""),e=e.replace("#","");const r=parseInt(t.substring(0,2),16),s=parseInt(t.substring(2,4),16),o=parseInt(t.substring(4,6),16),n=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-n),l=255-Math.abs(s-a),h=255-Math.abs(o-i);return c/=255,l/=255,h/=255,(c+l+h)/3};
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};
8
8
  /**
9
9
  * Function hexColorDelta() : Return color difference in ratio decimal point.
10
10
  *
11
11
  * @copyright http://jsfiddle.net/96sME/
12
- */var a=Object.freeze({__proto__:null,getCircularReplacer:o,hexColorDelta:n});class i{static wrappers={};static wrapperDepth=0;static sharedData={};static colorsInUse=[];defaultStyle;color;outputHandler;args={};name;state=!1;static getName(){return"Core/Modules/Logger"}static reset(){i.wrappers={},i.wrapperDepth=0,i.colorsInUse=[],i.sharedData={}}static createCustomWrapper(t,e){i.wrappers[t]||(i.wrappers[t.name]=[]),i.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?(i.sharedData[this.name]||(i.sharedData[this.name]=this.getRandomColor()),this.color=i.sharedData[this.name]):(this.color=this.getRandomColor(),i.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;i.wrapperDepth++;let r={...t};return Object.values(i.wrappers).forEach((([e])=>{t instanceof e.classType&&(r=e.callback(t)||r)})),4>i.wrapperDepth?(e&&r&&Object.entries(r).forEach((([t,e])=>{r[t]=this.useWrapper(e,!0)})),i.wrapperDepth--,r):(i.wrapperDepth--,r)}startEmpty(t=""){this.state&&this.printFunctionNotify("se",i.getCallerName(),t)}startWith(t){if(!this.state)return;t=Object.assign({},t);const e="se",r=i.getCallerName();if("string"==typeof t)this.printInLineString(e,r,t);else if(1===Object.keys(t).length){const s=Object.keys(t)[0];let o=Object.values(t)[0];"object"==typeof o?this.printNextLineObject(e,r,s,o||{}):"function"==typeof o?this.printInLineFunction(e,r,s,o):this.printInLineElement(e,r,s,o)}else this.printMultiLineObject(e,r,t)}object(t={},e=""){if(!this.state)return;const r=i.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",i.getCallerName(),t)}drop(t,e){if(!this.state)return;const r=i.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",i.getCallerName(),t),r&&this.printNextLineObject("tw",i.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=i.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=i.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 i.colorsInUse.some((e=>n(t,e)>=.8))?this.getRandomColor():t}out(...t){this.outputHandler.apply(this,t)}}class c extends s{args={};options={};logger;constructor(t={},e={}){super();const r=this.constructor.getName();this.logger=new i(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,r=this.options){throw new e(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}}let l={},h={},u={};var p=Object.freeze({__proto__:null,commands:l,controllers:{},data:h,internal:u});var g=Object.freeze({__proto__:null,CommandBase:c,CommandData:class extends c{static getName(){return"Core/CommandBases/CommandData"}getEndpoint(){throw new e(this,"getEndpoint")}apply(t=this.args,e=this.options){const r=this.applyEndpointFormat(this.getEndpoint(),t);return h.getClient().fetch(r,h.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 c{static getName(){return"Core/CommandBases/CommandInternal"}},CommandPublic:class extends c{static getName(){return"Core/CommandBases/CommandPublic"}}});var m=Object.freeze({__proto__:null,Controller:class extends s{commands;data;internal;static getName(){return"Core/Core/Controller"}constructor(){super(),this.initialize()}initialize(){this.register(),this.setupHooks&&this.setupHooks()}register(){this.commands=l.register(this.getCommands(),this),this.data=h.register(this.getData(),this),this.internal=u.register(this.getInternal(),this)}getCommands(){return{}}getData(){return{}}getInternal(){return{}}},ObjectBase:s});class d extends Error{constructor(t){super(`Command: '${t.getName()}' is already registered`)}}class f extends Error{constructor(t){super(`Command: '${t}' is not found`)}}class C extends Error{constructor(t){super(`Controller: '${t.getName()}' is already registered`)}}var y,b=Object.freeze({__proto__:null,CommandAlreadyRegistered:d,CommandNotFound:f,ControllerAlreadyRegistered:C,ForceMethod:e}),N=Object.freeze({__proto__:null,Logger:i});class w extends s{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 o=0;s>o;++o){const s=!0===r.pop?t.pop():t[o];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 i(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 d(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 f(t);return new s(e,r)}onBefore(t,e){w.hookCommand(this.onBeforeHooks,t,e)}onBeforeUI(t,e){w.hookCommand(this.onBeforeUIHooks,t,e)}onAfter(t,e){w.hookCommand(this.onAfterHooks,t,e)}onAfterUI(t,e){w.hookCommand(this.onAfterUIHooks,t,e)}onAfterOnce(t,e){w.hookCommand(this.onAfterOnceHooks,t,e)}onAfterAffect(t,e){w.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 w.runCallbacks(Object.assign([],this.onAfterHooks[t.getName()]),e,r)),this.onAfterOnceHooks&&await w.runCallbacks(this.onAfterOnceHooks[t.getName()],e,{...r,pop:!0}),this.onAfterUIHooks&&w.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()),w.trace.push(t.getName())}detachCurrent(t){delete this.current[t.getName()],delete this.currentArgs[t.getName()],w.trace.pop(),this.trace.pop()}}class O extends s{controllers={};static getName(){return"Core/Managers/Controllers"}get(t){return this.controllers[t]}getAll(){return this.controllers}register(t){if(this.controllers[t.getName()])throw new C(t);return this.controllers[t.getName()]=t,t}}!function(t){t.DELETE="DELETE",t.GET="GET",t.OPTIONS="OPTIONS",t.PATCH="PATCH",t.POST="POST",t.PUT="PUT",t.__EMPTY__=""}(y||(y={}));class A extends s{logger;apiBaseUrl;static getName(){return"Core/Clients/Http"}constructor(t="http://localhost"){super(),this.logger=new i(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"},o={};[y.POST,y.PUT,y.PATCH].includes(e)?(Object.assign(o,{"Content-Type":"application/json"}),Object.assign(s,{method:e,headers:o,body:JSON.stringify(r)})):Object.assign(s,{headers:o});const n=await globalThis.fetch(this.apiBaseUrl+t,s);let a;try{a=await n.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 k extends w{static client;currentHttpMethod;static getName(){return"Core/Managers/Data"}constructor(t){super(),k.client=new A(t.baseURL)}getClient(){return k.client}get(t,e={},r={}){return this.currentHttpMethod=y.GET,super.run(t,e,r)}update(t,e={},r={}){return this.currentHttpMethod=y.PATCH,super.run(t,e,r)}delete(t,e={},r={}){return this.currentHttpMethod=y.DELETE,super.run(t,e,r)}create(t,e={},r={}){return this.currentHttpMethod=y.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 y.GET===this.currentHttpMethod?s.args.query=e:s.args.data=e,e.result=await super.runInstance(t,s,r),this.currentHttpMethod=y.__EMPTY__,e.result}}class E extends w{static getName(){return"Core/Managers/Internal"}}var H=Object.freeze({__proto__:null,Commands:w,Controllers:O,Data:k,Internal:E}),_=Object.freeze({__proto__:null,commandBases:g,core:m,errors:b,managerBases:H,managers:p,modules:N,utils:a}),j="0.0.0-abc.1";const I=p;let $=!1;function B(){if($)throw Error("ZenCore is already initialized.")}B();let T={version:j};const M=[],U={initialize:t=>{B(),T=t||T,I.commands=new w,I.controllers=new O,I.data=new k(T),I.internal=new E,$=!0,M.forEach((t=>t()))},destroy:()=>{$=!1,I.commands={},I.controllers={},I.data={},I.internal={}},onAfterInitialize:t=>{M.push(t)},config:T,..._};globalThis?.ZenCore||(globalThis.ZenCore=U);export{g as commandBases,m as core,U as default,b as errors,H as managerBases,p as managers,N as modules,a as utils};
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};
@@ -1,12 +1,12 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["@zenflux/core"]={})}(this,(function(t){"use strict";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 o{virtualId=0;static getName(){throw new e("ObjectBase","getName")}constructor(){this.virtualId=s,s++}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.10";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()}}
2
2
  /**
3
3
  * Function getCircularReplacer() : Reduce circular references.
4
4
  *
5
5
  * @copyright https://stackoverflow.com/a/53731154
6
6
  */
7
- const n=()=>{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),o=parseInt(t.substring(4,6),16),n=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-n),l=255-Math.abs(s-a),h=255-Math.abs(o-i);return c/=255,l/=255,h/=255,(c+l+h)/3};
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};
8
8
  /**
9
9
  * Function hexColorDelta() : Return color difference in ratio decimal point.
10
10
  *
11
11
  * @copyright http://jsfiddle.net/96sME/
12
- */var i=Object.freeze({__proto__:null,getCircularReplacer:n,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 o=Object.values(t)[0];"object"==typeof o?this.printNextLineObject(e,r,s,o||{}):"function"==typeof o?this.printInLineFunction(e,r,s,o):this.printInLineElement(e,r,s,o)}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]),n())),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),n()):"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 o{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}}let h={},u={},p={};var g=Object.freeze({__proto__:null,commands:h,controllers:{},data:u,internal:p});var m=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 u.getClient().fetch(r,u.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 d=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=h.register(this.getCommands(),this),this.data=u.register(this.getData(),this),this.internal=p.register(this.getInternal(),this)}getCommands(){return{}}getData(){return{}}getInternal(){return{}}},ObjectBase:o});class f extends Error{constructor(t){super(`Command: '${t.getName()}' is already registered`)}}class C extends Error{constructor(t){super(`Command: '${t}' is not found`)}}class y extends Error{constructor(t){super(`Controller: '${t.getName()}' is already registered`)}}var b,N=Object.freeze({__proto__:null,CommandAlreadyRegistered:f,CommandNotFound:C,ControllerAlreadyRegistered:y,ForceMethod:r}),w=Object.freeze({__proto__:null,Logger:c});class O 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 o=0;s>o;++o){const s=!0===r.pop?t.pop():t[o];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 f(t);this.commands[e]=t,r[e]=t})),r}getAll(){return this.commands}getByName(t){return this.commands[t]}getLogger(){return this.logger}getCommandInstance(t,e={},r={}){const s=this.commands[t];if(!s)throw new C(t);return new s(e,r)}onBefore(t,e){O.hookCommand(this.onBeforeHooks,t,e)}onBeforeUI(t,e){O.hookCommand(this.onBeforeUIHooks,t,e)}onAfter(t,e){O.hookCommand(this.onAfterHooks,t,e)}onAfterUI(t,e){O.hookCommand(this.onAfterUIHooks,t,e)}onAfterOnce(t,e){O.hookCommand(this.onAfterOnceHooks,t,e)}onAfterAffect(t,e){O.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 O.runCallbacks(Object.assign([],this.onAfterHooks[t.getName()]),e,r)),this.onAfterOnceHooks&&await O.runCallbacks(this.onAfterOnceHooks[t.getName()],e,{...r,pop:!0}),this.onAfterUIHooks&&O.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()),O.trace.push(t.getName())}detachCurrent(t){delete this.current[t.getName()],delete this.currentArgs[t.getName()],O.trace.pop(),this.trace.pop()}}class A 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 y(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__=""}(b||(b={}));class k extends o{logger;apiBaseUrl;static getName(){return"Core/Clients/Http"}constructor(t="http://localhost"){super(),this.logger=new c(k.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"},o={};[b.POST,b.PUT,b.PATCH].includes(e)?(Object.assign(o,{"Content-Type":"application/json"}),Object.assign(s,{method:e,headers:o,body:JSON.stringify(r)})):Object.assign(s,{headers:o});const n=await globalThis.fetch(this.apiBaseUrl+t,s);let a;try{a=await n.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 O{static client;currentHttpMethod;static getName(){return"Core/Managers/Data"}constructor(t){super(),E.client=new k(t.baseURL)}getClient(){return E.client}get(t,e={},r={}){return this.currentHttpMethod=b.GET,super.run(t,e,r)}update(t,e={},r={}){return this.currentHttpMethod=b.PATCH,super.run(t,e,r)}delete(t,e={},r={}){return this.currentHttpMethod=b.DELETE,super.run(t,e,r)}create(t,e={},r={}){return this.currentHttpMethod=b.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 b.GET===this.currentHttpMethod?s.args.query=e:s.args.data=e,e.result=await super.runInstance(t,s,r),this.currentHttpMethod=b.__EMPTY__,e.result}}class _ extends O{static getName(){return"Core/Managers/Internal"}}var j=Object.freeze({__proto__:null,Commands:O,Controllers:A,Data:E,Internal:_}),H=Object.freeze({__proto__:null,commandBases:m,core:d,errors:N,managerBases:j,managers:g,modules:w,utils:i}),I="0.0.0-abc.1";const $=g;let T=!1;function B(){if(T)throw Error("ZenCore is already initialized.")}B();let M={version:I};const x=[],U={initialize:t=>{B(),M=t||M,$.commands=new O,$.controllers=new A,$.data=new E(M),$.internal=new _,T=!0,x.forEach((t=>t()))},destroy:()=>{T=!1,$.commands={},$.controllers={},$.data={},$.internal={}},onAfterInitialize:t=>{x.push(t)},config:M,...H};globalThis?.ZenCore||(globalThis.ZenCore=U),t.commandBases=m,t.core=d,t.default=U,t.errors=N,t.managerBases=j,t.managers=g,t.modules=w,t.utils=i,Object.defineProperty(t,"__esModule",{value:!0})}));
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})}));
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@zenflux/core",
3
- "version": "0.0.0-abc.1",
3
+ "version": "0.0.0-abc.10",
4
4
  "description": "ZenFlux core",
5
5
  "author": "Leonid Vinikov <leonidvinikov@gmail.com> (https://github.com/iNewLegend)",
6
6
  "scripts": {
7
7
  "test": "export flow_modules_logger=off && jest",
8
- "build": "rollup --config rollup.config.ts --configPlugin typescript"
8
+ "build": "rollup --config rollup.config.ts --configPlugin typescript",
9
+ "watch": "rollup --config rollup.config.ts --configPlugin typescript --watch"
9
10
  },
10
11
  "repository": {
11
12
  "type": "git",
@@ -5,8 +5,6 @@
5
5
  import { ForceMethod } from '../errors/force-method';
6
6
  import { CommandBase } from './command-base';
7
7
 
8
- import { data } from '../managers/';
9
-
10
8
  export abstract class CommandData extends CommandBase {
11
9
  static getName() {
12
10
  return 'Core/CommandBases/CommandData';
@@ -28,8 +26,8 @@ export abstract class CommandData extends CommandBase {
28
26
  apply( args = this.args, options = this.options ) {// eslint-disable-line @typescript-eslint/no-unused-vars
29
27
  const endpoint = this.applyEndpointFormat( this.getEndpoint(), args );
30
28
 
31
- return data.getClient().fetch(
32
- endpoint, data.currentHttpMethod, args || null
29
+ return __ZEN_MANAGERS__.data.getClient().fetch(
30
+ endpoint, __ZEN_MANAGERS__.data.currentHttpMethod, args || null
33
31
  );
34
32
  }
35
33
 
@@ -6,8 +6,6 @@ import ObjectBase from "./object-base";
6
6
 
7
7
  import { CommandData, CommandInternal, CommandPublic } from "../command-bases";
8
8
 
9
- import * as managers from "../managers/";
10
-
11
9
  export abstract class Controller extends ObjectBase {
12
10
  commands: { [ key: string ]: typeof CommandPublic };
13
11
  data: { [ key: string ]: typeof CommandData };
@@ -30,13 +28,13 @@ export abstract class Controller extends ObjectBase {
30
28
  }
31
29
 
32
30
  register() {
33
- this.commands = managers.commands.register( this.getCommands(), this ) as
31
+ this.commands = __ZEN_MANAGERS__.commands.register( this.getCommands(), this ) as
34
32
  { [ key: string ]: typeof CommandPublic };
35
33
 
36
- this.data = managers.data.register( this.getData(), this ) as
34
+ this.data = __ZEN_MANAGERS__.data.register( this.getData(), this ) as
37
35
  { [ key: string ]: typeof CommandData };
38
36
 
39
- this.internal = managers.internal.register( this.getInternal(), this ) as
37
+ this.internal = __ZEN_MANAGERS__.internal.register( this.getInternal(), this ) as
40
38
  { [ key: string ]: typeof CommandInternal };
41
39
  }
42
40
 
package/src/exports.ts CHANGED
@@ -8,4 +8,3 @@ export * as managers from "./managers";
8
8
  export * as managerBases from "./manager-bases";
9
9
  export * as modules from "./modules";
10
10
  export * as utils from "./utils";
11
-
package/src/globals.ts ADDED
@@ -0,0 +1,22 @@
1
+ if ( typeof __ZEN_MANAGERS__ === 'undefined' || ! __ZEN_MANAGERS__ ) {
2
+ // @ts-ignore
3
+ globalThis.__ZEN_MANAGERS__ = {};
4
+ }
5
+
6
+ import Commands from "./manager-bases/commands";
7
+ import Controllers from "./manager-bases/controllers";
8
+ import Data from "./manager-bases/data";
9
+ import Internal from "./manager-bases/internal";
10
+
11
+ declare global {
12
+ var ZenCore: any;
13
+ }
14
+
15
+ declare global {
16
+ var __ZEN_MANAGERS__: {
17
+ commands: Commands;
18
+ controllers: Controllers;
19
+ data: Data;
20
+ internal: Internal;
21
+ }
22
+ }
package/src/index.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
3
3
  */
4
+ export { CoreAPI as default } from "./initializer";
5
+
4
6
  export * from './exports';
5
7
 
6
- export { CoreAPI as default } from "./initializer";
7
8
 
@@ -2,10 +2,10 @@ import pkg from "../package.json";
2
2
 
3
3
  import * as exported from './exports';
4
4
 
5
- const managers = exported.managers;
6
-
7
5
  import { IAPIConfig } from "./interfaces/config";
8
6
 
7
+ import { destroy, initialize } from "./managers";
8
+
9
9
  declare global {
10
10
  var ZenCore: any;
11
11
  }
@@ -32,10 +32,7 @@ export const CoreAPI = {
32
32
 
33
33
  config = configuration || config;
34
34
 
35
- managers.commands = new exported.managerBases.Commands();
36
- managers.controllers = new exported.managerBases.Controllers();
37
- managers.data = new exported.managerBases.Data( config );
38
- managers.internal = new exported.managerBases.Internal();
35
+ initialize( config )
39
36
 
40
37
  isInitialized = true;
41
38
 
@@ -43,12 +40,9 @@ export const CoreAPI = {
43
40
  },
44
41
 
45
42
  destroy: () => {
46
- isInitialized = false;
43
+ destroy();
47
44
 
48
- managers.commands = {} as exported.managerBases.Commands;
49
- managers.controllers = {} as exported.managerBases.Controllers
50
- managers.data = {} as exported.managerBases.Data;
51
- managers.internal = {} as exported.managerBases.Internal;
45
+ isInitialized = false;
52
46
  },
53
47
 
54
48
  onAfterInitialize: ( callback: () => void ) => {
@@ -58,6 +52,8 @@ export const CoreAPI = {
58
52
  config,
59
53
 
60
54
  ...exported,
55
+
56
+ managers: typeof __ZEN_MANAGERS__ !== 'undefined' ? __ZEN_MANAGERS__ : undefined,
61
57
  }
62
58
 
63
59
  // TODO: Make it available only for development.
@@ -1,9 +1,41 @@
1
1
  /**
2
2
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
3
3
  */
4
- import * as managersBases from "../manager-bases";
4
+ import Commands from "../manager-bases/commands";
5
+ import Controllers from "../manager-bases/controllers";
6
+ import Data from "../manager-bases/data";
7
+ import Internal from "../manager-bases/internal";
8
+ import { IAPIConfig } from "../interfaces/config";
5
9
 
6
- export let commands = {} as managersBases.Commands;
7
- export let controllers = {} as managersBases.Controllers;
8
- export let data = {} as managersBases.Data;
9
- export let internal = {} as managersBases.Internal;
10
+ if ( typeof __ZEN_MANAGERS__ === 'undefined' || ! __ZEN_MANAGERS__ ) {
11
+ // @ts-ignore
12
+ globalThis.__ZEN_MANAGERS__ = {};
13
+ }
14
+
15
+ declare global {
16
+ var __ZEN_MANAGERS__: {
17
+ commands: Commands;
18
+ controllers: Controllers;
19
+ data: Data;
20
+ internal: Internal;
21
+ }
22
+ }
23
+
24
+ export function initialize( config: IAPIConfig ) {
25
+ __ZEN_MANAGERS__.commands = new Commands();
26
+ __ZEN_MANAGERS__.controllers = new Controllers();
27
+ __ZEN_MANAGERS__.data = new Data( config );
28
+ __ZEN_MANAGERS__.internal = new Internal();
29
+ }
30
+
31
+ export function destroy() {
32
+ __ZEN_MANAGERS__.commands = {} as Commands;
33
+ __ZEN_MANAGERS__.controllers = {} as Controllers;
34
+ __ZEN_MANAGERS__.data = {} as Data;
35
+ __ZEN_MANAGERS__.internal = {} as Internal;
36
+ }
37
+
38
+ export const controllers = __ZEN_MANAGERS__.controllers;
39
+ export const commands = __ZEN_MANAGERS__.commands;
40
+ export const data = __ZEN_MANAGERS__.data;
41
+ export const internal = __ZEN_MANAGERS__.internal;
package/types/index.d.ts CHANGED
@@ -1,2 +1,5 @@
1
- export * from '../dist/es/src/exports';
2
1
  export { initialize, destroy, onAfterInitialize } from "../dist/es/src/initializer";
2
+
3
+ export * from '../dist/es/src/exports';
4
+ export * as managers from "../dist/es/src/managers";
5
+