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