@decaf-ts/logging 0.24.0 → 0.24.2

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/logging.cjs CHANGED
@@ -1,2 +1,2 @@
1
- var t,e;t=this,e=function(t,e,r,n){"use strict";const o="ENV",s="__",i=["${","}"];var a;t.LogLevel=void 0,(a=t.LogLevel||(t.LogLevel={})).benchmark="benchmark",a.fatal="fatal",a.critical="critical",a.error="error",a.warn="warn",a.info="info",a.verbose="verbose",a.debug="debug",a.trace="trace",a.silly="silly";const c={benchmark:0,fatal:1,critical:2,error:3,warn:6,info:9,verbose:12,debug:15,trace:18,silly:21};var l;t.LoggingMode=void 0,(l=t.LoggingMode||(t.LoggingMode={})).RAW="raw",l.JSON="json";const u={app:{},separator:{},class:{fg:34},id:{fg:36},stack:{},timestamp:{},message:{error:{fg:31}},method:{},logLevel:{benchmark:{fg:32,style:["bold"]},fatal:{fg:31,style:["bold"]},critical:{fg:31,style:["bold"]},error:{fg:31,style:["bold"]},info:{fg:34,style:["bold"]},verbose:{fg:34,style:["bold"]},debug:{fg:33,style:["bold"]},trace:{fg:33,style:["bold"]},silly:{fg:33,style:["bold"]}}},g={env:"development",verbose:0,level:t.LogLevel.info,logLevel:!0,style:!1,filters:[],contextSeparator:".",separator:"-",timestamp:!0,timestampFormat:"HH:mm:ss.SSS",context:!0,meta:!0,format:t.LoggingMode.RAW,pattern:"{level} [{timestamp}] {app} {context} {separator} {message} {stack}",theme:u};class f{constructor(){this.descriptors=new Map}register(t){return this.descriptors.set(t.key,t),this}unregister(t){return this.descriptors.delete(t),this}get(t){return this.descriptors.get(t)}render(t,e){const r={},n=new Set;return e.forEach(e=>{if(n.has(e))return;n.add(e);const o=this.descriptors.get(e);if(!o)return;if(o.shouldInclude&&!o.shouldInclude(t))return;const s=o.render(t);if(void 0===s)return;const i=o.style?o.style(s,t):s;r[e]=i}),r}keys(){return Array.from(this.descriptors.keys())}}const p=new Map;function h(t){if(p.has(t))return p.get(t);const e=d(t||""),r=new Set,n=[];m(e,r,n);const o={pattern:t,segments:e,keys:n,includesMeta:r.has("meta")};return p.set(t,o),o}function y(t,e){return v(t.segments,e).text}function d(t){const e=[];let r=0;for(;r<t.length;){const n=t[r];if("["===n){const n=b(t,r,"[","]");if(-1===n){e.push({type:"literal",value:"["}),r++;continue}const o=t.slice(r+1,n);e.push({type:"optional",prefix:"[",suffix:"]",children:d(o)}),r=n+1;continue}if("{"===n){const n=t.indexOf("}",r+1);if(-1===n){e.push({type:"literal",value:"{"}),r++;continue}const o=t.slice(r+1,n).trim();e.push({type:"parameter",key:o}),r=n+1;continue}let o=r;for(;o<t.length&&"["!==t[o]&&"{"!==t[o];)o++;const s=t.slice(r,o);s.length&&e.push({type:"literal",value:s}),r=o}return e}function b(t,e,r,n){let o=0;for(let s=e;s<t.length;s++){const e=t[s];if(e===r)o++;else if(e===n&&(o--,0===o))return s}return-1}function m(t,e,r){for(const n of t)"parameter"===n.type&&(e.has(n.key)||(e.add(n.key),r.push(n.key))),"optional"===n.type&&m(n.children,e,r)}function v(t,e){const r=[];let n=!1;for(const o of t){const t=x(o,e);t.text.length&&r.push(t.text),n=n||t.hasValue}return{text:r.join(""),hasValue:n}}function x(t,e){if("literal"===t.type)return{text:t.value,hasValue:!1};if("parameter"===t.type){const r=e[t.key]??"";return{text:r,hasValue:r.length>0}}const r=v(t.children,e);return r.hasValue?{text:`${t.prefix}${r.text}${t.suffix}`,hasValue:!0}:{text:"",hasValue:!1}}const L=new f;L.register({key:"level",render(t){if(!1!==t.config.logLevel)return t.level.toUpperCase()},style:(t,e)=>e.applyTheme(t,"logLevel")}).register({key:"timestamp",shouldInclude:t=>!(!t.config.timestamp||!t.timestamp),render:t=>t.timestamp,style:(t,e)=>e.applyTheme(t,"timestamp")}).register({key:"app",shouldInclude:t=>!!t.app,render:t=>t.app,style:(t,e)=>e.applyTheme(t,"app")}).register({key:"context",shouldInclude:t=>!1!==t.config.context&&t.context.length>0,render(t){const e=t.config.contextSeparator||".";return t.context.join(e)},style:(t,e)=>e.applyTheme(t,"class")}).register({key:"separator",shouldInclude:t=>!!t.separator,render:t=>t.separator,style:(t,e)=>e.applyTheme(t,"separator")}).register({key:"message",render:t=>t.filteredMessage,style:(t,e)=>e.applyTheme(t,"message")}).register({key:"stack",shouldInclude:t=>!!t.stack,render:t=>t.stack,style:(t,e)=>e.applyTheme(t,"stack")}).register({key:"meta",shouldInclude:t=>!!t.metaString,render:t=>t.metaString}).register({key:"correlationId",shouldInclude:t=>!!t.correlationId,render:t=>t.correlationId,style:(t,e)=>e.applyTheme(t,"id")});const w=L;function E(t,e,r="g"){return Object.entries(e).forEach(([e,n])=>{const o=RegExp(k(e),r);t=t.replace(o,n)}),t}function O(t){return _(t).toUpperCase()}function _(t){return t.replace(/([a-z\d])([A-Z])/g,"$1_$2").replace(/[\s-]+/g,"_").toLowerCase()}function k(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function j(t,...e){if(e.length>1&&!e.every(t=>"string"==typeof t||"number"==typeof t))throw Error("Only string and number arguments are supported for multiple replacements.");if(1===e.length&&"object"==typeof e[0]){const r=e[0];return Object.entries(r).reduce((t,[e,r])=>t.replace(RegExp(`\\{${e}\\}`,"g"),()=>r),t)}return t.replace(/{(\d+)}/g,(t,r)=>void 0!==e[r]?e[r].toString():"undefined")}const P=j;function A(){return Object.getPrototypeOf(Object.getPrototypeOf(globalThis))!==Object.prototype}const R=Symbol("EnvironmentEmpty"),M=Symbol("EnvironmentModel"),S=/^[a-z][a-zA-Z0-9]*$/;class C extends r.ObjectAccumulator{static{this.factory=()=>new C}constructor(){super(),Object.defineProperty(this,M,{value:{},writable:!0,enumerable:!1,configurable:!1})}static isProxyableObject(t){if(!t||"object"!=typeof t)return!1;if(Array.isArray(t))return!0;const e=Object.getPrototypeOf(t);return e===Object.prototype||null===e}fromEnv(t){let e;return A()?e=globalThis[o]||{}:(e=globalThis.process.env,t=O(t)),this.parseEnvValue(e[t])}parseEnvValue(t){return C.parseRuntimeValue(t)}static parseRuntimeValue(t){if("string"!=typeof t)return t;if("true"===t)return!0;if("false"===t)return!1;const e=t.trim();return/^-?\d+(\.\d+)?$/.test(e)?Number(e):t}expand(t){Object.entries(t).forEach(([t,e])=>{C.mergeModel(this[M],t,e),Object.defineProperty(this,t,{get:()=>{const r=this.fromEnv(t);return void 0!==r?r:e&&"object"==typeof e?C.buildEnvProxy(e,[t]):""===e?R:e},set:t=>{e=t},configurable:!0,enumerable:!0})})}orThrow(){const t=this[M],e=t=>void 0!==t?this.parseEnvValue(t):void 0,r=(t,e=!1)=>C.missingEnvError(t,e),n=(t,o)=>{const s={get(s,i){if(i===Symbol.toPrimitive)return()=>C.buildEnvKey(o);if("toString"===i)return()=>C.buildEnvKey(o);if("valueOf"===i)return()=>C.buildEnvKey(o);if("symbol"==typeof i)return;if("toJSON"===i)return;if("then"===i)return;if("constructor"===i)return Object;if(Array.isArray(t)&&"length"===i)return t.length;if(Array.isArray(t)&&i in Array.prototype){const e=Reflect.get(t,i,t);return"function"==typeof e?e.bind(t):e}const a=[...o,i],{key:c,value:l}=C.readRuntimeForPath(a);if("string"==typeof l&&0===l.length)throw r(c,!0);const u=e(l);if(void 0!==u){if("string"==typeof u&&0===u.length)throw r(c,!0);return u}if(!t||!Object.prototype.hasOwnProperty.call(t,i))throw r(c);const g=t[i];if(void 0!==g){if(""===g)throw r(c);return C.isProxyableObject(g)?n(g,a):g}},ownKeys:()=>t?Reflect.ownKeys(t):[],getOwnPropertyDescriptor(e,r){if(t)return Object.prototype.hasOwnProperty.call(t,r)?{enumerable:!0,configurable:!0}:void 0}};return new Proxy(Array.isArray(t)?[]:{},s)};return new Proxy(this,{get(o,s,i){if("string"!=typeof s)return Reflect.get(o,s,i);if(!Object.prototype.hasOwnProperty.call(t,s))return Reflect.get(o,s,i);const{key:a,value:c}=C.readRuntimeForPath([s]);if("string"==typeof c&&0===c.length)throw r(a,!0);const l=e(c);if(void 0!==l){if("string"==typeof l&&0===l.length)throw r(a,!0);return l}const u=t[s];if(C.isProxyableObject(u))return n(u,[s]);if(void 0===u)return Reflect.get(o,s,i);const g=Reflect.get(o,s);if(void 0===g||""===g)throw r(a,""===g);return g}})}static instance(...t){if(!C._instance){const e=C.factory(...t),r=new Proxy(e,{get(t,e,r){const n=Reflect.get(t,e,r);if(n!==R&&("string"!=typeof e||!Object.prototype.hasOwnProperty.call(t,e)||void 0!==n)){if(void 0!==n)return n;if("string"==typeof e){if("app"===e)return;return C.buildEnvProxy(void 0,[e])}return n}}});C._instance=r}return C._instance}accumulate(t){return super.accumulate(t),this}static accumulate(t){const e=C.instance();return Object.keys(e).forEach(t=>{const r=Object.getOwnPropertyDescriptor(e,t);r&&r.configurable&&r.enumerable&&Object.defineProperty(e,t,{...r,enumerable:!1})}),e.accumulate(t),e}static get(t){return C._instance.get(t)}static formatEnvSegment(t){return S.test(t)?O(t):t.toUpperCase()}static buildEnvKey(t){return t.map(t=>C.formatEnvSegment(t)).join(s)}static buildRawKey(t){return t.join(s)}static readRuntimeForPath(t){const e=C.buildEnvKey(t),r=C.buildRawKey(t),n=C.readRuntimeEnv(e);if(void 0!==n)return{key:e,value:n};if(r!==e){const t=C.readRuntimeEnv(r);if(void 0!==t)return{key:r,value:t}}return{key:e,value:void 0}}static runtimeEnv(){return A()?globalThis[o]:globalThis?.process?.env}static getRuntimeChildKeys(t){const e=C.runtimeEnv();if(!e)return[];const r=[C.buildEnvKey(t),C.buildRawKey(t)],n=new Set;return Object.keys(e).forEach(t=>{r.forEach(e=>{if(!e)return;const r=`${e}${s}`;if(t.startsWith(r)){const e=t.slice(r.length).split(s)[0];e&&n.add(e)}})}),[...n]}static hasRuntimePath(t){const{value:e}=C.readRuntimeForPath(t);return void 0!==e||C.getRuntimeChildKeys(t).length>0}static buildEnvProxy(t,e){const r=t=>C.readRuntimeEnv(t),n=/^[0-9]+$/,o={get(o,s){if(s===Symbol.toPrimitive)return()=>C.buildEnvKey(e);if("toString"===s)return()=>C.buildEnvKey(e);if("valueOf"===s)return()=>C.buildEnvKey(e);if("symbol"==typeof s)return;if(Array.isArray(t)&&s in Array.prototype){const e=Reflect.get(t,s,t);return"function"==typeof e?e.bind(t):e}if(Array.isArray(t)&&"length"===s)return t.length;const i=[...e,s],a=C.buildEnvKey(i),c=C.buildRawKey(i);let l=r(a);if(void 0===l&&c!==a&&(l=r(c)),void 0!==l)return C.parseRuntimeValue(l);const u=!!t&&Object.prototype.hasOwnProperty.call(t,s),g=u?t[s]:void 0,f=C.hasRuntimePath(i);return Array.isArray(t)&&(t=>"string"==typeof t&&n.test(t))(s)?u?C.isProxyableObject(g)?C.buildEnvProxy(g,i):C.parseRuntimeValue(g):f?C.buildEnvProxy(void 0,i):void 0:g&&"object"==typeof g&&C.isProxyableObject(g)?C.buildEnvProxy(g,i):u&&""===g||u&&void 0===g?void 0:u?C.parseRuntimeValue(g):C.buildEnvProxy(void 0,i)},ownKeys(){const r=new Set;return t&&Reflect.ownKeys(t).forEach(t=>r.add(t)),C.getRuntimeChildKeys(e).forEach(t=>r.add(t)),[...r]},getOwnPropertyDescriptor:(r,n)=>t&&Object.prototype.hasOwnProperty.call(t,n)?Reflect.getOwnPropertyDescriptor(t,n):"string"==typeof n&&C.hasRuntimePath([...e,n])?{enumerable:!0,configurable:!0}:void 0};return new Proxy(Array.isArray(t)?[]:{},o)}static keys(t=!0){return C.instance().keys().map(e=>t?O(e):e)}static mergeModel(t,e,r){if(t){if(r&&"object"==typeof r&&!Array.isArray(r)){const n=t[e],o=n&&"object"==typeof n&&!Array.isArray(n)?n:{};return t[e]=o,void Object.entries(r).forEach(([t,e])=>{C.mergeModel(o,t,e)})}t[e]=r}}static readRuntimeEnv(t){if(A()){const e=globalThis[o];return e?e[t]:void 0}return globalThis?.process?.env?.[t]}static missingEnvError(t,e){return Error(`Environment variable ${t} is required but was ${e?"an empty string":"undefined"}.`)}}const $=C.accumulate(Object.assign({app:void 0},g,{env:(A()&&globalThis[o]?globalThis[o].NODE_ENV:globalThis.process.env.NODE_ENV)||"development"}));function T(t){if("function"!=typeof t)return!1;try{const e=Function.prototype.toString.call(t);if(/^\s*class[\s{]/.test(e))return!0}catch{}const e=Object.getOwnPropertyDescriptor(t,"prototype");if(!e||!e.value)return!1;if(!1===e.writable)return!0;const r=t.prototype;return!!Object.prototype.hasOwnProperty.call(r,"constructor")&&Object.getOwnPropertyNames(r).filter(t=>"constructor"!==t).length>0}function I(t){return"function"==typeof t&&!T(t)}function K(t){if(!I(t))return!1;const e=Object.getOwnPropertyDescriptor(t,"prototype");return!e||void 0===e.value}function N(t){if(null===t||"object"!=typeof t)return!1;const e=t.constructor;return!(!e||e===Object)&&T(e)}function V(t){if(null===t)return"null";if(void 0===t)return"undefined";if("string"==typeof t)return t;if(T(t))return t.name||"AnonymousClass";if(N(t)){const e=t.toString;if("function"==typeof e&&e!==Object.prototype.toString)try{const r=e.call(t);if("string"==typeof r&&r.length)return r}catch{}const r=t.constructor;return r&&r.name?r.name:"AnonymousInstance"}if(K(t)||I(t)){const e=t;return e.name?e.name:"anonymous"}if("object"==typeof t){const e=Object.prototype.toString.call(t),r=/^\[object ([^\]]+)\]$/.exec(e);return r?.[1]?r[1]:"Object"}return typeof t}const F=Symbol("MiniLoggerRootContext");class D{constructor(t,e,r=[]){this.conf=e,this.baseContext=Array.isArray(r)?[...r]:[],t&&this.baseContext.push(t),this.context=[...this.baseContext],this[F]=[...this.baseContext]}config(t){return this.conf&&t in this.conf?this.conf[t]:U.getConfig()[t]}for(t,e,...r){let n,o=e;const s=Array.isArray(this.context)?[...this.context]:"string"==typeof this.context&&this.context?[this.context]:[],i=this[F],a=Array.isArray(i)?[...i]:Array.isArray(this.baseContext)?[...this.baseContext]:[];"string"==typeof t?n=t:void 0!==t&&(T(t)||N(t)||I(t)?n=V(t):!o&&t&&"object"==typeof t&&(o=t));let c=n?[...s,n]:[...s];return new Proxy(this,{get:(t,e,r)=>{const n=Reflect.get(t,e,r);return"config"===e?new Proxy(this.config,{apply:(t,e,n)=>{const[s]=n;return o&&void 0!==s&&s in o?o[s]:Reflect.apply(t,r,n)},get:(t,e)=>o&&e in o?o[e]:Reflect.get(t,e,r)}):"clear"===e?()=>(c=[...a],r):"context"===e?c:"root"===e?[...a]:e===F?a:"for"===e?(...e)=>{if(o){const t=e[0];"string"==typeof t||T(t)||N(t)||I(t)?e[1]={...o,...e[1]||{}}:t&&"object"==typeof t&&(e[0]={...o,...t})}const r=Array.isArray(t.context)?[...t.context]:"string"==typeof t.context&&t.context?[t.context]:[];t.context=[...c];try{return t.for.apply(t,e)}finally{t.context=r}}:"getConfigSnapshot"===e?()=>{const e=t.getConfigSnapshot();return o&&Object.assign(e,o),e}:n}})}getConfigSnapshot(){return{...U.getConfig(),...this.conf||{}}}getContextSegments(){return Array.isArray(this.context)?[...this.context]:"string"==typeof this.context&&this.context?[this.context]:[]}resolveFilters(t){const e=t.filters||[];return Array.isArray(e)?e.filter(t=>"object"==typeof t&&null!==t&&"function"==typeof t.filter):[]}applyFilters(t,e,r){const n=this.resolveFilters(r);return n.length?n.reduce((t,n)=>{try{const o=n.filter(r,t,[...e]);return"string"==typeof o?o:t}catch{return t}},t):t}createLog(t,e,r,n){const o=!!this.config("style"),s=this.config("separator"),i=U.getConfig().app,a=this.config("timestamp")?(new Date).toISOString():void 0,c=this.getConfigSnapshot(),l=this.getContextSegments(),u="string"==typeof e?e:e instanceof Error?e.message:e+"",g=this.applyFilters(u,l,c),f=this.config("meta")&&n?n:void 0,p=f?this.formatMeta(f):void 0,d=p?this.applyFilters(p,l,c):void 0,b=this.config("correlationId"),m=null!=b?b+"":void 0;let v,x;if(r||e instanceof Error){const n=r||e;n.stack&&(x="string"==typeof e?g:n.message,v=` | ${x} - Stack trace:\n${o?U.theme(n.stack,"stack",t):n.stack}`)}const L={config:c,level:t,context:l,timestamp:a,app:"string"==typeof i&&i.length?i:void 0,separator:s,correlationId:m,rawMessage:u,filteredMessage:g,meta:f,metaString:d,stack:v,stackLabel:x,applyTheme:(e,r)=>o?U.theme(e,r,t):e},E=this.config("pattern"),O=c.pattern||"",_=h(E.length?E:O),k=w.render(L,_.keys);switch(this.config("format")){case"json":{const t=w.render(L,w.keys()),e={};return Object.entries(t).forEach(([t,r])=>{"meta"!==t&&(e[t]=r)}),L.meta&&(e.meta=L.meta),JSON.stringify(e)}case"raw":{let t=this.normalizePatternSpacing(y(_,k));return!_.includesMeta&&d&&(t=t?`${t} ${d}`:d),t}default:throw Error("Unsupported logging format: "+this.config("format"))}}formatMeta(t){try{return JSON.stringify(t)}catch(e){return t+""}}normalizePatternSpacing(t){return t.replace(/[ \t]{2,}/g," ").replace(/^[ \t]+|[ \t]+$/g,"")}log(e,r,n,o){const s=this.config("level");if(c[e]>c[s])return;let i;switch(e){case t.LogLevel.benchmark:i=console.log;break;case t.LogLevel.fatal:case t.LogLevel.critical:case t.LogLevel.error:i=console.error;break;case t.LogLevel.info:case t.LogLevel.verbose:i=console.log;break;case t.LogLevel.debug:i=console.debug;break;case t.LogLevel.trace:i=console.trace;break;case t.LogLevel.warn:i=console.warn;break;case t.LogLevel.silly:i=console.debug;break;default:throw Error("Invalid log level")}i(this.createLog(e,r,n,o))}benchmark(e,r){this.log(t.LogLevel.benchmark,e,void 0,r)}fatal(e,r,n){let o,s;r instanceof Error?(o=r,s=n):s=r,this.log(t.LogLevel.fatal,e,o,s)}critical(e,r,n){let o,s;r instanceof Error?(o=r,s=n):s=r,this.log(t.LogLevel.critical,e,o,s)}silly(e,r=0,n){const o="number"==typeof r?r:0,s="number"==typeof r?n:r;this.config("verbose")<o||this.log(t.LogLevel.silly,e,void 0,s)}verbose(e,r=0,n){const o="number"==typeof r?r:0,s="number"==typeof r?n:r;this.config("verbose")<o||this.log(t.LogLevel.verbose,e,void 0,s)}info(e,r){this.log(t.LogLevel.info,e,void 0,r)}debug(e,r){this.log(t.LogLevel.debug,e,void 0,r)}error(e,r,n){let o,s;r instanceof Error?(o=r,s=n):s=r,this.log(t.LogLevel.error,e,o,s)}warn(e,r){this.log(t.LogLevel.warn,e,void 0,r)}trace(e,r){this.log(t.LogLevel.trace,e,void 0,r)}setConfig(t){this.conf={...this.conf||{},...t}}get root(){return[...this.baseContext]}clear(){return this.context=[...this.baseContext],this}}class U{static{this._factory=(t,e)=>{const r="string"==typeof $.app?[$.app]:[];return new D(t,e,r)}}static{this._config=$}constructor(){}static setFactory(t){U._factory=t,this.global=void 0}static setConfig(t){Object.entries(t).forEach(([t,e])=>{this._config[t]=e})}static getConfig(){return this._config}static get(){return this.ensureRoot()}static verbose(t,e=0,r){return this.get().verbose(t,e,r)}static info(t,e){return this.get().info(t,e)}static trace(t,e){return this.get().trace(t,e)}static debug(t,e){return this.get().debug(t,e)}static benchmark(t,e){return this.get().benchmark(t,e)}static fatal(t,e,r){return this.get().fatal(t,e,r)}static critical(t,e,r){return this.get().critical(t,e,r)}static silly(t,e=0,r){return this.get().silly(t,e,r)}static warn(t,e){return this.get().warn(t,e)}static error(t,e,r){return this.get().error(t,e,r)}static for(t,e,...r){const n=void 0!==e?[t,e]:[t];return(this.global?this.global:this.ensureRoot(r)).for(...n)}static because(t,e){let r=this.ensureRoot().for(t,this._config);return e&&(r=r.for(e)),r}static baseContext(){const t=this._config.app;return"string"==typeof t&&t.length?[t]:[]}static attachRootContext(t){const e=t.root&&Array.isArray(t.root)?[...t.root]:this.baseContext();return(!t.context||Array.isArray(t.context)&&0===t.context.length)&&(t.context=[...e]),t[F]=[...e],t}static ensureRoot(t=[]){if(!this.global){const e=this._factory(void 0,void 0,...t);this.global=this.attachRootContext(e)}return this.global}static theme(r,n,o,s=u){if(!this._config.style)return r;const i=s[n];if(!i||!Object.keys(i).length)return r;let a=i;const c=Object.assign({},t.LogLevel);return Object.keys(i)[0]in c&&(a=i[o]||{}),Object.keys(a).reduce((t,r)=>{const n=a[r];return n?((t,r,n)=>{try{const o=t;let s=e.style(o);function i(t,r=!1){let i=r?s.background:s.foreground;if(!Array.isArray(t))return i.call(s,n);switch(t.length){case 1:return i=r?s.bgColor256:s.color256,i(t[0]);case 3:return i=r?s.bgRgb:s.rgb,s.rgb(t[0],t[1],t[2]);default:return e.style(o)}}function a(t){s="number"==typeof t?s.style(t):s[t]}switch(r){case"bg":case"fg":return i(n).text;case"style":return Array.isArray(n)?n.forEach(a):a(n),s.text;default:return o}}catch(c){return t}})(t,r,n):t},r)}static register(t){return w.register(t)}static unregister(t){return w.unregister(t)}}class z{get log(){return this._log||(this._log=U.for(this)),this._log}constructor(){}}class J extends z{get log(){return super.log.for(this,{filters:[]})}}const B="undefined"!=typeof globalThis&&"function"==typeof globalThis.performance?.now?()=>globalThis.performance.now():"undefined"!=typeof process&&"function"==typeof process.hrtime?.bigint?()=>{const t=process.hrtime.bigint();return Number(t)/1e6}:()=>Date.now();function W(t){const e=0>t?"-":"",r=Math.abs(t),n=Math.floor(r/36e5),o=Math.floor(r%36e5/6e4),s=Math.floor(r%6e4/1e3),i=Math.floor(r%1e3),a=(t,e)=>t.toString().padStart(e,"0");return`${e}${a(n,2)}:${a(o,2)}:${a(s,2)}.${a(i,3)}`}function Z(e=t.LogLevel.info,r=0,n=(...t)=>"called with "+t,o){return(t,s,i)=>{if(!i||"number"==typeof i)throw Error("Logging decoration only applies to methods");const a=t instanceof z?t.log.for(t[s]):U.for(t).for(t[s]),c=a[e].bind(a),l=i.value;return i.value=new Proxy(l,{apply(t,e,s){c(n(...s),r);try{const r=Reflect.apply(t,e,s);return r instanceof Promise?r.then(t=>(o&&c(o(void 0,t)),t)).catch(t=>{throw o&&a.error(o(t)),t}):(o&&c(o(void 0,r)),r)}catch(t){throw o&&a.error(o(t)),t}}}),i}}function q(){return(t,e,r)=>{if(!r)throw Error("final decorator can only be used on methods");return r?.configurable&&(r.configurable=!1),r}}class H extends J{constructor(t,e){super(),this.regexp=t,this.replacement=e}match(t){const e=this.regexp.exec(t);return this.regexp.lastIndex=0,e}filter(t,e,r){const n=this.log.for(this.filter);if(!this.match(e))return e;try{return e.replace(this.regexp,this.replacement)}catch(t){n.error("PatternFilter replacement error: "+t)}return""}}n.__decorate([q(),n.__metadata("design:type",Function),n.__metadata("design:paramtypes",[String]),n.__metadata("design:returntype",void 0)],H.prototype,"match",null);class G extends Error{constructor(t,e,r){if(e instanceof G)return e;super(`[${t}][${r}] ${e instanceof Error?e.message:e}`),this.code=r,e instanceof Error&&(this.stack=e.stack)}get message(){return`[${this.name}] ${this.code} | ${super.message.replaceAll(/\[.*?Error\]\[\d+\]\s/g,"")}`}toString(){return this.message}}t.BaseError=G,t.BrowserEnvKey=o,t.COMMIT="c700c07",t.DefaultLoggingConfig=g,t.DefaultPlaceholderWrappers=i,t.DefaultTheme=u,t.ENV_PATH_DELIMITER=s,t.Environment=C,t.FULL_VERSION="0.23.7-c700c07",t.LogFilter=J,t.LogParameterRegistry=f,t.LoggedClass=z,t.LoggedEnvironment=$,t.Logging=U,t.MiniLogger=D,t.NumericLogLevels=c,t.PACKAGE_NAME="@decaf-ts/logging",t.PatternFilter=H,t.ROOT_CONTEXT_SYMBOL=F,t.StopWatch=class{constructor(t=!1){this._startMs=null,this._elapsedMs=0,this._running=!1,this._laps=[],this._lastLapTotalMs=0,t&&this.start()}get running(){return this._running}get elapsedMs(){return this._running&&null!=this._startMs?this._elapsedMs+(B()-this._startMs):this._elapsedMs}start(){return this._running||(this._running=!0,this._startMs=B()),this}pause(){return this._running&&null!=this._startMs&&(this._elapsedMs+=B()-this._startMs,this._startMs=null,this._running=!1),this}resume(){return this._running||(this._running=!0,this._startMs=B()),this}stop(){return this.pause(),this._elapsedMs}reset(){const t=this._running;return this._startMs=t?B():null,this._elapsedMs=0,this._laps=[],this._lastLapTotalMs=0,this}lap(t){const e=this.elapsedMs,r=e-this._lastLapTotalMs,n={index:this._laps.length,label:t,ms:r,totalMs:e};return this._laps.push(n),this._lastLapTotalMs=e,n}get laps(){return this._laps}toString(){return W(this.elapsedMs)}toJSON(){return{running:this._running,elapsedMs:this.elapsedMs,laps:this._laps.slice()}}},t.VERSION="0.23.7",t.benchmark=()=>(t,e,r)=>{if(!r||"number"==typeof r)throw Error("benchmark decoration only applies to methods");const n=t instanceof z?t.log.for(t[e]):U.for(t).for(t[e]),o=r.value;return r.value=new Proxy(o,{apply(t,e,r){const o=B();try{const s=Reflect.apply(t,e,r);return s instanceof Promise?s.then(t=>(n.benchmark(`completed in ${B()-o}ms`),t)).catch(t=>{throw n.benchmark(`failed in ${B()-o}ms`),t}):(n.benchmark(`completed in ${B()-o}ms`),s)}catch(t){throw n.benchmark(`failed in ${B()-o}ms`),t}}}),r},t.compileLogPattern=h,t.debug=()=>Z(t.LogLevel.debug,0,(...t)=>"called with "+t,(t,e)=>t?"Failed with: "+t:e?"Completed with "+JSON.stringify(e):"completed"),t.escapeRegExp=k,t.final=q,t.formatMs=W,t.getObjectName=V,t.info=()=>Z(t.LogLevel.info),t.isBrowser=A,t.isClass=T,t.isFunction=I,t.isInstance=N,t.isMethod=K,t.log=Z,t.logParameterRegistry=w,t.now=B,t.padEnd=(t,e,r=" ")=>{if(1!==r.length)throw Error("Invalid character length for padding. must be one!");return t.padEnd(e,r)},t.patchPlaceholders=(t,e,r=i[0],n=i[1],o="g")=>E(t,Object.entries(e).reduce((t,[e,o])=>(t[`${r}${e}${n}`]=o,t),{}),o),t.patchString=E,t.renderPattern=y,t.sf=j,t.silly=()=>Z(t.LogLevel.silly),t.stringFormat=P,t.toCamelCase=t=>t.replace(/(?:^\w|[A-Z]|\b\w)/g,(t,e)=>0===e?t.toLowerCase():t.toUpperCase()).replace(/\s+/g,""),t.toENVFormat=O,t.toKebabCase=t=>t.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[\s_]+/g,"-").toLowerCase(),t.toPascalCase=t=>t.replace(/(?:^\w|[A-Z]|\b\w)/g,t=>t.toUpperCase()).replace(/\s+/g,""),t.toSnakeCase=_,t.trace=()=>Z(t.LogLevel.trace),t.verbose=(e=0)=>(e||(e=0),Z(t.LogLevel.verbose,e)),Object.keys(e).forEach(r=>{"default"===r||Object.prototype.hasOwnProperty.call(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:()=>e[r]})})},"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("styled-string-builder"),require("typed-object-accumulator"),require("tslib")):"function"==typeof define&&define.amd?define(["exports","styled-string-builder","typed-object-accumulator","tslib"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).logging={},t.styledStringBuilder,t.typedObjectAccumulator,t.tslib);
1
+ var t,e;t=this,e=function(t,e,r,n){"use strict";const o="ENV",s="__",i=["${","}"];var a;t.LogLevel=void 0,(a=t.LogLevel||(t.LogLevel={})).benchmark="benchmark",a.fatal="fatal",a.critical="critical",a.error="error",a.warn="warn",a.info="info",a.verbose="verbose",a.debug="debug",a.trace="trace",a.silly="silly";const c={benchmark:0,fatal:1,critical:2,error:3,warn:6,info:9,verbose:12,debug:15,trace:18,silly:21};var l;t.LoggingMode=void 0,(l=t.LoggingMode||(t.LoggingMode={})).RAW="raw",l.JSON="json";const u={app:{},separator:{},class:{fg:34},id:{fg:36},stack:{},timestamp:{},message:{error:{fg:31}},method:{},logLevel:{benchmark:{fg:32,style:["bold"]},fatal:{fg:31,style:["bold"]},critical:{fg:31,style:["bold"]},error:{fg:31,style:["bold"]},info:{fg:34,style:["bold"]},verbose:{fg:34,style:["bold"]},debug:{fg:33,style:["bold"]},trace:{fg:33,style:["bold"]},silly:{fg:33,style:["bold"]}}},g={env:"development",verbose:0,level:t.LogLevel.info,logLevel:!0,style:!1,filters:[],contextSeparator:".",separator:"-",timestamp:!0,timestampFormat:"HH:mm:ss.SSS",context:!0,meta:!0,format:t.LoggingMode.RAW,pattern:"{level} [{timestamp}] {app} {context} {separator} {message} {stack}",theme:u};class f{constructor(){this.descriptors=new Map}register(t){return this.descriptors.set(t.key,t),this}unregister(t){return this.descriptors.delete(t),this}get(t){return this.descriptors.get(t)}render(t,e){const r={},n=new Set;return e.forEach(e=>{if(n.has(e))return;n.add(e);const o=this.descriptors.get(e);if(!o)return;if(o.shouldInclude&&!o.shouldInclude(t))return;const s=o.render(t);if(void 0===s)return;const i=o.style?o.style(s,t):s;r[e]=i}),r}keys(){return Array.from(this.descriptors.keys())}}const p=new Map;function h(t){if(p.has(t))return p.get(t);const e=d(t||""),r=new Set,n=[];m(e,r,n);const o={pattern:t,segments:e,keys:n,includesMeta:r.has("meta")};return p.set(t,o),o}function y(t,e){return v(t.segments,e).text}function d(t){const e=[];let r=0;for(;r<t.length;){const n=t[r];if("["===n){const n=b(t,r,"[","]");if(-1===n){e.push({type:"literal",value:"["}),r++;continue}const o=t.slice(r+1,n);e.push({type:"optional",prefix:"[",suffix:"]",children:d(o)}),r=n+1;continue}if("{"===n){const n=t.indexOf("}",r+1);if(-1===n){e.push({type:"literal",value:"{"}),r++;continue}const o=t.slice(r+1,n).trim();e.push({type:"parameter",key:o}),r=n+1;continue}let o=r;for(;o<t.length&&"["!==t[o]&&"{"!==t[o];)o++;const s=t.slice(r,o);s.length&&e.push({type:"literal",value:s}),r=o}return e}function b(t,e,r,n){let o=0;for(let s=e;s<t.length;s++){const e=t[s];if(e===r)o++;else if(e===n&&(o--,0===o))return s}return-1}function m(t,e,r){for(const n of t)"parameter"===n.type&&(e.has(n.key)||(e.add(n.key),r.push(n.key))),"optional"===n.type&&m(n.children,e,r)}function v(t,e){const r=[];let n=!1;for(const o of t){const t=x(o,e);t.text.length&&r.push(t.text),n=n||t.hasValue}return{text:r.join(""),hasValue:n}}function x(t,e){if("literal"===t.type)return{text:t.value,hasValue:!1};if("parameter"===t.type){const r=e[t.key]??"";return{text:r,hasValue:r.length>0}}const r=v(t.children,e);return r.hasValue?{text:`${t.prefix}${r.text}${t.suffix}`,hasValue:!0}:{text:"",hasValue:!1}}const L=new f;L.register({key:"level",render(t){if(!1!==t.config.logLevel)return t.level.toUpperCase()},style:(t,e)=>e.applyTheme(t,"logLevel")}).register({key:"timestamp",shouldInclude:t=>!(!t.config.timestamp||!t.timestamp),render:t=>t.timestamp,style:(t,e)=>e.applyTheme(t,"timestamp")}).register({key:"app",shouldInclude:t=>!!t.app,render:t=>t.app,style:(t,e)=>e.applyTheme(t,"app")}).register({key:"context",shouldInclude:t=>!1!==t.config.context&&t.context.length>0,render(t){const e=t.config.contextSeparator||".";return t.context.join(e)},style:(t,e)=>e.applyTheme(t,"class")}).register({key:"separator",shouldInclude:t=>!!t.separator,render:t=>t.separator,style:(t,e)=>e.applyTheme(t,"separator")}).register({key:"message",render:t=>t.filteredMessage,style:(t,e)=>e.applyTheme(t,"message")}).register({key:"stack",shouldInclude:t=>!!t.stack,render:t=>t.stack,style:(t,e)=>e.applyTheme(t,"stack")}).register({key:"meta",shouldInclude:t=>!!t.metaString,render:t=>t.metaString}).register({key:"correlationId",shouldInclude:t=>!!t.correlationId,render:t=>t.correlationId,style:(t,e)=>e.applyTheme(t,"id")});const w=L;function E(t,e,r="g"){return Object.entries(e).forEach(([e,n])=>{const o=RegExp(k(e),r);t=t.replace(o,n)}),t}function O(t){return _(t).toUpperCase()}function _(t){return t.replace(/([a-z\d])([A-Z])/g,"$1_$2").replace(/[\s-]+/g,"_").toLowerCase()}function k(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function j(t,...e){if(e.length>1&&!e.every(t=>"string"==typeof t||"number"==typeof t))throw Error("Only string and number arguments are supported for multiple replacements.");if(1===e.length&&"object"==typeof e[0]){const r=e[0];return Object.entries(r).reduce((t,[e,r])=>t.replace(RegExp(`\\{${e}\\}`,"g"),()=>r),t)}return t.replace(/{(\d+)}/g,(t,r)=>void 0!==e[r]?e[r].toString():"undefined")}const P=j;function A(){return Object.getPrototypeOf(Object.getPrototypeOf(globalThis))!==Object.prototype}const R=Symbol("EnvironmentEmpty"),M=Symbol("EnvironmentModel"),S=/^[a-z][a-zA-Z0-9]*$/;class C extends r.ObjectAccumulator{static{this.factory=()=>new C}constructor(){super(),Object.defineProperty(this,M,{value:{},writable:!0,enumerable:!1,configurable:!1})}static isProxyableObject(t){if(!t||"object"!=typeof t)return!1;if(Array.isArray(t))return!0;const e=Object.getPrototypeOf(t);return e===Object.prototype||null===e}fromEnv(t){let e;return A()?e=globalThis[o]||{}:(e=globalThis.process.env,t=O(t)),this.parseEnvValue(e[t])}parseEnvValue(t){return C.parseRuntimeValue(t)}static parseRuntimeValue(t){if("string"!=typeof t)return t;if("true"===t)return!0;if("false"===t)return!1;const e=t.trim();return/^-?\d+(\.\d+)?$/.test(e)?Number(e):t}expand(t){Object.entries(t).forEach(([t,e])=>{C.mergeModel(this[M],t,e),Object.defineProperty(this,t,{get:()=>{const r=this.fromEnv(t);return void 0!==r?r:e&&"object"==typeof e?C.buildEnvProxy(e,[t]):""===e?R:e},set:t=>{e=t},configurable:!0,enumerable:!0})})}orThrow(){const t=this[M],e=t=>void 0!==t?this.parseEnvValue(t):void 0,r=(t,e=!1)=>C.missingEnvError(t,e),n=(t,o)=>{const s={get(s,i){if(i===Symbol.toPrimitive)return()=>C.buildEnvKey(o);if("toString"===i)return()=>C.buildEnvKey(o);if("valueOf"===i)return()=>C.buildEnvKey(o);if("symbol"==typeof i)return;if("toJSON"===i)return;if("then"===i)return;if("constructor"===i)return Object;if(Array.isArray(t)&&"length"===i)return t.length;if(Array.isArray(t)&&i in Array.prototype){const e=Reflect.get(t,i,t);return"function"==typeof e?e.bind(t):e}const a=[...o,i],{key:c,value:l}=C.readRuntimeForPath(a);if("string"==typeof l&&0===l.length)throw r(c,!0);const u=e(l);if(void 0!==u){if("string"==typeof u&&0===u.length)throw r(c,!0);return u}if(!t||!Object.prototype.hasOwnProperty.call(t,i))throw r(c);const g=t[i];if(void 0!==g){if(""===g)throw r(c);return C.isProxyableObject(g)?n(g,a):g}},ownKeys:()=>t?Reflect.ownKeys(t):[],getOwnPropertyDescriptor(e,r){if(t)return Object.prototype.hasOwnProperty.call(t,r)?{enumerable:!0,configurable:!0}:void 0}};return new Proxy(Array.isArray(t)?[]:{},s)};return new Proxy(this,{get(o,s,i){if("string"!=typeof s)return Reflect.get(o,s,i);if(!Object.prototype.hasOwnProperty.call(t,s))return Reflect.get(o,s,i);const{key:a,value:c}=C.readRuntimeForPath([s]);if("string"==typeof c&&0===c.length)throw r(a,!0);const l=e(c);if(void 0!==l){if("string"==typeof l&&0===l.length)throw r(a,!0);return l}const u=t[s];if(C.isProxyableObject(u))return n(u,[s]);if(void 0===u)return Reflect.get(o,s,i);const g=Reflect.get(o,s);if(void 0===g||""===g)throw r(a,""===g);return g}})}static instance(...t){if(!C._instance){const e=C.factory(...t),r=new Proxy(e,{get(t,e,r){const n=Reflect.get(t,e,r);if(n!==R&&("string"!=typeof e||!Object.prototype.hasOwnProperty.call(t,e)||void 0!==n)){if(void 0!==n)return n;if("string"==typeof e){if("app"===e)return;return C.buildEnvProxy(void 0,[e])}return n}}});C._instance=r}return C._instance}accumulate(t){return super.accumulate(t),this}static accumulate(t){const e=C.instance();return Object.keys(e).forEach(t=>{const r=Object.getOwnPropertyDescriptor(e,t);r&&r.configurable&&r.enumerable&&Object.defineProperty(e,t,{...r,enumerable:!1})}),e.accumulate(t),e}static get(t){return C._instance.get(t)}static formatEnvSegment(t){return S.test(t)?O(t):t.toUpperCase()}static buildEnvKey(t){return t.map(t=>C.formatEnvSegment(t)).join(s)}static buildRawKey(t){return t.join(s)}static readRuntimeForPath(t){const e=C.buildEnvKey(t),r=C.buildRawKey(t),n=C.readRuntimeEnv(e);if(void 0!==n)return{key:e,value:n};if(r!==e){const t=C.readRuntimeEnv(r);if(void 0!==t)return{key:r,value:t}}return{key:e,value:void 0}}static runtimeEnv(){return A()?globalThis[o]:globalThis?.process?.env}static getRuntimeChildKeys(t){const e=C.runtimeEnv();if(!e)return[];const r=[C.buildEnvKey(t),C.buildRawKey(t)],n=new Set;return Object.keys(e).forEach(t=>{r.forEach(e=>{if(!e)return;const r=`${e}${s}`;if(t.startsWith(r)){const e=t.slice(r.length).split(s)[0];e&&n.add(e)}})}),[...n]}static hasRuntimePath(t){const{value:e}=C.readRuntimeForPath(t);return void 0!==e||C.getRuntimeChildKeys(t).length>0}static buildEnvProxy(t,e){const r=t=>C.readRuntimeEnv(t),n=/^[0-9]+$/,o={get(o,s){if(s===Symbol.toPrimitive)return()=>C.buildEnvKey(e);if("toString"===s)return()=>C.buildEnvKey(e);if("valueOf"===s)return()=>C.buildEnvKey(e);if("symbol"==typeof s)return;if(Array.isArray(t)&&s in Array.prototype){const e=Reflect.get(t,s,t);return"function"==typeof e?e.bind(t):e}if(Array.isArray(t)&&"length"===s)return t.length;const i=[...e,s],a=C.buildEnvKey(i),c=C.buildRawKey(i);let l=r(a);if(void 0===l&&c!==a&&(l=r(c)),void 0!==l)return C.parseRuntimeValue(l);const u=!!t&&Object.prototype.hasOwnProperty.call(t,s),g=u?t[s]:void 0,f=C.hasRuntimePath(i);return Array.isArray(t)&&(t=>"string"==typeof t&&n.test(t))(s)?u?C.isProxyableObject(g)?C.buildEnvProxy(g,i):C.parseRuntimeValue(g):f?C.buildEnvProxy(void 0,i):void 0:g&&"object"==typeof g&&C.isProxyableObject(g)?C.buildEnvProxy(g,i):u&&""===g||u&&void 0===g?void 0:u?C.parseRuntimeValue(g):C.buildEnvProxy(void 0,i)},ownKeys(){const r=new Set;return t&&Reflect.ownKeys(t).forEach(t=>r.add(t)),C.getRuntimeChildKeys(e).forEach(t=>r.add(t)),[...r]},getOwnPropertyDescriptor:(r,n)=>t&&Object.prototype.hasOwnProperty.call(t,n)?Reflect.getOwnPropertyDescriptor(t,n):"string"==typeof n&&C.hasRuntimePath([...e,n])?{enumerable:!0,configurable:!0}:void 0};return new Proxy(Array.isArray(t)?[]:{},o)}static keys(t=!0){return C.instance().keys().map(e=>t?O(e):e)}static mergeModel(t,e,r){if(t){if(r&&"object"==typeof r&&!Array.isArray(r)){const n=t[e],o=n&&"object"==typeof n&&!Array.isArray(n)?n:{};return t[e]=o,void Object.entries(r).forEach(([t,e])=>{C.mergeModel(o,t,e)})}t[e]=r}}static readRuntimeEnv(t){if(A()){const e=globalThis[o];return e?e[t]:void 0}return globalThis?.process?.env?.[t]}static missingEnvError(t,e){return Error(`Environment variable ${t} is required but was ${e?"an empty string":"undefined"}.`)}}const $=C.accumulate(Object.assign({app:void 0},g,{env:(A()&&globalThis[o]?globalThis[o].NODE_ENV:globalThis.process.env.NODE_ENV)||"development"}));function T(t){if("function"!=typeof t)return!1;try{const e=Function.prototype.toString.call(t);if(/^\s*class[\s{]/.test(e))return!0}catch{}const e=Object.getOwnPropertyDescriptor(t,"prototype");if(!e||!e.value)return!1;if(!1===e.writable)return!0;const r=t.prototype;return!!Object.prototype.hasOwnProperty.call(r,"constructor")&&Object.getOwnPropertyNames(r).filter(t=>"constructor"!==t).length>0}function I(t){return"function"==typeof t&&!T(t)}function K(t){if(!I(t))return!1;const e=Object.getOwnPropertyDescriptor(t,"prototype");return!e||void 0===e.value}function N(t){if(null===t||"object"!=typeof t)return!1;const e=t.constructor;return!(!e||e===Object)&&T(e)}function V(t){if(null===t)return"null";if(void 0===t)return"undefined";if("string"==typeof t)return t;if(T(t))return t.name||"AnonymousClass";if(N(t)){const e=t.toString;if("function"==typeof e&&e!==Object.prototype.toString)try{const r=e.call(t);if("string"==typeof r&&r.length)return r}catch{}const r=t.constructor;return r&&r.name?r.name:"AnonymousInstance"}if(K(t)||I(t)){const e=t;return e.name?e.name:"anonymous"}if("object"==typeof t){const e=Object.prototype.toString.call(t),r=/^\[object ([^\]]+)\]$/.exec(e);return r?.[1]?r[1]:"Object"}return typeof t}const F=Symbol("MiniLoggerRootContext");class D{constructor(t,e,r=[]){this.conf=e,this.baseContext=Array.isArray(r)?[...r]:[],t&&this.baseContext.push(t),this.context=[...this.baseContext],this[F]=[...this.baseContext]}config(t){return this.conf&&t in this.conf?this.conf[t]:U.getConfig()[t]}for(t,e,...r){let n,o=e;const s=Array.isArray(this.context)?[...this.context]:"string"==typeof this.context&&this.context?[this.context]:[],i=this[F],a=Array.isArray(i)?[...i]:Array.isArray(this.baseContext)?[...this.baseContext]:[];"string"==typeof t?n=t:void 0!==t&&(T(t)||N(t)||I(t)?n=V(t):!o&&t&&"object"==typeof t&&(o=t));let c=n?[...s,n]:[...s];return new Proxy(this,{get:(t,e,r)=>{const n=Reflect.get(t,e,r);return"config"===e?new Proxy(this.config,{apply:(t,e,n)=>{const[s]=n;return o&&void 0!==s&&s in o?o[s]:Reflect.apply(t,r,n)},get:(t,e)=>o&&e in o?o[e]:Reflect.get(t,e,r)}):"clear"===e?()=>(c=[...a],r):"context"===e?c:"root"===e?[...a]:e===F?a:"for"===e?(...e)=>{if(o){const t=e[0];"string"==typeof t||T(t)||N(t)||I(t)?e[1]={...o,...e[1]||{}}:t&&"object"==typeof t&&(e[0]={...o,...t})}const r=Array.isArray(t.context)?[...t.context]:"string"==typeof t.context&&t.context?[t.context]:[];t.context=[...c];try{return t.for.apply(t,e)}finally{t.context=r}}:"getConfigSnapshot"===e?()=>{const e=t.getConfigSnapshot();return o&&Object.assign(e,o),e}:n}})}getConfigSnapshot(){return{...U.getConfig(),...this.conf||{}}}getContextSegments(){return Array.isArray(this.context)?[...this.context]:"string"==typeof this.context&&this.context?[this.context]:[]}resolveFilters(t){const e=t.filters||[];return Array.isArray(e)?e.filter(t=>"object"==typeof t&&null!==t&&"function"==typeof t.filter):[]}applyFilters(t,e,r){const n=this.resolveFilters(r);return n.length?n.reduce((t,n)=>{try{const o=n.filter(r,t,[...e]);return"string"==typeof o?o:t}catch{return t}},t):t}createLog(t,e,r,n){const o=!!this.config("style"),s=this.config("separator"),i=U.getConfig().app,a=this.config("timestamp")?(new Date).toISOString():void 0,c=this.getConfigSnapshot(),l=this.getContextSegments(),u="string"==typeof e?e:e instanceof Error?e.message:e+"",g=this.applyFilters(u,l,c),f=this.config("meta")&&n?n:void 0,p=f?this.formatMeta(f):void 0,d=p?this.applyFilters(p,l,c):void 0,b=this.config("correlationId"),m=null!=b?b+"":void 0;let v,x;if(r||e instanceof Error){const n=r||e;n.stack&&(x="string"==typeof e?g:n.message,v=` | ${x} - Stack trace:\n${o?U.theme(n.stack,"stack",t):n.stack}`)}const L={config:c,level:t,context:l,timestamp:a,app:"string"==typeof i&&i.length?i:void 0,separator:s,correlationId:m,rawMessage:u,filteredMessage:g,meta:f,metaString:d,stack:v,stackLabel:x,applyTheme:(e,r)=>o?U.theme(e,r,t):e},E=this.config("pattern"),O=c.pattern||"",_=h(E.length?E:O),k=w.render(L,_.keys);switch(this.config("format")){case"json":{const t=w.render(L,w.keys()),e={};return Object.entries(t).forEach(([t,r])=>{"meta"!==t&&(e[t]=r)}),L.meta&&(e.meta=L.meta),JSON.stringify(e)}case"raw":{let t=this.normalizePatternSpacing(y(_,k));return!_.includesMeta&&d&&(t=t?`${t} ${d}`:d),t}default:throw Error("Unsupported logging format: "+this.config("format"))}}formatMeta(t){try{return JSON.stringify(t)}catch(e){return t+""}}normalizePatternSpacing(t){return t.replace(/[ \t]{2,}/g," ").replace(/^[ \t]+|[ \t]+$/g,"")}log(e,r,n,o){const s=this.config("level");if(c[e]>c[s])return;let i;switch(e){case t.LogLevel.benchmark:i=console.log;break;case t.LogLevel.fatal:case t.LogLevel.critical:case t.LogLevel.error:i=console.error;break;case t.LogLevel.info:case t.LogLevel.verbose:i=console.log;break;case t.LogLevel.debug:i=console.debug;break;case t.LogLevel.trace:i=console.trace;break;case t.LogLevel.warn:i=console.warn;break;case t.LogLevel.silly:i=console.debug;break;default:throw Error("Invalid log level")}i(this.createLog(e,r,n,o))}benchmark(e,r){this.log(t.LogLevel.benchmark,e,void 0,r)}fatal(e,r,n){let o,s;r instanceof Error?(o=r,s=n):s=r,this.log(t.LogLevel.fatal,e,o,s)}critical(e,r,n){let o,s;r instanceof Error?(o=r,s=n):s=r,this.log(t.LogLevel.critical,e,o,s)}silly(e,r=0,n){const o="number"==typeof r?r:0,s="number"==typeof r?n:r;this.config("verbose")<o||this.log(t.LogLevel.silly,e,void 0,s)}verbose(e,r=0,n){const o="number"==typeof r?r:0,s="number"==typeof r?n:r;this.config("verbose")<o||this.log(t.LogLevel.verbose,e,void 0,s)}info(e,r){this.log(t.LogLevel.info,e,void 0,r)}debug(e,r){this.log(t.LogLevel.debug,e,void 0,r)}error(e,r,n){let o,s;r instanceof Error?(o=r,s=n):s=r,this.log(t.LogLevel.error,e,o,s)}warn(e,r){this.log(t.LogLevel.warn,e,void 0,r)}trace(e,r){this.log(t.LogLevel.trace,e,void 0,r)}setConfig(t){this.conf={...this.conf||{},...t}}get root(){return[...this.baseContext]}clear(){return this.context=[...this.baseContext],this}}class U{static{this._factory=(t,e)=>{const r="string"==typeof $.app?[$.app]:[];return new D(t,e,r)}}static{this._config=$}constructor(){}static setFactory(t){U._factory=t,this.global=void 0}static setConfig(t){Object.entries(t).forEach(([t,e])=>{this._config[t]=e})}static getConfig(){return this._config}static get(){return this.ensureRoot()}static verbose(t,e=0,r){return this.get().verbose(t,e,r)}static info(t,e){return this.get().info(t,e)}static trace(t,e){return this.get().trace(t,e)}static debug(t,e){return this.get().debug(t,e)}static benchmark(t,e){return this.get().benchmark(t,e)}static fatal(t,e,r){return this.get().fatal(t,e,r)}static critical(t,e,r){return this.get().critical(t,e,r)}static silly(t,e=0,r){return this.get().silly(t,e,r)}static warn(t,e){return this.get().warn(t,e)}static error(t,e,r){return this.get().error(t,e,r)}static for(t,e,...r){const n=void 0!==e?[t,e]:[t];return(this.global?this.global:this.ensureRoot(r)).for(...n)}static because(t,e){let r=this.ensureRoot().for(t,this._config);return e&&(r=r.for(e)),r}static baseContext(){const t=this._config.app;return"string"==typeof t&&t.length?[t]:[]}static attachRootContext(t){const e=t.root&&Array.isArray(t.root)?[...t.root]:this.baseContext();return(!t.context||Array.isArray(t.context)&&0===t.context.length)&&(t.context=[...e]),t[F]=[...e],t}static ensureRoot(t=[]){if(!this.global){const e=this._factory(void 0,void 0,...t);this.global=this.attachRootContext(e)}return this.global}static theme(r,n,o,s=u){if(!this._config.style)return r;const i=s[n];if(!i||!Object.keys(i).length)return r;let a=i;const c=Object.assign({},t.LogLevel);return Object.keys(i)[0]in c&&(a=i[o]||{}),Object.keys(a).reduce((t,r)=>{const n=a[r];return n?((t,r,n)=>{try{const o=t;let s=e.style(o);function i(t,r=!1){let i=r?s.background:s.foreground;if(!Array.isArray(t))return i.call(s,n);switch(t.length){case 1:return i=r?s.bgColor256:s.color256,i(t[0]);case 3:return i=r?s.bgRgb:s.rgb,s.rgb(t[0],t[1],t[2]);default:return e.style(o)}}function a(t){s="number"==typeof t?s.style(t):s[t]}switch(r){case"bg":case"fg":return i(n).text;case"style":return Array.isArray(n)?n.forEach(a):a(n),s.text;default:return o}}catch(c){return t}})(t,r,n):t},r)}static register(t){return w.register(t)}static unregister(t){return w.unregister(t)}}class z{get log(){return this._log||(this._log=U.for(this)),this._log}constructor(){}}class J extends z{get log(){return super.log.for(this,{filters:[]})}}const B="undefined"!=typeof globalThis&&"function"==typeof globalThis.performance?.now?()=>globalThis.performance.now():"undefined"!=typeof process&&"function"==typeof process.hrtime?.bigint?()=>{const t=process.hrtime.bigint();return Number(t)/1e6}:()=>Date.now();function W(t){const e=0>t?"-":"",r=Math.abs(t),n=Math.floor(r/36e5),o=Math.floor(r%36e5/6e4),s=Math.floor(r%6e4/1e3),i=Math.floor(r%1e3),a=(t,e)=>t.toString().padStart(e,"0");return`${e}${a(n,2)}:${a(o,2)}:${a(s,2)}.${a(i,3)}`}function Z(e=t.LogLevel.info,r=0,n=(...t)=>"called with "+t,o){return(t,s,i)=>{if(!i||"number"==typeof i)throw Error("Logging decoration only applies to methods");const a=t instanceof z?t.log.for(t[s]):U.for(t).for(t[s]),c=a[e].bind(a),l=i.value;return i.value=new Proxy(l,{apply(t,e,s){c(n(...s),r);try{const r=Reflect.apply(t,e,s);return r instanceof Promise?r.then(t=>(o&&c(o(void 0,t)),t)).catch(t=>{throw o&&a.error(o(t)),t}):(o&&c(o(void 0,r)),r)}catch(t){throw o&&a.error(o(t)),t}}}),i}}function q(){return(t,e,r)=>{if(!r)throw Error("final decorator can only be used on methods");return r?.configurable&&(r.configurable=!1),r}}class H extends J{constructor(t,e){super(),this.regexp=t,this.replacement=e}match(t){const e=this.regexp.exec(t);return this.regexp.lastIndex=0,e}filter(t,e,r){const n=this.log.for(this.filter);if(!this.match(e))return e;try{return e.replace(this.regexp,this.replacement)}catch(t){n.error("PatternFilter replacement error: "+t)}return""}}n.__decorate([q(),n.__metadata("design:type",Function),n.__metadata("design:paramtypes",[String]),n.__metadata("design:returntype",void 0)],H.prototype,"match",null);class G extends Error{constructor(t,e,r){if(e instanceof G)return e;super(`[${t}][${r}] ${e instanceof Error?e.message:e}`),this.code=r,e instanceof Error&&(this.stack=e.stack)}get message(){return`[${this.name}] ${this.code} | ${super.message.replaceAll(/\[.*?Error\]\[\d+\]\s/g,"")}`}toString(){return this.message}}t.BaseError=G,t.BrowserEnvKey=o,t.COMMIT="be2441c",t.DefaultLoggingConfig=g,t.DefaultPlaceholderWrappers=i,t.DefaultTheme=u,t.ENV_PATH_DELIMITER=s,t.Environment=C,t.FULL_VERSION="0.24.2-be2441c",t.LogFilter=J,t.LogParameterRegistry=f,t.LoggedClass=z,t.LoggedEnvironment=$,t.Logging=U,t.MiniLogger=D,t.NumericLogLevels=c,t.PACKAGE_NAME="@decaf-ts/logging",t.PatternFilter=H,t.ROOT_CONTEXT_SYMBOL=F,t.StopWatch=class{constructor(t=!1){this._startMs=null,this._elapsedMs=0,this._running=!1,this._laps=[],this._lastLapTotalMs=0,t&&this.start()}get running(){return this._running}get elapsedMs(){return this._running&&null!=this._startMs?this._elapsedMs+(B()-this._startMs):this._elapsedMs}start(){return this._running||(this._running=!0,this._startMs=B()),this}pause(){return this._running&&null!=this._startMs&&(this._elapsedMs+=B()-this._startMs,this._startMs=null,this._running=!1),this}resume(){return this._running||(this._running=!0,this._startMs=B()),this}stop(){return this.pause(),this._elapsedMs}reset(){const t=this._running;return this._startMs=t?B():null,this._elapsedMs=0,this._laps=[],this._lastLapTotalMs=0,this}lap(t){const e=this.elapsedMs,r=e-this._lastLapTotalMs,n={index:this._laps.length,label:t,ms:r,totalMs:e};return this._laps.push(n),this._lastLapTotalMs=e,n}get laps(){return this._laps}toString(){return W(this.elapsedMs)}toJSON(){return{running:this._running,elapsedMs:this.elapsedMs,laps:this._laps.slice()}}},t.VERSION="0.24.2",t.benchmark=()=>(t,e,r)=>{if(!r||"number"==typeof r)throw Error("benchmark decoration only applies to methods");const n=t instanceof z?t.log.for(t[e]):U.for(t).for(t[e]),o=r.value;return r.value=new Proxy(o,{apply(t,e,r){const o=B();try{const s=Reflect.apply(t,e,r);return s instanceof Promise?s.then(t=>(n.benchmark(`completed in ${B()-o}ms`),t)).catch(t=>{throw n.benchmark(`failed in ${B()-o}ms`),t}):(n.benchmark(`completed in ${B()-o}ms`),s)}catch(t){throw n.benchmark(`failed in ${B()-o}ms`),t}}}),r},t.compileLogPattern=h,t.debug=()=>Z(t.LogLevel.debug,0,(...t)=>"called with "+t,(t,e)=>t?"Failed with: "+t:e?"Completed with "+JSON.stringify(e):"completed"),t.escapeRegExp=k,t.final=q,t.formatMs=W,t.getObjectName=V,t.info=()=>Z(t.LogLevel.info),t.isBrowser=A,t.isClass=T,t.isFunction=I,t.isInstance=N,t.isMethod=K,t.log=Z,t.logParameterRegistry=w,t.now=B,t.padEnd=(t,e,r=" ")=>{if(1!==r.length)throw Error("Invalid character length for padding. must be one!");return t.padEnd(e,r)},t.patchPlaceholders=(t,e,r=i[0],n=i[1],o="g")=>E(t,Object.entries(e).reduce((t,[e,o])=>(t[`${r}${e}${n}`]=o,t),{}),o),t.patchString=E,t.renderPattern=y,t.sf=j,t.silly=()=>Z(t.LogLevel.silly),t.stringFormat=P,t.toCamelCase=t=>t.replace(/(?:^\w|[A-Z]|\b\w)/g,(t,e)=>0===e?t.toLowerCase():t.toUpperCase()).replace(/\s+/g,""),t.toENVFormat=O,t.toKebabCase=t=>t.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[\s_]+/g,"-").toLowerCase(),t.toPascalCase=t=>t.replace(/(?:^\w|[A-Z]|\b\w)/g,t=>t.toUpperCase()).replace(/\s+/g,""),t.toSnakeCase=_,t.trace=()=>Z(t.LogLevel.trace),t.verbose=(e=0)=>(e||(e=0),Z(t.LogLevel.verbose,e)),Object.keys(e).forEach(r=>{"default"===r||Object.prototype.hasOwnProperty.call(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:()=>e[r]})})},"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("styled-string-builder"),require("typed-object-accumulator"),require("tslib")):"function"==typeof define&&define.amd?define(["exports","styled-string-builder","typed-object-accumulator","tslib"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).logging={},t.styledStringBuilder,t.typedObjectAccumulator,t.tslib);
2
2
  //# sourceMappingURL=logging.cjs.map
