@virid/express 0.1.3 → 0.2.0

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/index.cjs CHANGED
@@ -2,39 +2,35 @@
2
2
  * @virid/express v0.1.3
3
3
  * Add express functionality to virid
4
4
  */
5
- var K=Object.defineProperty;var Rt=Object.getOwnPropertyDescriptor;var $t=Object.getOwnPropertyNames;var Tt=Object.prototype.hasOwnProperty;var Ht=(r,e,t)=>e in r?K(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var i=(r,e)=>K(r,"name",{value:e,configurable:!0});var Ot=(r,e)=>{for(var t in e)K(r,t,{get:e[t],enumerable:!0})},Vt=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of $t(e))!Tt.call(r,n)&&n!==t&&K(r,n,{get:()=>e[n],enumerable:!(s=Rt(e,n))||s.enumerable});return r};var Pt=r=>Vt(K({},"__esModule",{value:!0}),r);var y=(r,e,t)=>Ht(r,typeof e!="symbol"?e+"":e,t);var Rr={};Ot(Rr,{BadRequest:()=>Nt,BadRequestResponse:()=>oe,Body:()=>yr,ConflictResponse:()=>Ae,Cookies:()=>Mr,Created:()=>Dt,CreatedResponse:()=>ie,Ctx:()=>vr,CustomResponse:()=>_t,CustomResponseResponse:()=>he,ExpressPlugin:()=>Cr,Forbidden:()=>jt,ForbiddenResponse:()=>le,Headers:()=>xr,HttpContext:()=>X,HttpError:()=>k,HttpRequestMessage:()=>re,HttpResponse:()=>M,HttpRoute:()=>gr,HttpSystem:()=>mr,InternalServerError:()=>pe,InternalServerErrorResponse:()=>ue,NoContent:()=>Bt,NoContentResponse:()=>ae,NotFound:()=>Qt,NotFoundResponse:()=>de,Ok:()=>It,OkResponse:()=>ne,Params:()=>br,ParseBoolPipe:()=>Mt,ParseIntPipe:()=>xt,Query:()=>Sr,Req:()=>Er,Res:()=>wr,Stream:()=>Wt,StreamFile:()=>Ft,StreamFileResponse:()=>H,StreamResponse:()=>O,Unauthorized:()=>qt,UnauthorizedResponse:()=>ce,UnprocessableEntityResponse:()=>ke,addAutoPipe:()=>pr,getAutoPipe:()=>Me,parseRawCookie:()=>ze});module.exports=Pt(Rr);var St=require("@virid/core");var we=require("@virid/core");var R=require("@virid/core");var Ke=require("@virid/core");var Ce=class Ce{constructor(e,t,s,n,o){y(this,"id");y(this,"req");y(this,"res");y(this,"timestamp");y(this,"route");y(this,"rc",0);y(this,"isClosed",!1);this.id=e,this.req=t,this.res=s,this.timestamp=n,this.route=o}inc(){this.rc++}dec(){this.rc--,this.rc===0&&this.tryFinalize()}tryFinalize(){if(this.res.writableEnded||this.isClosed)return;this.isClosed=!0;let e=`[Virid Express] Request Orphaned: The connection was closed because all systems finished execution without sending a response.
5
+ var z=Object.defineProperty;var vt=Object.getOwnPropertyDescriptor;var St=Object.getOwnPropertyNames;var At=Object.prototype.hasOwnProperty;var bt=(r,e,t)=>e in r?z(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var i=(r,e)=>z(r,"name",{value:e,configurable:!0});var Rt=(r,e)=>{for(var t in e)z(r,t,{get:e[t],enumerable:!0})},kt=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of St(e))!At.call(r,n)&&n!==t&&z(r,n,{get:()=>e[n],enumerable:!(s=vt(e,n))||s.enumerable});return r};var $t=r=>kt(z({},"__esModule",{value:!0}),r);var y=(r,e,t)=>bt(r,typeof e!="symbol"?e+"":e,t);var Mr={};Rt(Mr,{BadRequest:()=>Ot,BadRequestResponse:()=>se,Body:()=>lr,ConflictResponse:()=>ve,Cookies:()=>ur,Created:()=>Ct,CreatedResponse:()=>te,Ctx:()=>fr,CustomResponse:()=>Dt,CustomResponseResponse:()=>ce,ExpressPlugin:()=>Er,Forbidden:()=>Pt,ForbiddenResponse:()=>ie,Headers:()=>dr,HttpContext:()=>Y,HttpError:()=>R,HttpRequestMessage:()=>J,HttpResponse:()=>E,HttpRoute:()=>or,HttpSystem:()=>cr,InternalServerError:()=>le,InternalServerErrorResponse:()=>oe,NoContent:()=>Ht,NoContentResponse:()=>re,NotFound:()=>It,NotFoundResponse:()=>ae,Ok:()=>Tt,OkResponse:()=>ee,Params:()=>mr,ParseBoolPipe:()=>ht,ParseIntPipe:()=>pt,Query:()=>gr,Req:()=>pr,Res:()=>hr,Stream:()=>Nt,StreamFile:()=>Bt,StreamFileResponse:()=>C,StreamResponse:()=>H,Unauthorized:()=>Vt,UnauthorizedResponse:()=>ne,UnprocessableEntityResponse:()=>Se,addAutoPipe:()=>ir,getAutoPipe:()=>me,parseRawCookie:()=>We});module.exports=$t(Mr);var yt=require("@virid/core");var xe=require("@virid/core");var $=require("@virid/core");var Le=require("@virid/core");var Ae=class Ae{constructor(e,t,s,n,o){y(this,"id");y(this,"req");y(this,"res");y(this,"timestamp");y(this,"route");y(this,"rc",0);y(this,"isClosed",!1);this.id=e,this.req=t,this.res=s,this.timestamp=n,this.route=o}inc(){this.rc++}dec(){this.rc--,this.rc===0&&this.tryFinalize()}tryFinalize(){if(this.res.writableEnded||this.isClosed)return;this.isClosed=!0;let e=`[Virid Express] Request Orphaned: The connection was closed because all systems finished execution without sending a response.
6
6
  Route: ${this.route}
7
- Uptime: ${Date.now()-this.timestamp}ms`;Ke.MessageWriter.error(new Error(e)),this.res.headersSent?this.res.end():this.res.status(500).json({error:"Internal Logic Error",message:"Request processed but no response was returned by any system."})}};i(Ce,"HttpContext");var X=Ce,Re=class Re{constructor(e,t=null,s={}){y(this,"status");y(this,"data");y(this,"headers");this.status=e,this.data=t,this.headers=s}};i(Re,"HttpResponse");var M=Re,$e=class $e extends M{constructor(e,t={}){super(200,e,t)}};i($e,"OkResponse");var ne=$e,Te=class Te extends M{constructor(e,t={}){super(201,e,t)}};i(Te,"CreatedResponse");var ie=Te,He=class He extends M{constructor(){super(204,null)}};i(He,"NoContentResponse");var ae=He,Oe=class Oe extends M{constructor(e="Bad Request"){super(400,{error:e})}};i(Oe,"BadRequestResponse");var oe=Oe,Ve=class Ve extends M{constructor(e="Unauthorized"){super(401,{error:e})}};i(Ve,"UnauthorizedResponse");var ce=Ve,Pe=class Pe extends M{constructor(e="Forbidden"){super(403,{error:e})}};i(Pe,"ForbiddenResponse");var le=Pe,Ie=class Ie extends M{constructor(e="Not Found"){super(404,{error:e})}};i(Ie,"NotFoundResponse");var de=Ie,De=class De extends M{constructor(e="Conflict"){super(409,{error:e})}};i(De,"ConflictResponse");var Ae=De,Be=class Be extends M{constructor(e){super(422,{errors:e})}};i(Be,"UnprocessableEntityResponse");var ke=Be,Ne=class Ne extends M{constructor(e="Internal Server Error"){super(500,{error:e})}};i(Ne,"InternalServerErrorResponse");var ue=Ne,qe=class qe extends M{constructor(e,t,s={}){super(e,t,s)}};i(qe,"CustomResponseResponse");var he=qe,je=class je extends M{constructor(t,s={dotfiles:"allow"}){super(206,s);y(this,"filePath");y(this,"options");this.filePath=t,this.options=s}};i(je,"StreamFileResponse");var H=je,Qe=class Qe extends M{constructor(t,s={}){super(s.status,{},s.headers);y(this,"stream");y(this,"options");this.stream=t,this.options=s}};i(Qe,"StreamResponse");var O=Qe,It=i((r,e={})=>new ne(r,e),"Ok"),Dt=i((r,e={})=>new ie(r,e),"Created"),Bt=i(()=>new ae,"NoContent"),Nt=i((r="Bad Request")=>new oe(r),"BadRequest"),qt=i((r="Unauthorized")=>new ce(r),"Unauthorized"),jt=i((r="Forbidden")=>new le(r),"Forbidden"),Qt=i((r="Not Found")=>new de(r),"NotFound"),pe=i((r="Internal Server Error")=>new ue(r),"InternalServerError"),_t=i((r,e,t={})=>new he(r,e,t),"CustomResponse"),Ft=i((r,e)=>new H(r,e),"StreamFile"),Wt=i((r,e)=>new O(r,e),"Stream"),_e=class _e extends Error{constructor(t,s){super(s);y(this,"status");y(this,"message");this.status=t,this.message=s}};i(_e,"HttpError");var k=_e;var v=new Map;function V(r,e){if(!r){e.dec();return}(Array.isArray(r)?r:[r]).forEach(s=>{s instanceof M?Ut(s,e):s instanceof k?(e.res.status(s.status).json(s.message),v.delete(e.id)):s instanceof R.BaseMessage?R.MessageWriter.write(s):R.MessageWriter.warn(`[Virid Express] Invalid Return Type: ${typeof s}. Expected HttpResponse or Message.`)}),e.dec()}i(V,"handleResult");function Ut(r,e){let{res:t}=e;if(r.headers&&Object.entries(r.headers).forEach(([s,n])=>t.setHeader(s,n)),r.status&&t.status(r.status),r instanceof H){e.inc(),t.sendFile(r.filePath,r.options,s=>{t.headersSent||R.MessageWriter.error(s,`[Virid Express] SteamFile Error: Path: ${r.filePath}`),e.res.end(),v.delete(e.id),e.isClosed=!0,e.dec()});return}if(r instanceof O){let{stream:s}=r;e.inc(),s.pipe(t);let n=i(()=>{v.has(e.id)&&(e.res.end(),v.delete(e.id),e.isClosed=!0,e.dec())},"cleanup");s.on("end",n),s.on("error",o=>{t.headersSent||R.MessageWriter.error(o,"[Virid Express] Stream Error"),n()}),s.on("close",n);return}t.status(r.status).json(r.data),v.delete(e.id)}i(Ut,"handleHttpResponse");var et=Object.defineProperty,Lt=i((r,e,t)=>e in r?et(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,"pe"),c=i((r,e)=>et(r,"name",{value:e,configurable:!0}),"o"),l=i((r,e,t)=>Lt(r,typeof e!="symbol"?e+"":e,t),"i"),P,tt=(P=class{static send(...e){p.write(this,...e)}},i(P,"L"),P);c(tt,"BaseMessage");var ye=tt,I,rt=(I=class extends ye{constructor(){super(),l(this,"__kind","SingleMessage")}},i(I,"W"),I);c(rt,"SingleMessage");var xe=rt,D,st=(D=class extends ye{constructor(){super(),l(this,"__kind","EventMessage")}},i(D,"F"),D);c(st,"EventMessage");var $=st,B,nt=(B=class extends ${constructor(e,t){super(),l(this,"error"),l(this,"context"),this.error=e,this.context=t}},i(B,"Q"),B);c(nt,"ErrorMessage");var Ue=nt,N,it=(N=class extends ${constructor(e){super(),l(this,"context"),this.context=e}},i(N,"z"),N);c(it,"WarnMessage");var Le=it,q,at=(q=class extends ${constructor(e){super(),l(this,"context"),this.context=e}},i(q,"U"),q);c(at,"InfoMessage");var Ge=at,j,ot=(j=class extends ${constructor(e,t,s){super(),l(this,"ComponentClass"),l(this,"recipe"),l(this,"label"),this.ComponentClass=e,this.recipe=t,this.label=s}},i(j,"J"),j);c(ot,"AtomicModifyMessage");var Xe=ot,Fe=new Map,We=new Map,Q,Gt=(Q=class extends xe{constructor(){super()}static send(...e){let t=new this(...e),s=t.debounceTime,n=Fe.get(this);if(n){t.debounceCallback(n);let a=We.get(this);a&&clearTimeout(a)}Fe.set(this,t);let o=setTimeout(()=>{Fe.delete(this),We.delete(this)},s);We.set(this,o),p.write(t)}debounceCallback(e){}},i(Q,"Y"),Q);c(Gt,"DebounceMessage");var fe=null;function ct(r){fe=r}i(ct,"ce");c(ct,"activateInstance");var zt=new Proxy({},{get(r,e){return e==="dispatch"?t=>{if(!fe){console.error(`[Virid] Message dispatched before system init: ${t.constructor.name}`);return}return fe.dispatch(t)}:Reflect.get(fe||{},e)}}),_,lt=(_=class{static write(e,...t){let s=typeof e=="function"?new e(...t):e;zt.dispatch(s)}static error(e,t=""){this.write(new Ue(e,t))}static warn(e){this.write(new Le(e))}static info(e){this.write(new Ge(e))}},i(_,"q"),_);c(lt,"MessageWriter");var p=lt,F,dt=(F=class{constructor(e){l(this,"dirtySignalTypes",new Set),l(this,"eventQueue",[]),l(this,"isRunning",!1),l(this,"globalTick",0),l(this,"internalDepth",0),l(this,"eventHub"),l(this,"tickPayload",{}),l(this,"beforeExecuteHooks",[]),l(this,"afterExecuteHooks",[]),l(this,"beforeTickHooks",[]),l(this,"afterTickHooks",[]),this.eventHub=e}addBeforeExecute(e,t,s){s?this.beforeExecuteHooks.unshift({type:e,handler:t}):this.beforeExecuteHooks.push({type:e,handler:t})}addAfterExecute(e,t,s){s?this.afterExecuteHooks.unshift({type:e,handler:t}):this.afterExecuteHooks.push({type:e,handler:t})}addBeforeTick(e,t){t?this.beforeTickHooks.unshift(e):this.beforeTickHooks.push(e)}addAfterTick(e,t){t?this.afterTickHooks.unshift(e):this.afterTickHooks.push(e)}markDirty(e){e instanceof $?this.eventQueue.push(e):e instanceof xe&&this.dirtySignalTypes.add(e.constructor)}tick(e){if(!(this.isRunning||this.dirtySignalTypes.size===0&&this.eventQueue.length===0)){if(this.internalDepth>100){this.internalDepth=0,this.dirtySignalTypes.clear(),this.eventQueue=[],this.eventHub.reset(),p.error(new Error("[Virid Dispatcher] Deadlock: Recursive loop detected \u{1F4A5}."));return}this.isRunning=!0,this.internalDepth++,queueMicrotask(()=>{let t,s;try{this.internalDepth==0&&(this.tickPayload={},this.executeTickHooks(this.beforeTickHooks));let n=this.prepareSnapshot();t=n.signalSnapshot,s=n.eventSnapshot;let o=this.collectTasks(s,t,e);this.executeTasks(o)}catch(n){p.error(n,"[Virid Dispatcher] Unhandled Error")}finally{t&&s&&this.clear(s,t),this.isRunning=!1,this.dirtySignalTypes.size>0||this.eventQueue.length>0?this.tick(e):(this.executeTickHooks(this.afterTickHooks),this.globalTick++,this.internalDepth=0)}})}}collectTasks(e,t,s){let n=[];for(let a of e)(s.get(a.constructor)||[]).forEach(d=>{n.push(new Je(d.fn,d.priority,a,{context:d.fn.systemContext,tick:this.globalTick,payload:{}}))});let o=new Set;for(let a of t)(s.get(a)||[]).forEach(d=>{o.has(d.fn)||(n.push(new Je(d.fn,d.priority,this.eventHub.peekSignal(a),{context:d.fn.systemContext,tick:this.globalTick,payload:{}})),o.add(d.fn))});return n}executeTasks(e){e.sort((t,s)=>s.priority-t.priority);for(let t of e)try{let s=t.execute(this.beforeExecuteHooks,this.afterExecuteHooks);s instanceof Promise&&s.catch(n=>p.error(n,`[Virid Dispatcher]: Async System Error.
7
+ Uptime: ${Date.now()-this.timestamp}ms`;Le.MessageWriter.error(new Error(e)),this.res.headersSent?this.res.end():this.res.status(500).json({error:"Internal Logic Error",message:"Request processed but no response was returned by any system."})}};i(Ae,"HttpContext");var Y=Ae,be=class be{constructor(e,t=null,s={}){y(this,"status");y(this,"data");y(this,"headers");this.status=e,this.data=t,this.headers=s}};i(be,"HttpResponse");var E=be,Re=class Re extends E{constructor(e,t={}){super(200,e,t)}};i(Re,"OkResponse");var ee=Re,ke=class ke extends E{constructor(e,t={}){super(201,e,t)}};i(ke,"CreatedResponse");var te=ke,$e=class $e extends E{constructor(){super(204,null)}};i($e,"NoContentResponse");var re=$e,Te=class Te extends E{constructor(e="Bad Request"){super(400,{error:e})}};i(Te,"BadRequestResponse");var se=Te,Ce=class Ce extends E{constructor(e="Unauthorized"){super(401,{error:e})}};i(Ce,"UnauthorizedResponse");var ne=Ce,He=class He extends E{constructor(e="Forbidden"){super(403,{error:e})}};i(He,"ForbiddenResponse");var ie=He,Oe=class Oe extends E{constructor(e="Not Found"){super(404,{error:e})}};i(Oe,"NotFoundResponse");var ae=Oe,Ve=class Ve extends E{constructor(e="Conflict"){super(409,{error:e})}};i(Ve,"ConflictResponse");var ve=Ve,Pe=class Pe extends E{constructor(e){super(422,{errors:e})}};i(Pe,"UnprocessableEntityResponse");var Se=Pe,Ie=class Ie extends E{constructor(e="Internal Server Error"){super(500,{error:e})}};i(Ie,"InternalServerErrorResponse");var oe=Ie,De=class De extends E{constructor(e,t,s={}){super(e,t,s)}};i(De,"CustomResponseResponse");var ce=De,Be=class Be extends E{constructor(t,s={dotfiles:"allow"}){super(206,s);y(this,"filePath");y(this,"options");this.filePath=t,this.options=s}};i(Be,"StreamFileResponse");var C=Be,Ne=class Ne extends E{constructor(t,s={}){super(s.status,{},s.headers);y(this,"stream");y(this,"options");this.stream=t,this.options=s}};i(Ne,"StreamResponse");var H=Ne,Tt=i((r,e={})=>new ee(r,e),"Ok"),Ct=i((r,e={})=>new te(r,e),"Created"),Ht=i(()=>new re,"NoContent"),Ot=i((r="Bad Request")=>new se(r),"BadRequest"),Vt=i((r="Unauthorized")=>new ne(r),"Unauthorized"),Pt=i((r="Forbidden")=>new ie(r),"Forbidden"),It=i((r="Not Found")=>new ae(r),"NotFound"),le=i((r="Internal Server Error")=>new oe(r),"InternalServerError"),Dt=i((r,e,t={})=>new ce(r,e,t),"CustomResponse"),Bt=i((r,e)=>new C(r,e),"StreamFile"),Nt=i((r,e)=>new H(r,e),"Stream"),qe=class qe extends Error{constructor(t,s){super(s);y(this,"status");y(this,"message");this.status=t,this.message=s}};i(qe,"HttpError");var R=qe;var v=new Map;function O(r,e){if(!r){e.dec();return}(Array.isArray(r)?r:[r]).forEach(s=>{s instanceof E?qt(s,e):s instanceof R?(e.res.status(s.status).json(s.message),v.delete(e.id)):s instanceof $.BaseMessage?$.MessageWriter.write(s):$.MessageWriter.warn(`[Virid Express] Invalid Return Type: ${typeof s}. Expected HttpResponse or Message.`)}),e.dec()}i(O,"handleResult");function qt(r,e){let{res:t}=e;if(r.headers&&Object.entries(r.headers).forEach(([s,n])=>t.setHeader(s,n)),r.status&&t.status(r.status),r instanceof C){e.inc(),t.sendFile(r.filePath,r.options,s=>{t.headersSent||$.MessageWriter.error(s,`[Virid Express] SteamFile Error: Path: ${r.filePath}`),e.res.end(),v.delete(e.id),e.isClosed=!0,e.dec()});return}if(r instanceof H){let{stream:s}=r;e.inc(),s.pipe(t);let n=i(()=>{v.has(e.id)&&(e.res.end(),v.delete(e.id),e.isClosed=!0,e.dec())},"cleanup");s.on("end",n),s.on("error",o=>{t.headersSent||$.MessageWriter.error(o,"[Virid Express] Stream Error"),n()}),s.on("close",n);return}t.status(r.status).json(r.data),v.delete(e.id)}i(qt,"handleHttpResponse");var Ye=Object.defineProperty,_t=i((r,e,t)=>e in r?Ye(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,"ce"),c=i((r,e)=>Ye(r,"name",{value:e,configurable:!0}),"o"),l=i((r,e,t)=>_t(r,typeof e!="symbol"?e+"":e,t),"i"),V,Ke=(V=class{static send(...e){m.write(this,...e)}},i(V,"N"),V);c(Ke,"BaseMessage");var ge=Ke,P,Xe=(P=class extends ge{constructor(){super(),l(this,"__kind","SingleMessage")}},i(P,"B"),P);c(Xe,"SingleMessage");var Ue=Xe,I,Je=(I=class extends ge{constructor(){super(),l(this,"__kind","EventMessage")}},i(I,"G"),I);c(Je,"EventMessage");var G=Je,D,Ze=(D=class extends G{constructor(e,t){super(),l(this,"error"),l(this,"context"),this.error=e,this.context=t}},i(D,"j"),D);c(Ze,"ErrorMessage");var _e=Ze,B,et=(B=class extends G{constructor(e){super(),l(this,"context"),this.context=e}},i(B,"L"),B);c(et,"WarnMessage");var je=et,N,tt=(N=class extends G{constructor(e){super(),l(this,"context"),this.context=e}},i(N,"W"),N);c(tt,"InfoMessage");var Qe=tt,de=null;function rt(r){de=r}i(rt,"re");c(rt,"activateInstance");var jt=new Proxy({},{get(r,e){return e==="dispatch"?t=>{if(!de){console.error(`[Virid] Message dispatched before system init: ${t.constructor.name}`);return}return de.dispatch(t)}:Reflect.get(de||{},e)}}),q,st=(q=class{static write(e,...t){let s=typeof e=="function"?new e(...t):e;jt.dispatch(s)}static error(e,t=""){this.write(new _e(e,t))}static warn(e){this.write(new je(e))}static info(e){this.write(new Qe(e))}},i(q,"Q"),q);c(st,"MessageWriter");var m=st,_,nt=(_=class{constructor(e){l(this,"dirtySignalTypes",new Set),l(this,"eventQueue",[]),l(this,"isRunning",!1),l(this,"globalTick",0),l(this,"internalDepth",0),l(this,"eventHub"),l(this,"tickPayload",{}),l(this,"beforeExecuteHooks",[]),l(this,"afterExecuteHooks",[]),l(this,"beforeTickHooks",[]),l(this,"afterTickHooks",[]),this.eventHub=e}addBeforeExecute(e,t,s){s?this.beforeExecuteHooks.unshift({type:e,handler:t}):this.beforeExecuteHooks.push({type:e,handler:t})}addAfterExecute(e,t,s){s?this.afterExecuteHooks.unshift({type:e,handler:t}):this.afterExecuteHooks.push({type:e,handler:t})}addBeforeTick(e,t){t?this.beforeTickHooks.unshift(e):this.beforeTickHooks.push(e)}addAfterTick(e,t){t?this.afterTickHooks.unshift(e):this.afterTickHooks.push(e)}markDirty(e){e instanceof G?this.eventQueue.push(e):e instanceof Ue&&this.dirtySignalTypes.add(e.constructor)}tick(e){if(!(this.isRunning||this.dirtySignalTypes.size===0&&this.eventQueue.length===0)){if(this.internalDepth>100){this.internalDepth=0,this.dirtySignalTypes.clear(),this.eventQueue=[],this.eventHub.reset(),m.error(new Error("[Virid Dispatcher] Deadlock: Recursive loop detected \u{1F4A5}."));return}this.isRunning=!0,this.internalDepth++,queueMicrotask(()=>{let t,s;try{this.internalDepth==1&&(this.tickPayload={},this.executeTickHooks(this.beforeTickHooks));let n=this.prepareSnapshot();t=n.signalSnapshot,s=n.eventSnapshot;let o=this.collectTasks(s,t,e);this.executeTasks(o)}catch(n){m.error(n,"[Virid Dispatcher] Unhandled Error")}finally{t&&s&&this.clear(s,t),this.isRunning=!1,this.dirtySignalTypes.size>0||this.eventQueue.length>0?this.tick(e):(this.executeTickHooks(this.afterTickHooks),this.globalTick++,this.internalDepth=0)}})}}collectTasks(e,t,s){let n=[];for(let a of e)(s.get(a.constructor)||[]).forEach(d=>{n.push(new Ge(d.fn,d.priority,a,{context:d.fn.systemContext,tick:this.globalTick,payload:{}}))});let o=new Set;for(let a of t)(s.get(a)||[]).forEach(d=>{o.has(d.fn)||(n.push(new Ge(d.fn,d.priority,this.eventHub.peekSignal(a),{context:d.fn.systemContext,tick:this.globalTick,payload:{}})),o.add(d.fn))});return n}executeTasks(e){e.sort((t,s)=>s.priority-t.priority);for(let t of e)try{let s=t.execute(this.beforeExecuteHooks,this.afterExecuteHooks);s instanceof Promise&&s.catch(n=>m.error(n,`[Virid Dispatcher]: Async System Error.
8
8
  SystemLocation: ${t.hookContext.context.targetClass.name}.${t.hookContext.context.methodName}
9
9
  MessageName: ${t.message.constructor.name}
10
- MessageData: ${JSON.stringify(t.message)}`))}catch(s){p.error(s,`[Virid Dispatcher]: Sync System Error.
10
+ MessageData: ${JSON.stringify(t.message)}`))}catch(s){m.error(s,`[Virid Dispatcher]: Sync System Error.
11
11
  SystemLocation: ${t.hookContext.context.targetClass.name}.${t.hookContext.context.methodName}
12
12
  MessageName: ${t.message.constructor.name}
13
- MessageData: ${JSON.stringify(t.message)}`)}}prepareSnapshot(){this.eventHub.flip();let e=new Set(this.dirtySignalTypes),t=[...this.eventQueue];return this.dirtySignalTypes.clear(),this.eventQueue=[],{signalSnapshot:e,eventSnapshot:t}}clear(e,t){let s=new Set(t);e.forEach(n=>s.add(n.constructor)),this.eventHub.clearSignals(s),this.eventHub.clearEvents()}executeTickHooks(e){let t={tick:this.globalTick,timestamp:Date.now(),payload:this.tickPayload};e.forEach(s=>s(t))}},i(F,"K"),F);c(dt,"Dispatcher");var Yt=dt,W,ut=(W=class{constructor(e,t,s,n){l(this,"fn"),l(this,"priority"),l(this,"message"),l(this,"hookContext"),this.fn=e,this.priority=t,this.message=s,this.hookContext=n}triggerHooks(e){let t=Array.isArray(this.message)?this.message[0]:this.message;if(t){for(let s of e)if(t instanceof s.type)try{let n=s.handler(this.message,this.hookContext);n instanceof Promise&&n.catch(o=>{p.error(o,`[Virid Hook] Async Hook Error:
13
+ MessageData: ${JSON.stringify(t.message)}`)}}prepareSnapshot(){this.eventHub.flip();let e=new Set(this.dirtySignalTypes),t=[...this.eventQueue];return this.dirtySignalTypes.clear(),this.eventQueue=[],{signalSnapshot:e,eventSnapshot:t}}clear(e,t){let s=new Set(t);e.forEach(n=>s.add(n.constructor)),this.eventHub.clearSignals(s),this.eventHub.clearEvents()}executeTickHooks(e){let t={tick:this.globalTick,timestamp:Date.now(),payload:this.tickPayload};e.forEach(s=>s(t))}},i(_,"z"),_);c(nt,"Dispatcher");var Qt=nt,j,it=(j=class{constructor(e,t,s,n){l(this,"fn"),l(this,"priority"),l(this,"message"),l(this,"hookContext"),this.fn=e,this.priority=t,this.message=s,this.hookContext=n}triggerHooks(e){let t=Array.isArray(this.message)?this.message[0]:this.message;if(t){for(let s of e)if(t instanceof s.type)try{let n=s.handler(this.message,this.hookContext);n instanceof Promise&&n.catch(o=>{m.error(o,`[Virid Hook] Async Hook Error:
14
14
  It is prohibited to use asynchronous hooks within Hook:
15
- ${s.type.name}`)})}catch(n){p.error(n,`[Virid Hook] Hook Execute Failed:
15
+ ${s.type.name}`)})}catch(n){m.error(n,`[Virid Hook] Hook Execute Failed:
16
16
  Triggered by: ${t.constructor.name}
17
- Registered type: ${s.type.name}`)}}}execute(e,t){this.triggerHooks(e);let s=c(()=>this.triggerHooks(t),"runAfter");try{let n=this.fn(this.message);return n instanceof Promise?n.finally(()=>s()):(s(),n)}catch(n){throw s(),n}}},i(W,"X"),W);c(ut,"ExecutionTask");var Je=ut,U,ht=(U=class{constructor(){l(this,"signalActive",new Map),l(this,"signalStaging",new Map),l(this,"eventActive",[]),l(this,"eventStaging",[])}push(e){if(e instanceof xe){let t=e.constructor;this.signalStaging.has(t)||this.signalStaging.set(t,[]),this.signalStaging.get(t).push(e)}else e instanceof $?this.eventStaging.push(e):p.error(new Error(`[Virid Message] Invalid Message:
18
- ${e.constructor.name} must extend SingleMessage or EventMessage`))}flip(){this.signalActive=this.signalStaging,this.signalStaging=new Map,this.eventActive=this.eventStaging,this.eventStaging=[]}peekSignal(e){return this.signalActive.get(e)||[]}getEventStream(){return this.eventActive}peekEventAt(e){return this.eventActive[e]}clearSignals(e){e.forEach(t=>this.signalActive.delete(t))}clearEvents(){this.eventActive=[]}reset(){this.signalActive.clear(),this.signalStaging.clear(),this.eventActive=[],this.eventStaging=[]}},i(U,"Z"),U);c(ht,"EventHub");var Kt=ht,L,pt=(L=class{constructor(){l(this,"systemTaskMap",new Map)}register(e,t,s=0){let n=this.systemTaskMap.get(e)||[];if(n.findIndex(o=>o.fn===t)===-1)n.push({fn:t,priority:s}),n.sort((o,a)=>a.priority-o.priority),this.systemTaskMap.set(e,n);else{let o=t.name||"Anonymous";return p.error(new Error(`[Virid Error] System Already Registered:
17
+ Registered type: ${s.type.name}`)}}}execute(e,t){this.triggerHooks(e);let s=c(()=>this.triggerHooks(t),"runAfter");try{let n=this.fn(this.message);return n instanceof Promise?n.finally(()=>s()):(s(),n)}catch(n){throw s(),n}}},i(j,"F"),j);c(it,"ExecutionTask");var Ge=it,Q,at=(Q=class{constructor(){l(this,"signalActive",new Map),l(this,"signalStaging",new Map),l(this,"eventActive",[]),l(this,"eventStaging",[])}push(e){if(e instanceof Ue){let t=e.constructor;this.signalStaging.has(t)||this.signalStaging.set(t,[]),this.signalStaging.get(t).push(e)}else e instanceof G?this.eventStaging.push(e):m.error(new Error(`[Virid Message] Invalid Message:
18
+ ${e.constructor.name} must extend SingleMessage or EventMessage`))}flip(){this.signalActive=this.signalStaging,this.signalStaging=new Map,this.eventActive=this.eventStaging,this.eventStaging=[]}peekSignal(e){return this.signalActive.get(e)||[]}getEventStream(){return this.eventActive}peekEventAt(e){return this.eventActive[e]}clearSignals(e){e.forEach(t=>this.signalActive.delete(t))}clearEvents(){this.eventActive=[]}reset(){this.signalActive.clear(),this.signalStaging.clear(),this.eventActive=[],this.eventStaging=[]}},i(Q,"U"),Q);c(at,"EventHub");var Ut=at,U,ot=(U=class{constructor(){l(this,"systemTaskMap",new Map)}register(e,t,s=0){let n=this.systemTaskMap.get(e)||[];if(n.findIndex(o=>o.fn===t)===-1)n.push({fn:t,priority:s}),n.sort((o,a)=>a.priority-o.priority),this.systemTaskMap.set(e,n);else{let o=t.name||"Anonymous";return m.error(new Error(`[Virid Error] System Already Registered:
19
19
  Class ${e.name}
20
- Function ${o}`)),()=>{}}return()=>{let o=this.systemTaskMap.get(e);if(o){let a=o.findIndex(d=>d.fn===t);a!==-1&&(o.splice(a,1),o.length===0&&this.systemTaskMap.delete(e))}}}},i(L,"ee"),L);c(pt,"MessageRegistry");var Xt=pt,G,ft=(G=class{constructor(){l(this,"eventHub",new Kt),l(this,"dispatcher",new Yt(this.eventHub)),l(this,"registry",new Xt),l(this,"middlewares",[]),ct(this)}useMiddleware(e,t){this.middlewares.push(e)}onBeforeExecute(e,t,s){this.dispatcher.addBeforeExecute(e,t,s)}onAfterExecute(e,t,s){this.dispatcher.addAfterExecute(e,t,s)}onBeforeTick(e,t){this.dispatcher.addBeforeTick(e,t)}onAfterTick(e,t){this.dispatcher.addAfterTick(e,t)}dispatch(e){if(!(e instanceof ye)){p.error(new Error(`[Virid Dispatch] Type Error: Message must be an instance of BaseMessage,message:${e}`));return}this.pipeline(e,()=>{if(!this.registry.systemTaskMap.has(e.constructor)){p.error(new Error(`[Virid Dispatch] No handler for message: ${e.constructor.name}`));return}this.eventHub.push(e),this.dispatcher.markDirty(e),this.dispatcher.tick(this.registry.systemTaskMap)})}pipeline(e,t){let s=0,n=c(()=>{s<this.middlewares.length?this.middlewares[s++](e,n):t()},"next");n()}register(e,t,s=0){return this.registry.register(e,t,s)}},i(G,"te"),G);c(ft,"MessageInternal");var Jt=ft,z,gt=(z=class{constructor(){l(this,"bindings",new Map),l(this,"singletonInstances",new Map)}bind(e){let t={type:"transient",ctor:e};return this.bindings.set(e,t),{toSelf:c(()=>({inSingletonScope:c(()=>(t.type="singleton",{onActivation:c(s=>{},"onActivation")}),"inSingletonScope")}),"toSelf")}}get(e,t){let s=this.bindings.get(e);if(!s)throw new Error(`[Virid Container] Unbound Constructor: No binding found for ${e.name}`);let n=s.ctor;if(s.type==="singleton"){if(!this.singletonInstances.has(e)){let a=new n,d=t(a);this.singletonInstances.set(e,d)}return this.singletonInstances.get(e)}let o=new n;return t(o)}},i(z,"re"),z);c(gt,"ViridContainer");var Zt=gt,h={reset:"\x1B[0m",red:"\x1B[31m",yellow:"\x1B[33m",blue:"\x1B[34m",magenta:"\x1B[35m",cyan:"\x1B[36m",gray:"\x1B[90m",bold:"\x1B[1m",green:"\x1B[32m"};function J(r,e,t){let s={params:r,targetClass:Object,methodName:t,originalMethod:e};return e.ccsContext=s,e}i(J,"N");c(J,"withContext");var er=c(r=>{let e=`${h.green}${h.bold} \u2714 [Virid Info] ${h.reset}`,t=`${h.magenta}${r.context}${h.reset}`;console.log(`${e}${h.gray}Global Info Caught:${h.reset}
21
- ${h.green}Details:${h.reset}`,r.context||"unknown Info")},"globalInfoHandler"),tr=c(r=>{let e=`${h.red}${h.bold} \u2716 [Virid Error] ${h.reset}`,t=`${h.magenta}${r.context}${h.reset}`;console.error(`${e}${h.gray}Global Error Caught:${h.reset}
22
- ${h.red}Context:${h.reset} ${t}
23
- ${h.red}Details:${h.reset}`,r.error||r||"unknown Error")},"globalErrorHandler"),rr=c(r=>{let e=`${h.yellow}${h.bold} \u26A0 [Virid Warn] ${h.reset}`,t=`${h.cyan}${r.context}${h.reset}`;console.warn(`${e}${h.gray}Global Warn Caught:${h.reset}
24
- ${h.yellow}Context:${h.reset} ${t}`)},"globalWarnHandler"),sr=c(r=>{let e=Z.get(r.ComponentClass);if(!e){console.error(`[Virid Modify] Component Not Found:
25
- Component ${r.ComponentClass.name} not found in Registry.`);return}try{r.recipe(e),p.warn(`[Virid Modify] Successfully:
26
- Modify on ${r.ComponentClass.name}
27
- label: ${r.label}`)}catch(t){p.error(t,`[Virid Error] Modify Failed:
28
- ${r.label}`)}},"atomicModifyHandler");function mt(r){r.register(Xe,J(Xe,sr,"GlobalAtomicModifier"),1e3),r.register(Le,J(Le,rr,"GlobalWarnHandler"),-999),r.register(Ue,J(Ue,tr,"GlobalErrorHandler"),-999),r.register(Ge,J(Ge,er,"GlobalInfoHandler"),-999),Z=r}i(mt,"le");c(mt,"initializeGlobalSystems");var Z=null,Ir=new Proxy({},{get(r,e){return(...t)=>{if(!Z){console.warn(`[Virid Vue] App method "${String(e)}" called before initialization.`);return}let s=Z[e];if(typeof s=="function")return s.apply(Z,t)}}}),Ze=new Set,Y,yt=(Y=class{constructor(){l(this,"container",new Zt),l(this,"messageInternal",new Jt),l(this,"activationHooks",[])}addActivationHook(e){this.activationHooks.push(e)}get(e){return e.length>0&&p.error(new Error(`[Virid Container] Violation: Component "${e.name}" should not have constructor arguments. Dependency Injection is only allowed in Systems.`)),this.container.get(e,t=>this.handleActivation(t))}handleActivation(e){return e&&this.activationHooks.reduce((t,s)=>{try{let n=s(t);return n===void 0&&p.warn(`[Virid Container] Hook Does Bot Return A Value: Hook "${s.name}" should return a instance to continue.`),n!==void 0?n:t}catch(n){return p.error(n,"[Virid Container] Activation Hook Failed"),t}},e)}bindController(e){return this.container.bind(e).toSelf(),{inSingletonScope:c(()=>({onActivation:c(()=>{},"onActivation")}),"inSingletonScope")}}bindComponent(e){return this.container.bind(e).toSelf().inSingletonScope(),{onActivation:c(()=>{},"onActivation")}}useMiddleware(e,t=!1){this.messageInternal.useMiddleware(e,t)}onBeforeExecute(e,t,s=!1){this.messageInternal.onBeforeExecute(e,t,s)}onAfterExecute(e,t,s=!1){this.messageInternal.onAfterExecute(e,t,s)}onBeforeTick(e,t=!1){this.messageInternal.onBeforeTick(e,t)}onAfterTick(e,t=!1){this.messageInternal.onAfterTick(e,t)}register(e,t,s=0){return this.messageInternal.register(e,t,s)}use(e,t){if(Ze.has(e.name))return p.warn(`[Virid Plugin] Duplicate Installation: Plugin ${e.name} has already been installed.`),this;try{e.install(this,t),Ze.add(e.name)}catch(s){p.error(s,`[Virid Plugin]: Install Failed: ${e.name}`)}return this}},i(Y,"ne"),Y);c(yt,"ViridApp");var nr=yt,ee=new nr;ee.addActivationHook(me);mt(ee);var b={SYSTEM:"virid:core:system",MESSAGE:"virid:core:message",CONTROLLER:"virid:core:controller",COMPONENT:"virid:core:component",SAFE:"virid:core:safe",OBSERVER:"virid:core:observer"},ge=c(r=>{r&&(Array.isArray(r)?r:[r]).forEach(e=>{e instanceof ye?p.write(e):p.warn("[Virid HandleResult] Invalid Return Type: Must return Message or Message[].")})},"handleResult");function ir(r={priority:0,messageClass:null}){return(e,t,s)=>{let n=s.value,o=Reflect.getMetadata("design:paramtypes",e,t),a=Reflect.getMetadata(b.MESSAGE,e,t)||null;if(!o){let g=new Error(`[Virid System] System Parameter Loss:
29
- Unable to recognize system parameters, please confirm if import "reflection-metadata" was introduced at the beginning!`);p.error(g);return}if(o.some(g=>g===void 0)){let g=new Error(`[Virid System] Parameter Metadata Loss in "${t}":
20
+ Function ${o}`)),()=>{}}return()=>{let o=this.systemTaskMap.get(e);if(o){let a=o.findIndex(d=>d.fn===t);a!==-1&&(o.splice(a,1),o.length===0&&this.systemTaskMap.delete(e))}}}},i(U,"J"),U);c(ot,"MessageRegistry");var Wt=ot,W,ct=(W=class{constructor(){l(this,"eventHub",new Ut),l(this,"dispatcher",new Qt(this.eventHub)),l(this,"registry",new Wt),l(this,"middlewares",[]),rt(this)}useMiddleware(e,t){this.middlewares.push(e)}onBeforeExecute(e,t,s){this.dispatcher.addBeforeExecute(e,t,s)}onAfterExecute(e,t,s){this.dispatcher.addAfterExecute(e,t,s)}onBeforeTick(e,t){this.dispatcher.addBeforeTick(e,t)}onAfterTick(e,t){this.dispatcher.addAfterTick(e,t)}dispatch(e){if(!(e instanceof ge)){m.error(new Error(`[Virid Dispatch] Type Error: Message must be an instance of BaseMessage,message:${e}`));return}this.pipeline(e,()=>{if(!this.registry.systemTaskMap.has(e.constructor)){m.error(new Error(`[Virid Dispatch] No handler for message: ${e.constructor.name}`));return}this.eventHub.push(e),this.dispatcher.markDirty(e),this.dispatcher.tick(this.registry.systemTaskMap)})}pipeline(e,t){let s=0,n=c(()=>{s<this.middlewares.length?this.middlewares[s++](e,n):t()},"next");n()}register(e,t,s=0){return this.registry.register(e,t,s)}},i(W,"Y"),W);c(ct,"MessageInternal");var Ft=ct,F,lt=(F=class{constructor(){l(this,"bindings",new Map),l(this,"singletonInstances",new Map)}bind(e){let t={type:"transient",ctor:e};return this.bindings.set(e,t),{toSelf:c(()=>({inSingletonScope:c(()=>(t.type="singleton",{onActivation:c(s=>{},"onActivation")}),"inSingletonScope")}),"toSelf")}}get(e,t){let s=this.bindings.get(e);if(!s)throw new Error(`[Virid Container] Unbound Constructor: No binding found for ${e.name}`);let n=s.ctor;if(s.type==="singleton"){if(!this.singletonInstances.has(e)){let a=new n,d=t(a);this.singletonInstances.set(e,d)}return this.singletonInstances.get(e)}let o=new n;return t(o)}},i(F,"q"),F);c(lt,"ViridContainer");var Lt=lt,p={reset:"\x1B[0m",red:"\x1B[31m",yellow:"\x1B[33m",blue:"\x1B[34m",magenta:"\x1B[35m",cyan:"\x1B[36m",gray:"\x1B[90m",bold:"\x1B[1m",green:"\x1B[32m"};function ue(r,e,t){let s={params:r,targetClass:Object,methodName:t,originalMethod:e};return e.ccsContext=s,e}i(ue,"K");c(ue,"withContext");var Gt=c(r=>{let e=`${p.green}${p.bold} \u2714 [Virid Info] ${p.reset}`,t=`${p.magenta}${r.context}${p.reset}`;console.log(`${e}${p.gray}Global Info Caught:${p.reset}
21
+ ${p.green}Details:${p.reset}`,r.context||"unknown Info")},"globalInfoHandler"),zt=c(r=>{let e=`${p.red}${p.bold} \u2716 [Virid Error] ${p.reset}`,t=`${p.magenta}${r.context}${p.reset}`;console.error(`${e}${p.gray}Global Error Caught:${p.reset}
22
+ ${p.red}Context:${p.reset} ${t}
23
+ ${p.red}Details:${p.reset}`,r.error||r||"unknown Error")},"globalErrorHandler"),Yt=c(r=>{let e=`${p.yellow}${p.bold} \u26A0 [Virid Warn] ${p.reset}`,t=`${p.cyan}${r.context}${p.reset}`;console.warn(`${e}${p.gray}Global Warn Caught:${p.reset}
24
+ ${p.yellow}Context:${p.reset} ${t}`)},"globalWarnHandler");function dt(r){r.register(je,ue(je,Yt,"GlobalWarnHandler"),-999),r.register(_e,ue(_e,zt,"GlobalErrorHandler"),-999),r.register(Qe,ue(Qe,Gt,"GlobalInfoHandler"),-999),pe=r}i(dt,"se");c(dt,"initializeGlobalSystems");var pe=null,kr=new Proxy({},{get(r,e){return(...t)=>{if(!pe){console.warn(`[Virid Vue] App method "${String(e)}" called before initialization.`);return}let s=pe[e];if(typeof s=="function")return s.apply(pe,t)}}}),ze=new Set,L,ut=(L=class{constructor(){l(this,"container",new Lt),l(this,"messageInternal",new Ft),l(this,"activationHooks",[])}addActivationHook(e){this.activationHooks.push(e)}get(e){return e.length>0&&m.error(new Error(`[Virid Container] Violation: Component "${e.name}" should not have constructor arguments. Dependency Injection is only allowed in Systems.`)),this.container.get(e,t=>this.handleActivation(t))}handleActivation(e){return e&&this.activationHooks.reduce((t,s)=>{try{let n=s(t);return n===void 0&&m.warn(`[Virid Container] Hook Does Bot Return A Value: Hook "${s.name}" should return a instance to continue.`),n!==void 0?n:t}catch(n){return m.error(n,"[Virid Container] Activation Hook Failed"),t}},e)}bindController(e){return this.container.bind(e).toSelf(),{inSingletonScope:c(()=>({onActivation:c(()=>{},"onActivation")}),"inSingletonScope")}}bindComponent(e){return this.container.bind(e).toSelf().inSingletonScope(),{onActivation:c(()=>{},"onActivation")}}useMiddleware(e,t=!1){this.messageInternal.useMiddleware(e,t)}onBeforeExecute(e,t,s=!1){this.messageInternal.onBeforeExecute(e,t,s)}onAfterExecute(e,t,s=!1){this.messageInternal.onAfterExecute(e,t,s)}onBeforeTick(e,t=!1){this.messageInternal.onBeforeTick(e,t)}onAfterTick(e,t=!1){this.messageInternal.onAfterTick(e,t)}register(e,t,s=0){return this.messageInternal.register(e,t,s)}use(e,t){if(ze.has(e.name))return m.warn(`[Virid Plugin] Duplicate Installation: Plugin ${e.name} has already been installed.`),this;try{e.install(this,t),ze.add(e.name)}catch(s){m.error(s,`[Virid Plugin]: Install Failed: ${e.name}`)}return this}},i(L,"Z"),L);c(ut,"ViridApp");var Kt=ut,K=new Kt;K.addActivationHook(fe);dt(K);var A={SYSTEM:"virid:core:system",MESSAGE:"virid:core:message",CONTROLLER:"virid:core:controller",COMPONENT:"virid:core:component",SAFE:"virid:core:safe",OBSERVER:"virid:core:observer"},he=c(r=>{r&&(Array.isArray(r)?r:[r]).forEach(e=>{e instanceof ge?m.write(e):m.warn("[Virid HandleResult] Invalid Return Type: Must return Message or Message[].")})},"handleResult");function Xt(r={priority:0,messageClass:null}){return(e,t,s)=>{let n=s.value,o=Reflect.getMetadata("design:paramtypes",e,t),a=Reflect.getMetadata(A.MESSAGE,e,t)||null;if(!o){let f=new Error(`[Virid System] System Parameter Loss:
25
+ Unable to recognize system parameters, please confirm if import "reflection-metadata" was introduced at the beginning!`);m.error(f);return}if(o.some(f=>f===void 0)){let f=new Error(`[Virid System] Parameter Metadata Loss in "${t}":
30
26
  One or more parameters have 'undefined' types.
31
27
  This usually happens when you forget to add a type annotation to a decorated parameter.
32
- Check parameter at index: ${o.indexOf(void 0)}`);p.error(g);return}if(r.messageClass&&a){p.error(new Error(`[Virid System] Multiple Messages Are Not Allowed: Cannot use @ message() and SystemParams simultaneously in ${t}`));return}if(!r.messageClass&&!a){p.error(new Error(`[Virid System] System Parameter Loss:
33
- Please declare the message type using the Message decorator`));return}let d=c(g=>{let E=o.map((x,A)=>{if(a&&a.index==A){let{messageClass:T,single:be}=a,se=Array.isArray(g)?g[0]:g;if(!(se instanceof T)){let Ct=se.constructor.name;throw new Error(`[Virid System] Type Mismatch: Expected ${T.name}, but received ${Ct}`)}if(se instanceof xe)return be?Array.isArray(g)?g[g.length-1]:g:Array.isArray(g)?g:[g];if(se instanceof $)return g;throw new Error(`[Virid System] unknown Message Types: Message ${T.name} is not a subclass of SingleMessage or EventMessage!`)}let C=ee.get(x);if(!C)throw new Error(`[Virid System] unknown Inject Data Types: ${x.name} is not registered in the container!`);return C}),w=n.apply(e,E);return w instanceof Promise?w.then(ge):ge(w)},"wrappedSystem"),f={params:o,targetClass:e,methodName:t,originalMethod:n};d.systemContext=f,s.value=d;let u=r.messageClass||a.messageClass;ee.register(u,d,r.priority)}}i(ir,"ft");c(ir,"System");function ar(r,e=!0){return(t,s,n)=>{if(Reflect.hasOwnMetadata(b.MESSAGE,t,s)){p.error(new Error(`[Virid Message] Multiple Messages Are Not Allowed: ${s} has multiple @Message() decorators!`));return}let o={index:n,messageClass:r,single:e};Reflect.defineMetadata(b.MESSAGE,o,t,s)}}i(ar,"pt");c(ar,"Message");function or(){return(r,e,t)=>{let s=Reflect.getMetadata(b.SAFE,r)||new Set;s.add(e),Reflect.defineMetadata(b.SAFE,s,r)}}i(or,"gt");c(or,"Safe");function cr(r,[]){return(e,t)=>{let s=Reflect.getMetadata(b.OBSERVER,e)||[];s.push({key:t,callback:r}),Reflect.defineMetadata(b.OBSERVER,s,e)}}i(cr,"mt");c(cr,"Observer");function lr(){return r=>{Reflect.defineMetadata(b.CONTROLLER,!0,r)}}i(lr,"yt");c(lr,"Controller");function dr(){return r=>{Reflect.defineMetadata(b.COMPONENT,!0,r)}}i(dr,"xt");c(dr,"Component");var ur=["push","pop","shift","unshift","splice","sort","reverse"];function me(r){return!r||typeof r!="object"||Object.prototype.hasOwnProperty.call(r,"__virid_observer_processed__")||(Object.defineProperty(r,"__virid_observer_processed__",{value:!0,enumerable:!1,configurable:!0}),(Reflect.getMetadata(b.OBSERVER,r.constructor)||[]).forEach(({propertyKey:e,callback:t})=>{let s={value:r[e]},n=new Proxy(s,{get(a,d){let f=a.value;return Array.isArray(f)&&ur.includes(d)?(...u)=>{let g=[...f],E=f[d].apply(f,u),w=t.call(r,g,f);return ge(w),E}:f},set(a,d,f){let u=a.value;if(f===u)return!0;a.value=f;let g=t.call(r,u,f);return ge(g),!0}}),o=c(()=>n.value,"getter");o.__virid_box__=s,Object.defineProperty(r,e,{get:o,set:c(a=>{n.value=a},"set"),enumerable:!0,configurable:!0}),s.value&&typeof s.value=="object"&&me(s.value)}),Reflect.ownKeys(r).forEach(e=>{if(e==="__virid_observer_processed__")return;let t=Object.getOwnPropertyDescriptor(r,e);if(t&&t.get)return;let s=r[e];s&&typeof s=="object"&&me(s)})),r}i(me,"_");c(me,"bindObservers");function hr(){return ee}i(hr,"It");c(hr,"createVirid");function xt(r){let e=parseInt(r,10);if(isNaN(e))throw new k(400,`Validation failed: "${r}" is not a number.`);return e}i(xt,"ParseIntPipe");function Mt(r){return r==="true"||r==="1"?!0:r==="false"||r==="0"?!1:!!r}i(Mt,"ParseBoolPipe");var te=new Map;te.set(Number,xt);te.set(Boolean,Mt);function pr(r,e){if(te.has(r)){p.error(new Error(`[Virid Express Pipe] Repeated Pipe: Auto pipe for ${r} has already been registered.`));return}te.set(r,e)}i(pr,"addAutoPipe");function Me(r){return te.get(r)}i(Me,"getAutoPipe");function ze(r){let e={};if(!r)return e;let t=r.split(";");for(let s of t){let n=s.indexOf("=");if(n===-1)continue;let o=s.substring(0,n).trim();if(!o)continue;let a=s.substring(n+1).trim();a[0]==='"'&&a[a.length-1]==='"'&&(a=a.slice(1,-1));try{e[o]=a.includes("%")?decodeURIComponent(a):a}catch{e[o]=a}}return e}i(ze,"parseRawCookie");var Et=require("@virid/core");var Ye=class Ye extends Et.EventMessage{constructor(t){super();y(this,"__virid_express_id");this.__virid_express_id=t,v.get(this.__virid_express_id).inc()}get requestId(){return this.__virid_express_id}};i(Ye,"HttpRequestMessage");var re=Ye;var Ee=new we.MessageRegistry,ve=new Map,fr=0;function wt(r){for(let[e,t]of Ee.systemTaskMap.entries())for(let s of t)r.register(e,s.fn,s.priority);Ee.systemTaskMap.clear()}i(wt,"registerHttpSystem");function vt(r){for(let[e,t]of ve.entries()){let{method:s,path:n,httpMessage:o}=t,a=s.toLowerCase();r[a](n,(d,f)=>{let u=fr++>>>0;v.set(u,new X(u,d,f,Date.now(),n));let g=new o(u);f.once("finish",()=>v.delete(u)),f.once("close",()=>v.delete(u)),we.MessageWriter.write(g)})}}i(vt,"registerHttpRoute");var Se=null;function bt(r,e){Se=r,wt(r),vt(e.server)}i(bt,"activateApp");var At=new Proxy({},{get(r,e){return(...t)=>{if(!Se)return St.MessageWriter.warn(`[Virid Vue] App method "${String(e)}" called before initialization.`),null;let s=Se[e];if(typeof s=="function")return s.apply(Se,t)}}});var S=require("@virid/core");var kt=require("@virid/core"),m={...kt.VIRID_METADATA,HTTPROUTE:"virid:express:route",HTTPSYSTEM:"virid:express:system",BODY:"virid:express:body",QUERY:"virid:express:query",HEADERS:"virid:express:header",REQUEST:"virid:express:request",RESPONSE:"virid:express:response",CONTEXT:"virid:express:context",PARAMS:"virid:express:params",COOKIES:"virid:express:cookie"};function gr(r){return e=>{let t=`${r.method}:${r.path}`;ve.has(t)&&S.MessageWriter.error(new Error(`[Virid Http] Routing Conflict: The request method ${r.method} for path ${r.path} has already been registered by ${e.name}`));let s=[];r.path.split("/").forEach(a=>{a.startsWith(":")&&s.push(a.substring(1))});let o={...r,httpMessage:e,params:s};ve.set(t,o)}}i(gr,"HttpRoute");function mr(r={priority:0,messageClass:null}){return(e,t,s)=>{let n=s.value,o=Reflect.getMetadata("design:paramtypes",e,t),a=Reflect.getMetadata(m.MESSAGE,e,t)||null,d=Ar(e,t,o);if(!o){let E=new Error(`[Virid HttpSystem] System Parameter Loss:
34
- Unable to recognize system parameters, please confirm if import "reflection-metadata" was introduced at the beginning!`);S.MessageWriter.error(E);return}if(o.some(E=>E===void 0)){let E=new Error(`[Virid HttpSystem] Parameter Metadata Loss in "${t}":
28
+ Check parameter at index: ${o.indexOf(void 0)}`);m.error(f);return}if(r.messageClass&&a){m.error(new Error(`[Virid System] Multiple Messages Are Not Allowed: Cannot use @ message() and SystemParams simultaneously in ${t}`));return}if(!r.messageClass&&!a){m.error(new Error(`[Virid System] System Parameter Loss:
29
+ Please declare the message type using the Message decorator`));return}let d=c(f=>{let M=o.map((x,b)=>{if(a&&a.index==b){let{messageClass:T,single:we}=a,Z=Array.isArray(f)?f[0]:f;if(!(Z instanceof T)){let wt=Z.constructor.name;throw new Error(`[Virid System] Type Mismatch: Expected ${T.name}, but received ${wt}`)}if(Z instanceof Ue)return we?Array.isArray(f)?f[f.length-1]:f:Array.isArray(f)?f:[f];if(Z instanceof G)return f;throw new Error(`[Virid System] unknown Message Types: Message ${T.name} is not a subclass of SingleMessage or EventMessage!`)}let k=K.get(x);if(!k)throw new Error(`[Virid System] unknown Inject Data Types: ${x.name} is not registered in the container!`);return k}),w=n.apply(e,M);return w instanceof Promise?w.then(he):he(w)},"wrappedSystem"),h={params:o,targetClass:e,methodName:t,originalMethod:n};d.systemContext=h,s.value=d;let u=r.messageClass||a.messageClass;K.register(u,d,r.priority)}}i(Xt,"it");c(Xt,"System");function Jt(r,e=!0){return(t,s,n)=>{if(Reflect.hasOwnMetadata(A.MESSAGE,t,s)){m.error(new Error(`[Virid Message] Multiple Messages Are Not Allowed: ${s} has multiple @Message() decorators!`));return}let o={index:n,messageClass:r,single:e};Reflect.defineMetadata(A.MESSAGE,o,t,s)}}i(Jt,"at");c(Jt,"Message");function Zt(){return(r,e,t)=>{let s=Reflect.getMetadata(A.SAFE,r)||new Set;s.add(e),Reflect.defineMetadata(A.SAFE,s,r)}}i(Zt,"ct");c(Zt,"Safe");function er(r){return(e,t)=>{let s=Reflect.getMetadata(A.OBSERVER,e)||[];s.push({propertyKey:t,callback:r}),Reflect.defineMetadata(A.OBSERVER,s,e)}}i(er,"lt");c(er,"Observer");function tr(){return r=>{Reflect.defineMetadata(A.CONTROLLER,!0,r)}}i(tr,"ht");c(tr,"Controller");function rr(){return r=>{Reflect.defineMetadata(A.COMPONENT,!0,r)}}i(rr,"ut");c(rr,"Component");var sr=["push","pop","shift","unshift","splice","sort","reverse"];function fe(r){return!r||typeof r!="object"||Object.prototype.hasOwnProperty.call(r,"__virid_observer_processed__")||(Object.defineProperty(r,"__virid_observer_processed__",{value:!0,enumerable:!1,configurable:!0}),(Reflect.getMetadata(A.OBSERVER,r)||[]).forEach(({propertyKey:e,callback:t})=>{console.log("instance :>> ",r),console.log("propertyKey :>> ",e);let s={value:r[e]},n=new Proxy(s,{get(a,d){let h=a.value;return Array.isArray(h)&&sr.includes(d)?(...u)=>{let f=[...h],M=h[d].apply(h,u),w=t.call(r,f,h);return he(w),M}:h},set(a,d,h){let u=a.value;if(h===u)return!0;a.value=h;let f=t.call(r,u,h);return he(f),!0}}),o=c(()=>n.value,"getter");o.__virid_box__=s,Object.defineProperty(r,e,{get:o,set:c(a=>{n.value=a},"set"),enumerable:!0,configurable:!0}),s.value&&typeof s.value=="object"&&fe(s.value)}),Reflect.ownKeys(r).forEach(e=>{if(e==="__virid_observer_processed__")return;let t=Object.getOwnPropertyDescriptor(r,e);if(t&&t.get)return;let s=r[e];s&&typeof s=="object"&&fe(s)})),r}i(fe,"P");c(fe,"bindObservers");function nr(){return K}i(nr,"Mt");c(nr,"createVirid");function pt(r){let e=parseInt(r,10);if(isNaN(e))throw new R(400,`Validation failed: "${r}" is not a number.`);return e}i(pt,"ParseIntPipe");function ht(r){return r==="true"||r==="1"?!0:r==="false"||r==="0"?!1:!!r}i(ht,"ParseBoolPipe");var X=new Map;X.set(Number,pt);X.set(Boolean,ht);function ir(r,e){if(X.has(r)){m.error(new Error(`[Virid Express Pipe] Repeated Pipe: Auto pipe for ${r} has already been registered.`));return}X.set(r,e)}i(ir,"addAutoPipe");function me(r){return X.get(r)}i(me,"getAutoPipe");function We(r){let e={};if(!r)return e;let t=r.split(";");for(let s of t){let n=s.indexOf("=");if(n===-1)continue;let o=s.substring(0,n).trim();if(!o)continue;let a=s.substring(n+1).trim();a[0]==='"'&&a[a.length-1]==='"'&&(a=a.slice(1,-1));try{e[o]=a.includes("%")?decodeURIComponent(a):a}catch{e[o]=a}}return e}i(We,"parseRawCookie");var ft=require("@virid/core");var Fe=class Fe extends ft.EventMessage{constructor(t){super();y(this,"__virid_express_id");this.__virid_express_id=t,v.get(this.__virid_express_id).inc()}get requestId(){return this.__virid_express_id}};i(Fe,"HttpRequestMessage");var J=Fe;var ye=new xe.MessageRegistry,Ee=new Map,ar=0;function gt(r){for(let[e,t]of ye.systemTaskMap.entries())for(let s of t)r.register(e,s.fn,s.priority);ye.systemTaskMap.clear()}i(gt,"registerHttpSystem");function mt(r){for(let[e,t]of Ee.entries()){let{method:s,path:n,httpMessage:o}=t,a=s.toLowerCase();r[a](n,(d,h)=>{let u=ar++>>>0;v.set(u,new Y(u,d,h,Date.now(),n));let f=new o(u);h.once("finish",()=>v.delete(u)),h.once("close",()=>v.delete(u)),xe.MessageWriter.write(f)})}}i(mt,"registerHttpRoute");var Me=null;function xt(r,e){Me=r,gt(r),mt(e.server)}i(xt,"activateApp");var Et=new Proxy({},{get(r,e){return(...t)=>{if(!Me)return yt.MessageWriter.warn(`[Virid Vue] App method "${String(e)}" called before initialization.`),null;let s=Me[e];if(typeof s=="function")return s.apply(Me,t)}}});var S=require("@virid/core");var Mt=require("@virid/core"),g={...Mt.VIRID_METADATA,HTTPROUTE:"virid:express:route",HTTPSYSTEM:"virid:express:system",BODY:"virid:express:body",QUERY:"virid:express:query",HEADERS:"virid:express:header",REQUEST:"virid:express:request",RESPONSE:"virid:express:response",CONTEXT:"virid:express:context",PARAMS:"virid:express:params",COOKIES:"virid:express:cookie"};function or(r){return e=>{let t=`${r.method}:${r.path}`;Ee.has(t)&&S.MessageWriter.error(new Error(`[Virid Http] Routing Conflict: The request method ${r.method} for path ${r.path} has already been registered by ${e.name}`));let s=[];r.path.split("/").forEach(a=>{a.startsWith(":")&&s.push(a.substring(1))});let o={...r,httpMessage:e,params:s};Ee.set(t,o)}}i(or,"HttpRoute");function cr(r={priority:0,messageClass:null}){return(e,t,s)=>{let n=s.value,o=Reflect.getMetadata("design:paramtypes",e,t),a=Reflect.getMetadata(g.MESSAGE,e,t)||null,d=yr(e,t,o);if(!o){let M=new Error(`[Virid HttpSystem] System Parameter Loss:
30
+ Unable to recognize system parameters, please confirm if import "reflection-metadata" was introduced at the beginning!`);S.MessageWriter.error(M);return}if(o.some(M=>M===void 0)){let M=new Error(`[Virid HttpSystem] Parameter Metadata Loss in "${t}":
35
31
  One or more parameters have 'undefined' types.
36
32
  This usually happens when you forget to add a type annotation to a decorated parameter.
37
- Check parameter at index: ${o.indexOf(void 0)}`);S.MessageWriter.error(E);return}if(r.messageClass&&a){S.MessageWriter.error(new Error(`[Virid HttpSystem] Multiple Messages Are Not Allowed: Cannot use @ message() and SystemParams simultaneously in ${t}`));return}if(!r.messageClass&&!a){S.MessageWriter.error(new Error(`[Virid HttpSystem] System Parameter Loss:
38
- Please declare the message type using the Message decorator`));return}let f=r.messageClass??a.messageClass;if(!re.isPrototypeOf(f)){S.MessageWriter.error(new Error(`[Virid HttpSystem] Wrong Message Type: ${f.name} is not a derived subclass of HttpRequestMessage!`));return}let u=i(E=>{let w=v.get(E.requestId);if(!w)throw new Error(`[Virid Express HttpSystem] Invalid Request Context: The request context for message ${E.requestId} is missing.`);try{let x=o.map((C,T)=>{if(a&&a.index==T){if(!(E instanceof f)){let be=E.constructor.name;throw new Error(`[Virid Express HttpSystem] Type Mismatch: Expected ${f.name}, but received ${be}`)}return E}else return kr(C,T,w,d)}),A=n.apply(e,x);return A instanceof Promise?A.then(C=>{V(C,w)}).catch(C=>{throw V(pe(),w),C}):V(A,w)}catch(x){throw x instanceof k?V(x,w):V(pe(),w),x}},"wrappedSystem"),g={params:o,targetClass:e,methodName:t,originalMethod:n};u.systemContext=g,s.value=u,Ee.register(f,u,r.priority)}}i(mr,"HttpSystem");function yr(){return(r,e,t)=>{if(Reflect.hasOwnMetadata(m.BODY,r,e)){S.MessageWriter.error(new Error(`[Virid Express Body] Multiple Body Are Not Allowed: ${e} has multiple @Body() decorators!`));return}let s={index:t};Reflect.defineMetadata(m.BODY,s,r,e)}}i(yr,"Body");function xr(){return(r,e,t)=>{if(Reflect.hasOwnMetadata(m.HEADERS,r,e)){S.MessageWriter.error(new Error(`[Virid Express Headers] Multiple Header Are Not Allowed: ${e} has multiple @Headers() decorators!`));return}let s={index:t};Reflect.defineMetadata(m.HEADERS,s,r,e)}}i(xr,"Headers");function Mr(){return(r,e,t)=>{if(Reflect.hasOwnMetadata(m.COOKIES,r,e)){S.MessageWriter.error(new Error(`[Virid Express Cookies] Multiple Header Are Not Allowed: ${e} has multiple @Cookies() decorators!`));return}let s={index:t};Reflect.defineMetadata(m.COOKIES,s,r,e)}}i(Mr,"Cookies");function Er(){return(r,e,t)=>{if(Reflect.hasOwnMetadata(m.REQUEST,r,e)){S.MessageWriter.error(new Error(`[Virid Express Req] Multiple Request Objects Are Not Allowed: ${e} has multiple @Req() decorators!`));return}let s={index:t};Reflect.defineMetadata(m.REQUEST,s,r,e)}}i(Er,"Req");function wr(){return(r,e,t)=>{if(Reflect.hasOwnMetadata(m.RESPONSE,r,e)){S.MessageWriter.error(new Error(`[Virid Express Res] Multiple Response Objects Are Not Allowed: ${e} has multiple @Res() decorators!`));return}let s={index:t};Reflect.defineMetadata(m.RESPONSE,s,r,e)}}i(wr,"Res");function vr(){return(r,e,t)=>{if(Reflect.hasOwnMetadata(m.CONTEXT,r,e)){S.MessageWriter.error(new Error(`[Virid Express Ctx] Multiple Context Objects Are Not Allowed: ${e} has multiple @Ctx() decorators!`));return}let s={index:t};Reflect.defineMetadata(m.CONTEXT,s,r,e)}}i(vr,"Ctx");function Sr(r,e){return(t,s,n)=>{let a=[...Reflect.getOwnMetadata(m.QUERY,t,s)||[],{index:n,query:r,pipe:e}];Reflect.defineMetadata(m.QUERY,a,t,s)}}i(Sr,"Query");function br(r,e){return(t,s,n)=>{let a=[...Reflect.getOwnMetadata(m.PARAMS,t,s)||[],{index:n,key:r,pipe:e}];Reflect.defineMetadata(m.PARAMS,a,t,s)}}i(br,"Params");function Ar(r,e,t){let s=Reflect.getOwnMetadata(m.BODY,r,e),n=Reflect.getOwnMetadata(m.HEADERS,r,e),o=Reflect.getOwnMetadata(m.COOKIES,r,e),a=Reflect.getOwnMetadata(m.RESPONSE,r,e),d=Reflect.getOwnMetadata(m.REQUEST,r,e),f=Reflect.getOwnMetadata(m.CONTEXT,r,e),g=(Reflect.getOwnMetadata(m.QUERY,r,e)||[]).map(x=>{if(!x.pipe){let A=t[x.index];x.pipe=Me(A)}return x}),w=(Reflect.getOwnMetadata(m.PARAMS,r,e)||[]).map(x=>{if(!x.pipe){let A=t[x.index];x.pipe=Me(A)}return x});return{bodyMeta:s,headerMeta:n,queryMeta:g,cookiesMeta:o,reqMeta:d,resMeta:a,ctxMeta:f,paramMeta:w}}i(Ar,"getHttpMetadata");function kr(r,e,t,s){let{req:n,res:o}=t;if(s.ctxMeta?.index===e)return t;let a=s.paramMeta?.find(u=>u.index===e);if(a){let u=a.key?n.params[a.key]:n.params;return a.pipe&&u!==void 0&&(u=a.pipe(u)),u}if(s.bodyMeta?.index===e)return n.body;if(s.headerMeta?.index===e)return n.headers;if(s.cookiesMeta?.index===e)return ze(n.headers.cookie);if(s.reqMeta?.index===e)return n;if(s.resMeta?.index===e)return o;let d=s.queryMeta?.find(u=>u.index===e);if(d){let u=n.query[d.query];if(u===void 0)throw new Error(`[Virid Express] Missing Query: "${d.query}"`);return d.pipe&&(u=d.pipe(u)),u}let f=At.get(r);if(!f)throw new Error(`[Virid System] Unknown Inject Type: ${r?.name||"Anonymous Class"} at index ${e}.
39
- Ensure it is registered in the IOC container or has a proper Http Decorator!`);return f}i(kr,"getHttpSystemArgs");var Cr={name:"@virid/express",install(r,e){bt(r,e)}};0&&(module.exports={BadRequest,BadRequestResponse,Body,ConflictResponse,Cookies,Created,CreatedResponse,Ctx,CustomResponse,CustomResponseResponse,ExpressPlugin,Forbidden,ForbiddenResponse,Headers,HttpContext,HttpError,HttpRequestMessage,HttpResponse,HttpRoute,HttpSystem,InternalServerError,InternalServerErrorResponse,NoContent,NoContentResponse,NotFound,NotFoundResponse,Ok,OkResponse,Params,ParseBoolPipe,ParseIntPipe,Query,Req,Res,Stream,StreamFile,StreamFileResponse,StreamResponse,Unauthorized,UnauthorizedResponse,UnprocessableEntityResponse,addAutoPipe,getAutoPipe,parseRawCookie});
33
+ Check parameter at index: ${o.indexOf(void 0)}`);S.MessageWriter.error(M);return}if(r.messageClass&&a){S.MessageWriter.error(new Error(`[Virid HttpSystem] Multiple Messages Are Not Allowed: Cannot use @ message() and SystemParams simultaneously in ${t}`));return}if(!r.messageClass&&!a){S.MessageWriter.error(new Error(`[Virid HttpSystem] System Parameter Loss:
34
+ Please declare the message type using the Message decorator`));return}let h=r.messageClass??a.messageClass;if(!J.isPrototypeOf(h)){S.MessageWriter.error(new Error(`[Virid HttpSystem] Wrong Message Type: ${h.name} is not a derived subclass of HttpRequestMessage!`));return}let u=i(M=>{let w=v.get(M.requestId);if(!w)throw new Error(`[Virid Express HttpSystem] Invalid Request Context: The request context for message ${M.requestId} is missing.`);try{let x=o.map((k,T)=>{if(a&&a.index==T){if(!(M instanceof h)){let we=M.constructor.name;throw new Error(`[Virid Express HttpSystem] Type Mismatch: Expected ${h.name}, but received ${we}`)}return M}else return xr(k,T,w,d)}),b=n.apply(e,x);return b instanceof Promise?b.then(k=>{O(k,w)}).catch(k=>{throw O(le(),w),k}):O(b,w)}catch(x){throw x instanceof R?O(x,w):O(le(),w),x}},"wrappedSystem"),f={params:o,targetClass:e,methodName:t,originalMethod:n};u.systemContext=f,s.value=u,ye.register(h,u,r.priority)}}i(cr,"HttpSystem");function lr(){return(r,e,t)=>{if(Reflect.hasOwnMetadata(g.BODY,r,e)){S.MessageWriter.error(new Error(`[Virid Express Body] Multiple Body Are Not Allowed: ${e} has multiple @Body() decorators!`));return}let s={index:t};Reflect.defineMetadata(g.BODY,s,r,e)}}i(lr,"Body");function dr(){return(r,e,t)=>{if(Reflect.hasOwnMetadata(g.HEADERS,r,e)){S.MessageWriter.error(new Error(`[Virid Express Headers] Multiple Header Are Not Allowed: ${e} has multiple @Headers() decorators!`));return}let s={index:t};Reflect.defineMetadata(g.HEADERS,s,r,e)}}i(dr,"Headers");function ur(){return(r,e,t)=>{if(Reflect.hasOwnMetadata(g.COOKIES,r,e)){S.MessageWriter.error(new Error(`[Virid Express Cookies] Multiple Header Are Not Allowed: ${e} has multiple @Cookies() decorators!`));return}let s={index:t};Reflect.defineMetadata(g.COOKIES,s,r,e)}}i(ur,"Cookies");function pr(){return(r,e,t)=>{if(Reflect.hasOwnMetadata(g.REQUEST,r,e)){S.MessageWriter.error(new Error(`[Virid Express Req] Multiple Request Objects Are Not Allowed: ${e} has multiple @Req() decorators!`));return}let s={index:t};Reflect.defineMetadata(g.REQUEST,s,r,e)}}i(pr,"Req");function hr(){return(r,e,t)=>{if(Reflect.hasOwnMetadata(g.RESPONSE,r,e)){S.MessageWriter.error(new Error(`[Virid Express Res] Multiple Response Objects Are Not Allowed: ${e} has multiple @Res() decorators!`));return}let s={index:t};Reflect.defineMetadata(g.RESPONSE,s,r,e)}}i(hr,"Res");function fr(){return(r,e,t)=>{if(Reflect.hasOwnMetadata(g.CONTEXT,r,e)){S.MessageWriter.error(new Error(`[Virid Express Ctx] Multiple Context Objects Are Not Allowed: ${e} has multiple @Ctx() decorators!`));return}let s={index:t};Reflect.defineMetadata(g.CONTEXT,s,r,e)}}i(fr,"Ctx");function gr(r,e){return(t,s,n)=>{let a=[...Reflect.getOwnMetadata(g.QUERY,t,s)||[],{index:n,query:r,pipe:e}];Reflect.defineMetadata(g.QUERY,a,t,s)}}i(gr,"Query");function mr(r,e){return(t,s,n)=>{let a=[...Reflect.getOwnMetadata(g.PARAMS,t,s)||[],{index:n,key:r,pipe:e}];Reflect.defineMetadata(g.PARAMS,a,t,s)}}i(mr,"Params");function yr(r,e,t){let s=Reflect.getOwnMetadata(g.BODY,r,e),n=Reflect.getOwnMetadata(g.HEADERS,r,e),o=Reflect.getOwnMetadata(g.COOKIES,r,e),a=Reflect.getOwnMetadata(g.RESPONSE,r,e),d=Reflect.getOwnMetadata(g.REQUEST,r,e),h=Reflect.getOwnMetadata(g.CONTEXT,r,e),f=(Reflect.getOwnMetadata(g.QUERY,r,e)||[]).map(x=>{if(!x.pipe){let b=t[x.index];x.pipe=me(b)}return x}),w=(Reflect.getOwnMetadata(g.PARAMS,r,e)||[]).map(x=>{if(!x.pipe){let b=t[x.index];x.pipe=me(b)}return x});return{bodyMeta:s,headerMeta:n,queryMeta:f,cookiesMeta:o,reqMeta:d,resMeta:a,ctxMeta:h,paramMeta:w}}i(yr,"getHttpMetadata");function xr(r,e,t,s){let{req:n,res:o}=t;if(s.ctxMeta?.index===e)return t;let a=s.paramMeta?.find(u=>u.index===e);if(a){let u=a.key?n.params[a.key]:n.params;return a.pipe&&u!==void 0&&(u=a.pipe(u)),u}if(s.bodyMeta?.index===e)return n.body;if(s.headerMeta?.index===e)return n.headers;if(s.cookiesMeta?.index===e)return We(n.headers.cookie);if(s.reqMeta?.index===e)return n;if(s.resMeta?.index===e)return o;let d=s.queryMeta?.find(u=>u.index===e);if(d){let u=n.query[d.query];if(u===void 0)throw new Error(`[Virid Express] Missing Query: "${d.query}"`);return d.pipe&&(u=d.pipe(u)),u}let h=Et.get(r);if(!h)throw new Error(`[Virid System] Unknown Inject Type: ${r?.name||"Anonymous Class"} at index ${e}.
35
+ Ensure it is registered in the IOC container or has a proper Http Decorator!`);return h}i(xr,"getHttpSystemArgs");var Er={name:"@virid/express",install(r,e){xt(r,e)}};0&&(module.exports={BadRequest,BadRequestResponse,Body,ConflictResponse,Cookies,Created,CreatedResponse,Ctx,CustomResponse,CustomResponseResponse,ExpressPlugin,Forbidden,ForbiddenResponse,Headers,HttpContext,HttpError,HttpRequestMessage,HttpResponse,HttpRoute,HttpSystem,InternalServerError,InternalServerErrorResponse,NoContent,NoContentResponse,NotFound,NotFoundResponse,Ok,OkResponse,Params,ParseBoolPipe,ParseIntPipe,Query,Req,Res,Stream,StreamFile,StreamFileResponse,StreamResponse,Unauthorized,UnauthorizedResponse,UnprocessableEntityResponse,addAutoPipe,getAutoPipe,parseRawCookie});
40
36
  //# sourceMappingURL=index.cjs.map