@zenflux/core 0.1.18 → 0.1.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,34 @@
1
1
  /**
2
- * Bundled with love using the help of @zenflux/cli toolkit v0.1.38
3
- * Bundle name: @zenflux/core fileName: 'zenflux-core', built at Thu Nov 20 2025 12:34:10 GMT+0200 (Israel Standard Time)
2
+ * Bundled with love using the help of @zenflux/cli toolkit v0.1.41
3
+ * Bundle name: @zenflux/core fileName: 'zenflux-core', built at Thu Dec 11 2025 19:18:14 GMT+0200 (Israel Standard Time)
4
4
  */
5
5
 
6
6
  'use strict';
7
7
 
8
8
  Object.defineProperty(exports, '__esModule', { value: true });
9
9
 
10
+ var util = require('util');
11
+
10
12
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
13
+ function _interopNamespaceDefault(e) {
14
+ var n = Object.create(null);
15
+ if (e) {
16
+ Object.keys(e).forEach(function (k) {
17
+ if (k !== 'default') {
18
+ var d = Object.getOwnPropertyDescriptor(e, k);
19
+ Object.defineProperty(n, k, d.get ? d : {
20
+ enumerable: true,
21
+ get: function () { return e[k]; }
22
+ });
23
+ }
24
+ });
25
+ }
26
+ n.default = e;
27
+ return Object.freeze(n);
28
+ }
29
+
30
+ var util__namespace = /*#__PURE__*/_interopNamespaceDefault(util);
31
+
11
32
  class CommandAlreadyRegistered extends Error{constructor(command){super(`Command: '${command.getName()}' is already registered`);}}
12
33
 
13
34
  class CommandNotFound extends Error{constructor(command){super(`Command: '${command}' is not found`);}}
@@ -55,33 +76,6 @@ get restful () { return restful; }
55
76
 
56
77
  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(){}}
57
78
 
58
- var index$1 = /*#__PURE__*/Object.freeze({
59
- __proto__: null,
60
- ControllerBase: ControllerBase,
61
- ObjectBase: ObjectBase
62
- });
63
-
64
- 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=new zCore.classes.Logger(type,{repeatedly:true});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}}
65
-
66
- class CommandPublic extends CommandBase{static getName(){return "ZenFlux/Core/CommandBases/CommandPublic"}}
67
-
68
- class CommandRestful extends CommandBase{static getName(){return "ZenFlux/Core/CommandBases/CommandRestful"}getEndpoint(){throw new ForceMethodImplementation(this,"getEndpoint")}apply(args=this.args,options=this.options){const endpoint=this.applyEndpointFormat(this.getEndpoint(),args);return restful.getClient().fetch(endpoint,restful.currentHttpMethod,args||null)}applyEndpointFormat(endpoint,data={}){if(endpoint.includes("{")){endpoint=endpoint.split("/").map(endpointPart=>{const match=endpointPart.match("\\{(.*?)\\}");if(match?.length&&"undefined"!==typeof data[match[1]]){return data[match[1]]}return endpointPart}).join("/");}return endpoint}}
69
-
70
- class CommandInternal extends CommandBase{static getName(){return "ZenFlux/Core/CommandBases/CommandInternal"}}
71
-
72
- var index = /*#__PURE__*/Object.freeze({
73
- __proto__: null,
74
- CommandBase: CommandBase,
75
- CommandInternal: CommandInternal,
76
- CommandPublic: CommandPublic,
77
- CommandRestful: CommandRestful
78
- });
79
-
80
- var indexPublic = /*#__PURE__*/Object.freeze({
81
- __proto__: null,
82
- ForceMethodImplementation: ForceMethodImplementation
83
- });
84
-
85
79
  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"}
86
80
 
87
81
  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}
@@ -110,9 +104,49 @@ let SimpleEventEmitter=class SimpleEventEmitter{listeners=new Map;on(event,callb
110
104
 
111
105
  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)}}
112
106
 