package/lib/cjs/index.cjs CHANGED
@@ -41,21 +41,21 @@ __exportStar(require("styled-string-builder"), exports);
41
41
  * @type {string}
42
42
  * @memberOf module:Logging
43
43
  */
44
- exports.VERSION = "0.23.7";
44
+ exports.VERSION = "0.24.2";
45
45
  /**
46
46
  * @description Represents the current commit hash of the module build.
47
47
  * @summary Stores the current git commit hash for the package. The build replaces
48
48
  * the placeholder with the actual commit hash at publish time.
49
49
  * @const COMMIT
50
50
  */
51
- exports.COMMIT = "c700c07";
51
+ exports.COMMIT = "be2441c";
52
52
  /**
53
53
  * @description Represents the full version string of the module.
54
54
  * @summary Stores the semver version and commit hash for the package.
55
55
  * The build replaces the placeholder with the actual `<version>-<commit>` value at publish time.
56
56
  * @const FULL_VERSION
57
57
  */
58
- exports.FULL_VERSION = "0.23.7-c700c07";
58
+ exports.FULL_VERSION = "0.24.2-be2441c";
59
59
  /**
60
60
  * @description Current package version string.
61
61
  * @summary Stores the package version for diagnostics and compatibility checks.
package/lib/esm/index.js CHANGED
@@ -24,21 +24,21 @@ export * from "styled-string-builder";
24
24
  * @type {string}
25
25
  * @memberOf module:Logging
26
26
  */
