@zenflux/core 0.0.0-abc.8 → 0.0.0-development.1
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 +231 -223
- package/dist/es/src/globals.d.ts +2 -0
- package/dist/es/src/index.d.ts +1 -2
- package/dist/es/src/initializer.d.ts +4 -1
- package/dist/es/src/interfaces/managers.d.ts +13 -0
- package/dist/es/src/managers/index.d.ts +2 -0
- package/dist/es/zenflux-core.js +229 -221
- package/dist/es/zenflux-core.mjs +3 -4
- package/dist/umd/zenflux-core.js +3 -4
- package/package.json +1 -1
- package/src/globals.ts +17 -5
- package/src/initializer.ts +3 -8
- package/src/interfaces/managers.ts +16 -0
- package/src/managers/index.ts +5 -12
package/dist/es/zenflux-core.js
CHANGED
|
@@ -1,42 +1,84 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
var name = "@zenflux/core";
|
|
2
|
+
var version = "0.0.0-abc.14";
|
|
3
|
+
var description = "ZenFlux core";
|
|
4
|
+
var author = "Leonid Vinikov <leonidvinikov@gmail.com> (https://github.com/iNewLegend)";
|
|
5
|
+
var scripts = {
|
|
6
|
+
test: "export flow_modules_logger=off && jest",
|
|
7
|
+
build: "rollup --config rollup.config.ts --configPlugin typescript",
|
|
8
|
+
watch: "rollup --config rollup.config.ts --configPlugin typescript --watch"
|
|
9
|
+
};
|
|
10
|
+
var repository = {
|
|
11
|
+
type: "git",
|
|
12
|
+
url: "git+https://github.com/zenflux/core.git"
|
|
13
|
+
};
|
|
14
|
+
var keywords = [
|
|
15
|
+
"zenflux",
|
|
16
|
+
"zen",
|
|
17
|
+
"flux",
|
|
18
|
+
"commands",
|
|
19
|
+
"manager",
|
|
20
|
+
"commands manager"
|
|
21
|
+
];
|
|
22
|
+
var files = [
|
|
23
|
+
"dist",
|
|
24
|
+
"src",
|
|
25
|
+
"types"
|
|
26
|
+
];
|
|
27
|
+
var license = "MIT";
|
|
28
|
+
var main = "dist/cjs/zenflux-core.js";
|
|
29
|
+
var unpkg = "dist/umd/zenflux-core.js";
|
|
30
|
+
var module = "dist/es/zenflux-core.js";
|
|
31
|
+
var types = "types/index.d.ts";
|
|
32
|
+
var devDependencies = {
|
|
33
|
+
"@babel/core": "^7.20.7",
|
|
34
|
+
"@babel/plugin-transform-runtime": "^7.19.6",
|
|
35
|
+
"@babel/preset-env": "^7.20.2",
|
|
36
|
+
"@babel/preset-typescript": "^7.18.6",
|
|
37
|
+
"@babel/runtime": "^7.20.7",
|
|
38
|
+
"@rollup/plugin-babel": "^6.0.3",
|
|
39
|
+
"@rollup/plugin-json": "^6.0.0",
|
|
40
|
+
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
41
|
+
"@rollup/plugin-replace": "^5.0.2",
|
|
42
|
+
"@rollup/plugin-terser": "^0.2.1",
|
|
43
|
+
"@rollup/plugin-typescript": "^10.0.1",
|
|
44
|
+
"@types/jest": "^29.2.5",
|
|
45
|
+
"@typescript-eslint/eslint-plugin": "^5.48.0",
|
|
46
|
+
"@typescript-eslint/parser": "^5.48.0",
|
|
47
|
+
"babel-jest": "^29.3.1",
|
|
48
|
+
rollup: "^3.9.1",
|
|
49
|
+
"ts-jest": "^29.0.3",
|
|
50
|
+
tslib: "^2.4.1"
|
|
51
|
+
};
|
|
52
|
+
var dependencies = {
|
|
53
|
+
"@babel/runtime": "^7.19.0"
|
|
54
|
+
};
|
|
55
|
+
var pkg = {
|
|
56
|
+
name: name,
|
|
57
|
+
version: version,
|
|
58
|
+
description: description,
|
|
59
|
+
author: author,
|
|
60
|
+
scripts: scripts,
|
|
61
|
+
repository: repository,
|
|
62
|
+
keywords: keywords,
|
|
63
|
+
files: files,
|
|
64
|
+
license: license,
|
|
65
|
+
main: main,
|
|
66
|
+
unpkg: unpkg,
|
|
67
|
+
module: module,
|
|
68
|
+
types: types,
|
|
69
|
+
devDependencies: devDependencies,
|
|
70
|
+
dependencies: dependencies
|
|
71
|
+
};
|
|
16
72
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
virtualId = 0;
|
|
27
|
-
static getName() {
|
|
28
|
-
throw new ForceMethodBase("ObjectBase", "getName");
|
|
29
|
-
}
|
|
30
|
-
constructor() {
|
|
31
|
-
this.virtualId = IdCounter;
|
|
32
|
-
APIIncreaseIdCounter();
|
|
33
|
-
}
|
|
34
|
-
getName() {
|
|
35
|
-
return this.constructor.getName();
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
function APIIncreaseIdCounter() {
|
|
39
|
-
return IdCounter++;
|
|
73
|
+
if (typeof __ZEN_MANAGERS__ === 'undefined' || !__ZEN_MANAGERS__) {
|
|
74
|
+
globalThis.__ZEN_MANAGERS__ = {
|
|
75
|
+
initialize: () => {},
|
|
76
|
+
destroy: () => {},
|
|
77
|
+
commands: {},
|
|
78
|
+
controllers: {},
|
|
79
|
+
data: {},
|
|
80
|
+
internal: {}
|
|
81
|
+
};
|
|
40
82
|
}
|
|
41
83
|
|
|
42
84
|
/**
|
|
@@ -393,120 +435,47 @@ class Logger {
|
|
|
393
435
|
}
|
|
394
436
|
}
|
|
395
437
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
options = {};
|
|
405
|
-
logger;
|
|
406
|
-
constructor(args = {}, options = {}) {
|
|
407
|
-
super();
|
|
408
|
-
const name = this.constructor.getName();
|
|
409
|
-
this.logger = new Logger(name, true, {
|
|
410
|
-
sameColor: true
|
|
411
|
-
});
|
|
412
|
-
this.logger.startWith({
|
|
413
|
-
args,
|
|
414
|
-
options
|
|
415
|
-
});
|
|
416
|
-
this.initialize(args, options);
|
|
417
|
-
}
|
|
418
|
-
initialize(args, options) {
|
|
419
|
-
this.args = args;
|
|
420
|
-
this.options = options;
|
|
421
|
-
}
|
|
422
|
-
apply(args = this.args, options = this.options) {
|
|
423
|
-
throw new ForceMethod(this, "apply");
|
|
424
|
-
}
|
|
425
|
-
async run() {
|
|
426
|
-
this.onBeforeApply && this.onBeforeApply();
|
|
427
|
-
const result = await this.apply(this.args, this.options);
|
|
428
|
-
this.onAfterApply && this.onAfterApply();
|
|
429
|
-
return result;
|
|
430
|
-
}
|
|
431
|
-
getArgs() {
|
|
432
|
-
return this.args;
|
|
433
|
-
}
|
|
434
|
-
getOptions() {
|
|
435
|
-
return this.options;
|
|
438
|
+
var index$5 = /*#__PURE__*/Object.freeze({
|
|
439
|
+
__proto__: null,
|
|
440
|
+
Logger: Logger
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
class ForceMethodBase extends Error {
|
|
444
|
+
constructor(className, methodName) {
|
|
445
|
+
super(`ForeMethod implementation: at '${className}' method: '${methodName}'`);
|
|
436
446
|
}
|
|
437
447
|
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
* @description: CommandPublic represents a USER action, every class which inherit from this class will USER action.
|
|
442
|
-
* */
|
|
443
|
-
class CommandPublic extends CommandBase {
|
|
444
|
-
static getName() {
|
|
445
|
-
return 'Core/CommandBases/CommandPublic';
|
|
448
|
+
class ForceMethod extends Error {
|
|
449
|
+
constructor(context, methodName) {
|
|
450
|
+
super(`ForeMethod implementation: at '${context.getName()}' method: '${methodName}'`);
|
|
446
451
|
}
|
|
447
452
|
}
|
|
448
453
|
|
|
449
454
|
/**
|
|
450
455
|
* @author: Leonid Vinikov <leonidvinikov@gmail.com>
|
|
451
|
-
* @description:
|
|
456
|
+
* @description: is base class/object for all classes, responsible for: 'getName', implementation.
|
|
452
457
|
*/
|
|
453
|
-
|
|
458
|
+
let IdCounter = 0;
|
|
459
|
+
/**
|
|
460
|
+
* Base class 4 *
|
|
461
|
+
*/
|
|
462
|
+
class ObjectBase {
|
|
463
|
+
virtualId = 0;
|
|
454
464
|
static getName() {
|
|
455
|
-
|
|
456
|
-
}
|
|
457
|
-
/**
|
|
458
|
-
* Function getEndpoint() : Override this method is required to determine endpoint and magic query params.
|
|
459
|
-
* @example
|
|
460
|
-
* ```
|
|
461
|
-
* args = { query: { id: 1 } };
|
|
462
|
-
* getEndpoint() = '/api/v1/users/{id}';
|
|
463
|
-
* result = '/api/v1/users/1';
|
|
464
|
-
* ```
|
|
465
|
-
*/
|
|
466
|
-
getEndpoint() {
|
|
467
|
-
throw new ForceMethod(this, 'getEndpoint');
|
|
465
|
+
throw new ForceMethodBase("ObjectBase", "getName");
|
|
468
466
|
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
467
|
+
constructor() {
|
|
468
|
+
this.virtualId = IdCounter;
|
|
469
|
+
APIIncreaseIdCounter();
|
|
472
470
|
}
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
if (endpoint.includes('{')) {
|
|
476
|
-
endpoint = endpoint.split('/').map(endpointPart => {
|
|
477
|
-
const match = endpointPart.match('\\{(.*?)\\}');
|
|
478
|
-
if (match?.length && 'undefined' !== typeof data[match[1]]) {
|
|
479
|
-
return data[match[1]];
|
|
480
|
-
}
|
|
481
|
-
return endpointPart;
|
|
482
|
-
}).join('/');
|
|
483
|
-
}
|
|
484
|
-
return endpoint;
|
|
471
|
+
getName() {
|
|
472
|
+
return this.constructor.getName();
|
|
485
473
|
}
|
|
486
474
|
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
* @author: Leonid Vinikov <leonidvinikov@gmail.com>
|
|
490
|
-
* @description: CommandInternal, is used when part of the logic needed to be in the command but not represent a user action.
|
|
491
|
-
*/
|
|
492
|
-
class CommandInternal extends CommandBase {
|
|
493
|
-
static getName() {
|
|
494
|
-
return 'Core/CommandBases/CommandInternal';
|
|
495
|
-
}
|
|
475
|
+
function APIIncreaseIdCounter() {
|
|
476
|
+
return IdCounter++;
|
|
496
477
|
}
|
|
497
478
|
|
|
498
|
-
/**
|
|
499
|
-
* @author: Leonid Vinikov <leonidvinikov@gmail.com>
|
|
500
|
-
*/
|
|
501
|
-
|
|
502
|
-
var index$5 = /*#__PURE__*/Object.freeze({
|
|
503
|
-
__proto__: null,
|
|
504
|
-
CommandBase: CommandBase,
|
|
505
|
-
CommandData: CommandData,
|
|
506
|
-
CommandInternal: CommandInternal,
|
|
507
|
-
CommandPublic: CommandPublic
|
|
508
|
-
});
|
|
509
|
-
|
|
510
479
|
/**
|
|
511
480
|
* @author: Leonid Vinikov <leonidvinikov@gmail.com>
|
|
512
481
|
* @description: Responsible for commands, Aka ( CommandsSpace ).
|
|
@@ -577,11 +546,6 @@ ControllerAlreadyRegistered: ControllerAlreadyRegistered,
|
|
|
577
546
|
ForceMethod: ForceMethod
|
|
578
547
|
});
|
|
579
548
|
|
|
580
|
-
var index$2 = /*#__PURE__*/Object.freeze({
|
|
581
|
-
__proto__: null,
|
|
582
|
-
Logger: Logger
|
|
583
|
-
});
|
|
584
|
-
|
|
585
549
|
/**
|
|
586
550
|
* @author: Leonid Vinikov <leonidvinikov@gmail.com>
|
|
587
551
|
* @description: Responsible for manging/running/hooking commands.
|
|
@@ -947,6 +911,7 @@ class Internal extends Commands {
|
|
|
947
911
|
/**
|
|
948
912
|
* @author: Leonid Vinikov <leonidvinikov@gmail.com>
|
|
949
913
|
*/
|
|
914
|
+
const afterInitializeCallbacks = [];
|
|
950
915
|
function initialize(config) {
|
|
951
916
|
__ZEN_MANAGERS__.commands = new Commands();
|
|
952
917
|
__ZEN_MANAGERS__.controllers = new Controllers();
|
|
@@ -963,9 +928,12 @@ const controllers = __ZEN_MANAGERS__.controllers;
|
|
|
963
928
|
const commands = __ZEN_MANAGERS__.commands;
|
|
964
929
|
const data = __ZEN_MANAGERS__.data;
|
|
965
930
|
const internal = __ZEN_MANAGERS__.internal;
|
|
931
|
+
__ZEN_MANAGERS__.initialize = initialize;
|
|
932
|
+
__ZEN_MANAGERS__.destroy = destroy;
|
|
966
933
|
|
|
967
|
-
var index$
|
|
934
|
+
var index$2 = /*#__PURE__*/Object.freeze({
|
|
968
935
|
__proto__: null,
|
|
936
|
+
afterInitializeCallbacks: afterInitializeCallbacks,
|
|
969
937
|
commands: commands,
|
|
970
938
|
controllers: controllers,
|
|
971
939
|
data: data,
|
|
@@ -974,6 +942,120 @@ initialize: initialize,
|
|
|
974
942
|
internal: internal
|
|
975
943
|
});
|
|
976
944
|
|
|
945
|
+
/**
|
|
946
|
+
* @author: Leonid Vinikov <leonidvinikov@gmail.com>
|
|
947
|
+
* @description: Base for all commands, they are all will be managed by the `Commands` managers.
|
|
948
|
+
* @TODO
|
|
949
|
+
* - Add validateArgs method or find something better.
|
|
950
|
+
*/
|
|
951
|
+
class CommandBase extends ObjectBase {
|
|
952
|
+
args = {};
|
|
953
|
+
options = {};
|
|
954
|
+
logger;
|
|
955
|
+
constructor(args = {}, options = {}) {
|
|
956
|
+
super();
|
|
957
|
+
const name = this.constructor.getName();
|
|
958
|
+
this.logger = new Logger(name, true, {
|
|
959
|
+
sameColor: true
|
|
960
|
+
});
|
|
961
|
+
this.logger.startWith({
|
|
962
|
+
args,
|
|
963
|
+
options
|
|
964
|
+
});
|
|
965
|
+
this.initialize(args, options);
|
|
966
|
+
}
|
|
967
|
+
initialize(args, options) {
|
|
968
|
+
this.args = args;
|
|
969
|
+
this.options = options;
|
|
970
|
+
}
|
|
971
|
+
apply(args = this.args, options = this.options) {
|
|
972
|
+
throw new ForceMethod(this, "apply");
|
|
973
|
+
}
|
|
974
|
+
async run() {
|
|
975
|
+
this.onBeforeApply && this.onBeforeApply();
|
|
976
|
+
const result = await this.apply(this.args, this.options);
|
|
977
|
+
this.onAfterApply && this.onAfterApply();
|
|
978
|
+
return result;
|
|
979
|
+
}
|
|
980
|
+
getArgs() {
|
|
981
|
+
return this.args;
|
|
982
|
+
}
|
|
983
|
+
getOptions() {
|
|
984
|
+
return this.options;
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
/**
|
|
989
|
+
* @author: Leonid Vinikov <leonidvinikov@gmail.com>
|
|
990
|
+
* @description: CommandPublic represents a USER action, every class which inherit from this class will USER action.
|
|
991
|
+
* */
|
|
992
|
+
class CommandPublic extends CommandBase {
|
|
993
|
+
static getName() {
|
|
994
|
+
return 'Core/CommandBases/CommandPublic';
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
/**
|
|
999
|
+
* @author: Leonid Vinikov <leonidvinikov@gmail.com>
|
|
1000
|
+
* @description: Each data command should represent a final REST endpoint.
|
|
1001
|
+
*/
|
|
1002
|
+
class CommandData extends CommandBase {
|
|
1003
|
+
static getName() {
|
|
1004
|
+
return 'Core/CommandBases/CommandData';
|
|
1005
|
+
}
|
|
1006
|
+
/**
|
|
1007
|
+
* Function getEndpoint() : Override this method is required to determine endpoint and magic query params.
|
|
1008
|
+
* @example
|
|
1009
|
+
* ```
|
|
1010
|
+
* args = { query: { id: 1 } };
|
|
1011
|
+
* getEndpoint() = '/api/v1/users/{id}';
|
|
1012
|
+
* result = '/api/v1/users/1';
|
|
1013
|
+
* ```
|
|
1014
|
+
*/
|
|
1015
|
+
getEndpoint() {
|
|
1016
|
+
throw new ForceMethod(this, 'getEndpoint');
|
|
1017
|
+
}
|
|
1018
|
+
apply(args = this.args, options = this.options) {
|
|
1019
|
+
const endpoint = this.applyEndpointFormat(this.getEndpoint(), args);
|
|
1020
|
+
return __ZEN_MANAGERS__.data.getClient().fetch(endpoint, __ZEN_MANAGERS__.data.currentHttpMethod, args || null);
|
|
1021
|
+
}
|
|
1022
|
+
applyEndpointFormat(endpoint, data = {}) {
|
|
1023
|
+
// Replace query with `magic` placeholders.
|
|
1024
|
+
if (endpoint.includes('{')) {
|
|
1025
|
+
endpoint = endpoint.split('/').map(endpointPart => {
|
|
1026
|
+
const match = endpointPart.match('\\{(.*?)\\}');
|
|
1027
|
+
if (match?.length && 'undefined' !== typeof data[match[1]]) {
|
|
1028
|
+
return data[match[1]];
|
|
1029
|
+
}
|
|
1030
|
+
return endpointPart;
|
|
1031
|
+
}).join('/');
|
|
1032
|
+
}
|
|
1033
|
+
return endpoint;
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
/**
|
|
1038
|
+
* @author: Leonid Vinikov <leonidvinikov@gmail.com>
|
|
1039
|
+
* @description: CommandInternal, is used when part of the logic needed to be in the command but not represent a user action.
|
|
1040
|
+
*/
|
|
1041
|
+
class CommandInternal extends CommandBase {
|
|
1042
|
+
static getName() {
|
|
1043
|
+
return 'Core/CommandBases/CommandInternal';
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
/**
|
|
1048
|
+
* @author: Leonid Vinikov <leonidvinikov@gmail.com>
|
|
1049
|
+
*/
|
|
1050
|
+
|
|
1051
|
+
var index$1 = /*#__PURE__*/Object.freeze({
|
|
1052
|
+
__proto__: null,
|
|
1053
|
+
CommandBase: CommandBase,
|
|
1054
|
+
CommandData: CommandData,
|
|
1055
|
+
CommandInternal: CommandInternal,
|
|
1056
|
+
CommandPublic: CommandPublic
|
|
1057
|
+
});
|
|
1058
|
+
|
|
977
1059
|
/**
|
|
978
1060
|
* @author: Leonid Vinikov <leonidvinikov@gmail.com>
|
|
979
1061
|
*/
|
|
@@ -992,87 +1074,15 @@ Internal: Internal
|
|
|
992
1074
|
|
|
993
1075
|
var exported = /*#__PURE__*/Object.freeze({
|
|
994
1076
|
__proto__: null,
|
|
995
|
-
commandBases: index$
|
|
1077
|
+
commandBases: index$1,
|
|
996
1078
|
core: index$4,
|
|
997
1079
|
errors: index$3,
|
|
998
1080
|
managerBases: index,
|
|
999
|
-
managers: index$
|
|
1000
|
-
modules: index$
|
|
1081
|
+
managers: index$2,
|
|
1082
|
+
modules: index$5,
|
|
1001
1083
|
utils: index$6
|
|
1002
1084
|
});
|
|
1003
1085
|
|
|
1004
|
-
var name = "@zenflux/core";
|
|
1005
|
-
var version = "0.0.0-abc.7";
|
|
1006
|
-
var description = "ZenFlux core";
|
|
1007
|
-
var author = "Leonid Vinikov <leonidvinikov@gmail.com> (https://github.com/iNewLegend)";
|
|
1008
|
-
var scripts = {
|
|
1009
|
-
test: "export flow_modules_logger=off && jest",
|
|
1010
|
-
build: "rollup --config rollup.config.ts --configPlugin typescript",
|
|
1011
|
-
watch: "rollup --config rollup.config.ts --configPlugin typescript --watch"
|
|
1012
|
-
};
|
|
1013
|
-
var repository = {
|
|
1014
|
-
type: "git",
|
|
1015
|
-
url: "git+https://github.com/zenflux/core.git"
|
|
1016
|
-
};
|
|
1017
|
-
var keywords = [
|
|
1018
|
-
"zenflux",
|
|
1019
|
-
"zen",
|
|
1020
|
-
"flux",
|
|
1021
|
-
"commands",
|
|
1022
|
-
"manager",
|
|
1023
|
-
"commands manager"
|
|
1024
|
-
];
|
|
1025
|
-
var files = [
|
|
1026
|
-
"dist",
|
|
1027
|
-
"src",
|
|
1028
|
-
"types"
|
|
1029
|
-
];
|
|
1030
|
-
var license = "MIT";
|
|
1031
|
-
var main = "dist/cjs/zenflux-core.js";
|
|
1032
|
-
var unpkg = "dist/umd/zenflux-core.js";
|
|
1033
|
-
var module = "dist/es/zenflux-core.js";
|
|
1034
|
-
var types = "types/index.d.ts";
|
|
1035
|
-
var devDependencies = {
|
|
1036
|
-
"@babel/core": "^7.20.7",
|
|
1037
|
-
"@babel/plugin-transform-runtime": "^7.19.6",
|
|
1038
|
-
"@babel/preset-env": "^7.20.2",
|
|
1039
|
-
"@babel/preset-typescript": "^7.18.6",
|
|
1040
|
-
"@babel/runtime": "^7.20.7",
|
|
1041
|
-
"@rollup/plugin-babel": "^6.0.3",
|
|
1042
|
-
"@rollup/plugin-json": "^6.0.0",
|
|
1043
|
-
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
1044
|
-
"@rollup/plugin-replace": "^5.0.2",
|
|
1045
|
-
"@rollup/plugin-terser": "^0.2.1",
|
|
1046
|
-
"@rollup/plugin-typescript": "^10.0.1",
|
|
1047
|
-
"@types/jest": "^29.2.5",
|
|
1048
|
-
"@typescript-eslint/eslint-plugin": "^5.48.0",
|
|
1049
|
-
"@typescript-eslint/parser": "^5.48.0",
|
|
1050
|
-
"babel-jest": "^29.3.1",
|
|
1051
|
-
rollup: "^3.9.1",
|
|
1052
|
-
"ts-jest": "^29.0.3",
|
|
1053
|
-
tslib: "^2.4.1"
|
|
1054
|
-
};
|
|
1055
|
-
var dependencies = {
|
|
1056
|
-
"@babel/runtime": "^7.19.0"
|
|
1057
|
-
};
|
|
1058
|
-
var pkg = {
|
|
1059
|
-
name: name,
|
|
1060
|
-
version: version,
|
|
1061
|
-
description: description,
|
|
1062
|
-
author: author,
|
|
1063
|
-
scripts: scripts,
|
|
1064
|
-
repository: repository,
|
|
1065
|
-
keywords: keywords,
|
|
1066
|
-
files: files,
|
|
1067
|
-
license: license,
|
|
1068
|
-
main: main,
|
|
1069
|
-
unpkg: unpkg,
|
|
1070
|
-
module: module,
|
|
1071
|
-
types: types,
|
|
1072
|
-
devDependencies: devDependencies,
|
|
1073
|
-
dependencies: dependencies
|
|
1074
|
-
};
|
|
1075
|
-
|
|
1076
1086
|
let isInitialized = false;
|
|
1077
1087
|
function errorInitTwice() {
|
|
1078
1088
|
if (isInitialized) {
|
|
@@ -1083,14 +1093,12 @@ errorInitTwice();
|
|
|
1083
1093
|
let config = {
|
|
1084
1094
|
version: pkg.version
|
|
1085
1095
|
};
|
|
1086
|
-
const afterInitializeCallbacks = [];
|
|
1087
1096
|
const CoreAPI = {
|
|
1088
1097
|
initialize: configuration => {
|
|
1089
1098
|
errorInitTwice();
|
|
1090
1099
|
config = configuration || config;
|
|
1091
1100
|
initialize(config);
|
|
1092
1101
|
isInitialized = true;
|
|
1093
|
-
afterInitializeCallbacks.forEach(callback => callback());
|
|
1094
1102
|
},
|
|
1095
1103
|
destroy: () => {
|
|
1096
1104
|
destroy();
|
|
@@ -1106,4 +1114,4 @@ const CoreAPI = {
|
|
|
1106
1114
|
// TODO: Make it available only for development.
|
|
1107
1115
|
if (!globalThis?.ZenCore) globalThis.ZenCore = CoreAPI;
|
|
1108
1116
|
|
|
1109
|
-
export { index$
|
|
1117
|
+
export { index$1 as commandBases, index$4 as core, CoreAPI as default, index$3 as errors, index as managerBases, index$2 as managers, index$5 as modules, index$6 as utils };
|
package/dist/es/zenflux-core.mjs
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
"undefined"!=typeof __ZEN_MANAGERS__&&__ZEN_MANAGERS__||(globalThis.__ZEN_MANAGERS__={
|
|
1
|
+
var t="0.0.0-abc.14";"undefined"!=typeof __ZEN_MANAGERS__&&__ZEN_MANAGERS__||(globalThis.__ZEN_MANAGERS__={initialize:()=>{},destroy:()=>{},commands:{},controllers:{},data:{},internal:{}})
|
|
2
2
|
/**
|
|
3
3
|
* Function getCircularReplacer() : Reduce circular references.
|
|
4
4
|
*
|
|
5
5
|
* @copyright https://stackoverflow.com/a/53731154
|
|
6
|
-
|
|
7
|
-
const n=()=>{const t=new WeakSet;return(e,r)=>{if("object"==typeof r&&null!==r){if(t.has(r))return;t.add(r)}return r}},o=function(t,e){t=t.replace("#",""),e=e.replace("#","");const r=parseInt(t.substring(0,2),16),s=parseInt(t.substring(2,4),16),n=parseInt(t.substring(4,6),16),o=parseInt(e.substring(0,2),16),a=parseInt(e.substring(2,4),16),i=parseInt(e.substring(4,6),16);let c=255-Math.abs(r-o),l=255-Math.abs(s-a),h=255-Math.abs(n-i);return c/=255,l/=255,h/=255,(c+l+h)/3};
|
|
6
|
+
*/;const e=()=>{const t=new WeakSet;return(e,r)=>{if("object"==typeof r&&null!==r){if(t.has(r))return;t.add(r)}return r}},r=function(t,e){t=t.replace("#",""),e=e.replace("#","");const r=parseInt(t.substring(0,2),16),s=parseInt(t.substring(2,4),16),n=parseInt(t.substring(4,6),16),o=parseInt(e.substring(0,2),16),a=parseInt(e.substring(2,4),16),i=parseInt(e.substring(4,6),16);let c=255-Math.abs(r-o),l=255-Math.abs(s-a),h=255-Math.abs(n-i);return c/=255,l/=255,h/=255,(c+l+h)/3};
|
|
8
7
|
/**
|
|
9
8
|
* Function hexColorDelta() : Return color difference in ratio decimal point.
|
|
10
9
|
*
|
|
11
10
|
* @copyright http://jsfiddle.net/96sME/
|
|
12
|
-
*/var 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};
|
|
11
|
+
*/var s=Object.freeze({__proto__:null,getCircularReplacer:e,hexColorDelta:r});class n{static wrappers={};static wrapperDepth=0;static sharedData={};static colorsInUse=[];defaultStyle;color;outputHandler;args={};name;state=!1;static getName(){return"Core/Modules/Logger"}static reset(){n.wrappers={},n.wrapperDepth=0,n.colorsInUse=[],n.sharedData={}}static createCustomWrapper(t,e){n.wrappers[t]||(n.wrappers[t.name]=[]),n.wrappers[t.name].push({classType:t,callback:e})}static getCallerName(){const t=Error(),e=t.stack?t.stack.split("\n")[3].trim():"_UNKNOWN_CALLER_NAME_";return e.startsWith("at new")?"constructor":e.split(".")[1].split(" ")[0]}static getFunctionView(t){let e="anonymous function()";return"string"!=typeof t&&0!==t.name.length&&(e=t.name.split(" ")[1]+"()"),e}constructor(t,e=!1,r={}){"off"!==globalThis.process?.env.flow_modules_logger&&(this.state=e,this.args=r,this.name="",this.name="string"==typeof t?t:t.constructor.name,e&&this.initialize())}initialize(){this.args.sameColor?(n.sharedData[this.name]||(n.sharedData[this.name]=this.getRandomColor()),this.color=n.sharedData[this.name]):(this.color=this.getRandomColor(),n.colorsInUse.push(this.color)),this.outputHandler=console.log,this.defaultStyle=["color: grey;font-size:7px","display: block","color: "+this.color,"color: grey","font-weight: bold","color: #607D8B","font-size: 16px;color: red;font-weight:800"]}setOutputHandler(t){this.outputHandler=t}useWrapper(t,e=!0){if(!t||"object"!=typeof t||Array.isArray(t))return t;n.wrapperDepth++;let r={...t};return Object.values(n.wrappers).forEach((([e])=>{t instanceof e.classType&&(r=e.callback(t)||r)})),4>n.wrapperDepth?(e&&r&&Object.entries(r).forEach((([t,e])=>{r[t]=this.useWrapper(e,!0)})),n.wrapperDepth--,r):(n.wrapperDepth--,r)}startEmpty(t=""){this.state&&this.printFunctionNotify("se",n.getCallerName(),t)}startWith(t){if(!this.state)return;t=Object.assign({},t);const e="se",r=n.getCallerName();if("string"==typeof t)this.printInLineString(e,r,t);else if(1===Object.keys(t).length){const s=Object.keys(t)[0];let n=Object.values(t)[0];"object"==typeof n?this.printNextLineObject(e,r,s,n||{}):"function"==typeof n?this.printInLineFunction(e,r,s,n):this.printInLineElement(e,r,s,n)}else this.printMultiLineObject(e,r,t)}object(t={},r=""){if(!this.state)return;const s=n.getCallerName();t=Object.create(t);for(let n in t)"object"==typeof t[n]&&(t[n]=JSON.stringify(this.useWrapper(t[n]),e())),this.out.apply(this,[`%c(ob)-> %c%c${this.name}%c::%c${s}%c() [${r}] ->> ${n}: '${t[n]}'%c`].concat(this.defaultStyle))}debug(t){this.state&&this.printFunctionNotify("db",n.getCallerName(),t)}drop(t,e){if(!this.state)return;const r=n.getCallerName();for(let e in t)this.out.apply(this,[`%c(dr)-> %c%c${this.name}%c::%c${r}%c() ->> corresponding ${e}: '${t[e]}' RESULT: %c↓`].concat(this.defaultStyle));this.out(e)}throw(t,e="null",r={}){throw this.printFunctionNotify("tw",n.getCallerName(),t),r&&this.printNextLineObject("tw",n.getCallerName(),e,r),Error().stack}clone(){return Object.assign(Object.create(Object.getPrototypeOf(this)),this)}printFunctionNotify(t,e,r){this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c() ${r}%c`].concat(this.defaultStyle))}printInLineElement(t,e,r,s){this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c() ->> ${r}: '${s}'%c`].concat(this.defaultStyle))}printInLineFunction(t,e,r,s){s=n.getFunctionView(s),this.printInLineElement(t,e,r,s)}printInLineString(t,e,r){this.printInLineElement(t,e,"(string)",r)}printNextLineObject(t,e,r,s){s=this.useWrapper(s),this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c() ->> ${r} %c↓`].concat(this.defaultStyle)),this.out(s)}printMultiLineObject(t,r,s){this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${r}%c(${Object.keys(s).join(", ")}) %c↓`].concat(this.defaultStyle));for(let t in s){let r=s[t];"object"==typeof r?r=JSON.stringify(this.useWrapper(r),e()):"function"==typeof s[t]&&(r=n.getFunctionView(r)),this.out.call(this,"%c"+t+": `"+this.useWrapper(r)+"`","color: #a3a3a3")}}getRandomColor(){let t="#";for(let e=0;6>e;e++)t+="0123456789ABCDEF"[Math.floor(16*Math.random())];return n.colorsInUse.some((e=>r(t,e)>=.8))?this.getRandomColor():t}out(...t){this.outputHandler.apply(this,t)}}var o=Object.freeze({__proto__:null,Logger:n});class a extends Error{constructor(t,e){super(`ForeMethod implementation: at '${t}' method: '${e}'`)}}class i extends Error{constructor(t,e){super(`ForeMethod implementation: at '${t.getName()}' method: '${e}'`)}}let c=0;class l{virtualId=0;static getName(){throw new a("ObjectBase","getName")}constructor(){this.virtualId=c,c++}getName(){return this.constructor.getName()}}var h=Object.freeze({__proto__:null,Controller:class extends l{commands;data;internal;static getName(){return"Core/Core/Controller"}constructor(){super(),this.initialize()}initialize(){this.register(),this.setupHooks&&this.setupHooks()}register(){this.commands=__ZEN_MANAGERS__.commands.register(this.getCommands(),this),this.data=__ZEN_MANAGERS__.data.register(this.getData(),this),this.internal=__ZEN_MANAGERS__.internal.register(this.getInternal(),this)}getCommands(){return{}}getData(){return{}}getInternal(){return{}}},ObjectBase:l});class u extends Error{constructor(t){super(`Command: '${t.getName()}' is already registered`)}}class p extends Error{constructor(t){super(`Command: '${t}' is not found`)}}class g extends Error{constructor(t){super(`Controller: '${t.getName()}' is already registered`)}}var m,d=Object.freeze({__proto__:null,CommandAlreadyRegistered:u,CommandNotFound:p,ControllerAlreadyRegistered:g,ForceMethod:i});class _ extends l{static trace=[];current={};currentArgs={};trace=[];commands={};onBeforeHooks={};onBeforeUIHooks={};onAfterHooks={};onAfterOnceHooks={};onAfterUIHooks={};onAfterAffectHooks={};logger;static getName(){return"Core/Managers/Commands"}static async runCallbacks(t,e={},r={}){const s=t?.length||0;for(let n=0;s>n;++n){const s=!0===r.pop?t.pop():t[n];if(!s)throw Error("Callback is not defined.");await s(e,r)}}static hookCommand(t,e,r){t[e]||(t[e]=[]),t[e].push(r)}constructor(){super(),this.logger=new n(this.getName(),!0),this.logger.startEmpty()}async run(t,e={},r={}){"string"==typeof t&&(t=this.getCommandInstance(t,e,r)),this.attachCurrent(t,e);const s=await this.runInstance(t,e,r);return this.detachCurrent(t),s}register(t,e){const r={};return Object.values(t).forEach((t=>{const e=t.getName();if(this.commands[e])throw new u(t);this.commands[e]=t,r[e]=t})),r}getAll(){return this.commands}getByName(t){return this.commands[t]}getLogger(){return this.logger}getCommandInstance(t,e={},r={}){const s=this.commands[t];if(!s)throw new p(t);return new s(e,r)}onBefore(t,e){_.hookCommand(this.onBeforeHooks,t,e)}onBeforeUI(t,e){_.hookCommand(this.onBeforeUIHooks,t,e)}onAfter(t,e){_.hookCommand(this.onAfterHooks,t,e)}onAfterUI(t,e){_.hookCommand(this.onAfterUIHooks,t,e)}onAfterOnce(t,e){_.hookCommand(this.onAfterOnceHooks,t,e)}onAfterAffect(t,e){_.hookCommand(this.onAfterAffectHooks,t,e)}onBeforeRun(t,e={},r={}){if(this.onBeforeHooks[t.getName()]){this.onBeforeHooks[t.getName()].forEach((t=>t(e,r)))}if(this.onBeforeUIHooks[t.getName()]){this.onBeforeUIHooks[t.getName()].forEach((t=>t(e,r)))}}async runInstance(t,e={},r={}){let s=null;return Object.keys(e).length?(this.logger.startWith({command:t.getName(),options:r,CommandArgs:"->"}),this.logger.debug("CommandArgs:"),this.logger.object(e)):this.logger.startWith({command:t.getName(),options:r,args:e}),this.onBeforeRun(t,e,r),s=await t.run(),await this.onAfterRun(t,e,r,s),s}async onAfterRun(t,e,r,s){return r=Object.assign({},r),this.onAfterAffectHooks[t.getName()]&&(this.onAfterAffectHooks[t.getName()].forEach((t=>{e.result=s,s=this.run(""+t,e,r)})),s=await s),this.onAfterHooks&&(e.result=s,await _.runCallbacks(Object.assign([],this.onAfterHooks[t.getName()]),e,r)),this.onAfterOnceHooks&&await _.runCallbacks(this.onAfterOnceHooks[t.getName()],e,{...r,pop:!0}),this.onAfterUIHooks&&_.runCallbacks(Object.assign([],this.onAfterUIHooks[t.getName()]),e,r),s}attachCurrent(t,e={}){this.current[t.getName()]=t,this.currentArgs[t.getName()]=e,this.trace.push(t.getName()),_.trace.push(t.getName())}detachCurrent(t){delete this.current[t.getName()],delete this.currentArgs[t.getName()],_.trace.pop(),this.trace.pop()}}class f extends l{controllers={};static getName(){return"Core/Managers/Controllers"}get(t){return this.controllers[t]}getAll(){return this.controllers}register(t){if(this.controllers[t.getName()])throw new g(t);return this.controllers[t.getName()]=t,t}}!function(t){t.DELETE="DELETE",t.GET="GET",t.OPTIONS="OPTIONS",t.PATCH="PATCH",t.POST="POST",t.PUT="PUT",t.__EMPTY__=""}(m||(m={}));class N extends l{logger;apiBaseUrl;static getName(){return"Core/Clients/Http"}constructor(t="http://localhost"){super(),this.logger=new n(N.getName(),!0),this.logger.startWith({apiBaseUrl:t}),this.apiBaseUrl=t+"/"}async fetch(t,e,r=null){this.logger.startWith({path:t,method:e,body:r});const s={credentials:"include"},n={};[m.POST,m.PUT,m.PATCH].includes(e)?(Object.assign(n,{"Content-Type":"application/json"}),Object.assign(s,{method:e,headers:n,body:JSON.stringify(r)})):Object.assign(s,{headers:n});const o=await globalThis.fetch(this.apiBaseUrl+t,s);let a;try{a=await o.json()}catch(t){return console.error(t),!1}if(a?.error&&a?.global&&a?.message)throw Error(a.message);return this.logger.drop({path:t},a),a}}class A extends _{static client;currentHttpMethod;static getName(){return"Core/Managers/Data"}constructor(t){super(),A.client=new N(t.baseURL)}getClient(){return A.client}get(t,e={},r={}){return this.currentHttpMethod=m.GET,super.run(t,e,r)}update(t,e={},r={}){return this.currentHttpMethod=m.PATCH,super.run(t,e,r)}delete(t,e={},r={}){return this.currentHttpMethod=m.DELETE,super.run(t,e,r)}create(t,e={},r={}){return this.currentHttpMethod=m.POST,super.run(t,e,r)}async runInstance(t,e={},r={}){if(!this.currentHttpMethod)throw Error('Cannot run directly use one of the http methods: "get", "update", "delete, "create');const s={type:this.currentHttpMethod,args:{query:{},data:{}}};return m.GET===this.currentHttpMethod?s.args.query=e:s.args.data=e,e.result=await super.runInstance(t,s,r),this.currentHttpMethod=m.__EMPTY__,e.result}}class E extends _{static getName(){return"Core/Managers/Internal"}}const C=[];function y(t){__ZEN_MANAGERS__.commands=new _,__ZEN_MANAGERS__.controllers=new f,__ZEN_MANAGERS__.data=new A(t),__ZEN_MANAGERS__.internal=new E}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;__ZEN_MANAGERS__.initialize=y,__ZEN_MANAGERS__.destroy=b;var H=Object.freeze({__proto__:null,afterInitializeCallbacks:C,commands:O,controllers:w,data:M,destroy:b,initialize:y,internal:k});class I 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:I,CommandData:class extends I{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 I{static getName(){return"Core/CommandBases/CommandInternal"}},CommandPublic:class extends I{static getName(){return"Core/CommandBases/CommandPublic"}}}),S=Object.freeze({__proto__:null,Commands:_,Controllers:f,Data:A,Internal:E}),R=Object.freeze({__proto__:null,commandBases:j,core:h,errors:d,managerBases:S,managers:H,modules:o,utils:s});let $=!1;function B(){if($)throw Error("ZenCore is already initialized.")}B();let T={version:t};const G={initialize:t=>{B(),T=t||T,y(T),$=!0},destroy:()=>{b(),$=!1},onAfterInitialize:t=>{C.push(t)},config:T,...R,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,S as managerBases,H as managers,o as modules,s as utils};
|