107
+ 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);}}}
108
+
109
+ 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)}}
110
+
111
+ function isDebugEnabled(type,name){return false}
112
+
113
+ class Debugger extends ObjectBase{shouldDebug;logger;static getName(){return "ZenFlux/Core/Modules/Debugger"}constructor(owner,prefix,shouldDebug=Logger.isDebugEnabled(),options){super(),this.shouldDebug=shouldDebug;if(shouldDebug){const loggerOptions=options?.skipEventBusHook?{skipEventBusHook:true}:undefined;this.logger=new Logger(owner,loggerOptions);if(prefix){this.logger.addMessagePrefix(prefix);}}else {this.log=()=>{};this.dumpDown=()=>{};this.enableCleanupDebug=()=>{};}}enableCleanupDebug(handle,id=""){if(!this.finalizationRegistry){this.finalizationRegistry=new FinalizationRegistry(id=>{this.log(this.constructor,`FinalizationRegistry: ${id}`);});}if(!id){id=handle.getName()+":"+handle.getUniqueId();}this.log(this.enableCleanupDebug,`Initialized: '${id}'`);this.finalizationRegistry.register(handle,id);}log(source,message,...args){if(args&&args.length>0){return this.logger.debug(source,message,...args)}this.logger.debug(source,message);}dumpDown(source,object,objectName=""){this.log(source,`${objectName?objectName+":":""} `+"🔽"+"\n"+pc.green(util__namespace.inspect(object,false,null,true)));}isEnabled(){return this.shouldDebug}}function createDebugger(owner,ownerType,prefix){const ownerName=typeof owner==="string"?owner:owner.getName();return new Debugger(owner,prefix,isDebugEnabled(ownerType,ownerName))}
114
+
115
+ class CacheBase extends InitializeBase{cache;cacheDebugger;constructor(shouldDebugCache=true){super();this.cacheDebugger=new Debugger(this,undefined,shouldDebugCache);this.cache=new Map;}getCache(key){this.cacheDebugger.log(this.getCache,`Getting cache for key: '${key}'`);const result=this.cache.get(key);if(result){this.cacheDebugger.log(this.getCache,`Got cache for key: '${key}'`);this.cacheDebugger.dumpDown(this.setCache,result);}return result}getCacheMap(){return this.cache}setCache(key,value){this.cacheDebugger.log(this.setCache,`Setting cache for key: '${key}'`);this.cacheDebugger.dumpDown(this.setCache,value);this.cache.set(key,value);}deleteCache(key){this.cacheDebugger.log(this.deleteCache,`Deleting cache for key: '${key}'`);if(!this.cache.has(key)){this.cacheDebugger.log(this.deleteCache,`Cache for key: '${key}' does not exist`);return false}return this.cache.delete(key)}deleteCacheWithPrefix(prefix){this.cacheDebugger.log(this.deleteCacheWithPrefix,`Deleting cache prefix: '${prefix}'`);for(const key of this.cache.keys()){if(key.startsWith(prefix)){this.deleteCache(key);}}}}
116
+
117
+ var index$1 = /*#__PURE__*/Object.freeze({
118
+ __proto__: null,
119
+ CacheBase: CacheBase,
120
+ ControllerBase: ControllerBase,
121
+ InitializeBase: InitializeBase,
122
+ ObjectBase: ObjectBase,
123
+ SingletonBase: SingletonBase
124
+ });
125
+
126
+ 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=new zCore.classes.Logger(type,{repeatedly:true});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}}
127
+
128
+ class CommandPublic extends CommandBase{static getName(){return "ZenFlux/Core/CommandBases/CommandPublic"}}
129
+
130
+ class CommandRestful extends CommandBase{static getName(){return "ZenFlux/Core/CommandBases/CommandRestful"}getEndpoint(){throw new ForceMethodImplementation(this,"getEndpoint")}apply(args=this.args,options=this.options){const endpoint=this.applyEndpointFormat(this.getEndpoint(),args);return restful.getClient().fetch(endpoint,restful.currentHttpMethod,args||null)}applyEndpointFormat(endpoint,data={}){if(endpoint.includes("{")){endpoint=endpoint.split("/").map(endpointPart=>{const match=endpointPart.match("\\{(.*?)\\}");if(match?.length&&"undefined"!==typeof data[match[1]]){return data[match[1]]}return endpointPart}).join("/");}return endpoint}}
131
+
132
+ class CommandInternal extends CommandBase{static getName(){return "ZenFlux/Core/CommandBases/CommandInternal"}}
133
+
134
+ var index = /*#__PURE__*/Object.freeze({
135
+ __proto__: null,
136
+ CommandBase: CommandBase,
137
+ CommandInternal: CommandInternal,
138
+ CommandPublic: CommandPublic,
139
+ CommandRestful: CommandRestful
140
+ });
141
+
142
+ var indexPublic = /*#__PURE__*/Object.freeze({
143
+ __proto__: null,
144
+ ForceMethodImplementation: ForceMethodImplementation
145
+ });
146
+
113
147
  var _package = {
114
148
  "name": "@zenflux/core",
115
- "version": "0.1.16",
149
+ "version": "0.1.19",
116
150
  "types": "dist/zenflux-core.d.ts",
117
151
  "type": "module",
118
152
  "files": [
@@ -157,7 +191,7 @@ var _package = {
157
191
  }
158
192
  };
159
193
  const name = "@zenflux/core";
160
- const version = "0.1.16";
194
+ const version = "0.1.19";
161
195
  const types = "dist/zenflux-core.d.ts";
162
196
  const type = "module";
163
197
  const files = ["dist","types"];
@@ -1,8 +1,10 @@
1
1
  /**
2
- * Bundled with love using the help of @zenflux/cli toolkit v0.1.38
3
- * Bundle name: @zenflux/core fileName: 'zenflux-core', built at Thu Nov 20 2025 12:34:10 GMT+0200 (Israel Standard Time)
2
+ * Bundled with love using the help of @zenflux/cli toolkit v0.1.41
3
+ * Bundle name: @zenflux/core fileName: 'zenflux-core', built at Thu Dec 11 2025 19:18:14 GMT+0200 (Israel Standard Time)
4
4
  */
5
5
 
6
+ import * as util from 'util';
7
+
6
8
  class CommandAlreadyRegistered extends Error{constructor(command){super(`Command: '${command.getName()}' is already registered`);}}
7
9
 
8
10
  class CommandNotFound extends Error{constructor(command){super(`Command: '${command}' is not found`);}}
@@ -50,33 +52,6 @@ get restful () { return restful; }
50
52
 
51
53
  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(){}}