27
- export const VERSION = "0.23.7";
27
+ export const VERSION = "0.24.2";
28
28
  /**
29
29
  * @description Represents the current commit hash of the module build.
30
30
  * @summary Stores the current git commit hash for the package. The build replaces
31
31
  * the placeholder with the actual commit hash at publish time.
32
32
  * @const COMMIT
33
33
  */
34
- export const COMMIT = "c700c07";
34
+ export const COMMIT = "be2441c";
35
35
  /**
36
36
  * @description Represents the full version string of the module.
37
37
  * @summary Stores the semver version and commit hash for the package.
38
38
  * The build replaces the placeholder with the actual `<version>-<commit>` value at publish time.
39
39
  * @const FULL_VERSION
40
40
  */
41
- export const FULL_VERSION = "0.23.7-c700c07";
41
+ export const FULL_VERSION = "0.24.2-be2441c";
42
42
  /**
43
43
  * @description Current package version string.
44
44
  * @summary Stores the package version for diagnostics and compatibility checks.
@@ -31,14 +31,14 @@ export declare const VERSION: string;
31
31
  * the placeholder with the actual commit hash at publish time.
32
32
  * @const COMMIT
33
33
  */
34
- export declare const COMMIT = "c700c07";
34
+ export declare const COMMIT = "be2441c";
35
35
  /**
36
36
  * @description Represents the full version string of the module.
37
37
  * @summary Stores the semver version and commit hash for the package.
38
38
  * The build replaces the placeholder with the actual `<version>-<commit>` value at publish time.
39
39
  * @const FULL_VERSION
40
40
  */
