@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.
@@ -2,45 +2,87 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- if (typeof __ZEN_MANAGERS__ === 'undefined' || !__ZEN_MANAGERS__) {
6
- // @ts-ignore
7
- globalThis.__ZEN_MANAGERS__ = {};
8
- }
9
-
10
- class ForceMethodBase extends Error {
11
- constructor(className, methodName) {
12
- super(`ForeMethod implementation: at '${className}' method: '${methodName}'`);
13
- }
14
- }
15
- class ForceMethod extends Error {
16
- constructor(context, methodName) {
17
- super(`ForeMethod implementation: at '${context.getName()}' method: '${methodName}'`);
18
- }
19
- }
5
+ var name = "@zenflux/core";
6
+ var version = "0.0.0-abc.14";
7
+ var description = "ZenFlux core";
8
+ var author = "Leonid Vinikov <leonidvinikov@gmail.com> (https://github.com/iNewLegend)";
9
+ var scripts = {
10
+ test: "export flow_modules_logger=off && jest",
11
+ build: "rollup --config rollup.config.ts --configPlugin typescript",
12
+ watch: "rollup --config rollup.config.ts --configPlugin typescript --watch"
13
+ };
14
+ var repository = {
15
+ type: "git",
16
+ url: "git+https://github.com/zenflux/core.git"
17
+ };
18
+ var keywords = [
19
+ "zenflux",
20
+ "zen",
21
+ "flux",
22
+ "commands",
23
+ "manager",
24
+ "commands manager"
25
+ ];
26
+ var files = [
27
+ "dist",
28
+ "src",
29
+ "types"
30
+ ];
31
+ var license = "MIT";
32
+ var main = "dist/cjs/zenflux-core.js";
33
+ var unpkg = "dist/umd/zenflux-core.js";
34
+ var module$1 = "dist/es/zenflux-core.js";
35
+ var types = "types/index.d.ts";
36
+ var devDependencies = {
37
+ "@babel/core": "^7.20.7",
38
+ "@babel/plugin-transform-runtime": "^7.19.6",
39
+ "@babel/preset-env": "^7.20.2",
40
+ "@babel/preset-typescript": "^7.18.6",
41
+ "@babel/runtime": "^7.20.7",
42
+ "@rollup/plugin-babel": "^6.0.3",
43
+ "@rollup/plugin-json": "^6.0.0",
44
+ "@rollup/plugin-node-resolve": "^15.0.1",
45
+ "@rollup/plugin-replace": "^5.0.2",
46
+ "@rollup/plugin-terser": "^0.2.1",
47
+ "@rollup/plugin-typescript": "^10.0.1",
48
+ "@types/jest": "^29.2.5",
49
+ "@typescript-eslint/eslint-plugin": "^5.48.0",
50
+ "@typescript-eslint/parser": "^5.48.0",
51
+ "babel-jest": "^29.3.1",
52
+ rollup: "^3.9.1",
53
+ "ts-jest": "^29.0.3",
54
+ tslib: "^2.4.1"
55
+ };
56
+ var dependencies = {
57
+ "@babel/runtime": "^7.19.0"
58
+ };
59
+ var pkg = {
60
+ name: name,
61
+ version: version,
62
+ description: description,
63
+ author: author,
64
+ scripts: scripts,
65
+ repository: repository,
66
+ keywords: keywords,
67
+ files: files,
68
+ license: license,
69
+ main: main,
70
+ unpkg: unpkg,
71
+ module: module$1,
72
+ types: types,
73
+ devDependencies: devDependencies,
74
+ dependencies: dependencies
75
+ };
20
76
 
