@zenflux/core 0.0.0-abc.7 → 0.0.0-abc.8
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 +57 -40
- package/dist/es/src/globals.d.ts +15 -0
- package/dist/es/src/index.d.ts +1 -0
- package/dist/es/src/initializer.d.ts +6 -5
- package/dist/es/src/managers/index.d.ts +7 -4
- package/dist/es/zenflux-core.js +53 -36
- package/dist/es/zenflux-core.mjs +2 -2
- package/dist/umd/zenflux-core.js +2 -2
- package/package.json +1 -1
- package/src/command-bases/command-data.ts +2 -4
- package/src/core/controller.ts +3 -5
- package/src/exports.ts +0 -1
- package/src/globals.ts +22 -0
- package/src/index.ts +2 -1
- package/src/initializer.ts +8 -10
- package/src/managers/index.ts +33 -4
- package/types/index.d.ts +4 -1
package/dist/cjs/zenflux-core.js
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
if (typeof __ZEN_MANAGERS__ === 'undefined' || !__ZEN_MANAGERS__) {
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
globalThis.__ZEN_MANAGERS__ = {};
|
|
8
|
+
}
|
|
9
|
+
|
|
5
10
|
class ForceMethodBase extends Error {
|
|
6
11
|
constructor(className, methodName) {
|
|
7
12
|
super(`ForeMethod implementation: at '${className}' method: '${methodName}'`);
|
|
@@ -445,19 +450,6 @@ class CommandPublic extends CommandBase {
|
|
|
445
450
|
}
|
|
446
451
|
}
|
|
447
452
|
|
|
448
|
-
let commands = Object.assign({});
|
|
449
|
-
let controllers = Object.assign({});
|
|
450
|
-
let data = Object.assign({});
|
|
451
|
-
let internal = Object.assign({});
|
|
452
|
-
|
|
453
|
-
var index$5 = /*#__PURE__*/Object.freeze({
|
|
454
|
-
__proto__: null,
|
|
455
|
-
get commands () { return commands; },
|
|
456
|
-
get controllers () { return controllers; },
|
|
457
|
-
get data () { return data; },
|
|
458
|
-
get internal () { return internal; }
|
|
459
|
-
});
|
|
460
|
-
|
|
461
453
|
/**
|
|
462
454
|
* @author: Leonid Vinikov <leonidvinikov@gmail.com>
|
|
463
455
|
* @description: Each data command should represent a final REST endpoint.
|
|
@@ -480,7 +472,7 @@ class CommandData extends CommandBase {
|
|
|
480
472
|
}
|
|
481
473
|
apply(args = this.args, options = this.options) {
|
|
482
474
|
const endpoint = this.applyEndpointFormat(this.getEndpoint(), args);
|
|
483
|
-
return data.getClient().fetch(endpoint, data.currentHttpMethod, args || null);
|
|
475
|
+
return __ZEN_MANAGERS__.data.getClient().fetch(endpoint, __ZEN_MANAGERS__.data.currentHttpMethod, args || null);
|
|
484
476
|
}
|
|
485
477
|
applyEndpointFormat(endpoint, data = {}) {
|
|
486
478
|
// Replace query with `magic` placeholders.
|
|
@@ -511,7 +503,7 @@ class CommandInternal extends CommandBase {
|
|
|
511
503
|
* @author: Leonid Vinikov <leonidvinikov@gmail.com>
|
|
512
504
|
*/
|
|
513
505
|
|
|
514
|
-
var index$
|
|
506
|
+
var index$5 = /*#__PURE__*/Object.freeze({
|
|
515
507
|
__proto__: null,
|
|
516
508
|
CommandBase: CommandBase,
|
|
517
509
|
CommandData: CommandData,
|
|
@@ -539,9 +531,9 @@ class Controller extends ObjectBase {
|
|
|
539
531
|
this.setupHooks && this.setupHooks();
|
|
540
532
|
}
|
|
541
533
|
register() {
|
|
542
|
-
this.commands = commands.register(this.getCommands(), this);
|
|
543
|
-
this.data = data.register(this.getData(), this);
|
|
544
|
-
this.internal = internal.register(this.getInternal(), this);
|
|
534
|
+
this.commands = __ZEN_MANAGERS__.commands.register(this.getCommands(), this);
|
|
535
|
+
this.data = __ZEN_MANAGERS__.data.register(this.getData(), this);
|
|
536
|
+
this.internal = __ZEN_MANAGERS__.internal.register(this.getInternal(), this);
|
|
545
537
|
}
|
|
546
538
|
getCommands() {
|
|
547
539
|
return {};
|
|
@@ -554,7 +546,7 @@ class Controller extends ObjectBase {
|
|
|
554
546
|
}
|
|
555
547
|
}
|
|
556
548
|
|
|
557
|
-
var index$
|
|
549
|
+
var index$4 = /*#__PURE__*/Object.freeze({
|
|
558
550
|
__proto__: null,
|
|
559
551
|
Controller: Controller,
|
|
560
552
|
ObjectBase: ObjectBase
|
|
@@ -581,7 +573,7 @@ class ControllerAlreadyRegistered extends Error {
|
|
|
581
573
|
}
|
|
582
574
|
}
|
|
583
575
|
|
|
584
|
-
var index$
|
|
576
|
+
var index$3 = /*#__PURE__*/Object.freeze({
|
|
585
577
|
__proto__: null,
|
|
586
578
|
CommandAlreadyRegistered: CommandAlreadyRegistered,
|
|
587
579
|
CommandNotFound: CommandNotFound,
|
|
@@ -589,7 +581,7 @@ ControllerAlreadyRegistered: ControllerAlreadyRegistered,
|
|
|
589
581
|
ForceMethod: ForceMethod
|
|
590
582
|
});
|
|
591
583
|
|
|
592
|
-
var index$
|
|
584
|
+
var index$2 = /*#__PURE__*/Object.freeze({
|
|
593
585
|
__proto__: null,
|
|
594
586
|
Logger: Logger
|
|
595
587
|
});
|
|
@@ -956,6 +948,36 @@ class Internal extends Commands {
|
|
|
956
948
|
}
|
|
957
949
|
}
|
|
958
950
|
|
|
951
|
+
/**
|
|
952
|
+
* @author: Leonid Vinikov <leonidvinikov@gmail.com>
|
|
953
|
+
*/
|
|
954
|
+
function initialize(config) {
|
|
955
|
+
__ZEN_MANAGERS__.commands = new Commands();
|
|
956
|
+
__ZEN_MANAGERS__.controllers = new Controllers();
|
|
957
|
+
__ZEN_MANAGERS__.data = new Data(config);
|
|
958
|
+
__ZEN_MANAGERS__.internal = new Internal();
|
|
959
|
+
}
|
|
960
|
+
function destroy() {
|
|
961
|
+
__ZEN_MANAGERS__.commands = {};
|
|
962
|
+
__ZEN_MANAGERS__.controllers = {};
|
|
963
|
+
__ZEN_MANAGERS__.data = {};
|
|
964
|
+
__ZEN_MANAGERS__.internal = {};
|
|
965
|
+
}
|
|
966
|
+
const controllers = __ZEN_MANAGERS__.controllers;
|
|
967
|
+
const commands = __ZEN_MANAGERS__.commands;
|
|
968
|
+
const data = __ZEN_MANAGERS__.data;
|
|
969
|
+
const internal = __ZEN_MANAGERS__.internal;
|
|
970
|
+
|
|
971
|
+
var index$1 = /*#__PURE__*/Object.freeze({
|
|
972
|
+
__proto__: null,
|
|
973
|
+
commands: commands,
|
|
974
|
+
controllers: controllers,
|
|
975
|
+
data: data,
|
|
976
|
+
destroy: destroy,
|
|
977
|
+
initialize: initialize,
|
|
978
|
+
internal: internal
|
|
979
|
+
});
|
|
980
|
+
|
|
959
981
|
/**
|
|
960
982
|
* @author: Leonid Vinikov <leonidvinikov@gmail.com>
|
|
961
983
|
*/
|
|
@@ -974,12 +996,12 @@ Internal: Internal
|
|
|
974
996
|
|
|
975
997
|
var exported = /*#__PURE__*/Object.freeze({
|
|
976
998
|
__proto__: null,
|
|
977
|
-
commandBases: index$
|
|
978
|
-
core: index$
|
|
979
|
-
errors: index$
|
|
999
|
+
commandBases: index$5,
|
|
1000
|
+
core: index$4,
|
|
1001
|
+
errors: index$3,
|
|
980
1002
|
managerBases: index,
|
|
981
|
-
managers: index$
|
|
982
|
-
modules: index$
|
|
1003
|
+
managers: index$1,
|
|
1004
|
+
modules: index$2,
|
|
983
1005
|
utils: index$6
|
|
984
1006
|
});
|
|
985
1007
|
|
|
@@ -1070,34 +1092,29 @@ const CoreAPI = {
|
|
|
1070
1092
|
initialize: configuration => {
|
|
1071
1093
|
errorInitTwice();
|
|
1072
1094
|
config = configuration || config;
|
|
1073
|
-
|
|
1074
|
-
controllers = new Controllers();
|
|
1075
|
-
data = new Data(config);
|
|
1076
|
-
internal = new Internal();
|
|
1095
|
+
initialize(config);
|
|
1077
1096
|
isInitialized = true;
|
|
1078
1097
|
afterInitializeCallbacks.forEach(callback => callback());
|
|
1079
1098
|
},
|
|
1080
1099
|
destroy: () => {
|
|
1100
|
+
destroy();
|
|
1081
1101
|
isInitialized = false;
|
|
1082
|
-
commands = {};
|
|
1083
|
-
controllers = {};
|
|
1084
|
-
data = {};
|
|
1085
|
-
internal = {};
|
|
1086
1102
|
},
|
|
1087
1103
|
onAfterInitialize: callback => {
|
|
1088
1104
|
afterInitializeCallbacks.push(callback);
|
|
1089
1105
|
},
|
|
1090
1106
|
config,
|
|
1091
|
-
...exported
|
|
1107
|
+
...exported,
|
|
1108
|
+
managers: typeof __ZEN_MANAGERS__ !== 'undefined' ? __ZEN_MANAGERS__ : undefined
|
|
1092
1109
|
};
|
|
1093
1110
|
// TODO: Make it available only for development.
|
|
1094
1111
|
if (!globalThis?.ZenCore) globalThis.ZenCore = CoreAPI;
|
|
1095
1112
|
|
|
1096
|
-
exports.commandBases = index$
|
|
1097
|
-
exports.core = index$
|
|
1113
|
+
exports.commandBases = index$5;
|
|
1114
|
+
exports.core = index$4;
|
|
1098
1115
|
exports.default = CoreAPI;
|
|
1099
|
-
exports.errors = index$
|
|
1116
|
+
exports.errors = index$3;
|
|
1100
1117
|
exports.managerBases = index;
|
|
1101
|
-
exports.managers = index$
|
|
1102
|
-
exports.modules = index$
|
|
1118
|
+
exports.managers = index$1;
|
|
1119
|
+
exports.modules = index$2;
|
|
1103
1120
|
exports.utils = index$6;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import Commands from "./manager-bases/commands";
|
|
2
|
+
import Controllers from "./manager-bases/controllers";
|
|
3
|
+
import Data from "./manager-bases/data";
|
|
4
|
+
import Internal from "./manager-bases/internal";
|
|
5
|
+
declare global {
|
|
6
|
+
var ZenCore: any;
|
|
7
|
+
}
|
|
8
|
+
declare global {
|
|
9
|
+
var __ZEN_MANAGERS__: {
|
|
10
|
+
commands: Commands;
|
|
11
|
+
controllers: Controllers;
|
|
12
|
+
data: Data;
|
|
13
|
+
internal: Internal;
|
|
14
|
+
};
|
|
15
|
+
}
|
package/dist/es/src/index.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import * as exported from './exports';
|
|
2
2
|
import { IAPIConfig } from "./interfaces/config";
|
|
3
|
-
declare global {
|
|
4
|
-
var ZenCore: any;
|
|
5
|
-
var exported: any;
|
|
6
|
-
}
|
|
7
3
|
export declare let config: IAPIConfig;
|
|
8
4
|
export declare const CoreAPI: {
|
|
5
|
+
managers: {
|
|
6
|
+
commands: exported.managerBases.Commands;
|
|
7
|
+
controllers: exported.managerBases.Controllers;
|
|
8
|
+
data: exported.managerBases.Data;
|
|
9
|
+
internal: exported.managerBases.Internal;
|
|
10
|
+
} | undefined;
|
|
9
11
|
commandBases: typeof exported.commandBases;
|
|
10
12
|
core: typeof exported.core;
|
|
11
13
|
errors: typeof exported.errors;
|
|
12
|
-
managers: typeof exported.managers;
|
|
13
14
|
managerBases: typeof exported.managerBases;
|
|
14
15
|
modules: typeof exported.modules;
|
|
15
16
|
utils: typeof exported.utils;
|
|
@@ -5,7 +5,10 @@ import Commands from "../manager-bases/commands";
|
|
|
5
5
|
import Controllers from "../manager-bases/controllers";
|
|
6
6
|
import Data from "../manager-bases/data";
|
|
7
7
|
import Internal from "../manager-bases/internal";
|
|
8
|
-
|
|
9
|
-
export declare
|
|
10
|
-
export declare
|
|
11
|
-
export declare
|
|
8
|
+
import { IAPIConfig } from "../interfaces/config";
|
|
9
|
+
export declare function initialize(config: IAPIConfig): void;
|
|
10
|
+
export declare function destroy(): void;
|
|
11
|
+
export declare const controllers: Controllers;
|
|
12
|
+
export declare const commands: Commands;
|
|
13
|
+
export declare const data: Data;
|
|
14
|
+
export declare const internal: Internal;
|
package/dist/es/zenflux-core.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
if (typeof __ZEN_MANAGERS__ === 'undefined' || !__ZEN_MANAGERS__) {
|
|
2
|
+
// @ts-ignore
|
|
3
|
+
globalThis.__ZEN_MANAGERS__ = {};
|
|
4
|
+
}
|
|
5
|
+
|
|
1
6
|
class ForceMethodBase extends Error {
|
|
2
7
|
constructor(className, methodName) {
|
|
3
8
|
super(`ForeMethod implementation: at '${className}' method: '${methodName}'`);
|
|
@@ -441,19 +446,6 @@ class CommandPublic extends CommandBase {
|
|
|
441
446
|
}
|
|
442
447
|
}
|
|
443
448
|
|
|
444
|
-
let commands = Object.assign({});
|
|
445
|
-
let controllers = Object.assign({});
|
|
446
|
-
let data = Object.assign({});
|
|
447
|
-
let internal = Object.assign({});
|
|
448
|
-
|
|
449
|
-
var index$5 = /*#__PURE__*/Object.freeze({
|
|
450
|
-
__proto__: null,
|
|
451
|
-
get commands () { return commands; },
|
|
452
|
-
get controllers () { return controllers; },
|
|
453
|
-
get data () { return data; },
|
|
454
|
-
get internal () { return internal; }
|
|
455
|
-
});
|
|
456
|
-
|
|
457
449
|
/**
|
|
458
450
|
* @author: Leonid Vinikov <leonidvinikov@gmail.com>
|
|
459
451
|
* @description: Each data command should represent a final REST endpoint.
|
|
@@ -476,7 +468,7 @@ class CommandData extends CommandBase {
|
|
|
476
468
|
}
|
|
477
469
|
apply(args = this.args, options = this.options) {
|
|
478
470
|
const endpoint = this.applyEndpointFormat(this.getEndpoint(), args);
|
|
479
|
-
return data.getClient().fetch(endpoint, data.currentHttpMethod, args || null);
|
|
471
|
+
return __ZEN_MANAGERS__.data.getClient().fetch(endpoint, __ZEN_MANAGERS__.data.currentHttpMethod, args || null);
|
|
480
472
|
}
|
|
481
473
|
applyEndpointFormat(endpoint, data = {}) {
|
|
482
474
|
// Replace query with `magic` placeholders.
|
|
@@ -507,7 +499,7 @@ class CommandInternal extends CommandBase {
|
|
|
507
499
|
* @author: Leonid Vinikov <leonidvinikov@gmail.com>
|
|
508
500
|
*/
|
|
509
501
|
|
|
510
|
-
var index$
|
|
502
|
+
var index$5 = /*#__PURE__*/Object.freeze({
|
|
511
503
|
__proto__: null,
|
|
512
504
|
CommandBase: CommandBase,
|
|
513
505
|
CommandData: CommandData,
|
|
@@ -535,9 +527,9 @@ class Controller extends ObjectBase {
|
|
|
535
527
|
this.setupHooks && this.setupHooks();
|
|
536
528
|
}
|
|
537
529
|
register() {
|
|
538
|
-
this.commands = commands.register(this.getCommands(), this);
|
|
539
|
-
this.data = data.register(this.getData(), this);
|
|
540
|
-
this.internal = internal.register(this.getInternal(), this);
|
|
530
|
+
this.commands = __ZEN_MANAGERS__.commands.register(this.getCommands(), this);
|
|
531
|
+
this.data = __ZEN_MANAGERS__.data.register(this.getData(), this);
|
|
532
|
+
this.internal = __ZEN_MANAGERS__.internal.register(this.getInternal(), this);
|
|
541
533
|
}
|
|
542
534
|
getCommands() {
|
|
543
535
|
return {};
|
|
@@ -550,7 +542,7 @@ class Controller extends ObjectBase {
|
|
|
550
542
|
}
|
|
551
543
|
}
|
|
552
544
|
|
|
553
|
-
var index$
|
|
545
|
+
var index$4 = /*#__PURE__*/Object.freeze({
|
|
554
546
|
__proto__: null,
|
|
555
547
|
Controller: Controller,
|
|
556
548
|
ObjectBase: ObjectBase
|
|
@@ -577,7 +569,7 @@ class ControllerAlreadyRegistered extends Error {
|
|
|
577
569
|
}
|
|
578
570
|
}
|
|
579
571
|
|
|
580
|
-
var index$
|
|
572
|
+
var index$3 = /*#__PURE__*/Object.freeze({
|
|
581
573
|
__proto__: null,
|
|
582
574
|
CommandAlreadyRegistered: CommandAlreadyRegistered,
|
|
583
575
|
CommandNotFound: CommandNotFound,
|
|
@@ -585,7 +577,7 @@ ControllerAlreadyRegistered: ControllerAlreadyRegistered,
|
|
|
585
577
|
ForceMethod: ForceMethod
|
|
586
578
|
});
|
|
587
579
|
|
|
588
|
-
var index$
|
|
580
|
+
var index$2 = /*#__PURE__*/Object.freeze({
|
|
589
581
|
__proto__: null,
|
|
590
582
|
Logger: Logger
|
|
591
583
|
});
|
|
@@ -952,6 +944,36 @@ class Internal extends Commands {
|
|
|
952
944
|
}
|
|
953
945
|
}
|
|
954
946
|
|
|
947
|
+
/**
|
|
948
|
+
* @author: Leonid Vinikov <leonidvinikov@gmail.com>
|
|
949
|
+
*/
|
|
950
|
+
function initialize(config) {
|
|
951
|
+
__ZEN_MANAGERS__.commands = new Commands();
|
|
952
|
+
__ZEN_MANAGERS__.controllers = new Controllers();
|
|
953
|
+
__ZEN_MANAGERS__.data = new Data(config);
|
|
954
|
+
__ZEN_MANAGERS__.internal = new Internal();
|
|
955
|
+
}
|
|
956
|
+
function destroy() {
|
|
957
|
+
__ZEN_MANAGERS__.commands = {};
|
|
958
|
+
__ZEN_MANAGERS__.controllers = {};
|
|
959
|
+
__ZEN_MANAGERS__.data = {};
|
|
960
|
+
__ZEN_MANAGERS__.internal = {};
|
|
961
|
+
}
|
|
962
|
+
const controllers = __ZEN_MANAGERS__.controllers;
|
|
963
|
+
const commands = __ZEN_MANAGERS__.commands;
|
|
964
|
+
const data = __ZEN_MANAGERS__.data;
|
|
965
|
+
const internal = __ZEN_MANAGERS__.internal;
|
|
966
|
+
|
|
967
|
+
var index$1 = /*#__PURE__*/Object.freeze({
|
|
968
|
+
__proto__: null,
|
|
969
|
+
commands: commands,
|
|
970
|
+
controllers: controllers,
|
|
971
|
+
data: data,
|
|
972
|
+
destroy: destroy,
|
|
973
|
+
initialize: initialize,
|
|
974
|
+
internal: internal
|
|
975
|
+
});
|
|
976
|
+
|
|
955
977
|
/**
|
|
956
978
|
* @author: Leonid Vinikov <leonidvinikov@gmail.com>
|
|
957
979
|
*/
|
|
@@ -970,12 +992,12 @@ Internal: Internal
|
|
|
970
992
|
|
|
971
993
|
var exported = /*#__PURE__*/Object.freeze({
|
|
972
994
|
__proto__: null,
|
|
973
|
-
commandBases: index$
|
|
974
|
-
core: index$
|
|
975
|
-
errors: index$
|
|
995
|
+
commandBases: index$5,
|
|
996
|
+
core: index$4,
|
|
997
|
+
errors: index$3,
|
|
976
998
|
managerBases: index,
|
|
977
|
-
managers: index$
|
|
978
|
-
modules: index$
|
|
999
|
+
managers: index$1,
|
|
1000
|
+
modules: index$2,
|
|
979
1001
|
utils: index$6
|
|
980
1002
|
});
|
|
981
1003
|
|
|
@@ -1066,27 +1088,22 @@ const CoreAPI = {
|
|
|
1066
1088
|
initialize: configuration => {
|
|
1067
1089
|
errorInitTwice();
|
|
1068
1090
|
config = configuration || config;
|
|
1069
|
-
|
|
1070
|
-
controllers = new Controllers();
|
|
1071
|
-
data = new Data(config);
|
|
1072
|
-
internal = new Internal();
|
|
1091
|
+
initialize(config);
|
|
1073
1092
|
isInitialized = true;
|
|
1074
1093
|
afterInitializeCallbacks.forEach(callback => callback());
|
|
1075
1094
|
},
|
|
1076
1095
|
destroy: () => {
|
|
1096
|
+
destroy();
|
|
1077
1097
|
isInitialized = false;
|
|
1078
|
-
commands = {};
|
|
1079
|
-
controllers = {};
|
|
1080
|
-
data = {};
|
|
1081
|
-
internal = {};
|
|
1082
1098
|
},
|
|
1083
1099
|
onAfterInitialize: callback => {
|
|
1084
1100
|
afterInitializeCallbacks.push(callback);
|
|
1085
1101
|
},
|
|
1086
1102
|
config,
|
|
1087
|
-
...exported
|
|
1103
|
+
...exported,
|
|
1104
|
+
managers: typeof __ZEN_MANAGERS__ !== 'undefined' ? __ZEN_MANAGERS__ : undefined
|
|
1088
1105
|
};
|
|
1089
1106
|
// TODO: Make it available only for development.
|
|
1090
1107
|
if (!globalThis?.ZenCore) globalThis.ZenCore = CoreAPI;
|
|
1091
1108
|
|
|
1092
|
-
export { index$
|
|
1109
|
+
export { index$5 as commandBases, index$4 as core, CoreAPI as default, index$3 as errors, index as managerBases, index$1 as managers, index$2 as modules, index$6 as utils };
|
package/dist/es/zenflux-core.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class t extends Error{constructor(t,e){super(`ForeMethod implementation: at '${t}' method: '${e}'`)}}class e extends Error{constructor(t,e){super(`ForeMethod implementation: at '${t.getName()}' method: '${e}'`)}}let r=0;class s{virtualId=0;static getName(){throw new t("ObjectBase","getName")}constructor(){this.virtualId=r,r++}getName(){return this.constructor.getName()}}
|
|
1
|
+
"undefined"!=typeof __ZEN_MANAGERS__&&__ZEN_MANAGERS__||(globalThis.__ZEN_MANAGERS__={});class t extends Error{constructor(t,e){super(`ForeMethod implementation: at '${t}' method: '${e}'`)}}class e extends Error{constructor(t,e){super(`ForeMethod implementation: at '${t.getName()}' method: '${e}'`)}}let r=0;class s{virtualId=0;static getName(){throw new t("ObjectBase","getName")}constructor(){this.virtualId=r,r++}getName(){return this.constructor.getName()}}
|
|
2
2
|
/**
|
|
3
3
|
* Function getCircularReplacer() : Reduce circular references.
|
|
4
4
|
*
|
|
@@ -9,4 +9,4 @@ const n=()=>{const t=new WeakSet;return(e,r)=>{if("object"==typeof r&&null!==r){
|
|
|
9
9
|
* Function hexColorDelta() : Return color difference in ratio decimal point.
|
|
10
10
|
*
|
|
11
11
|
* @copyright http://jsfiddle.net/96sME/
|
|
12
|
-
*/var a=Object.freeze({__proto__:null,getCircularReplacer:n,hexColorDelta:o});class i{static wrappers={};static wrapperDepth=0;static sharedData={};static colorsInUse=[];defaultStyle;color;outputHandler;args={};name;state=!1;static getName(){return"Core/Modules/Logger"}static reset(){i.wrappers={},i.wrapperDepth=0,i.colorsInUse=[],i.sharedData={}}static createCustomWrapper(t,e){i.wrappers[t]||(i.wrappers[t.name]=[]),i.wrappers[t.name].push({classType:t,callback:e})}static getCallerName(){const t=Error(),e=t.stack?t.stack.split("\n")[3].trim():"_UNKNOWN_CALLER_NAME_";return e.startsWith("at new")?"constructor":e.split(".")[1].split(" ")[0]}static getFunctionView(t){let e="anonymous function()";return"string"!=typeof t&&0!==t.name.length&&(e=t.name.split(" ")[1]+"()"),e}constructor(t,e=!1,r={}){"off"!==globalThis.process?.env.flow_modules_logger&&(this.state=e,this.args=r,this.name="",this.name="string"==typeof t?t:t.constructor.name,e&&this.initialize())}initialize(){this.args.sameColor?(i.sharedData[this.name]||(i.sharedData[this.name]=this.getRandomColor()),this.color=i.sharedData[this.name]):(this.color=this.getRandomColor(),i.colorsInUse.push(this.color)),this.outputHandler=console.log,this.defaultStyle=["color: grey;font-size:7px","display: block","color: "+this.color,"color: grey","font-weight: bold","color: #607D8B","font-size: 16px;color: red;font-weight:800"]}setOutputHandler(t){this.outputHandler=t}useWrapper(t,e=!0){if(!t||"object"!=typeof t||Array.isArray(t))return t;i.wrapperDepth++;let r={...t};return Object.values(i.wrappers).forEach((([e])=>{t instanceof e.classType&&(r=e.callback(t)||r)})),4>i.wrapperDepth?(e&&r&&Object.entries(r).forEach((([t,e])=>{r[t]=this.useWrapper(e,!0)})),i.wrapperDepth--,r):(i.wrapperDepth--,r)}startEmpty(t=""){this.state&&this.printFunctionNotify("se",i.getCallerName(),t)}startWith(t){if(!this.state)return;t=Object.assign({},t);const e="se",r=i.getCallerName();if("string"==typeof t)this.printInLineString(e,r,t);else if(1===Object.keys(t).length){const s=Object.keys(t)[0];let n=Object.values(t)[0];"object"==typeof n?this.printNextLineObject(e,r,s,n||{}):"function"==typeof n?this.printInLineFunction(e,r,s,n):this.printInLineElement(e,r,s,n)}else this.printMultiLineObject(e,r,t)}object(t={},e=""){if(!this.state)return;const r=i.getCallerName();t=Object.create(t);for(let s in t)"object"==typeof t[s]&&(t[s]=JSON.stringify(this.useWrapper(t[s]),n())),this.out.apply(this,[`%c(ob)-> %c%c${this.name}%c::%c${r}%c() [${e}] ->> ${s}: '${t[s]}'%c`].concat(this.defaultStyle))}debug(t){this.state&&this.printFunctionNotify("db",i.getCallerName(),t)}drop(t,e){if(!this.state)return;const r=i.getCallerName();for(let e in t)this.out.apply(this,[`%c(dr)-> %c%c${this.name}%c::%c${r}%c() ->> corresponding ${e}: '${t[e]}' RESULT: %c↓`].concat(this.defaultStyle));this.out(e)}throw(t,e="null",r={}){throw this.printFunctionNotify("tw",i.getCallerName(),t),r&&this.printNextLineObject("tw",i.getCallerName(),e,r),Error().stack}clone(){return Object.assign(Object.create(Object.getPrototypeOf(this)),this)}printFunctionNotify(t,e,r){this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c() ${r}%c`].concat(this.defaultStyle))}printInLineElement(t,e,r,s){this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c() ->> ${r}: '${s}'%c`].concat(this.defaultStyle))}printInLineFunction(t,e,r,s){s=i.getFunctionView(s),this.printInLineElement(t,e,r,s)}printInLineString(t,e,r){this.printInLineElement(t,e,"(string)",r)}printNextLineObject(t,e,r,s){s=this.useWrapper(s),this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c() ->> ${r} %c↓`].concat(this.defaultStyle)),this.out(s)}printMultiLineObject(t,e,r){this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c(${Object.keys(r).join(", ")}) %c↓`].concat(this.defaultStyle));for(let t in r){let e=r[t];"object"==typeof e?e=JSON.stringify(this.useWrapper(e),n()):"function"==typeof r[t]&&(e=i.getFunctionView(e)),this.out.call(this,"%c"+t+": `"+this.useWrapper(e)+"`","color: #a3a3a3")}}getRandomColor(){let t="#";for(let e=0;6>e;e++)t+="0123456789ABCDEF"[Math.floor(16*Math.random())];return i.colorsInUse.some((e=>o(t,e)>=.8))?this.getRandomColor():t}out(...t){this.outputHandler.apply(this,t)}}class c extends s{args={};options={};logger;constructor(t={},e={}){super();const r=this.constructor.getName();this.logger=new i(r,!0,{sameColor:!0}),this.logger.startWith({args:t,options:e}),this.initialize(t,e)}initialize(t,e){this.args=t,this.options=e}apply(t=this.args,r=this.options){throw new e(this,"apply")}async run(){this.onBeforeApply&&this.onBeforeApply();const t=await this.apply(this.args,this.options);return this.onAfterApply&&this.onAfterApply(),t}getArgs(){return this.args}getOptions(){return this.options}}let l=Object.assign({}),h=Object.assign({}),u=Object.assign({}),p=Object.assign({});var g=Object.freeze({__proto__:null,get commands(){return l},get controllers(){return h},get data(){return u},get internal(){return p}});var m=Object.freeze({__proto__:null,CommandBase:c,CommandData:class extends c{static getName(){return"Core/CommandBases/CommandData"}getEndpoint(){throw new e(this,"getEndpoint")}apply(t=this.args,e=this.options){const r=this.applyEndpointFormat(this.getEndpoint(),t);return u.getClient().fetch(r,u.currentHttpMethod,t||null)}applyEndpointFormat(t,e={}){return t.includes("{")&&(t=t.split("/").map((t=>{const r=t.match("\\{(.*?)\\}");return r?.length&&void 0!==e[r[1]]?e[r[1]]:t})).join("/")),t}},CommandInternal:class extends c{static getName(){return"Core/CommandBases/CommandInternal"}},CommandPublic:class extends c{static getName(){return"Core/CommandBases/CommandPublic"}}});var d=Object.freeze({__proto__:null,Controller:class extends s{commands;data;internal;static getName(){return"Core/Core/Controller"}constructor(){super(),this.initialize()}initialize(){this.register(),this.setupHooks&&this.setupHooks()}register(){this.commands=l.register(this.getCommands(),this),this.data=u.register(this.getData(),this),this.internal=p.register(this.getInternal(),this)}getCommands(){return{}}getData(){return{}}getInternal(){return{}}},ObjectBase:s});class f extends Error{constructor(t){super(`Command: '${t.getName()}' is already registered`)}}class C extends Error{constructor(t){super(`Command: '${t}' is not found`)}}class y extends Error{constructor(t){super(`Controller: '${t.getName()}' is already registered`)}}var b,N=Object.freeze({__proto__:null,CommandAlreadyRegistered:f,CommandNotFound:C,ControllerAlreadyRegistered:y,ForceMethod:e}),w=Object.freeze({__proto__:null,Logger:i});class O extends s{static trace=[];current={};currentArgs={};trace=[];commands={};onBeforeHooks={};onBeforeUIHooks={};onAfterHooks={};onAfterOnceHooks={};onAfterUIHooks={};onAfterAffectHooks={};logger;static getName(){return"Core/Managers/Commands"}static async runCallbacks(t,e={},r={}){const s=t?.length||0;for(let n=0;s>n;++n){const s=!0===r.pop?t.pop():t[n];if(!s)throw Error("Callback is not defined.");await s(e,r)}}static hookCommand(t,e,r){t[e]||(t[e]=[]),t[e].push(r)}constructor(){super(),this.logger=new i(this.getName(),!0),this.logger.startEmpty()}async run(t,e={},r={}){"string"==typeof t&&(t=this.getCommandInstance(t,e,r)),this.attachCurrent(t,e);const s=await this.runInstance(t,e,r);return this.detachCurrent(t),s}register(t,e){const r={};return Object.values(t).forEach((t=>{const e=t.getName();if(this.commands[e])throw new f(t);this.commands[e]=t,r[e]=t})),r}getAll(){return this.commands}getByName(t){return this.commands[t]}getLogger(){return this.logger}getCommandInstance(t,e={},r={}){const s=this.commands[t];if(!s)throw new C(t);return new s(e,r)}onBefore(t,e){O.hookCommand(this.onBeforeHooks,t,e)}onBeforeUI(t,e){O.hookCommand(this.onBeforeUIHooks,t,e)}onAfter(t,e){O.hookCommand(this.onAfterHooks,t,e)}onAfterUI(t,e){O.hookCommand(this.onAfterUIHooks,t,e)}onAfterOnce(t,e){O.hookCommand(this.onAfterOnceHooks,t,e)}onAfterAffect(t,e){O.hookCommand(this.onAfterAffectHooks,t,e)}onBeforeRun(t,e={},r={}){if(this.onBeforeHooks[t.getName()]){this.onBeforeHooks[t.getName()].forEach((t=>t(e,r)))}if(this.onBeforeUIHooks[t.getName()]){this.onBeforeUIHooks[t.getName()].forEach((t=>t(e,r)))}}async runInstance(t,e={},r={}){let s=null;return Object.keys(e).length?(this.logger.startWith({command:t.getName(),options:r,CommandArgs:"->"}),this.logger.debug("CommandArgs:"),this.logger.object(e)):this.logger.startWith({command:t.getName(),options:r,args:e}),this.onBeforeRun(t,e,r),s=await t.run(),await this.onAfterRun(t,e,r,s),s}async onAfterRun(t,e,r,s){return r=Object.assign({},r),this.onAfterAffectHooks[t.getName()]&&(this.onAfterAffectHooks[t.getName()].forEach((t=>{e.result=s,s=this.run(""+t,e,r)})),s=await s),this.onAfterHooks&&(e.result=s,await O.runCallbacks(Object.assign([],this.onAfterHooks[t.getName()]),e,r)),this.onAfterOnceHooks&&await O.runCallbacks(this.onAfterOnceHooks[t.getName()],e,{...r,pop:!0}),this.onAfterUIHooks&&O.runCallbacks(Object.assign([],this.onAfterUIHooks[t.getName()]),e,r),s}attachCurrent(t,e={}){this.current[t.getName()]=t,this.currentArgs[t.getName()]=e,this.trace.push(t.getName()),O.trace.push(t.getName())}detachCurrent(t){delete this.current[t.getName()],delete this.currentArgs[t.getName()],O.trace.pop(),this.trace.pop()}}class A extends s{controllers={};static getName(){return"Core/Managers/Controllers"}get(t){return this.controllers[t]}getAll(){return this.controllers}register(t){if(this.controllers[t.getName()])throw new y(t);return this.controllers[t.getName()]=t,t}}!function(t){t.DELETE="DELETE",t.GET="GET",t.OPTIONS="OPTIONS",t.PATCH="PATCH",t.POST="POST",t.PUT="PUT",t.__EMPTY__=""}(b||(b={}));class j extends s{logger;apiBaseUrl;static getName(){return"Core/Clients/Http"}constructor(t="http://localhost"){super(),this.logger=new i(j.getName(),!0),this.logger.startWith({apiBaseUrl:t}),this.apiBaseUrl=t+"/"}async fetch(t,e,r=null){this.logger.startWith({path:t,method:e,body:r});const s={credentials:"include"},n={};[b.POST,b.PUT,b.PATCH].includes(e)?(Object.assign(n,{"Content-Type":"application/json"}),Object.assign(s,{method:e,headers:n,body:JSON.stringify(r)})):Object.assign(s,{headers:n});const o=await globalThis.fetch(this.apiBaseUrl+t,s);let a;try{a=await o.json()}catch(t){return console.error(t),!1}if(a?.error&&a?.global&&a?.message)throw Error(a.message);return this.logger.drop({path:t},a),a}}class k extends O{static client;currentHttpMethod;static getName(){return"Core/Managers/Data"}constructor(t){super(),k.client=new j(t.baseURL)}getClient(){return k.client}get(t,e={},r={}){return this.currentHttpMethod=b.GET,super.run(t,e,r)}update(t,e={},r={}){return this.currentHttpMethod=b.PATCH,super.run(t,e,r)}delete(t,e={},r={}){return this.currentHttpMethod=b.DELETE,super.run(t,e,r)}create(t,e={},r={}){return this.currentHttpMethod=b.POST,super.run(t,e,r)}async runInstance(t,e={},r={}){if(!this.currentHttpMethod)throw Error('Cannot run directly use one of the http methods: "get", "update", "delete, "create');const s={type:this.currentHttpMethod,args:{query:{},data:{}}};return b.GET===this.currentHttpMethod?s.args.query=e:s.args.data=e,e.result=await super.runInstance(t,s,r),this.currentHttpMethod=b.__EMPTY__,e.result}}class E extends O{static getName(){return"Core/Managers/Internal"}}var H=Object.freeze({__proto__:null,Commands:O,Controllers:A,Data:k,Internal:E}),_=Object.freeze({__proto__:null,commandBases:m,core:d,errors:N,managerBases:H,managers:g,modules:w,utils:a}),I="0.0.0-abc.7";let $=!1;function B(){if($)throw Error("ZenCore is already initialized.")}B();let T={version:I};const M=[],U={initialize:t=>{B(),T=t||T,l=new O,h=new A,u=new k(T),p=new E,$=!0,M.forEach((t=>t()))},destroy:()=>{$=!1,l={},h={},u={},p={}},onAfterInitialize:t=>{M.push(t)},config:T,..._};globalThis?.ZenCore||(globalThis.ZenCore=U);export{m as commandBases,d as core,U as default,N as errors,H as managerBases,g as managers,w as modules,a as utils};
|
|
12
|
+
*/var a=Object.freeze({__proto__:null,getCircularReplacer:n,hexColorDelta:o});class i{static wrappers={};static wrapperDepth=0;static sharedData={};static colorsInUse=[];defaultStyle;color;outputHandler;args={};name;state=!1;static getName(){return"Core/Modules/Logger"}static reset(){i.wrappers={},i.wrapperDepth=0,i.colorsInUse=[],i.sharedData={}}static createCustomWrapper(t,e){i.wrappers[t]||(i.wrappers[t.name]=[]),i.wrappers[t.name].push({classType:t,callback:e})}static getCallerName(){const t=Error(),e=t.stack?t.stack.split("\n")[3].trim():"_UNKNOWN_CALLER_NAME_";return e.startsWith("at new")?"constructor":e.split(".")[1].split(" ")[0]}static getFunctionView(t){let e="anonymous function()";return"string"!=typeof t&&0!==t.name.length&&(e=t.name.split(" ")[1]+"()"),e}constructor(t,e=!1,r={}){"off"!==globalThis.process?.env.flow_modules_logger&&(this.state=e,this.args=r,this.name="",this.name="string"==typeof t?t:t.constructor.name,e&&this.initialize())}initialize(){this.args.sameColor?(i.sharedData[this.name]||(i.sharedData[this.name]=this.getRandomColor()),this.color=i.sharedData[this.name]):(this.color=this.getRandomColor(),i.colorsInUse.push(this.color)),this.outputHandler=console.log,this.defaultStyle=["color: grey;font-size:7px","display: block","color: "+this.color,"color: grey","font-weight: bold","color: #607D8B","font-size: 16px;color: red;font-weight:800"]}setOutputHandler(t){this.outputHandler=t}useWrapper(t,e=!0){if(!t||"object"!=typeof t||Array.isArray(t))return t;i.wrapperDepth++;let r={...t};return Object.values(i.wrappers).forEach((([e])=>{t instanceof e.classType&&(r=e.callback(t)||r)})),4>i.wrapperDepth?(e&&r&&Object.entries(r).forEach((([t,e])=>{r[t]=this.useWrapper(e,!0)})),i.wrapperDepth--,r):(i.wrapperDepth--,r)}startEmpty(t=""){this.state&&this.printFunctionNotify("se",i.getCallerName(),t)}startWith(t){if(!this.state)return;t=Object.assign({},t);const e="se",r=i.getCallerName();if("string"==typeof t)this.printInLineString(e,r,t);else if(1===Object.keys(t).length){const s=Object.keys(t)[0];let n=Object.values(t)[0];"object"==typeof n?this.printNextLineObject(e,r,s,n||{}):"function"==typeof n?this.printInLineFunction(e,r,s,n):this.printInLineElement(e,r,s,n)}else this.printMultiLineObject(e,r,t)}object(t={},e=""){if(!this.state)return;const r=i.getCallerName();t=Object.create(t);for(let s in t)"object"==typeof t[s]&&(t[s]=JSON.stringify(this.useWrapper(t[s]),n())),this.out.apply(this,[`%c(ob)-> %c%c${this.name}%c::%c${r}%c() [${e}] ->> ${s}: '${t[s]}'%c`].concat(this.defaultStyle))}debug(t){this.state&&this.printFunctionNotify("db",i.getCallerName(),t)}drop(t,e){if(!this.state)return;const r=i.getCallerName();for(let e in t)this.out.apply(this,[`%c(dr)-> %c%c${this.name}%c::%c${r}%c() ->> corresponding ${e}: '${t[e]}' RESULT: %c↓`].concat(this.defaultStyle));this.out(e)}throw(t,e="null",r={}){throw this.printFunctionNotify("tw",i.getCallerName(),t),r&&this.printNextLineObject("tw",i.getCallerName(),e,r),Error().stack}clone(){return Object.assign(Object.create(Object.getPrototypeOf(this)),this)}printFunctionNotify(t,e,r){this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c() ${r}%c`].concat(this.defaultStyle))}printInLineElement(t,e,r,s){this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c() ->> ${r}: '${s}'%c`].concat(this.defaultStyle))}printInLineFunction(t,e,r,s){s=i.getFunctionView(s),this.printInLineElement(t,e,r,s)}printInLineString(t,e,r){this.printInLineElement(t,e,"(string)",r)}printNextLineObject(t,e,r,s){s=this.useWrapper(s),this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c() ->> ${r} %c↓`].concat(this.defaultStyle)),this.out(s)}printMultiLineObject(t,e,r){this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c(${Object.keys(r).join(", ")}) %c↓`].concat(this.defaultStyle));for(let t in r){let e=r[t];"object"==typeof e?e=JSON.stringify(this.useWrapper(e),n()):"function"==typeof r[t]&&(e=i.getFunctionView(e)),this.out.call(this,"%c"+t+": `"+this.useWrapper(e)+"`","color: #a3a3a3")}}getRandomColor(){let t="#";for(let e=0;6>e;e++)t+="0123456789ABCDEF"[Math.floor(16*Math.random())];return i.colorsInUse.some((e=>o(t,e)>=.8))?this.getRandomColor():t}out(...t){this.outputHandler.apply(this,t)}}class c extends s{args={};options={};logger;constructor(t={},e={}){super();const r=this.constructor.getName();this.logger=new i(r,!0,{sameColor:!0}),this.logger.startWith({args:t,options:e}),this.initialize(t,e)}initialize(t,e){this.args=t,this.options=e}apply(t=this.args,r=this.options){throw new e(this,"apply")}async run(){this.onBeforeApply&&this.onBeforeApply();const t=await this.apply(this.args,this.options);return this.onAfterApply&&this.onAfterApply(),t}getArgs(){return this.args}getOptions(){return this.options}}var l=Object.freeze({__proto__:null,CommandBase:c,CommandData:class extends c{static getName(){return"Core/CommandBases/CommandData"}getEndpoint(){throw new e(this,"getEndpoint")}apply(t=this.args,e=this.options){const r=this.applyEndpointFormat(this.getEndpoint(),t);return __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 c{static getName(){return"Core/CommandBases/CommandInternal"}},CommandPublic:class extends c{static getName(){return"Core/CommandBases/CommandPublic"}}});var h=Object.freeze({__proto__:null,Controller:class extends s{commands;data;internal;static getName(){return"Core/Core/Controller"}constructor(){super(),this.initialize()}initialize(){this.register(),this.setupHooks&&this.setupHooks()}register(){this.commands=__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:s});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:e}),_=Object.freeze({__proto__:null,Logger:i});class f extends s{static trace=[];current={};currentArgs={};trace=[];commands={};onBeforeHooks={};onBeforeUIHooks={};onAfterHooks={};onAfterOnceHooks={};onAfterUIHooks={};onAfterAffectHooks={};logger;static getName(){return"Core/Managers/Commands"}static async runCallbacks(t,e={},r={}){const s=t?.length||0;for(let n=0;s>n;++n){const s=!0===r.pop?t.pop():t[n];if(!s)throw Error("Callback is not defined.");await s(e,r)}}static hookCommand(t,e,r){t[e]||(t[e]=[]),t[e].push(r)}constructor(){super(),this.logger=new i(this.getName(),!0),this.logger.startEmpty()}async run(t,e={},r={}){"string"==typeof t&&(t=this.getCommandInstance(t,e,r)),this.attachCurrent(t,e);const s=await this.runInstance(t,e,r);return this.detachCurrent(t),s}register(t,e){const r={};return Object.values(t).forEach((t=>{const e=t.getName();if(this.commands[e])throw new 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){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 s{controllers={};static getName(){return"Core/Managers/Controllers"}get(t){return this.controllers[t]}getAll(){return this.controllers}register(t){if(this.controllers[t.getName()])throw new 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 A extends s{logger;apiBaseUrl;static getName(){return"Core/Clients/Http"}constructor(t="http://localhost"){super(),this.logger=new i(A.getName(),!0),this.logger.startWith({apiBaseUrl:t}),this.apiBaseUrl=t+"/"}async fetch(t,e,r=null){this.logger.startWith({path:t,method:e,body:r});const s={credentials:"include"},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 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=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 C extends f{static getName(){return"Core/Managers/Internal"}}function y(t){__ZEN_MANAGERS__.commands=new f,__ZEN_MANAGERS__.controllers=new N,__ZEN_MANAGERS__.data=new E(t),__ZEN_MANAGERS__.internal=new C}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 H=Object.freeze({__proto__:null,commands:O,controllers:w,data:M,destroy:b,initialize:y,internal:k}),j=Object.freeze({__proto__:null,Commands:f,Controllers:N,Data:E,Internal:C}),I=Object.freeze({__proto__:null,commandBases:l,core:h,errors:d,managerBases:j,managers:H,modules:_,utils:a}),S="0.0.0-abc.7";let R=!1;function $(){if(R)throw Error("ZenCore is already initialized.")}$();let B={version:S};const T=[],G={initialize:t=>{$(),B=t||B,y(B),R=!0,T.forEach((t=>t()))},destroy:()=>{b(),R=!1},onAfterInitialize:t=>{T.push(t)},config:B,...I,managers:"undefined"!=typeof __ZEN_MANAGERS__?__ZEN_MANAGERS__:void 0};globalThis?.ZenCore||(globalThis.ZenCore=G);export{l as commandBases,h as core,G as default,d as errors,j as managerBases,H as managers,_ as modules,a as utils};
|
package/dist/umd/zenflux-core.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["@zenflux/core"]={})}(this,(function(t){"use strict";class e extends Error{constructor(t,e){super(`ForeMethod implementation: at '${t}' method: '${e}'`)}}class r extends Error{constructor(t,e){super(`ForeMethod implementation: at '${t.getName()}' method: '${e}'`)}}let s=0;class n{virtualId=0;static getName(){throw new e("ObjectBase","getName")}constructor(){this.virtualId=s,s++}getName(){return this.constructor.getName()}}
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["@zenflux/core"]={})}(this,(function(t){"use strict";"undefined"!=typeof __ZEN_MANAGERS__&&__ZEN_MANAGERS__||(globalThis.__ZEN_MANAGERS__={});class e extends Error{constructor(t,e){super(`ForeMethod implementation: at '${t}' method: '${e}'`)}}class r extends Error{constructor(t,e){super(`ForeMethod implementation: at '${t.getName()}' method: '${e}'`)}}let s=0;class n{virtualId=0;static getName(){throw new e("ObjectBase","getName")}constructor(){this.virtualId=s,s++}getName(){return this.constructor.getName()}}
|
|
2
2
|
/**
|
|
3
3
|
* Function getCircularReplacer() : Reduce circular references.
|
|
4
4
|
*
|
|
@@ -9,4 +9,4 @@ const o=()=>{const t=new WeakSet;return(e,r)=>{if("object"==typeof r&&null!==r){
|
|
|
9
9
|
* Function hexColorDelta() : Return color difference in ratio decimal point.
|
|
10
10
|
*
|
|
11
11
|
* @copyright http://jsfiddle.net/96sME/
|
|
12
|
-
*/var i=Object.freeze({__proto__:null,getCircularReplacer:o,hexColorDelta:a});class c{static wrappers={};static wrapperDepth=0;static sharedData={};static colorsInUse=[];defaultStyle;color;outputHandler;args={};name;state=!1;static getName(){return"Core/Modules/Logger"}static reset(){c.wrappers={},c.wrapperDepth=0,c.colorsInUse=[],c.sharedData={}}static createCustomWrapper(t,e){c.wrappers[t]||(c.wrappers[t.name]=[]),c.wrappers[t.name].push({classType:t,callback:e})}static getCallerName(){const t=Error(),e=t.stack?t.stack.split("\n")[3].trim():"_UNKNOWN_CALLER_NAME_";return e.startsWith("at new")?"constructor":e.split(".")[1].split(" ")[0]}static getFunctionView(t){let e="anonymous function()";return"string"!=typeof t&&0!==t.name.length&&(e=t.name.split(" ")[1]+"()"),e}constructor(t,e=!1,r={}){"off"!==globalThis.process?.env.flow_modules_logger&&(this.state=e,this.args=r,this.name="",this.name="string"==typeof t?t:t.constructor.name,e&&this.initialize())}initialize(){this.args.sameColor?(c.sharedData[this.name]||(c.sharedData[this.name]=this.getRandomColor()),this.color=c.sharedData[this.name]):(this.color=this.getRandomColor(),c.colorsInUse.push(this.color)),this.outputHandler=console.log,this.defaultStyle=["color: grey;font-size:7px","display: block","color: "+this.color,"color: grey","font-weight: bold","color: #607D8B","font-size: 16px;color: red;font-weight:800"]}setOutputHandler(t){this.outputHandler=t}useWrapper(t,e=!0){if(!t||"object"!=typeof t||Array.isArray(t))return t;c.wrapperDepth++;let r={...t};return Object.values(c.wrappers).forEach((([e])=>{t instanceof e.classType&&(r=e.callback(t)||r)})),4>c.wrapperDepth?(e&&r&&Object.entries(r).forEach((([t,e])=>{r[t]=this.useWrapper(e,!0)})),c.wrapperDepth--,r):(c.wrapperDepth--,r)}startEmpty(t=""){this.state&&this.printFunctionNotify("se",c.getCallerName(),t)}startWith(t){if(!this.state)return;t=Object.assign({},t);const e="se",r=c.getCallerName();if("string"==typeof t)this.printInLineString(e,r,t);else if(1===Object.keys(t).length){const s=Object.keys(t)[0];let n=Object.values(t)[0];"object"==typeof n?this.printNextLineObject(e,r,s,n||{}):"function"==typeof n?this.printInLineFunction(e,r,s,n):this.printInLineElement(e,r,s,n)}else this.printMultiLineObject(e,r,t)}object(t={},e=""){if(!this.state)return;const r=c.getCallerName();t=Object.create(t);for(let s in t)"object"==typeof t[s]&&(t[s]=JSON.stringify(this.useWrapper(t[s]),o())),this.out.apply(this,[`%c(ob)-> %c%c${this.name}%c::%c${r}%c() [${e}] ->> ${s}: '${t[s]}'%c`].concat(this.defaultStyle))}debug(t){this.state&&this.printFunctionNotify("db",c.getCallerName(),t)}drop(t,e){if(!this.state)return;const r=c.getCallerName();for(let e in t)this.out.apply(this,[`%c(dr)-> %c%c${this.name}%c::%c${r}%c() ->> corresponding ${e}: '${t[e]}' RESULT: %c↓`].concat(this.defaultStyle));this.out(e)}throw(t,e="null",r={}){throw this.printFunctionNotify("tw",c.getCallerName(),t),r&&this.printNextLineObject("tw",c.getCallerName(),e,r),Error().stack}clone(){return Object.assign(Object.create(Object.getPrototypeOf(this)),this)}printFunctionNotify(t,e,r){this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c() ${r}%c`].concat(this.defaultStyle))}printInLineElement(t,e,r,s){this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c() ->> ${r}: '${s}'%c`].concat(this.defaultStyle))}printInLineFunction(t,e,r,s){s=c.getFunctionView(s),this.printInLineElement(t,e,r,s)}printInLineString(t,e,r){this.printInLineElement(t,e,"(string)",r)}printNextLineObject(t,e,r,s){s=this.useWrapper(s),this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c() ->> ${r} %c↓`].concat(this.defaultStyle)),this.out(s)}printMultiLineObject(t,e,r){this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c(${Object.keys(r).join(", ")}) %c↓`].concat(this.defaultStyle));for(let t in r){let e=r[t];"object"==typeof e?e=JSON.stringify(this.useWrapper(e),o()):"function"==typeof r[t]&&(e=c.getFunctionView(e)),this.out.call(this,"%c"+t+": `"+this.useWrapper(e)+"`","color: #a3a3a3")}}getRandomColor(){let t="#";for(let e=0;6>e;e++)t+="0123456789ABCDEF"[Math.floor(16*Math.random())];return c.colorsInUse.some((e=>a(t,e)>=.8))?this.getRandomColor():t}out(...t){this.outputHandler.apply(this,t)}}class l extends n{args={};options={};logger;constructor(t={},e={}){super();const r=this.constructor.getName();this.logger=new c(r,!0,{sameColor:!0}),this.logger.startWith({args:t,options:e}),this.initialize(t,e)}initialize(t,e){this.args=t,this.options=e}apply(t=this.args,e=this.options){throw new r(this,"apply")}async run(){this.onBeforeApply&&this.onBeforeApply();const t=await this.apply(this.args,this.options);return this.onAfterApply&&this.onAfterApply(),t}getArgs(){return this.args}getOptions(){return this.options}}let h=Object.assign({}),u=Object.assign({}),p=Object.assign({}),g=Object.assign({});var m=Object.freeze({__proto__:null,get commands(){return h},get controllers(){return u},get data(){return p},get internal(){return g}});var d=Object.freeze({__proto__:null,CommandBase:l,CommandData:class extends l{static getName(){return"Core/CommandBases/CommandData"}getEndpoint(){throw new r(this,"getEndpoint")}apply(t=this.args,e=this.options){const r=this.applyEndpointFormat(this.getEndpoint(),t);return p.getClient().fetch(r,p.currentHttpMethod,t||null)}applyEndpointFormat(t,e={}){return t.includes("{")&&(t=t.split("/").map((t=>{const r=t.match("\\{(.*?)\\}");return r?.length&&void 0!==e[r[1]]?e[r[1]]:t})).join("/")),t}},CommandInternal:class extends l{static getName(){return"Core/CommandBases/CommandInternal"}},CommandPublic:class extends l{static getName(){return"Core/CommandBases/CommandPublic"}}});var f=Object.freeze({__proto__:null,Controller:class extends n{commands;data;internal;static getName(){return"Core/Core/Controller"}constructor(){super(),this.initialize()}initialize(){this.register(),this.setupHooks&&this.setupHooks()}register(){this.commands=h.register(this.getCommands(),this),this.data=p.register(this.getData(),this),this.internal=g.register(this.getInternal(),this)}getCommands(){return{}}getData(){return{}}getInternal(){return{}}},ObjectBase:n});class C extends Error{constructor(t){super(`Command: '${t.getName()}' is already registered`)}}class y extends Error{constructor(t){super(`Command: '${t}' is not found`)}}class b extends Error{constructor(t){super(`Controller: '${t.getName()}' is already registered`)}}var N,w=Object.freeze({__proto__:null,CommandAlreadyRegistered:C,CommandNotFound:y,ControllerAlreadyRegistered:b,ForceMethod:r}),O=Object.freeze({__proto__:null,Logger:c});class A extends n{static trace=[];current={};currentArgs={};trace=[];commands={};onBeforeHooks={};onBeforeUIHooks={};onAfterHooks={};onAfterOnceHooks={};onAfterUIHooks={};onAfterAffectHooks={};logger;static getName(){return"Core/Managers/Commands"}static async runCallbacks(t,e={},r={}){const s=t?.length||0;for(let n=0;s>n;++n){const s=!0===r.pop?t.pop():t[n];if(!s)throw Error("Callback is not defined.");await s(e,r)}}static hookCommand(t,e,r){t[e]||(t[e]=[]),t[e].push(r)}constructor(){super(),this.logger=new c(this.getName(),!0),this.logger.startEmpty()}async run(t,e={},r={}){"string"==typeof t&&(t=this.getCommandInstance(t,e,r)),this.attachCurrent(t,e);const s=await this.runInstance(t,e,r);return this.detachCurrent(t),s}register(t,e){const r={};return Object.values(t).forEach((t=>{const e=t.getName();if(this.commands[e])throw new C(t);this.commands[e]=t,r[e]=t})),r}getAll(){return this.commands}getByName(t){return this.commands[t]}getLogger(){return this.logger}getCommandInstance(t,e={},r={}){const s=this.commands[t];if(!s)throw new y(t);return new s(e,r)}onBefore(t,e){A.hookCommand(this.onBeforeHooks,t,e)}onBeforeUI(t,e){A.hookCommand(this.onBeforeUIHooks,t,e)}onAfter(t,e){A.hookCommand(this.onAfterHooks,t,e)}onAfterUI(t,e){A.hookCommand(this.onAfterUIHooks,t,e)}onAfterOnce(t,e){A.hookCommand(this.onAfterOnceHooks,t,e)}onAfterAffect(t,e){A.hookCommand(this.onAfterAffectHooks,t,e)}onBeforeRun(t,e={},r={}){if(this.onBeforeHooks[t.getName()]){this.onBeforeHooks[t.getName()].forEach((t=>t(e,r)))}if(this.onBeforeUIHooks[t.getName()]){this.onBeforeUIHooks[t.getName()].forEach((t=>t(e,r)))}}async runInstance(t,e={},r={}){let s=null;return Object.keys(e).length?(this.logger.startWith({command:t.getName(),options:r,CommandArgs:"->"}),this.logger.debug("CommandArgs:"),this.logger.object(e)):this.logger.startWith({command:t.getName(),options:r,args:e}),this.onBeforeRun(t,e,r),s=await t.run(),await this.onAfterRun(t,e,r,s),s}async onAfterRun(t,e,r,s){return r=Object.assign({},r),this.onAfterAffectHooks[t.getName()]&&(this.onAfterAffectHooks[t.getName()].forEach((t=>{e.result=s,s=this.run(""+t,e,r)})),s=await s),this.onAfterHooks&&(e.result=s,await A.runCallbacks(Object.assign([],this.onAfterHooks[t.getName()]),e,r)),this.onAfterOnceHooks&&await A.runCallbacks(this.onAfterOnceHooks[t.getName()],e,{...r,pop:!0}),this.onAfterUIHooks&&A.runCallbacks(Object.assign([],this.onAfterUIHooks[t.getName()]),e,r),s}attachCurrent(t,e={}){this.current[t.getName()]=t,this.currentArgs[t.getName()]=e,this.trace.push(t.getName()),A.trace.push(t.getName())}detachCurrent(t){delete this.current[t.getName()],delete this.currentArgs[t.getName()],A.trace.pop(),this.trace.pop()}}class j extends n{controllers={};static getName(){return"Core/Managers/Controllers"}get(t){return this.controllers[t]}getAll(){return this.controllers}register(t){if(this.controllers[t.getName()])throw new b(t);return this.controllers[t.getName()]=t,t}}!function(t){t.DELETE="DELETE",t.GET="GET",t.OPTIONS="OPTIONS",t.PATCH="PATCH",t.POST="POST",t.PUT="PUT",t.__EMPTY__=""}(N||(N={}));class k extends n{logger;apiBaseUrl;static getName(){return"Core/Clients/Http"}constructor(t="http://localhost"){super(),this.logger=new c(k.getName(),!0),this.logger.startWith({apiBaseUrl:t}),this.apiBaseUrl=t+"/"}async fetch(t,e,r=null){this.logger.startWith({path:t,method:e,body:r});const s={credentials:"include"},n={};[N.POST,N.PUT,N.PATCH].includes(e)?(Object.assign(n,{"Content-Type":"application/json"}),Object.assign(s,{method:e,headers:n,body:JSON.stringify(r)})):Object.assign(s,{headers:n});const o=await globalThis.fetch(this.apiBaseUrl+t,s);let a;try{a=await o.json()}catch(t){return console.error(t),!1}if(a?.error&&a?.global&&a?.message)throw Error(a.message);return this.logger.drop({path:t},a),a}}class E extends A{static client;currentHttpMethod;static getName(){return"Core/Managers/Data"}constructor(t){super(),E.client=new k(t.baseURL)}getClient(){return E.client}get(t,e={},r={}){return this.currentHttpMethod=N.GET,super.run(t,e,r)}update(t,e={},r={}){return this.currentHttpMethod=N.PATCH,super.run(t,e,r)}delete(t,e={},r={}){return this.currentHttpMethod=N.DELETE,super.run(t,e,r)}create(t,e={},r={}){return this.currentHttpMethod=N.POST,super.run(t,e,r)}async runInstance(t,e={},r={}){if(!this.currentHttpMethod)throw Error('Cannot run directly use one of the http methods: "get", "update", "delete, "create');const s={type:this.currentHttpMethod,args:{query:{},data:{}}};return N.GET===this.currentHttpMethod?s.args.query=e:s.args.data=e,e.result=await super.runInstance(t,s,r),this.currentHttpMethod=N.__EMPTY__,e.result}}class _ extends A{static getName(){return"Core/Managers/Internal"}}var H=Object.freeze({__proto__:null,Commands:A,Controllers:j,Data:E,Internal:_}),I=Object.freeze({__proto__:null,commandBases:d,core:f,errors:w,managerBases:H,managers:m,modules:O,utils:i}),$="0.0.0-abc.7";let T=!1;function B(){if(T)throw Error("ZenCore is already initialized.")}B();let M={version:$};const x=[],U={initialize:t=>{B(),M=t||M,h=new A,u=new j,p=new E(M),g=new _,T=!0,x.forEach((t=>t()))},destroy:()=>{T=!1,h={},u={},p={},g={}},onAfterInitialize:t=>{x.push(t)},config:M,...I};globalThis?.ZenCore||(globalThis.ZenCore=U),t.commandBases=d,t.core=f,t.default=U,t.errors=w,t.managerBases=H,t.managers=m,t.modules=O,t.utils=i,Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
12
|
+
*/var 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 y extends N{static client;currentHttpMethod;static getName(){return"Core/Managers/Data"}constructor(t){super(),y.client=new E(t.baseURL)}getClient(){return y.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 C extends N{static getName(){return"Core/Managers/Internal"}}function b(t){__ZEN_MANAGERS__.commands=new N,__ZEN_MANAGERS__.controllers=new A,__ZEN_MANAGERS__.data=new y(t),__ZEN_MANAGERS__.internal=new C}function w(){__ZEN_MANAGERS__.commands={},__ZEN_MANAGERS__.controllers={},__ZEN_MANAGERS__.data={},__ZEN_MANAGERS__.internal={}}const O=__ZEN_MANAGERS__.controllers,M=__ZEN_MANAGERS__.commands,k=__ZEN_MANAGERS__.data,j=__ZEN_MANAGERS__.internal;var H=Object.freeze({__proto__:null,commands:M,controllers:O,data:k,destroy:w,initialize:b,internal:j}),I=Object.freeze({__proto__:null,Commands:N,Controllers:A,Data:y,Internal:C}),S=Object.freeze({__proto__:null,commandBases:h,core:u,errors:_,managerBases:I,managers:H,modules:f,utils:i}),R="0.0.0-abc.7";let T=!1;function $(){if(T)throw Error("ZenCore is already initialized.")}$();let B={version:R};const G=[],x={initialize:t=>{$(),B=t||B,b(B),T=!0,G.forEach((t=>t()))},destroy:()=>{w(),T=!1},onAfterInitialize:t=>{G.push(t)},config:B,...S,managers:"undefined"!=typeof __ZEN_MANAGERS__?__ZEN_MANAGERS__:void 0};globalThis?.ZenCore||(globalThis.ZenCore=x),t.commandBases=h,t.core=u,t.default=x,t.errors=_,t.managerBases=I,t.managers=H,t.modules=f,t.utils=i,Object.defineProperty(t,"__esModule",{value:!0})}));
|
package/package.json
CHANGED
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
import { ForceMethod } from '../errors/force-method';
|
|
6
6
|
import { CommandBase } from './command-base';
|
|
7
7
|
|
|
8
|
-
import { data } from '../managers/';
|
|
9
|
-
|
|
10
8
|
export abstract class CommandData extends CommandBase {
|
|
11
9
|
static getName() {
|
|
12
10
|
return 'Core/CommandBases/CommandData';
|
|
@@ -28,8 +26,8 @@ export abstract class CommandData extends CommandBase {
|
|
|
28
26
|
apply( args = this.args, options = this.options ) {// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
29
27
|
const endpoint = this.applyEndpointFormat( this.getEndpoint(), args );
|
|
30
28
|
|
|
31
|
-
return data.getClient().fetch(
|
|
32
|
-
endpoint, data.currentHttpMethod, args || null
|
|
29
|
+
return __ZEN_MANAGERS__.data.getClient().fetch(
|
|
30
|
+
endpoint, __ZEN_MANAGERS__.data.currentHttpMethod, args || null
|
|
33
31
|
);
|
|
34
32
|
}
|
|
35
33
|
|
package/src/core/controller.ts
CHANGED
|
@@ -6,8 +6,6 @@ import ObjectBase from "./object-base";
|
|
|
6
6
|
|
|
7
7
|
import { CommandData, CommandInternal, CommandPublic } from "../command-bases";
|
|
8
8
|
|
|
9
|
-
import { commands, data, internal } from "../managers";
|
|
10
|
-
|
|
11
9
|
export abstract class Controller extends ObjectBase {
|
|
12
10
|
commands: { [ key: string ]: typeof CommandPublic };
|
|
13
11
|
data: { [ key: string ]: typeof CommandData };
|
|
@@ -30,13 +28,13 @@ export abstract class Controller extends ObjectBase {
|
|
|
30
28
|
}
|
|
31
29
|
|
|
32
30
|
register() {
|
|
33
|
-
this.commands = commands.register( this.getCommands(), this ) as
|
|
31
|
+
this.commands = __ZEN_MANAGERS__.commands.register( this.getCommands(), this ) as
|
|
34
32
|
{ [ key: string ]: typeof CommandPublic };
|
|
35
33
|
|
|
36
|
-
this.data = data.register( this.getData(), this ) as
|
|
34
|
+
this.data = __ZEN_MANAGERS__.data.register( this.getData(), this ) as
|
|
37
35
|
{ [ key: string ]: typeof CommandData };
|
|
38
36
|
|
|
39
|
-
this.internal = internal.register( this.getInternal(), this ) as
|
|
37
|
+
this.internal = __ZEN_MANAGERS__.internal.register( this.getInternal(), this ) as
|
|
40
38
|
{ [ key: string ]: typeof CommandInternal };
|
|
41
39
|
}
|
|
42
40
|
|
package/src/exports.ts
CHANGED
package/src/globals.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
if ( typeof __ZEN_MANAGERS__ === 'undefined' || ! __ZEN_MANAGERS__ ) {
|
|
2
|
+
// @ts-ignore
|
|
3
|
+
globalThis.__ZEN_MANAGERS__ = {};
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
import Commands from "./manager-bases/commands";
|
|
7
|
+
import Controllers from "./manager-bases/controllers";
|
|
8
|
+
import Data from "./manager-bases/data";
|
|
9
|
+
import Internal from "./manager-bases/internal";
|
|
10
|
+
|
|
11
|
+
declare global {
|
|
12
|
+
var ZenCore: any;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
declare global {
|
|
16
|
+
var __ZEN_MANAGERS__: {
|
|
17
|
+
commands: Commands;
|
|
18
|
+
controllers: Controllers;
|
|
19
|
+
data: Data;
|
|
20
|
+
internal: Internal;
|
|
21
|
+
}
|
|
22
|
+
}
|
package/src/index.ts
CHANGED
package/src/initializer.ts
CHANGED
|
@@ -4,9 +4,11 @@ import * as exported from './exports';
|
|
|
4
4
|
|
|
5
5
|
import { IAPIConfig } from "./interfaces/config";
|
|
6
6
|
|
|
7
|
+
import { destroy, initialize } from "./managers";
|
|
8
|
+
|
|
9
|
+
|
|
7
10
|
declare global {
|
|
8
11
|
var ZenCore: any;
|
|
9
|
-
var exported: any;
|
|
10
12
|
}
|
|
11
13
|
|
|
12
14
|
let isInitialized = false;
|
|
@@ -31,10 +33,7 @@ export const CoreAPI = {
|
|
|
31
33
|
|
|
32
34
|
config = configuration || config;
|
|
33
35
|
|
|
34
|
-
|
|
35
|
-
exported.managers.controllers = new exported.managerBases.Controllers();
|
|
36
|
-
exported.managers.data = new exported.managerBases.Data( config );
|
|
37
|
-
exported.managers.internal = new exported.managerBases.Internal();
|
|
36
|
+
initialize( config )
|
|
38
37
|
|
|
39
38
|
isInitialized = true;
|
|
40
39
|
|
|
@@ -42,12 +41,9 @@ export const CoreAPI = {
|
|
|
42
41
|
},
|
|
43
42
|
|
|
44
43
|
destroy: () => {
|
|
45
|
-
|
|
44
|
+
destroy();
|
|
46
45
|
|
|
47
|
-
|
|
48
|
-
exported.managers.controllers = {} as exported.managerBases.Controllers
|
|
49
|
-
exported.managers.data = {} as exported.managerBases.Data;
|
|
50
|
-
exported.managers.internal = {} as exported.managerBases.Internal;
|
|
46
|
+
isInitialized = false;
|
|
51
47
|
},
|
|
52
48
|
|
|
53
49
|
onAfterInitialize: ( callback: () => void ) => {
|
|
@@ -57,6 +53,8 @@ export const CoreAPI = {
|
|
|
57
53
|
config,
|
|
58
54
|
|
|
59
55
|
...exported,
|
|
56
|
+
|
|
57
|
+
managers: typeof __ZEN_MANAGERS__ !== 'undefined' ? __ZEN_MANAGERS__ : undefined,
|
|
60
58
|
}
|
|
61
59
|
|
|
62
60
|
// TODO: Make it available only for development.
|
package/src/managers/index.ts
CHANGED
|
@@ -5,8 +5,37 @@ import Commands from "../manager-bases/commands";
|
|
|
5
5
|
import Controllers from "../manager-bases/controllers";
|
|
6
6
|
import Data from "../manager-bases/data";
|
|
7
7
|
import Internal from "../manager-bases/internal";
|
|
8
|
+
import { IAPIConfig } from "../interfaces/config";
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
if ( typeof __ZEN_MANAGERS__ === 'undefined' || ! __ZEN_MANAGERS__ ) {
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
globalThis.__ZEN_MANAGERS__ = {};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
declare global {
|
|
16
|
+
var __ZEN_MANAGERS__: {
|
|
17
|
+
commands: Commands;
|
|
18
|
+
controllers: Controllers;
|
|
19
|
+
data: Data;
|
|
20
|
+
internal: Internal;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function initialize( config: IAPIConfig ) {
|
|
25
|
+
__ZEN_MANAGERS__.commands = new Commands();
|
|
26
|
+
__ZEN_MANAGERS__.controllers = new Controllers();
|
|
27
|
+
__ZEN_MANAGERS__.data = new Data( config );
|
|
28
|
+
__ZEN_MANAGERS__.internal = new Internal();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function destroy() {
|
|
32
|
+
__ZEN_MANAGERS__.commands = {} as Commands;
|
|
33
|
+
__ZEN_MANAGERS__.controllers = {} as Controllers;
|
|
34
|
+
__ZEN_MANAGERS__.data = {} as Data;
|
|
35
|
+
__ZEN_MANAGERS__.internal = {} as Internal;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const controllers = __ZEN_MANAGERS__.controllers;
|
|
39
|
+
export const commands = __ZEN_MANAGERS__.commands;
|
|
40
|
+
export const data = __ZEN_MANAGERS__.data;
|
|
41
|
+
export const internal = __ZEN_MANAGERS__.internal;
|