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