21
- /**
22
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
23
- * @description: is base class/object for all classes, responsible for: 'getName', implementation.
24
- */
25
- let IdCounter = 0;
26
- /**
27
- * Base class 4 *
28
- */
29
- class ObjectBase {
30
- virtualId = 0;
31
- static getName() {
32
- throw new ForceMethodBase("ObjectBase", "getName");
33
- }
34
- constructor() {
35
- this.virtualId = IdCounter;
36
- APIIncreaseIdCounter();
37
- }
38
- getName() {
39
- return this.constructor.getName();
40
- }
41
- }
42
- function APIIncreaseIdCounter() {
43
- return IdCounter++;
77
+ if (typeof __ZEN_MANAGERS__ === 'undefined' || !__ZEN_MANAGERS__) {
78
+ globalThis.__ZEN_MANAGERS__ = {
79
+ initialize: () => {},
80
+ destroy: () => {},
81
+ commands: {},
82
+ controllers: {},
83
+ data: {},
84
+ internal: {}
85
+ };
44
86
  }
45
87
 
46
88
  /**
@@ -397,120 +439,47 @@ class Logger {
397
439
  }
398
440
  }
399
441
 
400
- /**
401
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
402
- * @description: Base for all commands, they are all will be managed by the `Commands` managers.
403
- * @TODO
404
- * - Add validateArgs method or find something better.
405
- */
406
- class CommandBase extends ObjectBase {
407
- args = {};
408
- options = {};
409
- logger;
410
- constructor(args = {}, options = {}) {
411
- super();
412
- const name = this.constructor.getName();
413
- this.logger = new Logger(name, true, {
414
- sameColor: true
415
- });
416
- this.logger.startWith({
417
- args,
418
- options
419
- });
420
- this.initialize(args, options);
421
- }
422
- initialize(args, options) {
423
- this.args = args;
424
- this.options = options;
425
- }
426
- apply(args = this.args, options = this.options) {
427
- throw new ForceMethod(this, "apply");
428
- }
429
- async run() {
430
- this.onBeforeApply && this.onBeforeApply();
431
- const result = await this.apply(this.args, this.options);
432
- this.onAfterApply && this.onAfterApply();
433
- return result;
434
- }
435
- getArgs() {
436
- return this.args;
437
- }
438
- getOptions() {
439
- return this.options;
442
+ var index$5 = /*#__PURE__*/Object.freeze({
443
+ __proto__: null,
444
+ Logger: Logger
445
+ });
446
+
447
+ class ForceMethodBase extends Error {
448
+ constructor(className, methodName) {
449
+ super(`ForeMethod implementation: at '${className}' method: '${methodName}'`);
440
450
  }
441
451
  }
442
-
443
- /**
444
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
445
- * @description: CommandPublic represents a USER action, every class which inherit from this class will USER action.
446
- * */
447
- class CommandPublic extends CommandBase {
448
- static getName() {
449
- return 'Core/CommandBases/CommandPublic';
452
+ class ForceMethod extends Error {
453
+ constructor(context, methodName) {
454
+ super(`ForeMethod implementation: at '${context.getName()}' method: '${methodName}'`);
450
455
  }
451
456
  }
452
457
 
453
458
  /**
454
459
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
455
- * @description: Each data command should represent a final REST endpoint.
460
+ * @description: is base class/object for all classes, responsible for: 'getName', implementation.
456
461
  */
457
- class CommandData extends CommandBase {
462
+ let IdCounter = 0;
463
+ /**
464
+ * Base class 4 *
465
+ */
466
+ class ObjectBase {
467
+ virtualId = 0;
458
468
  static getName() {
459
- return 'Core/CommandBases/CommandData';
460
- }
461
- /**
462
- * Function getEndpoint() : Override this method is required to determine endpoint and magic query params.
463
- * @example
464
- * ```
465
- * args = { query: { id: 1 } };
466
- * getEndpoint() = '/api/v1/users/{id}';
467
- * result = '/api/v1/users/1';
468
- * ```
469
- */
470
- getEndpoint() {
471
- throw new ForceMethod(this, 'getEndpoint');
469
+ throw new ForceMethodBase("ObjectBase", "getName");
472
470
  }
473
- apply(args = this.args, options = this.options) {
474
- const endpoint = this.applyEndpointFormat(this.getEndpoint(), args);
475
- return __ZEN_MANAGERS__.data.getClient().fetch(endpoint, __ZEN_MANAGERS__.data.currentHttpMethod, args || null);
471
+ constructor() {
472
+ this.virtualId = IdCounter;
473
+ APIIncreaseIdCounter();
476
474
  }
477
- applyEndpointFormat(endpoint, data = {}) {
478
- // Replace query with `magic` placeholders.
479
- if (endpoint.includes('{')) {
480
- endpoint = endpoint.split('/').map(endpointPart => {
481
- const match = endpointPart.match('\\{(.*?)\\}');
482
- if (match?.length && 'undefined' !== typeof data[match[1]]) {
483
- return data[match[1]];
484
- }
485
- return endpointPart;
486
- }).join('/');
487
- }
488
- return endpoint;
475
+ getName() {
476
+ return this.constructor.getName();
489
477
  }
490
478
  }
491
-
492
- /**
493
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
494
- * @description: CommandInternal, is used when part of the logic needed to be in the command but not represent a user action.
495
- */
496
- class CommandInternal extends CommandBase {
497
- static getName() {
498
- return 'Core/CommandBases/CommandInternal';
499
- }
479
+ function APIIncreaseIdCounter() {
480
+ return IdCounter++;
500
481
  }
501
482
 
502
- /**
503
- * @author: Leonid Vinikov <leonidvinikov@gmail.com>
504
- */
505
-
506
- var index$5 = /*#__PURE__*/Object.freeze({
507
- __proto__: null,
508
- CommandBase: CommandBase,
509
- CommandData: CommandData,
510
- CommandInternal: CommandInternal,
511
- CommandPublic: CommandPublic
512
- });
513
-
514
483
  /**
515
484
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
516
485
  * @description: Responsible for commands, Aka ( CommandsSpace ).
@@ -581,11 +550,6 @@ ControllerAlreadyRegistered: ControllerAlreadyRegistered,
581
550
  ForceMethod: ForceMethod
582
551
  });
583
552
 
584
- var index$2 = /*#__PURE__*/Object.freeze({
585
- __proto__: null,
586
- Logger: Logger
587
- });
588
-
589
553
  /**
590
554
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
591
555
  * @description: Responsible for manging/running/hooking commands.
@@ -951,6 +915,7 @@ class Internal extends Commands {
951
915
  /**
952
916
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
953
917
  */
918
+ const afterInitializeCallbacks = [];
954
919
  function initialize(config) {
955
920
  __ZEN_MANAGERS__.commands = new Commands();
956
921
  __ZEN_MANAGERS__.controllers = new Controllers();
@@ -967,9 +932,12 @@ const controllers = __ZEN_MANAGERS__.controllers;
967
932
  const commands = __ZEN_MANAGERS__.commands;
968
933
  const data = __ZEN_MANAGERS__.data;
969
934
  const internal = __ZEN_MANAGERS__.internal;
935
+ __ZEN_MANAGERS__.initialize = initialize;
936
+ __ZEN_MANAGERS__.destroy = destroy;
970
937
 
971
- var index$1 = /*#__PURE__*/Object.freeze({
938
+ var index$2 = /*#__PURE__*/Object.freeze({
972
939
  __proto__: null,
940
+ afterInitializeCallbacks: afterInitializeCallbacks,
973
941
  commands: commands,
974
942
  controllers: controllers,
975
943
  data: data,
@@ -978,6 +946,120 @@ initialize: initialize,
978
946
  internal: internal
979
947
  });
980
948
 
949
+ /**
950
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
951
+ * @description: Base for all commands, they are all will be managed by the `Commands` managers.
952
+ * @TODO
953
+ * - Add validateArgs method or find something better.
954
+ */
955
+ class CommandBase extends ObjectBase {
956
+ args = {};
957
+ options = {};
958
+ logger;
959
+ constructor(args = {}, options = {}) {
960
+ super();
961
+ const name = this.constructor.getName();
962
+ this.logger = new Logger(name, true, {
963
+ sameColor: true
964
+ });
965
+ this.logger.startWith({
966
+ args,
967
+ options
968
+ });
969
+ this.initialize(args, options);
970
+ }
971
+ initialize(args, options) {
972
+ this.args = args;
973
+ this.options = options;
974
+ }
975
+ apply(args = this.args, options = this.options) {
976
+ throw new ForceMethod(this, "apply");
977
+ }
978
+ async run() {
979
+ this.onBeforeApply && this.onBeforeApply();
980
+ const result = await this.apply(this.args, this.options);
981
+ this.onAfterApply && this.onAfterApply();
982
+ return result;
983
+ }
984
+ getArgs() {
985
+ return this.args;
986
+ }
987
+ getOptions() {
988
+ return this.options;
989
+ }
990
+ }
991
+
992
+ /**
993
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
994
+ * @description: CommandPublic represents a USER action, every class which inherit from this class will USER action.
995
+ * */
996
+ class CommandPublic extends CommandBase {
997
+ static getName() {
998
+ return 'Core/CommandBases/CommandPublic';
999
+ }
1000
+ }
1001
+
1002
+ /**
1003
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
1004
+ * @description: Each data command should represent a final REST endpoint.
1005
+ */
1006
+ class CommandData extends CommandBase {
1007
+ static getName() {
1008
+ return 'Core/CommandBases/CommandData';
1009
+ }
1010
+ /**
1011
+ * Function getEndpoint() : Override this method is required to determine endpoint and magic query params.
1012
+ * @example
1013
+ * ```
1014
+ * args = { query: { id: 1 } };
1015
+ * getEndpoint() = '/api/v1/users/{id}';
1016
+ * result = '/api/v1/users/1';
1017
+ * ```
1018
+ */
1019
+ getEndpoint() {
1020
+ throw new ForceMethod(this, 'getEndpoint');
1021
+ }
1022
+ apply(args = this.args, options = this.options) {
1023
+ const endpoint = this.applyEndpointFormat(this.getEndpoint(), args);
1024
+ return __ZEN_MANAGERS__.data.getClient().fetch(endpoint, __ZEN_MANAGERS__.data.currentHttpMethod, args || null);
1025
+ }
1026
+ applyEndpointFormat(endpoint, data = {}) {
1027
+ // Replace query with `magic` placeholders.
1028
+ if (endpoint.includes('{')) {
1029
+ endpoint = endpoint.split('/').map(endpointPart => {
1030
+ const match = endpointPart.match('\\{(.*?)\\}');
1031
+ if (match?.length && 'undefined' !== typeof data[match[1]]) {
1032
+ return data[match[1]];
1033
+ }
1034
+ return endpointPart;
1035
+ }).join('/');
1036
+ }
1037
+ return endpoint;
1038
+ }
1039
+ }
1040
+
1041
+ /**
1042
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
1043
+ * @description: CommandInternal, is used when part of the logic needed to be in the command but not represent a user action.
1044
+ */
1045
+ class CommandInternal extends CommandBase {
1046
+ static getName() {
1047
+ return 'Core/CommandBases/CommandInternal';
1048
+ }
1049
+ }
1050
+
1051
+ /**
1052
+ * @author: Leonid Vinikov <leonidvinikov@gmail.com>
1053
+ */
1054
+
1055
+ var index$1 = /*#__PURE__*/Object.freeze({
1056
+ __proto__: null,
1057
+ CommandBase: CommandBase,
1058
+ CommandData: CommandData,
1059
+ CommandInternal: CommandInternal,
1060
+ CommandPublic: CommandPublic
1061
+ });
1062
+
981
1063
  /**
982
1064
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
983
1065
  */
@@ -996,87 +1078,15 @@ Internal: Internal
996
1078
 
997
1079
  var exported = /*#__PURE__*/Object.freeze({
998
1080
  __proto__: null,
999
- commandBases: index$5,
1081
+ commandBases: index$1,
1000
1082
  core: index$4,
1001
1083
  errors: index$3,
1002
1084
  managerBases: index,
1003
- managers: index$1,
1004
- modules: index$2,
1085
+ managers: index$2,
1086
+ modules: index$5,
1005
1087
  utils: index$6
1006
1088
  });
1007
1089
 
1008
- var name = "@zenflux/core";
1009
- var version = "0.0.0-abc.7";
1010
- var description = "ZenFlux core";
1011
- var author = "Leonid Vinikov <leonidvinikov@gmail.com> (https://github.com/iNewLegend)";
1012
- var scripts = {
1013
- test: "export flow_modules_logger=off && jest",
1014
- build: "rollup --config rollup.config.ts --configPlugin typescript",
1015
- watch: "rollup --config rollup.config.ts --configPlugin typescript --watch"
1016
- };
1017
- var repository = {
1018
- type: "git",
1019
- url: "git+https://github.com/zenflux/core.git"
1020
- };
1021
- var keywords = [
1022
- "zenflux",
1023
- "zen",
1024
- "flux",
1025
- "commands",
1026
- "manager",
1027
- "commands manager"
1028
- ];
1029
- var files = [
1030
- "dist",
1031
- "src",
1032
- "types"
1033
- ];
1034
- var license = "MIT";
1035
- var main = "dist/cjs/zenflux-core.js";
1036
- var unpkg = "dist/umd/zenflux-core.js";
1037
- var module$1 = "dist/es/zenflux-core.js";
1038
- var types = "types/index.d.ts";
1039
- var devDependencies = {
1040
- "@babel/core": "^7.20.7",
1041
- "@babel/plugin-transform-runtime": "^7.19.6",
1042
- "@babel/preset-env": "^7.20.2",
1043
- "@babel/preset-typescript": "^7.18.6",
1044
- "@babel/runtime": "^7.20.7",
1045
- "@rollup/plugin-babel": "^6.0.3",
1046
- "@rollup/plugin-json": "^6.0.0",
1047
- "@rollup/plugin-node-resolve": "^15.0.1",
1048
- "@rollup/plugin-replace": "^5.0.2",
1049
- "@rollup/plugin-terser": "^0.2.1",
1050
- "@rollup/plugin-typescript": "^10.0.1",
1051
- "@types/jest": "^29.2.5",
1052
- "@typescript-eslint/eslint-plugin": "^5.48.0",
1053
- "@typescript-eslint/parser": "^5.48.0",
1054
- "babel-jest": "^29.3.1",
1055
- rollup: "^3.9.1",
1056
- "ts-jest": "^29.0.3",
1057
- tslib: "^2.4.1"
1058
- };
1059
- var dependencies = {
1060
- "@babel/runtime": "^7.19.0"
1061
- };
1062
- var pkg = {
1063
- name: name,
1064
- version: version,
1065
- description: description,
1066
- author: author,
1067
- scripts: scripts,
1068
- repository: repository,
1069
- keywords: keywords,
1070
- files: files,
1071
- license: license,
1072
- main: main,
1073
- unpkg: unpkg,
1074
- module: module$1,
1075
- types: types,
1076
- devDependencies: devDependencies,
1077
- dependencies: dependencies
1078
- };
1079
-
1080
1090
  let isInitialized = false;
1081
1091
  function errorInitTwice() {
1082
1092
  if (isInitialized) {
@@ -1087,14 +1097,12 @@ errorInitTwice();
1087
1097
  let config = {
1088
1098
  version: pkg.version
1089
1099
  };
1090
- const afterInitializeCallbacks = [];
1091
1100
  const CoreAPI = {
1092
1101
  initialize: configuration => {
1093
1102
  errorInitTwice();
1094
1103
  config = configuration || config;
1095
1104
  initialize(config);
1096
1105
  isInitialized = true;
1097
- afterInitializeCallbacks.forEach(callback => callback());
1098
1106
  },
1099
1107
  destroy: () => {
1100
1108
  destroy();
@@ -1110,11 +1118,11 @@ const CoreAPI = {
1110
1118
  // TODO: Make it available only for development.
1111
1119
  if (!globalThis?.ZenCore) globalThis.ZenCore = CoreAPI;
1112
1120
 
1113
- exports.commandBases = index$5;
1121
+ exports.commandBases = index$1;
1114
1122
  exports.core = index$4;
1115
1123
  exports.default = CoreAPI;
1116
1124
  exports.errors = index$3;
1117
1125
  exports.managerBases = index;
1118
- exports.managers = index$1;
1119
- exports.modules = index$2;
1126
+ exports.managers = index$2;
1127
+ exports.modules = index$5;
1120
1128
  exports.utils = index$6;
@@ -7,6 +7,8 @@ declare global {
7
7
  }
8
8
  declare global {
9
9
  var __ZEN_MANAGERS__: {
10
+ initialize: (config: any) => void;
11
+ destroy: () => void;
10
12
  commands: Commands;
11
13
  controllers: Controllers;
12
14
  data: Data;
@@ -1,6 +1,5 @@
1
1
  /**
2
2
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
3
3
  */
4
- import './globals';
5
- export * from './exports';
6
4
  export { CoreAPI as default } from "./initializer";
5
+ export * from './exports';
@@ -1,8 +1,11 @@
1
- import * as exported from './exports';
1
+ import './globals';
2
2
  import { IAPIConfig } from "./interfaces/config";
3
+ import * as exported from './exports';
3
4
  export declare let config: IAPIConfig;
4
5
  export declare const CoreAPI: {
5
6
  managers: {
7
+ initialize: (config: any) => void;
8
+ destroy: () => void;
6
9
  commands: exported.managerBases.Commands;
7
10
  controllers: exported.managerBases.Controllers;
8
11
  data: exported.managerBases.Data;
@@ -0,0 +1,13 @@
1
+ import Commands from "../manager-bases/commands";
2
+ import Controllers from "../manager-bases/controllers";
3
+ import Data from "../manager-bases/data";
4
+ import Internal from "../manager-bases/internal";
5
+ import { IAPIConfig } from "./config";
6
+ export interface IManagers {
7
+ initialize: (config: IAPIConfig) => void;
8
+ destroy: () => void;
9
+ commands: Commands;
10
+ controllers: Controllers;
11
+ data: Data;
12
+ internal: Internal;
13
+ }
@@ -6,6 +6,8 @@ import Controllers from "../manager-bases/controllers";
6
6
  import Data from "../manager-bases/data";
7
7
  import Internal from "../manager-bases/internal";
8
8
  import { IAPIConfig } from "../interfaces/config";
9
+ import '../globals';
10
+ export declare const afterInitializeCallbacks: (() => void)[];
9
11
  export declare function initialize(config: IAPIConfig): void;
10
12
  export declare function destroy(): void;
11
13
  export declare const controllers: Controllers;