@zenflux/core 0.0.0-abc.7 → 0.0.0-abc.9
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.
- package/dist/cjs/zenflux-core.js +125 -103
- package/dist/es/src/globals.d.ts +15 -0
- package/dist/es/src/index.d.ts +1 -1
- package/dist/es/src/initializer.d.ts +0 -1
- package/dist/es/src/managers/index.d.ts +8 -4
- package/dist/es/zenflux-core.js +121 -99
- package/dist/es/zenflux-core.mjs +3 -3
- package/dist/umd/zenflux-core.js +3 -3
- package/package.json +1 -1
- package/src/command-bases/command-data.ts +2 -4
- package/src/core/controller.ts +3 -5
- package/src/exports.ts +0 -1
- package/src/globals.ts +22 -0
- package/src/index.ts +2 -1
- package/src/initializer.ts +8 -13
- package/src/managers/index.ts +22 -4
- package/types/index.d.ts +4 -1
package/dist/cjs/zenflux-core.js
CHANGED
|
@@ -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.9";
|
|
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 = Object.assign({});
|
|
449
|
-
let controllers = Object.assign({});
|
|
450
|
-
let data = Object.assign({});
|
|
451
|
-
let internal = Object.assign({});
|
|
452
|
-
|
|
453
|
-
var index$5 = /*#__PURE__*/Object.freeze({
|
|
454
|
-
__proto__: null,
|
|
455
|
-
get commands () { return commands; },
|
|
456
|
-
get controllers () { return controllers; },
|
|
457
|
-
get data () { return data; },
|
|
458
|
-
get internal () { return 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$
|
|
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$
|
|
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$
|
|
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$
|
|
651
|
+
var index$2 = /*#__PURE__*/Object.freeze({
|
|
593
652
|
__proto__: null,
|
|
594
653
|
Logger: Logger
|
|
595
654
|
});
|
|
@@ -956,6 +1015,41 @@ class Internal extends Commands {
|
|
|
956
1015
|
}
|
|
957
1016
|
}
|
|
958
1017
|
|
|
1018
|
+
if (typeof __ZEN_MANAGERS__ === 'undefined' || !__ZEN_MANAGERS__) {
|
|
1019
|
+
// @ts-ignore
|
|
1020
|
+
globalThis.__ZEN_MANAGERS__ = {};
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
/**
|
|
1024
|
+
* @author: Leonid Vinikov <leonidvinikov@gmail.com>
|
|
1025
|
+
*/
|
|
1026
|
+
function initialize(config) {
|
|
1027
|
+
__ZEN_MANAGERS__.commands = new Commands();
|
|
1028
|
+
__ZEN_MANAGERS__.controllers = new Controllers();
|
|
1029
|
+
__ZEN_MANAGERS__.data = new Data(config);
|
|
1030
|
+
__ZEN_MANAGERS__.internal = new Internal();
|
|
1031
|
+
}
|
|
1032
|
+
function destroy() {
|
|
1033
|
+
__ZEN_MANAGERS__.commands = {};
|
|
1034
|
+
__ZEN_MANAGERS__.controllers = {};
|
|
1035
|
+
__ZEN_MANAGERS__.data = {};
|
|
1036
|
+
__ZEN_MANAGERS__.internal = {};
|
|
1037
|
+
}
|
|
1038
|
+
const controllers = __ZEN_MANAGERS__.controllers;
|
|
1039
|
+
const commands = __ZEN_MANAGERS__.commands;
|
|
1040
|
+
const data = __ZEN_MANAGERS__.data;
|
|
1041
|
+
const internal = __ZEN_MANAGERS__.internal;
|
|
1042
|
+
|
|
1043
|
+
var index$1 = /*#__PURE__*/Object.freeze({
|
|
1044
|
+
__proto__: null,
|
|
1045
|
+
get commands () { return commands; },
|
|
1046
|
+
get controllers () { return controllers; },
|
|
1047
|
+
get data () { return data; },
|
|
1048
|
+
destroy: destroy,
|
|
1049
|
+
initialize: initialize,
|
|
1050
|
+
get internal () { return internal; }
|
|
1051
|
+
});
|
|
1052
|
+
|
|
959
1053
|
/**
|
|
960
1054
|
* @author: Leonid Vinikov <leonidvinikov@gmail.com>
|
|
961
1055
|
*/
|
|
@@ -974,87 +1068,15 @@ Internal: Internal
|
|
|
974
1068
|
|
|
975
1069
|
var exported = /*#__PURE__*/Object.freeze({
|
|
976
1070
|
__proto__: null,
|
|
977
|
-
commandBases: index$
|
|
978
|
-
core: index$
|
|
979
|
-
errors: index$
|
|
1071
|
+
commandBases: index$5,
|
|
1072
|
+
core: index$4,
|
|
1073
|
+
errors: index$3,
|
|
980
1074
|
managerBases: index,
|
|
981
|
-
managers: index$
|
|
982
|
-
modules: index$
|
|
1075
|
+
managers: index$1,
|
|
1076
|
+
modules: index$2,
|
|
983
1077
|
utils: index$6
|
|
984
1078
|
});
|
|
985
1079
|
|
|
986
|
-
var name = "@zenflux/core";
|
|
987
|
-
var version = "0.0.0-abc.7";
|
|
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
|
-
watch: "rollup --config rollup.config.ts --configPlugin typescript --watch"
|
|
994
|
-
};
|
|
995
|
-
var repository = {
|
|
996
|
-
type: "git",
|
|
997
|
-
url: "git+https://github.com/zenflux/core.git"
|
|
998
|
-
};
|
|
999
|
-
var keywords = [
|
|
1000
|
-
"zenflux",
|
|
1001
|
-
"zen",
|
|
1002
|
-
"flux",
|
|
1003
|
-
"commands",
|
|
1004
|
-
"manager",
|
|
1005
|
-
"commands manager"
|
|
1006
|
-
];
|
|
1007
|
-
var files = [
|
|
1008
|
-
"dist",
|
|
1009
|
-
"src",
|
|
1010
|
-
"types"
|
|
1011
|
-
];
|
|
1012
|
-
var license = "MIT";
|
|
1013
|
-
var main = "dist/cjs/zenflux-core.js";
|
|
1014
|
-
var unpkg = "dist/umd/zenflux-core.js";
|
|
1015
|
-
var module$1 = "dist/es/zenflux-core.js";
|
|
1016
|
-
var types = "types/index.d.ts";
|
|
1017
|
-
var devDependencies = {
|
|
1018
|
-
"@babel/core": "^7.20.7",
|
|
1019
|
-
"@babel/plugin-transform-runtime": "^7.19.6",
|
|
1020
|
-
"@babel/preset-env": "^7.20.2",
|
|
1021
|
-
"@babel/preset-typescript": "^7.18.6",
|
|
1022
|
-
"@babel/runtime": "^7.20.7",
|
|
1023
|
-
"@rollup/plugin-babel": "^6.0.3",
|
|
1024
|
-
"@rollup/plugin-json": "^6.0.0",
|
|
1025
|
-
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
1026
|
-
"@rollup/plugin-replace": "^5.0.2",
|
|
1027
|
-
"@rollup/plugin-terser": "^0.2.1",
|
|
1028
|
-
"@rollup/plugin-typescript": "^10.0.1",
|
|
1029
|
-
"@types/jest": "^29.2.5",
|
|
1030
|
-
"@typescript-eslint/eslint-plugin": "^5.48.0",
|
|
1031
|
-
"@typescript-eslint/parser": "^5.48.0",
|
|
1032
|
-
"babel-jest": "^29.3.1",
|
|
1033
|
-
rollup: "^3.9.1",
|
|
1034
|
-
"ts-jest": "^29.0.3",
|
|
1035
|
-
tslib: "^2.4.1"
|
|
1036
|
-
};
|
|
1037
|
-
var dependencies = {
|
|
1038
|
-
"@babel/runtime": "^7.19.0"
|
|
1039
|
-
};
|
|
1040
|
-
var pkg = {
|
|
1041
|
-
name: name,
|
|
1042
|
-
version: version,
|
|
1043
|
-
description: description,
|
|
1044
|
-
author: author,
|
|
1045
|
-
scripts: scripts,
|
|
1046
|
-
repository: repository,
|
|
1047
|
-
keywords: keywords,
|
|
1048
|
-
files: files,
|
|
1049
|
-
license: license,
|
|
1050
|
-
main: main,
|
|
1051
|
-
unpkg: unpkg,
|
|
1052
|
-
module: module$1,
|
|
1053
|
-
types: types,
|
|
1054
|
-
devDependencies: devDependencies,
|
|
1055
|
-
dependencies: dependencies
|
|
1056
|
-
};
|
|
1057
|
-
|
|
1058
1080
|
let isInitialized = false;
|
|
1059
1081
|
function errorInitTwice() {
|
|
1060
1082
|
if (isInitialized) {
|
|
@@ -1093,11 +1115,11 @@ const CoreAPI = {
|
|
|
1093
1115
|
// TODO: Make it available only for development.
|
|
1094
1116
|
if (!globalThis?.ZenCore) globalThis.ZenCore = CoreAPI;
|
|
1095
1117
|
|
|
1096
|
-
exports.commandBases = index$
|
|
1097
|
-
exports.core = index$
|
|
1118
|
+
exports.commandBases = index$5;
|
|
1119
|
+
exports.core = index$4;
|
|
1098
1120
|
exports.default = CoreAPI;
|
|
1099
|
-
exports.errors = index$
|
|
1121
|
+
exports.errors = index$3;
|
|
1100
1122
|
exports.managerBases = index;
|
|
1101
|
-
exports.managers = index$
|
|
1102
|
-
exports.modules = index$
|
|
1123
|
+
exports.managers = index$1;
|
|
1124
|
+
exports.modules = index$2;
|
|
1103
1125
|
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 __ZEN_MANAGERS__: {
|
|
7
|
+
commands: Commands;
|
|
8
|
+
controllers: Controllers;
|
|
9
|
+
data: Data;
|
|
10
|
+
internal: Internal;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
declare global {
|
|
14
|
+
var ZenCore: any;
|
|
15
|
+
}
|
package/dist/es/src/index.d.ts
CHANGED
|
@@ -5,7 +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
|
-
|
|
10
|
-
export declare
|
|
11
|
-
export declare
|
|
8
|
+
import { IAPIConfig } from "../interfaces/config";
|
|
9
|
+
import '../globals';
|
|
10
|
+
export declare function initialize(config: IAPIConfig): void;
|
|
11
|
+
export declare function destroy(): void;
|
|
12
|
+
export declare const controllers: Controllers;
|
|
13
|
+
export declare const commands: Commands;
|
|
14
|
+
export declare const data: Data;
|
|
15
|
+
export declare const internal: Internal;
|
package/dist/es/zenflux-core.js
CHANGED
|
@@ -1,3 +1,75 @@
|
|
|
1
|
+
var name = "@zenflux/core";
|
|
2
|
+
var version = "0.0.0-abc.9";
|
|
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 = Object.assign({});
|
|
445
|
-
let controllers = Object.assign({});
|
|
446
|
-
let data = Object.assign({});
|
|
447
|
-
let internal = Object.assign({});
|
|
448
|
-
|
|
449
|
-
var index$5 = /*#__PURE__*/Object.freeze({
|
|
450
|
-
__proto__: null,
|
|
451
|
-
get commands () { return commands; },
|
|
452
|
-
get controllers () { return controllers; },
|
|
453
|
-
get data () { return data; },
|
|
454
|
-
get internal () { return 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$
|
|
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$
|
|
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$
|
|
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$
|
|
647
|
+
var index$2 = /*#__PURE__*/Object.freeze({
|
|
589
648
|
__proto__: null,
|
|
590
649
|
Logger: Logger
|
|
591
650
|
});
|
|
@@ -952,6 +1011,41 @@ class Internal extends Commands {
|
|
|
952
1011
|
}
|
|
953
1012
|
}
|
|
954
1013
|
|
|
1014
|
+
if (typeof __ZEN_MANAGERS__ === 'undefined' || !__ZEN_MANAGERS__) {
|
|
1015
|
+
// @ts-ignore
|
|
1016
|
+
globalThis.__ZEN_MANAGERS__ = {};
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
/**
|
|
1020
|
+
* @author: Leonid Vinikov <leonidvinikov@gmail.com>
|
|
1021
|
+
*/
|
|
1022
|
+
function initialize(config) {
|
|
1023
|
+
__ZEN_MANAGERS__.commands = new Commands();
|
|
1024
|
+
__ZEN_MANAGERS__.controllers = new Controllers();
|
|
1025
|
+
__ZEN_MANAGERS__.data = new Data(config);
|
|
1026
|
+
__ZEN_MANAGERS__.internal = new Internal();
|
|
1027
|
+
}
|
|
1028
|
+
function destroy() {
|
|
1029
|
+
__ZEN_MANAGERS__.commands = {};
|
|
1030
|
+
__ZEN_MANAGERS__.controllers = {};
|
|
1031
|
+
__ZEN_MANAGERS__.data = {};
|
|
1032
|
+
__ZEN_MANAGERS__.internal = {};
|
|
1033
|
+
}
|
|
1034
|
+
const controllers = __ZEN_MANAGERS__.controllers;
|
|
1035
|
+
const commands = __ZEN_MANAGERS__.commands;
|
|
1036
|
+
const data = __ZEN_MANAGERS__.data;
|
|
1037
|
+
const internal = __ZEN_MANAGERS__.internal;
|
|
1038
|
+
|
|
1039
|
+
var index$1 = /*#__PURE__*/Object.freeze({
|
|
1040
|
+
__proto__: null,
|
|
1041
|
+
get commands () { return commands; },
|
|
1042
|
+
get controllers () { return controllers; },
|
|
1043
|
+
get data () { return data; },
|
|
1044
|
+
destroy: destroy,
|
|
1045
|
+
initialize: initialize,
|
|
1046
|
+
get internal () { return internal; }
|
|
1047
|
+
});
|
|
1048
|
+
|
|
955
1049
|
/**
|
|
956
1050
|
* @author: Leonid Vinikov <leonidvinikov@gmail.com>
|
|
957
1051
|
*/
|
|
@@ -970,87 +1064,15 @@ Internal: Internal
|
|
|
970
1064
|
|
|
971
1065
|
var exported = /*#__PURE__*/Object.freeze({
|
|
972
1066
|
__proto__: null,
|
|
973
|
-
commandBases: index$
|
|
974
|
-
core: index$
|
|
975
|
-
errors: index$
|
|
1067
|
+
commandBases: index$5,
|
|
1068
|
+
core: index$4,
|
|
1069
|
+
errors: index$3,
|
|
976
1070
|
managerBases: index,
|
|
977
|
-
managers: index$
|
|
978
|
-
modules: index$
|
|
1071
|
+
managers: index$1,
|
|
1072
|
+
modules: index$2,
|
|
979
1073
|
utils: index$6
|
|
980
1074
|
});
|
|
981
1075
|
|
|
982
|
-
var name = "@zenflux/core";
|
|
983
|
-
var version = "0.0.0-abc.7";
|
|
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
|
-
watch: "rollup --config rollup.config.ts --configPlugin typescript --watch"
|
|
990
|
-
};
|
|
991
|
-
var repository = {
|
|
992
|
-
type: "git",
|
|
993
|
-
url: "git+https://github.com/zenflux/core.git"
|
|
994
|
-
};
|
|
995
|
-
var keywords = [
|
|
996
|
-
"zenflux",
|
|
997
|
-
"zen",
|
|
998
|
-
"flux",
|
|
999
|
-
"commands",
|
|
1000
|
-
"manager",
|
|
1001
|
-
"commands manager"
|
|
1002
|
-
];
|
|
1003
|
-
var files = [
|
|
1004
|
-
"dist",
|
|
1005
|
-
"src",
|
|
1006
|
-
"types"
|
|
1007
|
-
];
|
|
1008
|
-
var license = "MIT";
|
|
1009
|
-
var main = "dist/cjs/zenflux-core.js";
|
|
1010
|
-
var unpkg = "dist/umd/zenflux-core.js";
|
|
1011
|
-
var module = "dist/es/zenflux-core.js";
|
|
1012
|
-
var types = "types/index.d.ts";
|
|
1013
|
-
var devDependencies = {
|
|
1014
|
-
"@babel/core": "^7.20.7",
|
|
1015
|
-
"@babel/plugin-transform-runtime": "^7.19.6",
|
|
1016
|
-
"@babel/preset-env": "^7.20.2",
|
|
1017
|
-
"@babel/preset-typescript": "^7.18.6",
|
|
1018
|
-
"@babel/runtime": "^7.20.7",
|
|
1019
|
-
"@rollup/plugin-babel": "^6.0.3",
|
|
1020
|
-
"@rollup/plugin-json": "^6.0.0",
|
|
1021
|
-
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
1022
|
-
"@rollup/plugin-replace": "^5.0.2",
|
|
1023
|
-
"@rollup/plugin-terser": "^0.2.1",
|
|
1024
|
-
"@rollup/plugin-typescript": "^10.0.1",
|
|
1025
|
-
"@types/jest": "^29.2.5",
|
|
1026
|
-
"@typescript-eslint/eslint-plugin": "^5.48.0",
|
|
1027
|
-
"@typescript-eslint/parser": "^5.48.0",
|
|
1028
|
-
"babel-jest": "^29.3.1",
|
|
1029
|
-
rollup: "^3.9.1",
|
|
1030
|
-
"ts-jest": "^29.0.3",
|
|
1031
|
-
tslib: "^2.4.1"
|
|
1032
|
-
};
|
|
1033
|
-
var dependencies = {
|
|
1034
|
-
"@babel/runtime": "^7.19.0"
|
|
1035
|
-
};
|
|
1036
|
-
var pkg = {
|
|
1037
|
-
name: name,
|
|
1038
|
-
version: version,
|
|
1039
|
-
description: description,
|
|
1040
|
-
author: author,
|
|
1041
|
-
scripts: scripts,
|
|
1042
|
-
repository: repository,
|
|
1043
|
-
keywords: keywords,
|
|
1044
|
-
files: files,
|
|
1045
|
-
license: license,
|
|
1046
|
-
main: main,
|
|
1047
|
-
unpkg: unpkg,
|
|
1048
|
-
module: module,
|
|
1049
|
-
types: types,
|
|
1050
|
-
devDependencies: devDependencies,
|
|
1051
|
-
dependencies: dependencies
|
|
1052
|
-
};
|
|
1053
|
-
|
|
1054
1076
|
let isInitialized = false;
|
|
1055
1077
|
function errorInitTwice() {
|
|
1056
1078
|
if (isInitialized) {
|
|
@@ -1089,4 +1111,4 @@ const CoreAPI = {
|
|
|
1089
1111
|
// TODO: Make it available only for development.
|
|
1090
1112
|
if (!globalThis?.ZenCore) globalThis.ZenCore = CoreAPI;
|
|
1091
1113
|
|
|
1092
|
-
export { index$
|
|
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 };
|
package/dist/es/zenflux-core.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
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()}}
|
|
2
2
|
/**
|
|
3
3
|
* Function getCircularReplacer() : Reduce circular references.
|
|
4
4
|
*
|
|
5
5
|
* @copyright https://stackoverflow.com/a/53731154
|
|
6
6
|
*/
|
|
7
|
-
const
|
|
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:n,hexColorDelta:o});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 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=i.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",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),n()):"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=>o(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=Object.assign({}),h=Object.assign({}),u=Object.assign({}),p=Object.assign({});var g=Object.freeze({__proto__:null,get commands(){return l},get controllers(){return h},get data(){return u},get internal(){return p}});var m=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 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 c{static getName(){return"Core/CommandBases/CommandInternal"}},CommandPublic:class extends c{static getName(){return"Core/CommandBases/CommandPublic"}}});var d=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=u.register(this.getData(),this),this.internal=p.register(this.getInternal(),this)}getCommands(){return{}}getData(){return{}}getInternal(){return{}}},ObjectBase:s});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:e}),w=Object.freeze({__proto__:null,Logger:i});class O 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 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 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 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 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 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 j extends s{logger;apiBaseUrl;static getName(){return"Core/Clients/Http"}constructor(t="http://localhost"){super(),this.logger=new i(j.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={};[b.POST,b.PUT,b.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 k extends O{static client;currentHttpMethod;static getName(){return"Core/Managers/Data"}constructor(t){super(),k.client=new j(t.baseURL)}getClient(){return k.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 E extends O{static getName(){return"Core/Managers/Internal"}}var H=Object.freeze({__proto__:null,Commands:O,Controllers:A,Data:k,Internal:E}),_=Object.freeze({__proto__:null,commandBases:m,core:d,errors:N,managerBases:H,managers:g,modules:w,utils:a}),I="0.0.0-abc.7";let $=!1;function B(){if($)throw Error("ZenCore is already initialized.")}B();let T={version:I};const M=[],U={initialize:t=>{B(),T=t||T,l=new O,h=new A,u=new k(T),p=new E,$=!0,M.forEach((t=>t()))},destroy:()=>{$=!1,l={},h={},u={},p={}},onAfterInitialize:t=>{M.push(t)},config:T,..._};globalThis?.ZenCore||(globalThis.ZenCore=U);export{m as commandBases,d as core,U as default,N as errors,H as managerBases,g as managers,w 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};
|
package/dist/umd/zenflux-core.js
CHANGED
|
@@ -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";
|
|
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()}}
|
|
2
2
|
/**
|
|
3
3
|
* Function getCircularReplacer() : Reduce circular references.
|
|
4
4
|
*
|
|
5
5
|
* @copyright https://stackoverflow.com/a/53731154
|
|
6
6
|
*/
|
|
7
|
-
const
|
|
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: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}}let h=Object.assign({}),u=Object.assign({}),p=Object.assign({}),g=Object.assign({});var m=Object.freeze({__proto__:null,get commands(){return h},get controllers(){return u},get data(){return p},get internal(){return g}});var d=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 p.getClient().fetch(r,p.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 f=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=h.register(this.getCommands(),this),this.data=p.register(this.getData(),this),this.internal=g.register(this.getInternal(),this)}getCommands(){return{}}getData(){return{}}getInternal(){return{}}},ObjectBase:n});class C extends Error{constructor(t){super(`Command: '${t.getName()}' is already registered`)}}class y extends Error{constructor(t){super(`Command: '${t}' is not found`)}}class b extends Error{constructor(t){super(`Controller: '${t.getName()}' is already registered`)}}var N,w=Object.freeze({__proto__:null,CommandAlreadyRegistered:C,CommandNotFound:y,ControllerAlreadyRegistered:b,ForceMethod:r}),O=Object.freeze({__proto__:null,Logger:c});class A 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 C(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 y(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 j 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 b(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__=""}(N||(N={}));class k extends n{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"},n={};[N.POST,N.PUT,N.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 A{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=N.GET,super.run(t,e,r)}update(t,e={},r={}){return this.currentHttpMethod=N.PATCH,super.run(t,e,r)}delete(t,e={},r={}){return this.currentHttpMethod=N.DELETE,super.run(t,e,r)}create(t,e={},r={}){return this.currentHttpMethod=N.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 N.GET===this.currentHttpMethod?s.args.query=e:s.args.data=e,e.result=await super.runInstance(t,s,r),this.currentHttpMethod=N.__EMPTY__,e.result}}class _ extends A{static getName(){return"Core/Managers/Internal"}}var H=Object.freeze({__proto__:null,Commands:A,Controllers:j,Data:E,Internal:_}),I=Object.freeze({__proto__:null,commandBases:d,core:f,errors:w,managerBases:H,managers:m,modules:O,utils:i}),$="0.0.0-abc.7";let T=!1;function B(){if(T)throw Error("ZenCore is already initialized.")}B();let M={version:$};const x=[],U={initialize:t=>{B(),M=t||M,h=new A,u=new j,p=new E(M),g=new _,T=!0,x.forEach((t=>t()))},destroy:()=>{T=!1,h={},u={},p={},g={}},onAfterInitialize:t=>{x.push(t)},config:M,...I};globalThis?.ZenCore||(globalThis.ZenCore=U),t.commandBases=d,t.core=f,t.default=U,t.errors=w,t.managerBases=H,t.managers=m,t.modules=O,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
|
@@ -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
|
|
package/src/core/controller.ts
CHANGED
|
@@ -6,8 +6,6 @@ import ObjectBase from "./object-base";
|
|
|
6
6
|
|
|
7
7
|
import { CommandData, CommandInternal, CommandPublic } from "../command-bases";
|
|
8
8
|
|
|
9
|
-
import { commands, data, internal } 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 = 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 = 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 = 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
package/src/globals.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
if ( typeof __ZEN_MANAGERS__ === 'undefined' || ! __ZEN_MANAGERS__ ) {
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
globalThis.__ZEN_MANAGERS__ = {};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare global {
|
|
12
|
+
var __ZEN_MANAGERS__: {
|
|
13
|
+
commands: Commands;
|
|
14
|
+
controllers: Controllers;
|
|
15
|
+
data: Data;
|
|
16
|
+
internal: Internal;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
declare global {
|
|
21
|
+
var ZenCore: any;
|
|
22
|
+
}
|
package/src/index.ts
CHANGED
package/src/initializer.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import pkg from "../package.json";
|
|
2
2
|
|
|
3
|
+
import '../globals'
|
|
4
|
+
|
|
3
5
|
import * as exported from './exports';
|
|
4
6
|
|
|
5
7
|
import { IAPIConfig } from "./interfaces/config";
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
var ZenCore: any;
|
|
9
|
-
var exported: any;
|
|
10
|
-
}
|
|
9
|
+
import { destroy, initialize } from "./managers";
|
|
11
10
|
|
|
12
11
|
let isInitialized = false;
|
|
13
12
|
|
|
@@ -31,10 +30,7 @@ export const CoreAPI = {
|
|
|
31
30
|
|
|
32
31
|
config = configuration || config;
|
|
33
32
|
|
|
34
|
-
|
|
35
|
-
exported.managers.controllers = new exported.managerBases.Controllers();
|
|
36
|
-
exported.managers.data = new exported.managerBases.Data( config );
|
|
37
|
-
exported.managers.internal = new exported.managerBases.Internal();
|
|
33
|
+
initialize( config )
|
|
38
34
|
|
|
39
35
|
isInitialized = true;
|
|
40
36
|
|
|
@@ -42,12 +38,9 @@ export const CoreAPI = {
|
|
|
42
38
|
},
|
|
43
39
|
|
|
44
40
|
destroy: () => {
|
|
45
|
-
|
|
41
|
+
destroy();
|
|
46
42
|
|
|
47
|
-
|
|
48
|
-
exported.managers.controllers = {} as exported.managerBases.Controllers
|
|
49
|
-
exported.managers.data = {} as exported.managerBases.Data;
|
|
50
|
-
exported.managers.internal = {} as exported.managerBases.Internal;
|
|
43
|
+
isInitialized = false;
|
|
51
44
|
},
|
|
52
45
|
|
|
53
46
|
onAfterInitialize: ( callback: () => void ) => {
|
|
@@ -57,6 +50,8 @@ export const CoreAPI = {
|
|
|
57
50
|
config,
|
|
58
51
|
|
|
59
52
|
...exported,
|
|
53
|
+
|
|
54
|
+
managers: typeof __ZEN_MANAGERS__ !== 'undefined' ? __ZEN_MANAGERS__ : undefined,
|
|
60
55
|
}
|
|
61
56
|
|
|
62
57
|
// TODO: Make it available only for development.
|
package/src/managers/index.ts
CHANGED
|
@@ -6,7 +6,25 @@ import Controllers from "../manager-bases/controllers";
|
|
|
6
6
|
import Data from "../manager-bases/data";
|
|
7
7
|
import Internal from "../manager-bases/internal";
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
import { IAPIConfig } from "../interfaces/config";
|
|
10
|
+
|
|
11
|
+
import '../globals'
|
|
12
|
+
|
|
13
|
+
export function initialize( config: IAPIConfig ) {
|
|
14
|
+
__ZEN_MANAGERS__.commands = new Commands();
|
|
15
|
+
__ZEN_MANAGERS__.controllers = new Controllers();
|
|
16
|
+
__ZEN_MANAGERS__.data = new Data( config );
|
|
17
|
+
__ZEN_MANAGERS__.internal = new Internal();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function destroy() {
|
|
21
|
+
__ZEN_MANAGERS__.commands = {} as Commands;
|
|
22
|
+
__ZEN_MANAGERS__.controllers = {} as Controllers;
|
|
23
|
+
__ZEN_MANAGERS__.data = {} as Data;
|
|
24
|
+
__ZEN_MANAGERS__.internal = {} as Internal;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const controllers = __ZEN_MANAGERS__.controllers;
|
|
28
|
+
export const commands = __ZEN_MANAGERS__.commands;
|
|
29
|
+
export const data = __ZEN_MANAGERS__.data;
|
|
30
|
+
export const internal = __ZEN_MANAGERS__.internal;
|