52
54
 
53
- var index$1 = /*#__PURE__*/Object.freeze({
54
- __proto__: null,
55
- ControllerBase: ControllerBase,
56
- ObjectBase: ObjectBase
57
- });
58
-
59
- 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=new zCore.classes.Logger(type,{repeatedly:true});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}}
60
-
61
- class CommandPublic extends CommandBase{static getName(){return "ZenFlux/Core/CommandBases/CommandPublic"}}
62
-
63
- class CommandRestful extends CommandBase{static getName(){return "ZenFlux/Core/CommandBases/CommandRestful"}getEndpoint(){throw new ForceMethodImplementation(this,"getEndpoint")}apply(args=this.args,options=this.options){const endpoint=this.applyEndpointFormat(this.getEndpoint(),args);return restful.getClient().fetch(endpoint,restful.currentHttpMethod,args||null)}applyEndpointFormat(endpoint,data={}){if(endpoint.includes("{")){endpoint=endpoint.split("/").map(endpointPart=>{const match=endpointPart.match("\\{(.*?)\\}");if(match?.length&&"undefined"!==typeof data[match[1]]){return data[match[1]]}return endpointPart}).join("/");}return endpoint}}
64
-
65
- class CommandInternal extends CommandBase{static getName(){return "ZenFlux/Core/CommandBases/CommandInternal"}}
66
-
67
- var index = /*#__PURE__*/Object.freeze({
68
- __proto__: null,
69
- CommandBase: CommandBase,
70
- CommandInternal: CommandInternal,
71
- CommandPublic: CommandPublic,
72
- CommandRestful: CommandRestful
73
- });
74
-
75
- var indexPublic = /*#__PURE__*/Object.freeze({
76
- __proto__: null,
77
- ForceMethodImplementation: ForceMethodImplementation
78
- });
79
-
80
55
  const DEFAULT_LOG_LEVEL="5";function getEnvVar(key){if(typeof process!=="undefined"&&process?.env){return process.env[key]??process.env[`VITE_${key}`]}if(typeof import.meta!=="undefined"&&import.meta.env){const env=import.meta.env;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
56
 
82
57
  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}
@@ -105,9 +80,49 @@ let SimpleEventEmitter=class SimpleEventEmitter{listeners=new Map;on(event,callb
105
80
 
106
81
  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
82
 
83
+ 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);}}}
84
+
85
+ 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)}}
86
+
87
+ function isDebugEnabled(type,name){return false}
88
+
89
+ class Debugger extends ObjectBase{shouldDebug;logger;static getName(){return "ZenFlux/Core/Modules/Debugger"}constructor(owner,prefix,shouldDebug=Logger.isDebugEnabled(),options){super(),this.shouldDebug=shouldDebug;if(shouldDebug){const loggerOptions=options?.skipEventBusHook?{skipEventBusHook:true}:undefined;this.logger=new Logger(owner,loggerOptions);if(prefix){this.logger.addMessagePrefix(prefix);}}else {this.log=()=>{};this.dumpDown=()=>{};this.enableCleanupDebug=()=>{};}}enableCleanupDebug(handle,id=""){if(!this.finalizationRegistry){this.finalizationRegistry=new FinalizationRegistry(id=>{this.log(this.constructor,`FinalizationRegistry: ${id}`);});}if(!id){id=handle.getName()+":"+handle.getUniqueId();}this.log(this.enableCleanupDebug,`Initialized: '${id}'`);this.finalizationRegistry.register(handle,id);}log(source,message,...args){if(args&&args.length>0){return this.logger.debug(source,message,...args)}this.logger.debug(source,message);}dumpDown(source,object,objectName=""){this.log(source,`${objectName?objectName+":":""} `+"🔽"+"\n"+pc.green(util.inspect(object,false,null,true)));}isEnabled(){return this.shouldDebug}}function createDebugger(owner,ownerType,prefix){const ownerName=typeof owner==="string"?owner:owner.getName();return new Debugger(owner,prefix,isDebugEnabled(ownerType,ownerName))}
90
+
91
+ class CacheBase extends InitializeBase{cache;cacheDebugger;constructor(shouldDebugCache=true){super();this.cacheDebugger=new Debugger(this,undefined,shouldDebugCache);this.cache=new Map;}getCache(key){this.cacheDebugger.log(this.getCache,`Getting cache for key: '${key}'`);const result=this.cache.get(key);if(result){this.cacheDebugger.log(this.getCache,`Got cache for key: '${key}'`);this.cacheDebugger.dumpDown(this.setCache,result);}return result}getCacheMap(){return this.cache}setCache(key,value){this.cacheDebugger.log(this.setCache,`Setting cache for key: '${key}'`);this.cacheDebugger.dumpDown(this.setCache,value);this.cache.set(key,value);}deleteCache(key){this.cacheDebugger.log(this.deleteCache,`Deleting cache for key: '${key}'`);if(!this.cache.has(key)){this.cacheDebugger.log(this.deleteCache,`Cache for key: '${key}' does not exist`);return false}return this.cache.delete(key)}deleteCacheWithPrefix(prefix){this.cacheDebugger.log(this.deleteCacheWithPrefix,`Deleting cache prefix: '${prefix}'`);for(const key of this.cache.keys()){if(key.startsWith(prefix)){this.deleteCache(key);}}}}
92
+
93
+ var index$1 = /*#__PURE__*/Object.freeze({
94
+ __proto__: null,
95
+ CacheBase: CacheBase,
96
+ ControllerBase: ControllerBase,
97
+ InitializeBase: InitializeBase,
98
+ ObjectBase: ObjectBase,
99
+ SingletonBase: SingletonBase
100
+ });
101
+
102
+ 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=new zCore.classes.Logger(type,{repeatedly:true});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}}
103
+
104
+ class CommandPublic extends CommandBase{static getName(){return "ZenFlux/Core/CommandBases/CommandPublic"}}
105
+
106
+ class CommandRestful extends CommandBase{static getName(){return "ZenFlux/Core/CommandBases/CommandRestful"}getEndpoint(){throw new ForceMethodImplementation(this,"getEndpoint")}apply(args=this.args,options=this.options){const endpoint=this.applyEndpointFormat(this.getEndpoint(),args);return restful.getClient().fetch(endpoint,restful.currentHttpMethod,args||null)}applyEndpointFormat(endpoint,data={}){if(endpoint.includes("{")){endpoint=endpoint.split("/").map(endpointPart=>{const match=endpointPart.match("\\{(.*?)\\}");if(match?.length&&"undefined"!==typeof data[match[1]]){return data[match[1]]}return endpointPart}).join("/");}return endpoint}}
107
+
108
+ class CommandInternal extends CommandBase{static getName(){return "ZenFlux/Core/CommandBases/CommandInternal"}}
109
+
110
+ var index = /*#__PURE__*/Object.freeze({
111
+ __proto__: null,
112
+ CommandBase: CommandBase,
113
+ CommandInternal: CommandInternal,
114
+ CommandPublic: CommandPublic,
115
+ CommandRestful: CommandRestful
116
+ });
117
+
118
+ var indexPublic = /*#__PURE__*/Object.freeze({
119
+ __proto__: null,
120
+ ForceMethodImplementation: ForceMethodImplementation
121
+ });
122
+
108
123
  var _package = {
109
124
  "name": "@zenflux/core",
110
- "version": "0.1.16",
125
+ "version": "0.1.19",
111
126
  "types": "dist/zenflux-core.d.ts",
112
127
  "type": "module",
113
128
  "files": [
@@ -152,7 +167,7 @@ var _package = {
152
167
  }
153
168
  };
154
169
  const name = "@zenflux/core";
155
- const version = "0.1.16";
170
+ const version = "0.1.19";
156
171
  const types = "dist/zenflux-core.d.ts";
157
172
  const type = "module";
158
173
  const files = ["dist","types"];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenflux/core",
3
- "version": "0.1.18",
3
+ "version": "0.1.20",
4
4
  "types": "dist/zenflux-core.d.ts",
5
5
  "type": "module",
6
6
  "files": [
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "devDependencies": {
34
34
  "@jest/globals": "^29.7.0",
35
- "@zenflux/cli": "0.1.40"
35
+ "@zenflux/cli": "0.1.42"
36
36
  },
37
37
  "publishConfig": {
38
38
  "access": "public"
@@ -41,6 +41,6 @@
41
41
  "fastmcp": "^3.23.1",
42
42
  "zod": "^4.1.12",
43
43
  "picocolors": "^1.0.0",
44
- "@zenflux/utils": "0.1.22"
44
+ "@zenflux/utils": "0.1.24"
45
45
  }
46
46
  }