@virid/express 0.1.2 → 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
@@ -1,40 +1,36 @@
1
1
  /**
2
- * @virid/express v0.1.1
2
+ * @virid/express v0.1.3
3
3
  * Add express functionality to virid
4
4
  */
5
- var Y=Object.defineProperty;var At=Object.getOwnPropertyDescriptor;var Ct=Object.getOwnPropertyNames;var Rt=Object.prototype.hasOwnProperty;var $t=(r,e,t)=>e in r?Y(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var i=(r,e)=>Y(r,"name",{value:e,configurable:!0});var kt=(r,e)=>{for(var t in e)Y(r,t,{get:e[t],enumerable:!0})},Tt=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Ct(e))!Rt.call(r,n)&&n!==t&&Y(r,n,{get:()=>e[n],enumerable:!(s=At(e,n))||s.enumerable});return r};var Ht=r=>Tt(Y({},"__esModule",{value:!0}),r);var y=(r,e,t)=>$t(r,typeof e!="symbol"?e+"":e,t);var br={};kt(br,{BadRequest:()=>It,BadRequestResponse:()=>ae,Body:()=>hr,ConflictResponse:()=>Se,Cookies:()=>gr,Created:()=>Vt,CreatedResponse:()=>ne,Ctx:()=>xr,CustomResponse:()=>qt,CustomResponseResponse:()=>ue,ExpressPlugin:()=>Sr,Forbidden:()=>Bt,ForbiddenResponse:()=>ce,Headers:()=>fr,HttpContext:()=>K,HttpError:()=>C,HttpRequestMessage:()=>te,HttpResponse:()=>M,HttpRoute:()=>ur,HttpSystem:()=>pr,InternalServerError:()=>pe,InternalServerErrorResponse:()=>de,NoContent:()=>Pt,NoContentResponse:()=>ie,NotFound:()=>Nt,NotFoundResponse:()=>le,Ok:()=>Ot,OkResponse:()=>se,Params:()=>Er,ParseBoolPipe:()=>mt,ParseIntPipe:()=>gt,Query:()=>Mr,Req:()=>mr,Res:()=>yr,Stream:()=>jt,StreamFile:()=>_t,StreamFileResponse:()=>H,StreamResponse:()=>O,Unauthorized:()=>Dt,UnauthorizedResponse:()=>oe,UnprocessableEntityResponse:()=>be,addAutoPipe:()=>lr,getAutoPipe:()=>ye,parseRawCookie:()=>Ue});module.exports=Ht(br);var Et=require("@virid/core");var Me=require("@virid/core");var $=require("@virid/core");var Ge=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.
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`;Ge.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 K=Ae,Ce=class Ce{constructor(e,t=null,s={}){y(this,"status");y(this,"data");y(this,"headers");this.status=e,this.data=t,this.headers=s}};i(Ce,"HttpResponse");var M=Ce,Re=class Re extends M{constructor(e,t={}){super(200,e,t)}};i(Re,"OkResponse");var se=Re,$e=class $e extends M{constructor(e,t={}){super(201,e,t)}};i($e,"CreatedResponse");var ne=$e,ke=class ke extends M{constructor(){super(204,null)}};i(ke,"NoContentResponse");var ie=ke,Te=class Te extends M{constructor(e="Bad Request"){super(400,{error:e})}};i(Te,"BadRequestResponse");var ae=Te,He=class He extends M{constructor(e="Unauthorized"){super(401,{error:e})}};i(He,"UnauthorizedResponse");var oe=He,Oe=class Oe extends M{constructor(e="Forbidden"){super(403,{error:e})}};i(Oe,"ForbiddenResponse");var ce=Oe,Ve=class Ve extends M{constructor(e="Not Found"){super(404,{error:e})}};i(Ve,"NotFoundResponse");var le=Ve,Pe=class Pe extends M{constructor(e="Conflict"){super(409,{error:e})}};i(Pe,"ConflictResponse");var Se=Pe,Ie=class Ie extends M{constructor(e){super(422,{errors:e})}};i(Ie,"UnprocessableEntityResponse");var be=Ie,De=class De extends M{constructor(e="Internal Server Error"){super(500,{error:e})}};i(De,"InternalServerErrorResponse");var de=De,Be=class Be extends M{constructor(e,t,s={}){super(e,t,s)}};i(Be,"CustomResponseResponse");var ue=Be,Ne=class Ne extends M{constructor(t,s={dotfiles:"allow"}){super(206,s);y(this,"filePath");y(this,"options");this.filePath=t,this.options=s}};i(Ne,"StreamFileResponse");var H=Ne,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,Ot=i((r,e={})=>new se(r,e),"Ok"),Vt=i((r,e={})=>new ne(r,e),"Created"),Pt=i(()=>new ie,"NoContent"),It=i((r="Bad Request")=>new ae(r),"BadRequest"),Dt=i((r="Unauthorized")=>new oe(r),"Unauthorized"),Bt=i((r="Forbidden")=>new ce(r),"Forbidden"),Nt=i((r="Not Found")=>new le(r),"NotFound"),pe=i((r="Internal Server Error")=>new de(r),"InternalServerError"),qt=i((r,e,t={})=>new ue(r,e,t),"CustomResponse"),_t=i((r,e)=>new H(r,e),"StreamFile"),jt=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 C=_e;var v=new Map;function V(r,e){if(!r){e.dec();return}(Array.isArray(r)?r:[r]).forEach(s=>{s instanceof M?Qt(s,e):s instanceof C?(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(V,"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 H){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 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||$.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 Xe=Object.defineProperty,Ft=i((r,e,t)=>e in r?Xe(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,"he"),c=i((r,e)=>Xe(r,"name",{value:e,configurable:!0}),"o"),l=i((r,e,t)=>Ft(r,typeof e!="symbol"?e+"":e,t),"i"),P,Je=(P=class{static send(...e){g.write(this,...e)}},i(P,"G"),P);c(Je,"BaseMessage");var me=Je,I,Ze=(I=class extends me{constructor(){super(),l(this,"__kind","SingleMessage")}},i(I,"j"),I);c(Ze,"SingleMessage");var We=Ze,D,et=(D=class extends me{constructor(){super(),l(this,"__kind","EventMessage")}},i(D,"L"),D);c(et,"EventMessage");var k=et,B,tt=(B=class extends k{constructor(e,t){super(),l(this,"error"),l(this,"context"),this.error=e,this.context=t}},i(B,"W"),B);c(tt,"ErrorMessage");var je=tt,N,rt=(N=class extends k{constructor(e){super(),l(this,"context"),this.context=e}},i(N,"F"),N);c(rt,"WarnMessage");var Qe=rt,q,st=(q=class extends k{constructor(e){super(),l(this,"context"),this.context=e}},i(q,"Q"),q);c(st,"InfoMessage");var Fe=st,_,nt=(_=class extends k{constructor(e,t,s){super(),l(this,"ComponentClass"),l(this,"recipe"),l(this,"label"),this.ComponentClass=e,this.recipe=t,this.label=s}},i(_,"z"),_);c(nt,"AtomicModifyMessage");var ze=nt,he=null;function it(r){he=r}i(it,"ne");c(it,"activateInstance");var Wt=new Proxy({},{get(r,e){return e==="dispatch"?t=>{if(!he){console.error(`[Virid] Message dispatched before system init: ${t.constructor.name}`);return}return he.dispatch(t)}:Reflect.get(he||{},e)}}),j,at=(j=class{static write(e,...t){let s=typeof e=="function"?new e(...t):e;Wt.dispatch(s)}static error(e,t=""){this.write(new je(e,t))}static warn(e){this.write(new Qe(e))}static info(e){this.write(new Fe(e))}},i(j,"U"),j);c(at,"MessageWriter");var g=at,Q,ot=(Q=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 k?this.eventQueue.push(e):e instanceof We&&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(),g.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){g.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 Ye(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 Ye(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=>g.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){g.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(Q,"J"),Q);c(ot,"Dispatcher");var Ut=ot,F,ct=(F=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=>{g.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){g.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(F,"Y"),F);c(ct,"ExecutionTask");var Ye=ct,W,lt=(W=class{constructor(){l(this,"signalActive",new Map),l(this,"signalStaging",new Map),l(this,"eventActive",[]),l(this,"eventStaging",[])}push(e){if(e instanceof We){let t=e.constructor;this.signalStaging.has(t)||this.signalStaging.set(t,[]),this.signalStaging.get(t).push(e)}else e instanceof k?this.eventStaging.push(e):g.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(W,"q"),W);c(lt,"EventHub");var Lt=lt,U,dt=(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 g.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(U,"K"),U);c(dt,"MessageRegistry");var Gt=dt,L,ut=(L=class{constructor(){l(this,"eventHub",new Lt),l(this,"dispatcher",new Ut(this.eventHub)),l(this,"registry",new Gt),l(this,"middlewares",[]),it(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 me)){g.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)){g.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(L,"X"),L);c(ut,"MessageInternal");var zt=ut,G,pt=(G=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(G,"Z"),G);c(pt,"ViridContainer");var Yt=pt,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 X(r,e,t){let s={params:r,targetClass:Object,methodName:t,originalMethod:e};return e.ccsContext=s,e}i(X,"N");c(X,"withContext");var Kt=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"),Xt=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}
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
22
  ${p.red}Context:${p.reset} ${t}
23
- ${p.red}Details:${p.reset}`,r.error||r||"unknown Error")},"globalErrorHandler"),Jt=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"),Zt=c(r=>{let e=J.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),g.warn(`[Virid Modify] Successfully:
26
- Modify on ${r.ComponentClass.name}
27
- label: ${r.label}`)}catch(t){g.error(t,`[Virid Error] Modify Failed:
28
- ${r.label}`)}},"atomicModifyHandler");function ht(r){r.register(ze,X(ze,Zt,"GlobalAtomicModifier"),1e3),r.register(Qe,X(Qe,Jt,"GlobalWarnHandler"),-999),r.register(je,X(je,Xt,"GlobalErrorHandler"),-999),r.register(Fe,X(Fe,Kt,"GlobalInfoHandler"),-999),J=r}i(ht,"oe");c(ht,"initializeGlobalSystems");var J=null,Hr=new Proxy({},{get(r,e){return(...t)=>{if(!J){console.warn(`[Virid Vue] App method "${String(e)}" called before initialization.`);return}let s=J[e];if(typeof s=="function")return s.apply(J,t)}}}),Ke=new Set,z,ft=(z=class{constructor(){l(this,"container",new Yt),l(this,"messageInternal",new zt),l(this,"activationHooks",[])}addActivationHook(e){this.activationHooks.push(e)}get(e){return e.length>0&&g.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&&g.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 g.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(Ke.has(e.name))return g.warn(`[Virid Plugin] Duplicate Installation: Plugin ${e.name} has already been installed.`),this;try{e.install(this,t),Ke.add(e.name)}catch(s){g.error(s,`[Virid Plugin]: Install Failed: ${e.name}`)}return this}},i(z,"te"),z);c(ft,"ViridApp");var er=ft,Z=new er;Z.addActivationHook(ge);ht(Z);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"},fe=c(r=>{r&&(Array.isArray(r)?r:[r]).forEach(e=>{e instanceof me?g.write(e):g.warn("[Virid HandleResult] Invalid Return Type: Must return Message or Message[].")})},"handleResult");function tr(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 f=new Error(`[Virid System] System Parameter Loss:
29
- Unable to recognize system parameters, please confirm if import "reflection-metadata" was introduced at the beginning!`);g.error(f);return}if(o.some(f=>f===void 0)){let f=new Error(`[Virid System] Parameter Metadata Loss in "${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)}`);g.error(f);return}if(r.messageClass&&a){g.error(new Error(`[Virid System] Multiple Messages Are Not Allowed: Cannot use @ message() and SystemParams simultaneously in ${t}`));return}if(!r.messageClass&&!a){g.error(new Error(`[Virid System] System Parameter Loss:
33
- Please declare the message type using the Message decorator`));return}let d=c(f=>{let E=o.map((x,A)=>{if(a&&a.index==A){let{messageClass:T,single:ve}=a,re=Array.isArray(f)?f[0]:f;if(!(re instanceof T)){let bt=re.constructor.name;throw new Error(`[Virid System] Type Mismatch: Expected ${T.name}, but received ${bt}`)}if(re instanceof We)return ve?Array.isArray(f)?f[f.length-1]:f:Array.isArray(f)?f:[f];if(re instanceof k)return f;throw new Error(`[Virid System] unknown Message Types: Message ${T.name} is not a subclass of SingleMessage or EventMessage!`)}let R=Z.get(x);if(!R)throw new Error(`[Virid System] unknown Inject Data Types: ${x.name} is not registered in the container!`);return R}),w=n.apply(e,E);return w instanceof Promise?w.then(fe):fe(w)},"wrappedSystem"),h={params:o,targetClass:e,methodName:t,originalMethod:n};d.systemContext=h,s.value=d;let u=r.messageClass||a.messageClass;Z.register(u,d,r.priority)}}i(tr,"lt");c(tr,"System");function rr(r,e=!0){return(t,s,n)=>{if(Reflect.hasOwnMetadata(b.MESSAGE,t,s)){g.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(rr,"ht");c(rr,"Message");function sr(){return(r,e,t)=>{let s=Reflect.getMetadata(b.SAFE,r)||new Set;s.add(e),Reflect.defineMetadata(b.SAFE,s,r)}}i(sr,"ut");c(sr,"Safe");function nr(r,[]){return(e,t)=>{let s=Reflect.getMetadata(b.OBSERVER,e)||[];s.push({key:t,callback:r}),Reflect.defineMetadata(b.OBSERVER,s,e)}}i(nr,"dt");c(nr,"Observer");function ir(){return r=>{Reflect.defineMetadata(b.CONTROLLER,!0,r)}}i(ir,"ft");c(ir,"Controller");function ar(){return r=>{Reflect.defineMetadata(b.COMPONENT,!0,r)}}i(ar,"pt");c(ar,"Component");var or=["push","pop","shift","unshift","splice","sort","reverse"];function ge(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 h=a.value;return Array.isArray(h)&&or.includes(d)?(...u)=>{let f=[...h],E=h[d].apply(h,u),w=t.call(r,f,h);return fe(w),E}: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 fe(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"&&ge(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"&&ge(s)})),r}i(ge,"_");c(ge,"bindObservers");function cr(){return Z}i(cr,"Ct");c(cr,"createVirid");function gt(r){let e=parseInt(r,10);if(isNaN(e))throw new C(400,`Validation failed: "${r}" is not a number.`);return e}i(gt,"ParseIntPipe");function mt(r){return r==="true"||r==="1"?!0:r==="false"||r==="0"?!1:!!r}i(mt,"ParseBoolPipe");var ee=new Map;ee.set(Number,gt);ee.set(Boolean,mt);function lr(r,e){if(ee.has(r)){g.error(new Error(`[Virid Express Pipe] Repeated Pipe: Auto pipe for ${r} has already been registered.`));return}ee.set(r,e)}i(lr,"addAutoPipe");function ye(r){return ee.get(r)}i(ye,"getAutoPipe");function Ue(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(Ue,"parseRawCookie");var yt=require("@virid/core");var Le=class Le extends yt.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(Le,"HttpRequestMessage");var te=Le;var xe=new Me.MessageRegistry,Ee=new Map,dr=0;function xt(r){for(let[e,t]of xe.systemTaskMap.entries())for(let s of t)r.register(e,s.fn,s.priority);xe.systemTaskMap.clear()}i(xt,"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=dr++>>>0;v.set(u,new K(u,d,h,Date.now(),n));let f=new o(u);h.once("finish",()=>v.delete(u)),h.once("close",()=>v.delete(u)),Me.MessageWriter.write(f)})}}i(Mt,"registerHttpRoute");var we=null;function wt(r,e){we=r,xt(r),Mt(e.server)}i(wt,"activateApp");var vt=new Proxy({},{get(r,e){return(...t)=>{if(!we)return Et.MessageWriter.warn(`[Virid Vue] App method "${String(e)}" called before initialization.`),null;let s=we[e];if(typeof s=="function")return s.apply(we,t)}}});var S=require("@virid/core");var St=require("@virid/core"),m={...St.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 ur(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(ur,"HttpRoute");function pr(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=wr(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 h=r.messageClass??a.messageClass;if(!te.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(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((R,T)=>{if(a&&a.index==T){if(!(E instanceof h)){let ve=E.constructor.name;throw new Error(`[Virid Express HttpSystem] Type Mismatch: Expected ${h.name}, but received ${ve}`)}return E}else return vr(R,T,w,d)}),A=n.apply(e,x);return A instanceof Promise?A.then(R=>{V(R,w)}).catch(R=>{throw V(pe(),w),R}):V(A,w)}catch(x){throw x instanceof C?V(x,w):V(pe(),w),x}},"wrappedSystem"),f={params:o,targetClass:e,methodName:t,originalMethod:n};u.systemContext=f,s.value=u,xe.register(h,u,r.priority)}}i(pr,"HttpSystem");function hr(){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(hr,"Body");function fr(){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(fr,"Headers");function gr(){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(gr,"Cookies");function mr(){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(mr,"Req");function yr(){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(yr,"Res");function xr(){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(xr,"Ctx");function Mr(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(Mr,"Query");function Er(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(Er,"Params");function wr(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),h=Reflect.getOwnMetadata(m.CONTEXT,r,e),f=(Reflect.getOwnMetadata(m.QUERY,r,e)||[]).map(x=>{if(!x.pipe){let A=t[x.index];x.pipe=ye(A)}return x}),w=(Reflect.getOwnMetadata(m.PARAMS,r,e)||[]).map(x=>{if(!x.pipe){let A=t[x.index];x.pipe=ye(A)}return x});return{bodyMeta:s,headerMeta:n,queryMeta:f,cookiesMeta:o,reqMeta:d,resMeta:a,ctxMeta:h,paramMeta:w}}i(wr,"getHttpMetadata");function vr(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 Ue(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=vt.get(r);if(!h)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 h}i(vr,"getHttpSystemArgs");var Sr={name:"@virid/express",install(r,e){wt(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