@zenflux/core 0.0.0-abc.0 → 0.0.0-devlopment.0
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 +16 -36
- package/dist/es/src/clients/http.d.ts +1 -1
- package/dist/es/src/command-bases/command-base.d.ts +1 -1
- package/dist/es/src/command-bases/command-internal.d.ts +1 -1
- package/dist/es/src/command-bases/command-public.d.ts +1 -1
- package/dist/es/src/command-bases/index.d.ts +0 -3
- package/dist/es/src/core/controller.d.ts +1 -1
- package/dist/es/src/enums/http.d.ts +0 -3
- package/dist/es/src/errors/command-already-registered.d.ts +1 -1
- package/dist/es/src/errors/command-not-found.d.ts +1 -1
- package/dist/es/src/errors/controller-already-registered.d.ts +1 -1
- package/dist/es/src/errors/force-method.d.ts +1 -1
- package/dist/es/src/exports.d.ts +0 -3
- package/dist/es/src/index.d.ts +0 -3
- package/dist/es/src/manager-bases/commands.d.ts +1 -1
- package/dist/es/src/manager-bases/controllers.d.ts +1 -1
- package/dist/es/src/manager-bases/data.d.ts +1 -1
- package/dist/es/src/manager-bases/index.d.ts +0 -3
- package/dist/es/src/manager-bases/internal.d.ts +1 -1
- package/dist/es/src/managers/index.d.ts +0 -3
- package/dist/es/zenflux-core.js +16 -36
- package/dist/es/zenflux-core.mjs +2 -2
- package/dist/umd/zenflux-core.js +1 -1
- package/package.json +1 -1
- package/src/initializer.ts +1 -1
package/dist/cjs/zenflux-core.js
CHANGED
|
@@ -14,7 +14,7 @@ class ForceMethod extends Error {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
* @author: Leonid Vinikov <
|
|
17
|
+
* @author: Leonid Vinikov <czf.leo123@gmail.com>
|
|
18
18
|
* @description: is base class/object for all classes, responsible for: 'getName', implementation.
|
|
19
19
|
*/
|
|
20
20
|
let IdCounter = 0;
|
|
@@ -91,7 +91,7 @@ hexColorDelta: hexColorDelta
|
|
|
91
91
|
});
|
|
92
92
|
|
|
93
93
|
/**
|
|
94
|
-
* @author: Leonid Vinikov <
|
|
94
|
+
* @author: Leonid Vinikov <czf.leo123@gmail.com>
|
|
95
95
|
* @description: Module for logging instances.
|
|
96
96
|
* @TODO:
|
|
97
97
|
* - Remove `@ts-ignore`, requires a refactor.
|
|
@@ -393,7 +393,7 @@ class Logger {
|
|
|
393
393
|
}
|
|
394
394
|
|
|
395
395
|
/**
|
|
396
|
-
* @author: Leonid Vinikov <
|
|
396
|
+
* @author: Leonid Vinikov <czf.leo123@gmail.com>
|
|
397
397
|
* @description: Base for all commands, they are all will be managed by the `Commands` managers.
|
|
398
398
|
* @TODO
|
|
399
399
|
* - Add validateArgs method or find something better.
|
|
@@ -436,7 +436,7 @@ class CommandBase extends ObjectBase {
|
|
|
436
436
|
}
|
|
437
437
|
|
|
438
438
|
/**
|
|
439
|
-
* @author: Leonid Vinikov <
|
|
439
|
+
* @author: Leonid Vinikov <czf.leo123@gmail.com>
|
|
440
440
|
* @description: CommandPublic represents a USER action, every class which inherit from this class will USER action.
|
|
441
441
|
* */
|
|
442
442
|
class CommandPublic extends CommandBase {
|
|
@@ -459,7 +459,7 @@ get internal () { return internal; }
|
|
|
459
459
|
});
|
|
460
460
|
|
|
461
461
|
/**
|
|
462
|
-
* @author: Leonid Vinikov <
|
|
462
|
+
* @author: Leonid Vinikov <czf.leo123@gmail.com>
|
|
463
463
|
* @description: Each data command should represent a final REST endpoint.
|
|
464
464
|
*/
|
|
465
465
|
class CommandData extends CommandBase {
|
|
@@ -498,7 +498,7 @@ class CommandData extends CommandBase {
|
|
|
498
498
|
}
|
|
499
499
|
|
|
500
500
|
/**
|
|
501
|
-
* @author: Leonid Vinikov <
|
|
501
|
+
* @author: Leonid Vinikov <czf.leo123@gmail.com>
|
|
502
502
|
* @description: CommandInternal, is used when part of the logic needed to be in the command but not represent a user action.
|
|
503
503
|
*/
|
|
504
504
|
class CommandInternal extends CommandBase {
|
|
@@ -507,10 +507,6 @@ class CommandInternal extends CommandBase {
|
|
|
507
507
|
}
|
|
508
508
|
}
|
|
509
509
|
|
|
510
|
-
/**
|
|
511
|
-
* @author: Leonid Vinikov <leonidvinikov@gmail.com>
|
|
512
|
-
*/
|
|
513
|
-
|
|
514
510
|
var index$4 = /*#__PURE__*/Object.freeze({
|
|
515
511
|
__proto__: null,
|
|
516
512
|
CommandBase: CommandBase,
|
|
@@ -520,7 +516,7 @@ CommandPublic: CommandPublic
|
|
|
520
516
|
});
|
|
521
517
|
|
|
522
518
|
/**
|
|
523
|
-
* @author: Leonid Vinikov <
|
|
519
|
+
* @author: Leonid Vinikov <czf.leo123@gmail.com>
|
|
524
520
|
* @description: Responsible for commands, Aka ( CommandsSpace ).
|
|
525
521
|
*/
|
|
526
522
|
class Controller extends ObjectBase {
|
|
@@ -567,7 +563,7 @@ class CommandAlreadyRegistered extends Error {
|
|
|
567
563
|
}
|
|
568
564
|
|
|
569
565
|
/**
|
|
570
|
-
* @author: Leonid Vinikov <
|
|
566
|
+
* @author: Leonid Vinikov <czf.leo123@gmail.com>
|
|
571
567
|
*/
|
|
572
568
|
class CommandNotFound extends Error {
|
|
573
569
|
constructor(command) {
|
|
@@ -595,7 +591,7 @@ Logger: Logger
|
|
|
595
591
|
});
|
|
596
592
|
|
|
597
593
|
/**
|
|
598
|
-
* @author: Leonid Vinikov <
|
|
594
|
+
* @author: Leonid Vinikov <czf.leo123@gmail.com>
|
|
599
595
|
* @description: Responsible for manging/running/hooking commands.
|
|
600
596
|
*/
|
|
601
597
|
class Commands extends ObjectBase {
|
|
@@ -782,7 +778,7 @@ class Commands extends ObjectBase {
|
|
|
782
778
|
}
|
|
783
779
|
|
|
784
780
|
/**
|
|
785
|
-
* @author: Leonid Vinikov <
|
|
781
|
+
* @author: Leonid Vinikov <czf.leo123@gmail.com>
|
|
786
782
|
* @description: Responsible for manging controllers, each controller is global singleton instance.
|
|
787
783
|
*/
|
|
788
784
|
class Controllers extends ObjectBase {
|
|
@@ -806,9 +802,6 @@ class Controllers extends ObjectBase {
|
|
|
806
802
|
}
|
|
807
803
|
}
|
|
808
804
|
|
|
809
|
-
/**
|
|
810
|
-
* @author: Leonid Vinikov <leonidvinikov@gmail.com>
|
|
811
|
-
*/
|
|
812
805
|
var HTTPMethodEnum;
|
|
813
806
|
(function (HTTPMethodEnum) {
|
|
814
807
|
HTTPMethodEnum["DELETE"] = "DELETE";
|
|
@@ -821,7 +814,7 @@ var HTTPMethodEnum;
|
|
|
821
814
|
})(HTTPMethodEnum || (HTTPMethodEnum = {}));
|
|
822
815
|
|
|
823
816
|
/**
|
|
824
|
-
* @author: Leonid Vinikov <
|
|
817
|
+
* @author: Leonid Vinikov <czf.leo123@gmail.com>
|
|
825
818
|
* @description: Providing a simple wrapper for fetch API.
|
|
826
819
|
*/
|
|
827
820
|
class Http extends ObjectBase {
|
|
@@ -889,7 +882,7 @@ class Http extends ObjectBase {
|
|
|
889
882
|
}
|
|
890
883
|
|
|
891
884
|
/**
|
|
892
|
-
* @author: Leonid Vinikov <
|
|
885
|
+
* @author: Leonid Vinikov <czf.leo123@gmail.com>
|
|
893
886
|
* @description: Responsible for manging data commands which are wrappers for HTTP requests.
|
|
894
887
|
*/
|
|
895
888
|
class Data extends Commands {
|
|
@@ -947,7 +940,7 @@ class Data extends Commands {
|
|
|
947
940
|
}
|
|
948
941
|
|
|
949
942
|
/**
|
|
950
|
-
* @author: Leonid Vinikov <
|
|
943
|
+
* @author: Leonid Vinikov <czf.leo123@gmail.com>
|
|
951
944
|
* @description: Responsible for manging internal commands, To serve commands that are not triggered by user.
|
|
952
945
|
*/
|
|
953
946
|
class Internal extends Commands {
|
|
@@ -956,10 +949,6 @@ class Internal extends Commands {
|
|
|
956
949
|
}
|
|
957
950
|
}
|
|
958
951
|
|
|
959
|
-
/**
|
|
960
|
-
* @author: Leonid Vinikov <leonidvinikov@gmail.com>
|
|
961
|
-
*/
|
|
962
|
-
|
|
963
952
|
var index = /*#__PURE__*/Object.freeze({
|
|
964
953
|
__proto__: null,
|
|
965
954
|
Commands: Commands,
|
|
@@ -968,10 +957,6 @@ Data: Data,
|
|
|
968
957
|
Internal: Internal
|
|
969
958
|
});
|
|
970
959
|
|
|
971
|
-
/**
|
|
972
|
-
* @author: Leonid Vinikov <leonidvinikov@gmail.com>
|
|
973
|
-
*/
|
|
974
|
-
|
|
975
960
|
var exported = /*#__PURE__*/Object.freeze({
|
|
976
961
|
__proto__: null,
|
|
977
962
|
commandBases: index$4,
|
|
@@ -984,7 +969,7 @@ utils: index$6
|
|
|
984
969
|
});
|
|
985
970
|
|
|
986
971
|
var name = "@zenflux/core";
|
|
987
|
-
var version = "0.0.0-
|
|
972
|
+
var version = "0.0.0-dev.0";
|
|
988
973
|
var description = "ZenFlux core";
|
|
989
974
|
var author = "Leonid Vinikov <leonidvinikov@gmail.com> (https://github.com/iNewLegend)";
|
|
990
975
|
var scripts = {
|
|
@@ -1003,11 +988,6 @@ var keywords = [
|
|
|
1003
988
|
"manager",
|
|
1004
989
|
"commands manager"
|
|
1005
990
|
];
|
|
1006
|
-
var files = [
|
|
1007
|
-
"dist",
|
|
1008
|
-
"src",
|
|
1009
|
-
"types"
|
|
1010
|
-
];
|
|
1011
991
|
var license = "MIT";
|
|
1012
992
|
var main = "dist/cjs/zenflux-core.js";
|
|
1013
993
|
var unpkg = "dist/umd/zenflux-core.js";
|
|
@@ -1028,6 +1008,7 @@ var devDependencies = {
|
|
|
1028
1008
|
"@types/jest": "^29.2.5",
|
|
1029
1009
|
"@typescript-eslint/eslint-plugin": "^5.48.0",
|
|
1030
1010
|
"@typescript-eslint/parser": "^5.48.0",
|
|
1011
|
+
"@zenflux/rollup": "^0.0.0-dev.0",
|
|
1031
1012
|
"babel-jest": "^29.3.1",
|
|
1032
1013
|
rollup: "^3.9.1",
|
|
1033
1014
|
"ts-jest": "^29.0.3",
|
|
@@ -1044,7 +1025,6 @@ var pkg = {
|
|
|
1044
1025
|
scripts: scripts,
|
|
1045
1026
|
repository: repository,
|
|
1046
1027
|
keywords: keywords,
|
|
1047
|
-
files: files,
|
|
1048
1028
|
license: license,
|
|
1049
1029
|
main: main,
|
|
1050
1030
|
unpkg: unpkg,
|
|
@@ -1090,7 +1070,7 @@ const CoreAPI = {
|
|
|
1090
1070
|
...exported
|
|
1091
1071
|
};
|
|
1092
1072
|
// TODO: Make it available only for development.
|
|
1093
|
-
|
|
1073
|
+
if (!globalThis?.ZenCore) globalThis.ZenCore = CoreAPI;
|
|
1094
1074
|
|
|
1095
1075
|
exports.commandBases = index$4;
|
|
1096
1076
|
exports.core = index$3;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @author: Leonid Vinikov <
|
|
2
|
+
* @author: Leonid Vinikov <czf.leo123@gmail.com>
|
|
3
3
|
* @description: Base for all commands, they are all will be managed by the `Commands` managers.
|
|
4
4
|
* @TODO
|
|
5
5
|
* - Add validateArgs method or find something better.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @author: Leonid Vinikov <
|
|
2
|
+
* @author: Leonid Vinikov <czf.leo123@gmail.com>
|
|
3
3
|
* @description: CommandInternal, is used when part of the logic needed to be in the command but not represent a user action.
|
|
4
4
|
*/
|
|
5
5
|
import CommandBase from "./command-base";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @author: Leonid Vinikov <
|
|
2
|
+
* @author: Leonid Vinikov <czf.leo123@gmail.com>
|
|
3
3
|
* @description: CommandPublic represents a USER action, every class which inherit from this class will USER action.
|
|
4
4
|
* */
|
|
5
5
|
import CommandBase from "./command-base";
|
package/dist/es/src/exports.d.ts
CHANGED
package/dist/es/src/index.d.ts
CHANGED
package/dist/es/zenflux-core.js
CHANGED
|
@@ -10,7 +10,7 @@ class ForceMethod extends Error {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* @author: Leonid Vinikov <
|
|
13
|
+
* @author: Leonid Vinikov <czf.leo123@gmail.com>
|
|
14
14
|
* @description: is base class/object for all classes, responsible for: 'getName', implementation.
|
|
15
15
|
*/
|
|
16
16
|
let IdCounter = 0;
|
|
@@ -87,7 +87,7 @@ hexColorDelta: hexColorDelta
|
|
|
87
87
|
});
|
|
88
88
|
|
|
89
89
|
/**
|
|
90
|
-
* @author: Leonid Vinikov <
|
|
90
|
+
* @author: Leonid Vinikov <czf.leo123@gmail.com>
|
|
91
91
|
* @description: Module for logging instances.
|
|
92
92
|
* @TODO:
|
|
93
93
|
* - Remove `@ts-ignore`, requires a refactor.
|
|
@@ -389,7 +389,7 @@ class Logger {
|
|
|
389
389
|
}
|
|
390
390
|
|
|
391
391
|
/**
|
|
392
|
-
* @author: Leonid Vinikov <
|
|
392
|
+
* @author: Leonid Vinikov <czf.leo123@gmail.com>
|
|
393
393
|
* @description: Base for all commands, they are all will be managed by the `Commands` managers.
|
|
394
394
|
* @TODO
|
|
395
395
|
* - Add validateArgs method or find something better.
|
|
@@ -432,7 +432,7 @@ class CommandBase extends ObjectBase {
|
|
|
432
432
|
}
|
|
433
433
|
|
|
434
434
|
/**
|
|
435
|
-
* @author: Leonid Vinikov <
|
|
435
|
+
* @author: Leonid Vinikov <czf.leo123@gmail.com>
|
|
436
436
|
* @description: CommandPublic represents a USER action, every class which inherit from this class will USER action.
|
|
437
437
|
* */
|
|
438
438
|
class CommandPublic extends CommandBase {
|
|
@@ -455,7 +455,7 @@ get internal () { return internal; }
|
|
|
455
455
|
});
|
|
456
456
|
|
|
457
457
|
/**
|
|
458
|
-
* @author: Leonid Vinikov <
|
|
458
|
+
* @author: Leonid Vinikov <czf.leo123@gmail.com>
|
|
459
459
|
* @description: Each data command should represent a final REST endpoint.
|
|
460
460
|
*/
|
|
461
461
|
class CommandData extends CommandBase {
|
|
@@ -494,7 +494,7 @@ class CommandData extends CommandBase {
|
|
|
494
494
|
}
|
|
495
495
|
|
|
496
496
|
/**
|
|
497
|
-
* @author: Leonid Vinikov <
|
|
497
|
+
* @author: Leonid Vinikov <czf.leo123@gmail.com>
|
|
498
498
|
* @description: CommandInternal, is used when part of the logic needed to be in the command but not represent a user action.
|
|
499
499
|
*/
|
|
500
500
|
class CommandInternal extends CommandBase {
|
|
@@ -503,10 +503,6 @@ class CommandInternal extends CommandBase {
|
|
|
503
503
|
}
|
|
504
504
|
}
|
|
505
505
|
|
|
506
|
-
/**
|
|
507
|
-
* @author: Leonid Vinikov <leonidvinikov@gmail.com>
|
|
508
|
-
*/
|
|
509
|
-
|
|
510
506
|
var index$4 = /*#__PURE__*/Object.freeze({
|
|
511
507
|
__proto__: null,
|
|
512
508
|
CommandBase: CommandBase,
|
|
@@ -516,7 +512,7 @@ CommandPublic: CommandPublic
|
|
|
516
512
|
});
|
|
517
513
|
|
|
518
514
|
/**
|
|
519
|
-
* @author: Leonid Vinikov <
|
|
515
|
+
* @author: Leonid Vinikov <czf.leo123@gmail.com>
|
|
520
516
|
* @description: Responsible for commands, Aka ( CommandsSpace ).
|
|
521
517
|
*/
|
|
522
518
|
class Controller extends ObjectBase {
|
|
@@ -563,7 +559,7 @@ class CommandAlreadyRegistered extends Error {
|
|
|
563
559
|
}
|
|
564
560
|
|
|
565
561
|
/**
|
|
566
|
-
* @author: Leonid Vinikov <
|
|
562
|
+
* @author: Leonid Vinikov <czf.leo123@gmail.com>
|
|
567
563
|
*/
|
|
568
564
|
class CommandNotFound extends Error {
|
|
569
565
|
constructor(command) {
|
|
@@ -591,7 +587,7 @@ Logger: Logger
|
|
|
591
587
|
});
|
|
592
588
|
|
|
593
589
|
/**
|
|
594
|
-
* @author: Leonid Vinikov <
|
|
590
|
+
* @author: Leonid Vinikov <czf.leo123@gmail.com>
|
|
595
591
|
* @description: Responsible for manging/running/hooking commands.
|
|
596
592
|
*/
|
|
597
593
|
class Commands extends ObjectBase {
|
|
@@ -778,7 +774,7 @@ class Commands extends ObjectBase {
|
|
|
778
774
|
}
|
|
779
775
|
|
|
780
776
|
/**
|
|
781
|
-
* @author: Leonid Vinikov <
|
|
777
|
+
* @author: Leonid Vinikov <czf.leo123@gmail.com>
|
|
782
778
|
* @description: Responsible for manging controllers, each controller is global singleton instance.
|
|
783
779
|
*/
|
|
784
780
|
class Controllers extends ObjectBase {
|
|
@@ -802,9 +798,6 @@ class Controllers extends ObjectBase {
|
|
|
802
798
|
}
|
|
803
799
|
}
|
|
804
800
|
|
|
805
|
-
/**
|
|
806
|
-
* @author: Leonid Vinikov <leonidvinikov@gmail.com>
|
|
807
|
-
*/
|
|
808
801
|
var HTTPMethodEnum;
|
|
809
802
|
(function (HTTPMethodEnum) {
|
|
810
803
|
HTTPMethodEnum["DELETE"] = "DELETE";
|
|
@@ -817,7 +810,7 @@ var HTTPMethodEnum;
|
|
|
817
810
|
})(HTTPMethodEnum || (HTTPMethodEnum = {}));
|
|
818
811
|
|
|
819
812
|
/**
|
|
820
|
-
* @author: Leonid Vinikov <
|
|
813
|
+
* @author: Leonid Vinikov <czf.leo123@gmail.com>
|
|
821
814
|
* @description: Providing a simple wrapper for fetch API.
|
|
822
815
|
*/
|
|
823
816
|
class Http extends ObjectBase {
|
|
@@ -885,7 +878,7 @@ class Http extends ObjectBase {
|
|
|
885
878
|
}
|
|
886
879
|
|
|
887
880
|
/**
|
|
888
|
-
* @author: Leonid Vinikov <
|
|
881
|
+
* @author: Leonid Vinikov <czf.leo123@gmail.com>
|
|
889
882
|
* @description: Responsible for manging data commands which are wrappers for HTTP requests.
|
|
890
883
|
*/
|
|
891
884
|
class Data extends Commands {
|
|
@@ -943,7 +936,7 @@ class Data extends Commands {
|
|
|
943
936
|
}
|
|
944
937
|
|
|
945
938
|
/**
|
|
946
|
-
* @author: Leonid Vinikov <
|
|
939
|
+
* @author: Leonid Vinikov <czf.leo123@gmail.com>
|
|
947
940
|
* @description: Responsible for manging internal commands, To serve commands that are not triggered by user.
|
|
948
941
|
*/
|
|
949
942
|
class Internal extends Commands {
|
|
@@ -952,10 +945,6 @@ class Internal extends Commands {
|
|
|
952
945
|
}
|
|
953
946
|
}
|
|
954
947
|
|
|
955
|
-
/**
|
|
956
|
-
* @author: Leonid Vinikov <leonidvinikov@gmail.com>
|
|
957
|
-
*/
|
|
958
|
-
|
|
959
948
|
var index = /*#__PURE__*/Object.freeze({
|
|
960
949
|
__proto__: null,
|
|
961
950
|
Commands: Commands,
|
|
@@ -964,10 +953,6 @@ Data: Data,
|
|
|
964
953
|
Internal: Internal
|
|
965
954
|
});
|
|
966
955
|
|
|
967
|
-
/**
|
|
968
|
-
* @author: Leonid Vinikov <leonidvinikov@gmail.com>
|
|
969
|
-
*/
|
|
970
|
-
|
|
971
956
|
var exported = /*#__PURE__*/Object.freeze({
|
|
972
957
|
__proto__: null,
|
|
973
958
|
commandBases: index$4,
|
|
@@ -980,7 +965,7 @@ utils: index$6
|
|
|
980
965
|
});
|
|
981
966
|
|
|
982
967
|
var name = "@zenflux/core";
|
|
983
|
-
var version = "0.0.0-
|
|
968
|
+
var version = "0.0.0-dev.0";
|
|
984
969
|
var description = "ZenFlux core";
|
|
985
970
|
var author = "Leonid Vinikov <leonidvinikov@gmail.com> (https://github.com/iNewLegend)";
|
|
986
971
|
var scripts = {
|
|
@@ -999,11 +984,6 @@ var keywords = [
|
|
|
999
984
|
"manager",
|
|
1000
985
|
"commands manager"
|
|
1001
986
|
];
|
|
1002
|
-
var files = [
|
|
1003
|
-
"dist",
|
|
1004
|
-
"src",
|
|
1005
|
-
"types"
|
|
1006
|
-
];
|
|
1007
987
|
var license = "MIT";
|
|
1008
988
|
var main = "dist/cjs/zenflux-core.js";
|
|
1009
989
|
var unpkg = "dist/umd/zenflux-core.js";
|
|
@@ -1024,6 +1004,7 @@ var devDependencies = {
|
|
|
1024
1004
|
"@types/jest": "^29.2.5",
|
|
1025
1005
|
"@typescript-eslint/eslint-plugin": "^5.48.0",
|
|
1026
1006
|
"@typescript-eslint/parser": "^5.48.0",
|
|
1007
|
+
"@zenflux/rollup": "^0.0.0-dev.0",
|
|
1027
1008
|
"babel-jest": "^29.3.1",
|
|
1028
1009
|
rollup: "^3.9.1",
|
|
1029
1010
|
"ts-jest": "^29.0.3",
|
|
@@ -1040,7 +1021,6 @@ var pkg = {
|
|
|
1040
1021
|
scripts: scripts,
|
|
1041
1022
|
repository: repository,
|
|
1042
1023
|
keywords: keywords,
|
|
1043
|
-
files: files,
|
|
1044
1024
|
license: license,
|
|
1045
1025
|
main: main,
|
|
1046
1026
|
unpkg: unpkg,
|
|
@@ -1086,6 +1066,6 @@ const CoreAPI = {
|
|
|
1086
1066
|
...exported
|
|
1087
1067
|
};
|
|
1088
1068
|
// TODO: Make it available only for development.
|
|
1089
|
-
|
|
1069
|
+
if (!globalThis?.ZenCore) globalThis.ZenCore = CoreAPI;
|
|
1090
1070
|
|
|
1091
1071
|
export { index$4 as commandBases, index$3 as core, CoreAPI as default, index$2 as errors, index as managerBases, index$5 as managers, index$1 as modules, index$6 as utils };
|
package/dist/es/zenflux-core.mjs
CHANGED
|
@@ -4,9 +4,9 @@ class t extends Error{constructor(t,e){super(`ForeMethod implementation: at '${t
|
|
|
4
4
|
*
|
|
5
5
|
* @copyright https://stackoverflow.com/a/53731154
|
|
6
6
|
*/
|
|
7
|
-
const
|
|
7
|
+
const o=()=>{const t=new WeakSet;return(e,r)=>{if("object"==typeof r&&null!==r){if(t.has(r))return;t.add(r)}return r}},n=function(t,e){t=t.replace("#",""),e=e.replace("#","");const r=parseInt(t.substring(0,2),16),s=parseInt(t.substring(2,4),16),o=parseInt(t.substring(4,6),16),n=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-n),l=255-Math.abs(s-a),h=255-Math.abs(o-i);return c/=255,l/=255,h/=255,(c+l+h)/3};
|
|
8
8
|
/**
|
|
9
9
|
* Function hexColorDelta() : Return color difference in ratio decimal point.
|
|
10
10
|
*
|
|
11
11
|
* @copyright http://jsfiddle.net/96sME/
|
|
12
|
-
*/var a=Object.freeze({__proto__:null,getCircularReplacer:n,hexColorDelta:o});class i{static wrappers={};static wrapperDepth=0;static sharedData={};static colorsInUse=[];defaultStyle;color;outputHandler;args={};name;state=!1;static getName(){return"Core/Modules/Logger"}static reset(){i.wrappers={},i.wrapperDepth=0,i.colorsInUse=[],i.sharedData={}}static createCustomWrapper(t,e){i.wrappers[t]||(i.wrappers[t.name]=[]),i.wrappers[t.name].push({classType:t,callback:e})}static getCallerName(){const t=Error(),e=t.stack?t.stack.split("\n")[3].trim():"_UNKNOWN_CALLER_NAME_";return e.startsWith("at new")?"constructor":e.split(".")[1].split(" ")[0]}static getFunctionView(t){let e="anonymous function()";return"string"!=typeof t&&0!==t.name.length&&(e=t.name.split(" ")[1]+"()"),e}constructor(t,e=!1,r={}){"off"!==globalThis.process?.env.flow_modules_logger&&(this.state=e,this.args=r,this.name="",this.name="string"==typeof t?t:t.constructor.name,e&&this.initialize())}initialize(){this.args.sameColor?(i.sharedData[this.name]||(i.sharedData[this.name]=this.getRandomColor()),this.color=i.sharedData[this.name]):(this.color=this.getRandomColor(),i.colorsInUse.push(this.color)),this.outputHandler=console.log,this.defaultStyle=["color: grey;font-size:7px","display: block","color: "+this.color,"color: grey","font-weight: bold","color: #607D8B","font-size: 16px;color: red;font-weight:800"]}setOutputHandler(t){this.outputHandler=t}useWrapper(t,e=!0){if(!t||"object"!=typeof t||Array.isArray(t))return t;i.wrapperDepth++;let r={...t};return Object.values(i.wrappers).forEach((([e])=>{t instanceof e.classType&&(r=e.callback(t)||r)})),4>i.wrapperDepth?(e&&r&&Object.entries(r).forEach((([t,e])=>{r[t]=this.useWrapper(e,!0)})),i.wrapperDepth--,r):(i.wrapperDepth--,r)}startEmpty(t=""){this.state&&this.printFunctionNotify("se",i.getCallerName(),t)}startWith(t){if(!this.state)return;t=Object.assign({},t);const e="se",r=i.getCallerName();if("string"==typeof t)this.printInLineString(e,r,t);else if(1===Object.keys(t).length){const s=Object.keys(t)[0];let n=Object.values(t)[0];"object"==typeof n?this.printNextLineObject(e,r,s,n||{}):"function"==typeof n?this.printInLineFunction(e,r,s,n):this.printInLineElement(e,r,s,n)}else this.printMultiLineObject(e,r,t)}object(t={},e=""){if(!this.state)return;const r=i.getCallerName();t=Object.create(t);for(let s in t)"object"==typeof t[s]&&(t[s]=JSON.stringify(this.useWrapper(t[s]),n())),this.out.apply(this,[`%c(ob)-> %c%c${this.name}%c::%c${r}%c() [${e}] ->> ${s}: '${t[s]}'%c`].concat(this.defaultStyle))}debug(t){this.state&&this.printFunctionNotify("db",i.getCallerName(),t)}drop(t,e){if(!this.state)return;const r=i.getCallerName();for(let e in t)this.out.apply(this,[`%c(dr)-> %c%c${this.name}%c::%c${r}%c() ->> corresponding ${e}: '${t[e]}' RESULT: %c↓`].concat(this.defaultStyle));this.out(e)}throw(t,e="null",r={}){throw this.printFunctionNotify("tw",i.getCallerName(),t),r&&this.printNextLineObject("tw",i.getCallerName(),e,r),Error().stack}clone(){return Object.assign(Object.create(Object.getPrototypeOf(this)),this)}printFunctionNotify(t,e,r){this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c() ${r}%c`].concat(this.defaultStyle))}printInLineElement(t,e,r,s){this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c() ->> ${r}: '${s}'%c`].concat(this.defaultStyle))}printInLineFunction(t,e,r,s){s=i.getFunctionView(s),this.printInLineElement(t,e,r,s)}printInLineString(t,e,r){this.printInLineElement(t,e,"(string)",r)}printNextLineObject(t,e,r,s){s=this.useWrapper(s),this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c() ->> ${r} %c↓`].concat(this.defaultStyle)),this.out(s)}printMultiLineObject(t,e,r){this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c(${Object.keys(r).join(", ")}) %c↓`].concat(this.defaultStyle));for(let t in r){let e=r[t];"object"==typeof e?e=JSON.stringify(this.useWrapper(e),n()):"function"==typeof r[t]&&(e=i.getFunctionView(e)),this.out.call(this,"%c"+t+": `"+this.useWrapper(e)+"`","color: #a3a3a3")}}getRandomColor(){let t="#";for(let e=0;6>e;e++)t+="0123456789ABCDEF"[Math.floor(16*Math.random())];return i.colorsInUse.some((e=>o(t,e)>=.8))?this.getRandomColor():t}out(...t){this.outputHandler.apply(this,t)}}class c extends s{args={};options={};logger;constructor(t={},e={}){super();const r=this.constructor.getName();this.logger=new i(r,!0,{sameColor:!0}),this.logger.startWith({args:t,options:e}),this.initialize(t,e)}initialize(t,e){this.args=t,this.options=e}apply(t=this.args,r=this.options){throw new e(this,"apply")}async run(){this.onBeforeApply&&this.onBeforeApply();const t=await this.apply(this.args,this.options);return this.onAfterApply&&this.onAfterApply(),t}getArgs(){return this.args}getOptions(){return this.options}}let l={},h={},u={},p={};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 k extends s{logger;apiBaseUrl;static getName(){return"Core/Clients/Http"}constructor(t="http://localhost"){super(),this.logger=new i(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={};[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 E extends O{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=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 H extends O{static getName(){return"Core/Managers/Internal"}}var _=Object.freeze({__proto__:null,Commands:O,Controllers:A,Data:E,Internal:H}),j=Object.freeze({__proto__:null,commandBases:m,core:d,errors:N,managerBases:_,managers:g,modules:w,utils:a}),I="0.0.0-abc.0";let $=!1;function B(){if($)throw Error("ZenCore is already initialized.")}B();let M={version:I};const T=[],U={initialize:t=>{B(),M=t||M,l=new O,h=new A,u=new E(M),p=new H,$=!0,T.forEach((t=>t()))},destroy:()=>{$=!1,l={},h={},u={},p={}},onAfterInitialize:t=>{T.push(t)},config:M,...j};export{m as commandBases,d as core,U as default,N as errors,_ as managerBases,g as managers,w as modules,a as utils};
|
|
12
|
+
*/var a=Object.freeze({__proto__:null,getCircularReplacer:o,hexColorDelta:n});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 o=Object.values(t)[0];"object"==typeof o?this.printNextLineObject(e,r,s,o||{}):"function"==typeof o?this.printInLineFunction(e,r,s,o):this.printInLineElement(e,r,s,o)}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]),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",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),o()):"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=>n(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={},h={},u={},p={};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 o=0;s>o;++o){const s=!0===r.pop?t.pop():t[o];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 k extends s{logger;apiBaseUrl;static getName(){return"Core/Clients/Http"}constructor(t="http://localhost"){super(),this.logger=new i(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"},o={};[b.POST,b.PUT,b.PATCH].includes(e)?(Object.assign(o,{"Content-Type":"application/json"}),Object.assign(s,{method:e,headers:o,body:JSON.stringify(r)})):Object.assign(s,{headers:o});const n=await globalThis.fetch(this.apiBaseUrl+t,s);let a;try{a=await n.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 O{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=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 H extends O{static getName(){return"Core/Managers/Internal"}}var _=Object.freeze({__proto__:null,Commands:O,Controllers:A,Data:E,Internal:H}),j=Object.freeze({__proto__:null,commandBases:m,core:d,errors:N,managerBases:_,managers:g,modules:w,utils:a}),I="0.0.0-dev.0";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 E(T),p=new H,$=!0,M.forEach((t=>t()))},destroy:()=>{$=!1,l={},h={},u={},p={}},onAfterInitialize:t=>{M.push(t)},config:T,...j};globalThis?.ZenCore||(globalThis.ZenCore=U);export{m as commandBases,d as core,U as default,N as errors,_ as managerBases,g as managers,w as modules,a as utils};
|
package/dist/umd/zenflux-core.js
CHANGED
|
@@ -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 i=Object.freeze({__proto__:null,getCircularReplacer:n,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 o=Object.values(t)[0];"object"==typeof o?this.printNextLineObject(e,r,s,o||{}):"function"==typeof o?this.printInLineFunction(e,r,s,o):this.printInLineElement(e,r,s,o)}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]),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",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),n()):"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 o{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={},u={},p={},g={};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 o{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:o});class y extends Error{constructor(t){super(`Command: '${t.getName()}' is already registered`)}}class C 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:y,CommandNotFound:C,ControllerAlreadyRegistered:b,ForceMethod:r}),O=Object.freeze({__proto__:null,Logger:c});class A extends o{static trace=[];current={};currentArgs={};trace=[];commands={};onBeforeHooks={};onBeforeUIHooks={};onAfterHooks={};onAfterOnceHooks={};onAfterUIHooks={};onAfterAffectHooks={};logger;static getName(){return"Core/Managers/Commands"}static async runCallbacks(t,e={},r={}){const s=t?.length||0;for(let o=0;s>o;++o){const s=!0===r.pop?t.pop():t[o];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 y(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){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 k extends o{controllers={};static getName(){return"Core/Managers/Controllers"}get(t){return this.controllers[t]}getAll(){return this.controllers}register(t){if(this.controllers[t.getName()])throw new 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 E extends o{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"},o={};[N.POST,N.PUT,N.PATCH].includes(e)?(Object.assign(o,{"Content-Type":"application/json"}),Object.assign(s,{method:e,headers:o,body:JSON.stringify(r)})):Object.assign(s,{headers:o});const n=await globalThis.fetch(this.apiBaseUrl+t,s);let a;try{a=await n.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 _ extends A{static client;currentHttpMethod;static getName(){return"Core/Managers/Data"}constructor(t){super(),_.client=new E(t.baseURL)}getClient(){return _.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 j extends A{static getName(){return"Core/Managers/Internal"}}var H=Object.freeze({__proto__:null,Commands:A,Controllers:k,Data:_,Internal:j}),I=Object.freeze({__proto__:null,commandBases:d,core:f,errors:w,managerBases:H,managers:m,modules:O,utils:i}),$="0.0.0-abc.0";let B=!1;function T(){if(B)throw Error("ZenCore is already initialized.")}T();let M={version:$};const x=[],U={initialize:t=>{T(),M=t||M,h=new A,u=new k,p=new _(M),g=new j,B=!0,x.forEach((t=>t()))},destroy:()=>{B=!1,h={},u={},p={},g={}},onAfterInitialize:t=>{x.push(t)},config:M,...I};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:n,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 o=Object.values(t)[0];"object"==typeof o?this.printNextLineObject(e,r,s,o||{}):"function"==typeof o?this.printInLineFunction(e,r,s,o):this.printInLineElement(e,r,s,o)}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]),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",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),n()):"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 o{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={},u={},p={},g={};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 o{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:o});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 o{static trace=[];current={};currentArgs={};trace=[];commands={};onBeforeHooks={};onBeforeUIHooks={};onAfterHooks={};onAfterOnceHooks={};onAfterUIHooks={};onAfterAffectHooks={};logger;static getName(){return"Core/Managers/Commands"}static async runCallbacks(t,e={},r={}){const s=t?.length||0;for(let o=0;s>o;++o){const s=!0===r.pop?t.pop():t[o];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 k extends o{controllers={};static getName(){return"Core/Managers/Controllers"}get(t){return this.controllers[t]}getAll(){return this.controllers}register(t){if(this.controllers[t.getName()])throw new 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 E extends o{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"},o={};[N.POST,N.PUT,N.PATCH].includes(e)?(Object.assign(o,{"Content-Type":"application/json"}),Object.assign(s,{method:e,headers:o,body:JSON.stringify(r)})):Object.assign(s,{headers:o});const n=await globalThis.fetch(this.apiBaseUrl+t,s);let a;try{a=await n.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 _ extends A{static client;currentHttpMethod;static getName(){return"Core/Managers/Data"}constructor(t){super(),_.client=new E(t.baseURL)}getClient(){return _.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 j extends A{static getName(){return"Core/Managers/Internal"}}var H=Object.freeze({__proto__:null,Commands:A,Controllers:k,Data:_,Internal:j}),I=Object.freeze({__proto__:null,commandBases:d,core:f,errors:w,managerBases:H,managers:m,modules:O,utils:i}),$="0.0.0-dev.0";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 k,p=new _(M),g=new j,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})}));
|
package/package.json
CHANGED
package/src/initializer.ts
CHANGED