@zenflux/core 0.1.28 → 0.1.30
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.
- package/dist/.tsconfig.probe.tsbuildinfo +1 -0
- package/dist/src/exports.d.ts +0 -3
- package/dist/src/index.d.ts +0 -5
- package/dist/src/modules/logger/implementation.d.ts +1 -0
- package/dist/zenflux-core.cjs +37 -119
- package/dist/zenflux-core.d.ts +3 -32
- package/dist/zenflux-core.mjs +38 -117
- package/package.json +2 -2
- package/src/bases/cache-base.ts +64 -0
- package/src/bases/controller-base.ts +96 -0
- package/src/bases/index.ts +9 -0
- package/src/bases/initialize-base.ts +32 -0
- package/src/bases/object-base.ts +55 -0
- package/src/bases/singleton-base.ts +18 -0
- package/src/clients/http.ts +152 -0
- package/src/command-bases/command-base.ts +80 -0
- package/src/command-bases/command-internal.ts +11 -0
- package/src/command-bases/command-public.ts +12 -0
- package/src/command-bases/command-restful.ts +55 -0
- package/src/command-bases/index.ts +8 -0
- package/src/errors/command-already-registered.ts +13 -0
- package/src/errors/command-not-found.ts +12 -0
- package/src/errors/controller-already-registered.ts +13 -0
- package/src/errors/controller-already-set.ts +13 -0
- package/src/errors/error-with-metadata.ts +29 -0
- package/src/errors/force-method-implementation.ts +15 -0
- package/src/errors/index-public.ts +1 -0
- package/src/errors/index.ts +10 -0
- package/src/exports-index.ts +15 -0
- package/src/exports.ts +55 -0
- package/src/index.ts +18 -0
- package/src/interfaces/commands.ts +17 -0
- package/src/interfaces/config.ts +23 -0
- package/src/interfaces/index.ts +8 -0
- package/src/interfaces/logger.ts +19 -0
- package/src/interfaces/restful.ts +23 -0
- package/src/managers/commands.ts +269 -0
- package/src/managers/controllers.ts +40 -0
- package/src/managers/export.ts +30 -0
- package/src/managers/index.ts +8 -0
- package/src/managers/internal.ts +11 -0
- package/src/managers/restful.ts +117 -0
- package/src/modules/debugger.ts +86 -0
- package/src/modules/event-bus/event-bus.ts +238 -0
- package/src/modules/export.ts +6 -0
- package/src/modules/logger/config.ts +66 -0
- package/src/modules/logger/create-logger.ts +38 -0
- package/src/modules/logger/implementation.ts +371 -0
- package/src/modules/logger/index.ts +3 -0
- package/src/modules/logger/logger-browser-infra.ts +364 -0
- package/src/modules/logger/types/picocolors.d.ts +15 -0
- package/src/modules/logger/utils/index.ts +3 -0
- package/src/modules/logger/utils/object.ts +19 -0
- package/src/modules/logger/utils/rgb.ts +34 -0
- package/src/modules/mcp-server/mcp-server.ts +139 -0
- package/src/modules/mcp-server/mcp-service.ts +80 -0
- package/src/modules/service/service-base.ts +55 -0
- package/src/modules/service/service-locator.ts +205 -0
- package/src/modules/service/service-with-dependencies-base.ts +51 -0
package/dist/zenflux-core.cjs
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Bundled with love using the help of @zenflux/cli toolkit v0.1.43
|
|
3
|
-
* Bundle name: @zenflux/core fileName: 'zenflux-core', built at Tue
|
|
3
|
+
* Bundle name: @zenflux/core fileName: 'zenflux-core', built at Tue Sep 01 2026 19:12:30 GMT+0300 (Israel Daylight Time)
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
'use strict';
|
|
7
7
|
|
|
8
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
9
|
-
|
|
10
8
|
var util = require('util');
|
|
11
9
|
var EventEmitter = require('events');
|
|
12
10
|
|
|
@@ -44,7 +42,37 @@ class ErrorWithMetadata extends Error{metadata;constructor(message,metadata=null
|
|
|
44
42
|
|
|
45
43
|
class ObjectBase{id;name="__UNDEFINED_NAME__";constructor(){this.name=this.getName();const timestamp=performance.now()*1e6;const random1=BigInt(Math.floor(Math.random()*1e6));const random2=BigInt(Math.floor(Math.random()*1e6));this.id=`${timestamp}${random1}${random2}`;}static getName(){throw new ForceMethodBase(this.name,"getName")}static getSourcePath(){throw new ForceMethodBase(this.name,"getSourcePath")}getName(){return this.constructor.getName()}getUniqueId(){return this.id}getInitialName(){return this.name}getHierarchyNames(){const classNames=[];let obj=Object.getPrototypeOf(this);let className;while((className=obj.getName())!=="Object"){classNames.push(className);obj=Object.getPrototypeOf(obj);if(obj.constructor===ObjectBase){break}}return classNames}}
|
|
46
44
|
|
|
47
|
-
|
|
45
|
+
var commonjsGlobal=typeof globalThis!=="undefined"?globalThis:typeof window!=="undefined"?window:typeof global!=="undefined"?global:typeof self!=="undefined"?self:{};function getDefaultExportFromCjs(x){return x&&x.__esModule&&Object.prototype.hasOwnProperty.call(x,"default")?x["default"]:x}function getDefaultExportFromNamespaceIfPresent(n){return n&&Object.prototype.hasOwnProperty.call(n,"default")?n["default"]:n}function getDefaultExportFromNamespaceIfNotNamed(n){return n&&Object.prototype.hasOwnProperty.call(n,"default")&&Object.keys(n).length===1?n["default"]:n}function getAugmentedNamespace(n){if(Object.prototype.hasOwnProperty.call(n,"__esModule"))return n;var f=n.default;if(typeof f=="function"){var a=function a(){var isInstance=false;try{isInstance=this instanceof a;}catch{}if(isInstance){return Reflect.construct(f,arguments,this.constructor)}return f.apply(this,arguments)};a.prototype=f.prototype;}else a={};Object.defineProperty(a,"__esModule",{value:true});Object.keys(n).forEach(function(k){var d=Object.getOwnPropertyDescriptor(n,k);Object.defineProperty(a,k,d.get?d:{enumerable:true,get:function(){return n[k]}});});return a}
|
|
46
|
+
|
|
47
|
+
var picocolors$1={exports:{}};
|
|
48
|
+
|
|
49
|
+
var picocolors=picocolors$1.exports;var hasRequiredPicocolors;function requirePicocolors(){if(hasRequiredPicocolors)return picocolors$1.exports;hasRequiredPicocolors=1;let p=process||{},argv=p.argv||[],env=p.env||{};let isColorSupported=!(!!env.NO_COLOR||argv.includes("--no-color"))&&(!!env.FORCE_COLOR||argv.includes("--color")||p.platform==="win32"||(p.stdout||{}).isTTY&&env.TERM!=="dumb"||!!env.CI);let formatter=(open,close,replace=open)=>input=>{let string=""+input,index=string.indexOf(close,open.length);return ~index?open+replaceClose(string,close,replace,index)+close:open+string+close};let replaceClose=(string,close,replace,index)=>{let result="",cursor=0;do{result+=string.substring(cursor,index)+replace;cursor=index+close.length;index=string.indexOf(close,cursor);}while(~index)return result+string.substring(cursor)};let createColors=(enabled=isColorSupported)=>{let f=enabled?formatter:()=>String;return {isColorSupported:enabled,reset:f("\x1b[0m","\x1b[0m"),bold:f("\x1b[1m","\x1b[22m","\x1b[22m\x1b[1m"),dim:f("\x1b[2m","\x1b[22m","\x1b[22m\x1b[2m"),italic:f("\x1b[3m","\x1b[23m"),underline:f("\x1b[4m","\x1b[24m"),inverse:f("\x1b[7m","\x1b[27m"),hidden:f("\x1b[8m","\x1b[28m"),strikethrough:f("\x1b[9m","\x1b[29m"),black:f("\x1b[30m","\x1b[39m"),red:f("\x1b[31m","\x1b[39m"),green:f("\x1b[32m","\x1b[39m"),yellow:f("\x1b[33m","\x1b[39m"),blue:f("\x1b[34m","\x1b[39m"),magenta:f("\x1b[35m","\x1b[39m"),cyan:f("\x1b[36m","\x1b[39m"),white:f("\x1b[37m","\x1b[39m"),gray:f("\x1b[90m","\x1b[39m"),bgBlack:f("\x1b[40m","\x1b[49m"),bgRed:f("\x1b[41m","\x1b[49m"),bgGreen:f("\x1b[42m","\x1b[49m"),bgYellow:f("\x1b[43m","\x1b[49m"),bgBlue:f("\x1b[44m","\x1b[49m"),bgMagenta:f("\x1b[45m","\x1b[49m"),bgCyan:f("\x1b[46m","\x1b[49m"),bgWhite:f("\x1b[47m","\x1b[49m"),blackBright:f("\x1b[90m","\x1b[39m"),redBright:f("\x1b[91m","\x1b[39m"),greenBright:f("\x1b[92m","\x1b[39m"),yellowBright:f("\x1b[93m","\x1b[39m"),blueBright:f("\x1b[94m","\x1b[39m"),magentaBright:f("\x1b[95m","\x1b[39m"),cyanBright:f("\x1b[96m","\x1b[39m"),whiteBright:f("\x1b[97m","\x1b[39m"),bgBlackBright:f("\x1b[100m","\x1b[49m"),bgRedBright:f("\x1b[101m","\x1b[49m"),bgGreenBright:f("\x1b[102m","\x1b[49m"),bgYellowBright:f("\x1b[103m","\x1b[49m"),bgBlueBright:f("\x1b[104m","\x1b[49m"),bgMagentaBright:f("\x1b[105m","\x1b[49m"),bgCyanBright:f("\x1b[106m","\x1b[49m"),bgWhiteBright:f("\x1b[107m","\x1b[49m")}};picocolors$1.exports=createColors();picocolors$1.exports.createColors=createColors;return picocolors$1.exports}
|
|
50
|
+
|
|
51
|
+
var picocolorsExports=requirePicocolors();var pc = getDefaultExportFromCjs(picocolorsExports);
|
|
52
|
+
|
|
53
|
+
const DEFAULT_LOG_LEVEL="5";function getEnvVar(key){if(typeof process!=="undefined"&&process?.env){return process.env[key]??process.env[`VITE_${key}`]}if(typeof ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('zenflux-core.cjs', document.baseURI).href)) })!=="undefined"&&undefined){const env=undefined;return env[key]??env[`VITE_${key}`]}return undefined}function getLoggerDefaultLevel(){return DEFAULT_LOG_LEVEL}function getLoggerLogLevel(){const raw=getEnvVar("LOGGER_LOG_LEVEL");return parseInt(raw??DEFAULT_LOG_LEVEL,10)}function getLoggerTimeFormat(){return (getEnvVar("LOGGER_TIME_FORMAT")||"").trim()}function getLoggerLogLevelString(){switch(getLoggerLogLevel()){case 0:return "NONE";case 1:return "ERROR";case 2:return "WARN";case 3:return "ADMIN";case 4:return "INFO";case 5:return "LOG";case 6:return "DEBUG";default:return "UNKNOWN"}}function isLoggerDebugEnabled(){return getLoggerLogLevel()>=6}function isLoggerDisabled(){return getEnvVar("LOGGER_DISABLED")==="true"}function isLoggerPreviousSourceDisabled(){return getEnvVar("LOGGER_LOG_PREVIOUS_CALLER_SOURCE_DISABLED")==="true"}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Reduce circular references.
|
|
57
|
+
*
|
|
58
|
+
* @copyright https://stackoverflow.com/a/53731154
|
|
59
|
+
*/const reduceCircularReferences=()=>{const seen=new WeakSet;return (key,value)=>{if(typeof value==="object"&&value!==null){if(seen.has(value)){return}seen.add(value);}return value}};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Function hexColorDelta() : Return color difference in ratio decimal point.
|
|
63
|
+
*
|
|
64
|
+
* @copyright http://jsfiddle.net/96sME/
|
|
65
|
+
*/const getHexColorDelta=function(hex1,hex2){hex1=hex1.replace("#","");hex2=hex2.replace("#","");const r1=parseInt(hex1.substring(0,2),16);const g1=parseInt(hex1.substring(2,4),16);const b1=parseInt(hex1.substring(4,6),16);const r2=parseInt(hex2.substring(0,2),16);const g2=parseInt(hex2.substring(2,4),16);const b2=parseInt(hex2.substring(4,6),16);let r=255-Math.abs(r1-r2);let g=255-Math.abs(g1-g2);let b=255-Math.abs(b1-b2);r/=255;g/=255;b/=255;return (r+g+b)/3};
|
|
66
|
+
|
|
67
|
+
const MAX_MAPPING_RECURSIVE_DEPTH=4,UNKNOWN_CALLER_NAME="anonymous function";Error.stackTraceLimit=50;class LoggerBrowserInfra extends ObjectBase{static mappers=[];static mapperDepth=0;static colorsOwners={};static colorsUsed=[];static outputSubscribers=new Set;defaultStyle;owner;args;color;outputHandler=console.log;pendingOutputMetadata;static getName(){return "ZenFlux/Logging/Modules/LoggerBrowserInfra"}static reset(){LoggerBrowserInfra.mappers=[];LoggerBrowserInfra.mapperDepth=0;LoggerBrowserInfra.colorsUsed=[];LoggerBrowserInfra.colorsOwners={};LoggerBrowserInfra.outputSubscribers.clear();}static attachOutputSubscriber(subscriber){LoggerBrowserInfra.outputSubscribers.add(subscriber);return ()=>{LoggerBrowserInfra.outputSubscribers.delete(subscriber);}}static createObjectMapper(callback){LoggerBrowserInfra.mappers.push(callback);}static useObjectMapper(obj,shouldHandleChildren=true){if(!obj||Array.isArray(obj)||"object"!==typeof obj){return obj}LoggerBrowserInfra.mapperDepth++;let result={...obj};LoggerBrowserInfra.mappers.forEach(mapper=>{result=mapper(obj)||result;});if(LoggerBrowserInfra.mapperDepth>=MAX_MAPPING_RECURSIVE_DEPTH){LoggerBrowserInfra.mapperDepth--;return result}if(shouldHandleChildren&&result){Object.entries(result).forEach(([key,value])=>{result[key]=this.useObjectMapper(value,true);});}LoggerBrowserInfra.mapperDepth--;return result}constructor(owner,args={}){super();this.args={repeatedly:false,...args};this.owner=owner;this.initialize();}getOwnerName(){if(typeof this.owner==="string"){return this.owner}if(this.owner instanceof ObjectBase){return this.owner.getName()}if(this.owner&&typeof this.owner.getName==="function"){return this.owner.getName()}return "UnknownOwner"}initialize(){const ownerName=this.getOwnerName();if(this.args.repeatedly&&LoggerBrowserInfra.colorsOwners[ownerName]){this.color=LoggerBrowserInfra.colorsOwners[ownerName];}else {this.color=this.getRandomColor();}LoggerBrowserInfra.colorsOwners[ownerName]=this.color;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"];}output(...args){this.outputHandler.apply(this,args);if(LoggerBrowserInfra.outputSubscribers.size===0){return}const event={logger:this,namespace:this.getOwnerName(),args,metadata:this.pendingOutputMetadata};LoggerBrowserInfra.outputSubscribers.forEach(subscriber=>{try{subscriber(event);}catch(error){console.error("[ZenFlux][Logger] output subscriber failed",error);}});}setOutputHandler(outputHandler){this.outputHandler=outputHandler;}runWithOutputMetadata(metadata,callback){const previous=this.pendingOutputMetadata;this.pendingOutputMetadata=metadata;try{return callback()}finally{this.pendingOutputMetadata=previous;}}printFunctionNotify(prefix,caller,output){const callerName=this.getCallerName(caller);this.output.apply(this,[`%c(${prefix})-> %c%c${this.getOwnerName()}%c::%c${callerName}%c() ${output}%c`].concat(this.defaultStyle));}printObjectEfficient(prefix,caller,params){params=Object.assign({},params);if(typeof params==="string"){this.printInLineString(prefix,caller,params);return}if(Object.keys(params).length===1){const key=Object.keys(params)[0];let value=Object.values(params)[0];if("object"===typeof value){this.printInNextLineObject(prefix,caller,key,value||{});}else if("function"===typeof value){this.printInLineFunction(prefix,caller,key,value);}else {this.printInLineElement(prefix,caller,key,value);}return}this.printMultiLineObject(prefix,caller,params);}printInLineElement(prefix,caller,key,value,notice=""){const callerName=this.getCallerName(caller),ownerName=this.getOwnerName(),format=notice.length?`%c(${prefix})-> %c%c${ownerName}%c::%c${callerName}%c() ->> [${notice}] ->> ${key}: '${value}'%c`:`%c(${prefix})-> %c%c${ownerName}%c::%c${callerName}%c() ->> ${key}: '${value}'%c`;this.output.apply(this,[format].concat(this.defaultStyle));}printInLineFunction(prefix,caller,key,fn){fn=this.getFunctionView(fn);this.printInLineElement(prefix,caller,key,fn);}printInLineString(prefix,caller,string){this.printInLineElement(prefix,caller,"(string)",string);}printInNextLineObject(prefix,caller,key,obj){const mapped=LoggerBrowserInfra.useObjectMapper(obj),callerName=this.getCallerName(caller);this.output.apply(this,[`%c(${prefix})-> %c%c${this.getOwnerName()}%c::%c${callerName}%c() ->> ${key} %c↓`].concat(this.defaultStyle));this.output(mapped);}printMultiLineObject(prefix,caller,obj){const callerName=this.getCallerName(caller);this.output.apply(this,[`%c(${prefix})-> %c%c${this.getOwnerName()}%c::%c${callerName}%c(${Object.keys(obj).join(", ")}) %c↓`].concat(this.defaultStyle));for(let key in obj){let value=obj[key];if(typeof value==="object"){const mapped=LoggerBrowserInfra.useObjectMapper(value);value=JSON.stringify(mapped,reduceCircularReferences());}else if(typeof obj[key]=="function"){value=this.getFunctionView(value);}this.output.apply(this,["%c"+key+": `"+value+"`","color: #a3a3a3"]);}}getRandomColor(){const hex="0123456789ABCDEF";let color="#";for(let i=0;i<6;i++){color+=hex[Math.floor(Math.random()*16)];}return color}getCallerName(caller){if("function"===typeof caller){return caller.prototype instanceof ObjectBase?"constructor":caller.name}throw new Error("Invalid caller")}getFunctionView(fn){let fReturn=UNKNOWN_CALLER_NAME;if(typeof fn!=="string"&&fn.name.length!==0){fReturn=fn.name.split(" ")[1]+"()";}return fReturn}}
|
|
68
|
+
|
|
69
|
+
let SimpleEventEmitter=class SimpleEventEmitter{listeners=new Map;on(event,callback){if(!this.listeners.has(event)){this.listeners.set(event,new Set);}this.listeners.get(event).add(callback);}off(event,callback){this.listeners.get(event)?.delete(callback);}emit(event,...args){const callbacks=this.listeners.get(event);if(!callbacks||callbacks.size===0){return false}callbacks.forEach(cb=>cb(...args));return true}removeAllListeners(event){this.listeners.delete(event);}eventNames(){return Array.from(this.listeners.keys())}};class EventBus extends ObjectBase{static instance=null;objects=new Map;eventEmitter=new SimpleEventEmitter;lastEmittedEvents=new Map;static getName(){return "ZenFlux/Core/Modules/EventBus"}static getInstance(){if(!EventBus.instance){EventBus.instance=new EventBus;}return EventBus.instance}static get $(){return EventBus.getInstance()}getObjectNames(){return Array.from(this.objects.keys())}getEventNames(){this.eventEmitter.eventNames();}getEventName(objectName,methodName){return `${objectName}::${methodName}`}on(objectName,methodName,callback){if(!this.objects.has(objectName)){throw new Error(`Object ${objectName} is not registered`)}this.eventEmitter.on(this.getEventName(objectName,methodName),callback);}onCalledBeforeDoInvoke(objectName,methodName,callback){this.on(objectName,methodName,callback);if(this.objects.has(objectName)){const objectEntry=this.objects.get(objectName);if(objectEntry){const method=objectEntry.methods.find(method=>method.name===methodName);if(method&&this.lastEmittedEvents.has(this.getEventName(objectName,methodName))){callback(...this.lastEmittedEvents.get(this.getEventName(objectName,methodName)));}}}}off(objectName,methodName,callback){this.eventEmitter.off(this.getEventName(objectName,methodName),callback);}register(object,methods){if(this.objects.has(object.getName())){throw new Error(`Error in: '${this.getName()}', object: '${object.getName()}' is already registered`)}this.objects.set(object.getName(),{object,methods});this.hook(object,methods);}registerMultiInstances(object,methods){const objectName=object.getName();if(this.objects.has(objectName)){const existingEntry=this.objects.get(objectName);if(Array.isArray(existingEntry.object)){existingEntry.object.push(object);}else {existingEntry.object=[existingEntry.object,object];}}else {this.objects.set(objectName,{object,methods});}this.hook(object,methods);}unregister(objectName){const entry=this.objects.get(objectName);if(!entry){return false}if(Array.isArray(entry.object)){entry.object.forEach(obj=>{this.unhookObject(obj,entry.methods);});}else {this.unhookObject(entry.object,entry.methods);}this.objects.delete(objectName);}unhookObject(object,methods){methods.forEach(method=>{this.ensureFunction(object,method);this.eventEmitter.removeAllListeners(this.getEventName(object.getName(),method.name));object[method.name]=method;});}unhook(entry){if(Array.isArray(entry.object)){entry.object.forEach(obj=>{this.unhookObject(obj,entry.methods);});}else {this.unhookObject(entry.object,entry.methods);}}emit(object,method,...args){const eventName=this.getEventName(object.getName(),method.name);this.lastEmittedEvents.set(eventName,args);return this.eventEmitter.emit(eventName,...args)}hook(object,methods){methods.forEach(method=>{this.ensureFunction(object,method);const originalMethod=method;const eventBusHook=async(...args)=>{const result=await originalMethod.apply(object,args);this.emit(object,method,...args);return result};object[method.name]=new Proxy(eventBusHook,{get(target,prop){if(prop==="name"){return method.name}return target[prop]}});});}ensureFunction(object,method){if("function"!==typeof method){throw new Error(`Method ${method} is not a function on ${object.getName()}`)}}}
|
|
70
|
+
|
|
71
|
+
const DEFAULT_LOG_PREFIX=pc.white("⚪ - [LOG]"),DEFAULT_INFO_PREFIX=pc.blue("🔵 - [INFO]"),DEFAULT_DEBUG_PREFIX=pc.gray("🟤 - [DEBUG]"),DEFAULT_WARN_PREFIX=pc.yellow("🟡 - [WARN]"),DEFAULT_ERROR_PREFIX=pc.red("🔴 - [ERROR]"),DEFAULT_ADMIN_PREFIX=pc.bold("🟣 - [ADMIN]");const LEVEL_LABELS={log:"LOG",info:"INFO",debug:"DEBUG",warn:"WARN",error:"ERROR",admin:"ADMIN"};const registeredNames={};function resetLoggerRegistry(){for(const key in registeredNames){delete registeredNames[key];}}class Logger extends LoggerBrowserInfra{static lastLogTime=Date.now();static timestampFormat=getLoggerTimeFormat();ownerName;messagePrefixes=[];config={};static setTimestampFormat(format){Logger.timestampFormat=(format||"").trim();}static getTimestampFormat(){return Logger.timestampFormat}static getName(){return "ZenFlux/Core/Modules/Logger"}static getLogLevelString(){return getLoggerLogLevelString()}static getLogLevel(){return getLoggerLogLevel()}static attachOutputListener(listener){return LoggerBrowserInfra.attachOutputSubscriber(listener)}static isDebugEnabled(){return isLoggerDebugEnabled()}constructor(owner,options){const{repeatedly=false,skipEventBusHook}=options||{};super(owner,{repeatedly});this.config={skipEventBusHook};this.ownerName=Logger.resolveOwnerName(owner);if(registeredNames[this.ownerName]){throw new Error(`Logger for '${this.ownerName}' already exists`)}registeredNames[this.ownerName]=true;if(isLoggerDisabled()){this.disableLoggers();return}if(isLoggerPreviousSourceDisabled()){this.getPreviousSource=()=>"";}switch(getLoggerLogLevel()){case 0:this.error=()=>{};case 1:this.warn=()=>{};case 2:this.admin=()=>{};case 3:this.info=()=>{};case 4:this.log=()=>{};case 5:this.debug=()=>{};}if(!this.config.skipEventBusHook){EventBus.$.registerMultiInstances(this,[this.outputEvent]);}}addMessagePrefix(prefix){this.messagePrefixes.push(prefix);}log(caller,message,...params){this.writeLog("log",DEFAULT_LOG_PREFIX,caller,message,...params);}info(caller,message,...params){this.writeLog("info",DEFAULT_INFO_PREFIX,caller,message,...params);}debug(caller,message,...params){this.writeLog("debug",DEFAULT_DEBUG_PREFIX,caller,message,...params);}warn(caller,message,...params){this.writeLog("warn",DEFAULT_WARN_PREFIX,caller,message,...params);}error(caller,message,...params){this.writeLog("error",DEFAULT_ERROR_PREFIX,caller,message,...params);}admin(caller,message,...params){this.writeLog("admin",DEFAULT_ADMIN_PREFIX,caller,message,...params);}startsEmpty(caller){this.printFunctionNotify("▶",caller,"");}startsWith(caller,params){this.printObjectEfficient("▶",caller,params);}dump(caller,params={},notice=""){for(const key in params){if(typeof params[key]==="object"){params[key]=JSON.stringify(LoggerBrowserInfra.useObjectMapper(params[key]),reduceCircularReferences());}this.printInLineElement("dp",caller,key,params[key],notice);}}drop(caller,according,data){for(const key in according){this.printInLineElement("dr",caller,key,according[key],"corresponding");}this.output(data);}throw(caller,output,name="null",params={}){this.printFunctionNotify("tw",caller,output);if(params){this.printInNextLineObject("tw",caller,name,params);}throw new Error().stack}beep(){console.log("\x07");}clone(){return Object.assign(Object.create(Object.getPrototypeOf(this)),this)}outputEvent(_prefix,_timeDiff,_source,_messagePrefix,_message,_params){}static resolveOwnerName(owner){if(typeof owner==="string"){return owner}if(owner instanceof ObjectBase){return owner.getName()}if(owner&&typeof owner.getName==="function"){return owner.getName()}return "UnknownOwner"}disableLoggers(){this.error=()=>{};this.warn=()=>{};this.admin=()=>{};this.info=()=>{};this.log=()=>{};this.debug=()=>{};}getStackTrace(){const stackTrace=(new Error().stack||"").split("\n");const stackLines=stackTrace.slice(1);const stackRegex=/ at (.+?) \((.+?)\)/;const result=[];for(const line of stackLines){const match=line.match(stackRegex);if(match){const[,context,file]=match;const parsedLine={context,file};if(line.startsWith("new")){parsedLine.isNew=true;parsedLine.object=context.split(" ")[1];}else if(context!=="Object.<anonymous>"){parsedLine.object=context;}result.push(parsedLine);}}return result}getPreviousSource(){const stack=this.getStackTrace().filter(line=>line.file.includes("/src/")).filter(line=>!line.file.includes("logger.ts")).filter(line=>!line.file.includes("debugger.ts")).filter(line=>!line.file.includes("/node_modules/"));let previousSource="";const previousCaller=stack[1]?.object?.split(".");if(previousCaller?.length>1){const previousCallerName=previousCaller[0],previousCallerMethod=previousCaller[1];previousSource=`${previousCallerName}::${previousCallerMethod}]`+"[";}return previousSource}writeLog(level,prefix,caller,message,...params){const callerName=this.getCallerName(caller);const source=this.getPreviousSource()+pc.white(`${this.ownerName}::${callerName}`);let messagePrefix="";if(this.messagePrefixes.length){messagePrefix=`[${this.messagePrefixes.join("][")}]`;}const timestampValue=Date.now();const timeDiff=(timestampValue-Logger.lastLogTime).toString().padStart(4,"0");const timeFormat=Logger.getTimestampFormat();const timestamp=timeFormat?this.formatTime(new Date(timestampValue),timeFormat):"";this.outputEvent(prefix,timeDiff,source,messagePrefix,message,params);const timestampPart=timestamp?`${timestamp} `:"";const output=`${timestampPart}${prefix}[+${timeDiff}ms][${source}]${messagePrefix}: ${message}`;const formatted=this.createBrowserFormat(level,callerName,messagePrefix,message);const metadata={id:`${timestampValue}-${Math.random().toString(16).slice(2)}`,level,namespace:this.ownerName,callerName,message,messagePrefix,payload:params.length===0?undefined:params.length===1?params[0]:params,timestamp:timestampValue,formatted};this.runWithOutputMetadata(metadata,()=>{this.output(output,...params);});Logger.lastLogTime=timestampValue;}createBrowserFormat(level,callerName,messagePrefix,message){const prefixLabel=LEVEL_LABELS[level]||level.toUpperCase();const prefixPart=messagePrefix?`${messagePrefix} `:"";return {format:`%c(${prefixLabel})-> %c%c${this.ownerName}%c::%c${callerName}%c() ${prefixPart}${message}%c`,styles:[...this.defaultStyle]}}formatTime(date,format){const pad=(num,size=2)=>num.toString().padStart(size,"0");const tokens={"YYYY":date.getFullYear().toString(),"Y":date.getFullYear().toString(),"M":pad(date.getMonth()+1),"D":pad(date.getDate()),"HH":pad(date.getHours()),"hh":pad(date.getHours()),"mm":pad(date.getMinutes()),"ss":pad(date.getSeconds()),"SSS":pad(date.getMilliseconds(),3),"S":pad(date.getMilliseconds(),3)};return format.replace(/YYYY|HH|hh|mm|ss|SSS|Y|M|D|S|h|m|s/g,token=>tokens[token]??token)}}
|
|
72
|
+
|
|
73
|
+
class ZenFluxLogger extends Logger{}const loggerCache=new Map;const resolveOwnerName=owner=>{if(typeof owner==="string"){return owner}if(owner&&typeof owner.getName==="function"){return owner.getName()}return "UnknownOwner"};const createLogger=(owner,options)=>{const ownerName=resolveOwnerName(owner);const cached=loggerCache.get(ownerName);if(cached){return cached}const logger=new ZenFluxLogger(owner,options);loggerCache.set(ownerName,logger);return logger};
|
|
74
|
+
|
|
75
|
+
class Commands extends ObjectBase{static trace=[];current={};currentArgs={};trace=[];commands={};onBeforeHooks={};onBeforeUIHooks={};onAfterHooks={};onAfterOnceHooks={};onAfterUIHooks={};onAfterAffectHooks={};logger;static getName(){return "ZenFlux/Core/Managers/Commands"}static async runCallbacks(callbacks,args={},options={}){const callbacksLength=callbacks?.length||0;for(let i=0;i<callbacksLength;++i){const callback=options.pop===true?callbacks.pop():callbacks[i];if(!callback){throw new Error("Callback is not defined.")}await callback(args,options);}}static hookCommand(stack,hookCommand,context){if(!stack[hookCommand]){stack[hookCommand]=[];}stack[hookCommand].push(context);}constructor(){super();const type=this.constructor;this.logger=createLogger(type);this.logger.startsEmpty(this.constructor);}async run(command,args={},options={}){if(typeof command==="string"){command=this.getCommandInstance(command,args,options);}this.attachCurrent(command,args);const result=await this.runInstance(command,args,options);this.detachCurrent(command);return result}register(commands,controller){const result={};Object.values(commands).forEach(command=>{const commandName=command.getName();if(this.commands[commandName]){throw new CommandAlreadyRegistered(command)}command.setController(controller);this.commands[commandName]=command;result[commandName]=command;});return result}getAll(){return this.commands}getByName(name){return this.commands[name]}getLogger(){return this.logger}getCommandInstance(name,args={},options={}){const CommandClass=this.commands[name];if(!CommandClass){throw new CommandNotFound(name)}return new CommandClass(args,options)}onBefore(hookCommand,callback){Commands.hookCommand(this.onBeforeHooks,hookCommand,callback);}onBeforeUI(hookCommand,callback){Commands.hookCommand(this.onBeforeUIHooks,hookCommand,callback);}onAfter(hookCommand,callback){Commands.hookCommand(this.onAfterHooks,hookCommand,callback);}onAfterUI(command,callback){Commands.hookCommand(this.onAfterUIHooks,command,callback);}onAfterOnce(command,callback){Commands.hookCommand(this.onAfterOnceHooks,command,callback);}onAfterAffect(hookCommand,affectCommand){Commands.hookCommand(this.onAfterAffectHooks,hookCommand,affectCommand);}onBeforeRun(command,args={},options={}){if(this.onBeforeHooks[command.getName()]){const callbacks=this.onBeforeHooks[command.getName()];callbacks.forEach(callback=>callback(args,options));}if(this.onBeforeUIHooks[command.getName()]){const callbacks=this.onBeforeUIHooks[command.getName()];callbacks.forEach(callback=>callback(args,options));}}async runInstance(command,args={},options={}){let result=null;this.logger.startsWith(this.runInstance,{command:command.getName(),options,args});this.onBeforeRun(command,args,options);result=await command.run();await this.onAfterRun(command,args,options,result);return result}async onAfterRun(command,args,options,result){options=Object.assign({},options);if(this.onAfterAffectHooks[command.getName()]){this.onAfterAffectHooks[command.getName()].forEach(command=>{args.result=result;result=this.run(command.toString(),args,options);});result=await result;}if(this.onAfterHooks){args.result=result;await Commands.runCallbacks(Object.assign([],this.onAfterHooks[command.getName()]),args,options);}if(this.onAfterOnceHooks){await Commands.runCallbacks(this.onAfterOnceHooks[command.getName()],args,{...options,pop:true});}if(this.onAfterUIHooks){Commands.runCallbacks(Object.assign([],this.onAfterUIHooks[command.getName()]),args,options);}return result}attachCurrent(command,args={}){this.current[command.getName()]=command;this.currentArgs[command.getName()]=args;this.trace.push(command.getName());Commands.trace.push(command.getName());}detachCurrent(command){delete this.current[command.getName()];delete this.currentArgs[command.getName()];Commands.trace.pop();this.trace.pop();}}
|
|
48
76
|
|
|
49
77
|
class Controllers extends ObjectBase{controllers={};constructor(){super();}static getName(){return "ZenFlux/Core/Managers/Controllers"}get(name){return this.controllers[name]}getAll(){return this.controllers}register(controller){if(this.controllers[controller.getName()]){throw new ControllerAlreadyRegistered(controller)}this.controllers[controller.getName()]=controller;return controller}}
|
|
50
78
|
|
|
@@ -56,57 +84,27 @@ E_HTTP_METHOD_TYPE: E_HTTP_METHOD_TYPE,
|
|
|
56
84
|
E_RESPONSE_HANDLER_TYPE: E_RESPONSE_HANDLER_TYPE
|
|
57
85
|
});
|
|
58
86
|
|
|
59
|
-
class Http extends ObjectBase{logger;apiBaseUrl;requestInit;errorHandler=undefined;responseFilter=undefined;responseHandler=undefined;static getName(){return "ZenFlux/Core/Clients/Http"}constructor(apiBaseUrl="http://localhost",requestInit={"credentials":"include"}){super();this.logger=new
|
|
87
|
+
class Http extends ObjectBase{logger;apiBaseUrl;requestInit;errorHandler=undefined;responseFilter=undefined;responseHandler=undefined;static getName(){return "ZenFlux/Core/Clients/Http"}constructor(apiBaseUrl="http://localhost",requestInit={"credentials":"include"}){super();this.logger=new Logger(Http);this.logger.startsWith(this.constructor,{apiBaseUrl});this.apiBaseUrl=apiBaseUrl+"/";this.requestInit=requestInit;}async fetch(path,method,body={}){this.logger.startsWith(this.constructor,{path,method,body});const params=Object.assign({},this.requestInit);const headers={};if(method===E_HTTP_METHOD_TYPE.GET){Object.assign(params,{headers});}else {Object.assign(headers,{"Content-Type":"application/json"});Object.assign(params,{method,headers:headers,body:JSON.stringify(body)});}const fetchPromise=globalThis.fetch(this.apiBaseUrl+path,params);let response=await fetchPromise;if(!response){return false}let data=undefined;try{if(!response.ok){throw new Error(response.statusText)}let responseText=await response.text();responseText=this.applyResponseFilter(responseText);if(response.headers?.get("Content-Type")?.includes("application/json")){data=JSON.parse(responseText);}else {data=responseText;}if(this.applyResponseHandler(data)){return false}}catch(e){if(this.applyErrorHandler(e)){return false}await Promise.reject(e);}this.logger.drop(this.fetch,{path},data);return data}setErrorHandler(callback){if(this.errorHandler){throw new Error("Error handler already set.")}this.errorHandler=callback;}setResponseFilter(callback){if(this.responseFilter){throw new Error("Response filter already set.")}this.responseFilter=callback;}setResponseHandler(callback){if(this.responseHandler){throw new Error("Response handler already set.")}this.responseHandler=callback;}applyErrorHandler(error){return !!this.errorHandler&&this.errorHandler(error)}applyResponseFilter(text){return this.responseFilter&&this.responseFilter(text)||text}applyResponseHandler(text){return !!this.responseHandler&&this.responseHandler(text)}}
|
|
60
88
|
|
|
61
89
|
class Restful extends Commands{static client;currentHttpMethod;static getName(){return "ZenFlux/Core/Managers/Restful"}constructor(Config){super();Restful.client=new Http(Config.baseURL,Config.requestInit);}getClient(){return Restful.client}get(command,args={},options={}){this.currentHttpMethod=E_HTTP_METHOD_TYPE.GET;return super.run(command,args,options)}update(command,args={},options={}){this.currentHttpMethod=E_HTTP_METHOD_TYPE.PATCH;return super.run(command,args,options)}delete(command,args={},options={}){this.currentHttpMethod=E_HTTP_METHOD_TYPE.DELETE;return super.run(command,args,options)}create(command,args={},options={}){this.currentHttpMethod=E_HTTP_METHOD_TYPE.POST;return super.run(command,args,options)}async runInstance(command,args={},options={}){if(!this.currentHttpMethod){throw new Error('Cannot run directly use one of the http methods: "get", "update", "delete, "create')}const newArgs={type:this.currentHttpMethod,args:{query:{},data:{}}};if(E_HTTP_METHOD_TYPE.GET===this.currentHttpMethod){newArgs.args.query=args;}else {newArgs.args.data=args;}args.result=await super.runInstance(command,newArgs,options);this.currentHttpMethod=E_HTTP_METHOD_TYPE.__EMPTY__;return args.result}setHandler(type,callback){switch(type){case E_RESPONSE_HANDLER_TYPE.ERROR_HANDLER:Restful.client.setErrorHandler(callback);break;case E_RESPONSE_HANDLER_TYPE.RESPONSE_FILTER:Restful.client.setResponseFilter(callback);break;case E_RESPONSE_HANDLER_TYPE.RESPONSE_HANDLER:Restful.client.setResponseHandler(callback);break;default:throw new Error(`Unknown handler type: '${type}'`)}}}
|
|
62
90
|
|
|
63
91
|
class Internal extends Commands{static getName(){return "ZenFlux/Core/Managers/Internal"}}
|
|
64
92
|
|
|
65
|
-
const afterInitializeCallbacks=[];function initialize
|
|
93
|
+
const afterInitializeCallbacks=[];function initialize(config){commands=new Commands;controllers=new Controllers;restful=new Restful(config);internal=new Internal;}function destroy(){commands={};controllers={};restful={};internal={};}let commands={};let controllers={};let restful={};let internal={};
|
|
66
94
|
|
|
67
95
|
var _export$1 = /*#__PURE__*/Object.freeze({
|
|
68
96
|
__proto__: null,
|
|
69
97
|
afterInitializeCallbacks: afterInitializeCallbacks,
|
|
70
98
|
get commands () { return commands; },
|
|
71
99
|
get controllers () { return controllers; },
|
|
72
|
-
destroy: destroy
|
|
73
|
-
initialize: initialize
|
|
100
|
+
destroy: destroy,
|
|
101
|
+
initialize: initialize,
|
|
74
102
|
get internal () { return internal; },
|
|
75
103
|
get restful () { return restful; }
|
|
76
104
|
});
|
|
77
105
|
|
|
78
106
|
class ControllerBase extends ObjectBase{commands;restful;internal;static getName(){return "ZenFlux/Core/ControllerBase"}constructor(){super();this.initialize();}initialize(){this.register();this.setupHooks&&this.setupHooks();}register(){this.commands=commands.register(this.getCommands(),this);this.restful=restful.register(this.getRestful(),this);this.internal=internal.register(this.getInternal(),this);}getCommands(){return {}}getRestful(){return {}}getInternal(){return {}}setupHooks(){}}
|
|
79
107
|
|
|
80
|
-
const DEFAULT_LOG_LEVEL="5";function getEnvVar(key){if(typeof process!=="undefined"&&process?.env){return process.env[key]??process.env[`VITE_${key}`]}if(typeof ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('zenflux-core.cjs', document.baseURI).href)) })!=="undefined"&&undefined){const env=undefined;return env[key]??env[`VITE_${key}`]}return undefined}function getLoggerDefaultLevel(){return DEFAULT_LOG_LEVEL}function getLoggerLogLevel(){const raw=getEnvVar("LOGGER_LOG_LEVEL");return parseInt(raw??DEFAULT_LOG_LEVEL,10)}function getLoggerTimeFormat(){return (getEnvVar("LOGGER_TIME_FORMAT")||"").trim()}function getLoggerLogLevelString(){switch(getLoggerLogLevel()){case 0:return "NONE";case 1:return "ERROR";case 2:return "WARN";case 3:return "ADMIN";case 4:return "INFO";case 5:return "LOG";case 6:return "DEBUG";default:return "UNKNOWN"}}function isLoggerDebugEnabled(){return getLoggerLogLevel()>=6}function isLoggerDisabled(){return getEnvVar("LOGGER_DISABLED")==="true"}function isLoggerPreviousSourceDisabled(){return getEnvVar("LOGGER_LOG_PREVIOUS_CALLER_SOURCE_DISABLED")==="true"}
|
|
81
|
-
|
|
82
|
-
var commonjsGlobal=typeof globalThis!=="undefined"?globalThis:typeof window!=="undefined"?window:typeof global!=="undefined"?global:typeof self!=="undefined"?self:{};function getDefaultExportFromCjs(x){return x&&x.__esModule&&Object.prototype.hasOwnProperty.call(x,"default")?x["default"]:x}function getDefaultExportFromNamespaceIfPresent(n){return n&&Object.prototype.hasOwnProperty.call(n,"default")?n["default"]:n}function getDefaultExportFromNamespaceIfNotNamed(n){return n&&Object.prototype.hasOwnProperty.call(n,"default")&&Object.keys(n).length===1?n["default"]:n}function getAugmentedNamespace(n){if(Object.prototype.hasOwnProperty.call(n,"__esModule"))return n;var f=n.default;if(typeof f=="function"){var a=function a(){var isInstance=false;try{isInstance=this instanceof a;}catch{}if(isInstance){return Reflect.construct(f,arguments,this.constructor)}return f.apply(this,arguments)};a.prototype=f.prototype;}else a={};Object.defineProperty(a,"__esModule",{value:true});Object.keys(n).forEach(function(k){var d=Object.getOwnPropertyDescriptor(n,k);Object.defineProperty(a,k,d.get?d:{enumerable:true,get:function(){return n[k]}});});return a}
|
|
83
|
-
|
|
84
|
-
var picocolors$1={exports:{}};
|
|
85
|
-
|
|
86
|
-
var picocolors=picocolors$1.exports;var hasRequiredPicocolors;function requirePicocolors(){if(hasRequiredPicocolors)return picocolors$1.exports;hasRequiredPicocolors=1;let p=process||{},argv=p.argv||[],env=p.env||{};let isColorSupported=!(!!env.NO_COLOR||argv.includes("--no-color"))&&(!!env.FORCE_COLOR||argv.includes("--color")||p.platform==="win32"||(p.stdout||{}).isTTY&&env.TERM!=="dumb"||!!env.CI);let formatter=(open,close,replace=open)=>input=>{let string=""+input,index=string.indexOf(close,open.length);return ~index?open+replaceClose(string,close,replace,index)+close:open+string+close};let replaceClose=(string,close,replace,index)=>{let result="",cursor=0;do{result+=string.substring(cursor,index)+replace;cursor=index+close.length;index=string.indexOf(close,cursor);}while(~index)return result+string.substring(cursor)};let createColors=(enabled=isColorSupported)=>{let f=enabled?formatter:()=>String;return {isColorSupported:enabled,reset:f("\x1b[0m","\x1b[0m"),bold:f("\x1b[1m","\x1b[22m","\x1b[22m\x1b[1m"),dim:f("\x1b[2m","\x1b[22m","\x1b[22m\x1b[2m"),italic:f("\x1b[3m","\x1b[23m"),underline:f("\x1b[4m","\x1b[24m"),inverse:f("\x1b[7m","\x1b[27m"),hidden:f("\x1b[8m","\x1b[28m"),strikethrough:f("\x1b[9m","\x1b[29m"),black:f("\x1b[30m","\x1b[39m"),red:f("\x1b[31m","\x1b[39m"),green:f("\x1b[32m","\x1b[39m"),yellow:f("\x1b[33m","\x1b[39m"),blue:f("\x1b[34m","\x1b[39m"),magenta:f("\x1b[35m","\x1b[39m"),cyan:f("\x1b[36m","\x1b[39m"),white:f("\x1b[37m","\x1b[39m"),gray:f("\x1b[90m","\x1b[39m"),bgBlack:f("\x1b[40m","\x1b[49m"),bgRed:f("\x1b[41m","\x1b[49m"),bgGreen:f("\x1b[42m","\x1b[49m"),bgYellow:f("\x1b[43m","\x1b[49m"),bgBlue:f("\x1b[44m","\x1b[49m"),bgMagenta:f("\x1b[45m","\x1b[49m"),bgCyan:f("\x1b[46m","\x1b[49m"),bgWhite:f("\x1b[47m","\x1b[49m"),blackBright:f("\x1b[90m","\x1b[39m"),redBright:f("\x1b[91m","\x1b[39m"),greenBright:f("\x1b[92m","\x1b[39m"),yellowBright:f("\x1b[93m","\x1b[39m"),blueBright:f("\x1b[94m","\x1b[39m"),magentaBright:f("\x1b[95m","\x1b[39m"),cyanBright:f("\x1b[96m","\x1b[39m"),whiteBright:f("\x1b[97m","\x1b[39m"),bgBlackBright:f("\x1b[100m","\x1b[49m"),bgRedBright:f("\x1b[101m","\x1b[49m"),bgGreenBright:f("\x1b[102m","\x1b[49m"),bgYellowBright:f("\x1b[103m","\x1b[49m"),bgBlueBright:f("\x1b[104m","\x1b[49m"),bgMagentaBright:f("\x1b[105m","\x1b[49m"),bgCyanBright:f("\x1b[106m","\x1b[49m"),bgWhiteBright:f("\x1b[107m","\x1b[49m")}};picocolors$1.exports=createColors();picocolors$1.exports.createColors=createColors;return picocolors$1.exports}
|
|
87
|
-
|
|
88
|
-
var picocolorsExports=requirePicocolors();var pc = getDefaultExportFromCjs(picocolorsExports);
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Reduce circular references.
|
|
92
|
-
*
|
|
93
|
-
* @copyright https://stackoverflow.com/a/53731154
|
|
94
|
-
*/const reduceCircularReferences=()=>{const seen=new WeakSet;return (key,value)=>{if(typeof value==="object"&&value!==null){if(seen.has(value)){return}seen.add(value);}return value}};
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Function hexColorDelta() : Return color difference in ratio decimal point.
|
|
98
|
-
*
|
|
99
|
-
* @copyright http://jsfiddle.net/96sME/
|
|
100
|
-
*/const getHexColorDelta=function(hex1,hex2){hex1=hex1.replace("#","");hex2=hex2.replace("#","");const r1=parseInt(hex1.substring(0,2),16);const g1=parseInt(hex1.substring(2,4),16);const b1=parseInt(hex1.substring(4,6),16);const r2=parseInt(hex2.substring(0,2),16);const g2=parseInt(hex2.substring(2,4),16);const b2=parseInt(hex2.substring(4,6),16);let r=255-Math.abs(r1-r2);let g=255-Math.abs(g1-g2);let b=255-Math.abs(b1-b2);r/=255;g/=255;b/=255;return (r+g+b)/3};
|
|
101
|
-
|
|
102
|
-
const MAX_MAPPING_RECURSIVE_DEPTH=4,UNKNOWN_CALLER_NAME="anonymous function";Error.stackTraceLimit=50;class LoggerBrowserInfra extends ObjectBase{static mappers=[];static mapperDepth=0;static colorsOwners={};static colorsUsed=[];static outputSubscribers=new Set;defaultStyle;owner;args;color;outputHandler=console.log;pendingOutputMetadata;static getName(){return "ZenFlux/Logging/Modules/LoggerBrowserInfra"}static reset(){LoggerBrowserInfra.mappers=[];LoggerBrowserInfra.mapperDepth=0;LoggerBrowserInfra.colorsUsed=[];LoggerBrowserInfra.colorsOwners={};LoggerBrowserInfra.outputSubscribers.clear();}static attachOutputSubscriber(subscriber){LoggerBrowserInfra.outputSubscribers.add(subscriber);return ()=>{LoggerBrowserInfra.outputSubscribers.delete(subscriber);}}static createObjectMapper(callback){LoggerBrowserInfra.mappers.push(callback);}static useObjectMapper(obj,shouldHandleChildren=true){if(!obj||Array.isArray(obj)||"object"!==typeof obj){return obj}LoggerBrowserInfra.mapperDepth++;let result={...obj};LoggerBrowserInfra.mappers.forEach(mapper=>{result=mapper(obj)||result;});if(LoggerBrowserInfra.mapperDepth>=MAX_MAPPING_RECURSIVE_DEPTH){LoggerBrowserInfra.mapperDepth--;return result}if(shouldHandleChildren&&result){Object.entries(result).forEach(([key,value])=>{result[key]=this.useObjectMapper(value,true);});}LoggerBrowserInfra.mapperDepth--;return result}constructor(owner,args={}){super();this.args={repeatedly:false,...args};this.owner=owner;this.initialize();}getOwnerName(){if(typeof this.owner==="string"){return this.owner}if(this.owner instanceof ObjectBase){return this.owner.getName()}if(this.owner&&typeof this.owner.getName==="function"){return this.owner.getName()}return "UnknownOwner"}initialize(){const ownerName=this.getOwnerName();if(this.args.repeatedly&&LoggerBrowserInfra.colorsOwners[ownerName]){this.color=LoggerBrowserInfra.colorsOwners[ownerName];}else {this.color=this.getRandomColor();}LoggerBrowserInfra.colorsOwners[ownerName]=this.color;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"];}output(...args){this.outputHandler.apply(this,args);if(LoggerBrowserInfra.outputSubscribers.size===0){return}const event={logger:this,namespace:this.getOwnerName(),args,metadata:this.pendingOutputMetadata};LoggerBrowserInfra.outputSubscribers.forEach(subscriber=>{try{subscriber(event);}catch(error){console.error("[ZenFlux][Logger] output subscriber failed",error);}});}setOutputHandler(outputHandler){this.outputHandler=outputHandler;}runWithOutputMetadata(metadata,callback){const previous=this.pendingOutputMetadata;this.pendingOutputMetadata=metadata;try{return callback()}finally{this.pendingOutputMetadata=previous;}}printFunctionNotify(prefix,caller,output){const callerName=this.getCallerName(caller);this.output.apply(this,[`%c(${prefix})-> %c%c${this.getOwnerName()}%c::%c${callerName}%c() ${output}%c`].concat(this.defaultStyle));}printObjectEfficient(prefix,caller,params){params=Object.assign({},params);if(typeof params==="string"){this.printInLineString(prefix,caller,params);return}if(Object.keys(params).length===1){const key=Object.keys(params)[0];let value=Object.values(params)[0];if("object"===typeof value){this.printInNextLineObject(prefix,caller,key,value||{});}else if("function"===typeof value){this.printInLineFunction(prefix,caller,key,value);}else {this.printInLineElement(prefix,caller,key,value);}return}this.printMultiLineObject(prefix,caller,params);}printInLineElement(prefix,caller,key,value,notice=""){const callerName=this.getCallerName(caller),ownerName=this.getOwnerName(),format=notice.length?`%c(${prefix})-> %c%c${ownerName}%c::%c${callerName}%c() ->> [${notice}] ->> ${key}: '${value}'%c`:`%c(${prefix})-> %c%c${ownerName}%c::%c${callerName}%c() ->> ${key}: '${value}'%c`;this.output.apply(this,[format].concat(this.defaultStyle));}printInLineFunction(prefix,caller,key,fn){fn=this.getFunctionView(fn);this.printInLineElement(prefix,caller,key,fn);}printInLineString(prefix,caller,string){this.printInLineElement(prefix,caller,"(string)",string);}printInNextLineObject(prefix,caller,key,obj){const mapped=LoggerBrowserInfra.useObjectMapper(obj),callerName=this.getCallerName(caller);this.output.apply(this,[`%c(${prefix})-> %c%c${this.getOwnerName()}%c::%c${callerName}%c() ->> ${key} %c↓`].concat(this.defaultStyle));this.output(mapped);}printMultiLineObject(prefix,caller,obj){const callerName=this.getCallerName(caller);this.output.apply(this,[`%c(${prefix})-> %c%c${this.getOwnerName()}%c::%c${callerName}%c(${Object.keys(obj).join(", ")}) %c↓`].concat(this.defaultStyle));for(let key in obj){let value=obj[key];if(typeof value==="object"){const mapped=LoggerBrowserInfra.useObjectMapper(value);value=JSON.stringify(mapped,reduceCircularReferences());}else if(typeof obj[key]=="function"){value=this.getFunctionView(value);}this.output.apply(this,["%c"+key+": `"+value+"`","color: #a3a3a3"]);}}getRandomColor(){const hex="0123456789ABCDEF";let color="#";for(let i=0;i<6;i++){color+=hex[Math.floor(Math.random()*16)];}return color}getCallerName(caller){if("function"===typeof caller){return caller.prototype instanceof ObjectBase?"constructor":caller.name}throw new Error("Invalid caller")}getFunctionView(fn){let fReturn=UNKNOWN_CALLER_NAME;if(typeof fn!=="string"&&fn.name.length!==0){fReturn=fn.name.split(" ")[1]+"()";}return fReturn}}
|
|
103
|
-
|
|
104
|
-
let SimpleEventEmitter=class SimpleEventEmitter{listeners=new Map;on(event,callback){if(!this.listeners.has(event)){this.listeners.set(event,new Set);}this.listeners.get(event).add(callback);}off(event,callback){this.listeners.get(event)?.delete(callback);}emit(event,...args){const callbacks=this.listeners.get(event);if(!callbacks||callbacks.size===0){return false}callbacks.forEach(cb=>cb(...args));return true}removeAllListeners(event){this.listeners.delete(event);}eventNames(){return Array.from(this.listeners.keys())}};class EventBus extends ObjectBase{static instance=null;objects=new Map;eventEmitter=new SimpleEventEmitter;lastEmittedEvents=new Map;static getName(){return "ZenFlux/Core/Modules/EventBus"}static getInstance(){if(!EventBus.instance){EventBus.instance=new EventBus;}return EventBus.instance}static get $(){return EventBus.getInstance()}getObjectNames(){return Array.from(this.objects.keys())}getEventNames(){this.eventEmitter.eventNames();}getEventName(objectName,methodName){return `${objectName}::${methodName}`}on(objectName,methodName,callback){if(!this.objects.has(objectName)){throw new Error(`Object ${objectName} is not registered`)}this.eventEmitter.on(this.getEventName(objectName,methodName),callback);}onCalledBeforeDoInvoke(objectName,methodName,callback){this.on(objectName,methodName,callback);if(this.objects.has(objectName)){const objectEntry=this.objects.get(objectName);if(objectEntry){const method=objectEntry.methods.find(method=>method.name===methodName);if(method&&this.lastEmittedEvents.has(this.getEventName(objectName,methodName))){callback(...this.lastEmittedEvents.get(this.getEventName(objectName,methodName)));}}}}off(objectName,methodName,callback){this.eventEmitter.off(this.getEventName(objectName,methodName),callback);}register(object,methods){if(this.objects.has(object.getName())){throw new Error(`Error in: '${this.getName()}', object: '${object.getName()}' is already registered`)}this.objects.set(object.getName(),{object,methods});this.hook(object,methods);}registerMultiInstances(object,methods){const objectName=object.getName();if(this.objects.has(objectName)){const existingEntry=this.objects.get(objectName);if(Array.isArray(existingEntry.object)){existingEntry.object.push(object);}else {existingEntry.object=[existingEntry.object,object];}}else {this.objects.set(objectName,{object,methods});}this.hook(object,methods);}unregister(objectName){const entry=this.objects.get(objectName);if(!entry){return false}if(Array.isArray(entry.object)){entry.object.forEach(obj=>{this.unhookObject(obj,entry.methods);});}else {this.unhookObject(entry.object,entry.methods);}this.objects.delete(objectName);}unhookObject(object,methods){methods.forEach(method=>{this.ensureFunction(object,method);this.eventEmitter.removeAllListeners(this.getEventName(object.getName(),method.name));object[method.name]=method;});}unhook(entry){if(Array.isArray(entry.object)){entry.object.forEach(obj=>{this.unhookObject(obj,entry.methods);});}else {this.unhookObject(entry.object,entry.methods);}}emit(object,method,...args){const eventName=this.getEventName(object.getName(),method.name);this.lastEmittedEvents.set(eventName,args);return this.eventEmitter.emit(eventName,...args)}hook(object,methods){methods.forEach(method=>{this.ensureFunction(object,method);const originalMethod=method;const eventBusHook=async(...args)=>{const result=await originalMethod.apply(object,args);this.emit(object,method,...args);return result};object[method.name]=new Proxy(eventBusHook,{get(target,prop){if(prop==="name"){return method.name}return target[prop]}});});}ensureFunction(object,method){if("function"!==typeof method){throw new Error(`Method ${method} is not a function on ${object.getName()}`)}}}
|
|
105
|
-
|
|
106
|
-
const DEFAULT_LOG_PREFIX=pc.white("⚪ - [LOG]"),DEFAULT_INFO_PREFIX=pc.blue("🔵 - [INFO]"),DEFAULT_DEBUG_PREFIX=pc.gray("🟤 - [DEBUG]"),DEFAULT_WARN_PREFIX=pc.yellow("🟡 - [WARN]"),DEFAULT_ERROR_PREFIX=pc.red("🔴 - [ERROR]"),DEFAULT_ADMIN_PREFIX=pc.bold("🟣 - [ADMIN]");const LEVEL_LABELS={log:"LOG",info:"INFO",debug:"DEBUG",warn:"WARN",error:"ERROR",admin:"ADMIN"};const registeredNames={};class Logger extends LoggerBrowserInfra{static lastLogTime=Date.now();static timestampFormat=getLoggerTimeFormat();ownerName;messagePrefixes=[];config={};static setTimestampFormat(format){Logger.timestampFormat=(format||"").trim();}static getTimestampFormat(){return Logger.timestampFormat}static getName(){return "ZenFlux/Core/Modules/Logger"}static getLogLevelString(){return getLoggerLogLevelString()}static getLogLevel(){return getLoggerLogLevel()}static attachOutputListener(listener){return LoggerBrowserInfra.attachOutputSubscriber(listener)}static isDebugEnabled(){return isLoggerDebugEnabled()}constructor(owner,options){const{repeatedly=false,skipEventBusHook}=options||{};super(owner,{repeatedly});this.config={skipEventBusHook};this.ownerName=Logger.resolveOwnerName(owner);if(registeredNames[this.ownerName]){throw new Error(`Logger for '${this.ownerName}' already exists`)}registeredNames[this.ownerName]=true;if(isLoggerDisabled()){this.disableLoggers();return}if(isLoggerPreviousSourceDisabled()){this.getPreviousSource=()=>"";}switch(getLoggerLogLevel()){case 0:this.error=()=>{};case 1:this.warn=()=>{};case 2:this.admin=()=>{};case 3:this.info=()=>{};case 4:this.log=()=>{};case 5:this.debug=()=>{};}if(!this.config.skipEventBusHook){EventBus.$.registerMultiInstances(this,[this.outputEvent]);}}addMessagePrefix(prefix){this.messagePrefixes.push(prefix);}log(caller,message,...params){this.writeLog("log",DEFAULT_LOG_PREFIX,caller,message,...params);}info(caller,message,...params){this.writeLog("info",DEFAULT_INFO_PREFIX,caller,message,...params);}debug(caller,message,...params){this.writeLog("debug",DEFAULT_DEBUG_PREFIX,caller,message,...params);}warn(caller,message,...params){this.writeLog("warn",DEFAULT_WARN_PREFIX,caller,message,...params);}error(caller,message,...params){this.writeLog("error",DEFAULT_ERROR_PREFIX,caller,message,...params);}admin(caller,message,...params){this.writeLog("admin",DEFAULT_ADMIN_PREFIX,caller,message,...params);}startsEmpty(caller){this.printFunctionNotify("▶",caller,"");}startsWith(caller,params){this.printObjectEfficient("▶",caller,params);}dump(caller,params={},notice=""){for(const key in params){if(typeof params[key]==="object"){params[key]=JSON.stringify(LoggerBrowserInfra.useObjectMapper(params[key]),reduceCircularReferences());}this.printInLineElement("dp",caller,key,params[key],notice);}}drop(caller,according,data){for(const key in according){this.printInLineElement("dr",caller,key,according[key],"corresponding");}this.output(data);}throw(caller,output,name="null",params={}){this.printFunctionNotify("tw",caller,output);if(params){this.printInNextLineObject("tw",caller,name,params);}throw new Error().stack}beep(){console.log("\x07");}clone(){return Object.assign(Object.create(Object.getPrototypeOf(this)),this)}outputEvent(_prefix,_timeDiff,_source,_messagePrefix,_message,_params){}static resolveOwnerName(owner){if(typeof owner==="string"){return owner}if(owner instanceof ObjectBase){return owner.getName()}if(owner&&typeof owner.getName==="function"){return owner.getName()}return "UnknownOwner"}disableLoggers(){this.error=()=>{};this.warn=()=>{};this.admin=()=>{};this.info=()=>{};this.log=()=>{};this.debug=()=>{};}getStackTrace(){const stackTrace=(new Error().stack||"").split("\n");const stackLines=stackTrace.slice(1);const stackRegex=/ at (.+?) \((.+?)\)/;const result=[];for(const line of stackLines){const match=line.match(stackRegex);if(match){const[,context,file]=match;const parsedLine={context,file};if(line.startsWith("new")){parsedLine.isNew=true;parsedLine.object=context.split(" ")[1];}else if(context!=="Object.<anonymous>"){parsedLine.object=context;}result.push(parsedLine);}}return result}getPreviousSource(){const stack=this.getStackTrace().filter(line=>line.file.includes("/src/")).filter(line=>!line.file.includes("logger.ts")).filter(line=>!line.file.includes("debugger.ts")).filter(line=>!line.file.includes("/node_modules/"));let previousSource="";const previousCaller=stack[1]?.object?.split(".");if(previousCaller?.length>1){const previousCallerName=previousCaller[0],previousCallerMethod=previousCaller[1];previousSource=`${previousCallerName}::${previousCallerMethod}]`+"[";}return previousSource}writeLog(level,prefix,caller,message,...params){const callerName=this.getCallerName(caller);const source=this.getPreviousSource()+pc.white(`${this.ownerName}::${callerName}`);let messagePrefix="";if(this.messagePrefixes.length){messagePrefix=`[${this.messagePrefixes.join("][")}]`;}const timestampValue=Date.now();const timeDiff=(timestampValue-Logger.lastLogTime).toString().padStart(4,"0");const timeFormat=Logger.getTimestampFormat();const timestamp=timeFormat?this.formatTime(new Date(timestampValue),timeFormat):"";this.outputEvent(prefix,timeDiff,source,messagePrefix,message,params);const timestampPart=timestamp?`${timestamp} `:"";const output=`${timestampPart}${prefix}[+${timeDiff}ms][${source}]${messagePrefix}: ${message}`;const formatted=this.createBrowserFormat(level,callerName,messagePrefix,message);const metadata={id:`${timestampValue}-${Math.random().toString(16).slice(2)}`,level,namespace:this.ownerName,callerName,message,messagePrefix,payload:params.length===0?undefined:params.length===1?params[0]:params,timestamp:timestampValue,formatted};this.runWithOutputMetadata(metadata,()=>{this.output(output,...params);});Logger.lastLogTime=timestampValue;}createBrowserFormat(level,callerName,messagePrefix,message){const prefixLabel=LEVEL_LABELS[level]||level.toUpperCase();const prefixPart=messagePrefix?`${messagePrefix} `:"";return {format:`%c(${prefixLabel})-> %c%c${this.ownerName}%c::%c${callerName}%c() ${prefixPart}${message}%c`,styles:[...this.defaultStyle]}}formatTime(date,format){const pad=(num,size=2)=>num.toString().padStart(size,"0");const tokens={"YYYY":date.getFullYear().toString(),"Y":date.getFullYear().toString(),"M":pad(date.getMonth()+1),"D":pad(date.getDate()),"HH":pad(date.getHours()),"hh":pad(date.getHours()),"mm":pad(date.getMinutes()),"ss":pad(date.getSeconds()),"SSS":pad(date.getMilliseconds(),3),"S":pad(date.getMilliseconds(),3)};return format.replace(/YYYY|HH|hh|mm|ss|SSS|Y|M|D|S|h|m|s/g,token=>tokens[token]??token)}}
|
|
107
|
-
|
|
108
|
-
class ZenFluxLogger extends Logger{}const loggerCache=new Map;const resolveOwnerName=owner=>{if(typeof owner==="string"){return owner}if(owner&&typeof owner.getName==="function"){return owner.getName()}return "UnknownOwner"};const createLogger=(owner,options)=>{const ownerName=resolveOwnerName(owner);const cached=loggerCache.get(ownerName);if(cached){return cached}const logger=new ZenFluxLogger(owner,options);loggerCache.set(ownerName,logger);return logger};
|
|
109
|
-
|
|
110
108
|
class InitializeBase extends ObjectBase{logger;constructor(shouldInitialize=true){super();this.logger=new Logger(this);if(this.initialize&&shouldInitialize){this.initialize();}}debounce(func,delay){let timeoutId;return (...args)=>{clearTimeout(timeoutId);timeoutId=setTimeout(()=>{func.apply(this,args);},delay);}}}
|
|
111
109
|
|
|
112
110
|
class SingletonBase extends InitializeBase{static instances=new Map;constructor(){super();}static getInstance(){if(!SingletonBase.instances.has(this)){SingletonBase.instances.set(this,new this);}return SingletonBase.instances.get(this)}}
|
|
@@ -126,7 +124,7 @@ ObjectBase: ObjectBase,
|
|
|
126
124
|
SingletonBase: SingletonBase
|
|
127
125
|
});
|
|
128
126
|
|
|
129
|
-
class CommandBase extends ObjectBase{static controller;args={};options={};logger;static getName(){return "ZenFlux/Core/CommandBases/CommandBase"}static setController(controller){if(this.controller){throw new ControllerAlreadySet(this.controller)}this.controller=controller;}static getController(){return this.controller}constructor(args={},options={}){super();const type=this.constructor;this.logger=
|
|
127
|
+
class CommandBase extends ObjectBase{static controller;args={};options={};logger;static getName(){return "ZenFlux/Core/CommandBases/CommandBase"}static setController(controller){if(this.controller){throw new ControllerAlreadySet(this.controller)}this.controller=controller;}static getController(){return this.controller}constructor(args={},options={}){super();const type=this.constructor;this.logger=createLogger(type);this.logger.startsWith(this.constructor,{args,options});this.initialize(args,options);}initialize(args,options){this.args=args;this.options=options;}apply(args=this.args,options=this.options){throw new ForceMethodImplementation(this,"apply")}async run(){return this.runInternal()}async runInternal(){this.onBeforeApply&&this.onBeforeApply();const result=await this.apply(this.args,this.options);this.onAfterApply&&this.onAfterApply();return result}}
|
|
130
128
|
|
|
131
129
|
class CommandPublic extends CommandBase{static getName(){return "ZenFlux/Core/CommandBases/CommandPublic"}}
|
|
132
130
|
|
|
@@ -164,88 +162,8 @@ ServiceWithDependenciesBase: ServiceWithDependenciesBase,
|
|
|
164
162
|
createLogger: createLogger
|
|
165
163
|
});
|
|
166
164
|
|
|
167
|
-
var _package = {
|
|
168
|
-
"name": "@zenflux/core",
|
|
169
|
-
"version": "0.1.27",
|
|
170
|
-
"types": "dist/zenflux-core.d.ts",
|
|
171
|
-
"type": "module",
|
|
172
|
-
"files": [
|
|
173
|
-
"dist",
|
|
174
|
-
"types"
|
|
175
|
-
],
|
|
176
|
-
"scripts": {
|
|
177
|
-
"@z-core--test": "jest",
|
|
178
|
-
"@z-core--build": "@z-cli @build",
|
|
179
|
-
"@z-core--dev": "@z-cli @watch --dev"
|
|
180
|
-
},
|
|
181
|
-
"exports": {
|
|
182
|
-
".": {
|
|
183
|
-
"import": "./dist/zenflux-core.mjs",
|
|
184
|
-
"default": "./dist/zenflux-core.cjs",
|
|
185
|
-
"require": "./dist/zenflux-core.mjs.js",
|
|
186
|
-
"types": "./dist/zenflux-core.d.ts"
|
|
187
|
-
},
|
|
188
|
-
"./dist/src/*": "./src/*",
|
|
189
|
-
"./src/*.ts": "./src/*.ts",
|
|
190
|
-
"./src/*": "./src/*.ts",
|
|
191
|
-
"./src/bases": "./src/bases/index.ts",
|
|
192
|
-
"./src/bases/*": "./src/bases/*.ts",
|
|
193
|
-
"./src/clients": "./src/clients/index.ts",
|
|
194
|
-
"./src/command-bases": "./src/command-bases/index.ts",
|
|
195
|
-
"./src/errors": "./src/errors/index.ts",
|
|
196
|
-
"./src/interfaces": "./src/interfaces/index.ts",
|
|
197
|
-
"./src/managers": "./src/managers/index.ts",
|
|
198
|
-
"./src/modules/logger": "./src/modules/logger/index.ts",
|
|
199
|
-
"./src/modules/*": "./src/modules/*.ts",
|
|
200
|
-
"./package.json": "./package.json"
|
|
201
|
-
},
|
|
202
|
-
"devDependencies": {
|
|
203
|
-
"@jest/globals": "^29.7.0",
|
|
204
|
-
"@zenflux/cli": "workspace:*"
|
|
205
|
-
},
|
|
206
|
-
"publishConfig": {
|
|
207
|
-
"access": "public"
|
|
208
|
-
},
|
|
209
|
-
"dependencies": {
|
|
210
|
-
"fastmcp": "^3.23.1",
|
|
211
|
-
"zod": "^4.1.12",
|
|
212
|
-
"picocolors": "^1.0.0",
|
|
213
|
-
"@zenflux/utils": "workspace:*"
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
const name = "@zenflux/core";
|
|
217
|
-
const version = "0.1.27";
|
|
218
|
-
const types = "dist/zenflux-core.d.ts";
|
|
219
|
-
const type = "module";
|
|
220
|
-
const files = ["dist","types"];
|
|
221
|
-
const scripts = {"@z-core--test":"jest","@z-core--build":"@z-cli @build","@z-core--dev":"@z-cli @watch --dev"};
|
|
222
|
-
const exports$1 = {".":{"import":"./dist/zenflux-core.mjs","default":"./dist/zenflux-core.cjs","require":"./dist/zenflux-core.mjs.js","types":"./dist/zenflux-core.d.ts"},"./dist/src/*":"./src/*","./src/*.ts":"./src/*.ts","./src/*":"./src/*.ts","./src/bases":"./src/bases/index.ts","./src/bases/*":"./src/bases/*.ts","./src/clients":"./src/clients/index.ts","./src/command-bases":"./src/command-bases/index.ts","./src/errors":"./src/errors/index.ts","./src/interfaces":"./src/interfaces/index.ts","./src/managers":"./src/managers/index.ts","./src/modules/logger":"./src/modules/logger/index.ts","./src/modules/*":"./src/modules/*.ts","./package.json":"./package.json"};
|
|
223
|
-
const devDependencies = {"@jest/globals":"^29.7.0","@zenflux/cli":"workspace:*"};
|
|
224
|
-
const publishConfig = {"access":"public"};
|
|
225
|
-
const dependencies = {"fastmcp":"^3.23.1","zod":"^4.1.12","picocolors":"^1.0.0","@zenflux/utils":"workspace:*"};
|
|
226
|
-
|
|
227
|
-
const classes={Logger};let exportedConfig={version:version};function initialize(config){if("undefined"!==typeof __ZEN_CORE__IS_INITIALIZED__&&__ZEN_CORE__IS_INITIALIZED__){throw new Error("ZenCore is already initialized.")}exportedConfig=config||exportedConfig;initialize$1(exportedConfig);globalThis.__ZEN_CORE__IS_INITIALIZED__=true;}function destroy(){destroy$1();globalThis.__ZEN_CORE__IS_INITIALIZED__=false;}function onAfterInitialize(callback){afterInitializeCallbacks.push(callback);}const config=exportedConfig;
|
|
228
|
-
|
|
229
|
-
var ZenCore = /*#__PURE__*/Object.freeze({
|
|
230
|
-
__proto__: null,
|
|
231
|
-
bases: index$1,
|
|
232
|
-
classes: classes,
|
|
233
|
-
commandBases: index,
|
|
234
|
-
config: config,
|
|
235
|
-
destroy: destroy,
|
|
236
|
-
errors: indexPublic,
|
|
237
|
-
initialize: initialize,
|
|
238
|
-
interfaces: index$2,
|
|
239
|
-
managers: _export$1,
|
|
240
|
-
modules: _export,
|
|
241
|
-
onAfterInitialize: onAfterInitialize
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
if(!globalThis?.zCore){globalThis.zCore=ZenCore;}
|
|
245
|
-
|
|
246
165
|
exports.bases = index$1;
|
|
247
166
|
exports.commandBases = index;
|
|
248
|
-
exports.default = ZenCore;
|
|
249
167
|
exports.errors = indexPublic;
|
|
250
168
|
exports.interfaces = index$2;
|
|
251
169
|
exports.managers = _export$1;
|
package/dist/zenflux-core.d.ts
CHANGED
|
@@ -22,10 +22,6 @@ declare abstract class CacheBase<CacheResult> extends InitializeBase {
|
|
|
22
22
|
protected deleteCacheWithPrefix(prefix: string): void;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
declare const classes: {
|
|
26
|
-
Logger: typeof modules.Logger;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
25
|
declare abstract class CommandBase extends ObjectBase {
|
|
30
26
|
private static controller;
|
|
31
27
|
protected args: ICommandArgsInterface;
|
|
@@ -143,8 +139,6 @@ declare class Commands extends ObjectBase {
|
|
|
143
139
|
|
|
144
140
|
declare let commands: Commands;
|
|
145
141
|
|
|
146
|
-
declare const config: interfaces.IAPIConfig;
|
|
147
|
-
|
|
148
142
|
declare abstract class ControllerBase extends ObjectBase {
|
|
149
143
|
private commands;
|
|
150
144
|
private restful;
|
|
@@ -207,8 +201,6 @@ declare const createLogger: (owner: string | object, options?: LoggerOptions_2)
|
|
|
207
201
|
|
|
208
202
|
declare function destroy(): void;
|
|
209
203
|
|
|
210
|
-
declare function destroy_2(): void;
|
|
211
|
-
|
|
212
204
|
declare enum E_HTTP_METHOD_TYPE {
|
|
213
205
|
DELETE = "DELETE",// Delete.
|
|
214
206
|
GET = "GET",// Read.
|
|
@@ -345,9 +337,7 @@ declare interface ILogger {
|
|
|
345
337
|
}, data: any): void;
|
|
346
338
|
}
|
|
347
339
|
|
|
348
|
-
declare function initialize(config
|
|
349
|
-
|
|
350
|
-
declare function initialize_2(config: IAPIConfig): void;
|
|
340
|
+
declare function initialize(config: IAPIConfig): void;
|
|
351
341
|
|
|
352
342
|
declare abstract class InitializeBase extends ObjectBase {
|
|
353
343
|
protected logger: Logger;
|
|
@@ -529,8 +519,8 @@ declare type LoggerOutputSubscriber = (event: LoggerOutputEvent) => void;
|
|
|
529
519
|
|
|
530
520
|
declare namespace managers {
|
|
531
521
|
export {
|
|
532
|
-
|
|
533
|
-
|
|
522
|
+
initialize,
|
|
523
|
+
destroy,
|
|
534
524
|
afterInitializeCallbacks,
|
|
535
525
|
commands,
|
|
536
526
|
controllers,
|
|
@@ -564,8 +554,6 @@ declare abstract class ObjectBase {
|
|
|
564
554
|
getHierarchyNames(): string[];
|
|
565
555
|
}
|
|
566
556
|
|
|
567
|
-
declare function onAfterInitialize(callback: () => void): void;
|
|
568
|
-
|
|
569
557
|
declare class Restful extends Commands {
|
|
570
558
|
private static client;
|
|
571
559
|
currentHttpMethod: E_HTTP_METHOD_TYPE;
|
|
@@ -669,23 +657,6 @@ declare type TServiceNameDependencies<T> = {
|
|
|
669
657
|
|
|
670
658
|
declare type TServicesNonEmpty<T> = keyof T extends never ? "Error: Services are required" : T;
|
|
671
659
|
|
|
672
|
-
declare namespace ZenCore {
|
|
673
|
-
export {
|
|
674
|
-
initialize,
|
|
675
|
-
destroy,
|
|
676
|
-
onAfterInitialize,
|
|
677
|
-
classes,
|
|
678
|
-
config,
|
|
679
|
-
bases,
|
|
680
|
-
commandBases,
|
|
681
|
-
errors,
|
|
682
|
-
interfaces,
|
|
683
|
-
managers,
|
|
684
|
-
modules
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
export default ZenCore;
|
|
688
|
-
|
|
689
660
|
declare class ZenFluxLogger extends Logger {
|
|
690
661
|
}
|
|
691
662
|
|