Socket
Socket
Sign inDemoInstall

@zenflux/core

Package Overview
Dependencies
2
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.0-abc.1 to 0.0.0-abc.2

35

dist/cjs/zenflux-core.js

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

var index$6 = /*#__PURE__*/Object.freeze({
var index$5 = /*#__PURE__*/Object.freeze({
__proto__: null,

@@ -449,15 +449,9 @@ getCircularReplacer: getCircularReplacer,

let commands = {};
let controllers = {};
let data = {};
let internal = {};
const managers = {
commands: {},
controllers: {},
data: {},
internal: {}
};
var index$5 = /*#__PURE__*/Object.freeze({
__proto__: null,
commands: commands,
controllers: controllers,
data: data,
internal: internal
});
/**

@@ -485,3 +479,3 @@ * @author: Leonid Vinikov <leonidvinikov@gmail.com>

const endpoint = this.applyEndpointFormat(this.getEndpoint(), args);
return data.getClient().fetch(endpoint, data.currentHttpMethod, args || null);
return managers.data.getClient().fetch(endpoint, managers.data.currentHttpMethod, args || null);
}

@@ -545,5 +539,5 @@ applyEndpointFormat(endpoint, data = {}) {

register() {
this.commands = commands.register(this.getCommands(), this);
this.data = data.register(this.getData(), this);
this.internal = internal.register(this.getInternal(), this);
this.commands = managers.commands.register(this.getCommands(), this);
this.data = managers.data.register(this.getData(), this);
this.internal = managers.internal.register(this.getInternal(), this);
}

@@ -985,5 +979,4 @@ getCommands() {

managerBases: index,
managers: index$5,
modules: index$1,
utils: index$6
utils: index$5
});

@@ -1062,3 +1055,2 @@

const managers = index$5;
let isInitialized = false;

@@ -1107,4 +1099,3 @@ function errorInitTwice() {

exports.managerBases = index;
exports.managers = index$5;
exports.modules = index$1;
exports.utils = index$6;
exports.utils = index$5;

@@ -7,5 +7,4 @@ /**

export * as errors from "./errors";
export * as managers from "./managers";
export * as managerBases from "./manager-bases";
export * as modules from "./modules";
export * as utils from "./utils";

@@ -11,3 +11,2 @@ import * as exported from './exports';

errors: typeof exported.errors;
managers: typeof exported.managers;
managerBases: typeof exported.managerBases;

@@ -14,0 +13,0 @@ modules: typeof exported.modules;

@@ -5,5 +5,8 @@ /**

import * as managersBases from "../manager-bases";
export declare let commands: managersBases.Commands;
export declare let controllers: managersBases.Controllers;
export declare let data: managersBases.Data;
export declare let internal: managersBases.Internal;
export declare const managers: {
commands: managersBases.Commands;
controllers: managersBases.Controllers;
data: managersBases.Data;
internal: managersBases.Internal;
};
export default managers;

@@ -83,3 +83,3 @@ class ForceMethodBase extends Error {

var index$6 = /*#__PURE__*/Object.freeze({
var index$5 = /*#__PURE__*/Object.freeze({
__proto__: null,

@@ -445,15 +445,9 @@ getCircularReplacer: getCircularReplacer,

let commands = {};
let controllers = {};
let data = {};
let internal = {};
const managers = {
commands: {},
controllers: {},
data: {},
internal: {}
};
var index$5 = /*#__PURE__*/Object.freeze({
__proto__: null,
commands: commands,
controllers: controllers,
data: data,
internal: internal
});
/**

@@ -481,3 +475,3 @@ * @author: Leonid Vinikov <leonidvinikov@gmail.com>

const endpoint = this.applyEndpointFormat(this.getEndpoint(), args);
return data.getClient().fetch(endpoint, data.currentHttpMethod, args || null);
return managers.data.getClient().fetch(endpoint, managers.data.currentHttpMethod, args || null);
}

@@ -541,5 +535,5 @@ applyEndpointFormat(endpoint, data = {}) {

register() {
this.commands = commands.register(this.getCommands(), this);
this.data = data.register(this.getData(), this);
this.internal = internal.register(this.getInternal(), this);
this.commands = managers.commands.register(this.getCommands(), this);
this.data = managers.data.register(this.getData(), this);
this.internal = managers.internal.register(this.getInternal(), this);
}

@@ -981,5 +975,4 @@ getCommands() {

managerBases: index,
managers: index$5,
modules: index$1,
utils: index$6
utils: index$5
});

@@ -1058,3 +1051,2 @@

const managers = index$5;
let isInitialized = false;

@@ -1098,2 +1090,2 @@ function errorInitTwice() {

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 };
export { index$4 as commandBases, index$3 as core, CoreAPI as default, index$2 as errors, index as managerBases, index$1 as modules, index$5 as utils };

@@ -12,2 +12,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";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()}}

* @copyright http://jsfiddle.net/96sME/
*/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})}));
*/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})}));
{
"name": "@zenflux/core",
"version": "0.0.0-abc.1",
"version": "0.0.0-abc.2",
"description": "ZenFlux core",

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

@@ -8,3 +8,3 @@ /**

import { data } from '../managers/';
import managers from '../managers/';

@@ -32,4 +32,4 @@ export abstract class CommandData extends CommandBase {

return data.getClient().fetch(
endpoint, data.currentHttpMethod, args || null
return managers.data.getClient().fetch(
endpoint, managers.data.currentHttpMethod, args || null
);

@@ -36,0 +36,0 @@ }

@@ -9,3 +9,3 @@ /**

import * as managers from "../managers/";
import managers from "../managers/";

@@ -12,0 +12,0 @@ export abstract class Controller extends ObjectBase {

@@ -7,3 +7,2 @@ /**

export * as errors from "./errors";
export * as managers from "./managers";
export * as managerBases from "./manager-bases";

@@ -10,0 +9,0 @@ export * as modules from "./modules";

import pkg from "../package.json";
import * as exported from './exports';
import managers from './managers';
const managers = exported.managers;
import { IAPIConfig } from "./interfaces/config";

@@ -8,0 +7,0 @@

@@ -6,5 +6,9 @@ /**

export let commands = {} as managersBases.Commands;
export let controllers = {} as managersBases.Controllers;
export let data = {} as managersBases.Data;
export let internal = {} as managersBases.Internal;
export const managers = {
commands: {} as managersBases.Commands,
controllers: {} as managersBases.Controllers,
data: {} as managersBases.Data,
internal: {} as managersBases.Internal,
}
export default managers;

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc