Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@zenflux/core

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zenflux/core - npm Package Compare versions

Comparing version 0.0.0-abc.18 to 0.0.0-abc.19

21

dist/cjs/zenflux-core.js

@@ -6,3 +6,3 @@ 'use strict';

var name = "@zenflux/core";
var version = "0.0.0-abc.17";
var version = "0.0.0-abc.14";
var description = "ZenFlux core";

@@ -78,11 +78,11 @@ var author = "Leonid Vinikov <leonidvinikov@gmail.com> (https://github.com/iNewLegend)";

const managers = {
initialize: () => {},
destroy: () => {},
commands: {},
controllers: {},
data: {},
internal: {}
};
if (typeof __ZEN_MANAGERS__ === 'undefined' || !__ZEN_MANAGERS__) {
const managers = {
initialize: () => {},
destroy: () => {},
commands: {},
controllers: {},
data: {},
internal: {}
};
globalThis.__ZEN_MANAGERS__ = managers;

@@ -1118,4 +1118,3 @@ }

config,
...exported,
managers: typeof __ZEN_MANAGERS__ !== 'undefined' ? __ZEN_MANAGERS__ : {}
...exported
};

@@ -1122,0 +1121,0 @@ // TODO: Make it available only for development.

@@ -1,5 +0,3 @@

