@zenflux/core 0.0.0-abc.0 → 0.0.0-abc.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.
@@ -452,10 +452,10 @@ let internal = {};
452
452
 
453
453
  var index$5 = /*#__PURE__*/Object.freeze({
454
454
  __proto__: null,
455
- get commands () { return commands; },
456
- get controllers () { return controllers; },
457
- get data () { return data; },
458
- get internal () { return internal; }
455
+ commands: commands,
456
+ controllers: controllers,
457
+ data: data,
458
+ internal: internal
459
459
  });
460
460
 
461
461
  /**
@@ -984,7 +984,7 @@ utils: index$6
984
984
  });
985
985
 
986
986
  var name = "@zenflux/core";
987
- var version = "0.0.0-abc.0";
987
+ var version = "0.0.0-abc.1";
988
988
  var description = "ZenFlux core";
989
989
  var author = "Leonid Vinikov <leonidvinikov@gmail.com> (https://github.com/iNewLegend)";
990
990
  var scripts = {
@@ -1054,6 +1054,7 @@ var pkg = {
1054
1054
  dependencies: dependencies
1055
1055
  };
1056
1056
 
1057
+ const managers = index$5;
1057
1058
  let isInitialized = false;
1058
1059
  function errorInitTwice() {
1059
1060
  if (isInitialized) {
@@ -1069,19 +1070,19 @@ const CoreAPI = {
1069
1070
  initialize: configuration => {
1070
1071
  errorInitTwice();
1071
1072
  config = configuration || config;
1072
- commands = new Commands();
1073
- controllers = new Controllers();
1074
- data = new Data(config);
1075
- internal = new Internal();
1073
+ managers.commands = new Commands();
1074
+ managers.controllers = new Controllers();
1075
+ managers.data = new Data(config);
1076
+ managers.internal = new Internal();
1076
1077
  isInitialized = true;
1077
1078
  afterInitializeCallbacks.forEach(callback => callback());
1078
1079
  },
1079
1080
  destroy: () => {
1080
1081
  isInitialized = false;
1081
- commands = {};
1082
- controllers = {};
1083
- data = {};
1084
- internal = {};
1082
+ managers.commands = {};
1083
+ managers.controllers = {};
1084
+ managers.data = {};
1085
+ managers.internal = {};
1085
1086
  },
1086
1087
  onAfterInitialize: callback => {
1087
1088
  afterInitializeCallbacks.push(callback);
@@ -1090,7 +1091,7 @@ const CoreAPI = {
1090
1091
  ...exported
1091
1092
  };
1092
1093
  // TODO: Make it available only for development.
1093
- // if ( ! globalThis?.ZenCore ) globalThis.ZenCore = CoreAPI;
1094
+ if (!globalThis?.ZenCore) globalThis.ZenCore = CoreAPI;
1094
1095
 
1095
1096
  exports.commandBases = index$4;
1096
1097
  exports.core = index$3;
@@ -448,10 +448,10 @@ let internal = {};
448
448
 
449
449
  var index$5 = /*#__PURE__*/Object.freeze({
450
450
  __proto__: null,
451
- get commands () { return commands; },
452
- get controllers () { return controllers; },
453
- get data () { return data; },
454
- get internal () { return internal; }
451
+ commands: commands,
452
+ controllers: controllers,
453
+ data: data,
454
+ internal: internal
455
455
  });
456
456
 
457
457
  /**
@@ -980,7 +980,7 @@ utils: index$6
980
980
  });
981
981
 
982
982
  var name = "@zenflux/core";
983
- var version = "0.0.0-abc.0";
983
+ var version = "0.0.0-abc.1";
984
984
  var description = "ZenFlux core";
985
985
  var author = "Leonid Vinikov <leonidvinikov@gmail.com> (https://github.com/iNewLegend)";
986
986
  var scripts = {
@@ -1050,6 +1050,7 @@ var pkg = {
1050
1050
  dependencies: dependencies
1051
1051
  };
1052
1052
 
1053
+ const managers = index$5;
1053
1054
  let isInitialized = false;
1054
1055
  function errorInitTwice() {
1055
1056
  if (isInitialized) {
@@ -1065,19 +1066,19 @@ const CoreAPI = {
1065
1066
  initialize: configuration => {
1066
1067
  errorInitTwice();
1067
1068
  config = configuration || config;
1068
- commands = new Commands();
1069
- controllers = new Controllers();
1070
- data = new Data(config);
1071
- internal = new Internal();
1069
+ managers.commands = new Commands();
1070
+ managers.controllers = new Controllers();
1071
+ managers.data = new Data(config);
1072
+ managers.internal = new Internal();
1072
1073
  isInitialized = true;
1073
1074
  afterInitializeCallbacks.forEach(callback => callback());
1074
1075
  },
1075
1076
  destroy: () => {
1076
1077
  isInitialized = false;
1077
- commands = {};
1078
- controllers = {};
1079
- data = {};
1080
- internal = {};
1078
+ managers.commands = {};
1079
+ managers.controllers = {};
1080
+ managers.data = {};
1081
+ managers.internal = {};
1081
1082
  },
1082
1083
  onAfterInitialize: callback => {
1083
1084
  afterInitializeCallbacks.push(callback);
@@ -1086,6 +1087,6 @@ const CoreAPI = {
1086
1087
  ...exported
1087
1088
  };
1088
1089
  // TODO: Make it available only for development.
1089
- // if ( ! globalThis?.ZenCore ) globalThis.ZenCore = CoreAPI;
1090
+ if (!globalThis?.ZenCore) globalThis.ZenCore = CoreAPI;
1090
1091
 
1091
1092
  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 };
@@ -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 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};
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={};var p=Object.freeze({__proto__:null,commands:l,controllers:{},data:h,internal:u});var g=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 h.getClient().fetch(r,h.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 m=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=h.register(this.getData(),this),this.internal=u.register(this.getInternal(),this)}getCommands(){return{}}getData(){return{}}getInternal(){return{}}},ObjectBase:s});class d extends Error{constructor(t){super(`Command: '${t.getName()}' is already registered`)}}class f extends Error{constructor(t){super(`Command: '${t}' is not found`)}}class C extends Error{constructor(t){super(`Controller: '${t.getName()}' is already registered`)}}var y,b=Object.freeze({__proto__:null,CommandAlreadyRegistered:d,CommandNotFound:f,ControllerAlreadyRegistered:C,ForceMethod:e}),N=Object.freeze({__proto__:null,Logger:i});class w 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 d(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 f(t);return new s(e,r)}onBefore(t,e){w.hookCommand(this.onBeforeHooks,t,e)}onBeforeUI(t,e){w.hookCommand(this.onBeforeUIHooks,t,e)}onAfter(t,e){w.hookCommand(this.onAfterHooks,t,e)}onAfterUI(t,e){w.hookCommand(this.onAfterUIHooks,t,e)}onAfterOnce(t,e){w.hookCommand(this.onAfterOnceHooks,t,e)}onAfterAffect(t,e){w.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 w.runCallbacks(Object.assign([],this.onAfterHooks[t.getName()]),e,r)),this.onAfterOnceHooks&&await w.runCallbacks(this.onAfterOnceHooks[t.getName()],e,{...r,pop:!0}),this.onAfterUIHooks&&w.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()),w.trace.push(t.getName())}detachCurrent(t){delete this.current[t.getName()],delete this.currentArgs[t.getName()],w.trace.pop(),this.trace.pop()}}class O 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 C(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__=""}(y||(y={}));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"},o={};[y.POST,y.PUT,y.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 k extends w{static client;currentHttpMethod;static getName(){return"Core/Managers/Data"}constructor(t){super(),k.client=new A(t.baseURL)}getClient(){return k.client}get(t,e={},r={}){return this.currentHttpMethod=y.GET,super.run(t,e,r)}update(t,e={},r={}){return this.currentHttpMethod=y.PATCH,super.run(t,e,r)}delete(t,e={},r={}){return this.currentHttpMethod=y.DELETE,super.run(t,e,r)}create(t,e={},r={}){return this.currentHttpMethod=y.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 y.GET===this.currentHttpMethod?s.args.query=e:s.args.data=e,e.result=await super.runInstance(t,s,r),this.currentHttpMethod=y.__EMPTY__,e.result}}class E extends w{static getName(){return"Core/Managers/Internal"}}var H=Object.freeze({__proto__:null,Commands:w,Controllers:O,Data:k,Internal:E}),_=Object.freeze({__proto__:null,commandBases:g,core:m,errors:b,managerBases:H,managers:p,modules:N,utils:a}),j="0.0.0-abc.1";const I=p;let $=!1;function B(){if($)throw Error("ZenCore is already initialized.")}B();let T={version:j};const M=[],U={initialize:t=>{B(),T=t||T,I.commands=new w,I.controllers=new O,I.data=new k(T),I.internal=new E,$=!0,M.forEach((t=>t()))},destroy:()=>{$=!1,I.commands={},I.controllers={},I.data={},I.internal={}},onAfterInitialize:t=>{M.push(t)},config:T,..._};globalThis?.ZenCore||(globalThis.ZenCore=U);export{g as commandBases,m as core,U as default,b as errors,H as managerBases,p as managers,N as modules,a as utils};
@@ -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={};var g=Object.freeze({__proto__:null,commands:h,controllers:{},data:u,internal:p});var m=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 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 l{static getName(){return"Core/CommandBases/CommandInternal"}},CommandPublic:class extends l{static getName(){return"Core/CommandBases/CommandPublic"}}});var d=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=u.register(this.getData(),this),this.internal=p.register(this.getInternal(),this)}getCommands(){return{}}getData(){return{}}getInternal(){return{}}},ObjectBase:o});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:r}),w=Object.freeze({__proto__:null,Logger:c});class O 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 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 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 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 o{logger;apiBaseUrl;static getName(){return"Core/Clients/Http"}constructor(t="http://localhost"){super(),this.logger=new c(k.getName(),!0),this.logger.startWith({apiBaseUrl:t}),this.apiBaseUrl=t+"/"}async fetch(t,e,r=null){this.logger.startWith({path:t,method:e,body:r});const s={credentials:"include"},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 _ extends O{static getName(){return"Core/Managers/Internal"}}var j=Object.freeze({__proto__:null,Commands:O,Controllers:A,Data:E,Internal:_}),H=Object.freeze({__proto__:null,commandBases:m,core:d,errors:N,managerBases:j,managers:g,modules:w,utils:i}),I="0.0.0-abc.1";const $=g;let T=!1;function B(){if(T)throw Error("ZenCore is already initialized.")}B();let M={version:I};const x=[],U={initialize:t=>{B(),M=t||M,$.commands=new O,$.controllers=new A,$.data=new E(M),$.internal=new _,T=!0,x.forEach((t=>t()))},destroy:()=>{T=!1,$.commands={},$.controllers={},$.data={},$.internal={}},onAfterInitialize:t=>{x.push(t)},config:M,...H};globalThis?.ZenCore||(globalThis.ZenCore=U),t.commandBases=m,t.core=d,t.default=U,t.errors=N,t.managerBases=j,t.managers=g,t.modules=w,t.utils=i,Object.defineProperty(t,"__esModule",{value:!0})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenflux/core",
3
- "version": "0.0.0-abc.0",
3
+ "version": "0.0.0-abc.1",
4
4
  "description": "ZenFlux core",
5
5
  "author": "Leonid Vinikov <leonidvinikov@gmail.com> (https://github.com/iNewLegend)",
6
6
  "scripts": {
@@ -2,6 +2,8 @@ import pkg from "../package.json";
2
2
 
3
3
  import * as exported from './exports';
4
4
 
5
+ const managers = exported.managers;
6
+
5
7
  import { IAPIConfig } from "./interfaces/config";
6
8
 
7
9
  declare global {
@@ -30,10 +32,10 @@ export const CoreAPI = {
30
32
 
31
33
  config = configuration || config;
32
34
 
33
- exported.managers.commands = new exported.managerBases.Commands();
34
- exported.managers.controllers = new exported.managerBases.Controllers();
35
- exported.managers.data = new exported.managerBases.Data( config );
36
- exported.managers.internal = new exported.managerBases.Internal();
35
+ managers.commands = new exported.managerBases.Commands();
36
+ managers.controllers = new exported.managerBases.Controllers();
37
+ managers.data = new exported.managerBases.Data( config );
38
+ managers.internal = new exported.managerBases.Internal();
37
39
 
38
40
  isInitialized = true;
39
41
 
@@ -43,10 +45,10 @@ export const CoreAPI = {
43
45
  destroy: () => {
44
46
  isInitialized = false;
45
47
 
46
- exported.managers.commands = {} as exported.managerBases.Commands;
47
- exported.managers.controllers = {} as exported.managerBases.Controllers
48
- exported.managers.data = {} as exported.managerBases.Data;
49
- exported.managers.internal = {} as exported.managerBases.Internal;
48
+ managers.commands = {} as exported.managerBases.Commands;
49
+ managers.controllers = {} as exported.managerBases.Controllers
50
+ managers.data = {} as exported.managerBases.Data;
51
+ managers.internal = {} as exported.managerBases.Internal;
50
52
  },
51
53
 
52
54
  onAfterInitialize: ( callback: () => void ) => {
@@ -59,5 +61,5 @@ export const CoreAPI = {
59
61
  }
60
62
 
61
63
  // TODO: Make it available only for development.
62
- // if ( ! globalThis?.ZenCore ) globalThis.ZenCore = CoreAPI;
64
+ if ( ! globalThis?.ZenCore ) globalThis.ZenCore = CoreAPI;
63
65