@zenflux/core 0.0.0-abc.2 → 0.0.0-abc.20

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.
@@ -1,12 +1,12 @@
1
- class t extends Error{constructor(t,e){super(`ForeMethod implementation: at '${t}' method: '${e}'`)}}class e extends Error{constructor(t,e){super(`ForeMethod implementation: at '${t.getName()}' method: '${e}'`)}}let r=0;class s{virtualId=0;static getName(){throw new t("ObjectBase","getName")}constructor(){this.virtualId=r,r++}getName(){return this.constructor.getName()}}
1
+ var t="0.0.0-abc.20";
2
2
  /**
3
3
  * Function getCircularReplacer() : Reduce circular references.
4
4
  *
5
5
  * @copyright https://stackoverflow.com/a/53731154
6
6
  */
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};
7
+ const e=()=>{const t=new WeakSet;return(e,r)=>{if("object"==typeof r&&null!==r){if(t.has(r))return;t.add(r)}return r}},r=function(t,e){t=t.replace("#",""),e=e.replace("#","");const r=parseInt(t.substring(0,2),16),s=parseInt(t.substring(2,4),16),n=parseInt(t.substring(4,6),16),o=parseInt(e.substring(0,2),16),a=parseInt(e.substring(2,4),16),i=parseInt(e.substring(4,6),16);let c=255-Math.abs(r-o),l=255-Math.abs(s-a),h=255-Math.abs(n-i);return c/=255,l/=255,h/=255,(c+l+h)/3};
8
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: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}}const l={commands:{},controllers:{},data:{},internal:{}};var h=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 l.data.getClient().fetch(r,l.data.currentHttpMethod,t||null)}applyEndpointFormat(t,e={}){return t.includes("{")&&(t=t.split("/").map((t=>{const r=t.match("\\{(.*?)\\}");return r?.length&&void 0!==e[r[1]]?e[r[1]]:t})).join("/")),t}},CommandInternal:class extends c{static getName(){return"Core/CommandBases/CommandInternal"}},CommandPublic:class extends c{static getName(){return"Core/CommandBases/CommandPublic"}}});var u=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.commands.register(this.getCommands(),this),this.data=l.data.register(this.getData(),this),this.internal=l.internal.register(this.getInternal(),this)}getCommands(){return{}}getData(){return{}}getInternal(){return{}}},ObjectBase:s});class p extends Error{constructor(t){super(`Command: '${t.getName()}' is already registered`)}}class g extends Error{constructor(t){super(`Command: '${t}' is not found`)}}class m extends Error{constructor(t){super(`Controller: '${t.getName()}' is already registered`)}}var d,f=Object.freeze({__proto__:null,CommandAlreadyRegistered:p,CommandNotFound:g,ControllerAlreadyRegistered:m,ForceMethod:e}),C=Object.freeze({__proto__:null,Logger:i});class y 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 p(t);this.commands[e]=t,r[e]=t})),r}getAll(){return this.commands}getByName(t){return this.commands[t]}getLogger(){return this.logger}getCommandInstance(t,e={},r={}){const s=this.commands[t];if(!s)throw new g(t);return new s(e,r)}onBefore(t,e){y.hookCommand(this.onBeforeHooks,t,e)}onBeforeUI(t,e){y.hookCommand(this.onBeforeUIHooks,t,e)}onAfter(t,e){y.hookCommand(this.onAfterHooks,t,e)}onAfterUI(t,e){y.hookCommand(this.onAfterUIHooks,t,e)}onAfterOnce(t,e){y.hookCommand(this.onAfterOnceHooks,t,e)}onAfterAffect(t,e){y.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 y.runCallbacks(Object.assign([],this.onAfterHooks[t.getName()]),e,r)),this.onAfterOnceHooks&&await y.runCallbacks(this.onAfterOnceHooks[t.getName()],e,{...r,pop:!0}),this.onAfterUIHooks&&y.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()),y.trace.push(t.getName())}detachCurrent(t){delete this.current[t.getName()],delete this.currentArgs[t.getName()],y.trace.pop(),this.trace.pop()}}class b 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 m(t);return this.controllers[t.getName()]=t,t}}!function(t){t.DELETE="DELETE",t.GET="GET",t.OPTIONS="OPTIONS",t.PATCH="PATCH",t.POST="POST",t.PUT="PUT",t.__EMPTY__=""}(d||(d={}));class N extends s{logger;apiBaseUrl;static getName(){return"Core/Clients/Http"}constructor(t="http://localhost"){super(),this.logger=new i(N.getName(),!0),this.logger.startWith({apiBaseUrl:t}),this.apiBaseUrl=t+"/"}async fetch(t,e,r=null){this.logger.startWith({path:t,method:e,body:r});const s={credentials:"include"},o={};[d.POST,d.PUT,d.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 w extends y{static client;currentHttpMethod;static getName(){return"Core/Managers/Data"}constructor(t){super(),w.client=new N(t.baseURL)}getClient(){return w.client}get(t,e={},r={}){return this.currentHttpMethod=d.GET,super.run(t,e,r)}update(t,e={},r={}){return this.currentHttpMethod=d.PATCH,super.run(t,e,r)}delete(t,e={},r={}){return this.currentHttpMethod=d.DELETE,super.run(t,e,r)}create(t,e={},r={}){return this.currentHttpMethod=d.POST,super.run(t,e,r)}async runInstance(t,e={},r={}){if(!this.currentHttpMethod)throw Error('Cannot run directly use one of the http methods: "get", "update", "delete, "create');const s={type:this.currentHttpMethod,args:{query:{},data:{}}};return d.GET===this.currentHttpMethod?s.args.query=e:s.args.data=e,e.result=await super.runInstance(t,s,r),this.currentHttpMethod=d.__EMPTY__,e.result}}class A extends y{static getName(){return"Core/Managers/Internal"}}var O=Object.freeze({__proto__:null,Commands:y,Controllers:b,Data:w,Internal:A}),k=Object.freeze({__proto__:null,commandBases:h,core:u,errors:f,managerBases:O,modules:C,utils:a}),E="0.0.0-abc.1";let H=!1;function I(){if(H)throw Error("ZenCore is already initialized.")}I();let j={version:E};const _=[],$={initialize:t=>{I(),j=t||j,l.commands=new y,l.controllers=new b,l.data=new w(j),l.internal=new A,H=!0,_.forEach((t=>t()))},destroy:()=>{H=!1,l.commands={},l.controllers={},l.data={},l.internal={}},onAfterInitialize:t=>{_.push(t)},config:j,...k};globalThis?.ZenCore||(globalThis.ZenCore=$);export{h as commandBases,u as core,$ as default,f as errors,O as managerBases,C as modules,a as utils};
12
+ */var s=Object.freeze({__proto__:null,getCircularReplacer:e,hexColorDelta:r});class n{static wrappers={};static wrapperDepth=0;static sharedData={};static colorsInUse=[];defaultStyle;color;outputHandler;args={};name;state=!1;static getName(){return"Core/Modules/Logger"}static reset(){n.wrappers={},n.wrapperDepth=0,n.colorsInUse=[],n.sharedData={}}static createCustomWrapper(t,e){n.wrappers[t]||(n.wrappers[t.name]=[]),n.wrappers[t.name].push({classType:t,callback:e})}static getCallerName(){const t=Error(),e=t.stack?t.stack.split("\n")[3].trim():"_UNKNOWN_CALLER_NAME_";return e.startsWith("at new")?"constructor":e.split(".")[1].split(" ")[0]}static getFunctionView(t){let e="anonymous function()";return"string"!=typeof t&&0!==t.name.length&&(e=t.name.split(" ")[1]+"()"),e}constructor(t,e=!1,r={}){"off"!==globalThis.process?.env.flow_modules_logger&&(this.state=e,this.args=r,this.name="",this.name="string"==typeof t?t:t.constructor.name,e&&this.initialize())}initialize(){this.args.sameColor?(n.sharedData[this.name]||(n.sharedData[this.name]=this.getRandomColor()),this.color=n.sharedData[this.name]):(this.color=this.getRandomColor(),n.colorsInUse.push(this.color)),this.outputHandler=console.log,this.defaultStyle=["color: grey;font-size:7px","display: block","color: "+this.color,"color: grey","font-weight: bold","color: #607D8B","font-size: 16px;color: red;font-weight:800"]}setOutputHandler(t){this.outputHandler=t}useWrapper(t,e=!0){if(!t||"object"!=typeof t||Array.isArray(t))return t;n.wrapperDepth++;let r={...t};return Object.values(n.wrappers).forEach((([e])=>{t instanceof e.classType&&(r=e.callback(t)||r)})),4>n.wrapperDepth?(e&&r&&Object.entries(r).forEach((([t,e])=>{r[t]=this.useWrapper(e,!0)})),n.wrapperDepth--,r):(n.wrapperDepth--,r)}startEmpty(t=""){this.state&&this.printFunctionNotify("se",n.getCallerName(),t)}startWith(t){if(!this.state)return;t=Object.assign({},t);const e="se",r=n.getCallerName();if("string"==typeof t)this.printInLineString(e,r,t);else if(1===Object.keys(t).length){const s=Object.keys(t)[0];let n=Object.values(t)[0];"object"==typeof n?this.printNextLineObject(e,r,s,n||{}):"function"==typeof n?this.printInLineFunction(e,r,s,n):this.printInLineElement(e,r,s,n)}else this.printMultiLineObject(e,r,t)}object(t={},r=""){if(!this.state)return;const s=n.getCallerName();t=Object.create(t);for(let n in t)"object"==typeof t[n]&&(t[n]=JSON.stringify(this.useWrapper(t[n]),e())),this.out.apply(this,[`%c(ob)-> %c%c${this.name}%c::%c${s}%c() [${r}] ->> ${n}: '${t[n]}'%c`].concat(this.defaultStyle))}debug(t){this.state&&this.printFunctionNotify("db",n.getCallerName(),t)}drop(t,e){if(!this.state)return;const r=n.getCallerName();for(let e in t)this.out.apply(this,[`%c(dr)-> %c%c${this.name}%c::%c${r}%c() ->> corresponding ${e}: '${t[e]}' RESULT: %c↓`].concat(this.defaultStyle));this.out(e)}throw(t,e="null",r={}){throw this.printFunctionNotify("tw",n.getCallerName(),t),r&&this.printNextLineObject("tw",n.getCallerName(),e,r),Error().stack}clone(){return Object.assign(Object.create(Object.getPrototypeOf(this)),this)}printFunctionNotify(t,e,r){this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c() ${r}%c`].concat(this.defaultStyle))}printInLineElement(t,e,r,s){this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c() ->> ${r}: '${s}'%c`].concat(this.defaultStyle))}printInLineFunction(t,e,r,s){s=n.getFunctionView(s),this.printInLineElement(t,e,r,s)}printInLineString(t,e,r){this.printInLineElement(t,e,"(string)",r)}printNextLineObject(t,e,r,s){s=this.useWrapper(s),this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c() ->> ${r} %c↓`].concat(this.defaultStyle)),this.out(s)}printMultiLineObject(t,r,s){this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${r}%c(${Object.keys(s).join(", ")}) %c↓`].concat(this.defaultStyle));for(let t in s){let r=s[t];"object"==typeof r?r=JSON.stringify(this.useWrapper(r),e()):"function"==typeof s[t]&&(r=n.getFunctionView(r)),this.out.call(this,"%c"+t+": `"+this.useWrapper(r)+"`","color: #a3a3a3")}}getRandomColor(){let t="#";for(let e=0;6>e;e++)t+="0123456789ABCDEF"[Math.floor(16*Math.random())];return n.colorsInUse.some((e=>r(t,e)>=.8))?this.getRandomColor():t}out(...t){this.outputHandler.apply(this,t)}}var o=Object.freeze({__proto__:null,Logger:n});class a extends Error{constructor(t){super(`Command: '${t.getName()}' is already registered`)}}class i extends Error{constructor(t){super(`Command: '${t}' is not found`)}}class c extends Error{constructor(t){super(`Controller: '${t.getName()}' is already registered`)}}class l extends Error{constructor(t,e){super(`ForeMethod implementation: at '${t}' method: '${e}'`)}}class h extends Error{constructor(t,e){super(`ForeMethod implementation: at '${t.getName()}' method: '${e}'`)}}var u=Object.freeze({__proto__:null,CommandAlreadyRegistered:a,CommandNotFound:i,ControllerAlreadyRegistered:c,ForceMethod:h});let p=0;class g{virtualId=0;static getName(){throw new l("ObjectBase","getName")}constructor(){this.virtualId=p,p++}getName(){return this.constructor.getName()}}class m extends g{static trace=[];current={};currentArgs={};trace=[];commands={};onBeforeHooks={};onBeforeUIHooks={};onAfterHooks={};onAfterOnceHooks={};onAfterUIHooks={};onAfterAffectHooks={};logger;static getName(){return"Core/Managers/Commands"}static async runCallbacks(t,e={},r={}){const s=t?.length||0;for(let n=0;s>n;++n){const s=!0===r.pop?t.pop():t[n];if(!s)throw Error("Callback is not defined.");await s(e,r)}}static hookCommand(t,e,r){t[e]||(t[e]=[]),t[e].push(r)}constructor(){super(),this.logger=new n(this.getName(),!0),this.logger.startEmpty()}async run(t,e={},r={}){"string"==typeof t&&(t=this.getCommandInstance(t,e,r)),this.attachCurrent(t,e);const s=await this.runInstance(t,e,r);return this.detachCurrent(t),s}register(t,e){const r={};return Object.values(t).forEach((t=>{const e=t.getName();if(this.commands[e])throw new a(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 i(t);return new s(e,r)}onBefore(t,e){m.hookCommand(this.onBeforeHooks,t,e)}onBeforeUI(t,e){m.hookCommand(this.onBeforeUIHooks,t,e)}onAfter(t,e){m.hookCommand(this.onAfterHooks,t,e)}onAfterUI(t,e){m.hookCommand(this.onAfterUIHooks,t,e)}onAfterOnce(t,e){m.hookCommand(this.onAfterOnceHooks,t,e)}onAfterAffect(t,e){m.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 m.runCallbacks(Object.assign([],this.onAfterHooks[t.getName()]),e,r)),this.onAfterOnceHooks&&await m.runCallbacks(this.onAfterOnceHooks[t.getName()],e,{...r,pop:!0}),this.onAfterUIHooks&&m.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()),m.trace.push(t.getName())}detachCurrent(t){delete this.current[t.getName()],delete this.currentArgs[t.getName()],m.trace.pop(),this.trace.pop()}}class d extends g{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}}var f;!function(t){t.DELETE="DELETE",t.GET="GET",t.OPTIONS="OPTIONS",t.PATCH="PATCH",t.POST="POST",t.PUT="PUT",t.__EMPTY__=""}(f||(f={}));class C extends g{logger;apiBaseUrl;static getName(){return"Core/Clients/Http"}constructor(t="http://localhost"){super(),this.logger=new n(C.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={};[f.POST,f.PUT,f.PATCH].includes(e)?(Object.assign(n,{"Content-Type":"application/json"}),Object.assign(s,{method:e,headers:n,body:JSON.stringify(r)})):Object.assign(s,{headers:n});const o=await globalThis.fetch(this.apiBaseUrl+t,s);let a;try{a=await o.json()}catch(t){return console.error(t),!1}if(a?.error&&a?.global&&a?.message)throw Error(a.message);return this.logger.drop({path:t},a),a}}class y extends m{static client;currentHttpMethod;static getName(){return"Core/Managers/Data"}constructor(t){super(),y.client=new C(t.baseURL)}getClient(){return y.client}get(t,e={},r={}){return this.currentHttpMethod=f.GET,super.run(t,e,r)}update(t,e={},r={}){return this.currentHttpMethod=f.PATCH,super.run(t,e,r)}delete(t,e={},r={}){return this.currentHttpMethod=f.DELETE,super.run(t,e,r)}create(t,e={},r={}){return this.currentHttpMethod=f.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 f.GET===this.currentHttpMethod?s.args.query=e:s.args.data=e,e.result=await super.runInstance(t,s,r),this.currentHttpMethod=f.__EMPTY__,e.result}}class b extends m{static getName(){return"Core/Managers/Internal"}}const N=[];function w(t){A=new m,k=new d,E=new y(t),H=new b}function O(){A={},k={},E={},H={}}var A={},k={},E={},H={},I=Object.freeze({__proto__:null,afterInitializeCallbacks:N,get commands(){return A},get controllers(){return k},get data(){return E},destroy:O,initialize:w,get internal(){return H}});class _ extends g{args={};options={};logger;constructor(t={},e={}){super();const r=this.constructor.getName();this.logger=new n(r,!0,{sameColor:!0}),this.logger.startWith({args:t,options:e}),this.initialize(t,e)}initialize(t,e){this.args=t,this.options=e}apply(t=this.args,e=this.options){throw new h(this,"apply")}async run(){this.onBeforeApply&&this.onBeforeApply();const t=await this.apply(this.args,this.options);return this.onAfterApply&&this.onAfterApply(),t}getArgs(){return this.args}getOptions(){return this.options}}var j=Object.freeze({__proto__:null,CommandBase:_,CommandData:class extends _{static getName(){return"Core/CommandBases/CommandData"}getEndpoint(){throw new h(this,"getEndpoint")}apply(t=this.args,e=this.options){const r=this.applyEndpointFormat(this.getEndpoint(),t);return E.getClient().fetch(r,E.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 _{static getName(){return"Core/CommandBases/CommandInternal"}},CommandPublic:class extends _{static getName(){return"Core/CommandBases/CommandPublic"}}});var $=Object.freeze({__proto__:null,Controller:class extends g{commands;data;internal;static getName(){return"Core/Core/Controller"}constructor(){super(),this.initialize()}initialize(){this.register(),this.setupHooks&&this.setupHooks()}register(){this.commands=A.register(this.getCommands(),this),this.data=E.register(this.getData(),this),this.internal=H.register(this.getInternal(),this)}getCommands(){return{}}getData(){return{}}getInternal(){return{}}},ObjectBase:g}),B=Object.freeze({__proto__:null,Commands:m,Controllers:d,Data:y,Internal:b}),T=Object.freeze({__proto__:null,commandBases:j,core:$,errors:u,managerBases:B,managers:I,modules:o,utils:s});let M=!1;function U(){if(M)throw Error("ZenCore is already initialized.")}U();let D={version:t};const L={initialize:t=>{U(),D=t||D,w(D),M=!0},destroy:()=>{O(),M=!1},onAfterInitialize:t=>{N.push(t)},config:D,...T};globalThis?.ZenCore||(globalThis.ZenCore=L);export{j as commandBases,$ as core,L as default,u as errors,B as managerBases,I as managers,o as modules,s as utils};
@@ -1,12 +1,12 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["@zenflux/core"]={})}(this,(function(t){"use strict";class e extends Error{constructor(t,e){super(`ForeMethod implementation: at '${t}' method: '${e}'`)}}class r extends Error{constructor(t,e){super(`ForeMethod implementation: at '${t.getName()}' method: '${e}'`)}}let s=0;class o{virtualId=0;static getName(){throw new e("ObjectBase","getName")}constructor(){this.virtualId=s,s++}getName(){return this.constructor.getName()}}
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["@zenflux/core"]={})}(this,(function(t){"use strict";var e="0.0.0-abc.20";
2
2
  /**
3
3
  * Function getCircularReplacer() : Reduce circular references.
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}},a=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};
7
+ const r=()=>{const t=new WeakSet;return(e,r)=>{if("object"==typeof r&&null!==r){if(t.has(r))return;t.add(r)}return r}},s=function(t,e){t=t.replace("#",""),e=e.replace("#","");const r=parseInt(t.substring(0,2),16),s=parseInt(t.substring(2,4),16),n=parseInt(t.substring(4,6),16),o=parseInt(e.substring(0,2),16),a=parseInt(e.substring(2,4),16),i=parseInt(e.substring(4,6),16);let c=255-Math.abs(r-o),l=255-Math.abs(s-a),h=255-Math.abs(n-i);return c/=255,l/=255,h/=255,(c+l+h)/3};
8
8
  /**
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}}const h={commands:{},controllers:{},data:{},internal:{}};var u=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 h.data.getClient().fetch(r,h.data.currentHttpMethod,t||null)}applyEndpointFormat(t,e={}){return t.includes("{")&&(t=t.split("/").map((t=>{const r=t.match("\\{(.*?)\\}");return r?.length&&void 0!==e[r[1]]?e[r[1]]:t})).join("/")),t}},CommandInternal:class extends l{static getName(){return"Core/CommandBases/CommandInternal"}},CommandPublic:class extends l{static getName(){return"Core/CommandBases/CommandPublic"}}});var p=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.commands.register(this.getCommands(),this),this.data=h.data.register(this.getData(),this),this.internal=h.internal.register(this.getInternal(),this)}getCommands(){return{}}getData(){return{}}getInternal(){return{}}},ObjectBase:o});class g extends Error{constructor(t){super(`Command: '${t.getName()}' is already registered`)}}class m extends Error{constructor(t){super(`Command: '${t}' is not found`)}}class d extends Error{constructor(t){super(`Controller: '${t.getName()}' is already registered`)}}var f,C=Object.freeze({__proto__:null,CommandAlreadyRegistered:g,CommandNotFound:m,ControllerAlreadyRegistered:d,ForceMethod:r}),y=Object.freeze({__proto__:null,Logger:c});class b 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 g(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 m(t);return new s(e,r)}onBefore(t,e){b.hookCommand(this.onBeforeHooks,t,e)}onBeforeUI(t,e){b.hookCommand(this.onBeforeUIHooks,t,e)}onAfter(t,e){b.hookCommand(this.onAfterHooks,t,e)}onAfterUI(t,e){b.hookCommand(this.onAfterUIHooks,t,e)}onAfterOnce(t,e){b.hookCommand(this.onAfterOnceHooks,t,e)}onAfterAffect(t,e){b.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 b.runCallbacks(Object.assign([],this.onAfterHooks[t.getName()]),e,r)),this.onAfterOnceHooks&&await b.runCallbacks(this.onAfterOnceHooks[t.getName()],e,{...r,pop:!0}),this.onAfterUIHooks&&b.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()),b.trace.push(t.getName())}detachCurrent(t){delete this.current[t.getName()],delete this.currentArgs[t.getName()],b.trace.pop(),this.trace.pop()}}class N 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 d(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__=""}(f||(f={}));class w extends o{logger;apiBaseUrl;static getName(){return"Core/Clients/Http"}constructor(t="http://localhost"){super(),this.logger=new c(w.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={};[f.POST,f.PUT,f.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 O extends b{static client;currentHttpMethod;static getName(){return"Core/Managers/Data"}constructor(t){super(),O.client=new w(t.baseURL)}getClient(){return O.client}get(t,e={},r={}){return this.currentHttpMethod=f.GET,super.run(t,e,r)}update(t,e={},r={}){return this.currentHttpMethod=f.PATCH,super.run(t,e,r)}delete(t,e={},r={}){return this.currentHttpMethod=f.DELETE,super.run(t,e,r)}create(t,e={},r={}){return this.currentHttpMethod=f.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 f.GET===this.currentHttpMethod?s.args.query=e:s.args.data=e,e.result=await super.runInstance(t,s,r),this.currentHttpMethod=f.__EMPTY__,e.result}}class A extends b{static getName(){return"Core/Managers/Internal"}}var k=Object.freeze({__proto__:null,Commands:b,Controllers:N,Data:O,Internal:A}),E=Object.freeze({__proto__:null,commandBases:u,core:p,errors:C,managerBases:k,modules:y,utils:i}),j="0.0.0-abc.1";let H=!1;function I(){if(H)throw Error("ZenCore is already initialized.")}I();let _={version:j};const $=[],T={initialize:t=>{I(),_=t||_,h.commands=new b,h.controllers=new N,h.data=new O(_),h.internal=new A,H=!0,$.forEach((t=>t()))},destroy:()=>{H=!1,h.commands={},h.controllers={},h.data={},h.internal={}},onAfterInitialize:t=>{$.push(t)},config:_,...E};globalThis?.ZenCore||(globalThis.ZenCore=T),t.commandBases=u,t.core=p,t.default=T,t.errors=C,t.managerBases=k,t.modules=y,t.utils=i,Object.defineProperty(t,"__esModule",{value:!0})}));
12
+ */var n=Object.freeze({__proto__:null,getCircularReplacer:r,hexColorDelta:s});class o{static wrappers={};static wrapperDepth=0;static sharedData={};static colorsInUse=[];defaultStyle;color;outputHandler;args={};name;state=!1;static getName(){return"Core/Modules/Logger"}static reset(){o.wrappers={},o.wrapperDepth=0,o.colorsInUse=[],o.sharedData={}}static createCustomWrapper(t,e){o.wrappers[t]||(o.wrappers[t.name]=[]),o.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?(o.sharedData[this.name]||(o.sharedData[this.name]=this.getRandomColor()),this.color=o.sharedData[this.name]):(this.color=this.getRandomColor(),o.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;o.wrapperDepth++;let r={...t};return Object.values(o.wrappers).forEach((([e])=>{t instanceof e.classType&&(r=e.callback(t)||r)})),4>o.wrapperDepth?(e&&r&&Object.entries(r).forEach((([t,e])=>{r[t]=this.useWrapper(e,!0)})),o.wrapperDepth--,r):(o.wrapperDepth--,r)}startEmpty(t=""){this.state&&this.printFunctionNotify("se",o.getCallerName(),t)}startWith(t){if(!this.state)return;t=Object.assign({},t);const e="se",r=o.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 s=o.getCallerName();t=Object.create(t);for(let n in t)"object"==typeof t[n]&&(t[n]=JSON.stringify(this.useWrapper(t[n]),r())),this.out.apply(this,[`%c(ob)-> %c%c${this.name}%c::%c${s}%c() [${e}] ->> ${n}: '${t[n]}'%c`].concat(this.defaultStyle))}debug(t){this.state&&this.printFunctionNotify("db",o.getCallerName(),t)}drop(t,e){if(!this.state)return;const r=o.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",o.getCallerName(),t),r&&this.printNextLineObject("tw",o.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=o.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,s){this.out.apply(this,[`%c(${t})-> %c%c${this.name}%c::%c${e}%c(${Object.keys(s).join(", ")}) %c↓`].concat(this.defaultStyle));for(let t in s){let e=s[t];"object"==typeof e?e=JSON.stringify(this.useWrapper(e),r()):"function"==typeof s[t]&&(e=o.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 o.colorsInUse.some((e=>s(t,e)>=.8))?this.getRandomColor():t}out(...t){this.outputHandler.apply(this,t)}}var a=Object.freeze({__proto__:null,Logger:o});class i extends Error{constructor(t){super(`Command: '${t.getName()}' is already registered`)}}class c extends Error{constructor(t){super(`Command: '${t}' is not found`)}}class l extends Error{constructor(t){super(`Controller: '${t.getName()}' is already registered`)}}class h extends Error{constructor(t,e){super(`ForeMethod implementation: at '${t}' method: '${e}'`)}}class u extends Error{constructor(t,e){super(`ForeMethod implementation: at '${t.getName()}' method: '${e}'`)}}var p=Object.freeze({__proto__:null,CommandAlreadyRegistered:i,CommandNotFound:c,ControllerAlreadyRegistered:l,ForceMethod:u});let g=0;class m{virtualId=0;static getName(){throw new h("ObjectBase","getName")}constructor(){this.virtualId=g,g++}getName(){return this.constructor.getName()}}class d extends m{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 o(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 i(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){d.hookCommand(this.onBeforeHooks,t,e)}onBeforeUI(t,e){d.hookCommand(this.onBeforeUIHooks,t,e)}onAfter(t,e){d.hookCommand(this.onAfterHooks,t,e)}onAfterUI(t,e){d.hookCommand(this.onAfterUIHooks,t,e)}onAfterOnce(t,e){d.hookCommand(this.onAfterOnceHooks,t,e)}onAfterAffect(t,e){d.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 d.runCallbacks(Object.assign([],this.onAfterHooks[t.getName()]),e,r)),this.onAfterOnceHooks&&await d.runCallbacks(this.onAfterOnceHooks[t.getName()],e,{...r,pop:!0}),this.onAfterUIHooks&&d.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()),d.trace.push(t.getName())}detachCurrent(t){delete this.current[t.getName()],delete this.currentArgs[t.getName()],d.trace.pop(),this.trace.pop()}}class f extends m{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 l(t);return this.controllers[t.getName()]=t,t}}var C;!function(t){t.DELETE="DELETE",t.GET="GET",t.OPTIONS="OPTIONS",t.PATCH="PATCH",t.POST="POST",t.PUT="PUT",t.__EMPTY__=""}(C||(C={}));class y extends m{logger;apiBaseUrl;static getName(){return"Core/Clients/Http"}constructor(t="http://localhost"){super(),this.logger=new o(y.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={};[C.POST,C.PUT,C.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 b extends d{static client;currentHttpMethod;static getName(){return"Core/Managers/Data"}constructor(t){super(),b.client=new y(t.baseURL)}getClient(){return b.client}get(t,e={},r={}){return this.currentHttpMethod=C.GET,super.run(t,e,r)}update(t,e={},r={}){return this.currentHttpMethod=C.PATCH,super.run(t,e,r)}delete(t,e={},r={}){return this.currentHttpMethod=C.DELETE,super.run(t,e,r)}create(t,e={},r={}){return this.currentHttpMethod=C.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 C.GET===this.currentHttpMethod?s.args.query=e:s.args.data=e,e.result=await super.runInstance(t,s,r),this.currentHttpMethod=C.__EMPTY__,e.result}}class N extends d{static getName(){return"Core/Managers/Internal"}}const w=[];function O(t){k=new d,_=new f,j=new b(t),E=new N}function A(){k={},_={},j={},E={}}var k={},_={},j={},E={},H=Object.freeze({__proto__:null,afterInitializeCallbacks:w,get commands(){return k},get controllers(){return _},get data(){return j},destroy:A,initialize:O,get internal(){return E}});class I extends m{args={};options={};logger;constructor(t={},e={}){super();const r=this.constructor.getName();this.logger=new o(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 u(this,"apply")}async run(){this.onBeforeApply&&this.onBeforeApply();const t=await this.apply(this.args,this.options);return this.onAfterApply&&this.onAfterApply(),t}getArgs(){return this.args}getOptions(){return this.options}}var $=Object.freeze({__proto__:null,CommandBase:I,CommandData:class extends I{static getName(){return"Core/CommandBases/CommandData"}getEndpoint(){throw new u(this,"getEndpoint")}apply(t=this.args,e=this.options){const r=this.applyEndpointFormat(this.getEndpoint(),t);return j.getClient().fetch(r,j.currentHttpMethod,t||null)}applyEndpointFormat(t,e={}){return t.includes("{")&&(t=t.split("/").map((t=>{const r=t.match("\\{(.*?)\\}");return r?.length&&void 0!==e[r[1]]?e[r[1]]:t})).join("/")),t}},CommandInternal:class extends I{static getName(){return"Core/CommandBases/CommandInternal"}},CommandPublic:class extends I{static getName(){return"Core/CommandBases/CommandPublic"}}});var T=Object.freeze({__proto__:null,Controller:class extends m{commands;data;internal;static getName(){return"Core/Core/Controller"}constructor(){super(),this.initialize()}initialize(){this.register(),this.setupHooks&&this.setupHooks()}register(){this.commands=k.register(this.getCommands(),this),this.data=j.register(this.getData(),this),this.internal=E.register(this.getInternal(),this)}getCommands(){return{}}getData(){return{}}getInternal(){return{}}},ObjectBase:m}),B=Object.freeze({__proto__:null,Commands:d,Controllers:f,Data:b,Internal:N}),M=Object.freeze({__proto__:null,commandBases:$,core:T,errors:p,managerBases:B,managers:H,modules:a,utils:n});let x=!1;function U(){if(x)throw Error("ZenCore is already initialized.")}U();let D={version:e};const L={initialize:t=>{U(),D=t||D,O(D),x=!0},destroy:()=>{A(),x=!1},onAfterInitialize:t=>{w.push(t)},config:D,...M};globalThis?.ZenCore||(globalThis.ZenCore=L),t.commandBases=$,t.core=T,t.default=L,t.errors=p,t.managerBases=B,t.managers=H,t.modules=a,t.utils=n,Object.defineProperty(t,"__esModule",{value:!0})}));
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@zenflux/core",
3
- "version": "0.0.0-abc.2",
3
+ "version": "0.0.0-abc.20",
4
4
  "description": "ZenFlux core",
5
5
  "author": "Leonid Vinikov <leonidvinikov@gmail.com> (https://github.com/iNewLegend)",
6
6
  "scripts": {
7
7
  "test": "export flow_modules_logger=off && jest",
8
- "build": "rollup --config rollup.config.ts --configPlugin typescript"
8
+ "build": "rollup --config rollup.config.ts --configPlugin typescript",
9
+ "watch": "rollup --config rollup.config.ts --configPlugin typescript --watch"
9
10
  },
10
11
  "repository": {
11
12
  "type": "git",
@@ -5,7 +5,7 @@
5
5
  import { ForceMethod } from '../errors/force-method';
6
6
  import { CommandBase } from './command-base';
7
7
 
8
- import managers from '../managers/';
8
+ import * as managers from '../managers';
9
9
 
10
10
  export abstract class CommandData extends CommandBase {
11
11
  static getName() {
@@ -6,7 +6,7 @@ import ObjectBase from "./object-base";
6
6
 
7
7
  import { CommandData, CommandInternal, CommandPublic } from "../command-bases";
8
8
 
9
- import managers from "../managers/";
9
+ import * as managers from "../managers";
10
10
 
11
11
  export abstract class Controller extends ObjectBase {
12
12
  commands: { [ key: string ]: typeof CommandPublic };
package/src/exports.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  export * as commandBases from "./command-bases";
5
5
  export * as core from "./core";
6
6
  export * as errors from "./errors";
7
+ export * as managers from "./managers";
7
8
  export * as managerBases from "./manager-bases";
8
9
  export * as modules from "./modules";
9
10
  export * as utils from "./utils";
10
-
package/src/index.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
3
3
  */
4
+ export { CoreAPI as default } from "./initializer";
5
+
4
6
  export * from './exports';
5
7
 
6
- export { CoreAPI as default } from "./initializer";
7
8
 
@@ -1,10 +1,13 @@
1
1
  import pkg from "../package.json";
2
2
 
3
- import * as exported from './exports';
4
- import managers from './managers';
3
+ import './globals'
5
4
 
6
5
  import { IAPIConfig } from "./interfaces/config";
7
6
 
7
+ import { destroy, initialize, afterInitializeCallbacks } from "./managers";
8
+
9
+ import * as exported from './exports';
10
+
8
11
  declare global {
9
12
  var ZenCore: any;
10
13
  }
@@ -23,7 +26,6 @@ export let config: IAPIConfig = {
23
26
  version: pkg.version,
24
27
  }
25
28
 
26
- const afterInitializeCallbacks: ( () => void )[] = [];
27
29
 
28
30
  export const CoreAPI = {
29
31
  initialize: ( configuration?: IAPIConfig ) => {
@@ -31,23 +33,16 @@ export const CoreAPI = {
31
33
 
32
34
  config = configuration || config;
33
35
 
34
- managers.commands = new exported.managerBases.Commands();
35
- managers.controllers = new exported.managerBases.Controllers();
36
- managers.data = new exported.managerBases.Data( config );
37
- managers.internal = new exported.managerBases.Internal();
36
+ initialize( config )
38
37
 
39
38
  isInitialized = true;
40
39
 
41
- afterInitializeCallbacks.forEach( ( callback ) => callback() );
42
40
  },
43
41
 
44
42
  destroy: () => {
45
- isInitialized = false;
43
+ destroy();
46
44
 
47
- managers.commands = {} as exported.managerBases.Commands;
48
- managers.controllers = {} as exported.managerBases.Controllers
49
- managers.data = {} as exported.managerBases.Data;
50
- managers.internal = {} as exported.managerBases.Internal;
45
+ isInitialized = false;
51
46
  },
52
47
 
53
48
  onAfterInitialize: ( callback: () => void ) => {
@@ -0,0 +1,16 @@
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
+
6
+ import { IAPIConfig } from "./config";
7
+
8
+ export interface IManagers {
9
+ initialize: ( config: IAPIConfig ) => void;
10
+ destroy: () => void;
11
+
12
+ commands: Commands;
13
+ controllers: Controllers;
14
+ data: Data;
15
+ internal: Internal;
16
+ }
@@ -4,9 +4,11 @@
4
4
  */
5
5
  import { Logger } from "../modules/";
6
6
  import { CommandBase } from "../command-bases";
7
- import { Controller, ObjectBase } from "../core";
8
7
  import { CommandAlreadyRegistered, CommandNotFound } from "../errors/";
9
8
 
9
+ import ObjectBase from "../core/object-base";
10
+ import Controller from "../core/controller";
11
+
10
12
  import {
11
13
  ICommandArgsInterface,
12
14
  CommandCallbackType,
@@ -2,7 +2,8 @@
2
2
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
3
3
  * @description: Responsible for manging controllers, each controller is global singleton instance.
4
4
  */
5
- import { Controller, ObjectBase } from "../core";
5
+ import ObjectBase from "../core/object-base";
6
+ import Controller from "../core/controller";
6
7
 
7
8
  import { ControllerAlreadyRegistered } from "../errors/controller-already-registered";
8
9
 
@@ -1,13 +1,42 @@
1
1
  /**
2
2
  * @author: Leonid Vinikov <leonidvinikov@gmail.com>
3
3
  */
4
- import * as managersBases from "../manager-bases";
4
+ import Commands from "../manager-bases/commands";
5
+ import Controllers from "../manager-bases/controllers";
6
+ import Data from "../manager-bases/data";
7
+ import Internal from "../manager-bases/internal";
5
8
 
6
- export const managers = {
7
- commands: {} as managersBases.Commands,
8
- controllers: {} as managersBases.Controllers,
9
- data: {} as managersBases.Data,
10
- internal: {} as managersBases.Internal,
9
+ import { IAPIConfig } from "../interfaces/config";
10
+
11
+ import '../globals';
12
+
13
+ export const afterInitializeCallbacks: ( () => void )[] = [];
14
+
15
+ export function initialize( config: IAPIConfig ) {
16
+ commands = new Commands();
17
+ controllers = new Controllers();
18
+ data = new Data( config );
19
+ internal = new Internal();
20
+ }
21
+
22
+ export function destroy() {
23
+ commands = {} as Commands;
24
+ controllers = {} as Controllers;
25
+ data = {} as Data;
26
+ internal = {} as Internal;
11
27
  }
12
28
 
13
- export default managers;
29
+ export var commands = {} as Commands;
30
+ export var controllers = {} as Controllers;
31
+ export var data = {} as Data;
32
+ export var internal = {} as Internal;
33
+
34
+ /*
35
+ __ZEN_MANAGERS__.initialize = initialize;
36
+ __ZEN_MANAGERS__.destroy = destroy;
37
+
38
+ export var commands = __ZEN_MANAGERS__.commands;
39
+ export var controllers = __ZEN_MANAGERS__.controllers;
40
+ export var data = __ZEN_MANAGERS__.data;
41
+ export var internal = __ZEN_MANAGERS__.internal;
42
+ */
package/types/index.d.ts CHANGED
@@ -1,2 +1,5 @@
1
- export * from '../dist/es/src/exports';
2
1
  export { initialize, destroy, onAfterInitialize } from "../dist/es/src/initializer";
2
+
3
+ export * from '../dist/es/src/exports';
4
+ export * as managers from "../dist/es/src/managers";
5
+