41
- export declare const FULL_VERSION = "0.23.7-c700c07";
41
+ export declare const FULL_VERSION = "0.24.2-be2441c";
42
42
  /**
43
43
  * @description Current package version string.
44
44
  * @summary Stores the package version for diagnostics and compatibility checks.
@@ -31,14 +31,14 @@ export declare const VERSION: string;
31
31
  * the placeholder with the actual commit hash at publish time.
32
32
  * @const COMMIT
33
33
  */
34
- export declare const COMMIT = "c700c07";
34
+ export declare const COMMIT = "be2441c";
35
35
  /**
36
36
  * @description Represents the full version string of the module.
37
37
  * @summary Stores the semver version and commit hash for the package.
38
38
  * The build replaces the placeholder with the actual `<version>-<commit>` value at publish time.
39
39
  * @const FULL_VERSION
40
40
  */
41
- export declare const FULL_VERSION = "0.23.7-c700c07";
41
+ export declare const FULL_VERSION = "0.24.2-be2441c";
42
42
  /**
43
43
  * @description Current package version string.
44
44
  * @summary Stores the package version for diagnostics and compatibility checks.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decaf-ts/logging",
3
- "version": "0.24.0",
3
+ "version": "0.24.2",
4
4
  "description": "simple winston inspired wrapper for cross lib logging",
5
5
  "type": "module",
6
6
  "exports": {
@@ -69,6 +69,7 @@
69
69
  "repo:setup": "npm run codex -- \"$(cat ./workdocs/ai/repo-setup.md)\nbase_path is ./\"",
70
70
  "repo:doc": "npm run codex -- \"$(cat ./workdocs/ai/doc.md) $(cat ./workdocs/ai/bulk-docs.md)\nbase_path is ./\"",
71
71
  "repo:tests": "npm run codex -- \"$(cat ./workdocs/ai/bulk-tests.md)\nbase_path is ./ and coverage is 95%\"",
72
+ "prepare-it-tests": "echo \"prepare-it-tests: no infra to boot\"",
72
73
  "repo:notes": "npm run codex -- \"$(cat ./workdocs/ai/release-notes.md)\nbase_path is ./\"",
73
74
  "repo:readme": "npm run codex -- \"$(cat ./workdocs/ai/update-readme.md)\nbase_path is ./\"",
74
75
  "repo:pr": "npm run repo:doc && npm run repo:tests && npm run repo:notes && npm run repo:readme",