import Commands from "./manager-bases/commands";
import Controllers from "./manager-bases/controllers";
import Data from "./manager-bases/data";
import Internal from "./manager-bases/internal";
import { IManagers } from "./interfaces/managers";
declare const managers: IManagers;
declare global {

@@ -9,10 +7,4 @@ var ZenCore: any;

declare global {
var __ZEN_MANAGERS__: {
initialize: (config: any) => void;
destroy: () => void;
commands: Commands;
controllers: Controllers;
data: Data;
internal: Internal;
};
var __ZEN_MANAGERS__: typeof managers;
}
export {};
import './globals';
import { IAPIConfig } from "./interfaces/config";
import * as exported from './exports';
import { IManagers } from "./interfaces/managers";
export declare let config: IAPIConfig;
export declare const CoreAPI: {
managers: IManagers;
commandBases: typeof exported.commandBases;
core: typeof exported.core;
errors: typeof exported.errors;
managers: typeof exported.managers;
managerBases: typeof exported.managerBases;

@@ -12,0 +11,0 @@ modules: typeof exported.modules;

var name = "@zenflux/core";
var version = "0.0.0-abc.17";
var version = "0.0.0-abc.14";
var description = "ZenFlux core";

@@ -73,11 +73,11 @@ var author = "Leonid Vinikov <leonidvinikov@gmail.com> (https://github.com/iNewLegend)";

const managers = {
initialize: () => {},
destroy: () => {},
commands: {},
controllers: {},
data: {},
internal: {}
};
if (typeof __ZEN_MANAGERS__ === 'undefined' || !__ZEN_MANAGERS__) {
const managers = {
initialize: () => {},
destroy: () => {},
commands: {},
controllers: {},
data: {},
internal: {}
};
globalThis.__ZEN_MANAGERS__ = managers;

@@ -1113,4 +1113,3 @@ }

config,
...exported,
managers: typeof __ZEN_MANAGERS__ !== 'undefined' ? __ZEN_MANAGERS__ : {}
...exported
};

@@ -1117,0 +1116,0 @@ // TODO: Make it available only for development.

@@ -1,2 +0,2 @@

!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.17";if("undefined"==typeof __ZEN_MANAGERS__||!__ZEN_MANAGERS__){globalThis.__ZEN_MANAGERS__={initialize:()=>{},destroy:()=>{},commands:{},controllers:{},data:{},internal:{}}}
!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.14";"undefined"!=typeof __ZEN_MANAGERS__&&__ZEN_MANAGERS__||(globalThis.__ZEN_MANAGERS__={initialize:()=>{},destroy:()=>{},commands:{},controllers:{},data:{},internal:{}})
/**

@@ -6,3 +6,3 @@ * Function getCircularReplacer() : Reduce circular references.

* @copyright https://stackoverflow.com/a/53731154
*/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};
*/;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};
/**

@@ -12,2 +12,2 @@ * Function hexColorDelta() : Return color difference in ratio decimal point.

* @copyright http://jsfiddle.net/96sME/
*/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,e){super(`ForeMethod implementation: at '${t}' method: '${e}'`)}}class c extends Error{constructor(t,e){super(`ForeMethod implementation: at '${t.getName()}' method: '${e}'`)}}let l=0;class h{virtualId=0;static getName(){throw new i("ObjectBase","getName")}constructor(){this.virtualId=l,l++}getName(){return this.constructor.getName()}}var u=Object.freeze({__proto__:null,Controller:class extends h{commands;data;internal;static getName(){return"Core/Core/Controller"}constructor(){super(),this.initialize()}initialize(){this.register(),this.setupHooks&&this.setupHooks()}register(){this.commands=__ZEN_MANAGERS__.commands.register(this.getCommands(),this),this.data=__ZEN_MANAGERS__.data.register(this.getData(),this),this.internal=__ZEN_MANAGERS__.internal.register(this.getInternal(),this)}getCommands(){return{}}getData(){return{}}getInternal(){return{}}},ObjectBase:h});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,_=Object.freeze({__proto__:null,CommandAlreadyRegistered:p,CommandNotFound:g,ControllerAlreadyRegistered:m,ForceMethod:c});class f extends h{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 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){f.hookCommand(this.onBeforeHooks,t,e)}onBeforeUI(t,e){f.hookCommand(this.onBeforeUIHooks,t,e)}onAfter(t,e){f.hookCommand(this.onAfterHooks,t,e)}onAfterUI(t,e){f.hookCommand(this.onAfterUIHooks,t,e)}onAfterOnce(t,e){f.hookCommand(this.onAfterOnceHooks,t,e)}onAfterAffect(t,e){f.hookCommand(this.onAfterAffectHooks,t,e)}onBeforeRun(t,e={},r={}){if(this.onBeforeHooks[t.getName()]){this.onBeforeHooks[t.getName()].forEach((t=>t(e,r)))}if(this.onBeforeUIHooks[t.getName()]){this.onBeforeUIHooks[t.getName()].forEach((t=>t(e,r)))}}async runInstance(t,e={},r={}){let s=null;return Object.keys(e).length?(this.logger.startWith({command:t.getName(),options:r,CommandArgs:"->"}),this.logger.debug("CommandArgs:"),this.logger.object(e)):this.logger.startWith({command:t.getName(),options:r,args:e}),this.onBeforeRun(t,e,r),s=await t.run(),await this.onAfterRun(t,e,r,s),s}async onAfterRun(t,e,r,s){return r=Object.assign({},r),this.onAfterAffectHooks[t.getName()]&&(this.onAfterAffectHooks[t.getName()].forEach((t=>{e.result=s,s=this.run(""+t,e,r)})),s=await s),this.onAfterHooks&&(e.result=s,await f.runCallbacks(Object.assign([],this.onAfterHooks[t.getName()]),e,r)),this.onAfterOnceHooks&&await f.runCallbacks(this.onAfterOnceHooks[t.getName()],e,{...r,pop:!0}),this.onAfterUIHooks&&f.runCallbacks(Object.assign([],this.onAfterUIHooks[t.getName()]),e,r),s}attachCurrent(t,e={}){this.current[t.getName()]=t,this.currentArgs[t.getName()]=e,this.trace.push(t.getName()),f.trace.push(t.getName())}detachCurrent(t){delete this.current[t.getName()],delete this.currentArgs[t.getName()],f.trace.pop(),this.trace.pop()}}class N extends h{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 A extends h{logger;apiBaseUrl;static getName(){return"Core/Clients/Http"}constructor(t="http://localhost"){super(),this.logger=new o(A.getName(),!0),this.logger.startWith({apiBaseUrl:t}),this.apiBaseUrl=t+"/"}async fetch(t,e,r=null){this.logger.startWith({path:t,method:e,body:r});const s={credentials:"include"},n={};[d.POST,d.PUT,d.PATCH].includes(e)?(Object.assign(n,{"Content-Type":"application/json"}),Object.assign(s,{method:e,headers:n,body:JSON.stringify(r)})):Object.assign(s,{headers:n});const o=await globalThis.fetch(this.apiBaseUrl+t,s);let a;try{a=await o.json()}catch(t){return console.error(t),!1}if(a?.error&&a?.global&&a?.message)throw Error(a.message);return this.logger.drop({path:t},a),a}}class E extends f{static client;currentHttpMethod;static getName(){return"Core/Managers/Data"}constructor(t){super(),E.client=new A(t.baseURL)}getClient(){return E.client}get(t,e={},r={}){return this.currentHttpMethod=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 y extends f{static getName(){return"Core/Managers/Internal"}}const C=[];function b(t){__ZEN_MANAGERS__.commands=new f,__ZEN_MANAGERS__.controllers=new N,__ZEN_MANAGERS__.data=new E(t),__ZEN_MANAGERS__.internal=new y}function w(){__ZEN_MANAGERS__.commands={},__ZEN_MANAGERS__.controllers={},__ZEN_MANAGERS__.data={},__ZEN_MANAGERS__.internal={}}const O=__ZEN_MANAGERS__.controllers,M=__ZEN_MANAGERS__.commands,k=__ZEN_MANAGERS__.data,j=__ZEN_MANAGERS__.internal;__ZEN_MANAGERS__.initialize=b,__ZEN_MANAGERS__.destroy=w;var H=Object.freeze({__proto__:null,afterInitializeCallbacks:C,commands:M,controllers:O,data:k,destroy:w,initialize:b,internal:j});class I extends h{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 c(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 S=Object.freeze({__proto__:null,CommandBase:I,CommandData:class extends I{static getName(){return"Core/CommandBases/CommandData"}getEndpoint(){throw new c(this,"getEndpoint")}apply(t=this.args,e=this.options){const r=this.applyEndpointFormat(this.getEndpoint(),t);return __ZEN_MANAGERS__.data.getClient().fetch(r,__ZEN_MANAGERS__.data.currentHttpMethod,t||null)}applyEndpointFormat(t,e={}){return t.includes("{")&&(t=t.split("/").map((t=>{const r=t.match("\\{(.*?)\\}");return r?.length&&void 0!==e[r[1]]?e[r[1]]:t})).join("/")),t}},CommandInternal:class extends I{static getName(){return"Core/CommandBases/CommandInternal"}},CommandPublic:class extends I{static getName(){return"Core/CommandBases/CommandPublic"}}}),R=Object.freeze({__proto__:null,Commands:f,Controllers:N,Data:E,Internal:y}),T=Object.freeze({__proto__:null,commandBases:S,core:u,errors:_,managerBases:R,managers:H,modules:a,utils:n});let $=!1;function B(){if($)throw Error("ZenCore is already initialized.")}B();let G={version:e};const Z={initialize:t=>{B(),G=t||G,b(G),$=!0},destroy:()=>{w(),$=!1},onAfterInitialize:t=>{C.push(t)},config:G,...T,managers:"undefined"!=typeof __ZEN_MANAGERS__?__ZEN_MANAGERS__:{}};globalThis?.ZenCore||(globalThis.ZenCore=Z),t.commandBases=S,t.core=u,t.default=Z,t.errors=_,t.managerBases=R,t.managers=H,t.modules=a,t.utils=n,Object.defineProperty(t,"__esModule",{value:!0})}));
*/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,e){super(`ForeMethod implementation: at '${t}' method: '${e}'`)}}class c extends Error{constructor(t,e){super(`ForeMethod implementation: at '${t.getName()}' method: '${e}'`)}}let l=0;class h{virtualId=0;static getName(){throw new i("ObjectBase","getName")}constructor(){this.virtualId=l,l++}getName(){return this.constructor.getName()}}var u=Object.freeze({__proto__:null,Controller:class extends h{commands;data;internal;static getName(){return"Core/Core/Controller"}constructor(){super(),this.initialize()}initialize(){this.register(),this.setupHooks&&this.setupHooks()}register(){this.commands=__ZEN_MANAGERS__.commands.register(this.getCommands(),this),this.data=__ZEN_MANAGERS__.data.register(this.getData(),this),this.internal=__ZEN_MANAGERS__.internal.register(this.getInternal(),this)}getCommands(){return{}}getData(){return{}}getInternal(){return{}}},ObjectBase:h});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,_=Object.freeze({__proto__:null,CommandAlreadyRegistered:p,CommandNotFound:g,ControllerAlreadyRegistered:m,ForceMethod:c});class f extends h{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 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){f.hookCommand(this.onBeforeHooks,t,e)}onBeforeUI(t,e){f.hookCommand(this.onBeforeUIHooks,t,e)}onAfter(t,e){f.hookCommand(this.onAfterHooks,t,e)}onAfterUI(t,e){f.hookCommand(this.onAfterUIHooks,t,e)}onAfterOnce(t,e){f.hookCommand(this.onAfterOnceHooks,t,e)}onAfterAffect(t,e){f.hookCommand(this.onAfterAffectHooks,t,e)}onBeforeRun(t,e={},r={}){if(this.onBeforeHooks[t.getName()]){this.onBeforeHooks[t.getName()].forEach((t=>t(e,r)))}if(this.onBeforeUIHooks[t.getName()]){this.onBeforeUIHooks[t.getName()].forEach((t=>t(e,r)))}}async runInstance(t,e={},r={}){let s=null;return Object.keys(e).length?(this.logger.startWith({command:t.getName(),options:r,CommandArgs:"->"}),this.logger.debug("CommandArgs:"),this.logger.object(e)):this.logger.startWith({command:t.getName(),options:r,args:e}),this.onBeforeRun(t,e,r),s=await t.run(),await this.onAfterRun(t,e,r,s),s}async onAfterRun(t,e,r,s){return r=Object.assign({},r),this.onAfterAffectHooks[t.getName()]&&(this.onAfterAffectHooks[t.getName()].forEach((t=>{e.result=s,s=this.run(""+t,e,r)})),s=await s),this.onAfterHooks&&(e.result=s,await f.runCallbacks(Object.assign([],this.onAfterHooks[t.getName()]),e,r)),this.onAfterOnceHooks&&await f.runCallbacks(this.onAfterOnceHooks[t.getName()],e,{...r,pop:!0}),this.onAfterUIHooks&&f.runCallbacks(Object.assign([],this.onAfterUIHooks[t.getName()]),e,r),s}attachCurrent(t,e={}){this.current[t.getName()]=t,this.currentArgs[t.getName()]=e,this.trace.push(t.getName()),f.trace.push(t.getName())}detachCurrent(t){delete this.current[t.getName()],delete this.currentArgs[t.getName()],f.trace.pop(),this.trace.pop()}}class N extends h{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 A extends h{logger;apiBaseUrl;static getName(){return"Core/Clients/Http"}constructor(t="http://localhost"){super(),this.logger=new o(A.getName(),!0),this.logger.startWith({apiBaseUrl:t}),this.apiBaseUrl=t+"/"}async fetch(t,e,r=null){this.logger.startWith({path:t,method:e,body:r});const s={credentials:"include"},n={};[d.POST,d.PUT,d.PATCH].includes(e)?(Object.assign(n,{"Content-Type":"application/json"}),Object.assign(s,{method:e,headers:n,body:JSON.stringify(r)})):Object.assign(s,{headers:n});const o=await globalThis.fetch(this.apiBaseUrl+t,s);let a;try{a=await o.json()}catch(t){return console.error(t),!1}if(a?.error&&a?.global&&a?.message)throw Error(a.message);return this.logger.drop({path:t},a),a}}class E extends f{static client;currentHttpMethod;static getName(){return"Core/Managers/Data"}constructor(t){super(),E.client=new A(t.baseURL)}getClient(){return E.client}get(t,e={},r={}){return this.currentHttpMethod=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 y extends f{static getName(){return"Core/Managers/Internal"}}const C=[];function b(t){__ZEN_MANAGERS__.commands=new f,__ZEN_MANAGERS__.controllers=new N,__ZEN_MANAGERS__.data=new E(t),__ZEN_MANAGERS__.internal=new y}function w(){__ZEN_MANAGERS__.commands={},__ZEN_MANAGERS__.controllers={},__ZEN_MANAGERS__.data={},__ZEN_MANAGERS__.internal={}}const O=__ZEN_MANAGERS__.controllers,M=__ZEN_MANAGERS__.commands,k=__ZEN_MANAGERS__.data,j=__ZEN_MANAGERS__.internal;__ZEN_MANAGERS__.initialize=b,__ZEN_MANAGERS__.destroy=w;var H=Object.freeze({__proto__:null,afterInitializeCallbacks:C,commands:M,controllers:O,data:k,destroy:w,initialize:b,internal:j});class I extends h{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 c(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 S=Object.freeze({__proto__:null,CommandBase:I,CommandData:class extends I{static getName(){return"Core/CommandBases/CommandData"}getEndpoint(){throw new c(this,"getEndpoint")}apply(t=this.args,e=this.options){const r=this.applyEndpointFormat(this.getEndpoint(),t);return __ZEN_MANAGERS__.data.getClient().fetch(r,__ZEN_MANAGERS__.data.currentHttpMethod,t||null)}applyEndpointFormat(t,e={}){return t.includes("{")&&(t=t.split("/").map((t=>{const r=t.match("\\{(.*?)\\}");return r?.length&&void 0!==e[r[1]]?e[r[1]]:t})).join("/")),t}},CommandInternal:class extends I{static getName(){return"Core/CommandBases/CommandInternal"}},CommandPublic:class extends I{static getName(){return"Core/CommandBases/CommandPublic"}}}),R=Object.freeze({__proto__:null,Commands:f,Controllers:N,Data:E,Internal:y}),T=Object.freeze({__proto__:null,commandBases:S,core:u,errors:_,managerBases:R,managers:H,modules:a,utils:n});let $=!1;function B(){if($)throw Error("ZenCore is already initialized.")}B();let G={version:e};const x={initialize:t=>{B(),G=t||G,b(G),$=!0},destroy:()=>{w(),$=!1},onAfterInitialize:t=>{C.push(t)},config:G,...T};globalThis?.ZenCore||(globalThis.ZenCore=x),t.commandBases=S,t.core=u,t.default=x,t.errors=_,t.managerBases=R,t.managers=H,t.modules=a,t.utils=n,Object.defineProperty(t,"__esModule",{value:!0})}));
{
"name": "@zenflux/core",
"version": "0.0.0-abc.18",
"version": "0.0.0-abc.19",
"description": "ZenFlux core",

@@ -5,0 +5,0 @@ "author": "Leonid Vinikov <leonidvinikov@gmail.com> (https://github.com/iNewLegend)",

@@ -8,13 +8,13 @@ import Commands from "./manager-bases/commands";

if ( typeof __ZEN_MANAGERS__ === 'undefined' || ! __ZEN_MANAGERS__ ) {
const managers: IManagers = {
initialize: () => {},
destroy: () => {},
const managers: IManagers = {
initialize: () => {},
destroy: () => {},
commands: {} as Commands,
controllers: {} as Controllers,
data: {} as Data,
internal: {} as Internal,
}
commands: {} as Commands,
controllers: {} as Controllers,
data: {} as Data,
internal: {} as Internal,
}
if ( typeof __ZEN_MANAGERS__ === 'undefined' || ! __ZEN_MANAGERS__ ) {
globalThis.__ZEN_MANAGERS__ = managers;

@@ -28,11 +28,3 @@ }

declare global {
var __ZEN_MANAGERS__: {
initialize: ( config: any ) => void;
destroy: () => void;
commands: Commands;
controllers: Controllers;
data: Data;
internal: Internal;
}
var __ZEN_MANAGERS__: typeof managers;
}

@@ -52,4 +52,2 @@ import pkg from "../package.json";

...exported,
managers: typeof __ZEN_MANAGERS__ !== 'undefined' ? __ZEN_MANAGERS__ : {} as IManagers
}

@@ -56,0 +54,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc